-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDirHistBox.cpp
More file actions
132 lines (101 loc) · 3.62 KB
/
DirHistBox.cpp
File metadata and controls
132 lines (101 loc) · 3.62 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Display a history list box and allows the user to select a string
// This is based on FXChoiceBox
#include "config.h"
#include "config.h"
#include "i18n.h"
#include <fx.h>
#include <fxkeys.h>
#include "xfedefs.h"
#include "DirHistBox.h"
#define VISIBLE_LINES 10
// Map
FXDEFMAP(DirHistBox) DirHistBoxMap[] =
{
FXMAPFUNC(SEL_KEYPRESS, 0, DirHistBox::onKeyPress),
FXMAPFUNC(SEL_KEYRELEASE, 0, DirHistBox::onKeyRelease),
FXMAPFUNC(SEL_FOCUSOUT, 0, DirHistBox::onCmdClose),
FXMAPFUNC(SEL_COMMAND, DirHistBox::ID_CLOSE, DirHistBox::onCmdClose),
FXMAPFUNC(SEL_CLICKED, DirHistBox::ID_CLICKED, DirHistBox::onCmdClicked),
};
// Object implementation
FXIMPLEMENT(DirHistBox, DialogBox, DirHistBoxMap, ARRAYNUMBER(DirHistBoxMap))
// Construct list box with given caption, icon, message text, and with choices from array of strings
DirHistBox::DirHistBox(FXWindow* owner, const char** choices, FXuint opts, int x, int y, int w, int h) :
DialogBox(owner, "", opts, x, y, w, h, 0, 0, 0, 0, 0, 0)
{
register int n;
FXHorizontalFrame* hor = new FXHorizontalFrame(this, FRAME_RAISED|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
list = new FXList(hor, this, ID_CLICKED, LIST_BROWSESELECT|LAYOUT_FILL_Y|LAYOUT_FILL_X|HSCROLLING_OFF);
list->setBackColor(this->getBackColor());
n = list->fillItems(choices);
list->setNumVisible(FXMIN(n, VISIBLE_LINES));
}
// Construct list box with given caption, icon, message text, and with choices from newline separated strings
DirHistBox::DirHistBox(FXWindow* owner, const FXString& choices, FXuint opts, int x, int y, int w, int h) :
DialogBox(owner, "", opts, x, y, w, h, 0, 0, 0, 0, 0, 0)
{
register int n;
FXHorizontalFrame* hor = new FXHorizontalFrame(this, FRAME_RAISED|FRAME_THICK|LAYOUT_SIDE_TOP|LAYOUT_FILL_X|LAYOUT_FILL_Y, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
list = new FXList(hor, this, ID_CLICKED, LIST_BROWSESELECT|LAYOUT_FILL_Y|LAYOUT_FILL_X|HSCROLLING_OFF);
list->setBackColor(this->getBackColor());
n = list->fillItems(choices);
list->setNumVisible(FXMIN(n, VISIBLE_LINES));
}
// Select item when click in list
long DirHistBox::onCmdClicked(FXObject*, FXSelector, void*)
{
getApp()->stopModal(this, list->getCurrentItem());
hide();
return(1);
}
// Close dialog
long DirHistBox::onCmdClose(FXObject*, FXSelector, void*)
{
getApp()->stopModal(this, -1);
hide();
return(1);
}
// Destroy list box
DirHistBox::~DirHistBox()
{
list = (FXList*)-1L;
}
// Show a modal list dialog
int DirHistBox::box(FXWindow* owner, FXuint opts, const char** choices, int x, int y, int w, int h)
{
DirHistBox box(owner, choices, opts, x, y, w, h);
return(box.execute(PLACEMENT_DEFAULT));
}
// Show a modal list dialog
int DirHistBox::box(FXWindow* owner, FXuint opts, const FXString& choices, int x, int y, int w, int h)
{
DirHistBox box(owner, choices, opts, x, y, w, h);
return(box.execute(PLACEMENT_DEFAULT));
}
// Keyboard press; handle escape to close the dialog
long DirHistBox::onKeyPress(FXObject* sender, FXSelector sel, void* ptr)
{
if (FXTopWindow::onKeyPress(sender, sel, ptr))
{
return(1);
}
if (((FXEvent*)ptr)->code == KEY_Escape)
{
handle(this, FXSEL(SEL_COMMAND, ID_CLOSE), NULL);
return(1);
}
return(0);
}
// Keyboard release; handle escape to close the dialog
long DirHistBox::onKeyRelease(FXObject* sender, FXSelector sel, void* ptr)
{
if (FXTopWindow::onKeyRelease(sender, sel, ptr))
{
return(1);
}
if (((FXEvent*)ptr)->code == KEY_Escape)
{
return(1);
}
return(0);
}