1 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
2 | * Version: CDDL 1.0/LGPL 2.1
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND
|
---|
5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
|
---|
6 | * this file except in compliance with the License. You may obtain a copy of
|
---|
7 | * the License at http://www.sun.com/cddl/
|
---|
8 | *
|
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | * for the specific language governing rights and limitations under the
|
---|
12 | * License.
|
---|
13 | *
|
---|
14 | * The Original Code is "NOM" Netlabs Object Model
|
---|
15 | *
|
---|
16 | * The Initial Developer of the Original Code is
|
---|
17 | * netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2005-2006
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | *
|
---|
23 | * Alternatively, the contents of this file may be used under the terms of
|
---|
24 | * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
|
---|
25 | * case the provisions of the LGPL are applicable instead of those above. If
|
---|
26 | * you wish to allow use of your version of this file only under the terms of
|
---|
27 | * the LGPL, and not to allow others to use your version of this file under
|
---|
28 | * the terms of the CDDL, indicate your decision by deleting the provisions
|
---|
29 | * above and replace them with the notice and other provisions required by the
|
---|
30 | * LGPL. If you do not delete the provisions above, a recipient may use your
|
---|
31 | * version of this file under the terms of any one of the CDDL or the LGPL.
|
---|
32 | *
|
---|
33 | * ***** END LICENSE BLOCK ***** */
|
---|
34 |
|
---|
35 | #include <gtk/gtk.h>
|
---|
36 |
|
---|
37 | static GtkWidget * dbgWindow;
|
---|
38 |
|
---|
39 | enum
|
---|
40 | {
|
---|
41 | COLUMN_ONE,
|
---|
42 | NUM_COLUMNS
|
---|
43 | };
|
---|
44 |
|
---|
45 | static void add_columns (GtkTreeView *treeview)
|
---|
46 | {
|
---|
47 | GtkCellRenderer *renderer;
|
---|
48 | GtkTreeViewColumn *column;
|
---|
49 |
|
---|
50 | /* column for description */
|
---|
51 | renderer = gtk_cell_renderer_text_new ();
|
---|
52 | column = gtk_tree_view_column_new_with_attributes ("Message",
|
---|
53 | renderer,
|
---|
54 | "text",
|
---|
55 | COLUMN_ONE,
|
---|
56 | NULL);
|
---|
57 | gtk_tree_view_column_set_sort_column_id (column, COLUMN_ONE);
|
---|
58 | gtk_tree_view_append_column (treeview, column);
|
---|
59 | }
|
---|
60 |
|
---|
61 | static GtkWidget* createDbgWindow(GtkWidget* dbgWindow, GtkTreeModel **model)
|
---|
62 | {
|
---|
63 | if (!dbgWindow)
|
---|
64 | {
|
---|
65 | GtkWidget* window=dbgWindow;
|
---|
66 | GtkWidget *vbox;
|
---|
67 | GtkWidget *label;
|
---|
68 | GtkWidget *sw;
|
---|
69 | GtkWidget *treeview;
|
---|
70 | /* create window, etc */
|
---|
71 | dbgWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
---|
72 | window=dbgWindow;
|
---|
73 | /* gtk_window_set_screen (GTK_WINDOW (dbgWindow),
|
---|
74 | gtk_widget_get_screen (do_widget)); */
|
---|
75 | gtk_window_set_title (GTK_WINDOW (dbgWindow), "Debug output");
|
---|
76 | #if 0
|
---|
77 | g_signal_connect (window, "destroy",
|
---|
78 | G_CALLBACK (gtk_widget_destroyed), &window);
|
---|
79 | #endif
|
---|
80 |
|
---|
81 | gtk_container_set_border_width (GTK_CONTAINER (dbgWindow), 8);
|
---|
82 | vbox = gtk_vbox_new (FALSE, 8);
|
---|
83 | gtk_container_add (GTK_CONTAINER (window), vbox);
|
---|
84 | label = gtk_label_new ("Voyager Desktop");
|
---|
85 | gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
|
---|
86 | sw = gtk_scrolled_window_new (NULL, NULL);
|
---|
87 | gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
|
---|
88 | GTK_SHADOW_ETCHED_IN);
|
---|
89 | gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
---|
90 | GTK_POLICY_NEVER,
|
---|
91 | GTK_POLICY_AUTOMATIC);
|
---|
92 | gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);
|
---|
93 | /* create tree view */
|
---|
94 | treeview = gtk_tree_view_new_with_model (*model);
|
---|
95 | gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (treeview), TRUE);
|
---|
96 |
|
---|
97 | gtk_container_add (GTK_CONTAINER (sw), treeview);
|
---|
98 |
|
---|
99 | /* add columns to the tree view */
|
---|
100 | add_columns (GTK_TREE_VIEW (treeview));
|
---|
101 |
|
---|
102 | /* finish & show */
|
---|
103 | gtk_window_set_default_size (GTK_WINDOW (window), 380, 250);
|
---|
104 |
|
---|
105 | }
|
---|
106 | if (!GTK_WIDGET_VISIBLE (dbgWindow))
|
---|
107 | gtk_widget_show_all (dbgWindow);
|
---|
108 | else
|
---|
109 | {
|
---|
110 | gtk_widget_destroy (dbgWindow);
|
---|
111 | dbgWindow = NULL;
|
---|
112 | }
|
---|
113 | return dbgWindow;
|
---|
114 | }
|
---|
115 |
|
---|
116 | void dbgPrintf(const gchar* gchrFormat, ...)
|
---|
117 | {
|
---|
118 | static GtkListStore *store=NULL;
|
---|
119 | GtkTreeIter iter;
|
---|
120 | gchar *gchrTemp;
|
---|
121 | va_list arg_ptr;
|
---|
122 |
|
---|
123 | return;
|
---|
124 |
|
---|
125 | if(store==NULL)
|
---|
126 | {
|
---|
127 | /* Create a list store and model holding the messages which will be
|
---|
128 | connected with a GtkTreeView */
|
---|
129 | GtkTreeModel *model;
|
---|
130 | store = gtk_list_store_new (NUM_COLUMNS,
|
---|
131 | G_TYPE_STRING);
|
---|
132 | /* create tree model */
|
---|
133 | model=GTK_TREE_MODEL (store);
|
---|
134 | dbgWindow=createDbgWindow( dbgWindow, &model);
|
---|
135 | }
|
---|
136 | /* add data to the list store */
|
---|
137 | va_start (arg_ptr, gchrFormat);
|
---|
138 | gchrTemp=g_strdup_vprintf(gchrFormat, arg_ptr);
|
---|
139 | va_end (arg_ptr);
|
---|
140 | gtk_list_store_append (store, &iter);
|
---|
141 | if(gchrTemp)
|
---|
142 | {
|
---|
143 | gtk_list_store_set (store, &iter,
|
---|
144 | COLUMN_ONE, gchrTemp,
|
---|
145 | -1);
|
---|
146 | g_free(gchrTemp);
|
---|
147 | }
|
---|
148 | else
|
---|
149 | {
|
---|
150 | gtk_list_store_set (store, &iter,
|
---|
151 | COLUMN_ONE, "Out of memory!",
|
---|
152 | -1);
|
---|
153 | }
|
---|
154 | }
|
---|