1 /* ------------------ msgbox.c ------------------ */
3 #include "dflat32/dflat.h"
6 extern DBOX InputBoxDB
;
9 static int ReturnValue
;
11 int MessageBoxProc(DFWINDOW wnd
, DFMESSAGE msg
, PARAM p1
, PARAM p2
)
15 GetClass(wnd
) = MESSAGEBOX
;
16 InitWindowColors(wnd
);
17 ClearAttribute(wnd
, CONTROLBOX
);
20 if (p1
== '\r' || p1
== ESC
)
21 ReturnValue
= (int)p1
;
26 return BaseWndProc(MESSAGEBOX
, wnd
, msg
, p1
, p2
);
29 int YesNoBoxProc(DFWINDOW wnd
, DFMESSAGE msg
, PARAM p1
, PARAM p2
)
33 GetClass(wnd
) = MESSAGEBOX
;
34 InitWindowColors(wnd
);
35 ClearAttribute(wnd
, CONTROLBOX
);
38 int c
= tolower((int)p1
);
40 DfSendMessage(wnd
, DFM_COMMAND
, ID_OK
, 0);
42 DfSendMessage(wnd
, DFM_COMMAND
, ID_CANCEL
, 0);
48 return BaseWndProc(MESSAGEBOX
, wnd
, msg
, p1
, p2
);
51 int ErrorBoxProc(DFWINDOW wnd
, DFMESSAGE msg
, PARAM p1
, PARAM p2
)
55 GetClass(wnd
) = ERRORBOX
;
56 InitWindowColors(wnd
);
59 if (p1
== '\r' || p1
== ESC
)
60 ReturnValue
= (int)p1
;
65 return BaseWndProc(ERRORBOX
, wnd
, msg
, p1
, p2
);
68 int CancelBoxProc(DFWINDOW wnd
, DFMESSAGE msg
, PARAM p1
, PARAM p2
)
73 DfSendMessage(wnd
, CAPTURE_MOUSE
, 0, 0);
74 DfSendMessage(wnd
, CAPTURE_KEYBOARD
, 0, 0);
77 if ((int) p1
== ID_CANCEL
&& (int) p2
== 0)
78 DfSendMessage(GetParent(wnd
), msg
, p1
, p2
);
82 DfSendMessage(wnd
, RELEASE_MOUSE
, 0, 0);
83 DfSendMessage(wnd
, RELEASE_KEYBOARD
, 0, 0);
89 return BaseWndProc(MESSAGEBOX
, wnd
, msg
, p1
, p2
);
92 void CloseCancelBox(void)
94 if (CancelWnd
!= NULL
)
95 DfSendMessage(CancelWnd
, CLOSE_WINDOW
, 0, 0);
98 static char *InputText
;
99 static int TextLength
;
101 int InputBoxProc(DFWINDOW wnd
, DFMESSAGE msg
, PARAM p1
, PARAM p2
)
106 rtn
= DefaultWndProc(wnd
, msg
, p1
, p2
);
107 DfSendMessage(ControlWindow(&InputBoxDB
,ID_INPUTTEXT
),
108 SETTEXTLENGTH
, TextLength
, 0);
111 if ((int) p1
== ID_OK
&& (int) p2
== 0)
112 GetItemText(wnd
, ID_INPUTTEXT
,
113 InputText
, TextLength
);
118 return DefaultWndProc(wnd
, msg
, p1
, p2
);
121 BOOL
InputBox(DFWINDOW wnd
,char *ttl
,char *msg
,char *text
,int len
)
125 InputBoxDB
.dwnd
.title
= ttl
;
126 InputBoxDB
.dwnd
.w
= 4 +
127 max(20, max(len
, max((int)strlen(ttl
), (int)strlen(msg
))));
128 InputBoxDB
.ctl
[1].dwnd
.x
= (InputBoxDB
.dwnd
.w
-2-len
)/2;
129 InputBoxDB
.ctl
[0].dwnd
.w
= strlen(msg
);
130 InputBoxDB
.ctl
[0].itext
= msg
;
131 InputBoxDB
.ctl
[1].dwnd
.w
= len
;
132 InputBoxDB
.ctl
[2].dwnd
.x
= (InputBoxDB
.dwnd
.w
- 20) / 2;
133 InputBoxDB
.ctl
[3].dwnd
.x
= InputBoxDB
.ctl
[2].dwnd
.x
+ 10;
134 InputBoxDB
.ctl
[2].isetting
= ON
;
135 InputBoxDB
.ctl
[3].isetting
= ON
;
136 return DfDialogBox(wnd
, &InputBoxDB
, TRUE
, InputBoxProc
);
139 BOOL
GenericMessage(DFWINDOW wnd
,char *ttl
,char *msg
,int buttonct
,
140 int (*wndproc
)(struct window
*,enum messages
,PARAM
,PARAM
),
141 char *b1
, char *b2
, int c1
, int c2
, int isModal
)
144 MsgBox
.dwnd
.title
= ttl
;
145 MsgBox
.ctl
[0].dwnd
.h
= MsgHeight(msg
);
147 MsgBox
.ctl
[0].dwnd
.w
= max(max(MsgWidth(msg
),
148 (int)(buttonct
*8 + buttonct
+ 2)), (int)strlen(ttl
)+2);
150 MsgBox
.ctl
[0].dwnd
.w
= max(MsgWidth(msg
), (int)(buttonct
*8 + buttonct
+ 2));
151 MsgBox
.dwnd
.h
= MsgBox
.ctl
[0].dwnd
.h
+6;
152 MsgBox
.dwnd
.w
= MsgBox
.ctl
[0].dwnd
.w
+4;
154 MsgBox
.ctl
[1].dwnd
.x
= (MsgBox
.dwnd
.w
- 10) / 2;
156 MsgBox
.ctl
[1].dwnd
.x
= (MsgBox
.dwnd
.w
- 20) / 2;
157 MsgBox
.ctl
[2].dwnd
.x
= MsgBox
.ctl
[1].dwnd
.x
+ 10;
158 MsgBox
.ctl
[2].class = BUTTON
;
160 MsgBox
.ctl
[1].dwnd
.y
= MsgBox
.dwnd
.h
- 4;
161 MsgBox
.ctl
[2].dwnd
.y
= MsgBox
.dwnd
.h
- 4;
162 MsgBox
.ctl
[0].itext
= msg
;
163 MsgBox
.ctl
[1].itext
= b1
;
164 MsgBox
.ctl
[2].itext
= b2
;
165 MsgBox
.ctl
[1].command
= c1
;
166 MsgBox
.ctl
[2].command
= c2
;
167 MsgBox
.ctl
[1].isetting
= ON
;
168 MsgBox
.ctl
[2].isetting
= ON
;
169 rtn
= DfDialogBox(wnd
, &MsgBox
, isModal
, wndproc
);
170 MsgBox
.ctl
[2].class = 0;
174 DFWINDOW
MomentaryMessage(char *msg
)
176 DFWINDOW wnd
= DfCreateWindow(
179 -1,-1,MsgHeight(msg
)+2,MsgWidth(msg
)+2,
181 HASBORDER
| SHADOW
| SAVESELF
);
182 DfSendMessage(wnd
, SETTEXT
, (PARAM
) msg
, 0);
183 WindowClientColor(wnd
, WHITE
, GREEN
);
184 WindowFrameColor(wnd
, WHITE
, GREEN
);
185 DfSendMessage (wnd
, SHOW_WINDOW
, 0, 0);
189 int MsgHeight(char *msg
)
193 while ((msg
= strchr(msg
, '\n')) != NULL
)
199 return min(h
, DfGetScreenHeight ()-10);
202 int MsgWidth(char *msg
)
207 while ((cp
= strchr(msg
, '\n')) != NULL
)
209 w
= max(w
, (int) (cp
-msg
));
213 return min(max((int)strlen(msg
), (int)w
), DfGetScreenWidth()-10);