2 Copyright (C) 2001-2006, William Joseph.
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
22 #if !defined( INCLUDED_GTKUTIL_WINDOW_H )
23 #define INCLUDED_GTKUTIL_WINDOW_H
26 #include <uilib/uilib.h>
28 #include "debugging/debugging.h"
29 #include "generic/callback.h"
32 inline gboolean window_focus_in_clear_focus_widget( GtkWidget* widget, GdkEventKey* event, gpointer data ){
33 gtk_window_set_focus( GTK_WINDOW( widget ), NULL );
37 inline guint window_connect_focus_in_clear_focus_widget( ui::Window window ){
38 return g_signal_connect( G_OBJECT( window ), "focus_in_event", G_CALLBACK( window_focus_in_clear_focus_widget ), NULL );
42 unsigned int connect_floating( ui::Window main_window, ui::Window floating );
43 ui::Window create_floating_window( const char* title, ui::Window parent );
44 void destroy_floating_window( ui::Window window );
46 ui::Window create_persistent_floating_window( const char* title, ui::Window main_window );
47 gboolean persistent_floating_window_delete( ui::Window floating, GdkEvent *event, ui::Window main_window );
49 void window_remove_minmax( ui::Window window );
51 typedef struct _GtkScrolledWindow GtkScrolledWindow;
52 GtkScrolledWindow* create_scrolled_window( GtkPolicyType hscrollbar_policy, GtkPolicyType vscrollbar_policy, int border = 0 );
61 WindowPosition( int _x, int _y, int _w, int _h )
62 : x( _x ), y( _y ), w( _w ), h( _h ){
66 const WindowPosition c_default_window_pos( 50, 25, 400, 300 );
68 inline void window_get_position( ui::Window window, WindowPosition& position ){
69 ASSERT_MESSAGE( window , "error saving window position" );
71 gtk_window_get_position( window, &position.x, &position.y );
72 gtk_window_get_size( window, &position.w, &position.h );
75 inline void window_set_position( ui::Window window, const WindowPosition& position ){
76 gtk_window_set_gravity( window, GDK_GRAVITY_STATIC );
78 GdkScreen* screen = gdk_screen_get_default();
81 || position.x > gdk_screen_get_width( screen )
82 || position.y > gdk_screen_get_height( screen ) ) {
83 gtk_window_set_position( window, GTK_WIN_POS_CENTER_ON_PARENT );
87 gtk_window_move( window, position.x, position.y );
90 gtk_window_set_default_size( window, position.w, position.h );
93 inline void WindowPosition_Parse( WindowPosition& position, const char* value ){
94 if ( sscanf( value, "%d %d %d %d", &position.x, &position.y, &position.w, &position.h ) != 4 ) {
95 position = WindowPosition( c_default_window_pos ); // ensure sane default value for window position
98 typedef ReferenceCaller1<WindowPosition, const char*, WindowPosition_Parse> WindowPositionImportStringCaller;
100 inline void WindowPosition_Write( const WindowPosition& position, const StringImportCallback& importCallback ){
102 sprintf( buffer, "%d %d %d %d", position.x, position.y, position.w, position.h );
103 importCallback( buffer );
105 typedef ConstReferenceCaller1<WindowPosition, const StringImportCallback&, WindowPosition_Write> WindowPositionExportStringCaller;
109 class WindowPositionTracker
111 WindowPosition m_position;
113 static gboolean configure( GtkWidget* widget, GdkEventConfigure *event, WindowPositionTracker* self ){
114 self->m_position = WindowPosition( event->x, event->y, event->width, event->height );
119 WindowPositionTracker()
120 : m_position( c_default_window_pos ){
123 void sync( ui::Window window ){
124 window_set_position( window, m_position );
127 void connect( ui::Window window ){
129 g_signal_connect( G_OBJECT( window ), "configure_event", G_CALLBACK( configure ), this );
132 const WindowPosition& getPosition() const {
137 void setPosition( const WindowPosition& position ){
138 m_position = position;
143 inline void WindowPositionTracker_importString( WindowPositionTracker& self, const char* value ){
144 WindowPosition position;
145 WindowPosition_Parse( position, value );
146 self.setPosition( position );
148 typedef ReferenceCaller1<WindowPositionTracker, const char*, WindowPositionTracker_importString> WindowPositionTrackerImportStringCaller;
150 inline void WindowPositionTracker_exportString( const WindowPositionTracker& self, const StringImportCallback& importer ){
151 WindowPosition_Write( self.getPosition(), importer );
153 typedef ConstReferenceCaller1<WindowPositionTracker, const StringImportCallback&, WindowPositionTracker_exportString> WindowPositionTrackerExportStringCaller;