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

  1.  
  2. /*******************************************************************
  3.  $CRT 22 Feb 1997 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>ListView1.c<<   09 Mar 1997    09:02:20 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##ex mcpp:cppc -gs -o pos:pos/Ex/ListView1 p:pLib/StartCode.o p:/pOS_RKRM/pIntui/ListView1.c p:pLib/StdIO.o -l pOSStub -l pOS -l CPPList
  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:Device/IEvent.h"
  56. #include "p:pGadget/Gadget.h"
  57. #include "p:pGadget/GadItem.h"
  58. #include "p:pScreen/ScrTags.h"
  59. #include "p:pScreen/Window.h"
  60. #include "p:pScreen/Screen.h"
  61. #include "p:pIntui/IntuMsg.h"
  62. #include "p:pIntui/Tags.h"
  63. #include "p:pIntui/OClass.h"
  64. #include "p:proto/pLibExt.h"
  65. #include "p:proto/pExec2.h"
  66. #include "p:proto/pDOS2.h"
  67. #include "p:proto/pIntui2.h"
  68. #include "p:proto/pList.h"
  69.  
  70. #ifdef _____ME_____
  71.   #include "grund/inc_string.h"
  72.   #include "grund/inc_stdio.h"
  73. #else
  74.  #ifdef __cplusplus
  75.  extern "C" {
  76.  #endif
  77.   #include <string.h>
  78.   #include <stdio.h>
  79.  #ifdef __cplusplus
  80.  }
  81.  #endif
  82. #endif
  83.  
  84.  
  85. const CHAR *HelpText=
  86. ""
  87. ;
  88.  
  89. const CHAR *PrgHeader=
  90. "";
  91.  
  92. const CHAR *PrgVerText=
  93. "$VER: 1.0 ("__DATE2__") (Copyright 1997 by proDAD) (Created by Holger Burkarth)";
  94.  
  95.  
  96. struct pOS_IntuiDevice *gb_IntuiBase;
  97.  
  98. /*----------------------------------
  99. -----------------------------------*/
  100. BOOL CreateLVList(struct pOS_MemPool* mp,struct pOS_List* list,
  101.                   const struct pOS_DrawInfo* dri,__CONST__ CHAR** names)
  102. {
  103.   BOOL Res=TRUE;
  104.   struct pOS_GadgetItem *GI;
  105.   ULONG i;
  106.  
  107.   for(i=1; names[0]; ++names,++i) {
  108.     GI=(struct pOS_GadgetItem*)pOS_AllocPoolMem(mp,sizeof(struct pOS_GadgetItem),MEMF_CLEAR);
  109.     if(GI) {
  110.  
  111.       GI->gdt_Render=(pOS_IntuiObj*)pOS_NewIObject(NULL,"itext.class",0,
  112.           ICLTAG_DrawInfo,       (ULONG)dri,
  113.           IOBJTAG_StaticString,  (ULONG)names[0],
  114.           TAG_END);
  115.  
  116.       if(GI->gdt_Render) {
  117.         GI->gdt_ID=i;
  118.         pOS_ListAddTail(list,&GI->gdt_Node);
  119.       }
  120.       else Res=FALSE;
  121.     }
  122.     else Res=FALSE;
  123.   }
  124.   return(Res);
  125. }
  126.  
  127.  
  128. /*----------------------------------
  129. -----------------------------------*/
  130. VOID DeleteLVList(struct pOS_MemPool* mp,struct pOS_List* list)
  131. {
  132.   struct pOS_GadgetItem *GI;
  133.  
  134.   while(GI=(struct pOS_GadgetItem*)pOS_ListRemHead(list)) {
  135.     if(GI->gdt_Render) pOS_IObjDisposeList(GI->gdt_Render);
  136.   }
  137. }
  138.  
  139.  
  140.  
  141. /*----------------------------------
  142. -----------------------------------*/
  143. VOID SetPopUpLayoutMode(pOS_Gadget* gad,ULONG id)
  144. {
  145.   static const ULONG Array[]={
  146.     IOBLAY_HVCenter,                      // 0
  147.     IOBLAY_Left,                          // 1
  148.     IOBLAY_Right,                         // 2
  149.     IOBLAY_Top,                           // 3
  150.     IOBLAY_Bottom,                        // 4
  151.     IOBLAY_Left | IOBLAY_Top,             // 5
  152.     IOBLAY_Right | IOBLAY_Bottom,         // 6
  153.   };
  154.  
  155.   pOS_SetGadgetAttrs(NULL,gad,
  156.       POPUPGADTAG_LayoutMode, Array[id],
  157.       TAG_END);
  158. }
  159.  
  160.  
  161. /*----------------------------------
  162. -----------------------------------*/
  163. #ifdef __cplusplus
  164. extern "C"
  165. #endif
  166.  
  167. VOID main()
  168. {
  169.   struct pOS_DosArgs* Args;
  170.   UWORD Err=0;
  171.   ULONG Ops[1]={0};
  172.  
  173.   gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  174.  
  175.   Args=pOS_ReadDosArgs(
  176. //
  177. "",
  178. Ops,sizeof(Ops)/sizeof(ULONG),
  179.  
  180.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  181.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  182.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  183.     TAG_END);
  184.  
  185.  
  186.   if(Args) {
  187.     struct pOS_List   LV1List;
  188.     struct pOS_Window *Win;
  189.     struct pOS_Screen *Scr;
  190.     struct pOS_Gadget *VGrpGad;
  191.     struct pOS_Gadget *HGrpGad;
  192.     struct pOS_Gadget *LV1Gad;
  193.     struct pOS_Gadget *LV2Gad;
  194.     struct pOS_Gadget *LV3Gad;
  195.     struct pOS_MemPool MP;
  196.  
  197.     pOS_ListInit(&LV1List);
  198.     pOS_InitMemPool(&MP,1024,MEMF_PUBLIC);
  199.  
  200.     if(Scr=pOS_LockPubScreen(NULL)) {
  201.       const struct pOS_DrawInfo *const Dri=Scr->scr_DrawInfo;
  202.  
  203.       static const pOS_TagItem StdTags[]={
  204.         ICLTAG_Immediate,      TRUE,      /* => IDCMP_GadgetDown */
  205.         ICLTAG_RelVerify,      TRUE,      /* => IDCMP_GadgetUp */
  206.         ICLTAG_UpdateGadget,   TRUE,      /* => IDCMP_UpdateGadget */
  207.         ICLTAG_Gwk,            1,         /* Layout Weight=1 */
  208.         LVGADTAG_CursorScroll, TRUE,
  209.         LVGADTAG_CursorSelect, TRUE,
  210.         LVGADTAG_VAutoGad,     TRUE,      /* create Slider */
  211.         LVGADTAG_Key1,         TRUE,
  212.         TAG_END
  213.       };
  214.  
  215.       static __CONST__ CHAR *Name1Array[]={
  216.         "Center",
  217.         "Left",
  218.         "Right",
  219.         "Top",
  220.         "Bottom",
  221.         "Left+Top",
  222.         "Right+Buttom",
  223.         NULL
  224.       };
  225.  
  226.       static const pOS_GadgetTagItem Name2Array[]={
  227.         {"Name2_1",1},
  228.         {"Name2_2",2},
  229.         {"Name2_3",3},
  230.         {"Name2_4",4},
  231.         {"Name2_5",5},
  232.         {"Name2_6",6},
  233.         NULL
  234.       };
  235.  
  236. /*** Variante - 1 ***/
  237.       CreateLVList(&MP,&LV1List,Dri,Name1Array);
  238.  
  239.       LV1Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GLVClass],0,
  240.         ICLTAG_DrawInfo,       (ULONG)Dri,
  241.         LVGADTAG_List,         (ULONG)&LV1List,
  242.         LVGADTAG_ItemID,       1,     /* select Item with ID=1 */
  243.         TAG_MORE, (ULONG)StdTags);
  244.  
  245. /*** Variante - 2 ***/
  246.       LV2Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GLVClass],0,
  247.         ICLTAG_DrawInfo,       (ULONG)Dri,
  248.         LVGADTAG_GadgetTagItem,(ULONG)Name2Array,
  249.         LVGADTAG_ItemID,       6,
  250.         TAG_MORE, (ULONG)StdTags);
  251.  
  252. /*** Variante - 3 ***/
  253.       LV3Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GLVPopupClass],0,
  254.         ICLTAG_DrawInfo,       (ULONG)Dri,
  255.         ICLTAG_Immediate,      TRUE,
  256.         ICLTAG_RelVerify,      TRUE,
  257.         ICLTAG_UpdateGadget,   TRUE,
  258.         LVGADTAG_GadgetTagItem,(ULONG)Name2Array,
  259.         POPUPGADTAG_MinPopStdWidth,  pOS_DRISTDFAC*5,
  260.         POPUPGADTAG_MinPopStdHeight, pOS_DRISTDFAC*6,
  261. //POPUPGADTAG_MainGadHeight,1,
  262. //        LVGADTAG_ItemID,       6,
  263.         ICLTAG_StdLableName, (ULONG)"_Lable",
  264.         TAG_END);
  265.  
  266.  
  267.       HGrpGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
  268.         ICLTAG_Gwk,            1,
  269.         GRPGADTAG_AddGadget,   (ULONG)LV3Gad,
  270.         TAG_DONE);
  271.  
  272.  
  273.       VGrpGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
  274.         ICLTAG_AutoDelete,     TRUE,
  275.         GRPGADTAG_Horiz,       TRUE,
  276.         GRPGADTAG_AddGadget,   (ULONG)LV1Gad,
  277.         GRPGADTAG_AddGadget,   (ULONG)LV2Gad,
  278.         GRPGADTAG_AddGadget,   (ULONG)HGrpGad,
  279.         TAG_DONE);
  280.  
  281.  
  282.       if(VGrpGad && LV1Gad && LV2Gad) {
  283.         static CHAR TitelBuffer[80]="ListView1";
  284.  
  285.         Win=pOS_OpenWindow(
  286.               SCRTAG_Title,    (ULONG)TitelBuffer,
  287.               SCRTAG_Screen,   (ULONG)Scr,
  288.               SCRTAG_Flags,    WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
  289.                                WINFLGF_SizeGadget | WINFLGF_Activate |
  290.                                WINFLGF_CloseGadget | WINFLGF_Dragbar |
  291.                                WINFLGF_SizeBBottom,
  292.               SCRTAG_IDCMP,    IDCMP_CloseWindow | IDCMP_StdSysMsg,
  293.               SCRTAG_AutoSizeGadget, (ULONG)VGrpGad,
  294.               SCRTAG_ZipGadget,      TRUE,
  295.               SCRTAG_UnderMouse,     TRUE,
  296.               TAG_DONE);
  297.  
  298.         if(Win) {
  299.           struct pOS_IntuiMessage *Msg;
  300.           BOOL Ende=FALSE;
  301.  
  302. /*\
  303. *** Move the selected item in view bound.
  304. \*/
  305.           pOS_SetGadgetAttrs(Win,LV1Gad,LVGADTAG_ViewItem,0, TAG_END);
  306.           pOS_SetGadgetAttrs(Win,LV2Gad,LVGADTAG_ViewItem,0, TAG_END);
  307.  
  308.  
  309.  
  310.           while(!Ende) {
  311.             if(DOSSIGF_CTRL_C & pOS_WaitSignal((1<<Win->win_UserPort->mp_SigBit) | DOSSIGF_CTRL_C)) break;
  312.  
  313.             while(Msg=(struct pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
  314.  
  315.               if(pOS_SysIMessage(Msg)) Msg=NULL;
  316.               else {
  317.                 switch(Msg->im_Class) {
  318.                   case IDCMP_GadgetDown:
  319.                   case IDCMP_GadgetUp:
  320.                   case IDCMP_UpdateGadget:
  321.                   case IDCMP_GadgetAbort:
  322.  
  323. //printf("code<%lx> %lx %ld\n",Msg->im_IAddress,Msg->im_Class,Msg->im_Code);
  324.  
  325.                     if(   Msg->im_Code==IEGUCODE_Select   // first select
  326.                        || Msg->im_Code==IEGUCODE_UpSelect // alternate select
  327.                        || Msg->im_Code==IEGUCODE_Inactive) // left focus (IDCMP_GadgetAbort)
  328.                     {
  329.                       ULONG LV1,LV2,LV3;
  330.                       pOS_GetGadgetAttr(Win,LV1Gad,LVGADTAG_ItemID,(ULONG*)&LV1);
  331.                       pOS_GetGadgetAttr(Win,LV2Gad,LVGADTAG_ItemID,(ULONG*)&LV2);
  332.                       pOS_GetGadgetAttr(Win,LV3Gad,LVGADTAG_ItemID,(ULONG*)&LV3);
  333.                       pOS_SPrintf(TitelBuffer,"ListView1: LV1=%ld LV2=%ld LV3=%ld",LV1,LV2,LV3);
  334.                       pOS_SetWindowTitles(Win,TitelBuffer,(CHAR*)~0);
  335.                       SetPopUpLayoutMode(LV3Gad,LV1-1);
  336.  
  337.                       if(Msg->im_IAddress==(APTR)LV2Gad) {
  338.                         pOS_SetGadgetAttrs(Win,LV3Gad,
  339.                           LVGADTAG_ItemID,   LV2,
  340.                           LVGADTAG_ViewItem, 0,
  341.                           TAG_END);
  342.  
  343.                       }
  344.                     }
  345.                     break;
  346.  
  347.                   case IDCMP_CloseWindow:  Ende=TRUE; break;
  348.                 }
  349.               }
  350.               if(Msg) pOS_ReplyMsg(&Msg->im_Message);
  351.             }
  352.           }
  353.           pOS_CloseWindow(Win);
  354.         }
  355.         else {printf("Cannot open window\n"); Err=DOSFAIL_FAIL;}
  356.       }
  357.       else {printf("Cannot create gadgets\n"); Err=DOSFAIL_FAIL;}
  358.       pOS_UnlockPubScreen(Scr);
  359.     }
  360.     else {printf("Cannot lock PubScreen\n"); Err=DOSFAIL_FAIL;}
  361.  
  362.     DeleteLVList(&MP,&LV1List);
  363.     pOS_FreePoolAll(&MP);
  364.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  365.   }
  366.   else Err=DOSFAIL_FAIL;
  367.  
  368.   pOS_SetShellFail(Err);
  369.  
  370.   pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);
  371. }
  372.