📄 dialog.c
字号:
#include "GUI.h"
#include <membox.h>
#include "pwin.h"
#include "guidebug.h"
Pw_Window * FocusedControl;
extern unsigned char xhuge _HeapGUI[GUI_HEAP_SIZE];
void cbRepaintDialog(Pw_GC * gc) {
Pw_Window* win;
Pw_Coord w, h;
win = Pw_GCGetWindow(gc);
Pw_WindowGetSize(win, &w, &h);
Pw_DrawFrameRect(gc, 0, 0, w, h, 1, NULL);
}
Pw_Window * GetPrevFocusAccepteble(void) {
Pw_Window * ctrl;
ctrl = Pw_WindowGetWindowAbove(FocusedControl);
while (ctrl && !(ctrl->focus_accept)) {
ctrl = Pw_WindowGetWindowAbove(ctrl);
}
return (ctrl);
}
Pw_Window * GetNextFocusAccepteble(void) {
Pw_Window * ctrl;
ctrl = Pw_WindowGetWindowBelow(FocusedControl);
while (ctrl && !(ctrl->focus_accept)) {
ctrl = Pw_WindowGetWindowBelow(ctrl);
}
return (ctrl);
}
//----------------------------------------------------------------
int cbDialog (Pw_Event * ev) {
Pw_Window * win ;
Pw_Window * new_focus_control;
int key;
TResFunc * ResProc;
int CtrlType;
win = Pw_EventGetWindow(ev);
ResProc = (TResFunc*) Pw_WindowGetClientData(win);
switch (Pw_EventGetType(ev)) {
case Pw_KeyPressEventType:
key = ev->key.keycode;
switch (key) {
case UP_KEY :
FocusedControl = Pw_DisplayGetFocusWindow(&Display);
new_focus_control = GetPrevFocusAccepteble();
if (new_focus_control && new_focus_control->focus_accept) {
Pw_WindowSetFocus(new_focus_control);
Pw_WindowRepaint(FocusedControl);
Pw_WindowRepaint(new_focus_control);
}
return TRUE;
case DOWN_KEY :
FocusedControl = Pw_DisplayGetFocusWindow(&Display);
new_focus_control = GetNextFocusAccepteble();
if (new_focus_control && new_focus_control->focus_accept) {
Pw_WindowSetFocus(new_focus_control);
Pw_WindowRepaint(FocusedControl);
Pw_WindowRepaint(new_focus_control);
}
return TRUE;
case ESC_KEY :
if (ResProc) {
ResProc(Pw_EventGetWindow(ev), FALSE);
return TRUE;
}
case ENTER_KEY :
new_focus_control = Pw_DisplayGetFocusWindow(&Display);
CtrlType = Pw_WindowGetClientDataId(new_focus_control);
if (CtrlType == OK_BUTT_ID) {
if (ResProc) {
ResProc(Pw_EventGetWindow(ev), TRUE);
return TRUE;
}
}
if (CtrlType == CANCEL_BUTT_ID) {
if (ResProc) {
ResProc(Pw_EventGetWindow(ev), FALSE);
return TRUE;
}
}
/* else
ResProc(Pw_EventGetWindow(ev), FALSE); */
return FALSE;
}
break;
case Pw_UserEventType :
break;
case Pw_DestroyEventType :
// GUI_Log1("DESTROY DIALOG", (unsigned long)Pw_EventGetWindow(ev));
_free_boxh (_HeapGUI, Pw_EventGetWindow(ev));
return TRUE;
}
return FALSE;
}
//----------------------------------------------------------------
Pw_Window * DialogCreate (const CONTROL_CREATE_INFO *info_struct ,
int CtrlCnt, Pw_Window * Parent,
TResFunc ResProc,
int x0, int y0, int width, int heigth) {
Pw_Window * DialogWin;
Pw_Window * Control;
//GUI_Log("CREATE DIALOG");
DialogWin = _calloc_boxh (_HeapGUI);
Pw_WindowCreate(Parent, x0, y0, width, heigth, DialogWin);
Pw_WindowSetRepaintCallback(DialogWin, cbRepaintDialog);
Pw_WindowSetEventCallback(DialogWin, cbDialog);
Pw_WindowSetClientData(DialogWin, (void*)ResProc);
Pw_WindowSetFocusAccept(DialogWin, TRUE);
Pw_WindowMap(DialogWin);
Pw_WindowSetFocus(DialogWin);
info_struct += CtrlCnt;
FocusedControl = NULL;
//GUI_Log1("Control count", CtrlCnt);
while (CtrlCnt-- > 0) {
info_struct--;
Control = info_struct->ControllCreate(info_struct, DialogWin, NULL);
if (info_struct->DefaultControl)
FocusedControl = Control;
}
if (FocusedControl) {
Pw_WindowSetFocus(FocusedControl);
Pw_WindowRepaint(FocusedControl);
}
//GUI_Log("DIALOG Created");
return DialogWin;
}
void DialogFree(Pw_Window * dialog) {
Pw_WindowDestroy (dialog);
//GUI_Log1("RETURN ", (long)Pw_WindowGetChildWindowOnTop(Desktop));
Pw_WindowSetFocus(GetTopChildVisibleVindow(Desktop));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -