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"
46 #include "gtkutil/window.h"
51 ui::Widget m_pNotebook{ui::null};
52 ui::Window m_window{ui::null};
55 void Create( ui::Window parent );
58 // 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
59 m_position_tracker.sync( m_window );
60 /* workaround for gtk 2.24 issue: not displayed glwidget after toggle */
61 GtkWidget* glwidget = GTK_WIDGET( g_object_get_data( G_OBJECT( m_window ), "glwidget" ) );
63 //if ( widget_is_visible( glwidget ) )
64 //globalOutputStream() << "glwidget have been already visible :0\n"; /* is not hidden aswell, according to this */
65 gtk_widget_hide( glwidget );
66 gtk_widget_show( glwidget );
74 WindowPositionTracker m_position_tracker;
81 std::size_t g_current_page;
82 std::vector<Callback<void(const Callback<void(const char *)> &)>> g_pages;
85 void GroupDialog_updatePageTitle( ui::Window window, std::size_t pageIndex ){
86 if ( pageIndex < g_pages.size() ) {
87 g_pages[pageIndex]( PointerCaller<GtkWindow, void(const char*), gtk_window_set_title>( window ) );
91 static gboolean switch_page( GtkNotebook *notebook, gpointer page, guint page_num, gpointer data ){
92 GroupDialog_updatePageTitle( ui::Window::from(data), page_num );
93 g_current_page = page_num;
98 GroupDlg::GroupDlg() : m_window( ui::null ){
99 m_position_tracker.setPosition( c_default_window_pos );
102 void GroupDlg::Create( ui::Window parent ){
103 ASSERT_MESSAGE( !m_window, "dialog already created" );
105 auto window = ui::Window(create_persistent_floating_window( "Entities", parent ));
107 global_accel_connect_window( window );
109 window_connect_focus_in_clear_focus_widget( window );
114 if ( g_multimon_globals.m_bStartOnPrimMon ) {
115 WindowPosition pos( m_position_tracker.getPosition() );
116 PositionWindowOnPrimaryScreen( pos );
117 m_position_tracker.setPosition( pos );
120 m_position_tracker.connect( window );
123 ui::Widget notebook = ui::Widget::from(gtk_notebook_new());
125 window.add(notebook);
126 gtk_notebook_set_tab_pos( GTK_NOTEBOOK( notebook ), GTK_POS_BOTTOM );
127 m_pNotebook = notebook;
129 notebook.connect( "switch_page", G_CALLBACK( switch_page ), (gpointer) window );
134 ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const Callback<void(const Callback<void(const char *)> &)>& title ){
135 ui::Widget w = ui::Label( tabLabel );
137 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 ) ));
138 g_pages.push_back( title );
144 bool GroupDialog_isShown(){
145 return g_GroupDlg.m_window.visible();
147 void GroupDialog_setShown( bool shown ){
148 shown ? g_GroupDlg.Show() : g_GroupDlg.Hide();
150 void GroupDialog_ToggleShow(){
151 GroupDialog_setShown( !GroupDialog_isShown() );
154 void GroupDialog_constructWindow( ui::Window main_window ){
155 g_GroupDlg.Create( main_window );
157 void GroupDialog_destroyWindow(){
158 ASSERT_TRUE( g_GroupDlg.m_window );
159 destroy_floating_window( g_GroupDlg.m_window );
160 g_GroupDlg.m_window = ui::Window{ui::null};
164 ui::Window GroupDialog_getWindow(){
165 return ui::Window(g_GroupDlg.m_window);
167 void GroupDialog_show(){
171 ui::Widget GroupDialog_getPage(){
172 return ui::Widget::from(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) ));
175 void GroupDialog_setPage( ui::Widget page ){
176 g_current_page = gtk_notebook_page_num( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), page );
177 gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
180 void GroupDialog_showPage( ui::Widget page ){
181 if ( GroupDialog_getPage() == page ) {
182 GroupDialog_ToggleShow();
186 g_GroupDlg.m_window.show();
187 GroupDialog_setPage( page );
191 void GroupDialog_cycle(){
192 g_current_page = ( g_current_page + 1 ) % g_pages.size();
193 gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
196 void GroupDialog_updatePageTitle( ui::Widget page ){
197 if ( GroupDialog_getPage() == page ) {
198 GroupDialog_updatePageTitle( g_GroupDlg.m_window, g_current_page );
203 #include "preferencesystem.h"
205 void GroupDialog_Construct(){
206 GlobalPreferenceSystem().registerPreference( "EntityWnd", make_property<WindowPositionTracker_String>( g_GroupDlg.m_position_tracker ) );
208 GlobalCommands_insert( "ViewEntityInfo", makeCallbackF(GroupDialog_ToggleShow), Accelerator( 'N' ) );
210 void GroupDialog_Destroy(){