home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 22 Feb 1997 : hb
-
- $AUT Holger Burkarth
- $DAT >>ListView1.c<< 09 Mar 1997 09:02:20 - (C) ProDAD
- *******************************************************************/
-
- //##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
-
- /***********************************************************
- pOS programing example - Copyright (C) 1995-97 proDAD
-
- This code was written as an easy to understand example,
- how to program pOS features. It is provided 'as-is',
- without any express or implied warranty.
-
- Permission is hereby granted to use, copy and modify
- this source code for any purpose, without fee, subject
- to the following conditions:
-
- (1) This notice may not be removed or altered from any
- source distribution.
-
- (2) Altered source versions must be plainly marked as
- such, and must not be misrepresented as being
- the original source code.
-
- (3) If only executable code is distributed, then the
- accompanying documentation have to state that
- "this software is based in part on examples of
- the pOS developer packet".
-
- (4) Permission for use of this code is granted only
- if the user accepts full responsibility for any
- undesirable consequences. proDAD accept NO LIABILITY
- for damages of any kind.
-
- ©proDAD
- ***********************************************************/
-
- /*\
- *** Example:
- ***
- \*/
-
-
- #define __COMPUTER_AMIGA 1
- #define NOMYDEBUG
-
- #include "p:pExec/Types.h"
- #include "p:pDOS/ArgTags.h"
- #include "p:pDOS/DosSig.h"
- #include "p:pDOS/DosErrors.h"
- #include "p:Device/IEvent.h"
- #include "p:pGadget/Gadget.h"
- #include "p:pGadget/GadItem.h"
- #include "p:pScreen/ScrTags.h"
- #include "p:pScreen/Window.h"
- #include "p:pScreen/Screen.h"
- #include "p:pIntui/IntuMsg.h"
- #include "p:pIntui/Tags.h"
- #include "p:pIntui/OClass.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
- #include "p:proto/pIntui2.h"
- #include "p:proto/pList.h"
-
- #ifdef _____ME_____
- #include "grund/inc_string.h"
- #include "grund/inc_stdio.h"
- #else
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include <string.h>
- #include <stdio.h>
- #ifdef __cplusplus
- }
- #endif
- #endif
-
-
- const CHAR *HelpText=
- ""
- ;
-
- const CHAR *PrgHeader=
- "";
-
- const CHAR *PrgVerText=
- "$VER: 1.0 ("__DATE2__") (Copyright 1997 by proDAD) (Created by Holger Burkarth)";
-
-
- struct pOS_IntuiDevice *gb_IntuiBase;
-
- /*----------------------------------
- -----------------------------------*/
- BOOL CreateLVList(struct pOS_MemPool* mp,struct pOS_List* list,
- const struct pOS_DrawInfo* dri,__CONST__ CHAR** names)
- {
- BOOL Res=TRUE;
- struct pOS_GadgetItem *GI;
- ULONG i;
-
- for(i=1; names[0]; ++names,++i) {
- GI=(struct pOS_GadgetItem*)pOS_AllocPoolMem(mp,sizeof(struct pOS_GadgetItem),MEMF_CLEAR);
- if(GI) {
-
- GI->gdt_Render=(pOS_IntuiObj*)pOS_NewIObject(NULL,"itext.class",0,
- ICLTAG_DrawInfo, (ULONG)dri,
- IOBJTAG_StaticString, (ULONG)names[0],
- TAG_END);
-
- if(GI->gdt_Render) {
- GI->gdt_ID=i;
- pOS_ListAddTail(list,&GI->gdt_Node);
- }
- else Res=FALSE;
- }
- else Res=FALSE;
- }
- return(Res);
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID DeleteLVList(struct pOS_MemPool* mp,struct pOS_List* list)
- {
- struct pOS_GadgetItem *GI;
-
- while(GI=(struct pOS_GadgetItem*)pOS_ListRemHead(list)) {
- if(GI->gdt_Render) pOS_IObjDisposeList(GI->gdt_Render);
- }
- }
-
-
-
- /*----------------------------------
- -----------------------------------*/
- VOID SetPopUpLayoutMode(pOS_Gadget* gad,ULONG id)
- {
- static const ULONG Array[]={
- IOBLAY_HVCenter, // 0
- IOBLAY_Left, // 1
- IOBLAY_Right, // 2
- IOBLAY_Top, // 3
- IOBLAY_Bottom, // 4
- IOBLAY_Left | IOBLAY_Top, // 5
- IOBLAY_Right | IOBLAY_Bottom, // 6
- };
-
- pOS_SetGadgetAttrs(NULL,gad,
- POPUPGADTAG_LayoutMode, Array[id],
- TAG_END);
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* Args;
- UWORD Err=0;
- ULONG Ops[1]={0};
-
- gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
-
- Args=pOS_ReadDosArgs(
- //
- "",
- Ops,sizeof(Ops)/sizeof(ULONG),
-
- ARGTAG_PrgHeaderText, (ULONG)PrgHeader, /* kurze Programm-Beschreibung */
- ARGTAG_HelpText, (ULONG)HelpText, /* Help-Texte */
- ARGTAG_PrgVerText, (ULONG)PrgVerText, /* VER-String */
- TAG_END);
-
-
- if(Args) {
- struct pOS_List LV1List;
- struct pOS_Window *Win;
- struct pOS_Screen *Scr;
- struct pOS_Gadget *VGrpGad;
- struct pOS_Gadget *HGrpGad;
- struct pOS_Gadget *LV1Gad;
- struct pOS_Gadget *LV2Gad;
- struct pOS_Gadget *LV3Gad;
- struct pOS_MemPool MP;
-
- pOS_ListInit(&LV1List);
- pOS_InitMemPool(&MP,1024,MEMF_PUBLIC);
-
- if(Scr=pOS_LockPubScreen(NULL)) {
- const struct pOS_DrawInfo *const Dri=Scr->scr_DrawInfo;
-
- static const pOS_TagItem StdTags[]={
- ICLTAG_Immediate, TRUE, /* => IDCMP_GadgetDown */
- ICLTAG_RelVerify, TRUE, /* => IDCMP_GadgetUp */
- ICLTAG_UpdateGadget, TRUE, /* => IDCMP_UpdateGadget */
- ICLTAG_Gwk, 1, /* Layout Weight=1 */
- LVGADTAG_CursorScroll, TRUE,
- LVGADTAG_CursorSelect, TRUE,
- LVGADTAG_VAutoGad, TRUE, /* create Slider */
- LVGADTAG_Key1, TRUE,
- TAG_END
- };
-
- static __CONST__ CHAR *Name1Array[]={
- "Center",
- "Left",
- "Right",
- "Top",
- "Bottom",
- "Left+Top",
- "Right+Buttom",
- NULL
- };
-
- static const pOS_GadgetTagItem Name2Array[]={
- {"Name2_1",1},
- {"Name2_2",2},
- {"Name2_3",3},
- {"Name2_4",4},
- {"Name2_5",5},
- {"Name2_6",6},
- NULL
- };
-
- /*** Variante - 1 ***/
- CreateLVList(&MP,&LV1List,Dri,Name1Array);
-
- LV1Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GLVClass],0,
- ICLTAG_DrawInfo, (ULONG)Dri,
- LVGADTAG_List, (ULONG)&LV1List,
- LVGADTAG_ItemID, 1, /* select Item with ID=1 */
- TAG_MORE, (ULONG)StdTags);
-
- /*** Variante - 2 ***/
- LV2Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GLVClass],0,
- ICLTAG_DrawInfo, (ULONG)Dri,
- LVGADTAG_GadgetTagItem,(ULONG)Name2Array,
- LVGADTAG_ItemID, 6,
- TAG_MORE, (ULONG)StdTags);
-
- /*** Variante - 3 ***/
- LV3Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GLVPopupClass],0,
- ICLTAG_DrawInfo, (ULONG)Dri,
- ICLTAG_Immediate, TRUE,
- ICLTAG_RelVerify, TRUE,
- ICLTAG_UpdateGadget, TRUE,
- LVGADTAG_GadgetTagItem,(ULONG)Name2Array,
- POPUPGADTAG_MinPopStdWidth, pOS_DRISTDFAC*5,
- POPUPGADTAG_MinPopStdHeight, pOS_DRISTDFAC*6,
- //POPUPGADTAG_MainGadHeight,1,
- // LVGADTAG_ItemID, 6,
- ICLTAG_StdLableName, (ULONG)"_Lable",
- TAG_END);
-
-
- HGrpGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
- ICLTAG_Gwk, 1,
- GRPGADTAG_AddGadget, (ULONG)LV3Gad,
- TAG_DONE);
-
-
- VGrpGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
- ICLTAG_AutoDelete, TRUE,
- GRPGADTAG_Horiz, TRUE,
- GRPGADTAG_AddGadget, (ULONG)LV1Gad,
- GRPGADTAG_AddGadget, (ULONG)LV2Gad,
- GRPGADTAG_AddGadget, (ULONG)HGrpGad,
- TAG_DONE);
-
-
- if(VGrpGad && LV1Gad && LV2Gad) {
- static CHAR TitelBuffer[80]="ListView1";
-
- Win=pOS_OpenWindow(
- SCRTAG_Title, (ULONG)TitelBuffer,
- SCRTAG_Screen, (ULONG)Scr,
- SCRTAG_Flags, WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
- WINFLGF_SizeGadget | WINFLGF_Activate |
- WINFLGF_CloseGadget | WINFLGF_Dragbar |
- WINFLGF_SizeBBottom,
- SCRTAG_IDCMP, IDCMP_CloseWindow | IDCMP_StdSysMsg,
- SCRTAG_AutoSizeGadget, (ULONG)VGrpGad,
- SCRTAG_ZipGadget, TRUE,
- SCRTAG_UnderMouse, TRUE,
- TAG_DONE);
-
- if(Win) {
- struct pOS_IntuiMessage *Msg;
- BOOL Ende=FALSE;
-
- /*\
- *** Move the selected item in view bound.
- \*/
- pOS_SetGadgetAttrs(Win,LV1Gad,LVGADTAG_ViewItem,0, TAG_END);
- pOS_SetGadgetAttrs(Win,LV2Gad,LVGADTAG_ViewItem,0, TAG_END);
-
-
-
- while(!Ende) {
- if(DOSSIGF_CTRL_C & pOS_WaitSignal((1<<Win->win_UserPort->mp_SigBit) | DOSSIGF_CTRL_C)) break;
-
- while(Msg=(struct pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
-
- if(pOS_SysIMessage(Msg)) Msg=NULL;
- else {
- switch(Msg->im_Class) {
- case IDCMP_GadgetDown:
- case IDCMP_GadgetUp:
- case IDCMP_UpdateGadget:
- case IDCMP_GadgetAbort:
-
- //printf("code<%lx> %lx %ld\n",Msg->im_IAddress,Msg->im_Class,Msg->im_Code);
-
- if( Msg->im_Code==IEGUCODE_Select // first select
- || Msg->im_Code==IEGUCODE_UpSelect // alternate select
- || Msg->im_Code==IEGUCODE_Inactive) // left focus (IDCMP_GadgetAbort)
- {
- ULONG LV1,LV2,LV3;
- pOS_GetGadgetAttr(Win,LV1Gad,LVGADTAG_ItemID,(ULONG*)&LV1);
- pOS_GetGadgetAttr(Win,LV2Gad,LVGADTAG_ItemID,(ULONG*)&LV2);
- pOS_GetGadgetAttr(Win,LV3Gad,LVGADTAG_ItemID,(ULONG*)&LV3);
- pOS_SPrintf(TitelBuffer,"ListView1: LV1=%ld LV2=%ld LV3=%ld",LV1,LV2,LV3);
- pOS_SetWindowTitles(Win,TitelBuffer,(CHAR*)~0);
- SetPopUpLayoutMode(LV3Gad,LV1-1);
-
- if(Msg->im_IAddress==(APTR)LV2Gad) {
- pOS_SetGadgetAttrs(Win,LV3Gad,
- LVGADTAG_ItemID, LV2,
- LVGADTAG_ViewItem, 0,
- TAG_END);
-
- }
- }
- break;
-
- case IDCMP_CloseWindow: Ende=TRUE; break;
- }
- }
- if(Msg) pOS_ReplyMsg(&Msg->im_Message);
- }
- }
- pOS_CloseWindow(Win);
- }
- else {printf("Cannot open window\n"); Err=DOSFAIL_FAIL;}
- }
- else {printf("Cannot create gadgets\n"); Err=DOSFAIL_FAIL;}
- pOS_UnlockPubScreen(Scr);
- }
- else {printf("Cannot lock PubScreen\n"); Err=DOSFAIL_FAIL;}
-
- DeleteLVList(&MP,&LV1List);
- pOS_FreePoolAll(&MP);
- pOS_DeleteDosArgs(Args); /* Args freigeben */
- }
- else Err=DOSFAIL_FAIL;
-
- pOS_SetShellFail(Err);
-
- pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);
- }
-