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 >
Wrap
C/C++ Source or Header
|
1994-04-19
|
17KB
|
667 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 sleepwin(VW *);
_PR int unsleep(VW *);
_PR void os_newvw(VW *);
_PR void os_killvw(VW *);
_PR void updatedimensions(VW *);
_PR void updatescroller(VW *);
_PR struct Window *newwindow(VW *, VW *, bool);
_PR void killwindow(VW *);
static void CloseSharedWindow(struct Window *);
static void StripIntuiMessages(struct MsgPort *, struct Window *);
_PR struct IntuiMessage *GetWinIMsg(struct Window *);
_PR void activatewin(VW *);
_PR void setvwtitle(VW *);
_PR void setvwpos(VW *, long, long, long, long);
_PR int ezreq(u_char *, u_char *, long, ...);
_PR int setfont(VW *);
_PR void unsetfont(VW *);
_PR void resetslptxtitles(TX *);
_PR bool makemousepos(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 *ScreenTitle = VERSSTRING;
static struct MsgPort *SharedPort;
#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
sleepwin(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_ScreenTitle, ScreenTitle,
WA_AutoAdjust, TRUE,
WA_PubScreenName, VSTR(vw->vw_WindowSys.ws_ScreenName),
WA_PubScreenFallBack, TRUE,
TAG_END))
{
swin->UserPort = SharedPort;
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;
clearmenu(vw->vw_Window);
Forbid();
StripIntuiMessages(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_Sleeping && 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_Sleeping = TRUE;
swin->UserData = (BYTE *)vw;
rc = TRUE;
}
else
cmd_signal(sym_error, LIST_1(MKSTR("Can't open window")));
return(rc);
}
int
unsleep(VW *vw)
{
int rc = TRUE;
if(vw->vw_Sleeping)
{
struct Window *oldwin = vw->vw_Window;
if(newwindow(vw, vw, FALSE))
{
Forbid();
StripIntuiMessages(oldwin->UserPort, oldwin);
oldwin->UserPort = NULL;
ModifyIDCMP(oldwin, 0L);
Permit();
CloseWindow(oldwin);
vw->vw_Sleeping = FALSE;
updatedimensions(vw);
#ifndef NOSCRLBAR
updatescroller(vw);
#endif
vw->vw_Flags |= VWFF_FORCE_REFRESH;
}
else
rc = FALSE;
}
return(rc);
}
void
os_newvw(VW *vw)
{
;
}
void
os_killvw(VW *vw)
{
}
void
updatedimensions(VW *vw)
{
if(vw->vw_Window && !vw->vw_Sleeping)
{
struct Window *wd = vw->vw_Window;
vw->vw_XStartPix = (UWORD)wd->BorderLeft;
vw->vw_YStartPix = (UWORD)wd->BorderTop;
vw->vw_XEndPix = wd->Width - (UWORD)wd->BorderRight - 1;
vw->vw_YEndPix = wd->Height - (UWORD)wd->BorderBottom;
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
updatescroller(VW *vw)
{
if(!vw->vw_Sleeping && 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 *
newwindow(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_Sleeping)
dimensions = oldVW->vw_WindowSys.ws_OldDimensions;
else
dimensions = &oldVW->vw_Window->LeftEdge;
truedims = TRUE;
}
else
dimensions = DefDims;
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] * vw->vw_FontY),
WA_IDCMP, SharedPort ? 0 : IDCMP,
WA_MinWidth, 80,
WA_MinHeight, 40,
WA_MaxWidth, ~0,
WA_MaxHeight, ~0,
#if AMIGA_INCLUDE_VER >= 39
WA_Flags, WFLAGS | WFLG_NEWLOOKMENUS,
#else
WA_Flags, WFLAGS,
#endif
#ifndef NOSCRLBAR
WA_Gadgets, vw->vw_SBar.gad,
#endif
WA_ScreenTitle, ScreenTitle,
WA_AutoAdjust, TRUE,
WA_PubScreen, scr,
WA_RptQueue, 2,
TAG_END))
{
if(SharedPort)
{
res->