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

  1.  
  2. /*******************************************************************
  3.  $CRT 02 Nov 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>WinMenu2.c<<   29 Jan 1997    13:25:38 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/Ex/WinMenu2 p:pLib/StartCode.o p:/pOS_RKRM/pIntui/WinMenu2.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. static CHAR *gb_Names[]=
  98. {
  99.   "env:sysgfx/prodad.anim"
  100. };
  101.  
  102.  
  103. /*----------------------------------
  104. -----------------------------------*/
  105. #ifdef __cplusplus
  106. extern "C"
  107. #endif
  108.  
  109. VOID main()
  110. {
  111.   struct pOS_DosArgs* Args;
  112.   UWORD Err=0;
  113.   ULONG Ops[1]={0};
  114.  
  115.   gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  116.  
  117.  
  118.   Args=pOS_ReadDosArgs(
  119. // 0         1
  120. "NAME/M",
  121. Ops,sizeof(Ops)/sizeof(ULONG),
  122.  
  123.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  124.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  125.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  126.     TAG_END);
  127.  
  128.   if(Args) {
  129.     struct pOS_Window *Win;
  130.     struct pOS_Gadget *Gad,*TextGad;
  131.     struct pOS_Screen *Scr;
  132.     CHAR** Names=(CHAR**)Ops[0];
  133.     UWORD NumNames=0;
  134.  
  135.     if(Names) for(; Names[NumNames]!=NULL; ++NumNames);
  136.     if(NumNames==0) {
  137.       Names=gb_Names;
  138.       NumNames=1;
  139.     }
  140.  
  141.     if(Scr=pOS_LockPubScreen("Workbench")) {
  142.       struct pOS_MenuList *MenuList;
  143.       static struct pOS_MenuTag gb_Menu[20];
  144.       const struct pOS_DrawInfo *const Dri=Scr->scr_DrawInfo;
  145.       struct pOS_TagItem *TagArray;
  146. /******
  147.  pOS_TagItem Tags2[]={
  148.    ICLTAG_DrawInfo, (ULONG)Scr->scr_DrawInfo,     // 0
  149.    IOGFXTAG_FileName,        (ULONG)Names[],      // 1
  150.    TAG_DONE                                       // 2
  151.  };
  152.  pOS_TagItem BTags2[]={
  153.    ICLTAG_RenderClassName, (ULONG)"igfx.class",   // 3
  154.    ICLTAG_RenderTags,      (ULONG)Tags2,          // 4
  155.    TAG_DONE                                       // 5
  156.  };
  157. ******/
  158.  
  159.       memset(gb_Menu,0,sizeof(gb_Menu));
  160.  
  161.       TagArray=(struct pOS_TagItem*)pOS_AllocVec(sizeof(struct pOS_TagItem)*6*NumNames,MEMF_CLEAR);
  162.       if(TagArray) {
  163.         UWORD i;
  164.         struct pOS_TagItem* Tag;
  165.  
  166.         for(i=0,Tag=TagArray; i<NumNames; ++i, Tag+=6) {
  167.           Tag[0].ti_Tag=ICLTAG_DrawInfo;        Tag[0].ti_Data=(ULONG)Scr->scr_DrawInfo;
  168.           Tag[1].ti_Tag=IOGFXTAG_FileName;      Tag[1].ti_Data=(ULONG)Names[i];
  169.           Tag[2].ti_Tag=TAG_END;
  170.           Tag[3].ti_Tag=ICLTAG_RenderClassName; Tag[3].ti_Data=(ULONG)"igfx.class";
  171.           Tag[4].ti_Tag=ICLTAG_RenderTags;      Tag[4].ti_Data=(ULONG)&Tag[0];
  172.           Tag[5].ti_Tag=TAG_END;
  173.  
  174.           gb_Menu[5+i].mt_Type=MENUTAGTYP_Item;
  175.           gb_Menu[5+i].mt_Tags=&Tag[3];
  176.         }
  177.       }
  178.       else printf("Cannot alloc TagArray\n");
  179.  
  180.       TextGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GTxtBoxClass],0,
  181.          ICLTAG_DrawInfo,      (ULONG)Scr->scr_DrawInfo,
  182.          IOBJTAG_StaticString, (ULONG)"*** Window-Menu-Demo-2 *** \nPress right mouse",
  183.          ICLTAG_AddWidth,      20,
  184.          ICLTAG_AddHeight,     10,
  185.          TAG_DONE);
  186.  
  187.       Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
  188.         ICLTAG_AutoDelete,    TRUE,
  189.         GRPGADTAG_BorLeft,    10,
  190.         GRPGADTAG_BorTop,     10,
  191.         GRPGADTAG_BorRight,   10,
  192.         GRPGADTAG_BorBottom,  10,
  193.         GRPGADTAG_AddGadget,(ULONG)TextGad,
  194.         TAG_DONE);
  195.  
  196.  
  197.       gb_Menu[0].mt_Type=MENUTAGTYP_Title;
  198.       gb_Menu[0].mt_U.mt_Lable="gTitle";
  199.       gb_Menu[1].mt_Type=MENUTAGTYP_Item;
  200.       gb_Menu[1].mt_U.mt_Lable="Item - 1";
  201.  
  202.       struct pOS_TagItem Tags1[]={
  203.         ICLTAG_Width,    40,
  204.         ICLTAG_Height,   40,
  205.         ICLTAG_DrawInfo, (ULONG)Scr->scr_DrawInfo,
  206.         ICLTAG_FrameType, IFRACLTYP_SysWDepth,
  207.         TAG_DONE
  208.       };
  209.       struct pOS_TagItem BTags1[]={
  210.         ICLTAG_RenderClassName, (ULONG)"iimage.class",
  211.         ICLTAG_RenderTags,      (ULONG)Tags1,
  212.         TAG_DONE
  213.       };
  214.       gb_Menu[2].mt_Type=MENUTAGTYP_Item;
  215.       gb_Menu[2].mt_Tags=BTags1;
  216.  
  217.       gb_Menu[3].mt_Type=MENUTAGTYP_Item;
  218.       gb_Menu[3].mt_U.mt_Lable="Item - 2";
  219.  
  220.       gb_Menu[4].mt_Type=MENUTAGTYP_Title;
  221.       gb_Menu[4].mt_U.mt_Lable="GFX";
  222.  
  223.  
  224.       printf("Create Menus ...\n");
  225.       if(MenuList=pOS_CreateMenuTagA(Scr->scr_DrawInfo,gb_Menu,0)) {
  226.         pOS_PreLayoutMenu(MenuList,Scr->scr_DrawInfo);
  227.  
  228.         Win=pOS_OpenWindow(
  229.             SCRTAG_Title,   (ULONG)"<-- Close",
  230.             SCRTAG_PubName, (ULONG)"Workbench",
  231.             SCRTAG_Flags,   WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
  232.                             WINFLGF_Activate | WINFLGF_CloseGadget | WINFLGF_Dragbar,
  233.             SCRTAG_IDCMP,   IDCMP_CloseWindow | IDCMP_MenuPick,
  234.             SCRTAG_AutoSizeGadget, (ULONG)Gad,
  235.             TAG_DONE);
  236.  
  237.         if(Win) {
  238.           struct pOS_IntuiMessage *Msg;
  239.           BOOL Ende=FALSE;
  240.           const UWORD MWidth =Win->win_Width;
  241.           const UWORD MHeight=Win->win_Height;
  242.  
  243.           pOS_SetMenuStrip(Win,MenuList);
  244.  
  245.           while(!Ende) {
  246.             ULONG Sig;
  247.             Sig=pOS_WaitSignal( (1<<Win->win_UserPort->mp_SigBit) | DOSSIGF_CTRL_C);
  248.             if(Sig & DOSSIGF_CTRL_C) Ende=TRUE;
  249.  
  250.             while(Msg=(struct pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
  251.               switch(Msg->im_Class) {
  252.  
  253.                 case IDCMP_MenuPick:
  254.                   break;
  255.  
  256.                 case IDCMP_CloseWindow:  Ende=TRUE; break;
  257.                 default: if(pOS_SysIMessage(Msg)) Msg=NULL;
  258.               }
  259.               if(Msg) pOS_ReplyMsg(&Msg->im_Message);
  260.             }
  261.           }
  262.           pOS_SetMenuStrip(Win,NULL);
  263.           pOS_CloseWindow(Win);
  264.         }
  265.         else printf("Cannot open window\n");
  266.         pOS_DeleteMenu(MenuList);
  267.       }
  268.       else printf("Error in pOS_CreateMenuTagA\n");
  269.       if(TagArray) pOS_FreeVec(TagArray);
  270.       pOS_UnlockPubScreen(Scr);
  271.     }
  272.     else printf("Cannot lock PubScreen\n");
  273.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  274.   }
  275.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  276.  
  277.   pOS_SetShellFail(Err);
  278.  
  279.   pOS_CloseLibrary((struct pOS_Library*)gb_IntuiBase);
  280. }
  281.