home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / DC-POS24.LZX / pOS / pOS_RKRM.lzx / pOS_RKRM / pIntui / WinMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-18  |  7.8 KB  |  267 lines

  1.  
  2. /*******************************************************************
  3.  $CRT 17 Jul 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>WinMenu.c<<   29 Jan 1997    13:25:24 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/Ex/WinMenu p:pLib/StartCode.o p:/pOS_RKRM/pIntui/WinMenu.c p:pLib/StdIO.o -l pOSStub -l pOS
  10.  
  11. /***********************************************************
  12.   pOS programing example - Copyright (C) 1995-97 proDAD
  13.  
  14.   This code was written as an easy to understand example,
  15.   how to program pOS features. It is provided 'as-is',
  16.   without any express or implied warranty.
  17.  
  18.   Permission is hereby granted to use, copy and modify
  19.   this source code for any purpose, without fee, subject
  20.   to the following conditions:
  21.  
  22.     (1) This notice may not be removed or altered from any
  23.         source distribution.
  24.  
  25.     (2) Altered source versions must be plainly marked as
  26.         such, and must not be misrepresented as being
  27.         the original source code.
  28.  
  29.     (3) If only executable code is distributed, then the
  30.         accompanying documentation have to state that
  31.         "this software is based in part on examples of
  32.         the pOS developer packet".
  33.  
  34.     (4) Permission for use of this code is granted only
  35.         if the user accepts full responsibility for any
  36.         undesirable consequences. proDAD accept NO LIABILITY
  37.         for damages of any kind.
  38.  
  39.   ©proDAD
  40. ***********************************************************/
  41.  
  42. /*\
  43. *** Example:
  44. ***
  45. \*/
  46.  
  47.  
  48. #define __COMPUTER_AMIGA 1
  49. #define NOMYDEBUG
  50.  
  51. #include "p:pExec/Types.h"
  52. #include "p:pDOS/ArgTags.h"
  53. #include "p:pDOS/DosSig.h"
  54. #include "p:pDOS/DosErrors.h"
  55. #include "p:pGadget/Gadget.h"
  56. #include "p:pScreen/ScrTags.h"
  57. #include "p:pScreen/Window.h"
  58. #include "p:pScreen/Screen.h"
  59. #include "p:pIntui/IntuMsg.h"
  60. #include "p:pIntui/Tags.h"
  61. #include "p:pIntui/FraClass.h"
  62. #include "p:pIntui/Menu.h"
  63. #include "p:proto/pLibExt.h"
  64. #include "p:proto/pExec2.h"
  65. #include "p:proto/pDOS2.h"
  66. #include "p:proto/pIntui2.h"
  67.  
  68. #ifdef _____ME_____
  69.   #include "grund/inc_string.h"
  70.   #include "grund/inc_stdio.h"
  71. #else
  72.  #ifdef __cplusplus
  73.  extern "C" {
  74.  #endif
  75.   #include <string.h>
  76.   #include <stdio.h>
  77.  #ifdef __cplusplus
  78.  }
  79.  #endif
  80. #endif
  81.  
  82.  
  83. const CHAR *HelpText=
  84. ""
  85. ;
  86.  
  87. const CHAR *PrgHeader=
  88. "";
  89.  
  90. const CHAR *PrgVerText=
  91. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  92.  
  93.  
  94. struct pOS_IntuiDevice *gb_IntuiBase;
  95.  
  96. /*----------------------------------
  97. -----------------------------------*/
  98. #ifdef __cplusplus
  99. extern "C"
  100. #endif
  101.  
  102. VOID main()
  103. {
  104.   struct pOS_DosArgs* Args;
  105.   UWORD Err=0;
  106.   ULONG Ops[2]={0,0};
  107.  
  108.   gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  109.  
  110.  
  111.   Args=pOS_ReadDosArgs(
  112. // 0         1
  113. "",
  114. Ops,sizeof(Ops)/sizeof(ULONG),
  115.  
  116.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  117.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  118.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  119.     TAG_END);
  120.  
  121.   if(Args) {
  122.     struct pOS_Window *Win;
  123.     struct pOS_Gadget *Gad,*TextGad;
  124.     struct pOS_Screen *Scr;
  125.  
  126.     if(Scr=pOS_LockPubScreen("Workbench")) {
  127.       struct pOS_MenuList *MenuList;
  128.       static struct pOS_MenuTag gb_Menu[14];
  129.       const struct pOS_DrawInfo *const Dri=Scr->scr_DrawInfo;
  130.  
  131.       TextGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GTxtBoxClass],0,
  132.          ICLTAG_DrawInfo,      (ULONG)Scr->scr_DrawInfo,
  133.          IOBJTAG_StaticString, (ULONG)"*** Window-Menu-Demo *** \nPress right mouse",
  134.          ICLTAG_AddWidth,      20,
  135.          ICLTAG_AddHeight,     10,
  136.          TAG_DONE);
  137.  
  138.       Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
  139.         ICLTAG_AutoDelete,    TRUE,
  140.         GRPGADTAG_BorLeft,    10,
  141.         GRPGADTAG_BorTop,     10,
  142.         GRPGADTAG_BorRight,   10,
  143.         GRPGADTAG_BorBottom,  10,
  144.         GRPGADTAG_AddGadget,(ULONG)TextGad,
  145.         TAG_DONE);
  146.  
  147.  
  148.       gb_Menu[0].mt_Type=MENUTAGTYP_Title;
  149.       gb_Menu[0].mt_U.mt_Lable="gTitle";
  150.       gb_Menu[1].mt_Type=MENUTAGTYP_Item;
  151.       gb_Menu[1].mt_U.mt_Lable="g_Item11";
  152.       gb_Menu[2].mt_Type=MENUTAGTYP_Item;
  153.       gb_Menu[2].mt_U.mt_Lable="gItem12";
  154.       gb_Menu[2].mt_Flags=MENUITF_Disabled;
  155.       gb_Menu[3].mt_Type=MENUTAGTYP_Sub;
  156.       gb_Menu[3].mt_U.mt_Lable="gSub11";
  157.       gb_Menu[4].mt_Type=MENUTAGTYP_Sub;
  158.       gb_Menu[4].mt_U.mt_Lable="gSub12";
  159.       gb_Menu[5].mt_Type=MENUTAGTYP_Item;
  160.       gb_Menu[5].mt_U.mt_Lable="gItem13";
  161.  
  162. // -----------------------------------------------------------
  163.       gb_Menu[6].mt_Type=MENUTAGTYP_Title;
  164.       gb_Menu[6].mt_U.mt_Lable="Mutual-Excl.";
  165.  
  166.       gb_Menu[7].mt_Type=MENUTAGTYP_Item;
  167.       gb_Menu[7].mt_U.mt_Lable="Plain";
  168.       gb_Menu[7].mt_Flags=MENUITF_Hook | MENUITF_IsChecked;
  169.       gb_Menu[7].mt_MutualExclude=0xfffe;
  170.  
  171.       gb_Menu[8].mt_Type=MENUTAGTYP_Item;
  172.       gb_Menu[8].mt_U.mt_Lable="Bold";
  173.       gb_Menu[8].mt_Flags=MENUITF_Hook | MENUITF_Toggle;
  174.       gb_Menu[8].mt_MutualExclude=0x0001;
  175.  
  176.       gb_Menu[9].mt_Type=MENUTAGTYP_Item;
  177.       gb_Menu[9].mt_U.mt_Lable="Italic";
  178.       gb_Menu[9].mt_Flags=MENUITF_Hook;
  179.       gb_Menu[9].mt_MutualExclude=0x0001;
  180.  
  181.       gb_Menu[10].mt_Type=MENUTAGTYP_Item;
  182.       gb_Menu[10].mt_U.mt_Lable="Underline";
  183.       gb_Menu[10].mt_Flags=MENUITF_Hook;
  184.       gb_Menu[10].mt_MutualExclude=0x0001;
  185.  
  186. // -----------------------------------------------------------
  187.  
  188.       gb_Menu[11].mt_Type=MENUTAGTYP_End;
  189.  
  190.  
  191.  
  192.       if(MenuList=pOS_CreateMenuTagA(Scr->scr_DrawInfo,gb_Menu,0)) {
  193.         pOS_PreLayoutMenu(MenuList,Scr->scr_DrawInfo);
  194.  
  195.         Win=pOS_OpenWindow(
  196.             SCRTAG_Title,   (ULONG)"<-- Close",
  197.             SCRTAG_PubName, (ULONG)"Workbench",
  198.             SCRTAG_Flags,   WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
  199.                             WINFLGF_Activate | WINFLGF_CloseGadget | WINFLGF_Dragbar,
  200.             SCRTAG_IDCMP,   IDCMP_CloseWindow | IDCMP_MenuPick,
  201.             SCRTAG_AutoSizeGadget, (ULONG)Gad,
  202.             TAG_DONE);
  203.  
  204.         if(Win) {
  205.           struct pOS_IntuiMessage *Msg;
  206.           BOOL Ende=FALSE;
  207.           const UWORD MWidth =Win->win_Width;
  208.           const UWORD MHeight=Win->win_Height;
  209.  
  210.           pOS_SetMenuStrip(Win,MenuList);
  211.  
  212.           while(!Ende) {
  213.             pOS_WaitPort(Win->win_UserPort);
  214.             while(Msg=(struct pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
  215.               switch(Msg->im_Class) {
  216.  
  217.                 case IDCMP_MenuPick:
  218.                   {
  219.                     struct pOS_MenuNum*  MN=(pOS_MenuNum*)&Msg->im_Code;
  220.                     struct pOS_MenuNum   MN2;
  221.                     SLONG Res;
  222.  
  223.                     printf("IDCMP_MenuPick: Title=%ld Item=%ld Sub=%ld\n",
  224.                            MN->men_U.men_Pck[MENNUPCK_Title],
  225.                            MN->men_U.men_Pck[MENNUPCK_Item],
  226.                            MN->men_U.men_Pck[MENNUPCK_Sub]);
  227.  
  228.  
  229.                     MN2.men_U.men_Pck[MENNUPCK_Title]=1;
  230.                     MN2.men_U.men_Pck[MENNUPCK_Item] =0;
  231.                     MN2.men_U.men_Pck[MENNUPCK_Sub]  =-1;
  232.  
  233.                     Res=pOS_GetWindowMenuChecker(Win,&MN2);
  234.                     if(Res!=-1) {
  235.                       printf(" Status: Plain-Checker=%ld\n",Res);
  236.                     }
  237.                   }
  238.                   break;
  239.  
  240.                 case IDCMP_CloseWindow:  Ende=TRUE; break;
  241.                 default: if(pOS_SysIMessage(Msg)) Msg=NULL;
  242.               }
  243.               if(Msg) pOS_ReplyMsg(&Msg->im_Message);
  244.             }
  245.           }
  246.           pOS_SetMenuStrip(Win,NULL);
  247.           pOS_CloseWindow(Win);
  248.         }
  249.         else printf("Cannot open window\n");
  250.         pOS_DeleteMenu(MenuList);
  251.       }
  252.       else printf("Error in pOS_CreateMenuTagA\n");
  253.  
  254.       pOS_UnlockPubScreen(Scr);
  255.     }
  256.     else printf("Cannot lock PubScreen\n");
  257.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  258.   }
  259.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  260.  
  261.   pOS_SetShellFail(Err);
  262.  
  263.   pOS_CloseLibrary((struct pOS_Library*)gb_IntuiBase);
  264. }
  265.  
  266.  
  267.