home *** CD-ROM | disk | FTP | other *** search
-
- /*******************************************************************
- $CRT 02 Jun 1996 : hb
-
- $AUT Holger Burkarth
- $DAT >>Win1.c<< 29 Jan 1997 13:24:32 - (C) ProDAD
- *******************************************************************/
-
- //##ex mcpp:cppc -gs -o pos:pos/Ex/Win1 p:pLib/StartCode.o p:/pOS_RKRM/pIntui/Win1.c p:pLib/StdIO.o -l pOSStub -l pOS
-
- /***********************************************************
- 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:pGadget/Gadget.h"
- #include "p:pScreen/ScrTags.h"
- #include "p:pScreen/Window.h"
- #include "p:pScreen/Screen.h"
- #include "p:pScreen/ScrCB.h"
- #include "p:pGFX/GfxTags.h"
- #include "p:pGFX/RastPort.h"
- #include "p:pIntui/IntuMsg.h"
- #include "p:pIntui/Tags.h"
- #include "p:pIntui/FraClass.h"
- #include "p:pIntui/EasyReq.h"
- #include "p:pIntui/EasyTags.h"
- #include "p:pDtType/DtTags.h"
- #include "p:pDtType/Picture.h"
- #include "p:proto/pLibExt.h"
- #include "p:proto/pExec2.h"
- #include "p:proto/pDOS2.h"
- #include "p:proto/pIntui2.h"
- #include "p:proto/pGFX2.h"
- #include "p:proto/pDtType2.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 1996-97 by proDAD) (Created by Holger Burkarth)";
-
-
- struct pOS_IntuiDevice *gb_IntuiBase;
- struct pOS_GfxBase *gb_GfxBase;
- struct pOS_DataTypeBase *gb_DtTypeBase;
-
-
- /*----------------------------------
- -----------------------------------*/
- BOOL CallBack_func(_R_A0 const struct pOS_Callback* cb,
- _R_A1 struct pOS_ScreenCallbackData* data)
- {
- BOOL Result;
-
- if(data->scb_Type==SCRCBTYP_Window) {
- ULONG Msk=cb->cb_UserData[0];
- const struct pOS_Window *const Win=data->scb_TU.scb_Window;
-
- switch(data->scb_Method) {
-
- case SCRCBMTH_Drag:
- if(Msk & 0x01) {
- Result=TRUE;
- data->scb_U.scb_Drag.scbd_X = (data->scb_U.scb_Drag.scbd_X+0x10) & ~0x1f;
- data->scb_U.scb_Drag.scbd_Y = (data->scb_U.scb_Drag.scbd_Y+0x08) & ~0x0f;
-
- if(data->scb_U.scb_Drag.scbd_X+Win->win_Width > Win->win_Screen->scr_Width)
- data->scb_U.scb_Drag.scbd_X-=0x20;
- if(data->scb_U.scb_Drag.scbd_Y+Win->win_Height > Win->win_Screen->scr_Height)
- data->scb_U.scb_Drag.scbd_Y-=0x20;
- }
- else Result=FALSE;
- break;
-
- case SCRCBMTH_Size:
- if(Msk & 0x02) {
- ULONG Val=data->scb_U.scb_Size.scbs_Width;
-
- if(data->scb_U.scb_Size.scbs_Height>Val) Val=data->scb_U.scb_Size.scbs_Height;
-
- Result=TRUE;
- if(Win->win_LeftEdge+Val>Win->win_Screen->scr_Width)
- Val=Win->win_Screen->scr_Width-Win->win_LeftEdge;
- if(Win->win_TopEdge+Val>Win->win_Screen->scr_Height)
- Val=Win->win_Screen->scr_Height-Win->win_TopEdge;
-
- data->scb_U.scb_Size.scbs_Width = Val;
- data->scb_U.scb_Size.scbs_Height = Val;
- }
- else Result=FALSE;
- break;
-
- default: Result=FALSE;
- }
- }
- else Result=FALSE;
-
- return(Result);
- }
-
-
- /*----------------------------------
- -----------------------------------*/
- #ifdef __cplusplus
- extern "C"
- #endif
-
- VOID main()
- {
- struct pOS_DosArgs* Args;
- UWORD Err=0;
- ULONG Ops[6]={0,0,0,0,0,0};
-
- gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
- gb_GfxBase=(struct pOS_GfxBase*)pOS_OpenLibrary("pgraphics.library",0);
- gb_DtTypeBase=(struct pOS_DataTypeBase*)pOS_OpenLibrary("pDtType.library",0);
-
-
- Args=pOS_ReadDosArgs(
- // 0 1 2 3 4 5
- "FOLLOW/S, TEXT/K, GRID/S, PROPSIZE/S, BGNAME/K, NOGAD/S",
- 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_Window *Win;
- struct pOS_Gadget *Gad,*TextGad;
- struct pOS_Screen *Scr;
- struct pOS_Callback CB;
- struct pOS_GfxMap* BgFillMap=NULL;
-
- ww_InitNode(&CB.cb_Node); // only in debug-mode
- CB.cb_Code=( ULONG(*)(_R_A0 const pOS_Callback*,_R_A1 APTR) ) CallBack_func;
- CB.cb_UserData[0]=(Ops[2] ? 0x01:0x00) | (Ops[3] ? 0x02:0x00);
-
- if(Scr=pOS_LockPubScreen("Workbench")) {
- const struct pOS_DrawInfo *const Dri=Scr->scr_DrawInfo;
-
- if(Ops[4]) { // BGNAME
- struct pOS_DataType* DT;
- DT=pOS_CreateFHDTObject(NULL,(dosname_t*)Ops[4],pOS_DTFORM_PICTURE,NULL,
- DCLTAG_Remap, TRUE, // remap erlauben
- PICTURETAG_GfxMapPtr, (ULONG)&BgFillMap, // result
- PICTURETAG_RemapMode, 0, // Mode => friend
- PICTURETAG_FriendGfxMap, (ULONG)Scr->scr_RastPort->rp_GfxMap,
- TAG_END);
- if(DT) pOS_DeleteDTObject(DT);
- }
-
- if(Ops[5]==0) { // NOGAD
- TextGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GTxtBoxClass],0,
- ICLTAG_DrawInfo, (ULONG)Scr->scr_DrawInfo,
- IOBJTAG_StaticString, Ops[1] ? Ops[1] : (ULONG)"Window-Demo",
- ICLTAG_AddWidth, 6,
- ICLTAG_AddHeight, 6,
- ICLTAG_Gwk, 1,
- #if 0
- ICLTAG_RenderLayMode,0x02,
- BUTGADTAG_MinStdWidth,16*16,
- BUTGADTAG_MinStdHeight,3*16,
- #endif
- TAG_DONE);
-
- Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
- ICLTAG_AutoDelete, TRUE,
- GRPGADTAG_BorLeft, 10,
- GRPGADTAG_BorTop, 10,
- GRPGADTAG_BorRight, 10,
- GRPGADTAG_BorBottom, 10,
- GRPGADTAG_AddGadget,(ULONG)TextGad,
- TAG_DONE);
- }
- else Gad=NULL;
-
- Win=pOS_OpenWindow(
- SCRTAG_Title, (ULONG)"Window-1",
- SCRTAG_PubName, (ULONG)"Workbench",
- SCRTAG_Flags, WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
- WINFLGF_Activate | WINFLGF_CloseGadget | WINFLGF_Dragbar
- | (CB.cb_UserData[0] ? (WINFLGF_SizeGadget|WINFLGF_SizeBBottom):0),
- SCRTAG_IDCMP, IDCMP_CloseWindow | IDCMP_MouseMove | IDCMP_VanillaKey,
- SCRTAG_UserHandler, (ULONG)&CB,
- SCRTAG_Width, 80,
- SCRTAG_AutoSizeGadget, (ULONG)Gad,
- SCRTAG_BgFillGfxMap, (ULONG)BgFillMap,
- TAG_DONE);
-
- if(Win) {
- struct pOS_IntuiMessage *Msg;
- BOOL Ende=FALSE;
- const UWORD MWidth =Win->win_Width;
- const UWORD MHeight=Win->win_Height;
-
- while(!Ende) {
- pOS_WaitPort(Win->win_UserPort);
- while(Msg=(struct pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
- switch(Msg->im_Class) {
-
- case IDCMP_MouseMove:
- if(Ops[0]) pOS_ChangeWindowBox(Win,Scr->scr_MouseX-4,Scr->scr_MouseY-4,MWidth,MHeight);
- break;
-
- case IDCMP_VanillaKey:
- switch(Msg->im_Code) {
-
- #if 0
- case 'a':
- pOS_SetGadgetAttrs(Win,TextGad,
- IOBJTAG_String, (ULONG)"Test",
- ICLTAG_RenderLayMode,0x01,
- TAG_END);
- break;
- #endif
-
- case 'r':
- {
- struct pOS_TagItem Tags[]={
- EASYTAG_WindowBusy, (ULONG)Win,
- TAG_END
- };
- struct pOS_EasyStruct ES={
- sizeof(pOS_EasyStruct),
- 0,0,
- "Window-Title",
- "Test-Requester\n\n%s",
- "_Ok|_Cancel",
- NULL,NULL,Tags
- };
-
- pOS_EasyRequestArgs(NULL,&ES,NULL,NULL);
- }
- break;
- }
- break;
-
- case IDCMP_CloseWindow: Ende=TRUE; break;
- default: if(pOS_SysIMessage(Msg)) Msg=NULL;
- }
-
- if(Msg) pOS_ReplyMsg(&Msg->im_Message);
- }
- }
- pOS_CloseWindow(Win);
- }
- else printf("Cannot open window\n");
- pOS_UnlockPubScreen(Scr);
- }
- else printf("Cannot lock PubScreen\n");
-
- if(BgFillMap) pOS_FreeGfxMap(BgFillMap);
- pOS_DeleteDosArgs(Args); /* Args freigeben */
- }
- else Err=DOSFAIL_FAIL; /* vollkommen fehlgeschlagen */
-
- pOS_SetShellFail(Err);
-
- pOS_CloseLibrary((pOS_Library*)gb_GfxBase);
- pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);
- pOS_CloseLibrary((pOS_Library*)gb_DtTypeBase);
- }
-