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
24 #include <gtk/gtkscrolledwindow.h>
27 #include "accelerator.h"
29 inline void CHECK_RESTORE( GtkWidget* w ){
30 if ( gpointer_to_int( g_object_get_data( G_OBJECT( w ), "was_mapped" ) ) != 0 ) {
32 /* workaround for gtk 2.24 issue: not displayed glwidget after min/restore */
33 GtkWidget* glwidget = GTK_WIDGET( g_object_get_data( G_OBJECT( w ), "glwidget" ) );
35 gtk_widget_hide( glwidget );
36 gtk_widget_show( glwidget );
41 inline void CHECK_MINIMIZE( GtkWidget* w ){
42 g_object_set_data( G_OBJECT( w ), "was_mapped", gint_to_pointer( GTK_WIDGET_VISIBLE( w ) ) );
43 //gtk_widget_hide( w ); //fix for gtk 2.24 + the whole scheme isn't needed with gtk 2.16, 2.24; they do it all alone
46 static gboolean main_window_iconified( GtkWidget* widget, GdkEventWindowState* event, gpointer data ){
47 if ( ( event->changed_mask & ( GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_WITHDRAWN ) ) != 0 ) {
48 if ( ( event->new_window_state & ( GDK_WINDOW_STATE_ICONIFIED | GDK_WINDOW_STATE_WITHDRAWN ) ) != 0 ) {
49 CHECK_MINIMIZE( GTK_WIDGET( data ) );
53 CHECK_RESTORE( GTK_WIDGET( data ) );
59 unsigned int connect_floating( GtkWindow* main_window, GtkWindow* floating ){
60 return g_signal_connect( G_OBJECT( main_window ), "window_state_event", G_CALLBACK( main_window_iconified ), floating );
63 gboolean destroy_disconnect_floating( GtkWindow* widget, gpointer data ){
64 g_signal_handler_disconnect( G_OBJECT( data ), gpointer_to_int( g_object_get_data( G_OBJECT( widget ), "floating_handler" ) ) );
68 gboolean floating_window_delete_present( GtkWindow* floating, GdkEventFocus *event, GtkWindow* main_window ){
69 if ( gtk_window_is_active( floating ) || gtk_window_is_active( main_window ) ) {
70 gtk_window_present( main_window );
75 guint connect_floating_window_delete_present( GtkWindow* floating, GtkWindow* main_window ){
76 return g_signal_connect( G_OBJECT( floating ), "delete_event", G_CALLBACK( floating_window_delete_present ), main_window );
79 gboolean floating_window_destroy_present( GtkWindow* floating, GtkWindow* main_window ){
80 if ( gtk_window_is_active( floating ) || gtk_window_is_active( main_window ) ) {
81 gtk_window_present( main_window );
86 guint connect_floating_window_destroy_present( GtkWindow* floating, GtkWindow* main_window ){
87 return g_signal_connect( G_OBJECT( floating ), "destroy", G_CALLBACK( floating_window_destroy_present ), main_window );
90 GtkWindow* create_floating_window( const char* title, GtkWindow* parent ){
91 GtkWindow* window = GTK_WINDOW( gtk_window_new( GTK_WINDOW_TOPLEVEL ) );
92 gtk_window_set_title( window, title );
95 gtk_window_set_transient_for( window, parent );
96 connect_floating_window_destroy_present( window, parent );
97 g_object_set_data( G_OBJECT( window ), "floating_handler", gint_to_pointer( connect_floating( parent, window ) ) );
98 g_signal_connect( G_OBJECT( window ), "destroy", G_CALLBACK( destroy_disconnect_floating ), parent );
100 //gtk_window_set_type_hint (window,GDK_WINDOW_TYPE_HINT_UTILITY);
101 //gtk_window_set_type_hint (window,GDK_WINDOW_TYPE_HINT_DIALOG);
102 gtk_window_set_keep_above ( window, TRUE );
103 GtkWidget* widget = GTK_WIDGET( window );
104 gtk_widget_realize ( widget );
105 GdkWindow* gdk_window = gtk_widget_get_window( widget );
106 //gdk_window_set_decorations ( gdk_window, (GdkWMDecoration)(GDK_DECOR_BORDER|GDK_DECOR_RESIZEH|GDK_DECOR_TITLE|GDK_DECOR_MENU|GDK_DECOR_MINIMIZE|GDK_DECOR_MAXIMIZE) );
107 //gdk_window_set_functions ( gdk_window, (GdkWMFunction)( GDK_FUNC_RESIZE|GDK_FUNC_MOVE|GDK_FUNC_MINIMIZE|GDK_FUNC_MAXIMIZE|GDK_FUNC_CLOSE ) );
108 //gdk_window_set_decorations ( gdk_window, (GdkWMDecoration)( GDK_DECOR_ALL ) );
109 //gdk_window_set_functions ( gdk_window, (GdkWMFunction)( GDK_FUNC_ALL ) );
110 //gdk_window_set_type_hint ( gdk_window, GDK_WINDOW_TYPE_HINT_DIALOG );
111 //gdk_window_set_type_hint ( gdk_window, GDK_WINDOW_TYPE_HINT_UTILITY );
112 //gdk_window_set_type_hint ( gdk_window, GDK_WINDOW_TYPE_HINT_NORMAL );
113 gdk_window_set_skip_taskbar_hint ( gdk_window, TRUE );
114 gdk_window_set_skip_pager_hint ( gdk_window, TRUE );
121 void destroy_floating_window( GtkWindow* window ){
122 gtk_widget_destroy( GTK_WIDGET( window ) );
125 gint window_realize_remove_sysmenu( GtkWidget* widget, gpointer data ){
126 gdk_window_set_decorations( widget->window, (GdkWMDecoration)( GDK_DECOR_ALL | GDK_DECOR_MENU ) );
130 gboolean persistent_floating_window_delete( GtkWindow* floating, GdkEvent *event, GtkWindow* main_window ){
131 gtk_widget_hide( GTK_WIDGET( floating ) );
135 GtkWindow* create_persistent_floating_window( const char* title, GtkWindow* main_window ){
136 GtkWindow* window = GTK_WINDOW( create_floating_window( title, main_window ) );
138 gtk_widget_set_events( GTK_WIDGET( window ), GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK );
140 connect_floating_window_delete_present( window, main_window );
141 g_signal_connect( G_OBJECT( window ), "delete_event", G_CALLBACK( persistent_floating_window_delete ), 0 );
144 if ( g_multimon_globals.m_bStartOnPrimMon && g_multimon_globals.m_bNoSysMenuPopups ) {
145 g_signal_connect( G_OBJECT( window ), "realize", G_CALLBACK( window_realize_remove_sysmenu ), 0 );
152 gint window_realize_remove_minmax( GtkWidget* widget, gpointer data ){
153 gdk_window_set_decorations( widget->window, (GdkWMDecoration)( GDK_DECOR_ALL | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE ) );
157 void window_remove_minmax( GtkWindow* window ){
158 g_signal_connect( G_OBJECT( window ), "realize", G_CALLBACK( window_realize_remove_minmax ), 0 );
162 GtkScrolledWindow* create_scrolled_window( GtkPolicyType hscrollbar_policy, GtkPolicyType vscrollbar_policy, int border ){
163 GtkScrolledWindow* scr = GTK_SCROLLED_WINDOW( gtk_scrolled_window_new( 0, 0 ) );
164 gtk_widget_show( GTK_WIDGET( scr ) );
165 gtk_scrolled_window_set_policy( scr, hscrollbar_policy, vscrollbar_policy );
166 gtk_scrolled_window_set_shadow_type( scr, GTK_SHADOW_IN );
167 gtk_container_set_border_width( GTK_CONTAINER( scr ), border );