2000-03-05 19:58:08 +00:00
|
|
|
/* -------------- button.c -------------- */
|
|
|
|
|
|
|
|
#include "dflat.h"
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
void PaintMsg(DFWINDOW wnd, DF_CTLWINDOW *ct, DFRECT *rc)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
2003-06-19 02:48:13 +00:00
|
|
|
if (DfIsVisible(wnd))
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
2003-06-19 02:48:13 +00:00
|
|
|
if (DfTestAttribute(wnd, DF_SHADOW))
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
/* -------- draw the button's shadow ------- */
|
|
|
|
int x;
|
2003-06-19 02:48:13 +00:00
|
|
|
DfBackground = DfWndBackground(DfGetParent(wnd));
|
|
|
|
DfForeground = BLACK;
|
|
|
|
for (x = 1; x <= DfWindowWidth(wnd); x++)
|
|
|
|
DfWPutch(wnd, (char)223, x, 1);
|
|
|
|
DfWPutch(wnd, (char)220, DfWindowWidth(wnd), 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
if (ct->itext != NULL)
|
|
|
|
{
|
2005-05-11 16:50:39 +00:00
|
|
|
char *txt;
|
2003-06-19 02:48:13 +00:00
|
|
|
txt = DfCalloc(1, strlen(ct->itext)+10);
|
|
|
|
if (ct->setting == DF_OFF) {
|
|
|
|
txt[0] = DF_CHANGECOLOR;
|
2000-03-05 19:58:08 +00:00
|
|
|
txt[1] = wnd->WindowColors
|
2003-06-19 02:48:13 +00:00
|
|
|
[DF_HILITE_COLOR] [DF_FG] | 0x80;
|
2000-03-05 19:58:08 +00:00
|
|
|
txt[2] = wnd->WindowColors
|
2003-06-19 02:48:13 +00:00
|
|
|
[DF_STD_COLOR] [DF_BG] | 0x80;
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
DfCopyCommand(txt+strlen(txt),ct->itext,!ct->setting,
|
|
|
|
DfWndBackground(wnd));
|
|
|
|
DfSendMessage(wnd, DFM_CLEARTEXT, 0, 0);
|
|
|
|
DfSendMessage(wnd, DFM_ADDTEXT, (DF_PARAM) txt, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
free(txt);
|
|
|
|
}
|
|
|
|
/* --------- write the button's text ------- */
|
2003-06-19 02:48:13 +00:00
|
|
|
DfWriteTextLine(wnd, rc, 0, wnd == DfInFocus);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
void LeftButtonMsg(DFWINDOW wnd, DFMESSAGE msg, DF_CTLWINDOW *ct)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
/* --------- draw a pushed button -------- */
|
|
|
|
int x;
|
2003-06-19 02:48:13 +00:00
|
|
|
DfBackground = DfWndBackground(DfGetParent(wnd));
|
|
|
|
DfForeground = DfWndBackground(wnd);
|
|
|
|
DfWPutch(wnd, ' ', 0, 0);
|
|
|
|
for (x = 0; x < DfWindowWidth(wnd); x++)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
2003-06-19 02:48:13 +00:00
|
|
|
DfWPutch(wnd, (char)220, x+1, 0);
|
|
|
|
DfWPutch(wnd, (char)223, x+1, 1);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
if (msg == DFM_LEFT_BUTTON)
|
|
|
|
DfSendMessage(NULL, DFM_WAITMOUSE, 0, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
else
|
2003-06-19 02:48:13 +00:00
|
|
|
DfSendMessage(NULL, DFM_WAITKEYBOARD, 0, 0);
|
|
|
|
DfSendMessage(wnd, DFM_PAINT, 0, 0);
|
|
|
|
if (ct->setting == DF_ON)
|
|
|
|
DfPostMessage(DfGetParent(wnd), DFM_COMMAND, ct->command, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
else
|
2003-06-19 02:48:13 +00:00
|
|
|
DfBeep();
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
int DfButtonProc(DFWINDOW wnd, DFMESSAGE msg, DF_PARAM p1, DF_PARAM p2)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
2003-06-19 02:48:13 +00:00
|
|
|
DF_CTLWINDOW *ct = DfGetControl(wnd);
|
2000-03-05 19:58:08 +00:00
|
|
|
if (ct != NULL) {
|
|
|
|
switch (msg) {
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_SETFOCUS:
|
|
|
|
DfBaseWndProc(DF_BUTTON, wnd, msg, p1, p2);
|
2000-03-05 19:58:08 +00:00
|
|
|
p1 = 0;
|
|
|
|
/* ------- fall through ------- */
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_PAINT:
|
2000-03-05 19:58:08 +00:00
|
|
|
PaintMsg(wnd, ct, (DFRECT*)p1);
|
|
|
|
return TRUE;
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_KEYBOARD:
|
2000-03-05 19:58:08 +00:00
|
|
|
if (p1 != '\r')
|
|
|
|
break;
|
|
|
|
/* ---- fall through ---- */
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_LEFT_BUTTON:
|
2000-03-05 19:58:08 +00:00
|
|
|
LeftButtonMsg(wnd, msg, ct);
|
|
|
|
return TRUE;
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_HORIZSCROLL:
|
2000-03-05 19:58:08 +00:00
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
return DfBaseWndProc(DF_BUTTON, wnd, msg, p1, p2);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* EOF */
|