home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / may94 / util / edit / jade.lha / Jade / src / amiga_windows.c < prev    next >
C/C++ Source or Header  |  1994-04-19  |  17KB  |  667 lines

  1. /* amiga_windows.c -- Window handling for AmigaDOS
  2.    Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
  3.  
  4. This file is part of Jade.
  5.  
  6. Jade is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. Jade is distributed in the hope that it will be useful, but
  12. WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with Jade; see the file COPYING.    If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "jade.h"
  21. #include "jade_protos.h"
  22. #include "revision.h"
  23.  
  24. /* The SET_WRITE_MASK() things needs all this.    */
  25. #ifdef _DCC
  26. # define  GfxBase_DECLARED
  27. #endif
  28. #include <clib/graphics_protos.h>
  29. #include <graphics/gfxbase.h>
  30. #include <graphics/gfxmacros.h>
  31. extern struct GfxBase *GfxBase;
  32.  
  33. #define INTUI_V36_NAMES_ONLY
  34. #include <clib/intuition_protos.h>
  35. #include <intuition/gadgetclass.h>
  36. #include <clib/diskfont_protos.h>
  37. #include <string.h>
  38. #include <stdlib.h>
  39.  
  40. _PR int sleepwin(VW *);
  41. _PR int unsleep(VW *);
  42. _PR void os_newvw(VW *);
  43. _PR void os_killvw(VW *);
  44. _PR void updatedimensions(VW *);
  45. _PR void updatescroller(VW *);
  46. _PR struct Window *newwindow(VW *, VW *, bool);
  47. _PR void killwindow(VW *);
  48. static void CloseSharedWindow(struct Window *);
  49. static void StripIntuiMessages(struct MsgPort *, struct Window *);
  50. _PR struct IntuiMessage *GetWinIMsg(struct Window *);
  51. _PR void activatewin(VW *);
  52. _PR void setvwtitle(VW *);
  53. _PR void setvwpos(VW *, long, long, long, long);
  54. _PR int ezreq(u_char *, u_char *, long, ...);
  55. _PR int setfont(VW *);
  56. _PR void unsetfont(VW *);
  57. _PR void resetslptxtitles(TX *);
  58. _PR bool makemousepos(POS *, VW *);
  59. _PR void sys_windows_init(void);
  60.  
  61. #define IDCMP (IDCMP_NEWSIZE | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE \
  62.     | IDCMP_MENUPICK | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY \
  63.     | IDCMP_ACTIVEWINDOW | IDCMP_GADGETUP | IDCMP_GADGETUP \
  64.     | IDCMP_INTUITICKS)
  65.  
  66. #define SIDCMP (IDCMP_MOUSEBUTTONS | IDCMP_RAWKEY | IDCMP_INTUITICKS)
  67.  
  68. #define WFLAGS (WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET \
  69.     | WFLG_SIZEGADGET | WFLG_REPORTMOUSE | WFLG_ACTIVATE | WFLG_RMBTRAP \
  70.     | WFLG_SMART_REFRESH | WFLG_NOCAREREFRESH)
  71.  
  72. #define SWFLAGS (WFLG_DRAGBAR | WFLG_ACTIVATE \
  73.     | WFLG_SMART_REFRESH | WFLG_NOCAREREFRESH | WFLG_RMBTRAP)
  74.  
  75. static const u_char *ScreenTitle = VERSSTRING;
  76. static struct MsgPort *SharedPort;
  77.  
  78. #ifdef AMIGA_NEED_VARARGS_STUBS
  79. ULONG
  80. SetGadgetAttrs(struct Gadget *gadget, struct Window *window, struct Requester *req, unsigned long tag1, ...)
  81. {
  82.     return(SetGadgetAttrsA(gadget, window, req, (struct TagItem *)&tag1));
  83. }
  84. APTR
  85. NewObject(struct IClass *class, UBYTE *classID, unsigned long tag1, ...)
  86. {
  87.     return(NewObjectA(class, classID, (struct TagItem *)&tag1));
  88. }
  89. #endif /* AMIGA_NEEDS_VARARGS_STUBS */
  90.  
  91. /*
  92.  * Have I screwed this up??
  93.  */
  94. int
  95. sleepwin(VW *vw)
  96. {
  97.     int rc = FALSE;
  98.     struct Window *swin;
  99.     if(swin = OpenWindowTags(NULL,
  100.                  WA_Left, vw->vw_Window->LeftEdge,
  101.                  WA_Top, vw->vw_Window->TopEdge,
  102.                  WA_Width, 150,
  103.                  WA_Height, vw->vw_Window->BorderTop,
  104.                  WA_IDCMP, 0,
  105.                  WA_Flags, SWFLAGS,
  106.                  WA_Title, VSTR(vw->vw_Tx->tx_BufferName),
  107.                  WA_ScreenTitle, ScreenTitle,
  108.                  WA_AutoAdjust, TRUE,
  109.                  WA_PubScreenName, VSTR(vw->vw_WindowSys.ws_ScreenName),
  110.                  WA_PubScreenFallBack, TRUE,
  111.                  TAG_END))
  112.     {
  113.     swin->UserPort = SharedPort;
  114.     ModifyIDCMP(swin, SIDCMP);
  115.  
  116.     vw->vw_WindowSys.ws_OldDimensions[0] = vw->vw_Window->LeftEdge;
  117.     vw->vw_WindowSys.ws_OldDimensions[1] = vw->vw_Window->TopEdge;
  118.     vw->vw_WindowSys.ws_OldDimensions[2] = vw->vw_Window->Width;
  119.     vw->vw_WindowSys.ws_OldDimensions[3] = vw->vw_Window->Height;
  120.  
  121.     clearmenu(vw->vw_Window);
  122.     Forbid();
  123.     StripIntuiMessages(vw->vw_Window->UserPort, vw->vw_Window);
  124.     vw->vw_Window->UserPort = NULL;
  125.     ModifyIDCMP(vw->vw_Window, 0L);
  126.     Permit();
  127.     CloseWindow(vw->vw_Window);
  128. #ifndef NOSCRLBAR
  129.     if(!vw->vw_Sleeping && vw->vw_SBar.gad)
  130.     {
  131.         DisposeObject(vw->vw_SBar.gad);
  132.         vw->vw_SBar.gad = NULL;
  133.     }
  134. #endif
  135.     vw->vw_Window = swin;
  136.     vw->vw_WindowSys.ws_Rp = swin->RPort;
  137.     vw->vw_Sleeping = TRUE;
  138.     swin->UserData = (BYTE *)vw;
  139.     rc = TRUE;
  140.     }
  141.     else
  142.     cmd_signal(sym_error, LIST_1(MKSTR("Can't open window")));
  143.     return(rc);
  144. }
  145.  
  146. int
  147. unsleep(VW *vw)
  148. {
  149.     int rc = TRUE;
  150.     if(vw->vw_Sleeping)
  151.     {
  152.     struct Window *oldwin = vw->vw_Window;
  153.     if(newwindow(vw, vw, FALSE))
  154.     {
  155.         Forbid();
  156.         StripIntuiMessages(oldwin->UserPort, oldwin);
  157.         oldwin->UserPort = NULL;
  158.         ModifyIDCMP(oldwin, 0L);
  159.         Permit();
  160.         CloseWindow(oldwin);
  161.         vw->vw_Sleeping = FALSE;
  162.         updatedimensions(vw);
  163. #ifndef NOSCRLBAR
  164.         updatescroller(vw);
  165. #endif
  166.         vw->vw_Flags |= VWFF_FORCE_REFRESH;
  167.     }
  168.     else
  169.         rc = FALSE;
  170.     }
  171.     return(rc);
  172. }
  173.  
  174. void
  175. os_newvw(VW *vw)
  176. {
  177.     ;
  178. }
  179. void
  180. os_killvw(VW *vw)
  181. {
  182. }
  183.  
  184. void
  185. updatedimensions(VW *vw)
  186. {
  187.     if(vw->vw_Window && !vw->vw_Sleeping)
  188.     {
  189.     struct Window *wd = vw->vw_Window;
  190.  
  191.     vw->vw_XStartPix = (UWORD)wd->BorderLeft;
  192.     vw->vw_YStartPix = (UWORD)wd->BorderTop;
  193.     vw->vw_XEndPix = wd->Width - (UWORD)wd->BorderRight - 1;
  194.     vw->vw_YEndPix = wd->Height - (UWORD)wd->BorderBottom;
  195.     vw->vw_XWidthPix = vw->vw_XEndPix - vw->vw_XStartPix;
  196.     vw->vw_YHeightPix = vw->vw_YEndPix - vw->vw_YStartPix;
  197.  
  198.     vw->vw_FontStart = vw->vw_YStartPix + vw->vw_Font->tf_Baseline;
  199.  
  200.     vw->vw_MaxX = (vw->vw_XWidthPix / vw->vw_FontX);
  201.     vw->vw_MaxY = (vw->vw_YHeightPix / vw->vw_FontY);
  202.     if((vw->vw_XStepRatio <= 0)
  203.        || ((vw->vw_XStep = vw->vw_MaxX / vw->vw_XStepRatio) <= 0))
  204.         vw->vw_XStep = 1;
  205.     if((vw->vw_YStepRatio <= 0)
  206.        || ((vw->vw_YStep = vw->vw_MaxY / vw->vw_YStepRatio) <= 0))
  207.         vw->vw_YStep = 1;
  208.     }
  209. }
  210.  
  211. #ifndef NOSCRLBAR
  212. void
  213. updatescroller(VW *vw)
  214. {
  215.     if(!vw->vw_Sleeping && vw->vw_SBar.gad)
  216.     {
  217.     vw->vw_SBar.top = vw->vw_StartLine;
  218.     vw->vw_SBar.total = vw->vw_Tx->tx_NumLines;
  219.     SetGadgetAttrs(vw->vw_SBar.gad, vw->vw_Window, NULL,
  220.                PGA_Visible, vw->vw_MaxY,
  221.                PGA_Total, vw->vw_SBar.total,
  222.                PGA_Top, vw->vw_SBar.top,
  223.                TAG_END);
  224.     }
  225. }
  226. #endif
  227.  
  228. /*
  229.  * Opens an editor window. Sets up the shared IDCMP
  230.  */
  231. struct Window *
  232. newwindow(VW *oldVW, VW *vw, bool useDefDims)
  233. {
  234.     u_short *dimensions;
  235.     struct Screen *scr;
  236.     struct Window *res = NULL;
  237.     bool truedims = FALSE;
  238.     if(!useDefDims && oldVW)
  239.     {
  240.     if(oldVW->vw_Sleeping)
  241.         dimensions = oldVW->vw_WindowSys.ws_OldDimensions;
  242.     else
  243.         dimensions = &oldVW->vw_Window->LeftEdge;
  244.     truedims = TRUE;
  245.     }
  246.     else
  247.     dimensions = DefDims;
  248.     if(scr = LockPubScreen(*VSTR(vw->vw_WindowSys.ws_ScreenName)
  249.                ? VSTR(vw->vw_WindowSys.ws_ScreenName)
  250.                : NULL))
  251.     {
  252. #ifndef NOSCRLBAR
  253.     if(vw->vw_SBar.gad = NewObject(NULL, "propgclass",
  254.                        GA_RelRight, -13,
  255.                        GA_Top, 1 + scr->WBorTop + scr->Font->ta_YSize + 1,
  256.                        GA_Width, 10,
  257.                        GA_RelHeight, -12 - (scr->WBorTop + scr->Font->ta_YSize + 1),
  258.                        GA_RelVerify, TRUE,
  259.                        GA_Immediate, TRUE,
  260.                        GA_FollowMouse, TRUE,
  261.                        GA_RightBorder, TRUE,
  262.                        PGA_Borderless, TRUE,
  263.                        PGA_Freedom, FREEVERT,
  264.                        PGA_Total, 1,
  265.                        PGA_Visible, 1,
  266.                        PGA_Top, 0,
  267.                        PGA_NewLook, TRUE,
  268.                        TAG_END))
  269.     {
  270. #endif
  271.         if(res = OpenWindowTags(NULL,
  272.                     WA_Left, dimensions[0],
  273.                     WA_Top, dimensions[1],
  274.                     WA_InnerWidth, truedims ? dimensions[2] : (dimensions[2] * vw->vw_FontX + 1),
  275.                     WA_InnerHeight, truedims ? dimensions[3] : (dimensions[3] * vw->vw_FontY),
  276.                     WA_IDCMP, SharedPort ? 0 : IDCMP,
  277.                     WA_MinWidth, 80,
  278.                     WA_MinHeight, 40,
  279.                     WA_MaxWidth, ~0,
  280.                     WA_MaxHeight, ~0,
  281. #if AMIGA_INCLUDE_VER >= 39
  282.                     WA_Flags, WFLAGS | WFLG_NEWLOOKMENUS,
  283. #else
  284.                     WA_Flags, WFLAGS,
  285. #endif
  286. #ifndef NOSCRLBAR
  287.                     WA_Gadgets, vw->vw_SBar.gad,
  288. #endif
  289.                     WA_ScreenTitle, ScreenTitle,
  290.                     WA_AutoAdjust, TRUE,
  291.                     WA_PubScreen, scr,
  292.                     WA_RptQueue, 2,
  293.                     TAG_END))
  294.         {
  295.         if(SharedPort)
  296.         {
  297.             res->