home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD1.bin / new / util / edit / jade / src / amiga_windows.c < prev    next >
C/C++ Source or Header  |  1994-10-01  |  17KB  |  662 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 sys_sleep_vw(VW *);
  41. _PR int sys_unsleep_vw(VW *);
  42. _PR void sys_new_vw(VW *);
  43. _PR void sys_kill_vw(VW *);
  44. _PR void sys_update_dimensions(VW *);
  45. _PR void sys_update_scroller(VW *);
  46. _PR struct Window *sys_new_window(VW *, VW *, bool);
  47. _PR void sys_kill_window(VW *);
  48. static void close_shared_window(struct Window *);
  49. static void strip_intui_messages(struct MsgPort *, struct Window *);
  50. _PR struct IntuiMessage *ami_get_win_imsg(struct Window *);
  51. _PR void sys_activate_win(VW *);
  52. _PR void sys_set_vw_pos(VW *, long, long, long, long);
  53. _PR int ami_ezreq(u_char *, u_char *, long, ...);
  54. _PR int sys_set_font(VW *);
  55. _PR void sys_unset_font(VW *);
  56. _PR void sys_reset_sleep_titles(TX *);
  57. _PR bool sys_get_mouse_pos(POS *, VW *);
  58. _PR void sys_windows_init(void);
  59.  
  60. #define IDCMP (IDCMP_NEWSIZE | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE \
  61.     | IDCMP_MENUPICK | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY \
  62.     | IDCMP_ACTIVEWINDOW | IDCMP_GADGETUP | IDCMP_GADGETUP \
  63.     | IDCMP_INTUITICKS)
  64.  
  65. #define SIDCMP (IDCMP_MOUSEBUTTONS | IDCMP_RAWKEY | IDCMP_INTUITICKS)
  66.  
  67. #define WFLAGS (WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET \
  68.     | WFLG_SIZEGADGET | WFLG_REPORTMOUSE | WFLG_ACTIVATE | WFLG_RMBTRAP \
  69.     | WFLG_SMART_REFRESH | WFLG_NOCAREREFRESH)
  70.  
  71. #define SWFLAGS (WFLG_DRAGBAR | WFLG_ACTIVATE \
  72.     | WFLG_SMART_REFRESH | WFLG_NOCAREREFRESH | WFLG_RMBTRAP)
  73.  
  74. static const u_char *window_title = VERSSTRING;
  75. static struct MsgPort *shared_window_port;
  76.  
  77. #ifdef AMIGA_NEED_VARARGS_STUBS
  78. ULONG
  79. SetGadgetAttrs(struct Gadget *gadget, struct Window *window, struct Requester *req, unsigned long tag1, ...)
  80. {
  81.     return(SetGadgetAttrsA(gadget, window, req, (struct TagItem *)&tag1));
  82. }
  83. APTR
  84. NewObject(struct IClass *class, UBYTE *classID, unsigned long tag1, ...)
  85. {
  86.     return(NewObjectA(class, classID, (struct TagItem *)&tag1));
  87. }
  88. #endif /* AMIGA_NEEDS_VARARGS_STUBS */
  89.  
  90. /*
  91.  * Have I screwed this up??
  92.  */
  93. int
  94. sys_sleep_vw(VW *vw)
  95. {
  96.     int rc = FALSE;
  97.     struct Window *swin;
  98.     if(swin = OpenWindowTags(NULL,
  99.                  WA_Left, vw->vw_Window->LeftEdge,
  100.                  WA_Top, vw->vw_Window->TopEdge,
  101.                  WA_Width, 150,
  102.                  WA_Height, vw->vw_Window->BorderTop,
  103.                  WA_IDCMP, 0,
  104.                  WA_Flags, SWFLAGS,
  105.                  WA_Title, VSTR(vw->vw_Tx->tx_BufferName),
  106.                  WA_AutoAdjust, TRUE,
  107.                  WA_PubScreenName, VSTR(vw->vw_WindowSys.ws_ScreenName),
  108.                  WA_PubScreenFallBack, TRUE,
  109.                  TAG_END))
  110.     {
  111.     swin->UserPort = shared_window_port;
  112.     ModifyIDCMP(swin, SIDCMP);
  113.  
  114.     vw->vw_WindowSys.ws_OldDimensions[0] = vw->vw_Window->LeftEdge;
  115.     vw->vw_WindowSys.ws_OldDimensions[1] = vw->vw_Window->TopEdge;
  116.     vw->vw_WindowSys.ws_OldDimensions[2] = vw->vw_Window->Width;
  117.     vw->vw_WindowSys.ws_OldDimensions[3] = vw->vw_Window->Height;
  118.  
  119.     ami_clear_menu(vw->vw_Window);
  120.     Forbid();
  121.     strip_intui_messages(vw->vw_Window->UserPort, vw->vw_Window);
  122.     vw->vw_Window->UserPort = NULL;
  123.     ModifyIDCMP(vw->vw_Window, 0L);
  124.     Permit();
  125.     CloseWindow(vw->vw_Window);
  126. #ifndef NOSCRLBAR
  127.     if(((vw->vw_Flags & VWFF_SLEEPING) == 0) && vw->vw_SBar.gad)
  128.     {
  129.         DisposeObject(vw->vw_SBar.gad);
  130.         vw->vw_SBar.gad = NULL;
  131.     }
  132. #endif
  133.     vw->vw_Window = swin;
  134.     vw->vw_WindowSys.ws_Rp = swin->RPort;
  135.     vw->vw_Flags |= VWFF_SLEEPING;
  136.     swin->UserData = (BYTE *)vw;
  137.     rc = TRUE;
  138.     }
  139.     else
  140.     cmd_signal(sym_error, LIST_1(MKSTR("Can't open window")));
  141.     return(rc);
  142. }
  143.  
  144. int
  145. sys_unsleep_vw(VW *vw)
  146. {
  147.     int rc = TRUE;
  148.     if(vw->vw_Flags & VWFF_SLEEPING)
  149.     {
  150.     struct Window *oldwin = vw->vw_Window;
  151.     if(sys_new_window(vw, vw, FALSE))
  152.     {
  153.         Forbid();
  154.         strip_intui_messages(oldwin->UserPort, oldwin);
  155.         oldwin->UserPort = NULL;
  156.         ModifyIDCMP(oldwin, 0L);
  157.         Permit();
  158.         CloseWindow(oldwin);
  159.         vw->vw_Flags &= ~VWFF_MESSAGE;
  160.         sys_update_dimensions(vw);
  161. #ifndef NOSCRLBAR
  162.         sys_update_scroller(vw);
  163. #endif
  164.         vw->vw_Flags |= VWFF_FORCE_REFRESH;
  165.     }
  166.     else
  167.         rc = FALSE;
  168.     }
  169.     return(rc);
  170. }
  171.  
  172. void
  173. sys_new_vw(VW *vw)
  174. {
  175. }
  176.  
  177. void
  178. sys_kill_vw(VW *vw)
  179. {
  180. }
  181.  
  182. void
  183. sys_update_dimensions(VW *vw)
  184. {
  185.     if(vw->vw_Window && ((vw->vw_Flags & VWFF_SLEEPING) == 0))
  186.     {
  187.     struct Window *wd = vw->vw_Window;
  188.  
  189.     vw->vw_MessageLineY = wd->Height - wd->BorderBottom
  190.         - vw->vw_FontY - 2;
  191.     vw->vw_MessageFontY = vw->vw_MessageLineY + 2 + FONT_ASCENT(vw);
  192.  
  193.     vw->vw_XStartPix = (UWORD)wd->BorderLeft;
  194.     vw->vw_YStartPix = (UWORD)wd->BorderTop;
  195.     vw->vw_XEndPix = wd->Width - (UWORD)wd->BorderRight - 1;
  196.     vw->vw_YEndPix = (vw->vw_MessageLineY - 1);
  197.     vw->vw_XWidthPix = vw->vw_XEndPix - vw->vw_XStartPix;
  198.     vw->vw_YHeightPix = vw->vw_YEndPix - vw->vw_YStartPix;
  199.  
  200.     vw->vw_FontStart = vw->vw_YStartPix + vw->vw_Font->tf_Baseline;
  201.  
  202.     vw->vw_MaxX = (vw->vw_XWidthPix / vw->vw_FontX);
  203.     vw->vw_MaxY = (vw->vw_YHeightPix / vw->vw_FontY);
  204.     if((vw->vw_XStepRatio <= 0)
  205.        || ((vw->vw_XStep = vw->vw_MaxX / vw->vw_XStepRatio) <= 0))
  206.         vw->vw_XStep = 1;
  207.     if((vw->vw_YStepRatio <= 0)
  208.        || ((vw->vw_YStep = vw->vw_MaxY / vw->vw_YStepRatio) <= 0))
  209.         vw->vw_YStep = 1;
  210.     }
  211. }
  212.  
  213. #ifndef NOSCRLBAR
  214. void
  215. sys_update_scroller(VW *vw)
  216. {
  217.     if(((vw->vw_Flags & VWFF_SLEEPING) == 0) && vw->vw_SBar.gad)
  218.     {
  219.     vw->vw_SBar.top = vw->vw_StartLine;
  220.     vw->vw_SBar.total = vw->vw_Tx->tx_NumLines;
  221.     SetGadgetAttrs(vw->vw_SBar.gad, vw->vw_Window, NULL,
  222.                PGA_Visible, vw->vw_MaxY,
  223.                PGA_Total, vw->vw_SBar.total,
  224.                PGA_Top, vw->vw_SBar.top,
  225.                TAG_END);
  226.     }
  227. }
  228. #endif
  229.  
  230. /*
  231.  * Opens an editor window. Sets up the shared IDCMP
  232.  */
  233. struct Window *
  234. sys_new_window(VW *oldVW, VW *vw, bool useDefDims)
  235. {
  236.     u_short *dimensions;
  237.     struct Screen *scr;
  238.     struct Window *res = NULL;
  239.     bool truedims = FALSE;
  240.     if(!useDefDims && oldVW)
  241.     {
  242.     if(oldVW->vw_Flags & VWFF_SLEEPING)
  243.         dimensions = oldVW->vw_WindowSys.ws_OldDimensions;
  244.     else
  245.         dimensions = &oldVW->vw_Window->LeftEdge;
  246.     truedims = TRUE;
  247.     }
  248.     else
  249.     dimensions = def_dims;
  250.     if(scr = LockPubScreen(*VSTR(vw->vw_WindowSys.ws_ScreenName)
  251.                ? VSTR(vw->vw_WindowSys.ws_ScreenName)
  252.                : NULL))
  253.     {
  254. #ifndef NOSCRLBAR
  255.     if(vw->vw_SBar.gad = NewObject(NULL, "propgclass",
  256.                        GA_RelRight, -13,
  257.                        GA_Top, 1 + scr->WBorTop + scr->Font->ta_YSize + 1,
  258.                        GA_Width, 10,
  259.                        GA_RelHeight, -12 - (scr->WBorTop + scr->Font->ta_YSize + 1),
  260.                        GA_RelVerify, TRUE,
  261.                        GA_Immediate, TRUE,
  262.                        GA_FollowMouse, TRUE,
  263.                        GA_RightBorder, TRUE,
  264.                        PGA_Borderless, TRUE,
  265.                        PGA_Freedom, FREEVERT,
  266.                        PGA_Total, 1,
  267.                        PGA_Visible, 1,
  268.                        PGA_Top, 0,
  269.                        PGA_NewLook, TRUE,
  270.                        TAG_END))
  271.     {
  272. #endif
  273.         if(res = OpenWindowTags(NULL,
  274.                     WA_Left, dimensions[0],
  275.                     WA_Top, dimensions[1],
  276.                     WA_InnerWidth, truedims ? dimensions[2] : (dimensions[2] * vw->vw_FontX + 1),
  277.                     WA_InnerHeight, truedims ? dimensions[3] : (dimensions[3] + 1) * vw->vw_FontY + 3,
  278.                     WA_IDCMP, shared_window_port ? 0 : IDCMP,
  279.                     WA_MinWidth, 80,
  280.                     WA_MinHeight, 40,
  281.                     WA_MaxWidth, ~0,
  282.