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