home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / util / misc / UserTool1_0.lha / UserTool / Source / UserTool.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-20  |  8.7 KB  |  302 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Michael D. Bayne
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include "UserTool.h"
  24.  
  25. struct Screen         *Scr = NULL;
  26. UBYTE                 *PubScreenName = NULL;
  27. APTR                   VisualInfo = NULL;
  28. struct Window         *UserToolWnd = NULL;
  29. struct Gadget         *UserToolGList = NULL;
  30. struct Menu           *UserToolMenus = NULL;
  31. struct IntuiMessage    UserToolMsg;
  32. struct Gadget         *UserToolGadgets[14];
  33. UWORD                  UserToolLeft = 164;
  34. UWORD                  UserToolTop = 18;
  35. UWORD                  UserToolWidth = 395;
  36. UWORD                  UserToolHeight = 179;
  37. UBYTE                 *UserToolWdt = (UBYTE *)"UserTool";
  38. struct TextAttr       *Font, Attr;
  39. UWORD                  FontX, FontY;
  40. UWORD                  OffX, OffY;
  41.  
  42. UBYTE *MEMBER0Labels[] = {
  43.     (UBYTE *)"N_on-Member",
  44.     (UBYTE *)"_Member",
  45.     (UBYTE *)"M_anager",
  46.     NULL };
  47.  
  48. struct NewMenu UserToolNewMenu[] = {
  49.     NM_TITLE, (STRPTR)"Project", NULL, 0, NULL, NULL,
  50.     NM_ITEM, (STRPTR)"Save", (STRPTR)"S", 0, 0L, (APTR)UserToolSAVE,
  51.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  52.     NM_ITEM, (STRPTR)"About", (STRPTR)"?", 0, 0L, (APTR)UserToolABOUT,
  53.     NM_ITEM, (STRPTR)NM_BARLABEL, NULL, 0, 0L, NULL,
  54.     NM_ITEM, (STRPTR)"Quit", (STRPTR)"Q", 0, 0L, (APTR)UserToolQUIT,
  55.     NM_END, NULL, NULL, 0, 0L, NULL };
  56.  
  57. UWORD UserToolGTypes[] = {
  58.     BUTTON_KIND,
  59.     BUTTON_KIND,
  60.     BUTTON_KIND,
  61.     BUTTON_KIND,
  62.     BUTTON_KIND,
  63.     STRING_KIND,
  64.     LISTVIEW_KIND,
  65.     INTEGER_KIND,
  66.     STRING_KIND,
  67.     STRING_KIND,
  68.     STRING_KIND,
  69.     STRING_KIND,
  70.     LISTVIEW_KIND,
  71.     MX_KIND
  72. };
  73.  
  74. struct NewGadget UserToolNGad[] = {
  75.     281, 69, 107, 13, (UBYTE *)"_Change Password", NULL, GD_CHANGEPASS, PLACETEXT_IN, NULL, (APTR)CHANGEPASSClicked,
  76.     8, 163, 81, 12, (UBYTE *)"_New", NULL, GD_NEW, PLACETEXT_IN, NULL, (APTR)NEWClicked,
  77.     91, 163, 81, 12, (UBYTE *)"_Delete", NULL, GD_DELETE, PLACETEXT_IN, NULL, (APTR)DELETEClicked,
  78.     184, 163, 101, 12, (UBYTE *)"N_ew", NULL, GD_NEWGROUP, PLACETEXT_IN, NULL, (APTR)NEWGROUPClicked,
  79.     287, 163, 101, 12, (UBYTE *)"De_lete", NULL, GD_DELETEGROUP, PLACETEXT_IN, NULL, (APTR)DELETEGROUPClicked,
  80.     8, 21, 164, 13, NULL, NULL, GD_USERSSTR, 0, NULL, (APTR)USERSSTRClicked,
  81.     8, 18, 164, 144, (UBYTE *)"_Users", NULL, GD_USERS, PLACETEXT_ABOVE|NG_HIGHLABEL, NULL, (APTR)USERSClicked,
  82.     272, 5, 116, 13, (UBYTE *)"User _ID", NULL, GD_USERID, PLACETEXT_LEFT, NULL, (APTR)USERIDClicked,
  83.     272, 21, 116, 13, (UBYTE *)"_Home directory", NULL, GD_HOMEDIR, PLACETEXT_LEFT, NULL, (APTR)HOMEDIRClicked,
  84.     272, 37, 116, 13, (UBYTE *)"_Real Name", NULL, GD_REALNAME, PLACETEXT_LEFT, NULL, (APTR)REALNAMEClicked,
  85.     314, 53, 74, 13, (UBYTE *)"_Port", NULL, GD_PORT, PLACETEXT_LEFT, NULL, (APTR)PORTClicked,
  86.     184, 66, 204, 13, NULL, NULL, GD_GROUPSTR, 0, NULL, (APTR)GROUPSTRClicked,
  87.     184, 99, 204, 63, (UBYTE *)"_Groups", NULL, GD_GROUPS, PLACETEXT_ABOVE|NG_HIGHLABEL, NULL, (APTR)GROUPSClicked,
  88.     252, 52, 17, 9, NULL, NULL, GD_MEMBER, PLACETEXT_LEFT, NULL, (APTR)MEMBERClicked
  89. };
  90.  
  91. ULONG UserToolGTags[] = {
  92.     (GT_Underscore), '_', (TAG_DONE),
  93.     (GT_Underscore), '_', (TAG_DONE),
  94.     (GT_Underscore), '_', (TAG_DONE),
  95.     (GT_Underscore), '_', (TAG_DONE),
  96.     (GT_Underscore), '_', (TAG_DONE),
  97.     (GTST_MaxChars), 256, (TAG_DONE),
  98.     (GTLV_ShowSelected), 1L, (GT_Underscore), '_', (TAG_DONE),
  99.     (GTIN_Number), 0, (GTIN_MaxChars), 10, (GT_Underscore), '_', (TAG_DONE),
  100.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE),
  101.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE),
  102.     (GTST_MaxChars), 256, (GT_Underscore), '_', (TAG_DONE),
  103.     (GTST_MaxChars), 256, (TAG_DONE),
  104.     (GTLV_ShowSelected), 1L, (GT_Underscore), '_', (TAG_DONE),
  105.     (GTMX_Labels), (ULONG)&MEMBER0Labels[ 0 ], (GT_Underscore), '_', (TAG_DONE)
  106. };
  107.  
  108. static UWORD ComputeX( UWORD value )
  109. {
  110.     return(( UWORD )((( FontX * value ) + 3 ) / 6 ));
  111. }
  112.  
  113. static UWORD ComputeY( UWORD value )
  114. {
  115.     return(( UWORD )((( FontY * value ) + 4 ) / 9 ));
  116. }
  117.  
  118. static void ComputeFont( UWORD width, UWORD height )
  119. {
  120.     Font = &Attr;
  121.     Font->ta_Name = (STRPTR)Scr->RastPort.Font->tf_Message.mn_Node.ln_Name;
  122.     Font->ta_YSize = FontY = Scr->RastPort.Font->tf_YSize;
  123.     FontX = Scr->RastPort.Font->tf_XSize;
  124.  
  125.     OffX = Scr->WBorLeft;
  126.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  127.  
  128.     if ( width && height ) {
  129.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  130.             goto UseTopaz;
  131.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  132.             goto UseTopaz;
  133.     }
  134.     return;
  135.  
  136. UseTopaz:
  137.     Font->ta_Name = (STRPTR)"topaz.font";
  138.     FontX = FontY = Font->ta_YSize = 8;
  139. }
  140.  
  141. int SetupScreen( void )
  142. {
  143.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  144.         return( 1L );
  145.  
  146.     ComputeFont( 0, 0 );
  147.  
  148.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  149.         return( 2L );
  150.  
  151.     return( 0L );
  152. }
  153.  
  154. void CloseDownScreen( void )
  155. {
  156.     if ( VisualInfo ) {
  157.         FreeVisualInfo( VisualInfo );
  158.         VisualInfo = NULL;
  159.     }
  160.  
  161.     if ( Scr        ) {
  162.         UnlockPubScreen( NULL, Scr );
  163.         Scr = NULL;
  164.     }
  165. }
  166.  
  167. int HandleUserToolIDCMP( void )
  168. {
  169.     struct IntuiMessage    *m;
  170.     struct MenuItem        *n;
  171.     int            (*func)();
  172.     BOOL            running = TRUE;
  173.  
  174.     while( m = GT_GetIMsg( UserToolWnd->UserPort )) {
  175.  
  176.         CopyMem(( char * )m, ( char * )&UserToolMsg, (long)sizeof( struct IntuiMessage ));
  177.  
  178.         GT_ReplyIMsg( m );
  179.  
  180.         switch ( UserToolMsg.Class ) {
  181.  
  182.             case    IDCMP_REFRESHWINDOW:
  183.                 GT_BeginRefresh( UserToolWnd );
  184.                 GT_EndRefresh( UserToolWnd, TRUE );
  185.                 break;
  186.  
  187.             case    IDCMP_CLOSEWINDOW:
  188.                 running = UserToolCloseWindow();
  189.                 break;
  190.  
  191.             case    IDCMP_VANILLAKEY:
  192.                 running = UserToolVanillaKey();
  193.                 break;
  194.  
  195.             case    IDCMP_GADGETUP:
  196.             case    IDCMP_GADGETDOWN:
  197.                 func = ( void * )(( struct Gadget * )UserToolMsg.IAddress )->UserData;
  198.                 running = func();
  199.                 break;
  200.  
  201.             case    IDCMP_MENUPICK:
  202.                 while( UserToolMsg.Code != MENUNULL ) {
  203.                     n = ItemAddress( UserToolMenus, UserToolMsg.Code );
  204.                     func = (void *)(GTMENUITEM_USERDATA( n ));
  205.                     running = func();
  206.                     UserToolMsg.Code = n->NextSelect;
  207.                 }
  208.                 break;
  209.         }
  210.     }
  211.     return( running );
  212. }
  213.  
  214. int OpenUserToolWindow( void )
  215. {
  216.     struct NewGadget    ng;
  217.     struct Gadget    *g;
  218.     struct TagItem    *tmp;
  219.     UWORD        lc, tc;
  220.     UWORD        wleft = UserToolLeft, wtop = UserToolTop, ww, wh;
  221.  
  222.     ComputeFont( UserToolWidth, UserToolHeight );
  223.  
  224.     ww = ComputeX( UserToolWidth );
  225.     wh = ComputeY( UserToolHeight );
  226.  
  227.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  228.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  229.  
  230.     if ( ! ( g = CreateContext( &UserToolGList )))
  231.         return( 1L );
  232.  
  233.     for( lc = 0, tc = 0; lc < UserTool_CNT; lc++ ) {
  234.  
  235.         CopyMem((char * )&UserToolNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  236.  
  237.         ng.ng_VisualInfo = VisualInfo;
  238.         ng.ng_TextAttr   = Font;
  239.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  240.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  241.         ng.ng_Width      = ComputeX( ng.ng_Width );
  242.         ng.ng_Height     = ComputeY( ng.ng_Height);
  243.  
  244.         if ( UserToolGTypes[ lc ] == LISTVIEW_KIND ) {
  245.             if ( tmp = FindTagItem( GTLV_ShowSelected, ( struct TagItem * )&UserToolGTags[ tc ] )) {
  246.                 if ( tmp->ti_Data ) tmp->ti_Data = (ULONG)g;
  247.             }
  248.         }
  249.  
  250.         UserToolGadgets[ lc ] = g = CreateGadgetA((ULONG)UserToolGTypes[ lc ], g, &ng, ( struct TagItem * )&UserToolGTags[ tc ] );
  251.  
  252.         while( UserToolGTags[ tc ] ) tc += 2;
  253.         tc++;
  254.  
  255.         if ( NOT g )
  256.             return( 2L );
  257.     }
  258.  
  259.     if ( ! ( UserToolMenus = CreateMenus( UserToolNewMenu, GTMN_FrontPen, 0L, TAG_DONE )))
  260.         return( 3L );
  261.  
  262.     LayoutMenus( UserToolMenus, VisualInfo, TAG_DONE );
  263.  
  264.     if ( ! ( UserToolWnd = OpenWindowTags( NULL,
  265.                 WA_Left,    wleft,
  266.                 WA_Top,        wtop,
  267.                 WA_Width,    ww + OffX + Scr->WBorRight,
  268.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  269.                 WA_IDCMP,    BUTTONIDCMP|STRINGIDCMP|LISTVIEWIDCMP|INTEGERIDCMP|MXIDCMP|IDCMP_MENUPICK|IDCMP_CLOSEWINDOW|IDCMP_VANILLAKEY|IDCMP_REFRESHWINDOW,
  270.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SIZEBBOTTOM|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  271.                 WA_Gadgets,    UserToolGList,
  272.                 WA_Title,    UserToolWdt,
  273.                 WA_ScreenTitle,    "UserTool by Michael D. Bayne",
  274.                 WA_PubScreen,    Scr,
  275.                 TAG_DONE )))
  276.     return( 4L );
  277.  
  278.     SetMenuStrip( UserToolWnd, UserToolMenus );
  279.     GT_RefreshWindow( UserToolWnd, NULL );
  280.  
  281.     return( 0L );
  282. }
  283.  
  284. void CloseUserToolWindow( void )
  285. {
  286.     if ( UserToolMenus      ) {
  287.         ClearMenuStrip( UserToolWnd );
  288.         FreeMenus( UserToolMenus );
  289.         UserToolMenus = NULL;    }
  290.  
  291.     if ( UserToolWnd        ) {
  292.         CloseWindow( UserToolWnd );
  293.         UserToolWnd = NULL;
  294.     }
  295.  
  296.     if ( UserToolGList      ) {
  297.         FreeGadgets( UserToolGList );
  298.         UserToolGList = NULL;
  299.     }
  300. }
  301.  
  302.