1
// =====================================================================
5
// Author: Stelios Buononos, M0GLD
8
// This file is part of flrig.
10
// flrig is free software; you can redistribute it and/or modify
11
// it under the terms of the GNU General Public License as published by
12
// the Free Software Foundation; either version 3 of the License, or
13
// (at your option) any later version.
15
// flrig is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU General Public License for more details.
20
// You should have received a copy of the GNU General Public License
21
// along with this program. If not, see <http://www.gnu.org/licenses/>.
22
// ----------------------------------------------------------------------------
27
#include <FL/Fl_Window.H>
28
#include <FL/Fl_Widget.H>
29
#include <FL/Fl_Input.H>
30
#include <FL/Fl_Menu_Item.H>
31
#include <FL/Fl_Tooltip.H>
40
enum { OP_UNDO, OP_CUT, OP_COPY, OP_PASTE, OP_DELETE, OP_CLEAR, OP_SELECT_ALL };
42
static Fl_Menu_Item cmenu[] = {
43
{ make_icon_label(_("Undo"), edit_undo_icon), 0, 0, 0, FL_MENU_DIVIDER, _FL_MULTI_LABEL },
44
{ make_icon_label(_("Cut"), edit_cut_icon), 0, 0, 0, 0, _FL_MULTI_LABEL },
45
{ make_icon_label(_("Copy"), edit_copy_icon), 0, 0, 0, 0, _FL_MULTI_LABEL },
46
{ make_icon_label(_("Paste"), edit_paste_icon), 0, 0, 0, 0, _FL_MULTI_LABEL },
47
{ make_icon_label(_("Delete"), trash_icon), 0, 0, 0, 0, _FL_MULTI_LABEL },
48
{ make_icon_label(_("Clear"), edit_clear_icon), 0, 0, 0, FL_MENU_DIVIDER, _FL_MULTI_LABEL },
49
{ make_icon_label(_("Select All"), edit_select_all_icon), 0, 0, 0, 0, _FL_MULTI_LABEL },
52
static bool cmenu_init = false;
55
Fl_Input2::Fl_Input2(int x, int y, int w, int h, const char* l)
56
: Fl_Input(x, y, w, h, l)
59
for (size_t i = 0; i < sizeof(cmenu)/sizeof(*cmenu) - 1; i++)
60
if (cmenu[i].labeltype() == _FL_MULTI_LABEL)
61
set_icon_label(&cmenu[i]);
66
int Fl_Input2::handle(int event)
70
int b = Fl::event_key();
72
// stop the move-to-next-field madness, we have Tab for that!
73
if (unlikely((b == FL_Left && p == 0) || (b == FL_Right && p == size()) ||
74
(b == FL_Up && line_start(p) == 0) ||
75
(b == FL_Down && line_end(p) == size())))
77
else if (unlikely(Fl::event_state() & (FL_ALT | FL_META))) {
79
case 'c': { // capitalise
80
if (readonly() || p == size())
83
while (p < size() && isspace(*(value() + p)))
87
char c = toupper(*(value() + p));
88
replace(p, p + 1, &c, 1);
89
position(word_end(p));
92
case 'u': case 'l': { // upper/lower case
93
if (readonly() || p == size())
95
while (p < size() && isspace(*(value() + p)))
97
int n = word_end(p) - p;
101
char* s = new char[n];
102
memcpy(s, value() + p, n);
104
for (int i = 0; i < n; i++)
105
s[i] = toupper(s[i]);
107
for (int i = 0; i < n; i++)
108
s[i] = tolower(s[i]);
109
replace(p, p + n, s, n);
119
return Fl_Input::handle(event);
120
case FL_MOUSEWHEEL: {
121
if (!((type() & (FL_MULTILINE_INPUT | FL_MULTILINE_OUTPUT)) && Fl::event_inside(this)))
122
return Fl_Input::handle(event);
124
if (!((d = Fl::event_dy()) || (d = Fl::event_dx())))
125
return Fl_Input::handle(event);
126
if (Fl::focus() != this)
128
up_down_position(d + (d > 0 ? line_end(position()) : line_start(position())));
132
if (Fl::event_button() == FL_RIGHT_MOUSE)
136
return Fl_Input::handle(event);
139
bool sel = position() != mark(), ro = readonly();
140
set_active(&cmenu[OP_UNDO], !ro);
141
set_active(&cmenu[OP_CUT], !ro && sel);
142
set_active(&cmenu[OP_COPY], sel);
143
set_active(&cmenu[OP_PASTE], !ro);
144
set_active(&cmenu[OP_DELETE], !ro && sel);
145
set_active(&cmenu[OP_CLEAR], !ro && size());
146
set_active(&cmenu[OP_SELECT_ALL], size());
149
window()->cursor(FL_CURSOR_DEFAULT);
150
int t = Fl_Tooltip::enabled();
151
Fl_Tooltip::disable();
152
const Fl_Menu_Item* m = cmenu->popup(Fl::event_x(), Fl::event_y());
153
Fl_Tooltip::enable(t);