querydialog.c
来自「Very very small GUI. Usefull for small s」· C语言 代码 · 共 146 行
C
146 行
#include <membox.h>
#include "GUI.h"
#include "Globalvars.h"
#include "pwin.h"
#include "guidebug.h"
#define BUTTON_DEFAULT_FONT F9x15_pwf
extern unsigned char xhuge _HeapGUI[GUI_HEAP_SIZE];
void RepaintQueryDialog (Pw_GC * gc);
void QueryEndDialog (Pw_Window * win) ;
//---------------------------------------------------
int HandleQueryDialog (Pw_Event * ev) {
Pw_Window * win;
//Pw_Window * new_focus_control;
//Pw_UserEvent * UserEvent;
//int CtrlID;
//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 ESC_KEY :
QueryEndDialog(win);
return TRUE;
case ENTER_KEY :
new_focus_control = Pw_DisplayGetFocusWindow(&Display);
CtrlType = Pw_WindowGetClientDataId(new_focus_control);
if (CtrlType == CANCEL_BUTT_ID) {
if (ResProc) {
QueryEndDialog(win);
}
}
else {
if (CtrlType == OK_BUTT_ID) {
if (ResProc) {
ResProc(Pw_EventGetWindow(ev), TRUE);
QueryEndDialog(win);
}
}
}
return TRUE;
} */
case Pw_UserEventType :
break;
case Pw_DestroyEventType :
_free_boxh (_HeapGUI, Pw_EventGetWindow(ev));
return TRUE;
}
return FALSE;
}
//---------------------------------------------------
void RepaintQueryDialog (Pw_GC * gc) {
Pw_Window* win;
Pw_Coord w, h;
int x, y, ty;
char * sm = "Confirmation\0";
win = Pw_GCGetWindow(gc);
Pw_WindowGetSize(win, &w, &h);
Pw_GCSetFont(gc, BUTTON_DEFAULT_FONT);
Pw_GCSetColor(gc, pw_black_pixel);
Pw_DrawFrameRect(gc, 0, 0, w, h, 2, NULL);
ty = Pw_GCGetFontHeight(gc);
Pw_GCSetColor(gc, pw_white_pixel);
Pw_FillRect(gc, 0, 0, w, ty + 4);
x = (w - Pw_FontGetStringWidth(gc->font, sm))/2;
y = ty - 2;
Pw_GCSetColor(gc, pw_black_pixel); // header
Pw_DrawString(gc, x, y, sm);
}
//---------------------------------------------------
void QueryEndDialog (Pw_Window * win) {
Pw_Window* parent;
parent = win->parent;
Pw_WindowUnmap(win);
DialogFree(win);
BPA_GUI_SendMessage(parent, GUI_BUTTON_PRESSED, NULL);//&MeasPoint);
//GUI_Log("ESC END QUERY DIALOG");
}
//---------------------------------------------------
int cbDialog (Pw_Event * ev);
Pw_Window * CreateQueryDialog(TResFunc ResProc , Pw_Window * Parent, char * Caption, char * ButtA, char * ButtB) {
CONTROL_CREATE_INFO CaptionText;
CONTROL_CREATE_INFO ButtonA;
CONTROL_CREATE_INFO ButtonB;
Pw_Window * DialogWin;
Pw_Window * Control;
int x, y, w, h, wt;
x = 20, y = 80; w = 280; h = 80;
CaptionText.ControllCreate = CreateStaticText;
ButtonA.ControllCreate = CreateButton;
ButtonB.ControllCreate = CreateButton;
CaptionText.ID = STATICTEXT_ID;
ButtonA.ID = OK_BUTT_ID;
ButtonB.ID = CANCEL_BUTT_ID;
CaptionText.FocusAccept = FALSE;
ButtonA.FocusAccept = TRUE;
ButtonB.FocusAccept = TRUE;
CaptionText.x0 = 10; CaptionText.y0 = 23;
wt = Pw_FontGetStringWidth(BUTTON_DEFAULT_FONT, Caption);
if ((w - wt) < 16) w = wt + 16;
if (w > 280) w = 280;
CaptionText.xSize = w - 10;
x = (LCD_XSIZE - w)/2;
CaptionText.ySize = Pw_FontGetHeight(BUTTON_DEFAULT_FONT)+4;
ButtonA.x0 = 48; ButtonA.y0 = h - 30; ButtonA.xSize = 80; ButtonA.ySize = 19;
ButtonB.x0 = 168; ButtonB.y0 = h - 30; ButtonB.xSize = 80; ButtonB.ySize = 19;
ButtonA.DefaultControl = TRUE;
ButtonB.DefaultControl = FALSE;
DialogWin = _calloc_boxh (_HeapGUI);
Pw_WindowCreate(Parent, x, y, w, h, DialogWin);
Pw_WindowSetRepaintCallback(DialogWin, RepaintQueryDialog);
// Pw_WindowSetEventCallback(DialogWin, HandleQueryDialog);
Pw_WindowSetEventCallback(DialogWin, cbDialog);
Pw_WindowSetClientData(DialogWin, (void*)ResProc);// !!!!!
Pw_WindowSetFocusAccept(DialogWin, TRUE);
Pw_WindowMap(DialogWin);
Pw_WindowSetFocus(DialogWin);
Control = CreateStaticText(&CaptionText, DialogWin, NULL);
Pw_WindowSetClientData(Control, Caption);
Control = CreateButton(&ButtonB, DialogWin, NULL);
Pw_WindowSetClientData(Control, ButtB);
Control = CreateButton(&ButtonA, DialogWin, NULL);
Pw_WindowSetClientData(Control, ButtA);
Pw_WindowSetFocus(Control);
Pw_WindowRepaint(DialogWin);
return (DialogWin);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?