1
// =====================================================================
5
// Author: Stelios Buononos, M0GLD
8
// This software is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It is
11
// copyright under the GNU General Public License.
13
// You should have received a copy of the GNU General Public License
14
// along with the program; if not, write to the Free Software
16
// 59 Temple Place, Suite 330
17
// Boston, MA 02111-1307 USA
19
// =====================================================================
24
#include <FL/Fl_Window.H>
25
#include <FL/Fl_Widget.H>
26
#include <FL/Fl_Input.H>
27
#include <FL/Fl_Menu_Item.H>
28
#include <FL/Fl_Tooltip.H>
37
enum { OP_UNDO, OP_CUT, OP_COPY, OP_PASTE, OP_DELETE, OP_CLEAR, OP_SELECT_ALL };
39
static Fl_Menu_Item cmenu[] = {
40
{ make_icon_label(_("Undo"), edit_undo_icon), 0, 0, 0, FL_MENU_DIVIDER, _FL_MULTI_LABEL },
41
{ make_icon_label(_("Cut"), edit_cut_icon), 0, 0, 0, 0, _FL_MULTI_LABEL },
42
{ make_icon_label(_("Copy"), edit_copy_icon), 0, 0, 0, 0, _FL_MULTI_LABEL },
43
{ make_icon_label(_("Paste"), edit_paste_icon), 0, 0, 0, 0, _FL_MULTI_LABEL },
44
{ make_icon_label(_("Delete"), trash_icon), 0, 0, 0, 0, _FL_MULTI_LABEL },
45
{ make_icon_label(_("Clear"), edit_clear_icon), 0, 0, 0, FL_MENU_DIVIDER, _FL_MULTI_LABEL },
46
{ make_icon_label(_("Select All"), edit_select_all_icon), 0, 0, 0, 0, _FL_MULTI_LABEL },
49
static bool cmenu_init = false;
52
Fl_Input2::Fl_Input2(int x, int y, int w, int h, const char* l)
53
: Fl_Input(x, y, w, h, l)
56
for (size_t i = 0; i < sizeof(cmenu)/sizeof(*cmenu) - 1; i++)
57
if (cmenu[i].labeltype() == _FL_MULTI_LABEL)
58
set_icon_label(&cmenu[i]);
63
int Fl_Input2::handle(int event)
67
int b = Fl::event_key();
69
// stop the move-to-next-field madness, we have Tab for that!
70
if (unlikely((b == FL_Left && p == 0) || (b == FL_Right && p == size()) ||
71
(b == FL_Up && line_start(p) == 0) ||
72
(b == FL_Down && line_end(p) == size())))
74
else if (unlikely(Fl::event_state() & (FL_ALT | FL_META))) {
76
case 'c': { // capitalise
77
if (readonly() || p == size())
80
while (p < size() && isspace(*(value() + p)))
84
char c = toupper(*(value() + p));
85
replace(p, p + 1, &c, 1);
86
position(word_end(p));
89
case 'u': case 'l': { // upper/lower case
90
if (readonly() || p == size())
92
while (p < size() && isspace(*(value() + p)))
94
int n = word_end(p) - p;
98
char* s = new char[n];
99
memcpy(s, value() + p, n);
101
for (int i = 0; i < n; i++)
102
s[i] = toupper(s[i]);
104
for (int i = 0; i < n; i++)
105
s[i] = tolower(s[i]);
106
replace(p, p + n, s, n);
116
return Fl_Input::handle(event);
117
case FL_MOUSEWHEEL: {
118
if (!((type() & (FL_MULTILINE_INPUT | FL_MULTILINE_OUTPUT)) && Fl::event_inside(this)))
119
return Fl_Input::handle(event);
121
if (!((d = Fl::event_dy()) || (d = Fl::event_dx())))
122
return Fl_Input::handle(event);
123
if (Fl::focus() != this)
125
up_down_position(d + (d > 0 ? line_end(position()) : line_start(position())));
129
if (Fl::event_button() == FL_RIGHT_MOUSE)
133
return Fl_Input::handle(event);
136
bool sel = position() != mark(), ro = readonly();
137
set_active(&cmenu[OP_UNDO], !ro);
138
set_active(&cmenu[OP_CUT], !ro && sel);
139
set_active(&cmenu[OP_COPY], sel);
140
set_active(&cmenu[OP_PASTE], !ro);
141
set_active(&cmenu[OP_DELETE], !ro && sel);
142
set_active(&cmenu[OP_CLEAR], !ro && size());
143
set_active(&cmenu[OP_SELECT_ALL], size());
146
window()->cursor(FL_CURSOR_DEFAULT);
147
int t = Fl_Tooltip::enabled();
148
Fl_Tooltip::disable();
149
const Fl_Menu_Item* m = cmenu->popup(Fl::event_x(), Fl::event_y());
150
Fl_Tooltip::enable(t);