Line data Source code
1 : /* File: gui_toolbox.c; Copyright and License: see below */
2 :
3 : #include "gui_toolbox.h"
4 : #include "ctrl_multi_step_changer.h"
5 : #include "u8/u8_trace.h"
6 : #include "u8/u8_error.h"
7 : #include "utf8stringbuf/utf8string.h"
8 : #include <assert.h>
9 : #include <gtk/gtk.h>
10 : #include <stdbool.h>
11 :
12 : static bool gui_toolbox_glib_signal_initialized = false;
13 : static guint gui_toolbox_glib_signal_id = 0;
14 : const char *GUI_TOOLBOX_GLIB_SIGNAL_NAME = "cfu_tool_changed";
15 :
16 0 : void gui_toolbox_init ( gui_toolbox_t *this_,
17 : GtkWidget *toolbar,
18 : GtkWidget *tool_navigate,
19 : GtkWidget *tool_edit,
20 : GtkWidget *tool_create,
21 : GtkWidget *tool_search,
22 : GdkClipboard *gtk_clipboard,
23 : gui_marked_set_t *marker,
24 : gui_simple_message_to_user_t *message_to_user,
25 : data_database_reader_t *db_reader,
26 : ctrl_controller_t *controller )
27 : {
28 0 : U8_TRACE_BEGIN();
29 0 : assert( NULL != tool_navigate );
30 0 : assert( NULL != tool_edit );
31 0 : assert( NULL != tool_create );
32 0 : assert( NULL != tool_search );
33 0 : assert( NULL != gtk_clipboard );
34 0 : assert( NULL != marker );
35 0 : assert( NULL != message_to_user );
36 0 : assert( NULL != db_reader );
37 0 : assert( NULL != controller );
38 :
39 0 : (*this_).selected_tool = GUI_TOOL_NAVIGATE;
40 0 : (*this_).marker = marker;
41 0 : (*this_).message_to_user = message_to_user;
42 0 : (*this_).db_reader = db_reader;
43 0 : (*this_).controller = controller;
44 0 : (*this_).toolbar = toolbar;
45 0 : (*this_).tool_navigate = tool_navigate;
46 0 : (*this_).tool_edit = tool_edit;
47 0 : (*this_).tool_create = tool_create;
48 0 : (*this_).tool_search = tool_search;
49 :
50 0 : gui_clipboard_init ( &((*this_).clipboard),
51 : gtk_clipboard,
52 : message_to_user,
53 : db_reader,
54 : controller
55 : );
56 :
57 : /* define a new signal */
58 0 : if ( ! gui_toolbox_glib_signal_initialized )
59 : {
60 0 : gui_toolbox_glib_signal_id = g_signal_new (
61 : GUI_TOOLBOX_GLIB_SIGNAL_NAME,
62 : G_TYPE_OBJECT,
63 : G_SIGNAL_RUN_FIRST,
64 : 0,
65 : NULL,
66 : NULL,
67 : g_cclosure_marshal_VOID__INT,
68 : G_TYPE_NONE,
69 : 1,
70 : G_TYPE_INT /* gui_tool_t */
71 : );
72 0 : gui_toolbox_glib_signal_initialized = true;
73 0 : U8_TRACE_INFO_INT( "g_signal_new(\"cfu_tool_changed\") returned new signal id", gui_toolbox_glib_signal_id );
74 : }
75 :
76 0 : U8_TRACE_END();
77 0 : }
78 :
79 0 : void gui_toolbox_destroy ( gui_toolbox_t *this_ )
80 : {
81 0 : U8_TRACE_BEGIN();
82 :
83 0 : gui_clipboard_destroy ( &((*this_).clipboard) );
84 :
85 0 : (*this_).db_reader = NULL;
86 0 : (*this_).controller = NULL;
87 0 : (*this_).marker = NULL;
88 0 : (*this_).message_to_user = NULL;
89 0 : (*this_).toolbar = NULL;
90 0 : (*this_).tool_navigate = NULL;
91 0 : (*this_).tool_edit = NULL;
92 0 : (*this_).tool_create = NULL;
93 0 : (*this_).tool_search = NULL;
94 :
95 0 : U8_TRACE_END();
96 0 : }
97 :
98 0 : void gui_toolbox_set_selected_tool( gui_toolbox_t *this_, gui_tool_t tool )
99 : {
100 0 : switch ( tool )
101 : {
102 0 : case GUI_TOOL_NAVIGATE:
103 : {
104 0 : gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( (*this_).tool_navigate ), true );
105 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
106 0 : (*this_).selected_tool = GUI_TOOL_NAVIGATE;
107 0 : gui_toolbox_private_notify_listeners( this_ );
108 : }
109 0 : break;
110 :
111 0 : case GUI_TOOL_EDIT:
112 : {
113 0 : gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( (*this_).tool_edit ), true );
114 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
115 0 : (*this_).selected_tool = GUI_TOOL_EDIT;
116 0 : gui_toolbox_private_notify_listeners( this_ );
117 : }
118 0 : break;
119 :
120 0 : case GUI_TOOL_SEARCH:
121 : {
122 0 : gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( (*this_).tool_search ), true );
123 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
124 0 : (*this_).selected_tool = GUI_TOOL_SEARCH;
125 0 : gui_toolbox_private_notify_listeners( this_ );
126 : }
127 0 : break;
128 :
129 0 : case GUI_TOOL_CREATE:
130 : {
131 0 : gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( (*this_).tool_create ), true );
132 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
133 0 : (*this_).selected_tool = GUI_TOOL_CREATE;
134 0 : gui_toolbox_private_notify_listeners( this_ );
135 : }
136 0 : break;
137 :
138 0 : default:
139 : {
140 0 : U8_LOG_ERROR( "invalid enum value" );
141 : }
142 0 : break;
143 : }
144 0 : }
145 :
146 0 : void gui_toolbox_navigate_btn_callback( GtkWidget* button, gpointer data )
147 : {
148 0 : U8_TRACE_BEGIN();
149 0 : gui_toolbox_t *this_ = data;
150 0 : assert( NULL != this_ );
151 :
152 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
153 :
154 0 : (*this_).selected_tool = GUI_TOOL_NAVIGATE;
155 :
156 0 : gui_toolbox_private_notify_listeners( this_ );
157 :
158 0 : U8_TRACE_TIMESTAMP();
159 0 : U8_TRACE_END();
160 0 : }
161 :
162 0 : void gui_toolbox_edit_btn_callback( GtkWidget* button, gpointer data )
163 : {
164 0 : U8_TRACE_BEGIN();
165 0 : gui_toolbox_t *this_ = data;
166 0 : assert( NULL != this_ );
167 :
168 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
169 :
170 0 : (*this_).selected_tool = GUI_TOOL_EDIT;
171 :
172 0 : gui_toolbox_private_notify_listeners( this_ );
173 :
174 0 : U8_TRACE_TIMESTAMP();
175 0 : U8_TRACE_END();
176 0 : }
177 :
178 0 : void gui_toolbox_create_btn_callback( GtkWidget* button, gpointer data )
179 : {
180 0 : U8_TRACE_BEGIN();
181 0 : gui_toolbox_t *this_ = data;
182 0 : assert( NULL != this_ );
183 :
184 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
185 :
186 0 : (*this_).selected_tool = GUI_TOOL_CREATE;
187 :
188 0 : gui_toolbox_private_notify_listeners( this_ );
189 :
190 0 : U8_TRACE_TIMESTAMP();
191 0 : U8_TRACE_END();
192 0 : }
193 :
194 0 : void gui_toolbox_search_btn_callback( GtkWidget* button, gpointer data )
195 : {
196 0 : U8_TRACE_BEGIN();
197 0 : gui_toolbox_t *this_ = data;
198 0 : assert( NULL != this_ );
199 :
200 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
201 :
202 0 : (*this_).selected_tool = GUI_TOOL_SEARCH;
203 :
204 0 : gui_toolbox_private_notify_listeners( this_ );
205 :
206 0 : U8_TRACE_TIMESTAMP();
207 0 : U8_TRACE_END();
208 0 : }
209 :
210 0 : void gui_toolbox_search_id_btn_callback( GtkWidget* button, gpointer data )
211 : {
212 0 : U8_TRACE_BEGIN();
213 0 : gui_toolbox_t *this_ = data;
214 0 : assert( NULL != this_ );
215 :
216 0 : gui_toolbox_set_selected_tool( this_, GUI_TOOL_SEARCH );
217 :
218 0 : U8_TRACE_TIMESTAMP();
219 0 : U8_TRACE_END();
220 0 : }
221 :
222 0 : void gui_toolbox_cut_btn_callback( GtkWidget* button, gpointer data )
223 : {
224 0 : U8_TRACE_BEGIN();
225 0 : gui_toolbox_t *this_ = data;
226 0 : assert( NULL != this_ );
227 :
228 0 : gui_toolbox_cut( this_ );
229 :
230 0 : U8_TRACE_TIMESTAMP();
231 0 : U8_TRACE_END();
232 0 : }
233 :
234 0 : void gui_toolbox_cut( gui_toolbox_t *this_ )
235 : {
236 0 : U8_TRACE_BEGIN();
237 : u8_error_t ctrl_err;
238 :
239 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
240 :
241 : data_stat_t stat;
242 0 : data_stat_init(&stat);
243 :
244 0 : const data_small_set_t *const set_to_be_cut = gui_marked_set_get_selected_set_const( (*this_).marker );
245 :
246 : /* do not check if set is empty; gui_clipboard_copy_set_to_clipboard will do this */
247 :
248 0 : gui_clipboard_copy_set_to_clipboard( &((*this_).clipboard), set_to_be_cut, &stat );
249 :
250 0 : ctrl_err = gui_toolbox_private_delete_set( this_, set_to_be_cut, &stat );
251 :
252 0 : gui_marked_set_clear_selected_set( (*this_).marker );
253 :
254 0 : if ( U8_ERROR_INPUT_EMPTY == ctrl_err )
255 : {
256 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
257 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
258 : GUI_SIMPLE_MESSAGE_CONTENT_NO_SELECTION
259 : );
260 : }
261 0 : else if ( u8_error_contains( ctrl_err, U8_ERROR_OBJECT_STILL_REFERENCED ) )
262 : {
263 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
264 : GUI_SIMPLE_MESSAGE_TYPE_ERROR,
265 : GUI_SIMPLE_MESSAGE_CONTENT_DELETING_NOT_POSSIBLE
266 : );
267 : }
268 0 : else if ( U8_ERROR_NONE != ctrl_err )
269 : {
270 0 : U8_LOG_ERROR_HEX( "Error in ctrl_classifier_controller_delete_set_from_diagram", ctrl_err );
271 : }
272 : else
273 : {
274 0 : gui_simple_message_to_user_show_message_with_stat ( (*this_).message_to_user,
275 : GUI_SIMPLE_MESSAGE_TYPE_INFO,
276 : GUI_SIMPLE_MESSAGE_CONTENT_CUT_TO_CLIPBOARD,
277 : &stat
278 : );
279 : }
280 :
281 0 : data_stat_destroy(&stat);
282 :
283 0 : U8_TRACE_END();
284 0 : }
285 :
286 0 : void gui_toolbox_copy_btn_callback( GtkWidget* button, gpointer data )
287 : {
288 0 : U8_TRACE_BEGIN();
289 0 : gui_toolbox_t *this_ = data;
290 0 : assert( NULL != this_ );
291 :
292 0 : gui_toolbox_copy( this_ );
293 :
294 0 : U8_TRACE_TIMESTAMP();
295 0 : U8_TRACE_END();
296 0 : }
297 :
298 0 : void gui_toolbox_copy( gui_toolbox_t *this_ )
299 : {
300 0 : U8_TRACE_BEGIN();
301 : int out_err;
302 :
303 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
304 :
305 : data_stat_t stat;
306 0 : data_stat_init(&stat);
307 :
308 0 : const data_small_set_t *const set_to_be_copied = gui_marked_set_get_selected_set_const( (*this_).marker );
309 :
310 : /* even in case data_small_set_is_empty( set_to_be_copied ),
311 : * it is possible to copy an empty set to the clipboard
312 : * --> therefore simply continue... */
313 0 : out_err = gui_clipboard_copy_set_to_clipboard( &((*this_).clipboard), set_to_be_copied, &stat );
314 :
315 0 : if ( out_err == 0 )
316 : {
317 0 : if ( 0 == data_stat_get_total_count( &stat ) )
318 : {
319 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
320 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
321 : GUI_SIMPLE_MESSAGE_CONTENT_NO_SELECTION
322 : );
323 : }
324 : else
325 : {
326 0 : gui_simple_message_to_user_show_message_with_stat( (*this_).message_to_user,
327 : GUI_SIMPLE_MESSAGE_TYPE_INFO,
328 : GUI_SIMPLE_MESSAGE_CONTENT_COPY_TO_CLIPBOARD,
329 : &stat
330 : );
331 : }
332 : }
333 : else
334 : {
335 : /* error to be shown to the user */
336 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
337 : GUI_SIMPLE_MESSAGE_TYPE_ERROR,
338 : GUI_SIMPLE_MESSAGE_CONTENT_STRING_TRUNCATED
339 : );
340 : }
341 :
342 0 : data_stat_destroy(&stat);
343 :
344 0 : U8_TRACE_END();
345 0 : }
346 :
347 0 : void gui_toolbox_paste_btn_callback( GtkWidget* button, gpointer data )
348 : {
349 0 : U8_TRACE_BEGIN();
350 0 : gui_toolbox_t *this_ = data;
351 0 : assert( NULL != this_ );
352 :
353 0 : gui_toolbox_paste( this_ );
354 :
355 0 : U8_TRACE_TIMESTAMP();
356 0 : U8_TRACE_END();
357 0 : }
358 :
359 0 : void gui_toolbox_paste( gui_toolbox_t *this_ )
360 : {
361 0 : U8_TRACE_BEGIN();
362 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
363 :
364 0 : const data_id_t destination_diagram_id = gui_marked_set_get_focused_diagram( (*this_).marker );
365 0 : if ( data_id_is_valid( &destination_diagram_id ) )
366 : {
367 0 : const data_row_id_t dest_diagram_row_id = data_id_get_row_id( &destination_diagram_id );
368 0 : gui_clipboard_request_clipboard_text( &((*this_).clipboard), dest_diagram_row_id );
369 :
370 : /* Note: (*this_).message_to_user is updated by (*this_).clipboard already - nothing to do here */
371 : }
372 : else
373 : {
374 : /* error to be shown to the user */
375 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
376 : GUI_SIMPLE_MESSAGE_TYPE_ERROR,
377 : GUI_SIMPLE_MESSAGE_CONTENT_NO_FOCUS
378 : );
379 : }
380 :
381 0 : U8_TRACE_END();
382 0 : }
383 :
384 0 : void gui_toolbox_delete_btn_callback( GtkWidget* button, gpointer data )
385 : {
386 0 : U8_TRACE_BEGIN();
387 0 : gui_toolbox_t *this_ = data;
388 0 : assert( NULL != this_ );
389 :
390 0 : gui_toolbox_delete( this_ );
391 :
392 0 : U8_TRACE_TIMESTAMP();
393 0 : U8_TRACE_END();
394 0 : }
395 :
396 0 : void gui_toolbox_delete( gui_toolbox_t *this_ )
397 : {
398 0 : U8_TRACE_BEGIN();
399 : u8_error_t ctrl_err;
400 :
401 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
402 :
403 : data_stat_t stat;
404 0 : data_stat_init(&stat);
405 :
406 0 : const data_small_set_t *const set_to_be_deleted = gui_marked_set_get_selected_set_const( (*this_).marker );
407 :
408 : /* do not check if set is empty; gui_toolbox_private_delete_set will do this */
409 :
410 0 : ctrl_err = gui_toolbox_private_delete_set( this_, set_to_be_deleted, &stat );
411 :
412 0 : gui_marked_set_clear_selected_set( (*this_).marker );
413 :
414 0 : if ( U8_ERROR_INPUT_EMPTY == ctrl_err )
415 : {
416 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
417 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
418 : GUI_SIMPLE_MESSAGE_CONTENT_NO_SELECTION
419 : );
420 : }
421 0 : else if ( u8_error_contains( ctrl_err, U8_ERROR_OBJECT_STILL_REFERENCED ) )
422 : {
423 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
424 : GUI_SIMPLE_MESSAGE_TYPE_ERROR,
425 : GUI_SIMPLE_MESSAGE_CONTENT_DELETING_NOT_POSSIBLE
426 : );
427 : }
428 0 : else if ( U8_ERROR_NONE != ctrl_err )
429 : {
430 0 : U8_LOG_ERROR_HEX( "Error in ctrl_classifier_controller_delete_set_from_diagram", ctrl_err );
431 : }
432 : else
433 : {
434 0 : gui_simple_message_to_user_show_message_with_stat ( (*this_).message_to_user,
435 : GUI_SIMPLE_MESSAGE_TYPE_INFO,
436 : GUI_SIMPLE_MESSAGE_CONTENT_DELETE,
437 : &stat
438 : );
439 : }
440 :
441 0 : data_stat_destroy(&stat);
442 :
443 0 : U8_TRACE_END();
444 0 : }
445 :
446 0 : u8_error_t gui_toolbox_private_delete_set( gui_toolbox_t *this_,
447 : const data_small_set_t *set_to_be_deleted,
448 : data_stat_t *io_stat )
449 : {
450 0 : U8_TRACE_BEGIN();
451 0 : assert( NULL != set_to_be_deleted );
452 0 : assert( NULL != io_stat );
453 : u8_error_t ctrl_err;
454 :
455 : ctrl_multi_step_changer_t multi_stepper;
456 0 : ctrl_multi_step_changer_init( &multi_stepper, (*this_).controller, (*this_).db_reader );
457 :
458 0 : ctrl_err = ctrl_multi_step_changer_delete_set ( &multi_stepper, set_to_be_deleted, io_stat );
459 :
460 0 : ctrl_multi_step_changer_destroy( &multi_stepper );
461 :
462 0 : U8_TRACE_END_ERR( ctrl_err );
463 0 : return ctrl_err;
464 : }
465 :
466 0 : void gui_toolbox_highlight_btn_callback( GtkWidget* button, gpointer data )
467 : {
468 0 : U8_TRACE_BEGIN();
469 0 : gui_toolbox_t *this_ = data;
470 0 : assert( NULL != this_ );
471 :
472 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
473 :
474 0 : const data_small_set_t *const set_to_be_highlighted = gui_marked_set_get_selected_set_const( (*this_).marker );
475 :
476 : /* do not check if set is empty; gui_toolbox_private_toggle_display_flag_in_set will do this */
477 :
478 0 : gui_toolbox_private_toggle_display_flag_in_set( this_,
479 : set_to_be_highlighted,
480 : DATA_DIAGRAMELEMENT_FLAG_EMPHASIS | DATA_DIAGRAMELEMENT_FLAG_GRAY_OUT
481 : );
482 :
483 0 : U8_TRACE_TIMESTAMP();
484 0 : U8_TRACE_END();
485 0 : }
486 :
487 0 : void gui_toolbox_instantiate_btn_callback( GtkWidget* button, gpointer data )
488 : {
489 0 : U8_TRACE_BEGIN();
490 0 : gui_toolbox_t *this_ = data;
491 0 : assert( NULL != this_ );
492 :
493 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
494 :
495 0 : const data_small_set_t *const set_to_be_instantiated = gui_marked_set_get_selected_set_const( (*this_).marker );
496 :
497 : /* do not check if set is empty; gui_toolbox_private_toggle_display_flag_in_set will do this */
498 :
499 0 : gui_toolbox_private_toggle_display_flag_in_set( this_,
500 : set_to_be_instantiated,
501 : DATA_DIAGRAMELEMENT_FLAG_NAMED_INSTANCE | DATA_DIAGRAMELEMENT_FLAG_ANONYMOUS_INSTANCE
502 : );
503 :
504 0 : U8_TRACE_TIMESTAMP();
505 0 : U8_TRACE_END();
506 0 : }
507 :
508 0 : void gui_toolbox_reset_btn_callback( GtkWidget* button, gpointer data )
509 : {
510 0 : U8_TRACE_BEGIN();
511 0 : gui_toolbox_t *this_ = data;
512 0 : assert( NULL != this_ );
513 :
514 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
515 :
516 0 : gui_marked_set_clear_selected_set( (*this_).marker );
517 : //gui_marked_set_clear_focused( (*this_).marker );
518 :
519 : /* trigger redraw */
520 0 : gui_toolbox_private_notify_listeners( this_ );
521 :
522 0 : U8_TRACE_TIMESTAMP();
523 0 : U8_TRACE_END();
524 0 : }
525 :
526 0 : void gui_toolbox_private_toggle_display_flag_in_set( gui_toolbox_t *this_,
527 : const data_small_set_t *set_to_be_toggled,
528 : data_diagramelement_flag_t flag_bits_to_toggle )
529 : {
530 0 : U8_TRACE_BEGIN();
531 0 : u8_error_t error = U8_ERROR_NONE;
532 0 : bool new_pattern_initialized = false;
533 0 : data_diagramelement_flag_t new_pattern = DATA_DIAGRAMELEMENT_FLAG_NONE;
534 0 : bool is_first = true;
535 :
536 0 : for ( int index = 0; index < data_small_set_get_count( set_to_be_toggled ); index ++ )
537 : {
538 : data_id_t current_id;
539 0 : current_id = data_small_set_get_id( set_to_be_toggled, index );
540 0 : switch ( data_id_get_table( ¤t_id ) )
541 : {
542 0 : case DATA_TABLE_CLASSIFIER:
543 : {
544 : /* program internal error */
545 0 : U8_LOG_WARNING( "gui_toolbox_private_toggle_display_flag_in_set cannot toggle display flags in non-diagramelements." );
546 0 : error |= U8_ERROR_INVALID_REQUEST;
547 : }
548 0 : break;
549 :
550 0 : case DATA_TABLE_FEATURE:
551 : {
552 : /* program internal error */
553 0 : U8_LOG_WARNING( "gui_toolbox_private_toggle_display_flag_in_set cannot toggle display flags in non-diagramelements." );
554 0 : error |= U8_ERROR_INVALID_REQUEST;
555 : }
556 0 : break;
557 :
558 0 : case DATA_TABLE_RELATIONSHIP:
559 : {
560 : /* program internal error */
561 0 : U8_LOG_WARNING( "gui_toolbox_private_toggle_display_flag_in_set cannot toggle display flags in non-diagramelements." );
562 0 : error |= U8_ERROR_INVALID_REQUEST;
563 : }
564 0 : break;
565 :
566 0 : case DATA_TABLE_DIAGRAMELEMENT:
567 : {
568 : data_diagramelement_t out_diagramelement;
569 0 : data_row_id_t diag_elem_id = data_id_get_row_id( ¤t_id );
570 : ctrl_diagram_controller_t *diag_ctrl;
571 0 : diag_ctrl = ctrl_controller_get_diagram_control_ptr( (*this_).controller );
572 :
573 0 : error |= (u8_error_t) data_database_reader_get_diagramelement_by_id ( (*this_).db_reader,
574 : diag_elem_id,
575 : &out_diagramelement
576 : );
577 : data_diagramelement_flag_t current_flags;
578 0 : current_flags = data_diagramelement_get_display_flags( &out_diagramelement );
579 :
580 0 : if ( ! new_pattern_initialized )
581 : {
582 : /* select zero or one bit to set. alg: select the next highest bit */
583 0 : bool last_was_set = true;
584 0 : new_pattern = DATA_DIAGRAMELEMENT_FLAG_NONE;
585 0 : for ( int bit = 0; bit < 8*sizeof(data_diagramelement_flag_t); bit ++ )
586 : {
587 0 : data_diagramelement_flag_t probe = (1 << bit);
588 0 : if ( 0 != ( probe & flag_bits_to_toggle ) )
589 : {
590 : /* this is a relevant bit */
591 0 : if ( 0 != ( probe & current_flags ) )
592 : {
593 0 : new_pattern = DATA_DIAGRAMELEMENT_FLAG_NONE;
594 0 : last_was_set = true;
595 : }
596 : else
597 : {
598 0 : if ( last_was_set )
599 : {
600 0 : new_pattern = probe;
601 : }
602 0 : last_was_set = false;
603 : }
604 : }
605 : }
606 0 : new_pattern_initialized = true;
607 : }
608 :
609 0 : current_flags = (current_flags & (~flag_bits_to_toggle)) | new_pattern;
610 :
611 0 : error |= ctrl_diagram_controller_update_diagramelement_display_flags( diag_ctrl,
612 : diag_elem_id,
613 : current_flags,
614 : ( is_first
615 : ? CTRL_UNDO_REDO_ACTION_BOUNDARY_START_NEW
616 0 : : CTRL_UNDO_REDO_ACTION_BOUNDARY_APPEND )
617 : );
618 0 : is_first = false;
619 : }
620 0 : break;
621 :
622 0 : case DATA_TABLE_DIAGRAM:
623 : {
624 : /* program internal error */
625 0 : U8_LOG_WARNING( "gui_toolbox_private_toggle_display_flag_in_set cannot toggle display flags in non-diagramelements." );
626 0 : error |= U8_ERROR_INVALID_REQUEST;
627 : }
628 0 : break;
629 :
630 0 : default:
631 : {
632 : /* program internal error */
633 0 : U8_LOG_ERROR( "gui_toolbox_private_toggle_display_flag_in_set fould illegal data_table_t enum value." );
634 : }
635 0 : break;
636 : }
637 : }
638 :
639 0 : if ( error != U8_ERROR_NONE )
640 : {
641 : /* error to be shown to the user */
642 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
643 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
644 : GUI_SIMPLE_MESSAGE_CONTENT_SET_PARTLY_UNSUITABLE
645 : );
646 : }
647 0 : else if ( 0 == data_small_set_get_count( set_to_be_toggled ) )
648 : {
649 : /* error to be shown to the user */
650 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
651 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
652 : GUI_SIMPLE_MESSAGE_CONTENT_NO_SELECTION
653 : );
654 : }
655 :
656 0 : U8_TRACE_END();
657 0 : }
658 :
659 0 : void gui_toolbox_undo_btn_callback( GtkWidget* button, gpointer data )
660 : {
661 0 : U8_TRACE_BEGIN();
662 0 : gui_toolbox_t *this_ = data;
663 0 : assert( this_ != NULL );
664 : u8_error_t ctrl_err;
665 :
666 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
667 :
668 : data_stat_t stat;
669 0 : data_stat_init(&stat);
670 :
671 0 : ctrl_err = ctrl_controller_undo( (*this_).controller, &stat );
672 0 : if ( U8_ERROR_INVALID_REQUEST == ctrl_err )
673 : {
674 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
675 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
676 : GUI_SIMPLE_MESSAGE_CONTENT_NO_MORE_UNDO
677 : );
678 : }
679 0 : else if ( U8_ERROR_ARRAY_BUFFER_EXCEEDED == ctrl_err )
680 : {
681 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
682 : GUI_SIMPLE_MESSAGE_TYPE_ERROR,
683 : GUI_SIMPLE_MESSAGE_CONTENT_UNDO_NOT_POSSIBLE
684 : );
685 : }
686 : else
687 : {
688 : /* success */
689 0 : gui_simple_message_to_user_show_message_with_stat ( (*this_).message_to_user,
690 : GUI_SIMPLE_MESSAGE_TYPE_INFO,
691 : GUI_SIMPLE_MESSAGE_CONTENT_UNDO,
692 : &stat
693 : );
694 : }
695 :
696 0 : data_stat_destroy(&stat);
697 :
698 0 : U8_TRACE_TIMESTAMP();
699 0 : U8_TRACE_END();
700 0 : }
701 :
702 0 : gboolean gui_toolbox_undo_shortcut_callback( GtkWidget* widget, GVariant* args, gpointer user_data )
703 : {
704 0 : gui_toolbox_undo_btn_callback( widget, user_data );
705 0 : return TRUE;
706 : }
707 :
708 0 : void gui_toolbox_redo_btn_callback( GtkWidget* button, gpointer data )
709 : {
710 0 : U8_TRACE_BEGIN();
711 0 : gui_toolbox_t *this_ = data;
712 0 : assert( this_ != NULL );
713 : u8_error_t ctrl_err;
714 :
715 0 : gui_simple_message_to_user_hide( (*this_).message_to_user );
716 :
717 : data_stat_t stat;
718 0 : data_stat_init(&stat);
719 :
720 0 : ctrl_err = ctrl_controller_redo( (*this_).controller, &stat );
721 0 : if ( U8_ERROR_INVALID_REQUEST == ctrl_err )
722 : {
723 0 : gui_simple_message_to_user_show_message( (*this_).message_to_user,
724 : GUI_SIMPLE_MESSAGE_TYPE_WARNING,
725 : GUI_SIMPLE_MESSAGE_CONTENT_NO_MORE_REDO
726 : );
727 : }
728 : else
729 : {
730 : /* success */
731 0 : gui_simple_message_to_user_show_message_with_stat ( (*this_).message_to_user,
732 : GUI_SIMPLE_MESSAGE_TYPE_INFO,
733 : GUI_SIMPLE_MESSAGE_CONTENT_REDO,
734 : &stat
735 : );
736 : }
737 :
738 0 : data_stat_destroy(&stat);
739 :
740 0 : U8_TRACE_TIMESTAMP();
741 0 : U8_TRACE_END();
742 0 : }
743 :
744 : /*!
745 : * \brief callback that informs that the redo shortcut was activated
746 : */
747 0 : gboolean gui_toolbox_redo_shortcut_callback( GtkWidget* widget, GVariant* args, gpointer user_data )
748 : {
749 0 : gui_toolbox_redo_btn_callback( widget, user_data );
750 0 : return TRUE;
751 : }
752 :
753 0 : void gui_toolbox_private_notify_listeners( gui_toolbox_t *this_ )
754 : {
755 0 : U8_TRACE_BEGIN();
756 :
757 0 : U8_TRACE_INFO( "g_signal_emit to listeners" );
758 0 : g_signal_emit( (*this_).toolbar, gui_toolbox_glib_signal_id, 0, (*this_).selected_tool );
759 :
760 0 : U8_TRACE_END();
761 0 : }
762 :
763 :
764 : /*
765 : Copyright 2016-2024 Andreas Warnke
766 :
767 : Licensed under the Apache License, Version 2.0 (the "License");
768 : you may not use this file except in compliance with the License.
769 : You may obtain a copy of the License at
770 :
771 : http://www.apache.org/licenses/LICENSE-2.0
772 :
773 : Unless required by applicable law or agreed to in writing, software
774 : distributed under the License is distributed on an "AS IS" BASIS,
775 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
776 : See the License for the specific language governing permissions and
777 : limitations under the License.
778 : */
|