| 1 |
/********************************************************************\
|
| 2 |
* duigtktop.c -- top level gtk anchor point *
|
| 3 |
* Copyright (C) 2002,2004 Linas Vepstas <linas@linas.org> *
|
| 4 |
* http://dwi.sourceforge.net *
|
| 5 |
* *
|
| 6 |
* This library is free software; you can redistribute it and/or *
|
| 7 |
* modify it under the terms of the GNU Lesser General Public *
|
| 8 |
* License as published by the Free Software Foundation; either *
|
| 9 |
* version 2.1 of the License, or (at your option) any later version.
|
| 10 |
* *
|
| 11 |
* This library is distributed in the hope that it will be useful, *
|
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
| 14 |
* GNU Lesser General Public License for more details. *
|
| 15 |
* *
|
| 16 |
* You should have received a copy of the GNU Lesser General Public *
|
| 17 |
* License along with the GNU C Library; if not, write to the Free *
|
| 18 |
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
|
| 19 |
* Boston, MA 02110-1301, USA. *
|
| 20 |
\********************************************************************/
|
| 21 |
|
| 22 |
/**
|
| 23 |
@file duitop-gtk.c
|
| 24 |
@brief top level gtk anchor point
|
| 25 |
@author 2002,2004 Linas Vepstas <linas@linas.org>
|
| 26 |
*/
|
| 27 |
|
| 28 |
#include <string.h>
|
| 29 |
#include "interface.h"
|
| 30 |
#include "window.h"
|
| 31 |
#include "perr.h"
|
| 32 |
|
| 33 |
struct DuiGtkTop_s
|
| 34 |
{
|
| 35 |
GList *window_list;
|
| 36 |
};
|
| 37 |
|
| 38 |
/* =================================================================== */
|
| 39 |
|
| 40 |
DuiGtkTop *
|
| 41 |
dui_gtk_top_new (void)
|
| 42 |
{
|
| 43 |
DuiGtkTop *top;
|
| 44 |
|
| 45 |
top = g_new0 (DuiGtkTop, 1);
|
| 46 |
top->window_list = NULL;
|
| 47 |
return top;
|
| 48 |
}
|
| 49 |
|
| 50 |
void
|
| 51 |
dui_gtk_top_destroy (DuiGtkTop *top)
|
| 52 |
{
|
| 53 |
GList *node;
|
| 54 |
if (!top) return;
|
| 55 |
for (node=top->window_list; node; node=node->next)
|
| 56 |
{
|
| 57 |
DuiWindow *win = node->data;
|
| 58 |
dui_window_destroy (win);
|
| 59 |
}
|
| 60 |
g_list_free (top->window_list);
|
| 61 |
g_free (top);
|
| 62 |
}
|
| 63 |
|
| 64 |
/* =================================================================== */
|
| 65 |
|
| 66 |
void
|
| 67 |
dui_gtk_top_add_window (DuiGtkTop *top, DuiWindow *win)
|
| 68 |
{
|
| 69 |
if (!win) return;
|
| 70 |
top->window_list = g_list_append (top->window_list, win);
|
| 71 |
}
|
| 72 |
|
| 73 |
/* =================================================================== */
|
| 74 |
|
| 75 |
DuiWindow *
|
| 76 |
dui_gtk_top_find_window_by_name (DuiGtkTop *top, const gchar * name)
|
| 77 |
{
|
| 78 |
GList *node;
|
| 79 |
|
| 80 |
if (!name) return NULL;
|
| 81 |
|
| 82 |
for (node=top->window_list; node; node=node->next)
|
| 83 |
{
|
| 84 |
DuiWindow *win = node->data;
|
| 85 |
const gchar *winname = dui_window_get_name (win);
|
| 86 |
if (winname && !strcmp(winname, name))
|
| 87 |
{
|
| 88 |
return win;
|
| 89 |
}
|
| 90 |
}
|
| 91 |
return NULL;
|
| 92 |
}
|
| 93 |
|
| 94 |
/* =================================================================== */
|
| 95 |
|
| 96 |
static gboolean
|
| 97 |
dui_gtk_top_realize (gpointer self, gboolean fatal_if_no_main)
|
| 98 |
{
|
| 99 |
DuiGtkTop *top = self;
|
| 100 |
GList *node;
|
| 101 |
gboolean found_app_window = 0;
|
| 102 |
|
| 103 |
for (node=top->window_list; node; node=node->next)
|
| 104 |
{
|
| 105 |
DuiWindow *win = node->data;
|
| 106 |
dui_window_resolve (win);
|
| 107 |
}
|
| 108 |
|
| 109 |
for (node=top->window_list; node; node=node->next)
|
| 110 |
{
|
| 111 |
DuiWindow *win = node->data;
|
| 112 |
gboolean is_app_window = dui_window_is_app_main_window(win);
|
| 113 |
if (is_app_window)
|
| 114 |
{
|
| 115 |
dui_window_realize (win);
|
| 116 |
found_app_window = 1;
|
| 117 |
}
|
| 118 |
}
|
| 119 |
|
| 120 |
/* Without this test, its just too easy to write an estron file
|
| 121 |
* that just hangs there, doing nothing, and you scratch your
|
| 122 |
* head wondering why ...
|
| 123 |
*/
|
| 124 |
/** @bug it is still too easy to hang estron with a
|
| 125 |
flawed estron file, despite passing TRUE to dui_interface_realize,
|
| 126 |
typically after this point. Check why. */
|
| 127 |
if (fatal_if_no_main && 0 == found_app_window)
|
| 128 |
{
|
| 129 |
// fatal causes an abort which causes a crash detection dialogue.
|
| 130 |
PWARN ("could not find an application main window!");
|
| 131 |
return FALSE;
|
| 132 |
}
|
| 133 |
return TRUE;
|
| 134 |
}
|
| 135 |
|
| 136 |
/* =================================================================== */
|
| 137 |
|
| 138 |
DuiInterfacePlugin *
|
| 139 |
dui_gtk_top_plugin_new (DuiGtkTop *top)
|
| 140 |
{
|
| 141 |
DuiInterfacePlugin *dip;
|
| 142 |
|
| 143 |
dip = g_new0 (DuiInterfacePlugin, 1);
|
| 144 |
dip->plugin_name = "dui_gtk_top";
|
| 145 |
dip->self = top;
|
| 146 |
dip->realize = dui_gtk_top_realize;
|
| 147 |
|
| 148 |
return dip;
|
| 149 |
}
|
| 150 |
|
| 151 |
/* ========================== END OF FILE ============================ */
|