home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 9
/
FreshFishVol9-CD2.bin
/
bbs
/
util
/
snoopdos-3.0.lha
/
SnoopDos
/
Source
/
miscwin.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-17
|
33KB
|
1,186 lines
/*
* MISCWIN.C vi:ts=4
*
* Copyright (c) Eddy Carroll, September 1994.
*
* This module contains miscellaneous functions associated with
* the SnoopDos GUI, but nevertheless not directly tied to any
* particular window.
*
*/
#include "system.h"
#include "snoopdos.h"
#include "gui.h"
#if 0
#define DB(s) KPrintF(s)
#else
#define DB(s)
#endif
/*
* Four dummy requesters for use when disabling window input
*/
struct FileRequester *SnoopDosFR;
APTR AG_Context;
struct NewAmigaGuide AG_NewGuide;
char *PendingAGuideMsg;
extern struct TextAttr TopazFontAttr;
extern struct TextAttr SystemFontAttr;
extern struct TextAttr WindowFontAttr;
extern struct TextAttr BufferFontAttr;
/*
* Now our busy pointer for V37 users (borrowed from ToolMaker)
*/
UWORD __chip WaitPointer[36] = {
0x0000, 0x0000, 0x0400, 0x07C0, 0x0000, 0x07C0, 0x0100, 0x0380,
0x0000, 0x07E0, 0x07C0, 0x1FF8, 0x1FF0, 0x3FEC, 0x3FF8, 0x7FDE,
0x3FF8, 0x7FBE, 0x7FFC, 0xFF7F, 0x7EFC, 0xFFFF, 0x7FFC, 0xFFFF,
0x3FF8, 0x7FFE, 0x3FF8, 0x7FFE, 0x1FF0, 0x3FFC, 0x07C0, 0x1FF8,
0x0000, 0x07E0, 0x0000, 0x0000
};
ULONG __chip FileButtonData[] = {
0x0FF00000, 0x0C180000, 0x0C140000, 0x0C120000, 0x0C1F0000,
0x0C030000, 0x0C030000, 0x0C030000, 0x0C030000, 0x0FFF0000,
};
ULONG __chip FontButtonData[] = {
0x0FE00000, 0x09200000, 0x01000000, 0x017F0000, 0x01490000,
0x01080000, 0x01080000, 0x00080000, 0x00080000, 0x00080000,
};
/*
* This structure holds all the information we need to know about
* one of our custom images
*/
struct CustomBitMap {
struct Image image;
struct Image altimage;
struct BitMap bitmap;
struct RastPort rport;
};
struct CustomImage {
struct CustomBitMap image[2];
int size;
};
/*****************************************************************************
*
* Start of functions!
*
*****************************************************************************/
/*
* DisableWindow(window, requester)
*
* Disables the specified window by displaying a dummy requester in it
* and turning on the wait pointer. It is assumed that the window
* exists and has not been disabled already.
*/
void DisableWindow(struct Window *win, struct Requester *req)
{
InitRequester(req);
if (Request(req, win)) {
/*
* Use the new V39 system busy pointer if possible, else
* drop back to our own busy pointer
*/
if (IntuitionBase->LibNode.lib_Version >= 39)
SetWindowPointer(win,
WA_BusyPointer, TRUE,
WA_PointerDelay, TRUE,
TAG_DONE);
else
SetPointer(win, WaitPointer, 16, 16, -6, 0);
}
}
/*
* EnableWindow()
*
* Enables the specified window by removing the dummy requester
* placed inside it earlier. You must have called DisableWindow()
* with the same parameters first.
*/
void EnableWindow(struct Window *win, struct Requester *req)
{
EndRequest(req, win);
ClearPointer(win);
}
/*
* DisableAllWindows()
*
* Disables all windows by opening a dummy requester in them and
* setting the window pointer to busy. Calls to this function
* nest, so be sure to call EnableAllWindows the correct number
* of times. This is intended for use when displaying modal
* requesters (e.g. ASL, error messages, etc.)
*/
void DisableAllWindows(void)
{
DisableNestCount++;
if (DisableNestCount == 1) {
if (MainWindow) {
/*
* If we are disabling the main window, we won't be able
* to respond to IDCMP_SIZEVERIFY messages, so instead, we
* just stop requesting them. This lets the user resize the
* window when we have a file/font requester up, even though
* it won't redraw until the requester is finished.
*/
ModifyIDCMP(MainWindow,MainWindow->IDCMPFlags & ~IDCMP_SIZEVERIFY);
DisableWindow(MainWindow, &MainRequester);
}
if (SetWindow) DisableWindow(SetWindow, &SetRequester);
if (FuncWindow) DisableWindow(FuncWindow, &FuncRequester);
if (FormWindow) DisableWindow(FormWindow, &FormRequester);
}
}
/*
* EnableAllWindows()
*
* Re-enables all windows disabled by calling DisableAllWindows()
*/
void EnableAllWindows(void)
{
DisableNestCount--;
if (DisableNestCount == 0) {
if (SetWindow) EnableWindow(SetWindow, &SetRequester);
if (FuncWindow) EnableWindow(FuncWindow, &FuncRequester);
if (FormWindow) EnableWindow(FormWindow, &FormRequester);
if (MainWindow) {
/*
* Because the user might have resized the main window
* while we were disabled, causing us to miss the resize
* message (which happens when IDCMP_SIZEVERIFY is active)
* we check to see if the size has changed and if it has,
* cause a fake RESIZE message to be sent to ourself.
*/
EnableWindow(MainWindow, &MainRequester);
ModifyIDCMP(MainWindow, MainWindow->IDCMPFlags | IDCMP_SIZEVERIFY);
if (MainWindow->Width != CurWindowWidth ||
MainWindow->Height != CurWindowHeight) {
SizeWindow(MainWindow, 0, 0);
}
}
}
}
/*
* RecordWindowSizes()
*
* Records the current size and position of all open windows on the
* display so that they can be re-opened in the same position next time.
* Usually called before a window is closed, but may also be called
* when (for example) settings are being saved.
*/
void RecordWindowSizes(void)
{
if (MainWindow) {
CurSettings.MainWinLeft = MainWindow->LeftEdge;
CurSettings.MainWinTop = MainWindow->TopEdge;
CurSettings.MainWinWidth = MainWindow->Width;
CurSettings.MainWinHeight = MainWindow->Height;
}
if (FormWindow) {
CurSettings.FormWinLeft = FormWindow->LeftEdge;
CurSettings.FormWinTop = FormWindow->TopEdge;
}
if (FuncWindow) {
CurSettings.FuncWinLeft = FuncWindow->LeftEdge;
CurSettings.FuncWinTop = FuncWindow->TopEdge;
}
if (SetWindow) {
CurSettings.SetupWinLeft = SetWindow->LeftEdge;
CurSettings.SetupWinTop = SetWindow->TopEdge;
}
}
/*
* ShowError(errormsg)
*
* Displays the specified error message in a requester (on the same
* screen as the main SnoopDos window if possible, else on the
* default window), waits for an OKAY click, and returns.
*/
void ShowError(char *errormsg, ...)
{
static struct EasyStruct es = {
sizeof(struct EasyStruct),
0,
"SnoopDos",
NULL,
NULL
};
int pausestate = Paused;
Paused = 0;
es.es_TextFormat = errormsg;
es.es_GadgetFormat = MSG(MSG_ERROR_OKAY);
DisableAllWindows();
/*
* If MainWindow is NULL, then the requester will appear on
* the default public screen
*/
EasyRequestArgs(MainWindow, &es, 0, (&errormsg)+1);
EnableAllWindows();
Paused = pausestate;
}
/*
* GetResponse(prompt, message, params, ...)
*
* Displays an easy requester with the specified prompts, waits for the
* user to click on an option, then returns the selected option.
*
* Note that options are numbered 1,2,3....,0 with the leftmost gadget
* returning 1 and the rightmost gadget returning 0.
*/
int GetResponse(char *prompts, char *reqmsg, ...)
{
static struct EasyStruct es = {
sizeof(struct EasyStruct),
0,
"SnoopDos",
NULL,
NULL
};
int pausestate = Paused;
int choice;
Paused = 0;
es.es_TextFormat = reqmsg;
es.es_GadgetFormat = prompts;
DisableAllWindows();
choice = EasyRequestArgs(MainWindow, &es, 0, (&reqmsg)+1);
EnableAllWindows();
Paused = pausestate;
return (choice);
}
/*
* MaxTextLen(font, textarray)
*
* Returns the length (in pixels) of the longest string in the given
* zero-terminated array of message IDs, using the given font.
*/
int MaxTextLen(struct TextFont *font, int *ids)
{
struct RastPort rp;
int maxlen = 0;
InitRastPort(&rp);
SetFont(&rp, font);
while (*ids) {
char *msg = MSG(*ids++);
int len = TextLength(&rp, msg, strlen(msg));
if (len > maxlen)
maxlen = len;
}
return (maxlen);
}
/*
* GetTextLen(font, msg)
*
* Returns the length (in pixels) of the given message indicated by the
* message ID, when rendered in the given font.
*/
int GetTextLen(struct TextFont *font, char *msg)
{
struct RastPort rp;
InitRastPort(&rp);
SetFont(&rp, font);
return (TextLength(&rp, msg, strlen(msg)));
}
/*
* AddKeyShortcut(shortcut, gadid, msgid)
*
* Checks the string corresponding to msgid for an underlined
* chara