~ubuntu-branches/ubuntu/wily/flrig/wily

« back to all changes in this revision

Viewing changes to .pc/0001-License-Declaration.patch/src/flinput2.cxx

  • Committer: Package Import Robot
  • Author(s): Kamal Mostafa
  • Date: 2014-10-25 11:17:10 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20141025111710-n32skgya3l9u1brw
Tags: 1.3.17-1
* New upstream release (Closes: #761839)
* Debian Standards-Version: 3.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// =====================================================================
2
 
//
3
 
// flinput2.cxx
4
 
//
5
 
// Author: Stelios Buononos, M0GLD
6
 
// Copyright: 2010
7
 
//
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.
12
 
//
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
15
 
// Foundation, Inc.
16
 
// 59 Temple Place, Suite 330
17
 
// Boston, MA  02111-1307 USA
18
 
//
19
 
// =====================================================================
20
 
 
21
 
#include <cctype>
22
 
 
23
 
#include <FL/Fl.H>
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>
29
 
 
30
 
#include "config.h"
31
 
 
32
 
#include "icons.h"
33
 
#include "flinput2.h"
34
 
#include "gettext.h"
35
 
#include "util.h"
36
 
 
37
 
enum { OP_UNDO, OP_CUT, OP_COPY, OP_PASTE, OP_DELETE, OP_CLEAR, OP_SELECT_ALL };
38
 
 
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 },
47
 
        { 0 }
48
 
};
49
 
static bool cmenu_init = false;
50
 
 
51
 
 
52
 
Fl_Input2::Fl_Input2(int x, int y, int w, int h, const char* l)
53
 
        : Fl_Input(x, y, w, h, l)
54
 
{
55
 
        if (!cmenu_init) {
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]);
59
 
                cmenu_init = true;
60
 
        }
61
 
}
62
 
 
63
 
int Fl_Input2::handle(int event)
64
 
{
65
 
        switch (event) {
66
 
        case FL_KEYBOARD: {
67
 
                int b = Fl::event_key();
68
 
                int p = position();
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())))
73
 
                        return 1;
74
 
                else if (unlikely(Fl::event_state() & (FL_ALT | FL_META))) {
75
 
                        switch (b) {
76
 
                        case 'c': { // capitalise
77
 
                                if (readonly() || p == size())
78
 
                                        return 1;
79
 
 
80
 
                                while (p < size() && isspace(*(value() + p)))
81
 
                                        p++;
82
 
                                if (p == size())
83
 
                                        return 1;
84
 
                                char c = toupper(*(value() + p));
85
 
                                replace(p, p + 1, &c, 1);
86
 
                                position(word_end(p));
87
 
                        }
88
 
                                return 1;
89
 
                        case 'u': case 'l': { // upper/lower case
90
 
                                if (readonly() || p == size())
91
 
                                        return 1;
92
 
                                while (p < size() && isspace(*(value() + p)))
93
 
                                        p++;
94
 
                                int n = word_end(p) - p;
95
 
                                if (n == 0)
96
 
                                        return 1;
97
 
 
98
 
                                char* s = new char[n];
99
 
                                memcpy(s, value() + p, n);
100
 
                                if (b == 'u')
101
 
                                        for (int i = 0; i < n; i++)
102
 
                                                s[i] = toupper(s[i]);
103
 
                                else
104
 
                                        for (int i = 0; i < n; i++)
105
 
                                                s[i] = tolower(s[i]);
106
 
                                replace(p, p + n, s, n);
107
 
                                position(p + n);
108
 
                                delete [] s;
109
 
                                return 1;
110
 
                        }
111
 
                        default:
112
 
                                break;
113
 
                        }
114
 
                }
115
 
        }
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);
120
 
                int d;
121
 
                if (!((d = Fl::event_dy()) || (d = Fl::event_dx())))
122
 
                        return Fl_Input::handle(event);
123
 
                if (Fl::focus() != this)
124
 
                        take_focus();
125
 
                up_down_position(d + (d > 0 ? line_end(position()) : line_start(position())));
126
 
                return 1;
127
 
        }
128
 
        case FL_PUSH:
129
 
                if (Fl::event_button() == FL_RIGHT_MOUSE)
130
 
                        break;
131
 
                // fall through
132
 
        default:
133
 
                return Fl_Input::handle(event);
134
 
        }
135
 
 
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());
144
 
 
145
 
        take_focus();
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);
151
 
 
152
 
        if (!m)
153
 
                return 1;
154
 
        switch (m - cmenu) {
155
 
        case OP_UNDO:
156
 
                undo();
157
 
                break;
158
 
        case OP_CUT:
159
 
                cut();
160
 
                copy_cuts();
161
 
                break;
162
 
        case OP_COPY:
163
 
                copy(1);
164
 
                break;
165
 
        case OP_PASTE:
166
 
                Fl::paste(*this, 1);
167
 
                break;
168
 
        case OP_DELETE:
169
 
                cut();
170
 
                break;
171
 
        case OP_CLEAR:
172
 
                cut(0, size());
173
 
                break;
174
 
        case OP_SELECT_ALL:
175
 
                position(0, size());
176
 
                break;
177
 
        }
178
 
 
179
 
        return 1;
180
 
}