Merge branch 'master' of ssh://pege77@mercury.wipsl.com/var/git/irreco-theme-editor
[irreco.git] / irreco / src / core / irreco_window_manager.c
blob7ed1848cf63e547dc0eb8e092ac9e64e72916eeb
1 /*
2 * irreco - Ir Remote Control
3 * Copyright (C) 2007 Arto Karppinen (arto.karppinen@iki.fi)
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 #include "irreco_window_manager.h"
22 /**
23 * @addtogroup IrrecoWindowManager
24 * @ingroup Irreco
26 * Creates and destroys irreco windows, and stores some data for them.
28 * @{
31 /**
32 * @file
33 * Source file of @ref IrrecoWindowManager.
36 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
37 /* Construction & Destruction */
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 /**
41 * @name Construction & Destruction
42 * @{
45 IrrecoWindowManager *irreco_window_manager_create(IrrecoData * irreco_data)
47 IrrecoWindowManager *manager;
48 IRRECO_ENTER
50 manager = g_slice_new0(IrrecoWindowManager);
51 manager->irreco_data = irreco_data;
53 IRRECO_DEBUG("IrrecoData = %p\n", (void*) irreco_data);
54 IRRECO_RETURN_PTR(manager);
57 void irreco_window_manager_destroy(IrrecoWindowManager * manager)
59 IRRECO_ENTER
60 g_slice_free(IrrecoWindowManager, manager);
61 IRRECO_RETURN
64 /** @} */
68 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
69 /* Public Functions */
70 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
72 /**
73 * @name Public Functions
74 * @{
76 gboolean irreco_window_manager_clean(IrrecoWindowManager * manager);
77 void irreco_window_manager_show(IrrecoWindowManager * manager,
78 IrrecoWindowId id)
80 IRRECO_ENTER
82 if (manager->current_layout != NULL) {
83 irreco_button_layout_reset(manager->current_layout);
85 if (manager->to_be_destroyed != 0) {
86 IRRECO_RETURN
89 switch (id) {
90 case IRRECO_WINDOW_USER:
92 if (manager->edit_window != NULL) {
93 manager->to_be_destroyed = IRRECO_WINDOW_EDIT;
94 irreco_window_edit_set_layout(manager->edit_window,
95 NULL);
96 gtk_idle_add(GTK_FUNCTION(irreco_window_manager_clean),
97 manager);
100 manager->current_window = IRRECO_WINDOW_USER;
101 manager->user_window = irreco_window_user_create(manager);
102 irreco_window_user_set_layout(manager->user_window,
103 manager->current_layout);
104 break;
106 case IRRECO_WINDOW_EDIT:
108 if (manager->user_window != NULL) {
109 manager->to_be_destroyed = IRRECO_WINDOW_USER;
110 irreco_window_user_set_layout(manager->user_window,
111 NULL);
112 gtk_idle_add(GTK_FUNCTION(irreco_window_manager_clean),
113 manager);
117 manager->current_window = IRRECO_WINDOW_EDIT;
118 manager->edit_window = irreco_window_edit_create(manager);
119 break;
121 default:
122 IRRECO_ERROR("Unknown window id \"%i\".\n", id);
123 break;
126 IRRECO_RETURN
130 * We use this to destroy the old window after the new one has been drawn
131 * to the screen.
133 gboolean irreco_window_manager_clean(IrrecoWindowManager * manager)
135 IRRECO_ENTER
137 switch (manager->to_be_destroyed) {
138 case IRRECO_WINDOW_USER:
139 irreco_window_user_destroy(manager->user_window);
140 manager->user_window = NULL;
141 break;
143 case IRRECO_WINDOW_EDIT:
144 irreco_window_edit_destroy(manager->edit_window);
145 manager->edit_window = NULL;
146 break;
148 default:
149 IRRECO_ERROR("Unknown window id \"%i\".\n",
150 manager->to_be_destroyed);
151 break;
154 manager->to_be_destroyed = 0;
155 IRRECO_RETURN_BOOL(FALSE);
159 void irreco_window_manager_set_layout(IrrecoWindowManager * manager,
160 IrrecoButtonLayout * layout)
162 IRRECO_ENTER
164 g_assert(manager != NULL);
166 if (layout == NULL) {
167 IRRECO_PRINTF("Layout is NULL.\n");
168 } else if (layout == manager->current_layout) {
169 IRRECO_PRINTF("Layout \"%s\" is already set.\n",
170 irreco_button_layout_get_name(layout));
171 IRRECO_RETURN
172 } else {
173 IRRECO_PRINTF("Setting layout \"%s\".\n",
174 irreco_button_layout_get_name(layout));
177 irreco_button_layout_reset(layout);
178 irreco_button_layout_reset(manager->current_layout);
179 manager->current_layout = layout;
181 switch (manager->current_window) {
182 case IRRECO_WINDOW_USER:
183 irreco_window_user_set_layout(manager->user_window, layout);
184 break;
186 case IRRECO_WINDOW_EDIT:
187 irreco_window_edit_set_layout(manager->edit_window, layout);
188 break;
190 default:
191 IRRECO_ERROR("Unknown window id \"%i\".\n",
192 manager->current_window);
193 break;
196 IRRECO_RETURN
199 GtkWindow *irreco_window_manager_get_gtk_window(IrrecoWindowManager * manager)
201 IRRECO_ENTER
202 switch (manager->current_window) {
203 case IRRECO_WINDOW_USER:
204 IRRECO_DEBUG_LINE;
205 IRRECO_RETURN_PTR(irreco_window_get_gtk_window(
206 manager->user_window->window));
208 case IRRECO_WINDOW_EDIT:
209 IRRECO_DEBUG_LINE;
210 IRRECO_RETURN_PTR(irreco_window_get_gtk_window(
211 manager->edit_window->window));
213 default:
214 IRRECO_ERROR("Unknown window id \"%i\".\n",
215 manager->current_window);
216 IRRECO_RETURN_PTR(NULL);
220 /** @} */
221 /** @} */