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

  1.  
  2. /*******************************************************************
  3.  $CRT 02 Jun 1996 : hb
  4.  
  5.  $AUT Holger Burkarth
  6.  $DAT >>Win1.c<<   29 Jan 1997    13:24:32 - (C) ProDAD
  7. *******************************************************************/
  8.  
  9. //##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
  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:pScreen/ScrCB.h"
  60. #include "p:pGFX/GfxTags.h"
  61. #include "p:pGFX/RastPort.h"
  62. #include "p:pIntui/IntuMsg.h"
  63. #include "p:pIntui/Tags.h"
  64. #include "p:pIntui/FraClass.h"
  65. #include "p:pIntui/EasyReq.h"
  66. #include "p:pIntui/EasyTags.h"
  67. #include "p:pDtType/DtTags.h"
  68. #include "p:pDtType/Picture.h"
  69. #include "p:proto/pLibExt.h"
  70. #include "p:proto/pExec2.h"
  71. #include "p:proto/pDOS2.h"
  72. #include "p:proto/pIntui2.h"
  73. #include "p:proto/pGFX2.h"
  74. #include "p:proto/pDtType2.h"
  75.  
  76. #ifdef _____ME_____
  77.   #include "grund/inc_string.h"
  78.   #include "grund/inc_stdio.h"
  79. #else
  80.  #ifdef __cplusplus
  81.  extern "C" {
  82.  #endif
  83.   #include <string.h>
  84.   #include <stdio.h>
  85.  #ifdef __cplusplus
  86.  }
  87.  #endif
  88. #endif
  89.  
  90.  
  91. const CHAR *HelpText=
  92. ""
  93. ;
  94.  
  95. const CHAR *PrgHeader=
  96. "";
  97.  
  98. const CHAR *PrgVerText=
  99. "$VER: 1.0 ("__DATE2__") (Copyright 1996-97 by proDAD) (Created by Holger Burkarth)";
  100.  
  101.  
  102. struct pOS_IntuiDevice *gb_IntuiBase;
  103. struct pOS_GfxBase *gb_GfxBase;
  104. struct pOS_DataTypeBase *gb_DtTypeBase;
  105.  
  106.  
  107. /*----------------------------------
  108. -----------------------------------*/
  109. BOOL CallBack_func(_R_A0 const struct pOS_Callback* cb,
  110.                    _R_A1 struct pOS_ScreenCallbackData* data)
  111. {
  112.   BOOL Result;
  113.  
  114.   if(data->scb_Type==SCRCBTYP_Window) {
  115.     ULONG Msk=cb->cb_UserData[0];
  116.     const struct pOS_Window *const Win=data->scb_TU.scb_Window;
  117.  
  118.     switch(data->scb_Method) {
  119.  
  120.       case SCRCBMTH_Drag:
  121.         if(Msk & 0x01) {
  122.           Result=TRUE;
  123.           data->scb_U.scb_Drag.scbd_X = (data->scb_U.scb_Drag.scbd_X+0x10) & ~0x1f;
  124.           data->scb_U.scb_Drag.scbd_Y = (data->scb_U.scb_Drag.scbd_Y+0x08) & ~0x0f;
  125.  
  126.           if(data->scb_U.scb_Drag.scbd_X+Win->win_Width > Win->win_Screen->scr_Width)
  127.             data->scb_U.scb_Drag.scbd_X-=0x20;
  128.           if(data->scb_U.scb_Drag.scbd_Y+Win->win_Height > Win->win_Screen->scr_Height)
  129.             data->scb_U.scb_Drag.scbd_Y-=0x20;
  130.         }
  131.         else Result=FALSE;
  132.         break;
  133.  
  134.       case SCRCBMTH_Size:
  135.         if(Msk & 0x02) {
  136.           ULONG Val=data->scb_U.scb_Size.scbs_Width;
  137.  
  138.           if(data->scb_U.scb_Size.scbs_Height>Val) Val=data->scb_U.scb_Size.scbs_Height;
  139.  
  140.           Result=TRUE;
  141.           if(Win->win_LeftEdge+Val>Win->win_Screen->scr_Width)
  142.                 Val=Win->win_Screen->scr_Width-Win->win_LeftEdge;
  143.           if(Win->win_TopEdge+Val>Win->win_Screen->scr_Height)
  144.                 Val=Win->win_Screen->scr_Height-Win->win_TopEdge;
  145.  
  146.           data->scb_U.scb_Size.scbs_Width  = Val;
  147.           data->scb_U.scb_Size.scbs_Height = Val;
  148.         }
  149.         else Result=FALSE;
  150.         break;
  151.  
  152.       default: Result=FALSE;
  153.     }
  154.   }
  155.   else Result=FALSE;
  156.  
  157.   return(Result);
  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[6]={0,0,0,0,0,0};
  172.  
  173.   gb_IntuiBase=(struct pOS_IntuiDevice*)pOS_OpenLibrary("pintui.library",0);
  174.   gb_GfxBase=(struct pOS_GfxBase*)pOS_OpenLibrary("pgraphics.library",0);
  175.   gb_DtTypeBase=(struct pOS_DataTypeBase*)pOS_OpenLibrary("pDtType.library",0);
  176.  
  177.  
  178.   Args=pOS_ReadDosArgs(
  179. // 0         1       2          3         4        5
  180. "FOLLOW/S, TEXT/K, GRID/S, PROPSIZE/S, BGNAME/K, NOGAD/S",
  181. Ops,sizeof(Ops)/sizeof(ULONG),
  182.  
  183.     ARGTAG_PrgHeaderText, (ULONG)PrgHeader,    /* kurze Programm-Beschreibung */
  184.     ARGTAG_HelpText,      (ULONG)HelpText,     /* Help-Texte */
  185.     ARGTAG_PrgVerText,    (ULONG)PrgVerText,   /* VER-String */
  186.     TAG_END);
  187.  
  188.   if(Args) {
  189.     struct pOS_Window *Win;
  190.     struct pOS_Gadget *Gad,*TextGad;
  191.     struct pOS_Screen *Scr;
  192.     struct pOS_Callback CB;
  193.     struct pOS_GfxMap*  BgFillMap=NULL;
  194.  
  195.     ww_InitNode(&CB.cb_Node); // only in debug-mode
  196.     CB.cb_Code=( ULONG(*)(_R_A0 const pOS_Callback*,_R_A1 APTR) ) CallBack_func;
  197.     CB.cb_UserData[0]=(Ops[2] ? 0x01:0x00) | (Ops[3] ? 0x02:0x00);
  198.  
  199.     if(Scr=pOS_LockPubScreen("Workbench")) {
  200.       const struct pOS_DrawInfo *const Dri=Scr->scr_DrawInfo;
  201.  
  202.       if(Ops[4]) { // BGNAME
  203.         struct pOS_DataType* DT;
  204.         DT=pOS_CreateFHDTObject(NULL,(dosname_t*)Ops[4],pOS_DTFORM_PICTURE,NULL,
  205.              DCLTAG_Remap,            TRUE,            // remap erlauben
  206.              PICTURETAG_GfxMapPtr,    (ULONG)&BgFillMap,    // result
  207.              PICTURETAG_RemapMode,    0,            // Mode => friend
  208.              PICTURETAG_FriendGfxMap, (ULONG)Scr->scr_RastPort->rp_GfxMap,
  209.              TAG_END);
  210.         if(DT) pOS_DeleteDTObject(DT);
  211.       }
  212.  
  213.       if(Ops[5]==0) { // NOGAD
  214.         TextGad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GTxtBoxClass],0,
  215.            ICLTAG_DrawInfo,       (ULONG)Scr->scr_DrawInfo,
  216.            IOBJTAG_StaticString,  Ops[1] ? Ops[1] : (ULONG)"Window-Demo",
  217.            ICLTAG_AddWidth,       6,
  218.            ICLTAG_AddHeight,      6,
  219.            ICLTAG_Gwk,            1,
  220. #if 0
  221. ICLTAG_RenderLayMode,0x02,
  222. BUTGADTAG_MinStdWidth,16*16,
  223. BUTGADTAG_MinStdHeight,3*16,
  224. #endif
  225.            TAG_DONE);
  226.  
  227.         Gad=(struct pOS_Gadget*)pOS_NewIObject(NULL,Dri->dri_Names[SCRNAM_GGroupClass],0,
  228.           ICLTAG_AutoDelete,    TRUE,
  229.           GRPGADTAG_BorLeft,    10,
  230.           GRPGADTAG_BorTop,     10,
  231.           GRPGADTAG_BorRight,   10,
  232.           GRPGADTAG_BorBottom,  10,
  233.           GRPGADTAG_AddGadget,(ULONG)TextGad,
  234.           TAG_DONE);
  235.       }
  236.       else Gad=NULL;
  237.  
  238.       Win=pOS_OpenWindow(
  239.           SCRTAG_Title,   (ULONG)"Window-1",
  240.           SCRTAG_PubName, (ULONG)"Workbench",
  241.           SCRTAG_Flags,   WINFLGF_DepthGadget | WINFLGF_SimpleRefresh |
  242.                           WINFLGF_Activate | WINFLGF_CloseGadget | WINFLGF_Dragbar
  243.                        | (CB.cb_UserData[0] ? (WINFLGF_SizeGadget|WINFLGF_SizeBBottom):0),
  244.           SCRTAG_IDCMP,   IDCMP_CloseWindow | IDCMP_MouseMove | IDCMP_VanillaKey,
  245.           SCRTAG_UserHandler,    (ULONG)&CB,
  246.           SCRTAG_Width,  80,
  247.           SCRTAG_AutoSizeGadget, (ULONG)Gad,
  248.           SCRTAG_BgFillGfxMap,   (ULONG)BgFillMap,
  249.           TAG_DONE);
  250.  
  251.       if(Win) {
  252.         struct pOS_IntuiMessage *Msg;
  253.         BOOL Ende=FALSE;
  254.         const UWORD MWidth =Win->win_Width;
  255.         const UWORD MHeight=Win->win_Height;
  256.  
  257.         while(!Ende) {
  258.           pOS_WaitPort(Win->win_UserPort);
  259.           while(Msg=(struct pOS_IntuiMessage*)pOS_GetMsg(Win->win_UserPort)) {
  260.             switch(Msg->im_Class) {
  261.  
  262.               case IDCMP_MouseMove:
  263.                 if(Ops[0]) pOS_ChangeWindowBox(Win,Scr->scr_MouseX-4,Scr->scr_MouseY-4,MWidth,MHeight);
  264.                 break;
  265.  
  266.               case IDCMP_VanillaKey:
  267.                 switch(Msg->im_Code) {
  268.  
  269. #if 0
  270.                   case 'a':
  271.                     pOS_SetGadgetAttrs(Win,TextGad,
  272.                       IOBJTAG_String, (ULONG)"Test",
  273.                       ICLTAG_RenderLayMode,0x01,
  274.                       TAG_END);
  275.                     break;
  276. #endif
  277.  
  278.                   case 'r':
  279.                     {
  280.                       struct pOS_TagItem Tags[]={
  281.                         EASYTAG_WindowBusy, (ULONG)Win,
  282.                         TAG_END
  283.                       };
  284.                       struct pOS_EasyStruct ES={
  285.                         sizeof(pOS_EasyStruct),
  286.                         0,0,
  287.                         "Window-Title",
  288.                         "Test-Requester\n\n%s",
  289.                         "_Ok|_Cancel",
  290.                         NULL,NULL,Tags
  291.                       };
  292.  
  293.                       pOS_EasyRequestArgs(NULL,&ES,NULL,NULL);
  294.                     }
  295.                     break;
  296.                 }
  297.                 break;
  298.  
  299.               case IDCMP_CloseWindow:  Ende=TRUE; break;
  300.               default: if(pOS_SysIMessage(Msg)) Msg=NULL;
  301.             }
  302.  
  303.             if(Msg) pOS_ReplyMsg(&Msg->im_Message);
  304.           }
  305.         }
  306.         pOS_CloseWindow(Win);
  307.       }
  308.       else printf("Cannot open window\n");
  309.       pOS_UnlockPubScreen(Scr);
  310.     }
  311.     else printf("Cannot lock PubScreen\n");
  312.  
  313.     if(BgFillMap) pOS_FreeGfxMap(BgFillMap);
  314.     pOS_DeleteDosArgs(Args);  /* Args freigeben */
  315.   }
  316.   else Err=DOSFAIL_FAIL;  /* vollkommen fehlgeschlagen */
  317.  
  318.   pOS_SetShellFail(Err);
  319.  
  320.   pOS_CloseLibrary((pOS_Library*)gb_GfxBase);
  321.   pOS_CloseLibrary((pOS_Library*)gb_IntuiBase);
  322.   pOS_CloseLibrary((pOS_Library*)gb_DtTypeBase);
  323. }
  324.