home *** CD-ROM | disk | FTP | other *** search
- /* ******************************************************************** */
- /* C code generated by: */
- /* Visual Arts Version 2.1 */
- /* Copyright 1994-95 Danny Y. Wong All rights reserved */
- /* Calgary, Alberta (CANADA) */
- /* Partial of the code is copyright by Jaba Development */
- /* ******************************************************************** */
-
- #include <VisualArts.h>
-
- #define ID_ObjID1 0
-
- #define MainNumGads 1
-
- #include "Console_func.c"
-
-
- int GetPubScreen(void);
- void ClosePubScreen(void);
- int OpenMainWindow(char windtitle[]);
- void CloseMainWindow(void);
- int InitMainConsole(void);
- int MainConsoleHandler(void);
- int MainHandler(void);
- int MainMainHandler(void);
- void DrawMainObjs(void);
- int main(int argc, char *argv[]);
-
- char myString[256];
- short counter=0;
- UBYTE *PubScrName = "Workbench";
- struct DrawInfo *ScrDrawInfo = NULL;
- APTR VisualInfo = NULL;
- struct Screen *Scr = NULL;
- struct Window *MainWnd = NULL;
- struct Window *MainConWnd = NULL;
- struct MsgPort *MainConWritePort = NULL;
- struct MsgPort *MainConReadPort = NULL;
- struct IOStdReq *MainConWriteReq = NULL;
- struct IOStdReq *MainConReadReq = NULL;
- struct Gadget *MainGList = NULL;
- struct Gadget *MainGadgets[MainNumGads];
- struct IntuiMessage MainMsg;
- UWORD MainLeft = 118;
- UWORD MainTop = 32;
- UWORD MainWidth = 314;
- UWORD MainHeight = 50;
- char character;
- struct TextAttr topaz8 = { (STRPTR)"topaz.font", 8, 0x00, 0x01 };
- struct TextAttr topaz800 = { (STRPTR)"topaz.font", 8, 0x00, 0x00 };
-
- struct IntuiText MainIText[] = {
- 1, 0, JAM2, 71, 2, &topaz800, (UBYTE *)"Text from Console Window", NULL,
- };
-
- WORD MainGadTypes[] = {
- TEXT_KIND,
- };
-
- struct NewGadget MainNGads[] = {
- 7, 12, 293, 22, (UBYTE *)"", &topaz800, ID_ObjID1, PLACETEXT_LEFT, NULL, NULL,
- };
-
- ULONG MainNTags[] = {
- (GTTX_Text),(ULONG)"", (GTTX_Border), TRUE, TAG_DONE,
- };
-
-
- int GetPubScreen(void)
- {
- if (!(Scr = LockPubScreen(PubScrName)))
- return(1L);
-
- if (!(VisualInfo = GetVisualInfo(Scr, TAG_DONE)))
- return(2L);
-
- if (!(ScrDrawInfo = GetScreenDrawInfo(Scr)))
- return(3L);
- return(0L);
- }
-
- void ClosePubScreen(void)
- {
- if (VisualInfo)
- FreeVisualInfo(VisualInfo);
- if (Scr)
- UnlockPubScreen(NULL, Scr);
- if (ScrDrawInfo)
- FreeScreenDrawInfo(Scr, ScrDrawInfo);
- }
-
- int InitMainConsole(void)
- {
- MainConWnd = OpenWindowTags( NULL,
- WA_Left, 200,
- WA_Top, 100,
- WA_Width, 250,
- WA_Height, 50,
- WA_Title, "Console Window",
- WA_IDCMP, NULL,
- WA_Flags, WFLG_DRAGBAR | WFLG_SIMPLE_REFRESH | WFLG_DEPTHGADGET,
- WA_CustomScreen, Scr,
- TAG_DONE );
-
- if ( MainConWnd == NULL )
- return(6L);
-
- MainConWritePort = CreatePort("Main.con.write", 0);
- if ( !MainConWritePort)
- return(1L);
- MainConWriteReq = CreateStdIO(MainConWritePort);
- if ( !MainConWriteReq)
- return(2L);
- MainConReadPort = CreatePort("Main.con.read", 0);
- if ( !MainConReadPort)
- return(3L);
- MainConReadReq = CreateStdIO(MainConReadPort);
- if ( !MainConReadReq)
- return(4L);
- if ((OpenConsole(MainConWriteReq, MainConReadReq, MainConWnd)) != 0)
- return(5L);
-
- return(0L);
- }
-
-
- int OpenMainWindow(char windtitle[80])
- {
- struct NewGadget NewGad;
- struct Gadget *Gad;
- register UWORD i, j;
- UWORD offsetx = Scr->WBorLeft;
- UWORD offsety = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
-
- if (!(Gad = CreateContext(&MainGList)))
- return(1L);
-
- for (i=0, j=0; i < MainNumGads; i++)
- {
- CopyMem((char *)&MainNGads[i], (char *)&NewGad, (long)sizeof(struct NewGadget));
-
- NewGad.ng_VisualInfo = VisualInfo;
- NewGad.ng_LeftEdge += offsetx;
- NewGad.ng_TopEdge += offsety;
-
- MainGadgets[i] = Gad = CreateGadgetA((ULONG)MainGadTypes[i], Gad, &NewGad,
- (struct TagItem *)&MainNTags[j]);
- while (MainNTags[j])
- j +=2;
- j++;
- if (!Gad)
- return(2L);
- }
- if (!(MainWnd = OpenWindowTags(NULL,
- WA_Left, MainLeft,
- WA_Top, MainTop,
- WA_Width, MainWidth,
- WA_Height, MainHeight,
- WA_NewLookMenus, TRUE,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_NEWSIZE ,
- WA_Flags, WFLG_CLOSEGADGET | WFLG_DEPTHGADGET | WFLG_SIMPLE_REFRESH |
- WFLG_ACTIVATE | WFLG_DRAGBAR ,
- WA_Gadgets, MainGList,
- WA_Title, windtitle,
- WA_ScreenTitle, "Visual Arts V2.1 Copyright 1994-95 Danny Y. Wong All Rights Reserved.",
- WA_PubScreen, Scr,
- WA_MinWidth, 160,
- WA_MinHeight, 50,
- WA_MaxWidth, 640,
- WA_MaxHeight, 200,
- TAG_DONE)))
- return(3L);
-
- DrawMainObjs();
- GT_RefreshWindow(MainWnd, NULL);
- RefreshGadgets(MainGadgets[0], MainWnd, NULL);
- if (InitMainConsole())
- return(4L);
- return(0L);
- }
-
- void CloseMainWindow(void)
- {
- if (MainConWnd)
- CloseWindow(MainConWnd);
- if (MainConWriteReq)
- CloseDevice((struct IORequest *)MainConWriteReq);
- if (MainConReadReq)
- DeleteStdIO(MainConReadReq);
- if (MainConReadPort)
- DeletePort(MainConReadPort);
- if (MainConWriteReq)
- DeleteStdIO(MainConWriteReq);
- if (MainConWriteReq)
- DeletePort(MainConWritePort);
- if (MainWnd)
- CloseWindow(MainWnd);
- if (MainGList)
- FreeGadgets(MainGList);
- }
-
- int MainHandler(void)
- {
- struct IntuiMessage *msg;
- struct VAobject VAObject;
- int running = 1;
- ULONG class;
- UWORD code;
-
- while (msg=GT_GetIMsg(MainWnd->UserPort))
- {
- CopyMem((char *)msg, (char *)&MainMsg, (long)sizeof(struct IntuiMessage));
- class = msg->Class;
- code = msg->Code;
-
- VAObject.va_Window = (struct Window *)MainWnd;
- VAObject.va_Gadget = (struct Gadget *)msg->IAddress;
- VAObject.va_IntuiMsg = (struct IntuiMessage *)msg;
- VAObject.va_Flags = 0;
- VAObject.va_UserData = 0;
-
- GT_ReplyIMsg(msg);
- switch(class)
- {
-
- case IDCMP_NEWSIZE:
- break;
-
- case IDCMP_CLOSEWINDOW:
- return(0);
- break;
- }
- }
- return(running);
- }
-
- void DrawMainObjs(void)
- {
- PrintIText(MainWnd->RPort, MainIText, MainWnd->BorderLeft, MainWnd->BorderTop);
-
- }
-
- int MainConsoleHandler(void)
- {
- while( CheckIO((struct IORequest *)MainConReadReq))
- {
- WaitIO( (struct IORequest *)MainConReadReq);
- QueueRead(MainConReadReq, &character);
- ConPutChar(MainConWriteReq, character);
- if ((int)character == 13 || counter > 255)
- {
- myString[counter]='\0';
- ConPutChar(MainConWriteReq, (char)12);
- GT_SetGadgetAttrs(MainGadgets[0], MainWnd, NULL,
- GTTX_Text, " ");
- GT_SetGadgetAttrs(MainGadgets[0], MainWnd, NULL,
- GTTX_Text, myString);
- counter=0;
- }
- else
- if (isprint(character))
- myString[counter++] = character;
- }
- return(1);
- }
-
-
- int MainMainHandler(void)
- {
- int running = 1;
- ULONG windsig, signals;
-
- ULONG consolesig;
- QueueRead(MainConReadReq, &character);
- consolesig = 1L << MainConReadReq->io_Message.mn_ReplyPort->mp_SigBit;
- windsig = 1L << MainWnd->UserPort->mp_SigBit;
- while (running == 1)
- {
- signals = Wait( windsig | consolesig );
- if (signals & windsig)
- {
- running = MainHandler();
- }
- else
- if (signals & consolesig)
- running = MainConsoleHandler();
- }
- return(running);
- }
-
- int main(int argc, char *argv[])
- {
- int rc;
-
- if (!(GetPubScreen()))
- {
- if (!(OpenMainWindow("Console Demo")))
- {
- rc = MainMainHandler();
- CloseMainWindow();
- }
- ClosePubScreen();
- }
- return(0L);
- }
-