Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************
- * Project: NetButton *
- * Purpose: GUI for RoadShow TCP/IP Stack *
- * File: NetButton.c *
- * Version: 1.0 TEST *
- * Author: Michael Bergmann *
- * Date: 2025/04/04 *
- * *
- * GUI made with ReBuild v1.3 beta *
- * Tested Compilers: *
- * : SAS/C v6.58 *
- * VBCC v0.91 pre *
- * amiga-gcc v6.5 *
- * HINT: Might be linked against *
- * amiga.lib and reaction.lib! *
- *********************************************
- */
- /* --- Put INCLUDE-Files here: --- */
- #include <clib/macros.h>
- #include <clib/alib_protos.h>
- #include <clib/compiler-specific.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/utility.h>
- #include <proto/graphics.h>
- #include <proto/intuition.h>
- #include <proto/gadtools.h>
- #include <proto/icon.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <proto/window.h>
- #include <proto/layout.h>
- #include <proto/button.h>
- #include <proto/string.h>
- #include <proto/label.h>
- #include <proto/requester.h>
- #include <classes/requester.h>
- #include <libraries/gadtools.h>
- #include <reaction/reaction.h>
- #include <intuition/gadgetclass.h>
- #include <intuition/icclass.h>
- #include <reaction/reaction_macros.h>
- #include <classes/window.h>
- #include <exec/memory.h>
- #define myDebug TRUE /* Debugging Texts TRUE or FALSE */
- #ifdef myDebug
- #include <stdio.h> /* used for puts(), printf() */
- char *str_greet = "Hello Stranger!\n We're ready to DEBUG now!\n\n";
- char *str_bye = "\n\nAll Done!\nThis Demo quits now.\n\Hope you liked it?";
- #endif
- /* construct version tag */
- #define PROGNAME "NetButton"
- #define VERSIONR "1.0.0"
- #define COPYRIGHT "Copyright © 2025 by Micha B."
- /* construct version tag */
- #if defined(__VBCC__)
- #define PROGDATE __AMIGADATE__
- #define COMPILER "compiled with VBCC"
- #endif
- #if defined(__SASC)
- #define PROGDATE __AMIGADATE__
- #define COMPILER "compiled with SAS/C v6.58"
- #endif
- #if defined(__GNUC__)
- #define PROGDATE __DATE__
- #define COMPILER "compiled with GNU gcc"
- #endif
- #if defined (_DCC)
- /* AmigaOS Version String */
- #define VERSTAG "\0$VER: NetButton 1.0.0 (6.4.2025) - (compiled with DCC v1.12) - Copyright © 2025 by Micha B."
- char *version = VERSTAG;
- #endif
- #ifndef _DCC
- /* AmigaOS Version String */
- const char *version = "\0$VER: " PROGNAME " " VERSIONR " (" PROGDATE ") - (" COMPILER ") - " COPYRIGHT "\n";
- #endif
- BOOL connected = TRUE;
- /* Function Proto Types */
- int main(void);
- void window_main( void );
- int setup( void );
- void cleanup( void );
- void runWindow( Object *window_object, int window_id, struct Menu *menu_strip, struct Gadget *win_gadgets[] );
- int reqabout(Object *reactionWindow);
- int reqquit(Object *reactionWindow);
- int reqnoroadshow(Object *reactionWindow);
- void checkConnection(struct Window *main_window, struct Gadget *win_gadgets[]);
- struct Screen *gScreen = NULL;
- struct DrawInfo *gDrawInfo = NULL;
- APTR gVisinfo = NULL;
- struct MsgPort *gAppPort = NULL;
- /* --- Menu IDs ----------------------------------------------------------------------------------------- */
- enum menus
- {
- /* Menu "Project" */
- MN_INFO, MN_QUIT
- };
- /* --- Requesters ---------------------------------------------------------------------------------------- */
- /* 'No OS 3.2' box */
- struct EasyStruct warnreq =
- {
- sizeof(struct EasyStruct),
- 0,
- "Error",
- "Needs AmigaOS 3.2.x\n\nNo Chance to run this program on your machine!",
- "Ok"
- };
- /* 'requester.class' box */
- struct EasyStruct noreqclassreq =
- {
- sizeof(struct EasyStruct),
- 0,
- "Critical Error",
- " requester.class could not be opened.\nThis App refuses to start!",
- "Ok"
- };
- int reqabout(Object *reactionWindow)
- {
- Object *reqobj;
- ULONG win;
- int res=0;
- GetAttr(WINDOW_Window, reactionWindow, &win);
- reqobj = NewObject(REQUESTER_GetClass(), NULL, REQ_Type, REQTYPE_INFO, REQ_Image, REQIMAGE_INFO,
- REQ_TitleText, "About NetButton",
- REQ_BodyText," NetButton v1.0\n Interface GUI for RoadShow TCP/IP Stack\n\n (c) Micha B. 04/2025\n Mail: [email protected]\nWeb: www.mbergmann-sh.de",
- REQ_GadgetText, "_Ok",
- TAG_DONE);
- if (reqobj)
- {
- res=DoMethod(reqobj, RM_OPENREQ, NULL, win, NULL);
- DisposeObject(reqobj);
- }
- return res;
- }
- int reqquit(Object *reactionWindow)
- {
- Object *reqobj;
- ULONG win;
- int res=0;
- GetAttr(WINDOW_Window, reactionWindow, &win);
- reqobj = NewObject(REQUESTER_GetClass(), NULL, REQ_Type, REQTYPE_INFO, REQ_Image, REQIMAGE_QUESTION,
- REQ_TitleText, "NetButton Emergency Exit",
- REQ_BodyText," Do you realy want to quit?",
- REQ_GadgetText, "_Yes|_Cancel",
- TAG_DONE);
- if (reqobj)
- {
- res=DoMethod(reqobj, RM_OPENREQ, NULL, win, NULL);
- DisposeObject(reqobj);
- }
- return res;
- }
- int reqnoroadshow(Object *reactionWindow)
- {
- Object *reqobj;
- ULONG win;
- int res=0;
- GetAttr(WINDOW_Window, reactionWindow, &win);
- reqobj = NewObject(REQUESTER_GetClass(), NULL, REQ_Type, REQTYPE_INFO, REQ_Image, REQIMAGE_WARNING,
- REQ_TitleText, "NetButton Warning",
- REQ_BodyText," It looks like you don't have\n the RoadShow TCP/IP Stack\n installed on your System!\n\n NetButton makes no sense.\n Program will quit now!",
- REQ_GadgetText, "_Ok",
- TAG_DONE);
- if (reqobj)
- {
- res=DoMethod(reqobj, RM_OPENREQ, NULL, win, NULL);
- DisposeObject(reqobj);
- }
- return res;
- }
- struct Library *WindowBase = NULL,
- *ButtonBase = NULL,
- *StringBase = NULL,
- *LabelBase = NULL,
- *RequesterBase = NULL,
- *GadToolsBase = NULL,
- *LayoutBase = NULL,
- *IconBase = NULL;
- struct IntuitionBase *IntuitionBase = NULL;
- /* --- window ids ------------------------------------------------------------------------------------- */
- enum win { window_main_id = 4 };
- /* --- Window_Main gadgets ---------------------------------------------------------------------------- */
- /* THESE are for identification by GetAttr() and SetGadgetAttrs() */
- /* e.g. GetAttr(STRINGA_TextVal, (APTR)win_gadgets[string_euro], (ULONG *)&myText); */
- enum window_main_idx { vert_main, vert_buttons, button_on, button_off, string_status };
- /* THOSE are for identification by menu and gadget events */
- /* e.g. case string_eur_id: */
- enum window_main_id { vert_main_id = 6, vert_buttons_id = 7, button_on_id = 8, button_off_id = 10,
- string_status_id = 11 };
- /* --- Function: checkConnection() ----------------------------------------------------------------------- */
- /* --- Check Net status, set Buttons accordingly --------------------------------------------------------- */
- void checkConnection(struct Window *main_window, struct Gadget *win_gadgets[])
- {
- if(connected)
- {
- SetGadgetAttrs((APTR)win_gadgets[button_on], main_window, NULL, GA_Disabled, TRUE, TAG_END);
- SetGadgetAttrs((APTR)win_gadgets[button_off], main_window, NULL, GA_Disabled, FALSE, TAG_END);
- SetGadgetAttrs((APTR)win_gadgets[string_status], main_window, 0, STRINGA_TextVal, "ONLINE", TAG_END );
- }
- else
- {
- SetGadgetAttrs((APTR)win_gadgets[button_on], main_window, NULL, GA_Disabled, FALSE, TAG_END);
- SetGadgetAttrs((APTR)win_gadgets[button_off], main_window, NULL, GA_Disabled, TRUE, TAG_END);
- SetGadgetAttrs((APTR)win_gadgets[string_status], main_window, 0, STRINGA_TextVal, "OFFLINE", TAG_END );
- }
- printf("connected = %ld\n", connected);
- }
- /* --- Function: setup() --------------------------------------------------------------------------------- */
- /* --- Open libs, gadgets, classes and other ressources -------------------------------------------------- */
- int setup( void )
- {
- if( !(IntuitionBase = (struct IntuitionBase*) OpenLibrary("intuition.library",0L)) ) return 0;
- if( !(GadToolsBase = (struct Library*) OpenLibrary("gadtools.library",0L) ) ) return 0;
- if( !(WindowBase = (struct Library*) OpenLibrary("window.class",0L) ) ) return 0;
- if( !(IconBase = (struct Library*) OpenLibrary("icon.library",0L) ) ) return 0;
- /* --- Check for a sufficient OS! --- */
- if( !(LayoutBase = (struct Library*) OpenLibrary("gadgets/layout.gadget",47) ) )
- {
- if (myDebug)
- puts(" FAIL: layout.gadget");
- EasyRequest(NULL, &warnreq, NULL);
- return 0;
- }
- if( !(ButtonBase = (struct Library*) OpenLibrary("gadgets/button.gadget",47L) ) ) return 0;
- if( !(StringBase = (struct Library*) OpenLibrary("gadgets/string.gadget",47L) ) ) return 0;
- if( !(LabelBase = (struct Library*) OpenLibrary("images/label.image",47L) ) ) return 0;
- if( !(RequesterBase = (struct Library*) OpenLibrary("classes/requester.class",47L) ) )
- {
- if(myDebug)
- puts("FAIL: requester.class");
- EasyRequest(NULL, &noreqclassreq, NULL);
- return 0;
- }
- if( !(gScreen = LockPubScreen( 0 ) ) ) return 0;
- if( !(gVisinfo = GetVisualInfo( gScreen, TAG_DONE ) ) ) return 0;
- if( !(gDrawInfo = GetScreenDrawInfo ( gScreen ) ) ) return 0;
- if( !(gAppPort = CreateMsgPort() ) ) return 0;
- return -1;
- } /* END Function setup() */
- /* --- Function: cleanup() -------------------------------------------------------------------------------- */
- /* --- Close used ressources and clean up for shutdown ---------------------------------------------------- */
- void cleanup( void )
- {
- if ( gDrawInfo ) FreeScreenDrawInfo( gScreen, gDrawInfo);
- if ( gVisinfo ) FreeVisualInfo( gVisinfo );
- if ( gAppPort ) DeleteMsgPort( gAppPort );
- if ( gScreen ) UnlockPubScreen( 0, gScreen );
- if (GadToolsBase) CloseLibrary( (struct Library *)GadToolsBase );
- if (IconBase) CloseLibrary( (struct Library *)IconBase );
- if (IntuitionBase) CloseLibrary( (struct Library *)IntuitionBase );
- if (ButtonBase) CloseLibrary( (struct Library *)ButtonBase );
- if (StringBase) CloseLibrary( (struct Library *)StringBase );
- if (LabelBase) CloseLibrary( (struct Library *)LabelBase );
- if (LayoutBase) CloseLibrary( (struct Library *)LayoutBase );
- if (WindowBase) CloseLibrary( (struct Library *)WindowBase );
- if (RequesterBase) CloseLibrary( (struct Library *)RequesterBase );
- } /* END Function cleanup() */
- /* --- Function: runWindow() ------------------------------------------------------------------------------ */
- /* --- IDCMP Event Handling is done here ------------------------------------------------------------------ */
- void runWindow( Object *window_object, int window_id, struct Menu *menu_strip, struct Gadget *win_gadgets[] )
- {
- struct Window *main_window = NULL;
- struct MenuItem *menuitem = NULL;
- LONG myItem = 0; /* GT menu identifier */
- ULONG selected; /* used for Content query */
- ULONG status = 0; /* used for Status query */
- ULONG req_result = 0;
- if ( window_object )
- {
- if ( main_window = (struct Window *) RA_OpenWindow( window_object ))
- {
- WORD Code;
- ULONG wait = 0, signal = 0, result = 0, done = FALSE;
- GetAttr( WINDOW_SigMask, window_object, &signal );
- if ( menu_strip) SetMenuStrip( main_window, menu_strip );
- if(myDebug)
- printf("%s\n", str_greet);
- /* Check initial connection status */
- checkConnection(main_window, win_gadgets);
- while ( !done)
- {
- wait = Wait( signal | SIGBREAKF_CTRL_C );
- if ( wait & SIGBREAKF_CTRL_C )
- done = TRUE;
- else
- while (( result = RA_HandleInput( window_object, &Code )) != WMHI_LASTMSG)
- {
- switch ( result & WMHI_CLASSMASK )
- {
- case WMHI_RAWKEY:
- puts("RAWKEY!");
- checkConnection(main_window, win_gadgets);
- printf("connectet = %ld\n", connected);
- break;
- case WMHI_VANILLAKEY:
- puts("VANILLAKEY!");
- printf("connectet = %ld\n", connected);
- break;
- case WMHI_INTUITICK:
- puts("INTUITICK!");
- break;
- case WMHI_ACTIVE:
- puts("Active!");
- checkConnection(main_window, win_gadgets);
- printf("connectet = %ld\n", connected);
- break;
- /* --- WINDOW -------------------------------------------- */
- case WMHI_CLOSEWINDOW:
- SetAttrs(window_object, WA_BusyPointer, TRUE, TAG_DONE); /* Modal: ON */
- /* call Quit-Requester */
- req_result = reqquit(window_object);
- if(myDebug)
- printf("req_result = %d\n", req_result);
- if (req_result == 1)
- {
- if(myDebug)
- printf("%s\n", str_bye);
- done = TRUE;
- }
- SetAttrs(window_object, WA_BusyPointer, FALSE, TAG_DONE); /* Modal: OFF */
- break;
- /* --- MENUS -------------------------------------------- */
- case WMHI_MENUPICK:
- if(myDebug)
- puts("\nMenu pick!");
- printf("connectet = %ld\n", connected);
- menuitem = ItemAddress(menu_strip, result & WMHI_MENUMASK);
- if(myDebug)
- printf(" ItemAdress = %ld\n", menuitem);
- checkConnection(main_window, win_gadgets);
- printf("connectet = %ld\n", connected);
- /* Check if menuitem equals to Zero. If Zero, an enforcer hit will occour when */
- /* attempting to examine, so we do not allow switching on menuitem == 0! */
- if(!(menuitem == 0))
- {
- checkConnection(main_window, win_gadgets);
- /* --- ...get menu entries by using GadTools' GTMENUITEM_USERDATA field macro --- */
- myItem = ((long)GTMENUITEM_USERDATA(ItemAddress(menu_strip, result & WMHI_MENUMASK)));
- /* --- Identify selected menu entry */
- switch(myItem)
- {
- case MN_INFO:
- if(myDebug)
- puts("\n Menu 'Project': <INFO> was selected.");
- SetAttrs(window_object, WA_BusyPointer, TRUE, TAG_DONE); /* Modal: ON */
- /* call About-Requester */
- req_result = reqabout(window_object);
- checkConnection(main_window, win_gadgets);
- SetAttrs(window_object, WA_BusyPointer, FALSE, TAG_DONE); /* Modal: OFF */
- checkConnection(main_window, win_gadgets);
- break;
- case MN_QUIT:
- if(myDebug)
- puts("\n Menu 'Project': <QUIT> was selected.");
- SetAttrs(window_object, WA_BusyPointer, TRUE, TAG_DONE); /* Modal: ON */
- /* call Quit-Requester */
- req_result = reqquit(window_object);
- if(myDebug)
- printf("req_result = %d\n", req_result);
- if (req_result == 1)
- {
- if(myDebug)
- printf("%s\n", str_bye);
- done = TRUE;
- }
- SetAttrs(window_object, WA_BusyPointer, FALSE, TAG_DONE); /* Modal: OFF */
- checkConnection(main_window, win_gadgets);
- break;
- } /* END switch(myItem) */
- } /* END if(!(menuitem == 0)) */
- break; /* END WMHI_MENUPICK */
- /* --- GADGETS ----------------------------------------- */
- case WMHI_GADGETUP:
- checkConnection(main_window, win_gadgets);
- switch (result & WMHI_GADGETMASK)
- {
- /* --- Gadget 1 --- */
- case button_on_id:
- if(myDebug)
- puts("Button: UP pressed");
- connected = TRUE;
- checkConnection(main_window, win_gadgets);
- break;
- /* --- Gadget 2 --- */
- case button_off_id:
- if(myDebug)
- puts("Button: DOWN pressed");
- connected = FALSE;
- checkConnection(main_window, win_gadgets);
- break;
- } /* END switch (result & WMHI_GADGETMASK) */
- break; /* END case WMHI_GADGETUP */
- /* --- ICONIFY ----------------------------------------- */
- case WMHI_ICONIFY:
- if ( RA_Iconify( window_object ) )
- main_window = NULL;
- break;
- /* --- UNICONIFY --------------------------------------- */
- case WMHI_UNICONIFY:
- main_window = RA_OpenWindow( window_object );
- if ( menu_strip) SetMenuStrip( main_window, menu_strip );
- break;
- } /* END switch ( result & WMHI_CLASSMASK ) */
- } /* END while (( result = RA_HandleInput( window_object, &Code )) != WMHI_LASTMSG) */
- } /* END while ( !done) */
- } /* END if ( main_window = (struct Window *) RA_OpenWindow( window_object )) */
- } /* END if ( window_object ) */
- } /* END Function runWindow() */
- /* --- Function: window_main() ----------------------------------- */
- /* --- All window-specific setup for main Window is done here. --- */
- /* ---'runWindow()' is called for message handling afterwards. --- */
- void window_main( void )
- {
- /* We changed ReBuild's menu struct output in order to obey to GadTools Menu handling! */
- /* Replaced: Last NULL argument by (APTR) <Item identifier> */
- struct NewMenu menuData[] =
- {
- { NM_TITLE, "Project", 0, 0, 0, NULL },
- { NM_ITEM, "Info...", "I", 0, 6, (APTR)MN_INFO },
- { NM_ITEM, NM_BARLABEL, 0, 0, 5, NULL },
- { NM_ITEM, "Quit", "Q", 0, 3, (APTR)MN_QUIT },
- { NM_END, NULL, 0, 0, 0, (APTR)0 }
- };
- struct Menu *menu_strip = NULL;
- struct Gadget *main_gadgets[ 6 ];
- Object *window_object = NULL;
- struct HintInfo hintInfo[] =
- {
- {vert_main_id,-1,"",0},
- {vert_buttons_id,-1,"",0},
- {button_on_id,-1,"Switch Network ON",0},
- {button_off_id,-1,"Switch Network OFF",0},
- {string_status_id,-1,"Show Network Status",0},
- {-1,-1,NULL,0}
- };
- menu_strip = CreateMenusA( menuData, TAG_END );
- LayoutMenus( menu_strip, gVisinfo,
- GTMN_NewLookMenus, TRUE,
- TAG_DONE );
- window_object = WindowObject,
- WA_Title, "RoadShow Control",
- WA_ScreenTitle, "NetButton RoadShow Control v1.0",
- WA_Left, 5,
- WA_Top, 20,
- WA_Width, 150,
- WA_Height, 20,
- WA_MinWidth, 150,
- WA_MinHeight, 20,
- WA_MaxWidth, 8192,
- WA_MaxHeight, 8192,
- WINDOW_LockHeight, TRUE,
- WINDOW_IconifyGadget, TRUE,
- WINDOW_HintInfo, hintInfo,
- WINDOW_GadgetHelp, TRUE,
- WINDOW_AppPort, gAppPort,
- WINDOW_IconifyGadget, TRUE,
- WA_CloseGadget, TRUE,
- WA_DepthGadget, TRUE,
- WA_SizeGadget, TRUE,
- WA_DragBar, TRUE,
- WA_Activate, TRUE,
- WINDOW_Position, WPOS_TOPLEFT,
- WINDOW_IconTitle, "NetButton",
- WINDOW_Icon, GetDiskObject("NetButton"),
- WA_NoCareRefresh, TRUE,
- WA_IDCMP, IDCMP_GADGETDOWN | IDCMP_GADGETUP | IDCMP_CLOSEWINDOW | IDCMP_MENUPICK |
- IDCMP_NEWSIZE | IDCMP_REFRESHWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_INTUITICKS | IDCMP_IDCMPUPDATE,
- WINDOW_ParentGroup, VLayoutObject,
- LAYOUT_SpaceOuter, TRUE,
- LAYOUT_DeferLayout, TRUE,
- LAYOUT_AddChild, main_gadgets[vert_main] = LayoutObject,
- GA_ID, vert_main_id,
- LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
- LAYOUT_AddChild, main_gadgets[vert_buttons] = LayoutObject,
- GA_ID, vert_buttons_id,
- LAYOUT_Orientation, LAYOUT_ORIENT_VERT,
- LAYOUT_SpaceOuter, TRUE,
- LAYOUT_FixedVert, FALSE,
- LAYOUT_EvenSize, TRUE,
- LAYOUT_DeferLayout, TRUE,
- LAYOUT_AddChild, main_gadgets[button_on] = ButtonObject,
- GA_ID, button_on_id,
- GA_Text, "Go ONLINE",
- GA_RelVerify, TRUE,
- GA_TabCycle, TRUE,
- GA_Disabled, TRUE,
- BUTTON_TextPen, 1,
- BUTTON_BackgroundPen, 0,
- BUTTON_FillTextPen, 1,
- BUTTON_FillPen, 3,
- ButtonEnd,
- LAYOUT_AddChild, main_gadgets[button_off] = ButtonObject,
- GA_ID, button_off_id,
- GA_Text, "Go OFFLINE",
- GA_RelVerify, TRUE,
- GA_TabCycle, TRUE,
- GA_Disabled, FALSE,
- BUTTON_TextPen, 1,
- BUTTON_BackgroundPen, 0,
- BUTTON_FillTextPen, 1,
- BUTTON_FillPen, 3,
- ButtonEnd,
- LAYOUT_AddChild, main_gadgets[string_status] = StringObject,
- GA_ID, string_status_id,
- GA_RelVerify, TRUE,
- GA_TabCycle, TRUE,
- GA_ReadOnly, TRUE,
- STRINGA_TextVal, "ONLINE",
- STRINGA_MaxChars, 80,
- STRINGA_Justification, GACT_STRINGCENTER,
- StringEnd,
- CHILD_Label, LabelObject,
- LABEL_Text, "Status:",
- LabelEnd,
- LayoutEnd,
- LayoutEnd,
- LayoutEnd,
- WindowEnd;
- main_gadgets[5] = 0;
- runWindow( window_object, window_main_id, menu_strip, main_gadgets );
- if ( window_object ) DisposeObject( window_object );
- if ( menu_strip ) FreeMenus( menu_strip );
- } /* END Function window_main() */
- /* --- Main Function ---------------------------------------------------------------------------------- */
- int main(void)
- {
- if ( setup() ) /* This will satisfy all needs... */
- {
- window_main(); /* ...and open Application's main Window + implement Event handling by running 'runWindow()' */
- }
- cleanup(); /* Clean up stuff and exit */
- } /* END main() */
Advertisement
Add Comment
Please, Sign In to add comment