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