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 );
62 #define GARUX_GTK_WORKAROUND
63 #ifndef GARUX_GTK_WORKAROUND
64 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
65 GtkWidget* glwidget = GTK_WIDGET( g_object_get_data( G_OBJECT( m_window ), "glwidget" ) );
67 //if ( widget_is_visible( glwidget ) )
68 //globalOutputStream() << "glwidget have been already visible :0\n"; /* is not hidden aswell, according to this */
69 gtk_widget_hide( glwidget );
70 gtk_widget_show( glwidget );
79 WindowPositionTracker m_position_tracker;
86 std::size_t g_current_page;
87 std::vector<Callback<void(const Callback<void(const char *)> &)>> g_pages;
90 static void workaround_macos_show_hide(){
91 #ifdef WORKAROUND_MACOS_GTK2_GLWIDGET
92 if ( g_current_page == 2 )
94 TextureBrowser_showGLWidget();
98 TextureBrowser_hideGLWidget();
100 #endif // WORKAROUND_MACOS_GTK2_GLWIDGET
103 void GroupDialog_updatePageTitle( ui::Window window, std::size_t pageIndex ){
104 if ( pageIndex < g_pages.size() ) {
105 g_pages[pageIndex]( PointerCaller<GtkWindow, void(const char*), gtk_window_set_title>( window ) );
108 workaround_macos_show_hide();
111 static gboolean switch_page( GtkNotebook *notebook, gpointer page, guint page_num, gpointer data ){
112 g_current_page = page_num;
113 GroupDialog_updatePageTitle( ui::Window::from(data), page_num );
117 GroupDlg::GroupDlg() : m_window( ui::null ){
118 m_position_tracker.setPosition( c_default_window_pos );
121 void GroupDlg::Create( ui::Window parent ){
122 ASSERT_MESSAGE( !m_window, "dialog already created" );
124 auto window = ui::Window(create_persistent_floating_window( "Entities", parent ));
126 global_accel_connect_window( window );
128 window_connect_focus_in_clear_focus_widget( window );
133 if ( g_multimon_globals.m_bStartOnPrimMon ) {
134 WindowPosition pos( m_position_tracker.getPosition() );
135 PositionWindowOnPrimaryScreen( pos );
136 m_position_tracker.setPosition( pos );
139 m_position_tracker.connect( window );
142 ui::Widget notebook = ui::Widget::from(gtk_notebook_new());
144 window.add(notebook);
145 gtk_notebook_set_tab_pos( GTK_NOTEBOOK( notebook ), GTK_POS_BOTTOM );
146 m_pNotebook = notebook;
148 notebook.connect( "switch_page", G_CALLBACK( switch_page ), (gpointer) window );
152 ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const Callback<void(const Callback<void(const char *)> &)>& title ){
153 ui::Widget w = ui::Label( tabLabel );
155 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 ) ));
156 g_pages.push_back( title );
161 bool GroupDialog_isShown(){
162 return g_GroupDlg.m_window.visible();
164 void GroupDialog_setShown( bool shown ){
165 shown ? g_GroupDlg.Show() : g_GroupDlg.Hide();
167 void GroupDialog_ToggleShow(){
168 GroupDialog_setShown( !GroupDialog_isShown() );
171 void GroupDialog_constructWindow( ui::Window main_window ){
172 g_GroupDlg.Create( main_window );
174 void GroupDialog_destroyWindow(){
175 ASSERT_TRUE( g_GroupDlg.m_window );
176 destroy_floating_window( g_GroupDlg.m_window );
177 g_GroupDlg.m_window = ui::Window{ui::null};
180 ui::Window GroupDialog_getWindow(){
181 return ui::Window(g_GroupDlg.m_window);
183 void GroupDialog_show(){
187 ui::Widget GroupDialog_getPage(){
188 return ui::Widget::from(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) ) );
191 void GroupDialog_setPage( ui::Widget page ){
192 g_current_page = gtk_notebook_page_num( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), page );
193 gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
195 workaround_macos_show_hide();
198 #ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
199 void GroupDialog_cycle(){
200 g_current_page = ( g_current_page + 1 ) % g_pages.size();
201 gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
203 #endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET
205 void GroupDialog_showPage( ui::Widget page ){
207 if ( GroupDialog_getPage() == page ) {
208 GroupDialog_ToggleShow();
210 #ifdef WORKAROUND_WINDOWS_GTK2_GLWIDGET
211 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
212 /* this is very ugly: cycle to next tab then return to current tab immediately to force the refresh
213 * this fixes the drawing of texture tab when window is restored and current tab is texture tab
214 * this is called for nothing when windows is minimized and called for nothing when current tab
215 * is not texture tab, hopefully it's a workaround that would disappear with gtk 3 */
217 GroupDialog_setPage( page );
218 #endif // WORKAROUND_WINDOWS_GTK2_GLWIDGET
223 g_GroupDlg.m_window.show();
224 GroupDialog_setPage( page );
227 workaround_macos_show_hide();
230 void GroupDialog_updatePageTitle( ui::Widget page ){
231 if ( GroupDialog_getPage() == page ) {
232 GroupDialog_updatePageTitle( g_GroupDlg.m_window, g_current_page );
236 #include "preferencesystem.h"
238 void GroupDialog_Construct(){
239 GlobalPreferenceSystem().registerPreference( "EntityWnd", make_property<WindowPositionTracker_String>( g_GroupDlg.m_position_tracker ) );
241 GlobalCommands_insert( "ViewEntityInfo", makeCallbackF(GroupDialog_ToggleShow), Accelerator( 'N' ) );
243 void GroupDialog_Destroy(){