LCOV - code coverage report
Current view: top level - gui/source - gui_search_request.c (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.57.0_covts Lines: 0 107 0.0 %
Date: 2024-04-07 11:14:42 Functions: 0 8 0.0 %

          Line data    Source code
       1             : /* File: gui_search_request.c; Copyright and License: see below */
       2             : 
       3             : #include "gui_search_request.h"
       4             : #include "set/data_full_id.h"
       5             : #include "data_id.h"
       6             : #include "utf8stringbuf/utf8string.h"
       7             : #include "u8/u8_trace.h"
       8             : #include "u8/u8_log.h"
       9             : #include <assert.h>
      10             : 
      11           0 : void gui_search_request_init ( gui_search_request_t *this_,
      12             :                                GtkWidget *search_label,
      13             :                                GtkWidget *search_entry,
      14             :                                GtkWidget *search_button,
      15             :                                gui_marked_set_t *marked_set,
      16             :                                gui_search_runner_t *search_runner )
      17             : {
      18           0 :     U8_TRACE_BEGIN();
      19           0 :     assert ( search_label != NULL );
      20           0 :     assert ( search_entry != NULL );
      21           0 :     assert ( search_button != NULL );
      22           0 :     assert ( marked_set != NULL );
      23           0 :     assert ( search_runner != NULL );
      24             : 
      25           0 :     (*this_).search_label = search_label;
      26           0 :     (*this_).search_entry = search_entry;
      27           0 :     (*this_).search_button = search_button;
      28           0 :     (*this_).marked_set = marked_set;
      29           0 :     (*this_).search_runner = search_runner;
      30             : 
      31           0 :     U8_TRACE_END();
      32           0 : }
      33             : 
      34           0 : void gui_search_request_destroy ( gui_search_request_t *this_ )
      35             : {
      36           0 :     U8_TRACE_BEGIN();
      37             : 
      38           0 :     (*this_).search_label = NULL;
      39           0 :     (*this_).search_entry = NULL;
      40           0 :     (*this_).search_button = NULL;
      41           0 :     (*this_).marked_set = NULL;
      42           0 :     (*this_).search_runner = NULL;
      43             : 
      44           0 :     U8_TRACE_END();
      45           0 : }
      46             : 
      47           0 : void gui_search_request_show ( gui_search_request_t *this_ )
      48             : {
      49           0 :     U8_TRACE_BEGIN();
      50             : 
      51           0 :     gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_label ), TRUE );
      52           0 :     gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_entry ), TRUE );
      53           0 :     gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_button ), TRUE );
      54             : 
      55           0 :     U8_TRACE_END();
      56           0 : }
      57             : 
      58           0 : void gui_search_request_hide ( gui_search_request_t *this_ )
      59             : {
      60           0 :     U8_TRACE_BEGIN();
      61             : 
      62           0 :     gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_label ), FALSE );
      63           0 :     gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_entry ), FALSE );
      64           0 :     gtk_widget_set_visible( GTK_WIDGET ( (*this_).search_button ), FALSE );
      65             : 
      66           0 :     U8_TRACE_END();
      67           0 : }
      68             : 
      69           0 : void gui_search_request_tool_changed_callback( GtkWidget *widget, gui_tool_t tool, gpointer data )
      70             : {
      71           0 :     U8_TRACE_BEGIN();
      72           0 :     gui_search_request_t *this_ = data;
      73           0 :     assert( NULL != this_ );
      74             : 
      75             :     /* info: This function is called once for activating a tool and once for deactiaving it! */
      76             : 
      77           0 :     switch ( tool )
      78             :     {
      79           0 :         case GUI_TOOL_NAVIGATE:
      80             :         {
      81           0 :             U8_TRACE_INFO("GUI_TOOL_NAVIGATE");
      82           0 :             gui_search_request_hide( this_ );
      83             :         }
      84           0 :         break;
      85             : 
      86           0 :         case GUI_TOOL_EDIT:
      87             :         {
      88           0 :             U8_TRACE_INFO("GUI_TOOL_EDIT");
      89           0 :             gui_search_request_hide( this_ );
      90             :         }
      91           0 :         break;
      92             : 
      93           0 :         case GUI_TOOL_SEARCH:
      94             :         {
      95           0 :             U8_TRACE_INFO("GUI_TOOL_SEARCH");
      96           0 :             gui_search_request_show( this_ );
      97             :         }
      98           0 :         break;
      99             : 
     100           0 :         case GUI_TOOL_CREATE:
     101             :         {
     102           0 :             U8_TRACE_INFO("GUI_TOOL_CREATE");
     103           0 :             gui_search_request_hide( this_ );
     104             :         }
     105           0 :         break;
     106             : 
     107           0 :         default:
     108             :         {
     109           0 :             U8_LOG_ERROR("selected_tool is out of range");
     110             :         }
     111           0 :         break;
     112             :     }
     113             : 
     114           0 :     U8_TRACE_END();
     115           0 : }
     116             : 
     117           0 : void gui_search_request_search_start_callback( GtkWidget* trigger_widget, gpointer data )
     118             : {
     119           0 :     U8_TRACE_BEGIN();
     120           0 :     gui_search_request_t *this_ = data;
     121           0 :     assert( NULL != this_ );
     122             :     /* note: button may bei either the text entry widget or the search button widget */
     123             : 
     124             :     const char* text;
     125           0 :     GtkEntryBuffer *const search_buf = gtk_entry_get_buffer( GTK_ENTRY( (*this_).search_entry ) );
     126           0 :     text = gtk_entry_buffer_get_text( search_buf );
     127             : 
     128           0 :     if ( text != NULL )
     129             :     {
     130           0 :         gui_search_runner_run ( (*this_).search_runner, text );
     131             :     }
     132             :     else
     133             :     {
     134           0 :         assert(false);
     135             :     }
     136             : 
     137           0 :     U8_TRACE_END();
     138           0 : }
     139             : 
     140           0 : void gui_search_request_id_search_callback ( GtkWidget *widget, gpointer user_data )
     141             : {
     142           0 :     U8_TRACE_BEGIN();
     143             :     gui_search_request_t *this_;
     144           0 :     this_ = (gui_search_request_t*) user_data;
     145           0 :     assert ( NULL != this_ );
     146             : 
     147           0 :     data_full_id_t focused_id = gui_marked_set_get_focused ( (*this_).marked_set );
     148           0 :     if ( data_full_id_is_valid( &focused_id ) )
     149             :     {
     150             :         /* get the primary id unless it is a DIAGRAMELEMENT, then take the secondary id */
     151           0 :         const data_id_t *const vis_id = data_full_id_get_primary_id_ptr( &focused_id );
     152           0 :         const data_id_t *const model_id
     153           0 :             = (DATA_TABLE_DIAGRAMELEMENT == data_id_get_table( vis_id ))
     154           0 :             ? data_full_id_get_secondary_id_ptr( &focused_id )
     155           0 :             : vis_id;
     156             : 
     157           0 :         char focused_id_buf[DATA_ID_MAX_UTF8STRING_LENGTH] = "";
     158           0 :         utf8stringbuf_t focused_id_str = UTF8STRINGBUF(focused_id_buf);
     159           0 :         const utf8error_t id_err = data_id_to_utf8stringbuf( model_id, focused_id_str );
     160           0 :         if ( id_err == UTF8ERROR_SUCCESS )
     161             :         {
     162           0 :             GtkEntryBuffer *const name_buf = gtk_entry_get_buffer( GTK_ENTRY( (*this_).search_entry ) );
     163           0 :             gtk_entry_buffer_set_text( name_buf, utf8stringbuf_get_string( focused_id_str ), -1 /* = n_chars */ );
     164           0 :             gui_search_runner_run ( (*this_).search_runner, utf8stringbuf_get_string( focused_id_str ) );
     165             :         }
     166             :     }
     167             : 
     168           0 :     U8_TRACE_TIMESTAMP();
     169           0 :     U8_TRACE_END();
     170           0 : }
     171             : 
     172           0 : void gui_search_request_data_changed_callback( GtkWidget *widget, data_change_message_t *msg, gpointer user_data )
     173             : {
     174           0 :     U8_TRACE_BEGIN();
     175           0 :     assert( NULL != msg );
     176           0 :     gui_search_request_t *this_ = user_data;
     177           0 :     assert( NULL != this_ );
     178           0 :     assert ( NULL != widget );
     179             : 
     180             :     data_change_event_type_t evt_type;
     181           0 :     evt_type = data_change_message_get_event ( msg );
     182             : 
     183           0 :     if ( evt_type == DATA_CHANGE_EVENT_TYPE_DB_OPENED )
     184             :     {
     185           0 :         GtkEntryBuffer *const search_buf = gtk_entry_get_buffer( GTK_ENTRY( (*this_).search_entry ) );
     186           0 :         gtk_entry_buffer_set_text ( search_buf, "", 0 /* = n_chars */ );
     187             :     }
     188             : 
     189           0 :     U8_TRACE_END();
     190           0 : }
     191             : 
     192             : 
     193             : /*
     194             : Copyright 2019-2024 Andreas Warnke
     195             : 
     196             : Licensed under the Apache License, Version 2.0 (the "License");
     197             : you may not use this file except in compliance with the License.
     198             : You may obtain a copy of the License at
     199             : 
     200             :     http://www.apache.org/licenses/LICENSE-2.0
     201             : 
     202             : Unless required by applicable law or agreed to in writing, software
     203             : distributed under the License is distributed on an "AS IS" BASIS,
     204             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     205             : See the License for the specific language governing permissions and
     206             : limitations under the License.
     207             : */

Generated by: LCOV version 1.16