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 <gtk/gtknotebook.h>
36 #include <gtk/gtktextview.h>
37 #include <gtk/gtklabel.h>
38 #include <gtk/gtkscrolledwindow.h>
40 #include "gtkutil/widget.h"
41 #include "gtkutil/accelerator.h"
42 #include "entityinspector.h"
49 #include <gtk/gtkwidget.h>
50 #include "gtkutil/window.h"
55 GtkWidget* m_pNotebook;
59 void Create( GtkWindow* parent );
62 // 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
63 m_position_tracker.sync( m_window );
64 gtk_widget_show( GTK_WIDGET( m_window ) );
67 gtk_widget_hide( GTK_WIDGET( m_window ) );
70 WindowPositionTracker m_position_tracker;
77 std::size_t g_current_page;
78 std::vector<StringExportCallback> g_pages;
81 void GroupDialog_updatePageTitle( GtkWindow* window, std::size_t pageIndex ){
82 if ( pageIndex < g_pages.size() ) {
83 g_pages[pageIndex]( PointerCaller1<GtkWindow, const char*, gtk_window_set_title>( window ) );
87 static gboolean switch_page( GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer data ){
88 GroupDialog_updatePageTitle( GTK_WINDOW( data ), page_num );
89 g_current_page = page_num;
94 GroupDlg::GroupDlg() : m_window( 0 ){
95 m_position_tracker.setPosition( c_default_window_pos );
98 void GroupDlg::Create( GtkWindow* parent ){
99 ASSERT_MESSAGE( m_window == 0, "dialog already created" );
101 GtkWindow* window = create_persistent_floating_window( "Entities", parent );
103 global_accel_connect_window( window );
105 window_connect_focus_in_clear_focus_widget( window );
110 if ( g_multimon_globals.m_bStartOnPrimMon ) {
111 WindowPosition pos( m_position_tracker.getPosition() );
112 PositionWindowOnPrimaryScreen( pos );
113 m_position_tracker.setPosition( pos );
116 m_position_tracker.connect( window );
119 GtkWidget* notebook = gtk_notebook_new();
120 gtk_widget_show( notebook );
121 gtk_container_add( GTK_CONTAINER( window ), notebook );
122 gtk_notebook_set_tab_pos( GTK_NOTEBOOK( notebook ), GTK_POS_BOTTOM );
123 m_pNotebook = notebook;
125 g_signal_connect( G_OBJECT( notebook ), "switch_page", G_CALLBACK( switch_page ), window );
130 GtkWidget* GroupDialog_addPage( const char* tabLabel, GtkWidget* widget, const StringExportCallback& title ){
131 GtkWidget* w = gtk_label_new( tabLabel );
132 gtk_widget_show( w );
133 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 ) );
134 g_pages.push_back( title );
140 bool GroupDialog_isShown(){
141 return widget_is_visible( GTK_WIDGET( g_GroupDlg.m_window ) );
143 void GroupDialog_setShown( bool shown ){
144 shown ? g_GroupDlg.Show() : g_GroupDlg.Hide();
146 void GroupDialog_ToggleShow(){
147 GroupDialog_setShown( !GroupDialog_isShown() );
150 void GroupDialog_constructWindow( GtkWindow* main_window ){
151 g_GroupDlg.Create( main_window );
153 void GroupDialog_destroyWindow(){
154 ASSERT_NOTNULL( g_GroupDlg.m_window );
155 destroy_floating_window( g_GroupDlg.m_window );
156 g_GroupDlg.m_window = 0;
160 GtkWindow* GroupDialog_getWindow(){
161 return g_GroupDlg.m_window;
163 void GroupDialog_show(){
167 GtkWidget* GroupDialog_getPage(){
168 return gtk_notebook_get_nth_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
171 void GroupDialog_setPage( GtkWidget* page ){
172 g_current_page = gtk_notebook_page_num( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), page );
173 gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
176 void GroupDialog_showPage( GtkWidget* page ){
177 if ( GroupDialog_getPage() == page ) {
178 GroupDialog_ToggleShow();
182 gtk_widget_show( GTK_WIDGET( g_GroupDlg.m_window ) );
183 GroupDialog_setPage( page );
187 void GroupDialog_cycle(){
188 g_current_page = ( g_current_page + 1 ) % g_pages.size();
189 gtk_notebook_set_current_page( GTK_NOTEBOOK( g_GroupDlg.m_pNotebook ), gint( g_current_page ) );
192 void GroupDialog_updatePageTitle( GtkWidget* page ){
193 if ( GroupDialog_getPage() == page ) {
194 GroupDialog_updatePageTitle( g_GroupDlg.m_window, g_current_page );
199 #include "preferencesystem.h"
201 void GroupDialog_Construct(){
202 GlobalPreferenceSystem().registerPreference( "EntityWnd", WindowPositionTrackerImportStringCaller( g_GroupDlg.m_position_tracker ), WindowPositionTrackerExportStringCaller( g_GroupDlg.m_position_tracker ) );
204 GlobalCommands_insert( "ViewEntityInfo", FreeCaller<GroupDialog_ToggleShow>(), Accelerator( 'N' ) );
206 void GroupDialog_Destroy(){