2000-03-05 19:58:08 +00:00
|
|
|
/* ------------------ msgbox.c ------------------ */
|
|
|
|
|
|
|
|
#include "dflat.h"
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
extern DF_DBOX MsgBox;
|
|
|
|
extern DF_DBOX InputBoxDB;
|
2000-03-05 19:58:08 +00:00
|
|
|
DFWINDOW CancelWnd;
|
|
|
|
|
|
|
|
static int ReturnValue;
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
int DfMessageBoxProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
switch (msg) {
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_CREATE_WINDOW:
|
|
|
|
DfGetClass(wnd) = DF_MESSAGEBOX;
|
|
|
|
DfInitWindowColors(wnd);
|
|
|
|
DfClearAttribute(wnd, DF_CONTROLBOX);
|
2000-03-05 19:58:08 +00:00
|
|
|
break;
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_KEYBOARD:
|
|
|
|
if (p1 == '\r' || p1 == DF_ESC)
|
2000-03-05 19:58:08 +00:00
|
|
|
ReturnValue = (int)p1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
return DfBaseWndProc(DF_MESSAGEBOX, wnd, msg, p1, p2);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
int DfYesNoBoxProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
switch (msg) {
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_CREATE_WINDOW:
|
|
|
|
DfGetClass(wnd) = DF_MESSAGEBOX;
|
|
|
|
DfInitWindowColors(wnd);
|
|
|
|
DfClearAttribute(wnd, DF_CONTROLBOX);
|
2000-03-05 19:58:08 +00:00
|
|
|
break;
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_KEYBOARD: {
|
2000-03-05 19:58:08 +00:00
|
|
|
int c = tolower((int)p1);
|
|
|
|
if (c == 'y')
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(wnd, DFM_COMMAND, DF_ID_OK, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
else if (c == 'n')
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(wnd, DFM_COMMAND, DF_ID_CANCEL, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
return DfBaseWndProc(DF_MESSAGEBOX, wnd, msg, p1, p2);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
int DfErrorBoxProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
switch (msg) {
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_CREATE_WINDOW:
|
|
|
|
DfGetClass(wnd) = DF_ERRORBOX;
|
|
|
|
DfInitWindowColors(wnd);
|
2000-03-05 19:58:08 +00:00
|
|
|
break;
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_KEYBOARD:
|
|
|
|
if (p1 == '\r' || p1 == DF_ESC)
|
2000-03-05 19:58:08 +00:00
|
|
|
ReturnValue = (int)p1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
return DfBaseWndProc(DF_ERRORBOX, wnd, msg, p1, p2);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
int DfCancelBoxProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
switch (msg) {
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_CREATE_WINDOW:
|
2000-03-05 19:58:08 +00:00
|
|
|
CancelWnd = wnd;
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(wnd, DFM_CAPTURE_MOUSE, 0, 0);
|
|
|
|
DfSendMessage(wnd, DFM_CAPTURE_KEYBOARD, 0, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
break;
|
|
|
|
case DFM_COMMAND:
|
2003-06-19 02:48:13 +00:00
|
|
|
if ((int) p1 == DF_ID_CANCEL && (int) p2 == 0)
|
|
|
|
DfSendMessage(DfGetParent(wnd), msg, p1, p2);
|
2000-03-05 19:58:08 +00:00
|
|
|
return TRUE;
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_CLOSE_WINDOW:
|
2000-03-05 19:58:08 +00:00
|
|
|
CancelWnd = NULL;
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(wnd, DFM_RELEASE_MOUSE, 0, 0);
|
|
|
|
DfSendMessage(wnd, DFM_RELEASE_KEYBOARD, 0, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
p1 = TRUE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
return DfBaseWndProc(DF_MESSAGEBOX, wnd, msg, p1, p2);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
void DfCloseCancelBox(void)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
if (CancelWnd != NULL)
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(CancelWnd, DFM_CLOSE_WINDOW, 0, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *InputText;
|
|
|
|
static int TextLength;
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
int InputBoxProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
int rtn;
|
|
|
|
switch (msg) {
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_CREATE_WINDOW:
|
|
|
|
rtn = DfDefaultWndProc(wnd, msg, p1, p2);
|
|
|
|
DfSendMessage(DfControlWindow(&InputBoxDB,DF_ID_INPUTTEXT),
|
|
|
|
DFM_SETTEXTLENGTH, TextLength, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
return rtn;
|
|
|
|
case DFM_COMMAND:
|
2003-06-19 02:48:13 +00:00
|
|
|
if ((int) p1 == DF_ID_OK && (int) p2 == 0)
|
|
|
|
DfGetItemText(wnd, DF_ID_INPUTTEXT,
|
2000-03-05 19:58:08 +00:00
|
|
|
InputText, TextLength);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
return DfDefaultWndProc(wnd, msg, p1, p2);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
BOOL DfInputBox(DFWINDOW wnd,char *ttl,char *msg,char *text,int len)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
InputText = text;
|
|
|
|
TextLength = len;
|
|
|
|
InputBoxDB.dwnd.title = ttl;
|
2005-05-07 21:24:31 +00:00
|
|
|
InputBoxDB.dwnd.w = 4 +
|
2000-03-05 19:58:08 +00:00
|
|
|
max(20, max(len, max((int)strlen(ttl), (int)strlen(msg))));
|
|
|
|
InputBoxDB.ctl[1].dwnd.x = (InputBoxDB.dwnd.w-2-len)/2;
|
|
|
|
InputBoxDB.ctl[0].dwnd.w = strlen(msg);
|
|
|
|
InputBoxDB.ctl[0].itext = msg;
|
|
|
|
InputBoxDB.ctl[1].dwnd.w = len;
|
|
|
|
InputBoxDB.ctl[2].dwnd.x = (InputBoxDB.dwnd.w - 20) / 2;
|
|
|
|
InputBoxDB.ctl[3].dwnd.x = InputBoxDB.ctl[2].dwnd.x + 10;
|
2003-06-19 02:48:13 +00:00
|
|
|
InputBoxDB.ctl[2].isetting = DF_ON;
|
|
|
|
InputBoxDB.ctl[3].isetting = DF_ON;
|
2000-03-05 19:58:08 +00:00
|
|
|
return DfDialogBox(wnd, &InputBoxDB, TRUE, InputBoxProc);
|
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
BOOL DfGenericMessage(DFWINDOW wnd,char *ttl,char *msg,int buttonct,
|
|
|
|
int (*wndproc)(struct DfWindow *,enum DfMessages,DF_PARAM,DF_PARAM),
|
2000-03-05 19:58:08 +00:00
|
|
|
char *b1, char *b2, int c1, int c2, int isModal)
|
|
|
|
{
|
|
|
|
BOOL rtn;
|
|
|
|
MsgBox.dwnd.title = ttl;
|
2003-06-19 02:48:13 +00:00
|
|
|
MsgBox.ctl[0].dwnd.h = DfMsgHeight(msg);
|
2000-03-05 19:58:08 +00:00
|
|
|
if (ttl)
|
2003-06-19 02:48:13 +00:00
|
|
|
MsgBox.ctl[0].dwnd.w = max(max(DfMsgWidth(msg),
|
2000-03-05 19:58:08 +00:00
|
|
|
(int)(buttonct*8 + buttonct + 2)), (int)strlen(ttl)+2);
|
|
|
|
else
|
2003-06-19 02:48:13 +00:00
|
|
|
MsgBox.ctl[0].dwnd.w = max(DfMsgWidth(msg), (int)(buttonct*8 + buttonct + 2));
|
2000-03-05 19:58:08 +00:00
|
|
|
MsgBox.dwnd.h = MsgBox.ctl[0].dwnd.h+6;
|
|
|
|
MsgBox.dwnd.w = MsgBox.ctl[0].dwnd.w+4;
|
|
|
|
if (buttonct == 1)
|
|
|
|
MsgBox.ctl[1].dwnd.x = (MsgBox.dwnd.w - 10) / 2;
|
|
|
|
else {
|
|
|
|
MsgBox.ctl[1].dwnd.x = (MsgBox.dwnd.w - 20) / 2;
|
|
|
|
MsgBox.ctl[2].dwnd.x = MsgBox.ctl[1].dwnd.x + 10;
|
2003-06-19 02:48:13 +00:00
|
|
|
MsgBox.ctl[2].class = DF_BUTTON;
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
MsgBox.ctl[1].dwnd.y = MsgBox.dwnd.h - 4;
|
|
|
|
MsgBox.ctl[2].dwnd.y = MsgBox.dwnd.h - 4;
|
|
|
|
MsgBox.ctl[0].itext = msg;
|
|
|
|
MsgBox.ctl[1].itext = b1;
|
|
|
|
MsgBox.ctl[2].itext = b2;
|
|
|
|
MsgBox.ctl[1].command = c1;
|
|
|
|
MsgBox.ctl[2].command = c2;
|
2003-06-19 02:48:13 +00:00
|
|
|
MsgBox.ctl[1].isetting = DF_ON;
|
|
|
|
MsgBox.ctl[2].isetting = DF_ON;
|
2000-03-05 19:58:08 +00:00
|
|
|
rtn = DfDialogBox(wnd, &MsgBox, isModal, wndproc);
|
|
|
|
MsgBox.ctl[2].class = 0;
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
DFWINDOW DfMomentaryMessage(char *msg)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
2003-06-19 02:48:13 +00:00
|
|
|
DFWINDOW wnd = DfDfCreateWindow(
|
|
|
|
DF_TEXTBOX,
|
2000-03-05 19:58:08 +00:00
|
|
|
NULL,
|
2003-06-19 02:48:13 +00:00
|
|
|
-1,-1,DfMsgHeight(msg)+2,DfMsgWidth(msg)+2,
|
2000-03-05 19:58:08 +00:00
|
|
|
NULL,NULL,NULL,
|
2003-06-19 02:48:13 +00:00
|
|
|
DF_HASBORDER | DF_SHADOW | DF_SAVESELF);
|
|
|
|
DfSendMessage(wnd, DFM_SETTEXT, (DF_PARAM) msg, 0);
|
|
|
|
DfWindowClientColor(wnd, WHITE, GREEN);
|
|
|
|
DfWindowFrameColor(wnd, WHITE, GREEN);
|
|
|
|
DfSendMessage (wnd, DFM_SHOW_WINDOW, 0, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
return wnd;
|
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
int DfMsgHeight(char *msg)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
2000-03-08 01:49:37 +00:00
|
|
|
int h = 1;
|
|
|
|
|
|
|
|
while ((msg = strchr(msg, '\n')) != NULL)
|
|
|
|
{
|
|
|
|
h++;
|
|
|
|
msg++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return min(h, DfGetScreenHeight ()-10);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
int DfMsgWidth(char *msg)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
2000-03-08 01:49:37 +00:00
|
|
|
int w = 0;
|
|
|
|
char *cp = msg;
|
|
|
|
|
|
|
|
while ((cp = strchr(msg, '\n')) != NULL)
|
|
|
|
{
|
|
|
|
w = max(w, (int) (cp-msg));
|
|
|
|
msg = cp+1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return min(max((int)strlen(msg), (int)w), DfGetScreenWidth()-10);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
2002-10-03 20:57:13 +00:00
|
|
|
/* EOF */
|