home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / fish / system_utils / windows&screens / winman / winman.c < prev    next >
C/C++ Source or Header  |  1990-12-20  |  6KB  |  231 lines

  1. /*======================================*/
  2. /*                                                                            */
  3. /* Simple window manager V1.0                        */
  4. /*                                                                            */
  5. /* © J.Tyberghein.                                            */
  6. /*        Sun Sep 23 21:05:52 1990                    */
  7. /*                                                                            */
  8. /*======================================*/
  9.  
  10.  
  11. #include <exec/types.h>
  12. #include <exec/memory.h>
  13. #include <graphics/gfx.h>
  14. #include <graphics/gfxmacros.h>
  15. #include <intuition/intuitionbase.h>
  16. #include <proto/exec.h>
  17. #include <proto/intuition.h>
  18. #include <proto/wb.h>
  19. #include <proto/dos.h>
  20. #include <clib/dos_protos.h>
  21. #include <clib/exec_protos.h>
  22. #include <clib/intuition_protos.h>
  23. #include <clib/wb_protos.h>
  24. #include <workbench/workbench.h>
  25. #include <string.h>
  26.  
  27. /*** Menu ID's ***/
  28. #define MENU_QUIT        1000
  29. #define MENU_MAX        1001
  30. #define MENU_MIN        1002
  31. #define MENU_CASC        1003
  32. #define MENU_HTILE    1004
  33. #define MENU_VTILE    1005
  34. #define MENU_ABOUT    1100
  35.  
  36. /*** Error codes ***/
  37. #define ERR_OPENLIB    -1
  38. #define ERR_PORT        -2
  39. #define ERR_APMENU    -3
  40.  
  41.  
  42. struct MsgPort *port = NULL;
  43.  
  44. extern APTR DOSBase;
  45. struct IntuitionBase *IntuitionBase = NULL;
  46. APTR WorkbenchBase = NULL;
  47. APTR am1 = NULL,am2 = NULL,am3 = NULL,am4 = NULL,am5 = NULL,am6 = NULL,am7 = NULL;
  48.  
  49.  
  50. void __regargs CloseStuff (int rc)
  51. {
  52.     switch (rc)
  53.         {
  54.             case -1 : PutStr ("Error opening library !\n"); break;
  55.             case -2 : PutStr ("Error creating message port !\n"); break;
  56.             case -3 : PutStr ("Error adding menu to workbench !\n"); break;
  57.         }
  58.  
  59.     if (am7) RemoveAppMenuItem (am7);
  60.     if (am6) RemoveAppMenuItem (am6);
  61.     if (am5) RemoveAppMenuItem (am5);
  62.     if (am4) RemoveAppMenuItem (am4);
  63.     if (am3) RemoveAppMenuItem (am3);
  64.     if (am2) RemoveAppMenuItem (am2);
  65.     if (am1) RemoveAppMenuItem (am1);
  66.  
  67.     if (port) DeleteMsgPort (port);
  68.     if (IntuitionBase) CloseLibrary ((struct Library *)IntuitionBase);
  69.     if (WorkbenchBase) CloseLibrary ((struct Library *)WorkbenchBase);
  70.     XCEXIT (rc);
  71. }
  72.  
  73.  
  74. void OpenStuff ()
  75. {
  76.     if (!(IntuitionBase = (struct IntuitionBase *)OpenLibrary ("intuition.library",36L)))
  77.         {
  78.             Write (Output (),"You need AmigaDOS 2.0\n",22);
  79.             CloseStuff (0);
  80.         }
  81.  
  82.     if (!(WorkbenchBase = (APTR )OpenLibrary ("workbench.library",0L)))
  83.         CloseStuff (ERR_OPENLIB);
  84.  
  85.     if (!(port = (struct MsgPort *)CreateMsgPort ()))
  86.         CloseStuff (ERR_PORT);
  87.  
  88.     if (!(am1 = (APTR)AddAppMenuItemA (MENU_QUIT,0,"WM: Quit",port,NULL)))
  89.         CloseStuff (ERR_APMENU);
  90.     if (!(am7 = (APTR)AddAppMenuItemA (MENU_ABOUT,0,"WM: About",port,NULL)))
  91.         CloseStuff (ERR_APMENU);
  92.     if (!(am2 = (APTR)AddAppMenuItemA (MENU_MAX,0,"WM: Maximize",port,NULL)))
  93.         CloseStuff (ERR_APMENU);
  94.     if (!(am3 = (APTR)AddAppMenuItemA (MENU_MIN,0,"WM: Minimize",port,NULL)))
  95.         CloseStuff (ERR_APMENU);
  96.     if (!(am4 = (APTR)AddAppMenuItemA (MENU_CASC,0,"WM: Cascade",port,NULL)))
  97.         CloseStuff (ERR_APMENU);
  98.     if (!(am5 = (APTR)AddAppMenuItemA (MENU_HTILE,0,"WM: Horiz Tile",port,NULL)))
  99.         CloseStuff (ERR_APMENU);
  100.     if (!(am6 = (APTR)AddAppMenuItemA (MENU_VTILE,0,"WM: Vert Tile",port,NULL)))
  101.         CloseStuff (ERR_APMENU);
  102.  
  103. }
  104.  
  105.  
  106. void __regargs Minimize (struct Screen *scr)
  107. {
  108.     struct Window *win;
  109.  
  110.     for (win=scr->FirstWindow ; win ; win=win->NextWindow)
  111.         if (win->Flags & WINDOWSIZING) ChangeWindowBox (win,win->LeftEdge,win->TopEdge,win->MinWidth,win->MinHeight);
  112. }
  113.  
  114.  
  115.  
  116. void __regargs Maximize (struct Screen *scr)
  117. {
  118.     struct Window *win;
  119.  
  120.     for (win=scr->FirstWindow ; win ; win=win->NextWindow)
  121.         if (win->Flags & WINDOWSIZING) ChangeWindowBox (win,0,0,scr->Width,scr->Height);
  122. }
  123.  
  124.  
  125. void __regargs Cascade (struct Screen *scr)
  126. {
  127.     struct Window *win;
  128.     int wd,x,y,w,h,cx,cy;
  129.  
  130.     for (win=scr->FirstWindow,wd=0 ; win ; win=win->NextWindow)
  131.         if ((win->Flags & WINDOWDRAG) || (win->Flags & WINDOWSIZING)) wd++;
  132.  
  133.     cx = cy = (wd-1)*20;
  134.  
  135.     for (win=scr->FirstWindow ; win ; win=win->NextWindow)
  136.         {
  137.             x = win->LeftEdge;
  138.             y = win->TopEdge;
  139.             w = win->Width;
  140.             h = win->Height;
  141.             if (win->Flags & WINDOWDRAG) { x = cx; y = cy; }
  142.             if (win->Flags & WINDOWSIZING) { w = scr->Width-x; h = scr->Height-y; }
  143.             if ((win->Flags & WINDOWDRAG) || (win->Flags & WINDOWSIZING))
  144.                 {
  145.                     ChangeWindowBox (win,x,y,w,h);
  146.                     WindowToBack (win);
  147.                     cx -= 20;
  148.                     cy -= 20;
  149.                     if (cx>scr->Width-20 || cy>scr->Height-20) return;
  150.                 }
  151.         }
  152. }
  153.  
  154.  
  155. void __regargs HorizTile (struct Screen *scr)
  156. {
  157.     struct Window *win;
  158.     int wd,cx,cw;
  159.  
  160.     for (win=scr->FirstWindow,wd=0 ; win ; win=win->NextWindow)
  161.         if ((win->Flags & WINDOWDRAG) && (win->Flags & WINDOWSIZING)) wd++;
  162.  
  163.     cx = 0;
  164.     if (wd) cw = scr->Width/wd;
  165.  
  166.     for (win=scr->FirstWindow ; win ; win=win->NextWindow)
  167.         if ((win->Flags & WINDOWDRAG) && (win->Flags & WINDOWSIZING))
  168.             {
  169.                 ChangeWindowBox (win,cx,0,cw,scr->Height);
  170.                 cx += cw;;
  171.             }
  172. }
  173.  
  174.  
  175. void __regargs VertTile (struct Screen *scr)
  176. {
  177.     struct Window *win;
  178.     int wd,cy,ch;
  179.  
  180.     for (win=scr->FirstWindow,wd=0 ; win ; win=win->NextWindow)
  181.         if ((win->Flags & WINDOWDRAG) && (win->Flags & WINDOWSIZING)) wd++;
  182.  
  183.     cy = 0;
  184.     if (wd) ch = scr->Height/wd;
  185.  
  186.     for (win=scr->FirstWindow ; win ; win=win->NextWindow)
  187.         if ((win->Flags & WINDOWDRAG) && (win->Flags & WINDOWSIZING))
  188.             {
  189.                 ChangeWindowBox (win,0,cy,scr->Width,ch);
  190.                 cy += ch;;
  191.             }
  192. }
  193.  
  194.  
  195. void argmain ()
  196. {
  197.     unsigned int x,y;
  198.     struct Screen *scr;
  199.     struct AppMessage *apm;
  200.     ULONG ID;
  201.  
  202.     OpenStuff ();
  203.  
  204.     Requester ("Window manager","","Installed",0);
  205.  
  206.     x = y = 50;
  207.     do
  208.         {
  209.             WaitPort (port);
  210.             apm = (struct AppMessage *)GetMsg (port);
  211.             ID = apm->am_ID;
  212.             ReplyMsg ((struct Message *)apm);
  213.  
  214.             Forbid ();
  215.             scr = IntuitionBase->FirstScreen;
  216.             switch (ID)
  217.                 {
  218.                     case MENU_MAX        : Maximize (scr); break;
  219.                     case MENU_MIN        : Minimize (scr); break;
  220.                     case MENU_CASC    : Cascade (scr); break;
  221.                     case MENU_HTILE    : HorizTile (scr); break;
  222.                     case MENU_VTILE    : VertTile (scr); break;
  223.                     case MENU_ABOUT    : Requester ("Window manager V1.0","Written by J.Tyberghein","23 Sep 1990",0); break;
  224.                 }
  225.             Permit ();
  226.         }
  227.     while (ID != MENU_QUIT);
  228.  
  229.     CloseStuff (0);
  230. }
  231.