Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 233 lines (185 sloc) 5.857 kb
0991a5c @tbradshaw The GtkRadiant sources as originally released under the GPL license.
tbradshaw authored
1 /*
2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 //
23 // Floating dialog that contains a notebook with at least Entities and Group tabs
24 // I merged the 2 MS Windows dialogs in a single class
25 //
26 // Leonardo Zide (leo@lokigames.com)
27 //
28
29 #include "groupdialog.h"
30
31 #include "debugging/debugging.h"
32
33 #include <vector>
34
35 #include <gtk/gtknotebook.h>
36 #include <gtk/gtktextview.h>
37 #include <gtk/gtklabel.h>
38 #include <gtk/gtkscrolledwindow.h>
39
40 #include "gtkutil/widget.h"
41 #include "gtkutil/accelerator.h"
42 #include "entityinspector.h"
43 #include "gtkmisc.h"
44 #include "multimon.h"
45 #include "console.h"
46 #include "commands.h"
47
48
49 #include <gtk/gtkwidget.h>
50 #include "gtkutil/window.h"
51
52 class GroupDlg
53 {
54 public:
55 GtkWidget* m_pNotebook;
56 GtkWindow* m_window;
57
58 GroupDlg();
59 void Create(GtkWindow* parent);
60
61 void Show()
62 {
63 // workaround for strange gtk behaviour - modifying the contents of a window while it is not visible causes the window position to change without sending a configure_event
64 m_position_tracker.sync(m_window);
65 gtk_widget_show(GTK_WIDGET(m_window));
66 }
67 void Hide()
68 {
69 gtk_widget_hide(GTK_WIDGET(m_window));
70 }
71
72 WindowPositionTracker m_position_tracker;
73 };
74
75 namespace
76 {
77 GroupDlg g_GroupDlg;
78
79 std::size_t g_current_page;
80 std::vector<StringExportCallback> g_pages;
81 }
82
83 void GroupDialog_updatePageTitle(GtkWindow* window, std::size_t pageIndex)
84 {
85 if(pageIndex < g_pages.size())
86 {
87 g_pages[pageIndex](PointerCaller1<GtkWindow, const char*, gtk_window_set_title>(window));
88 }
89 }
90
91 static gboolean switch_page(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer data)
92 {
93 GroupDialog_updatePageTitle(GTK_WINDOW(data), page_num);
94 g_current_page = page_num;
95
96 return FALSE;
97 }
98
99 GroupDlg::GroupDlg() : m_window(0)
100 {
101 m_position_tracker.setPosition(c_default_window_pos);
102 }
103
104 void GroupDlg::Create(GtkWindow* parent)
105 {
106 ASSERT_MESSAGE(m_window == 0, "dialog already created");
107
108 GtkWindow* window = create_persistent_floating_window("Entities", parent);
109
110 global_accel_connect_window(window);
111
112 window_connect_focus_in_clear_focus_widget(window);
113
114 m_window = window;
115
116 #ifdef WIN32
117 if( g_multimon_globals.m_bStartOnPrimMon )
118 {
119 WindowPosition pos(m_position_tracker.getPosition());
120 PositionWindowOnPrimaryScreen(pos);
121 m_position_tracker.setPosition(pos);
122 }
123 #endif
124 m_position_tracker.connect(window);
125
126 {
127 GtkWidget* notebook = gtk_notebook_new();
128 gtk_widget_show(notebook);
129 gtk_container_add (GTK_CONTAINER (window), notebook);
130 gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), GTK_POS_BOTTOM);
131 m_pNotebook = notebook;
132
133 g_signal_connect(G_OBJECT(notebook), "switch_page", G_CALLBACK(switch_page), window);
134 }
135 }
136
137
138 GtkWidget* GroupDialog_addPage(const char* tabLabel, GtkWidget* widget, const StringExportCallback& title)
139 {
140 GtkWidget* w = gtk_label_new(tabLabel);
141 gtk_widget_show(w);
142 GtkWidget* page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(g_GroupDlg.m_pNotebook), gtk_notebook_insert_page(GTK_NOTEBOOK(g_GroupDlg.m_pNotebook), widget, w, -1));
143 g_pages.push_back(title);
144
145 return page;
146 }
147
148
149 bool GroupDialog_isShown()
150 {
151 return widget_is_visible(GTK_WIDGET(g_GroupDlg.m_window));
152 }
153 void GroupDialog_setShown(bool shown)
154 {
155 shown ? g_GroupDlg.Show() : g_GroupDlg.Hide();
156 }
157 void GroupDialog_ToggleShow()
158 {
159 GroupDialog_setShown(!GroupDialog_isShown());
160 }
161
162 void GroupDialog_constructWindow(GtkWindow* main_window)
163 {
164 g_GroupDlg.Create(main_window);
165 }
166 void GroupDialog_destroyWindow()
167 {
168 ASSERT_NOTNULL(g_GroupDlg.m_window);
169 destroy_floating_window(g_GroupDlg.m_window);
170 g_GroupDlg.m_window = 0;
171 }
172
173
174 GtkWindow* GroupDialog_getWindow()
175 {
176 return g_GroupDlg.m_window;
177 }
178 void GroupDialog_show()
179 {
180 g_GroupDlg.Show();
181 }
182
183 GtkWidget* GroupDialog_getPage()
184 {
185 return gtk_notebook_get_nth_page(GTK_NOTEBOOK(g_GroupDlg.m_pNotebook), gint(g_current_page));
186 }
187
188 void GroupDialog_setPage(GtkWidget* page)
189 {
190 g_current_page = gtk_notebook_page_num(GTK_NOTEBOOK(g_GroupDlg.m_pNotebook), page);
191 gtk_notebook_set_current_page(GTK_NOTEBOOK(g_GroupDlg.m_pNotebook), gint(g_current_page));
192 }
193
194 void GroupDialog_showPage(GtkWidget* page)
195 {
196 if(GroupDialog_getPage() == page)
197 {
198 GroupDialog_ToggleShow();
199 }
200 else
201 {
202 gtk_widget_show(GTK_WIDGET(g_GroupDlg.m_window));
203 GroupDialog_setPage(page);
204 }
205 }
206
207 void GroupDialog_cycle()
208 {
209 g_current_page = (g_current_page + 1) % g_pages.size();
210 gtk_notebook_set_current_page(GTK_NOTEBOOK(g_GroupDlg.m_pNotebook), gint(g_current_page));
211 }
212
213 void GroupDialog_updatePageTitle(GtkWidget* page)
214 {
215 if(GroupDialog_getPage() == page)
216 {
217 GroupDialog_updatePageTitle(g_GroupDlg.m_window, g_current_page);
218 }
219 }
220
221
222 #include "preferencesystem.h"
223
224 void GroupDialog_Construct()
225 {
226 GlobalPreferenceSystem().registerPreference("EntityWnd", WindowPositionTrackerImportStringCaller(g_GroupDlg.m_position_tracker), WindowPositionTrackerExportStringCaller(g_GroupDlg.m_position_tracker));
227
228 GlobalCommands_insert("ViewEntityInfo", FreeCaller<GroupDialog_ToggleShow>(), Accelerator('N'));
229 }
230 void GroupDialog_Destroy()
231 {
232 }
Something went wrong with that request. Please try again.