LCOV - code coverage report
Current view: top level - gui/source - gui_window_manager.c (source / functions) Hit Total Coverage
Test: crystal-facet-uml_v1.61.0_covts Lines: 0 67 0.0 %
Date: 2024-10-26 21:44:38 Functions: 0 5 0.0 %

          Line data    Source code
       1             : /* File: gui_window_manager.c; Copyright and License: see below */
       2             : 
       3             : #include "gui_window_manager.h"
       4             : #include "ctrl_controller.h"
       5             : #include "u8/u8_trace.h"
       6             : #include <gtk/gtk.h>
       7             : #include <stdio.h>
       8             : #include <stdbool.h>
       9             : 
      10           0 : void gui_window_manager_init( gui_window_manager_t *this_,
      11             :                               io_data_file_t *data_file,
      12             :                               GtkApplication *gtk_app )
      13             : {
      14           0 :     U8_TRACE_BEGIN();
      15           0 :     assert( data_file != NULL );
      16           0 :     assert( gtk_app != NULL );
      17             : 
      18           0 :     gui_resources_init( &((*this_).gui_resources) );
      19           0 :     data_database_reader_init( &((*this_).db_reader), io_data_file_get_database_ptr( data_file ) );
      20           0 :     (*this_).controller = io_data_file_get_controller_ptr( data_file );
      21           0 :     (*this_).data_file = data_file;
      22           0 :     (*this_).gtk_app = gtk_app;
      23           0 :     observer_init( &((*this_).window_close_observer),
      24             :                    this_,
      25             :                    (void (*)(void*,void*)) &gui_window_manager_close_main_window_callback,
      26             :                    "gui_window_manager_close_main_window_callback()"
      27             :                   );
      28           0 :     observer_init( &((*this_).window_open_observer),
      29             :                    this_,
      30             :                    (void (*)(void*,void*)) &gui_window_manager_open_main_window_callback,
      31             :                    "gui_window_manager_open_main_window_callback()"
      32             :                   );
      33           0 :     for( int index = 0; index < GUI_WINDOW_MANAGER_MAX_MAIN_WINDOWS; index ++ )
      34             :     {
      35           0 :         (*this_).main_window_active[index] = false;
      36             :     }
      37             : 
      38           0 :     U8_TRACE_END();
      39           0 : }
      40             : 
      41           0 : void gui_window_manager_destroy( gui_window_manager_t *this_ )
      42             : {
      43           0 :     U8_TRACE_BEGIN();
      44             : 
      45           0 :     for( int index = 0; index < GUI_WINDOW_MANAGER_MAX_MAIN_WINDOWS; index ++ )
      46             :     {
      47           0 :         if ( (*this_).main_window_active[index] )
      48             :         {
      49           0 :             gui_main_window_destroy( &((*this_).main_window[index]) );
      50           0 :             (*this_).main_window_active[index] = false;
      51             :         }
      52             :     }
      53           0 :     observer_destroy( &((*this_).window_close_observer) );
      54           0 :     data_database_reader_destroy( &((*this_).db_reader) );
      55           0 :     gui_resources_destroy( &((*this_).gui_resources) );
      56           0 :     (*this_).controller = NULL;
      57           0 :     (*this_).data_file = NULL;
      58           0 :     (*this_).gtk_app = NULL;
      59             : 
      60           0 :     U8_TRACE_END();
      61           0 : }
      62             : 
      63           0 : gui_main_window_t *gui_window_manager_open_main_window( gui_window_manager_t *this_ )
      64             : {
      65           0 :     U8_TRACE_BEGIN();
      66             :     gui_main_window_t *result;
      67             : 
      68           0 :     int pos = -1;
      69           0 :     for( int index = 0; index < GUI_WINDOW_MANAGER_MAX_MAIN_WINDOWS; index ++ )
      70             :     {
      71           0 :         if ( ! (*this_).main_window_active[index] )
      72             :         {
      73           0 :             pos = index;
      74             :         }
      75             :     }
      76             : 
      77           0 :     if ( -1 != pos )
      78             :     {
      79           0 :         gui_main_window_init( &((*this_).main_window[pos]),
      80             :                               (*this_).controller,
      81             :                               (*this_).data_file,
      82             :                               &((*this_).db_reader),
      83             :                               &((*this_).gui_resources),
      84             :                               (*this_).gtk_app,
      85             :                               &((*this_).window_close_observer),
      86             :                               &((*this_).window_open_observer)
      87             :                             );
      88           0 :         (*this_).main_window_active[pos] = true;
      89           0 :         U8_TRACE_INFO_INT( "main_window[] index:", pos );
      90           0 :         result = &((*this_).main_window[pos]);
      91             :     }
      92             :     else
      93             :     {
      94           0 :         U8_LOG_ERROR_INT( "Maximum number of windows already open.", GUI_WINDOW_MANAGER_MAX_MAIN_WINDOWS );
      95           0 :         result = NULL;
      96             :     }
      97             : 
      98           0 :     U8_TRACE_END();
      99           0 :     return result;
     100             : }
     101             : 
     102           0 : void gui_window_manager_close_main_window_callback( gui_window_manager_t *this_, gui_main_window_t *main_window )
     103             : {
     104           0 :     U8_TRACE_BEGIN();
     105           0 :     int count_active = 0;
     106           0 :     int count_closed = 0;
     107             : 
     108           0 :     for( int index = 0; index < GUI_WINDOW_MANAGER_MAX_MAIN_WINDOWS; index ++ )
     109             :     {
     110           0 :         if ( (*this_).main_window_active[index] )
     111             :         {
     112           0 :             if ( main_window == &((*this_).main_window[index]) )
     113             :             {
     114           0 :                 gui_main_window_destroy( &((*this_).main_window[index]) );
     115           0 :                 (*this_).main_window_active[index] = false;
     116           0 :                 U8_TRACE_INFO_INT( "main_window[] index:", index );
     117           0 :                 count_closed ++;
     118             :             }
     119             :             else
     120             :             {
     121           0 :                 count_active ++;
     122             :             }
     123             :         }
     124             :     }
     125             : 
     126           0 :     if ( count_closed == 0 )
     127             :     {
     128           0 :         U8_LOG_ERROR( "no window of given address found" );
     129             :     }
     130             :     if ( count_active == 0 )
     131             :     {
     132             :         /* application states are managed by gtk */
     133             :     }
     134             : 
     135           0 :     U8_TRACE_END();
     136           0 : }
     137             : 
     138           0 : void gui_window_manager_open_main_window_callback( gui_window_manager_t *this_, gui_simple_message_to_user_t *message_to_user )
     139             : {
     140           0 :     U8_TRACE_BEGIN();
     141             : 
     142             :     gui_main_window_t *new_win;
     143           0 :     new_win = gui_window_manager_open_main_window( this_ );
     144             : 
     145           0 :     if ( NULL == new_win )
     146             :     {
     147           0 :         gui_simple_message_to_user_show_message_with_quantity( message_to_user,
     148             :                                                                GUI_SIMPLE_MESSAGE_TYPE_WARNING,
     149             :                                                                GUI_SIMPLE_MESSAGE_CONTENT_MAX_WINDOWS_ALREADY_OPEN,
     150             :                                                                GUI_WINDOW_MANAGER_MAX_MAIN_WINDOWS
     151             :                                                              );
     152             :     }
     153             : 
     154           0 :     U8_TRACE_END();
     155           0 : }
     156             : 
     157             : 
     158             : /*
     159             : Copyright 2016-2024 Andreas Warnke
     160             : 
     161             : Licensed under the Apache License, Version 2.0 (the "License");
     162             : you may not use this file except in compliance with the License.
     163             : You may obtain a copy of the License at
     164             : 
     165             :     http://www.apache.org/licenses/LICENSE-2.0
     166             : 
     167             : Unless required by applicable law or agreed to in writing, software
     168             : distributed under the License is distributed on an "AS IS" BASIS,
     169             : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     170             : See the License for the specific language governing permissions and
     171             : limitations under the License.
     172             : */

Generated by: LCOV version 1.16