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"
23 * @addtogroup IrrecoWindowManager
26 * Creates and destroys irreco windows, and stores some data for them.
33 * Source file of @ref IrrecoWindowManager.
36 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
37 /* Construction & Destruction */
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
41 * @name Construction & Destruction
45 IrrecoWindowManager
*irreco_window_manager_create(IrrecoData
* irreco_data
)
47 IrrecoWindowManager
*manager
;
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
)
60 g_slice_free(IrrecoWindowManager
, manager
);
68 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
69 /* Public Functions */
70 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
73 * @name Public Functions
76 gboolean
irreco_window_manager_clean(IrrecoWindowManager
* manager
);
77 void irreco_window_manager_show(IrrecoWindowManager
* manager
,
82 if (manager
->current_layout
!= NULL
) {
83 irreco_button_layout_reset(manager
->current_layout
);
85 if (manager
->to_be_destroyed
!= 0) {
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
,
96 gtk_idle_add(GTK_FUNCTION(irreco_window_manager_clean
),
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
);
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
,
112 gtk_idle_add(GTK_FUNCTION(irreco_window_manager_clean
),
117 manager
->current_window
= IRRECO_WINDOW_EDIT
;
118 manager
->edit_window
= irreco_window_edit_create(manager
);
122 IRRECO_ERROR("Unknown window id \"%i\".\n", id
);
130 * We use this to destroy the old window after the new one has been drawn
133 gboolean
irreco_window_manager_clean(IrrecoWindowManager
* manager
)
137 switch (manager
->to_be_destroyed
) {
138 case IRRECO_WINDOW_USER
:
139 irreco_window_user_destroy(manager
->user_window
);
140 manager
->user_window
= NULL
;
143 case IRRECO_WINDOW_EDIT
:
144 irreco_window_edit_destroy(manager
->edit_window
);
145 manager
->edit_window
= NULL
;
149 IRRECO_ERROR("Unknown window id \"%i\".\n",
150 manager
->to_be_destroyed
);
154 manager
->to_be_destroyed
= 0;
155 IRRECO_RETURN_BOOL(FALSE
);
159 void irreco_window_manager_set_layout(IrrecoWindowManager
* manager
,
160 IrrecoButtonLayout
* layout
)
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
));
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
);
186 case IRRECO_WINDOW_EDIT
:
187 irreco_window_edit_set_layout(manager
->edit_window
, layout
);
191 IRRECO_ERROR("Unknown window id \"%i\".\n",
192 manager
->current_window
);
199 GtkWindow
*irreco_window_manager_get_gtk_window(IrrecoWindowManager
* manager
)
202 switch (manager
->current_window
) {
203 case IRRECO_WINDOW_USER
:
205 IRRECO_RETURN_PTR(irreco_window_get_gtk_window(
206 manager
->user_window
->window
));
208 case IRRECO_WINDOW_EDIT
:
210 IRRECO_RETURN_PTR(irreco_window_get_gtk_window(
211 manager
->edit_window
->window
));
214 IRRECO_ERROR("Unknown window id \"%i\".\n",
215 manager
->current_window
);
216 IRRECO_RETURN_PTR(NULL
);