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_dlg.h"
23 * @addtogroup IrrecoDlg
26 * Base class for Irreco dialogs.
33 * Source file of @ref IrrecoDlg.
38 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
40 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
42 #define IRRECO_DLG_CHILD_DATA_KEY "IrrecoChildDialog"
44 static void irreco_dlg_data_key_cleanup(IrrecoDlg
*self
, GtkWindow
*parent
);
48 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
49 /* Construction & Destruction */
50 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
53 * @name Construction & Destruction
57 G_DEFINE_TYPE(IrrecoDlg
, irreco_dlg
, GTK_TYPE_DIALOG
)
59 static void irreco_dlg_finalize(GObject
*object
)
61 G_OBJECT_CLASS(irreco_dlg_parent_class
)->finalize(object
);
64 static void irreco_dlg_class_init(IrrecoDlgClass
*klass
)
66 GObjectClass
*object_class
= G_OBJECT_CLASS(klass
);
67 object_class
->finalize
= irreco_dlg_finalize
;
70 static void irreco_dlg_init(IrrecoDlg
*self
)
76 GtkWidget
*irreco_dlg_new(void)
78 return g_object_new(IRRECO_TYPE_DLG
, NULL
);
85 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
86 /* Private Functions */
87 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
93 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
94 /* Public Functions */
95 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
98 * @name Public Functions
103 * Find the current topmost window, and set it as the parent window of this
106 * Normal Gtk windowing system stores only the parent window of dialogs. It
107 * does not store which children a parent window has. Because of that, it
108 * is not possible to iterate towards the topmost window from the parent windows
109 * until you reach the topmost window. This is a problem because Irreco uses
110 * a lot of dialogs, and dialogs may be created on somewhat random order.
111 * Especially windows created by backends can cause problems if order of window
112 * parentage is not properly handled.
114 * irreco_dlg_set_parent() works around this problem by using
115 * g_object_set_data() function to store a pointer to the current child window
116 * inside the parent window. This in effect creates a linked list of GtkWindows
117 * which can then be iterated until the current topmost window is found.
120 * Any GtkWindow which has IrrecoChildDialog data key set or
121 * Irreco main window.
123 void irreco_dlg_set_parent(IrrecoDlg
*self
, GtkWindow
*parent
)
129 if (gtk_window_get_transient_for(GTK_WINDOW(self
))) {
130 IRRECO_PRINTF("Dialog is already tracient for something.\n");
134 /* Iterate trough child windows, until we find the one that is
135 topmost on screen. */
137 data
= g_object_get_data(G_OBJECT(parent
),
138 IRRECO_DLG_CHILD_DATA_KEY
);
139 if (data
!= NULL
&& GTK_IS_WINDOW(data
)) {
140 parent
= GTK_WINDOW(data
);
147 IRRECO_PRINTF("Number of parent dialogs on screen: %i\n", depth
);
149 /* Set self as a child window. */
150 gtk_window_set_transient_for(GTK_WINDOW(self
), parent
);
151 g_object_set_data(G_OBJECT(parent
), IRRECO_DLG_CHILD_DATA_KEY
, self
);
153 /* Set up cleanup event. */
154 g_signal_connect(G_OBJECT(self
), "destroy",
155 G_CALLBACK(irreco_dlg_data_key_cleanup
), parent
);
163 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
164 /* Events and Callbacks */
165 /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/
168 * @name Events and Callbacks
172 static void irreco_dlg_data_key_cleanup(IrrecoDlg
*self
, GtkWindow
*parent
)
177 if (G_IS_OBJECT(parent
) == FALSE
) IRRECO_RETURN
;
179 /* Does parent have a pointer which points to this instace? */
180 data
= g_object_get_data(G_OBJECT(parent
), IRRECO_DLG_CHILD_DATA_KEY
);
181 if (data
== NULL
|| data
!= self
) IRRECO_RETURN
;
183 /* Remote the pointer. */
184 g_object_steal_data(G_OBJECT(parent
), IRRECO_DLG_CHILD_DATA_KEY
);