1
0
mirror of https://github.com/weiju/amiga-stuff synced 2026-03-17 16:33:16 +00:00

filerequester is opened in its own window

This commit is contained in:
Wei-ju Wu
2016-01-12 23:06:47 -08:00
parent 98bef3439f
commit cb73ab7d07
5 changed files with 118 additions and 61 deletions

1
requesters/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
main

View File

@ -1,17 +1,18 @@
#include <intuition/intuition.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/dos_protos.h>
#include <clib/alib_stdio_protos.h>
#include "filereq.h"
#define REQ_TEXT_XOFFSET 10
#define REQ_WIDTH 240
#define REQ_HEIGHT 170
#define REQ_HEIGHT 175
#define TOPAZ_BASELINE 8
#define BUTTON_Y 140
#define BUTTON_Y 135
#define BUTTON_HEIGHT 18
#define BUTTON_TEXT_XOFFSET 14
@ -24,39 +25,53 @@
#define STR_GADGET_Y 120
#define PATH_GADGET_WIDTH 100
static struct Requester requester;
static BOOL req_opened = FALSE;
static struct Window *req_window;
struct Requester requester;
struct IntuiText labels[] = {
static struct IntuiText labels[] = {
{1, 0, JAM2, REQ_TEXT_XOFFSET, STR_GADGET_Y, NULL, "Enter file path", NULL},
{1, 0, JAM2, 10, TOPAZ_BASELINE - 4, NULL, "Ok", NULL},
{1, 0, JAM2, 10, TOPAZ_BASELINE - 4, NULL, "Cancel", NULL} /* TOPAZ_BASELINE is 8 */
};
WORD gadget_border_points[3][10] = {
static WORD gadget_border_points[3][10] = {
{0, 0, OK_BUTTON_WIDTH, 0, OK_BUTTON_WIDTH, BUTTON_HEIGHT, 0, BUTTON_HEIGHT, 0, 0},
{0, 0, CANCEL_BUTTON_WIDTH, 0, CANCEL_BUTTON_WIDTH, BUTTON_HEIGHT, 0, BUTTON_HEIGHT, 0, 0},
/* the -2 is the margin to set to avoid that the string gadget will overdraw the
borders */
{-2, -2, PATH_GADGET_WIDTH, -2, PATH_GADGET_WIDTH, 10, -2, 10, -2, -2}
};
struct Border gadget_borders[] = {
static struct Border gadget_borders[] = {
{0, 0, 1, 0, JAM1, 5, gadget_border_points[0], NULL},
{0, 0, 1, 0, JAM1, 5, gadget_border_points[1], NULL},
{0, 0, 1, 0, JAM1, 5, gadget_border_points[2], NULL}
};
WORD req_border_points[] = {
0, 0, REQ_WIDTH - 1, 0, REQ_WIDTH - 1, REQ_HEIGHT - 1, 0, REQ_HEIGHT - 1, 0, 0
};
struct Border req_border = {0, 0, 1, 0, JAM1, 5, req_border_points, NULL};
static UBYTE buffer[81], undobuffer[81];
static struct StringInfo strinfo = {buffer, undobuffer, 0, 80, 0, 0, 0, 0, 0, 0, NULL, 0, NULL};
UBYTE buffer[81], undobuffer[81];
struct StringInfo strinfo = {buffer, undobuffer, 0, 80, 0, 0, 0, 0, 0, 0, NULL, 0, NULL};
#define REQWIN_WIDTH 260
#define REQWIN_HEIGHT 180
#define WIN_TITLE "Open File..."
static struct NewWindow newwin = {
0, 0, REQWIN_WIDTH, REQWIN_HEIGHT, 0, 1,
IDCMP_CLOSEWINDOW | IDCMP_GADGETUP,
WFLG_CLOSEGADGET | WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_DRAGBAR | WFLG_DEPTHGADGET,
NULL, NULL, WIN_TITLE,
NULL, NULL,
REQWIN_WIDTH, REQWIN_HEIGHT,
REQWIN_WIDTH, REQWIN_HEIGHT,
WBENCHSCREEN
};
/*
Note: Cancel does not specify the GACT_ENDGADGET flag, it seems that
IDCMP_REQCLEAR is not fired when Intuition closes the requester automatically
*/
struct Gadget gadgets[] = {
static struct Gadget gadgets[] = {
{&gadgets[1], OK_BUTTON_X, BUTTON_Y, OK_BUTTON_WIDTH, BUTTON_HEIGHT, GFLG_GADGHCOMP,
GACT_RELVERIFY, GTYP_BOOLGADGET | GTYP_REQGADGET, &gadget_borders[0], NULL,
&labels[1], 0, NULL, REQ_OK_BUTTON_ID, NULL},
@ -68,14 +83,13 @@ struct Gadget gadgets[] = {
&labels[3], 0, &strinfo, 103, NULL},
};
BOOL initialized = 0;
#define PATHBUFFER_SIZE 200
char dirname[PATHBUFFER_SIZE + 1];
BPTR flock;
LONG error;
struct FileInfoBlock fileinfo;
static char dirname[PATHBUFFER_SIZE + 1];
static BPTR flock;
static LONG error;
static struct FileInfoBlock fileinfo;
void print_fileinfo(struct FileInfoBlock *fileinfo)
static void print_fileinfo(struct FileInfoBlock *fileinfo)
{
if (fileinfo->fib_DirEntryType > 0) {
printf("dir: '%s'\n", fileinfo->fib_FileName);
@ -84,10 +98,56 @@ void print_fileinfo(struct FileInfoBlock *fileinfo)
}
}
struct Requester *open_file(struct Window *window)
static void close_requester()
{
puts("close_requester()");
if (req_opened) {
puts("EndRequest()");
EndRequest(&requester, req_window);
req_opened = FALSE;
}
}
static void handle_events()
{
BOOL done = FALSE;
struct IntuiMessage *msg;
ULONG msgClass;
UWORD menuCode;
int buttonId;
while (!done) {
Wait(1 << req_window->UserPort->mp_SigBit);
if (msg = (struct IntuiMessage *) GetMsg(req_window->UserPort)) {
msgClass = msg->Class;
switch (msgClass) {
case IDCMP_CLOSEWINDOW:
close_requester();
done = TRUE;
break;
case IDCMP_GADGETUP:
buttonId = (int) ((struct Gadget *) (msg->IAddress))->GadgetID;
if (buttonId == REQ_OK_BUTTON_ID) {
close_requester();
done = TRUE;
}
else if (buttonId == REQ_CANCEL_BUTTON_ID) {
close_requester();
done = TRUE;
}
break;
default:
break;
}
ReplyMsg((struct Message *) msg);
}
}
}
void open_file(struct Window *window)
{
BOOL result;
if (!initialized) {
if (req_window = OpenWindow(&newwin)) {
InitRequester(&requester);
requester.LeftEdge = 20;
requester.TopEdge = 20;
@ -96,7 +156,7 @@ struct Requester *open_file(struct Window *window)
requester.Flags = 0;
requester.BackFill = 0;
requester.ReqGadget = &gadgets[0];
requester.ReqBorder = &req_border;
requester.ReqBorder = NULL; // &req_border;
requester.ReqText = &labels[0];
/* scan current directory */
@ -105,27 +165,34 @@ struct Requester *open_file(struct Window *window)
function GetCurrentDirName() does not exist, but it's obtainable
by calling Cli() and querying the returned CommandLineInterface
structure
*/
puts("scanning directory...");
*/
//puts("scanning directory...");
/*
// on AmigaOS 1.x, this function does not exist !!!
GetCurrentDirName(dirname, PATHBUFFER_SIZE);
printf("current dir: '%s'\n", dirname);
flock = Lock(dirname, SHARED_LOCK);
if (Examine(flock, &fileinfo)) {
while (ExNext(flock, &fileinfo)) {
print_fileinfo(&fileinfo);
}
error = IoErr();
if (error != ERROR_NO_MORE_ENTRIES) {
puts("unknown I/O error, TODO handle");
}
while (ExNext(flock, &fileinfo)) {
print_fileinfo(&fileinfo);
}
error = IoErr();
if (error != ERROR_NO_MORE_ENTRIES) {
puts("unknown I/O error, TODO handle");
}
}
UnLock(flock);
*/
initialized = 1;
if (req_opened = Request(&requester, req_window)) {
puts("handle requester events...");
handle_events();
puts("quit handling requester events");
CloseWindow(req_window);
req_window = NULL;
} else {
puts("Request() failed !!!");
}
} else {
puts("OpenWindow() failed !!!");
}
result = Request(&requester, window);
return result ? &requester : NULL;
}

View File

@ -2,7 +2,7 @@
#ifndef __FILEREQ_H__
#define __FILEREQ_H__
extern struct Requester *open_file(struct Window *window);
extern void open_file(struct Window *window);
#define REQ_OK_BUTTON_ID 101
#define REQ_CANCEL_BUTTON_ID 102

Binary file not shown.

View File

@ -46,10 +46,10 @@
#define OPEN_MENU_ITEM_NUM 0
#define QUIT_MENU_ITEM_NUM 1
struct NewWindow newwin = {
static struct NewWindow newwin = {
WIN_LEFT, WIN_TOP, WIN_WIDTH, WIN_HEIGHT, 0, 1,
IDCMP_CLOSEWINDOW | IDCMP_MENUPICK | IDCMP_GADGETUP | IDCMP_REQCLEAR,
WINDOWCLOSE | SMART_REFRESH | ACTIVATE | WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH | NOCAREREFRESH,
WINDOWCLOSE | SMART_REFRESH | ACTIVATE | WINDOWSIZING | WINDOWDRAG | WINDOWDEPTH,
NULL, NULL, WIN_TITLE,
NULL, NULL,
WIN_MIN_WIDTH, WIN_MIN_HEIGHT,
@ -57,25 +57,25 @@ struct NewWindow newwin = {
WBENCHSCREEN
};
struct IntuiText menutext[] = {
static struct IntuiText menutext[] = {
{0, 1, JAM2, 0, 1, NULL, "Open...", NULL},
{0, 1, JAM2, 0, 1, NULL, "Quit", NULL}
};
struct MenuItem fileMenuItems[] = {
static struct MenuItem fileMenuItems[] = {
{&fileMenuItems[1], 0, 0, 0, 0, ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ, 0,
&menutext[0], NULL, 'O', NULL, 0},
{NULL, 0, 0, 0, 0, ITEMTEXT | ITEMENABLED | HIGHCOMP | COMMSEQ, 0,
&menutext[1], NULL, 'Q', NULL, 0}
};
struct Menu menus[] = {
static struct Menu menus[] = {
{NULL, 20, 0, 0, 0, MENUENABLED | MIDRAWN, "File", &fileMenuItems[0], 0, 0, 0, 0}
};
struct Window *window;
static struct Window *window;
void cleanup()
static void cleanup()
{
if (window) {
ClearMenuStrip(window);
@ -83,9 +83,7 @@ void cleanup()
}
}
struct Requester *filereq;
BOOL handle_menu(UWORD menuNum, UWORD itemNum, UWORD subItemNum)
static BOOL handle_menu(UWORD menuNum, UWORD itemNum, UWORD subItemNum)
{
printf("menu, menu num: %d, item num: %d, sub item num: %d\n",
(int) menuNum, (int) itemNum, (int) subItemNum);
@ -94,12 +92,12 @@ BOOL handle_menu(UWORD menuNum, UWORD itemNum, UWORD subItemNum)
return TRUE;
}
if (menuNum == FILE_MENU_NUM && itemNum == OPEN_MENU_ITEM_NUM) {
filereq = open_file(window);
open_file(window);
}
return FALSE;
}
void handle_events()
static void handle_events()
{
BOOL done = FALSE;
struct IntuiMessage *msg;
@ -108,6 +106,7 @@ void handle_events()
int buttonId;
while (!done) {
puts("main, wait...");
Wait(1 << window->UserPort->mp_SigBit);
if (msg = (struct IntuiMessage *) GetMsg(window->UserPort)) {
msgClass = msg->Class;
@ -119,14 +118,6 @@ void handle_events()
menuCode = msg->Code;
done = handle_menu(MENUNUM(menuCode), ITEMNUM(menuCode), SUBNUM(menuCode));
break;
case IDCMP_GADGETUP:
buttonId = (int) ((struct Gadget *) (msg->IAddress))->GadgetID;
if (buttonId == REQ_OK_BUTTON_ID && filereq) EndRequest(filereq, window);
else if (buttonId == REQ_CANCEL_BUTTON_ID && filereq) EndRequest(filereq, window);
break;
case IDCMP_REQCLEAR:
puts("requester closed");
break;
default:
break;
}
@ -135,7 +126,7 @@ void handle_events()
}
}
void setup_menu()
static void setup_menu()
{
UWORD txWidth, txHeight, txBaseline, txSpacing, itemWidth, itemHeight, numItems;
struct RastPort *rp = &window->WScreen->RastPort;
@ -164,7 +155,6 @@ void setup_menu()
fileMenuItems[i].Height = itemHeight;
fileMenuItems[i].Width = itemWidth;
}
SetMenuStrip(window, &menus[0]);
}
@ -180,10 +170,9 @@ int main(int argc, char **argv)
/* Adjust the new screen according to the IFF image */
if (window = OpenWindow(&newwin)) {
setup_menu();
// Note: rastport is the entire window, including title bars
//DrawImage(window->RPort, &image, 2, 10);
handle_events();
}
puts("main cleanup");
cleanup();
return 1;
}