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"
31 #include "debugging/debugging.h"
35 #include "gtkutil/widget.h"
36 #include "gtkutil/accelerator.h"
37 #include "entityinspector.h"
44 #include "gtkutil/window.h"
49 ui::Widget m_pNotebook;
53 void Create( ui::Window parent );
56 // 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
57 m_position_tracker.sync( m_window );
58 gtk_widget_show( GTK_WIDGET( m_window ) );
61 gtk_widget_hide( GTK_WIDGET( m_window ) );
64 WindowPositionTracker m_position_tracker;
71 std::size_t g_current_page;
72 std::vector<StringExportCallback> g_pages;
75 void GroupDialog_updatePageTitle( ui::Window window, std::size_t pageIndex ){
76 if ( pageIndex < g_pages.size() ) {
77 g_pages[pageIndex]( PointerCaller1<GtkWindow, const char*, gtk_window_set_title>( window ) );
81 static gboolean switch_page( GtkNotebook *notebook, gpointer page, guint page_num, gpointer data ){
82 GroupDialog_updatePageTitle( ui::Window(GTK_WINDOW( data )), page_num );
83 g_current_page = page_num;
88 GroupDlg::GroupDlg() : m_window( 0 ){
89 m_position_tracker.setPosition( c_default_window_pos );
92 void GroupDlg::Create( ui::Window parent ){
93 ASSERT_MESSAGE( !m_window, "dialog already created" );
95 ui::Window window = ui::Window(create_persistent_floating_window( "Entities", parent ));
97 global_accel_connect_window( window );
99 window_connect_focus_in_clear_focus_widget( window );
104 if ( g_multimon_globals.m_bStartOnPrimMon ) {
105 WindowPosition pos( m_position_tracker.getPosition() );
106 PositionWindowOnPrimaryScreen( pos );
107 m_position_tracker.setPosition( pos );
110 m_position_tracker.connect( window );
113 ui::Widget notebook = ui::Widget(gtk_notebook_new());
114 gtk_widget_show( notebook );
115 gtk_container_add( GTK_CONTAINER( window ), notebook );
116 gtk_notebook_set_tab_pos( GTK_NOTEBOOK( notebook ), GTK_POS_BOTTOM );
117 m_pNotebook = notebook;
119 g_signal_connect( G_OBJECT(notebook), "switch_page", G_CALLBACK( switch_page ), (gpointer) window );
124 ui::Widget GroupDialog_addPage( const char* tabLabel, ui::Widget widget, const StringExportCallback& title ){
125 ui::Widget w = ui::Label( tabLabel );
126 gtk_widget_show( w );
127 ui::Widget page = ui::Widget(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gtk_notebook_insert_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), widget, w, -1 ) ));
128 g_pages.push_back( title );
134 bool GroupDialog_isShown(){
135 return widget_is_visible( g_GroupDlg.m_window );
137 void GroupDialog_setShown( bool shown ){
138 shown ? g_GroupDlg.Show() : g_GroupDlg.Hide();
140 void GroupDialog_ToggleShow(){
141 GroupDialog_setShown( !GroupDialog_isShown() );
144 void GroupDialog_constructWindow( ui::Window main_window ){
145 g_GroupDlg.Create( main_window );
147 void GroupDialog_destroyWindow(){
148 ASSERT_TRUE( g_GroupDlg.m_window );
149 destroy_floating_window( g_GroupDlg.m_window );
150 g_GroupDlg.m_window = ui::Window();
154 ui::Window GroupDialog_getWindow(){
155 return ui::Window(g_GroupDlg.m_window);
157 void GroupDialog_show(){
161 ui::Widget GroupDialog_getPage(){
162 return ui::Widget(gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) ));
165 void GroupDialog_setPage( ui::Widget page ){
166 g_current_page = gtk_notebook_page_num( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), page );
167 gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
170 void GroupDialog_showPage( ui::Widget page ){
171 if ( GroupDialog_getPage() == page ) {
172 GroupDialog_ToggleShow();
176 gtk_widget_show( GTK_WIDGET( g_GroupDlg.m_window ) );
177 GroupDialog_setPage( page );
181 void GroupDialog_cycle(){
182 g_current_page = ( g_current_page + 1 ) % g_pages.size();
183 gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
186 void GroupDialog_updatePageTitle( ui::Widget page ){
187 if ( GroupDialog_getPage() == page ) {
188 GroupDialog_updatePageTitle( g_GroupDlg.m_window, g_current_page );
193 #include "preferencesystem.h"
195 void GroupDialog_Construct(){
196 GlobalPreferenceSystem().registerPreference( "EntityWnd", WindowPositionTrackerImportStringCaller( g_GroupDlg.m_position_tracker ), WindowPositionTrackerExportStringCaller( g_GroupDlg.m_position_tracker ) );
198 GlobalCommands_insert( "ViewEntityInfo", FreeCaller<GroupDialog_ToggleShow>(), Accelerator( 'N' ) );
200 void GroupDialog_Destroy(){