Commit 06a2fa8d2219adc64a51d1e6fd075b2e26569f19
1 parent
e4005363
Exists in
master
and in
1 other branch
Implementing copy with center button.
Showing
3 changed files
with
94 additions
and
27 deletions
Show diff stats
src/include/terminal.h
... | ... | @@ -157,6 +157,7 @@ G_BEGIN_DECLS |
157 | 157 | int drawing : 1; /// @brief Draw widget? |
158 | 158 | int freeze : 1; /// @brief Truee when the "save settings" signal is disabled. |
159 | 159 | int append : 1; /// @brief Next smart-copy operation will be append. |
160 | + int copying : 1; /// @brief Copy with center mouse button | |
160 | 161 | |
161 | 162 | /// @brief Action properties. |
162 | 163 | GtkResponseType responses[V3270_TOGGLEABLE_DIALOG_CUSTOM]; | ... | ... |
src/terminal/drawing/draw.c
... | ... | @@ -118,22 +118,40 @@ gboolean v3270_expose(GtkWidget *widget, GdkEventExpose *event) |
118 | 118 | #endif // GTk3 |
119 | 119 | |
120 | 120 | |
121 | -static void get_element_colors(unsigned short attr, GdkRGBA **fg, GdkRGBA **bg, GdkRGBA *color) | |
122 | -{ | |
123 | - if(attr & LIB3270_ATTR_SELECTED) | |
124 | - { | |
125 | - *fg = color+V3270_COLOR_SELECTED_FG; | |
126 | - *bg = color+V3270_COLOR_SELECTED_BG; | |
127 | - } | |
128 | - else | |
129 | - { | |
121 | +static void get_element_colors(unsigned short attr, GdkRGBA **fg, GdkRGBA **bg, GdkRGBA *color) { | |
122 | + | |
123 | + int index[2]; | |
124 | + | |
125 | + if(attr & LIB3270_ATTR_SELECTED) { | |
126 | + | |
127 | + index[0] = V3270_COLOR_SELECTED_FG; | |
128 | + index[1] = V3270_COLOR_SELECTED_BG; | |
129 | + | |
130 | +// *fg = color+V3270_COLOR_SELECTED_FG; | |
131 | +// *bg = color+V3270_COLOR_SELECTED_BG; | |
132 | + | |
133 | + } else { | |
134 | + | |
135 | + if(attr & LIB3270_ATTR_FIELD) | |
136 | + index[0] = (attr & 0x0003)+V3270_COLOR_FIELD; | |
137 | + else | |
138 | + index[0] = (attr & 0x000F); | |
139 | + | |
140 | + index[1] = ((attr & 0x00F0) >> 4); | |
141 | + | |
142 | + /* | |
130 | 143 | *bg = color+((attr & 0x00F0) >> 4); |
131 | 144 | |
132 | 145 | if(attr & LIB3270_ATTR_FIELD) |
133 | 146 | *fg = color+(attr & 0x0003)+V3270_COLOR_FIELD; |
134 | 147 | else |
135 | 148 | *fg = color+(attr & 0x000F); |
149 | + */ | |
136 | 150 | } |
151 | + | |
152 | + *fg = color+index[0]; | |
153 | + *bg = color+index[1]; | |
154 | + | |
137 | 155 | } |
138 | 156 | |
139 | 157 | void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, v3270FontInfo *fontInfo, GdkRectangle *rect, GdkRGBA *color) | ... | ... |
src/terminal/mouse.c
... | ... | @@ -84,24 +84,23 @@ static void single_click(v3270 *widget, int baddr) { |
84 | 84 | |
85 | 85 | } |
86 | 86 | |
87 | -static void button_1_press(GtkWidget *widget, GdkEventType type, int baddr) | |
88 | -{ | |
87 | +static void button_1_press(v3270 *terminal, GdkEventType type, int baddr) { | |
89 | 88 | #pragma GCC diagnostic push |
90 | 89 | #pragma GCC diagnostic ignored "-Wswitch" |
91 | 90 | |
92 | 91 | switch(type) { |
93 | 92 | case GDK_BUTTON_PRESS: // Single click - set mode |
94 | - single_click(GTK_V3270(widget),baddr); | |
93 | + single_click(terminal,baddr); | |
95 | 94 | break; |
96 | 95 | |
97 | 96 | case GDK_2BUTTON_PRESS: // Double click - Select word |
98 | - if(lib3270_select_word_at(GTK_V3270(widget)->host,baddr)) | |
99 | - lib3270_ring_bell(GTK_V3270(widget)->host); | |
97 | + if(lib3270_select_word_at(terminal->host,baddr)) | |
98 | + lib3270_ring_bell(terminal->host); | |
100 | 99 | break; |
101 | 100 | |
102 | 101 | case GDK_3BUTTON_PRESS: // Triple clock - Select field |
103 | - if(lib3270_select_field_at(GTK_V3270(widget)->host,baddr)) | |
104 | - lib3270_ring_bell(GTK_V3270(widget)->host); | |
102 | + if(lib3270_select_field_at(terminal->host,baddr)) | |
103 | + lib3270_ring_bell(terminal->host); | |
105 | 104 | break; |
106 | 105 | |
107 | 106 | } |
... | ... | @@ -110,6 +109,33 @@ static void button_1_press(GtkWidget *widget, GdkEventType type, int baddr) |
110 | 109 | |
111 | 110 | } |
112 | 111 | |
112 | +static void button_2_press(v3270 *terminal, GdkEventType type, int baddr) { | |
113 | + #pragma GCC diagnostic push | |
114 | + #pragma GCC diagnostic ignored "-Wswitch" | |
115 | + | |
116 | + switch(type) { | |
117 | + case GDK_BUTTON_PRESS: // Single click - set mode | |
118 | + if(lib3270_get_selection_flags(terminal->host,baddr)) { | |
119 | + | |
120 | + debug("%s: Center button press over selected area.", __FUNCTION__); | |
121 | + terminal->copying = 1; | |
122 | + | |
123 | + } | |
124 | + break; | |
125 | + | |
126 | + case GDK_2BUTTON_PRESS: // Double click - Select word | |
127 | + terminal->copying = 0; | |
128 | + lib3270_unselect(terminal->host); | |
129 | + break; | |
130 | + | |
131 | + default: | |
132 | + terminal->copying = 0; | |
133 | + | |
134 | + } | |
135 | + | |
136 | + #pragma GCC diagnostic pop | |
137 | +} | |
138 | + | |
113 | 139 | void v3270_emit_popup(v3270 *widget, int baddr, GdkEventButton *event) { |
114 | 140 | unsigned char chr = 0; |
115 | 141 | unsigned short attr; |
... | ... | @@ -147,19 +173,26 @@ static V3270_OIA_FIELD get_field_from_event(v3270 *widget, GdkEventButton *event |
147 | 173 | gboolean v3270_button_press_event(GtkWidget *widget, GdkEventButton *event) |
148 | 174 | { |
149 | 175 | int baddr = v3270_get_offset_at_point(GTK_V3270(widget),event->x,event->y); |
176 | + v3270 * terminal = GTK_V3270(widget); | |
150 | 177 | |
151 | 178 | if(baddr >= 0) { |
152 | 179 | |
153 | 180 | // Click inside the terminal contents. |
181 | + debug("Button %d pressed on terminal addr %d",(int) event->button,baddr); | |
154 | 182 | |
155 | - GTK_V3270(widget)->oia.selected = V3270_OIA_FIELD_INVALID; | |
183 | + terminal->oia.selected = V3270_OIA_FIELD_INVALID; | |
156 | 184 | |
157 | 185 | switch(event->button) { |
158 | 186 | case 1: // Left button |
159 | - button_1_press(widget,event->type,baddr); | |
187 | + button_1_press(terminal,event->type,baddr); | |
188 | + break; | |
189 | + | |
190 | + case 2: // Center button | |
191 | + button_2_press(terminal,event->type,baddr); | |
160 | 192 | break; |
161 | 193 | |
162 | 194 | case 3: // Right button |
195 | + | |
163 | 196 | if(event->type == GDK_BUTTON_PRESS) |
164 | 197 | v3270_emit_popup(GTK_V3270(widget),baddr,event); |
165 | 198 | break; |
... | ... | @@ -204,19 +237,23 @@ gboolean v3270_button_press_event(GtkWidget *widget, GdkEventButton *event) |
204 | 237 | return FALSE; |
205 | 238 | } |
206 | 239 | |
207 | -gboolean v3270_button_release_event(GtkWidget *widget, GdkEventButton*event) | |
208 | -{ | |
240 | +gboolean v3270_button_release_event(GtkWidget *widget, GdkEventButton*event) { | |
241 | + | |
242 | + v3270 * terminal = GTK_V3270(widget); | |
243 | + | |
244 | + debug("%s(%d)",__FUNCTION__,(int) event->button); | |
245 | + | |
209 | 246 | switch(event->button) { |
210 | 247 | case 1: // Left button |
211 | - GTK_V3270(widget)->selecting = 0; | |
212 | - GTK_V3270(widget)->moving = 0; | |
213 | - GTK_V3270(widget)->resizing = 0; | |
248 | + terminal->selecting = 0; | |
249 | + terminal->moving = 0; | |
250 | + terminal->resizing = 0; | |
214 | 251 | |
215 | - if(GTK_V3270(widget)->oia.selected != V3270_OIA_FIELD_INVALID && GTK_V3270(widget)->oia.selected == get_field_from_event(GTK_V3270(widget),event)) | |
252 | + if(terminal->oia.selected != V3270_OIA_FIELD_INVALID && terminal->oia.selected == get_field_from_event(terminal,event)) | |
216 | 253 | { |
217 | 254 | gboolean handled = FALSE; |
218 | - gboolean connected = lib3270_is_connected(GTK_V3270(widget)->host) ? TRUE : FALSE; | |
219 | - V3270_OIA_FIELD field = GTK_V3270(widget)->oia.selected; | |
255 | + gboolean connected = lib3270_is_connected(terminal->host) ? TRUE : FALSE; | |
256 | + V3270_OIA_FIELD field = terminal->oia.selected; | |
220 | 257 | |
221 | 258 | g_signal_emit(widget, v3270_widget_signal[V3270_SIGNAL_FIELD], 0, |
222 | 259 | connected, |
... | ... | @@ -243,12 +280,23 @@ gboolean v3270_button_release_event(GtkWidget *widget, GdkEventButton*event) |
243 | 280 | |
244 | 281 | } |
245 | 282 | |
246 | - GTK_V3270(widget)->oia.selected = V3270_OIA_FIELD_INVALID; | |
283 | + terminal->oia.selected = V3270_OIA_FIELD_INVALID; | |
284 | + | |
285 | + break; | |
286 | + | |
287 | + case 2: // Center button | |
288 | + | |
289 | + if(lib3270_has_selection(terminal->host)) { | |
290 | + debug("%s: Copy with center button",__FUNCTION__); | |
291 | + v3270_clipboard_set(widget,V3270_COPY_SMART,FALSE); | |
292 | + } | |
247 | 293 | |
248 | 294 | break; |
249 | 295 | |
250 | 296 | } |
251 | 297 | |
298 | + terminal->copying = 0; | |
299 | + | |
252 | 300 | return FALSE; |
253 | 301 | } |
254 | 302 | ... | ... |