home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
new
/
util
/
edit
/
jade
/
src
/
amiga_windows.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-10-01
|
17KB
|
662 lines
/* amiga_windows.c -- Window handling for AmigaDOS
Copyright (C) 1993, 1994 John Harper <jsh@ukc.ac.uk>
This file is part of Jade.
Jade is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
Jade is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Jade; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include "jade.h"
#include "jade_protos.h"
#include "revision.h"
/* The SET_WRITE_MASK() things needs all this. */
#ifdef _DCC
# define GfxBase_DECLARED
#endif
#include <clib/graphics_protos.h>
#include <graphics/gfxbase.h>
#include <graphics/gfxmacros.h>
extern struct GfxBase *GfxBase;
#define INTUI_V36_NAMES_ONLY
#include <clib/intuition_protos.h>
#include <intuition/gadgetclass.h>
#include <clib/diskfont_protos.h>
#include <string.h>
#include <stdlib.h>
_PR int sys_sleep_vw(VW *);
_PR int sys_unsleep_vw(VW *);
_PR void sys_new_vw(VW *);
_PR void sys_kill_vw(VW *);
_PR void sys_update_dimensions(VW *);
_PR void sys_update_scroller(VW *);
_PR struct Window *sys_new_window(VW *, VW *, bool);
_PR void sys_kill_window(VW *);
static void close_shared_window(struct Window *);
static void strip_intui_messages(struct MsgPort *, struct Window *);
_PR struct IntuiMessage *ami_get_win_imsg(struct Window *);
_PR void sys_activate_win(VW *);
_PR void sys_set_vw_pos(VW *, long, long, long, long);
_PR int ami_ezreq(u_char *, u_char *, long, ...);
_PR int sys_set_font(VW *);
_PR void sys_unset_font(VW *);
_PR void sys_reset_sleep_titles(TX *);
_PR bool sys_get_mouse_pos(POS *, VW *);
_PR void sys_windows_init(void);
#define IDCMP (IDCMP_NEWSIZE | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE \
| IDCMP_MENUPICK | IDCMP_CLOSEWINDOW | IDCMP_RAWKEY \
| IDCMP_ACTIVEWINDOW | IDCMP_GADGETUP | IDCMP_GADGETUP \
| IDCMP_INTUITICKS)
#define SIDCMP (IDCMP_MOUSEBUTTONS | IDCMP_RAWKEY | IDCMP_INTUITICKS)
#define WFLAGS (WFLG_DRAGBAR | WFLG_DEPTHGADGET | WFLG_CLOSEGADGET \
| WFLG_SIZEGADGET | WFLG_REPORTMOUSE | WFLG_ACTIVATE | WFLG_RMBTRAP \
| WFLG_SMART_REFRESH | WFLG_NOCAREREFRESH)
#define SWFLAGS (WFLG_DRAGBAR | WFLG_ACTIVATE \
| WFLG_SMART_REFRESH | WFLG_NOCAREREFRESH | WFLG_RMBTRAP)
static const u_char *window_title = VERSSTRING;
static struct MsgPort *shared_window_port;
#ifdef AMIGA_NEED_VARARGS_STUBS
ULONG
SetGadgetAttrs(struct Gadget *gadget, struct Window *window, struct Requester *req, unsigned long tag1, ...)
{
return(SetGadgetAttrsA(gadget, window, req, (struct TagItem *)&tag1));
}
APTR
NewObject(struct IClass *class, UBYTE *classID, unsigned long tag1, ...)
{
return(NewObjectA(class, classID, (struct TagItem *)&tag1));
}
#endif /* AMIGA_NEEDS_VARARGS_STUBS */
/*
* Have I screwed this up??
*/
int
sys_sleep_vw(VW *vw)
{
int rc = FALSE;
struct Window *swin;
if(swin = OpenWindowTags(NULL,
WA_Left, vw->vw_Window->LeftEdge,
WA_Top, vw->vw_Window->TopEdge,
WA_Width, 150,
WA_Height, vw->vw_Window->BorderTop,
WA_IDCMP, 0,
WA_Flags, SWFLAGS,
WA_Title, VSTR(vw->vw_Tx->tx_BufferName),
WA_AutoAdjust, TRUE,
WA_PubScreenName, VSTR(vw->vw_WindowSys.ws_ScreenName),
WA_PubScreenFallBack, TRUE,
TAG_END))
{
swin->UserPort = shared_window_port;
ModifyIDCMP(swin, SIDCMP);
vw->vw_WindowSys.ws_OldDimensions[0] = vw->vw_Window->LeftEdge;
vw->vw_WindowSys.ws_OldDimensions[1] = vw->vw_Window->TopEdge;
vw->vw_WindowSys.ws_OldDimensions[2] = vw->vw_Window->Width;
vw->vw_WindowSys.ws_OldDimensions[3] = vw->vw_Window->Height;
ami_clear_menu(vw->vw_Window);
Forbid();
strip_intui_messages(vw->vw_Window->UserPort, vw->vw_Window);
vw->vw_Window->UserPort = NULL;
ModifyIDCMP(vw->vw_Window, 0L);
Permit();
CloseWindow(vw->vw_Window);
#ifndef NOSCRLBAR
if(((vw->vw_Flags & VWFF_SLEEPING) == 0) && vw->vw_SBar.gad)
{
DisposeObject(vw->vw_SBar.gad);
vw->vw_SBar.gad = NULL;
}
#endif
vw->vw_Window = swin;
vw->vw_WindowSys.ws_Rp = swin->RPort;
vw->vw_Flags |= VWFF_SLEEPING;
swin->UserData = (BYTE *)vw;
rc = TRUE;
}
else
cmd_signal(sym_error, LIST_1(MKSTR("Can't open window")));
return(rc);
}
int
sys_unsleep_vw(VW *vw)
{
int rc = TRUE;
if(vw->vw_Flags & VWFF_SLEEPING)
{
struct Window *oldwin = vw->vw_Window;
if(sys_new_window(vw, vw, FALSE))
{
Forbid();
strip_intui_messages(oldwin->UserPort, oldwin);
oldwin->UserPort = NULL;
ModifyIDCMP(oldwin, 0L);
Permit();
CloseWindow(oldwin);
vw->vw_Flags &= ~VWFF_MESSAGE;
sys_update_dimensions(vw);
#ifndef NOSCRLBAR
sys_update_scroller(vw);
#endif
vw->vw_Flags |= VWFF_FORCE_REFRESH;
}
else
rc = FALSE;
}
return(rc);
}
void
sys_new_vw(VW *vw)
{
}
void
sys_kill_vw(VW *vw)
{
}
void
sys_update_dimensions(VW *vw)
{
if(vw->vw_Window && ((vw->vw_Flags & VWFF_SLEEPING) == 0))
{
struct Window *wd = vw->vw_Window;
vw->vw_MessageLineY = wd->Height - wd->BorderBottom
- vw->vw_FontY - 2;
vw->vw_MessageFontY = vw->vw_MessageLineY + 2 + FONT_ASCENT(vw);
vw->vw_XStartPix = (UWORD)wd->BorderLeft;
vw->vw_YStartPix = (UWORD)wd->BorderTop;
vw->vw_XEndPix = wd->Width - (UWORD)wd->BorderRight - 1;
vw->vw_YEndPix = (vw->vw_MessageLineY - 1);
vw->vw_XWidthPix = vw->vw_XEndPix - vw->vw_XStartPix;
vw->vw_YHeightPix = vw->vw_YEndPix - vw->vw_YStartPix;
vw->vw_FontStart = vw->vw_YStartPix + vw->vw_Font->tf_Baseline;
vw->vw_MaxX = (vw->vw_XWidthPix / vw->vw_FontX);
vw->vw_MaxY = (vw->vw_YHeightPix / vw->vw_FontY);
if((vw->vw_XStepRatio <= 0)
|| ((vw->vw_XStep = vw->vw_MaxX / vw->vw_XStepRatio) <= 0))
vw->vw_XStep = 1;
if((vw->vw_YStepRatio <= 0)
|| ((vw->vw_YStep = vw->vw_MaxY / vw->vw_YStepRatio) <= 0))
vw->vw_YStep = 1;
}
}
#ifndef NOSCRLBAR
void
sys_update_scroller(VW *vw)
{
if(((vw->vw_Flags & VWFF_SLEEPING) == 0) && vw->vw_SBar.gad)
{
vw->vw_SBar.top = vw->vw_StartLine;
vw->vw_SBar.total = vw->vw_Tx->tx_NumLines;
SetGadgetAttrs(vw->vw_SBar.gad, vw->vw_Window, NULL,
PGA_Visible, vw->vw_MaxY,
PGA_Total, vw->vw_SBar.total,
PGA_Top, vw->vw_SBar.top,
TAG_END);
}
}
#endif
/*
* Opens an editor window. Sets up the shared IDCMP
*/
struct Window *
sys_new_window(VW *oldVW, VW *vw, bool useDefDims)
{
u_short *dimensions;
struct Screen *scr;
struct Window *res = NULL;
bool truedims = FALSE;
if(!useDefDims && oldVW)
{
if(oldVW->vw_Flags & VWFF_SLEEPING)
dimensions = oldVW->vw_WindowSys.ws_OldDimensions;
else
dimensions = &oldVW->vw_Window->LeftEdge;
truedims = TRUE;
}
else
dimensions = def_dims;
if(scr = LockPubScreen(*VSTR(vw->vw_WindowSys.ws_ScreenName)
? VSTR(vw->vw_WindowSys.ws_ScreenName)
: NULL))
{
#ifndef NOSCRLBAR
if(vw->vw_SBar.gad = NewObject(NULL, "propgclass",
GA_RelRight, -13,
GA_Top, 1 + scr->WBorTop + scr->Font->ta_YSize + 1,
GA_Width, 10,
GA_RelHeight, -12 - (scr->WBorTop + scr->Font->ta_YSize + 1),
GA_RelVerify, TRUE,
GA_Immediate, TRUE,
GA_FollowMouse, TRUE,
GA_RightBorder, TRUE,
PGA_Borderless, TRUE,
PGA_Freedom, FREEVERT,
PGA_Total, 1,
PGA_Visible, 1,
PGA_Top, 0,
PGA_NewLook, TRUE,
TAG_END))
{
#endif
if(res = OpenWindowTags(NULL,
WA_Left, dimensions[0],
WA_Top, dimensions[1],
WA_InnerWidth, truedims ? dimensions[2] : (dimensions[2] * vw->vw_FontX + 1),
WA_InnerHeight, truedims ? dimensions[3] : (dimensions[3] + 1) * vw->vw_FontY + 3,
WA_IDCMP, shared_window_port ? 0 : IDCMP,
WA_MinWidth, 80,
WA_MinHeight, 40,
WA_MaxWidth, ~0,