2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
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.
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.
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
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
26 // Leonardo Zide (leo@lokigames.com)
29 #include "groupdialog.h"
30 #include "globaldefs.h"
32 #include "debugging/debugging.h"
37 #include "gtkutil/widget.h"
38 #include "gtkutil/accelerator.h"
39 #include "entityinspector.h"
44 #include "gtkutil/window.h"
46 #if defined(WORKAROUND_WINDOWS_GTK2_GLWIDGET) || defined(WORKAROUND_MACOS_GTK2_GLWIDGET)
47 #include "texwindow.h"
48 #endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET || WORKAROUND_MACOS_GTK2_GLWIDGET
53 ui::Widget m_pNotebook{ui::null};
54 ui::Window m_window{ui::null};
57 void Create( ui::Window parent );
60 // 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
61 m_position_tracker.sync( m_window );
68 WindowPositionTracker m_position_tracker;
75 std::size_t g_current_page;
76 std::vector<Callback<void(const Callback<void(const char *)> &)>> g_pages;
79 static void workaround_macos_show_hide(){
80 #ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
81 if ( g_current_page == 2 )
83 TextureBrowser_showGLWidget();
87 TextureBrowser_hideGLWidget();
89 #endif // WORKAROUND_MACOS_GTK2_GLWIDGET
92 void GroupDialog_updatePageTitle( ui::Window window, std::size_t pageIndex ){
93 if ( pageIndex < g_pages.size() ) {
94 g_pages[pageIndex]( PointerCaller<GtkWindow, void(const char*), gtk_window_set_title>( window ) );
97 workaround_macos_show_hide();
100 static gboolean switch_page( GtkNotebook *notebook, gpointer page, guint page_num, gpointer data ){
101 g_current_page = page_num;
102 GroupDialog_updatePageTitle( ui::Window::from(data), page_num );
106 GroupDlg::GroupDlg() : m_window( ui::null ){
107 m_position_tracker.setPosition( c_default_window_pos );
110 void GroupDlg::Create( ui::Window parent ){
111 ASSERT_MESSAGE( !m_window, "dialog already created" );
113 auto window = ui::Window(create_persistent_floating_window( "Entities", parent ));
115 global_accel_connect_window( window );
117 window_connect_focus_in_clear_focus_widget( window );
122 if ( g_multimon_globals.m_bStartOnPrimMon ) {
123 WindowPosition pos( m_position_tracker.getPosition() );
124 PositionWindowOnPrimaryScreen( pos );
125 m_position_tracker.setPosition( pos );
128 m_position_tracker.connect( window );
131 ui::Widget notebook = ui::Widget::from(gtk_notebook_new());
133 window.add(notebook);
134 gtk_notebook_set_tab_pos( GTK_NOTEBOOK( notebook ), GTK_POS_BOTTOM );
135 m_pNotebook = notebook;
137 notebook.connect( "switch_page", G_CALLBACK( switch_page ), (gpointer) window );
141 ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const Callback<void(const Callback<void(const char *)> &)>& title ){
142 ui::Widget w = ui::Label( tabLabel );
144 auto page = ui::Widget::from(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gtk_notebook_insert_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), widget, w, -1 ) ));
145 g_pages.push_back( title );
150 bool GroupDialog_isShown(){
151 return g_GroupDlg.m_window.visible();
153 void GroupDialog_setShown( bool shown ){
154 shown ? g_GroupDlg.Show() : g_GroupDlg.Hide();
156 void GroupDialog_ToggleShow(){
157 GroupDialog_setShown( !GroupDialog_isShown() );
160 void GroupDialog_constructWindow( ui::Window main_window ){
161 g_GroupDlg.Create( main_window );
163 void GroupDialog_destroyWindow(){
164 ASSERT_TRUE( g_GroupDlg.m_window );
165 destroy_floating_window( g_GroupDlg.m_window );
166 g_GroupDlg.m_window = ui::Window{ui::null};
169 ui::Window GroupDialog_getWindow(){
170 return ui::Window(g_GroupDlg.m_window);
172 void GroupDialog_show(){
176 ui::Widget GroupDialog_getPage(){
177 return ui::Widget::from(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) ) );
180 void GroupDialog_setPage( ui::Widget page ){
181 g_current_page = gtk_notebook_page_num( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), page );
182 gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
184 workaround_macos_show_hide();
187 #ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
188 void GroupDialog_cycle(){
189 g_current_page = ( g_current_page + 1 ) % g_pages.size();
190 gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
192 #endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET
194 void GroupDialog_showPage( ui::Widget page ){
196 if ( GroupDialog_getPage() == page ) {
197 GroupDialog_ToggleShow();
199 #ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
200 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
201 /* this is very ugly: cycle to next tab then return to current tab immediately to force the refresh
202 * this fixes the drawing of texture tab when window is restored and current tab is texture tab
203 * this is called for nothing when windows is minimized and called for nothing when current tab
204 * is not texture tab, hopefully it's a workaround that would disappear with gtk 3 */
206 GroupDialog_setPage( page );
207 #endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET
212 g_GroupDlg.m_window.show();
213 GroupDialog_setPage( page );
216 workaround_macos_show_hide();
219 void GroupDialog_updatePageTitle( ui::Widget page ){
220 if ( GroupDialog_getPage() == page ) {
221 GroupDialog_updatePageTitle( g_GroupDlg.m_window, g_current_page );
225 #include "preferencesystem.h"
227 void GroupDialog_Construct(){
228 GlobalPreferenceSystem().registerPreference( "EntityWnd", make_property<WindowPositionTracker_String>( g_GroupDlg.m_position_tracker ) );
230 GlobalCommands_insert( "ViewEntityInfo", makeCallbackF(GroupDialog_ToggleShow), Accelerator( 'N' ) );
232 void GroupDialog_Destroy(){