home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************/
- /* */
- /* Amiga C Encyclopedia (ACE) V3.0 Amiga C Club (ACC) */
- /* ------------------------------- ------------------ */
- /* */
- /* Book: ACM Intuition Amiga C Club */
- /* Chapter: Gadgets Tulevagen 22 */
- /* File: Example13.c 181 41 LIDINGO */
- /* Author: Anders Bjerin SWEDEN */
- /* Date: 92-05-01 */
- /* Version: 1.10 */
- /* */
- /* Copyright 1992, Anders Bjerin - Amiga C Club (ACC) */
- /* */
- /* Registered members may use this program freely in their */
- /* own commercial/noncommercial programs/articles. */
- /* */
- /***********************************************************/
-
- /* This example demonstrates how to use six string gadgets which */
- /* are automatically activated (selected) when the user release */
- /* the gadget above. */
-
-
-
- /* We use Intuition: */
- #include <intuition/intuition.h>
-
-
- /* Maximum length of the string gadgets: */
- #define STRINGSIZE 50
-
-
- /* We are using the Intuition library: */
- struct IntuitionBase *IntuitionBase;
-
-
-
- /* The coordinates for the box: */
- SHORT my_points[]=
- {
- -7, -4, /* Start at position (-7, -4) */
- 200, -4, /* Draw a line to the right to position (200,-4) */
- 200, 11, /* Draw a line down to position (200,11) */
- -7, 11, /* Draw a line to the right to position (-7,11) */
- -7, -4 /* Finish of by drawing a line up to position (-7,-4) */
- };
-
- /* The Border structure: */
- struct Border my_border=
- {
- 0, 0, /* LeftEdge, TopEdge. */
- 1, /* FrontPen, colour register 1. */
- 0, /* BackPen, for the moment unused. */
- JAM1, /* DrawMode, draw the lines with colour 1. */
- 5, /* Count, 5 pair of coordinates in the array. */
- my_points, /* XY, pointer to the array with the coordinates. */
- NULL, /* NextBorder, no other Border structures are connected. */
- };
-
- UBYTE my_undo_buffer[STRINGSIZE]; /* Must be at least as big as my_buffer. */
-
-
-
- /*****************/
- /* Textstring 1: */
- /*****************/
-
- UBYTE my_buffer1[STRINGSIZE]; /* 50 characters including the NULL-sign. */
-
- /* The IntuiText structure: */
- struct IntuiText text1=
- {
- 1, /* FrontPen, colour register 1. */
- 0, /* BackPen, colour register 0. */
- JAM1, /* DrawMode, draw the characters with colour 1, do not */
- /* change the background. */
- -77, 0, /* LeftEdge, TopEdge. */
- NULL, /* ITextFont, use default font. */
- " Name:",/* IText, the text that will be printed. */
- NULL, /* NextText, no other IntuiText structures. */
- };
-
- struct StringInfo string_info1=
- {
- my_buffer1, /* Buffer, pointer to a null-terminated string. */
- my_undo_buffer, /* UndoBuffer, pointer to a null-terminated string. */
- /* (Remember my_buffer is equal to &my_buffer[0]) */
- 0, /* BufferPos, initial position of the cursor. */
- 50, /* MaxChars, 50 characters + null-sign ('\0'). */
- 0, /* DispPos, first character in the string should be */
- /* first character in the display. */
-
- /* Intuition initializes and maintaines these variables: */
-
- 0, /* UndoPos */
- 0, /* NumChars */
- 0, /* DispCount */
- 0, 0, /* CLeft, CTop */
- NULL, /* LayerPtr */
- NULL, /* LongInt */
- NULL, /* AltKeyMap */
- };
-
- struct Gadget gadget1=
- {
- NULL, /* NextGadget, no more gadgets in the list. */
- 92, /* LeftEdge, 92 pixels out. */
- 30, /* TopEdge, 30 lines down. */
- 198, /* Width, 198 pixels wide. */
- 8, /* Height, 8 pixels lines heigh. */
- GADGHCOMP, /* Flags, draw the select box in the complement */
- /* colours. Note: it actually only the cursor which */
- /* will be drawn in the complement colours (yellow). */
- /* If you set the flag GADGHNONE the cursor will not be */
- /* highlighted, and the user will therefore not be able */
- /* to see it. */
- GADGIMMEDIATE| /* Activation, our program will recieve a message when */
- RELVERIFY, /* the user has selected this gadget, and when the user */
- /* has released it. */
- STRGADGET, /* GadgetType, a String gadget. */
- (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
- NULL, /* SelectRender, NULL since we do not supply the gadget */
- /* with an alternative image. */
- &text1, /* GadgetText, a pointer to our IntuiText structure. */
- NULL, /* MutualExclude, no mutual exclude. */
- (APTR) &string_info1, /* SpecialInfo, a pointer to a StringInfo str. */
- 0, /* GadgetID, no id. */
- NULL /* UserData, no user data connected to the gadget. */
- };
-
-
-
- /*****************/
- /* Textstring 2: */
- /*****************/
-
- UBYTE my_buffer2[STRINGSIZE]; /* 50 characters including the NULL-sign. */
-
- /* The IntuiText structure: */
- struct IntuiText text2=
- {
- 1, /* FrontPen, colour register 1. */
- 0, /* BackPen, colour register 0. */
- JAM1, /* DrawMode, draw the characters with colour 1, do not */
- /* change the background. */
- -77, 0, /* LeftEdge, TopEdge. */
- NULL, /* ITextFont, use default font. */
- "Address:",/* IText, the text that will be printed. */
- NULL, /* NextText, no other IntuiText structures. */
- };
-
- struct StringInfo string_info2=
- {
- my_buffer2, /* Buffer, pointer to a null-terminated string. */
- my_undo_buffer, /* UndoBuffer, pointer to a null-terminated string. */
- /* (Remember my_buffer is equal to &my_buffer[0]) */
- 0, /* BufferPos, initial position of the cursor. */
- 50, /* MaxChars, 50 characters + null-sign ('\0'). */
- 0, /* DispPos, first character in the string should be */
- /* first character in the display. */
-
- /* Intuition initializes and maintaines these variables: */
-
- 0, /* UndoPos */
- 0, /* NumChars */
- 0, /* DispCount */
- 0, 0, /* CLeft, CTop */
- NULL, /* LayerPtr */
- NULL, /* LongInt */
- NULL, /* AltKeyMap */
- };
-
- struct Gadget gadget2=
- {
- &gadget1, /* NextGadget, no more gadgets in the list. */
- 92, /* LeftEdge, 92 pixels out. */
- 50, /* TopEdge, 50 lines down. */
- 198, /* Width, 198 pixels wide. */
- 8, /* Height, 8 pixels lines heigh. */
- GADGHCOMP, /* Flags, draw the select box in the complement */
- /* colours. Note: it actually only the cursor which */
- /* will be drawn in the complement colours (yellow). */
- /* If you set the flag GADGHNONE the cursor will not be */
- /* highlighted, and the user will therefore not be able */
- /* to see it. */
- GADGIMMEDIATE| /* Activation, our program will recieve a message when */
- RELVERIFY, /* the user has selected this gadget, and when the user */
- /* has released it. */
- STRGADGET, /* GadgetType, a String gadget. */
- (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
- NULL, /* SelectRender, NULL since we do not supply the gadget */
- /* with an alternative image. */
- &text2, /* GadgetText, a pointer to our IntuiText structure. */
- NULL, /* MutualExclude, no mutual exclude. */
- (APTR) &string_info2, /* SpecialInfo, a pointer to a StringInfo str. */
- 0, /* GadgetID, no id. */
- NULL /* UserData, no user data connected to the gadget. */
- };
-
-
-
- /*****************/
- /* Textstring 3: */
- /*****************/
-
- UBYTE my_buffer3[STRINGSIZE]; /* 50 characters including the NULL-sign. */
-
- /* The IntuiText structure: */
- struct IntuiText text3=
- {
- 1, /* FrontPen, colour register 1. */
- 0, /* BackPen, colour register 0. */
- JAM1, /* DrawMode, draw the characters with colour 1, do not */
- /* change the background. */
- -77, 0, /* LeftEdge, TopEdge. */
- NULL, /* ITextFont, use default font. */
- " City:",/* IText, the text that will be printed. */
- NULL, /* NextText, no other IntuiText structures. */
- };
-
- struct StringInfo string_info3=
- {
- my_buffer3, /* Buffer, pointer to a null-terminated string. */
- my_undo_buffer, /* UndoBuffer, pointer to a null-terminated string. */
- /* (Remember my_buffer is equal to &my_buffer[0]) */
- 0, /* BufferPos, initial position of the cursor. */
- 50, /* MaxChars, 50 characters + null-sign ('\0'). */
- 0, /* DispPos, first character in the string should be */
- /* first character in the display. */
-
- /* Intuition initializes and maintaines these variables: */
-
- 0, /* UndoPos */
- 0, /* NumChars */
- 0, /* DispCount */
- 0, 0, /* CLeft, CTop */
- NULL, /* LayerPtr */
- NULL, /* LongInt */
- NULL, /* AltKeyMap */
- };
-
- struct Gadget gadget3=
- {
- &gadget2, /* NextGadget, no more gadgets in the list. */
- 92, /* LeftEdge, 92 pixels out. */
- 70, /* TopEdge, 70 lines down. */
- 198, /* Width, 198 pixels wide. */
- 8, /* Height, 8 pixels lines heigh. */
- GADGHCOMP, /* Flags, draw the select box in the complement */
- /* colours. Note: it actually only the cursor which */
- /* will be drawn in the complement colours (yellow). */
- /* If you set the flag GADGHNONE the cursor will not be */
- /* highlighted, and the user will therefore not be able */
- /* to see it. */
- GADGIMMEDIATE| /* Activation, our program will recieve a message when */
- RELVERIFY, /* the user has selected this gadget, and when the user */
- /* has released it. */
- STRGADGET, /* GadgetType, a String gadget. */
- (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
- NULL, /* SelectRender, NULL since we do not supply the gadget */
- /* with an alternative image. */
- &text3, /* GadgetText, a pointer to our IntuiText structure. */
- NULL, /* MutualExclude, no mutual exclude. */
- (APTR) &string_info3, /* SpecialInfo, a pointer to a StringInfo str. */
- 0, /* GadgetID, no id. */
- NULL /* UserData, no user data connected to the gadget. */
- };
-
-
-
- /*****************/
- /* Textstring 4: */
- /*****************/
-
- UBYTE my_buffer4[STRINGSIZE]; /* 50 characters including the NULL-sign. */
-
- /* The IntuiText structure: */
- struct IntuiText text4=
- {
- 1, /* FrontPen, colour register 1. */
- 0, /* BackPen, colour register 0. */
- JAM1, /* DrawMode, draw the characters with colour 1, do not */
- /* change the background. */
- -77, 0, /* LeftEdge, TopEdge. */
- NULL, /* ITextFont, use default font. */
- " State:",/* IText, the text that will be printed. */
- NULL, /* NextText, no other IntuiText structures. */
- };
-
- struct StringInfo string_info4=
- {
- my_buffer4, /* Buffer, pointer to a null-terminated string. */
- my_undo_buffer, /* UndoBuffer, pointer to a null-terminated string. */
- /* (Remember my_buffer is equal to &my_buffer[0]) */
- 0, /* BufferPos, initial position of the cursor. */
- 50, /* MaxChars, 50 characters + null-sign ('\0'). */
- 0, /* DispPos, first character in the string should be */
- /* first character in the display. */
-
- /* Intuition initializes and maintaines these variables: */
-
- 0, /* UndoPos */
- 0, /* NumChars */
- 0, /* DispCount */
- 0, 0, /* CLeft, CTop */
- NULL, /* LayerPtr */
- NULL, /* LongInt */
- NULL, /* AltKeyMap */
- };
-
- struct Gadget gadget4=
- {
- &gadget3, /* NextGadget, no more gadgets in the list. */
- 92, /* LeftEdge, 92 pixels out. */
- 90, /* TopEdge, 90 lines down. */
- 198, /* Width, 198 pixels wide. */
- 8, /* Height, 8 pixels lines heigh. */
- GADGHCOMP, /* Flags, draw the select box in the complement */
- /* colours. Note: it actually only the cursor which */
- /* will be drawn in the complement colours (yellow). */
- /* If you set the flag GADGHNONE the cursor will not be */
- /* highlighted, and the user will therefore not be able */
- /* to see it. */
- GADGIMMEDIATE| /* Activation, our program will recieve a message when */
- RELVERIFY, /* the user has selected this gadget, and when the user */
- /* has released it. */
- STRGADGET, /* GadgetType, a String gadget. */
- (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
- NULL, /* SelectRender, NULL since we do not supply the gadget */
- /* with an alternative image. */
- &text4, /* GadgetText, a pointer to our IntuiText structure. */
- NULL, /* MutualExclude, no mutual exclude. */
- (APTR) &string_info4, /* SpecialInfo, a pointer to a StringInfo str. */
- 0, /* GadgetID, no id. */
- NULL /* UserData, no user data connected to the gadget. */
- };
-
-
-
- /*****************/
- /* Textstring 5: */
- /*****************/
-
- UBYTE my_buffer5[STRINGSIZE]; /* 50 characters including the NULL-sign. */
-
- /* The IntuiText structure: */
- struct IntuiText text5=
- {
- 1, /* FrontPen, colour register 1. */
- 0, /* BackPen, colour register 0. */
- JAM1, /* DrawMode, draw the characters with colour 1, do not */
- /* change the background. */
- -77, 0, /* LeftEdge, TopEdge. */
- NULL, /* ITextFont, use default font. */
- "Country:",/* IText, the text that will be printed. */
- NULL, /* NextText, no other IntuiText structures. */
- };
-
- struct StringInfo string_info5=
- {
- my_buffer5, /* Buffer, pointer to a null-terminated string. */
- my_undo_buffer, /* UndoBuffer, pointer to a null-terminated string. */
- /* (Remember my_buffer is equal to &my_buffer[0]) */
- 0, /* BufferPos, initial position of the cursor. */
- 50, /* MaxChars, 50 characters + null-sign ('\0'). */
- 0, /* DispPos, first character in the string should be */
- /* first character in the display. */
-
- /* Intuition initializes and maintaines these variables: */
-
- 0, /* UndoPos */
- 0, /* NumChars */
- 0, /* DispCount */
- 0, 0, /* CLeft, CTop */
- NULL, /* LayerPtr */
- NULL, /* LongInt */
- NULL, /* AltKeyMap */
- };
-
- struct Gadget gadget5=
- {
- &gadget4, /* NextGadget, no more gadgets in the list. */
- 92, /* LeftEdge, 92 pixels out. */
- 110, /* TopEdge, 110 lines down. */
- 198, /* Width, 198 pixels wide. */
- 8, /* Height, 8 pixels lines heigh. */
- GADGHCOMP, /* Flags, draw the select box in the complement */
- /* colours. Note: it actually only the cursor which */
- /* will be drawn in the complement colours (yellow). */
- /* If you set the flag GADGHNONE the cursor will not be */
- /* highlighted, and the user will therefore not be able */
- /* to see it. */
- GADGIMMEDIATE| /* Activation, our program will recieve a message when */
- RELVERIFY, /* the user has selected this gadget, and when the user */
- /* has released it. */
- STRGADGET, /* GadgetType, a String gadget. */
- (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
- NULL, /* SelectRender, NULL since we do not supply the gadget */
- /* with an alternative image. */
- &text5, /* GadgetText, a pointer to our IntuiText structure. */
- NULL, /* MutualExclude, no mutual exclude. */
- (APTR) &string_info5, /* SpecialInfo, a pointer to a StringInfo str. */
- 0, /* GadgetID, no id. */
- NULL /* UserData, no user data connected to the gadget. */
- };
-
-
-
- /*****************/
- /* Textstring 6: */
- /*****************/
-
- UBYTE my_buffer6[STRINGSIZE]; /* 50 characters including the NULL-sign. */
-
- /* The IntuiText structure: */
- struct IntuiText text6=
- {
- 1, /* FrontPen, colour register 1. */
- 0, /* BackPen, colour register 0. */
- JAM1, /* DrawMode, draw the characters with colour 1, do not */
- /* change the background. */
- -77, 0, /* LeftEdge, TopEdge. */
- NULL, /* ITextFont, use default font. */
- " Phone:",/* IText, the text that will be printed. */
- NULL, /* NextText, no other IntuiText structures. */
- };
-
- struct StringInfo string_info6=
- {
- my_buffer6, /* Buffer, pointer to a null-terminated string. */
- my_undo_buffer, /* UndoBuffer, pointer to a null-terminated string. */
- /* (Remember my_buffer is equal to &my_buffer[0]) */
- 0, /* BufferPos, initial position of the cursor. */
- 50, /* MaxChars, 50 characters + null-sign ('\0'). */
- 0, /* DispPos, first character in the string should be */
- /* first character in the display. */
-
- /* Intuition initializes and maintaines these variables: */
-
- 0, /* UndoPos */
- 0, /* NumChars */
- 0, /* DispCount */
- 0, 0, /* CLeft, CTop */
- NULL, /* LayerPtr */
- NULL, /* LongInt */
- NULL, /* AltKeyMap */
- };
-
- struct Gadget gadget6=
- {
- &gadget5, /* NextGadget, no more gadgets in the list. */
- 92, /* LeftEdge, 92 pixels out. */
- 130, /* TopEdge, 130 lines down. */
- 198, /* Width, 198 pixels wide. */
- 8, /* Height, 8 pixels lines heigh. */
- GADGHCOMP, /* Flags, draw the select box in the complement */
- /* colours. Note: it actually only the cursor which */
- /* will be drawn in the complement colours (yellow). */
- /* If you set the flag GADGHNONE the cursor will not be */
- /* highlighted, and the user will therefore not be able */
- /* to see it. */
- GADGIMMEDIATE| /* Activation, our program will recieve a message when */
- RELVERIFY, /* the user has selected this gadget, and when the user */
- /* has released it. */
- STRGADGET, /* GadgetType, a String gadget. */
- (APTR) &my_border, /* GadgetRender, a pointer to our Border structure. */
- NULL, /* SelectRender, NULL since we do not supply the gadget */
- /* with an alternative image. */
- &text6, /* GadgetText, a pointer to our IntuiText structure. */
- NULL, /* MutualExclude, no mutual exclude. */
- (APTR) &string_info6, /* SpecialInfo, a pointer to a StringInfo str. */
- 0, /* GadgetID, no id. */
- NULL /* UserData, no user data connected to the gadget. */
- };
-
-
-
-
- /* Declare a pointer to a Window structure: */
- struct Window *my_window;
-
- /* Declare and initialize your NewWindow structure: */
- struct NewWindow my_new_window=
- {
- 0, /* LeftEdge x position of the window. */
- 10, /* TopEdge y positio of the window. */
- 400, /* Width 400 pixels wide. */
- 180, /* Height 180 lines high. */
- 0, /* DetailPen Text should be drawn with colour reg. 0 */
- 1, /* BlockPen Blocks should be drawn with colour reg. 1 */
- CLOSEWINDOW| /* IDCMPFlags The window will give us a message if the */
- /* user has selected the Close window gad, */
- GADGETDOWN| /* or a gadget has been pressed on, or */
- GADGETUP, /* a gadge has been released. */
- SMART_REFRESH| /* Flags Intuition should refresh the window. */
- WINDOWCLOSE| /* Close Gadget. */
- WINDOWDRAG| /* Drag gadget. */
- WINDOWDEPTH| /* Depth arrange Gadgets. */
- WINDOWSIZING| /* Sizing Gadget. */
- ACTIVATE, /* The window should be Active when opened. */
- &gadget6, /* FirstGadget A pointer to the String gadget. */
- NULL, /* CheckMark Use Intuition's default CheckMark. */
- "Automatically activated string gadgets",/* Title Title of the window. */
- NULL, /* Screen Connected to the Workbench Screen. */
- NULL, /* BitMap No Custom BitMap. */
- 400, /* MinWidth We will not allow the window to become */
- 180, /* MinHeight smaller than 400 x 180, and not bigger */
- 640, /* MaxWidth than 640 x 200. */
- 200, /* MaxHeight */
- WBENCHSCREEN /* Type Connected to the Workbench Screen. */
- };
-
-
-
- main()
- {
- /* Boolean variable used for the while loop: */
- BOOL close_me;
-
- /* Declare a variable in which we will store the IDCMP flag: */
- ULONG class;
- CPTR address;
-
- /* Declare a pointer to an IntuiMessage structure: */
- struct IntuiMessage *my_message;
-
-
-
- /* Put some text (thi time nothing) into the buffer strings: */
- strcpy( my_buffer1, "" );
- strcpy( my_buffer2, "" );
- strcpy( my_buffer3, "" );
- strcpy( my_buffer4, "" );
- strcpy( my_buffer5, "" );
- strcpy( my_buffer6, "" );
-
-
-
- /* Before we can use Intuition we need to open the Intuition Library: */
- IntuitionBase = (struct IntuitionBase *)
- OpenLibrary( "intuition.library", 0 );
-
- if( IntuitionBase == NULL )
- exit(); /* Could NOT open the Intuition Library! */
-
-
-
- /* We will now try to open the window: */
- my_window = (struct Window *) OpenWindow( &my_new_window );
-
- /* Have we opened the window succesfully? */
- if(my_window == NULL)
- {
- /* Could NOT open the Window! */
-
- /* Close the Intuition Library since we have opened it: */
- CloseLibrary( IntuitionBase );
-
- exit();
- }
- /* We have opened the window, and everything seems to be OK. */
-
-
-
- /* Activate the first gadget: */
- ActivateGadget( &gadget1, my_window, NULL );
-
-
- close_me = FALSE;
-
- /* Stay in the while loop until the user has selected the Close window */
- /* gadget: */
- while( close_me == FALSE )
- {
- /* Wait until we have recieved a message: */
- Wait( 1 << my_window->UserPort->mp_SigBit );
-
- /* As long as we can collect messages sucessfully we stay in the loop: */
- while( my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort) )
- {
- /* After we have collected the message we can read it, and save any */
- /* important values which we maybe want to check later: */
-
- /* Save the IDCMP flag: */
- class = my_message->Class;
-
- /* Save the address of the sender: */
- address = (CPTR) my_message->IAddress;
-
- /* After we have read it we reply as fast as possible: */
- /* REMEMBER! Do never try to read a message after you have replied! */
- /* Some other process has maybe changed it. */
- ReplyMsg( my_message );
-
- /* Check which IDCMP flag was sent: */
- switch( class )
- {
- case CLOSEWINDOW: /* The user selected the Close window gadget! */
- close_me=TRUE;
- break;
-
- case GADGETDOWN:
- /* The user has selected a String gadget: */
- /* (Clicked inside the select box) */
- printf("A string gadget was selected.\n");
- break;
-
- case GADGETUP:
- /* The user has released a String gadget: */
- /* (Pressed ENTER or RETURN) */
-
- /* If gadget1 was released, activate gadget2, */
- /* if gadget2 was released, activate gadget3, */
- /* and so on... */
- if( address == (CPTR) &gadget1 )
- ActivateGadget( &gadget2, my_window, NULL );
- if( address == (CPTR) &gadget2 )
- ActivateGadget( &gadget3, my_window, NULL );
- if( address == (CPTR) &gadget3 )
- ActivateGadget( &gadget4, my_window, NULL );
- if( address == (CPTR) &gadget4 )
- ActivateGadget( &gadget5, my_window, NULL );
- if( address == (CPTR) &gadget5 )
- ActivateGadget( &gadget6, my_window, NULL );
- if( address == (CPTR) &gadget6 )
- ActivateGadget( &gadget1, my_window, NULL );
-
- break;
- }
- }
- }
-
-
- /* We should always close the windows we have opened before we leave: */
- CloseWindow( my_window );
-
-
- /* Print out the contents of the strings: */
- printf(" Name: %s\n", string_info1.Buffer);
- printf("Address: %s\n", string_info2.Buffer);
- printf(" City: %s\n", string_info3.Buffer);
- printf(" State: %s\n", string_info4.Buffer);
- printf("Country: %s\n", string_info5.Buffer);
- printf(" Phone: %s\n", string_info6.Buffer);
-
-
-
- /* Close the Intuition Library since we have opened it: */
- CloseLibrary( IntuitionBase );
-
- /* THE END */
- }
-