]> git.xonotic.org Git - xonotic/netradiant.git/blob - libs/gtkutil/paned.cpp
Wrap GtkPaned
[xonotic/netradiant.git] / libs / gtkutil / paned.cpp
1 /*
2    Copyright (C) 2001-2006, William Joseph.
3    All Rights Reserved.
4
5    This file is part of GtkRadiant.
6
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.
11
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.
16
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
20  */
21
22 #include "paned.h"
23
24 #include <gtk/gtkhpaned.h>
25 #include <gtk/gtkvpaned.h>
26 #include <uilib/uilib.h>
27
28 #include "frame.h"
29
30
31 class PanedState
32 {
33 public:
34 float position;
35 int size;
36 };
37
38 gboolean hpaned_allocate( GtkWidget* widget, GtkAllocation* allocation, PanedState* paned ){
39         if ( paned->size != allocation->width ) {
40                 paned->size = allocation->width;
41                 gtk_paned_set_position( GTK_PANED( widget ), static_cast<int>( paned->size * paned->position ) );
42         }
43         return FALSE;
44 }
45
46 gboolean vpaned_allocate( GtkWidget* widget, GtkAllocation* allocation, PanedState* paned ){
47         if ( paned->size != allocation->height ) {
48                 paned->size = allocation->height;
49                 gtk_paned_set_position( GTK_PANED( widget ), static_cast<int>( paned->size * paned->position ) );
50         }
51         return FALSE;
52 }
53
54 gboolean paned_position( GtkWidget* widget, gpointer dummy, PanedState* paned ){
55         if ( paned->size != -1 ) {
56                 paned->position = gtk_paned_get_position( GTK_PANED( widget ) ) / static_cast<float>( paned->size );
57         }
58         return FALSE;
59 }
60
61 PanedState g_hpaned = { 0.5f, -1, };
62 PanedState g_vpaned1 = { 0.5f, -1, };
63 PanedState g_vpaned2 = { 0.5f, -1, };
64
65 GtkHPaned* create_split_views( GtkWidget* topleft, GtkWidget* topright, GtkWidget* botleft, GtkWidget* botright ){
66         GtkHPaned* hsplit = ui::HPaned();
67         gtk_widget_show( GTK_WIDGET( hsplit ) );
68
69         g_signal_connect( G_OBJECT( hsplit ), "size_allocate", G_CALLBACK( hpaned_allocate ), &g_hpaned );
70         g_signal_connect( G_OBJECT( hsplit ), "notify::position", G_CALLBACK( paned_position ), &g_hpaned );
71
72         {
73                 GtkVPaned* vsplit = ui::VPaned();
74                 gtk_paned_add1( GTK_PANED( hsplit ), GTK_WIDGET( vsplit ) );
75                 gtk_widget_show( GTK_WIDGET( vsplit ) );
76
77                 g_signal_connect( G_OBJECT( vsplit ), "size_allocate", G_CALLBACK( vpaned_allocate ), &g_vpaned1 );
78                 g_signal_connect( G_OBJECT( vsplit ), "notify::position", G_CALLBACK( paned_position ), &g_vpaned1 );
79
80                 gtk_paned_add1( GTK_PANED( vsplit ), GTK_WIDGET( create_framed_widget( topleft ) ) );
81                 gtk_paned_add2( GTK_PANED( vsplit ), GTK_WIDGET( create_framed_widget( topright ) ) );
82         }
83         {
84                 GtkVPaned* vsplit = ui::VPaned();
85                 gtk_paned_add2( GTK_PANED( hsplit ), GTK_WIDGET( vsplit ) );
86                 gtk_widget_show( GTK_WIDGET( vsplit ) );
87
88                 g_signal_connect( G_OBJECT( vsplit ), "size_allocate", G_CALLBACK( vpaned_allocate ), &g_vpaned2 );
89                 g_signal_connect( G_OBJECT( vsplit ), "notify::position", G_CALLBACK( paned_position ), &g_vpaned2 );
90
91                 gtk_paned_add1( GTK_PANED( vsplit ), GTK_WIDGET( create_framed_widget( botleft ) ) );
92                 gtk_paned_add2( GTK_PANED( vsplit ), GTK_WIDGET( create_framed_widget( botright ) ) );
93         }
94         return hsplit;
95 }