-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInputDialog.cpp
More file actions
86 lines (64 loc) · 2.61 KB
/
InputDialog.cpp
File metadata and controls
86 lines (64 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Simple input dialog (without history)
#include "config.h"
#include "i18n.h"
#include <fx.h>
#include <fxkeys.h>
#include "xfeutils.h"
#include "InputDialog.h"
FXDEFMAP(InputDialog) InputDialogMap[] =
{
FXMAPFUNC(SEL_KEYPRESS, 0, InputDialog::onCmdKeyPress),
};
// Object implementation
FXIMPLEMENT(InputDialog, DialogBox, InputDialogMap, ARRAYNUMBER(InputDialogMap))
// Construct a dialog box
InputDialog::InputDialog(FXWindow* win, FXString inp, FXString message, FXString title, FXString label, FXIcon* icon, FXbool option, FXString optiontext) :
DialogBox(win, title, DECOR_TITLE|DECOR_BORDER|DECOR_STRETCHABLE|DECOR_MAXIMIZE|DECOR_CLOSE)
{
// Buttons
FXHorizontalFrame* buttons = new FXHorizontalFrame(this, PACK_UNIFORM_WIDTH|LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X, 0, 0, 0, 0, 10, 10, 5, 5);
// Accept
new FXButton(buttons, _("&Accept"), NULL, this, ID_ACCEPT, FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT, 0, 0, 0, 0, 20, 20);
// Cancel
new FXButton(buttons, _("&Cancel"), NULL, this, ID_CANCEL, FRAME_RAISED|FRAME_THICK|LAYOUT_RIGHT, 0, 0, 0, 0, 20, 20);
// Optional check box
checkbutton = new FXHorizontalFrame(this, JUSTIFY_RIGHT|LAYOUT_SIDE_BOTTOM|LAYOUT_FILL_X, 0, 0, 0, 0, 10, 10, 0, 0);
if (option)
{
new FXCheckButton(checkbutton, optiontext, this, ID_TOGGLE_OPTION);
}
// Vertical frame
FXVerticalFrame* contents = new FXVerticalFrame(this, LAYOUT_SIDE_TOP|FRAME_NONE|LAYOUT_FILL_X|LAYOUT_FILL_Y);
// Icon and message line
FXMatrix* matrix = new FXMatrix(contents, 2, MATRIX_BY_COLUMNS|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y);
new FXLabel(matrix, "", icon, LAYOUT_LEFT);
msg = new FXLabel(matrix,"",NULL,JUSTIFY_LEFT|LAYOUT_CENTER_Y|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
msg->setText(message);
// Label and input field
new FXLabel(matrix, label, NULL, LAYOUT_RIGHT|LAYOUT_CENTER_Y|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW);
input = new FXTextField(matrix, 40, 0, 0, LAYOUT_CENTER_Y|LAYOUT_CENTER_X|FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_COLUMN|LAYOUT_FILL_ROW|LAYOUT_FILL_X);
input->setText(inp);
}
void InputDialog::create()
{
DialogBox::create();
input->setFocus();
}
long InputDialog::onCmdKeyPress(FXObject* sender, FXSelector sel, void* ptr)
{
FXEvent* event = (FXEvent*)ptr;
switch (event->code)
{
case KEY_Escape:
handle(this, FXSEL(SEL_COMMAND, ID_CANCEL), NULL);
return(1);
case KEY_KP_Enter:
case KEY_Return:
handle(this, FXSEL(SEL_COMMAND, ID_ACCEPT), NULL);
return(1);
default:
FXTopWindow::onKeyPress(sender, sel, ptr);
return(1);
}
return(0);
}