📄 dialbox.c
字号:
ct = DfFindCommand(wnd->extension, cmd, DF_SPINBUTTON);
if (ct == NULL)
ct = DfFindCommand(wnd->extension, cmd, DF_TEXT);
if (ct != NULL) {
DFWINDOW cwnd = (DFWINDOW) (ct->wnd);
switch (ct->class) {
case DF_COMBOBOX:
case DF_EDITBOX:
DfSendMessage(cwnd, DFM_CLEARTEXT, 0, 0);
DfSendMessage(cwnd, DFM_ADDTEXT, (DF_PARAM) text, 0);
if (!DfIsMultiLine(cwnd))
DfSendMessage(cwnd, DFM_PAINT, 0, 0);
break;
case DF_LISTBOX:
case DF_TEXTBOX:
case DF_SPINBUTTON:
DfSendMessage(cwnd, DFM_ADDTEXT, (DF_PARAM) text, 0);
break;
case DF_TEXT: {
DfSendMessage(cwnd, DFM_CLEARTEXT, 0, 0);
DfSendMessage(cwnd, DFM_ADDTEXT, (DF_PARAM) text, 0);
DfSendMessage(cwnd, DFM_PAINT, 0, 0);
break;
}
default:
break;
}
}
}
/* ------- get the text of a control window ------ */
void DfGetItemText(DFWINDOW wnd, enum DfCommands cmd,
char *text, int len)
{
DF_CTLWINDOW *ct = DfFindCommand(wnd->extension, cmd, DF_EDITBOX);
char *cp;
if (ct == NULL)
ct = DfFindCommand(wnd->extension, cmd, DF_COMBOBOX);
if (ct == NULL)
ct = DfFindCommand(wnd->extension, cmd, DF_TEXTBOX);
if (ct == NULL)
ct = DfFindCommand(wnd->extension, cmd, DF_TEXT);
if (ct != NULL) {
DFWINDOW cwnd = (DFWINDOW) (ct->wnd);
if (cwnd != NULL) {
switch (ct->class) {
case DF_TEXT:
if (DfGetText(cwnd) != NULL) {
cp = strchr(DfGetText(cwnd), '\n');
if (cp != NULL)
len = (int) (cp - DfGetText(cwnd));
strncpy(text, DfGetText(cwnd), len);
*(text+len) = '\0';
}
break;
case DF_TEXTBOX:
if (DfGetText(cwnd) != NULL)
strncpy(text, DfGetText(cwnd), len);
break;
case DF_COMBOBOX:
case DF_EDITBOX:
DfSendMessage(cwnd,DFM_GETTEXT,(DF_PARAM)text,len);
break;
default:
break;
}
}
}
}
/* ------- set the text of a listbox control window ------ */
void DfGetDlgListText(DFWINDOW wnd, char *text, enum DfCommands cmd)
{
DF_CTLWINDOW *ct = DfFindCommand(wnd->extension, cmd, DF_LISTBOX);
int sel = DfSendMessage(ct->wnd, DFM_LB_CURRENTSELECTION, 0, 0);
DfSendMessage(ct->wnd, DFM_LB_GETTEXT, (DF_PARAM) text, sel);
}
/* -- find control structure associated with text control -- */
static DF_CTLWINDOW *AssociatedControl(DF_DBOX *db,enum DfCommands Tcmd)
{
DF_CTLWINDOW *ct = db->ctl;
while (ct->class) {
if (ct->class != DF_TEXT)
if (ct->command == Tcmd)
break;
ct++;
}
return ct;
}
/* --- process dialog box shortcut keys --- */
static void dbShortcutKeys(DF_DBOX *db, int ky)
{
DF_CTLWINDOW *ct;
int ch = DfAltConvert(ky);
if (ch != 0) {
ct = db->ctl;
while (ct->class) {
char *cp = ct->itext;
while (cp && *cp) {
if (*cp == DF_SHORTCUTCHAR &&
tolower(*(cp+1)) == ch) {
if (ct->class == DF_TEXT)
ct = AssociatedControl(db, ct->command);
if (ct->class == DF_RADIOBUTTON)
DfSetRadioButton(db, ct);
else if (ct->class == DF_CHECKBOX) {
ct->setting ^= DF_ON;
DfSendMessage(ct->wnd, DFM_PAINT, 0, 0);
}
else if (ct->class) {
DfSendMessage(ct->wnd, DFM_SETFOCUS, TRUE, 0);
if (ct->class == DF_BUTTON)
DfSendMessage(ct->wnd,DFM_KEYBOARD,'\r',0);
}
return;
}
cp++;
}
ct++;
}
}
}
/* --- dynamically add or remove scroll bars
from a control window ---- */
void DfSetScrollBars(DFWINDOW wnd)
{
int oldattr = DfGetAttribute(wnd);
if (wnd->wlines > DfClientHeight(wnd))
DfAddAttribute(wnd, DF_VSCROLLBAR);
else
DfClearAttribute(wnd, DF_VSCROLLBAR);
if (wnd->textwidth > DfClientWidth(wnd))
DfAddAttribute(wnd, DF_HSCROLLBAR);
else
DfClearAttribute(wnd, DF_HSCROLLBAR);
if (DfGetAttribute(wnd) != oldattr)
DfSendMessage(wnd, DFM_BORDER, 0, 0);
}
/* ------- DFM_CREATE_WINDOW Message (Control) ----- */
static void CtlCreateWindowMsg(DFWINDOW wnd)
{
DF_CTLWINDOW *ct;
ct = wnd->ct = wnd->extension;
wnd->extension = NULL;
if (ct != NULL)
ct->wnd = wnd;
}
/* ------- DFM_KEYBOARD Message (Control) ----- */
static BOOL CtlKeyboardMsg(DFWINDOW wnd, DF_PARAM p1, DF_PARAM p2)
{
DF_CTLWINDOW *ct = DfGetControl(wnd);
switch ((int) p1) {
case DF_F1:
if (DfWindowMoving || DfWindowSizing)
break;
if (!DfDisplayHelp(wnd, ct->help))
DfSendMessage(DfGetParent(wnd),DFM_COMMAND,DF_ID_HELP,0);
return TRUE;
case ' ':
if (!((int)p2 & DF_ALTKEY))
break;
case DF_ALT_F6:
case DF_CTRL_F4:
case DF_ALT_F4:
DfPostMessage(DfGetParent(wnd), DFM_KEYBOARD, p1, p2);
return TRUE;
default:
break;
}
if (DfGetClass(wnd) == DF_EDITBOX)
if (DfIsMultiLine(wnd))
return FALSE;
switch ((int) p1) {
case DF_UP:
if (!DfIsDerivedFrom(wnd, DF_LISTBOX)) {
p1 = DF_CTRL_FIVE;
p2 = DF_LEFTSHIFT;
}
break;
case DF_BS:
if (!DfIsDerivedFrom(wnd, DF_EDITBOX)) {
p1 = DF_CTRL_FIVE;
p2 = DF_LEFTSHIFT;
}
break;
case DF_DN:
if (!DfIsDerivedFrom(wnd, DF_LISTBOX) &&
!DfIsDerivedFrom(wnd, DF_COMBOBOX))
p1 = '\t';
break;
case DF_FWD:
if (!DfIsDerivedFrom(wnd, DF_EDITBOX))
p1 = '\t';
break;
case '\r':
if (DfIsDerivedFrom(wnd, DF_EDITBOX))
if (DfIsMultiLine(wnd))
break;
if (DfIsDerivedFrom(wnd, DF_BUTTON))
break;
DfSendMessage(DfGetParent(wnd), DFM_COMMAND, DF_ID_OK, 0);
return TRUE;
default:
break;
}
return FALSE;
}
/* ------- DFM_CLOSE_WINDOW Message (Control) ----- */
static void CtlCloseWindowMsg(DFWINDOW wnd)
{
DF_CTLWINDOW *ct = DfGetControl(wnd);
if (ct != NULL) {
ct->wnd = NULL;
if (DfGetParent(wnd)->ReturnCode == DF_ID_OK) {
if (ct->class == DF_EDITBOX || ct->class == DF_COMBOBOX) {
if (wnd->TextChanged) {
ct->itext=DfRealloc(ct->itext,strlen(wnd->text)+1);
strcpy(ct->itext, wnd->text);
if (!DfIsMultiLine(wnd)) {
char *cp = ct->itext+strlen(ct->itext)-1;
if (*cp == '\n')
*cp = '\0';
}
}
}
else if (ct->class == DF_RADIOBUTTON || ct->class == DF_CHECKBOX)
ct->isetting = ct->setting;
}
}
}
static void FixColors(DFWINDOW wnd)
{
DF_CTLWINDOW *ct = wnd->ct;
if (ct->class != DF_BUTTON)
{
if (ct->class != DF_SPINBUTTON && ct->class != DF_COMBOBOX)
{
wnd->WindowColors[DF_FRAME_COLOR][DF_FG] =
DfGetParent(wnd)->WindowColors[DF_FRAME_COLOR][DF_FG];
wnd->WindowColors[DF_FRAME_COLOR][DF_BG] =
DfGetParent(wnd)->WindowColors[DF_FRAME_COLOR][DF_BG];
if (ct->class != DF_EDITBOX && ct->class != DF_LISTBOX)
{
wnd->WindowColors[DF_STD_COLOR][DF_FG] =
DfGetParent(wnd)->WindowColors[DF_STD_COLOR][DF_FG];
wnd->WindowColors[DF_STD_COLOR][DF_BG] =
DfGetParent(wnd)->WindowColors[DF_STD_COLOR][DF_BG];
}
}
}
}
/* -- generic window processor used by dialog box controls -- */
static int ControlProc(DFWINDOW wnd,DFMESSAGE msg,DF_PARAM p1,DF_PARAM p2)
{
DF_DBOX *db;
if (wnd == NULL)
return FALSE;
db = DfGetParent(wnd) ? DfGetParent(wnd)->extension : NULL;
switch (msg) {
case DFM_CREATE_WINDOW:
CtlCreateWindowMsg(wnd);
break;
case DFM_KEYBOARD:
if (CtlKeyboardMsg(wnd, p1, p2))
return TRUE;
break;
case DFM_PAINT:
FixColors(wnd);
if (DfGetClass(wnd) == DF_EDITBOX ||
DfGetClass(wnd) == DF_LISTBOX ||
DfGetClass(wnd) == DF_TEXTBOX)
DfSetScrollBars(wnd);
break;
case DFM_BORDER:
FixColors(wnd);
if (DfGetClass(wnd) == DF_EDITBOX) {
DFWINDOW oldFocus = DfInFocus;
DfInFocus = NULL;
DfDefaultWndProc(wnd, msg, p1, p2);
DfInFocus = oldFocus;
return TRUE;
}
break;
case DFM_SETFOCUS: {
DFWINDOW pwnd = DfGetParent(wnd);
if (p1)
{
DfDefaultWndProc(wnd, msg, p1, p2);
if (pwnd != NULL)
{
pwnd->dfocus = wnd;
DfSendMessage(pwnd, DFM_COMMAND,
inFocusCommand(db), DFM_ENTERFOCUS);
}
return TRUE;
}
else
DfSendMessage(pwnd, DFM_COMMAND,
inFocusCommand(db), DFM_LEAVEFOCUS);
break;
}
case DFM_CLOSE_WINDOW:
CtlCloseWindowMsg(wnd);
break;
default:
break;
}
return DfDefaultWndProc(wnd, msg, p1, p2);
}
/* ---- change the focus to the first control --- */
static void FirstFocus(DF_DBOX *db)
{
DF_CTLWINDOW *ct = db->ctl;
if (ct != NULL)
{
while (ct->class == DF_TEXT || ct->class == DF_BOX) {
ct++;
if (ct->class == 0)
return;
}
DfSendMessage(ct->wnd, DFM_SETFOCUS, TRUE, 0);
}
}
/* ---- change the focus to the next control --- */
static void NextFocus(DF_DBOX *db)
{
DF_CTLWINDOW *ct = WindowControl(db, DfInFocus);
int looped = 0;
if (ct != NULL)
{
do
{
ct++;
if (ct->class == 0)
{
if (looped)
return;
looped++;
ct = db->ctl;
}
} while (ct->class == DF_TEXT || ct->class == DF_BOX);
DfSendMessage(ct->wnd, DFM_SETFOCUS, TRUE, 0);
}
}
/* ---- change the focus to the previous control --- */
static void PrevFocus(DF_DBOX *db)
{
DF_CTLWINDOW *ct = WindowControl(db, DfInFocus);
int looped = 0;
if (ct != NULL)
{
do
{
if (ct == db->ctl)
{
if (looped)
return;
looped++;
while (ct->class)
ct++;
}
--ct;
} while (ct->class == DF_TEXT || ct->class == DF_BOX);
DfSendMessage(ct->wnd, DFM_SETFOCUS, TRUE, 0);
}
}
void DfSetFocusCursor(DFWINDOW wnd)
{
if (wnd == DfInFocus)
{
DfSendMessage(NULL, DFM_SHOW_CURSOR, 0, 0);
DfSendMessage(wnd, DFM_KEYBOARD_CURSOR, 1, 0);
}
}
/* EOF */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -