| 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 | #include "frame.h" |
| 24 | |
| 25 | gboolean hpaned_allocate(ui::Widget widget, GtkAllocation* allocation, PanedState* paned ){ |
| 26 | if ( paned->size != allocation->width ) { |
| 27 | paned->size = allocation->width; |
| 28 | gtk_paned_set_position( GTK_PANED( widget ), static_cast<int>( paned->size * paned->position ) ); |
| 29 | } |
| 30 | return FALSE; |
| 31 | } |
| 32 | |
| 33 | gboolean vpaned_allocate(ui::Widget widget, GtkAllocation* allocation, PanedState* paned ){ |
| 34 | if ( paned->size != allocation->height ) { |
| 35 | paned->size = allocation->height; |
| 36 | gtk_paned_set_position( GTK_PANED( widget ), static_cast<int>( paned->size * paned->position ) ); |
| 37 | } |
| 38 | return FALSE; |
| 39 | } |
| 40 | |
| 41 | gboolean paned_position(ui::Widget widget, gpointer dummy, PanedState* paned ){ |
| 42 | if ( paned->size != -1 ) { |
| 43 | paned->position = gtk_paned_get_position( GTK_PANED( widget ) ) / static_cast<float>( paned->size ); |
| 44 | } |
| 45 | return FALSE; |
| 46 | } |
| 47 | |
| 48 | PanedState g_hpaned = { 0.5f, -1, }; |
| 49 | PanedState g_vpaned1 = { 0.5f, -1, }; |
| 50 | PanedState g_vpaned2 = { 0.5f, -1, }; |
| 51 | |
| 52 | ui::Widget create_split_views( ui::Widget topleft, ui::Widget topright, ui::Widget botleft, ui::Widget botright, ui::Widget& vsplit1, ui::Widget& vsplit2 ){ |
| 53 | auto hsplit = ui::HPaned(ui::New); |
| 54 | hsplit.show(); |
| 55 | |
| 56 | hsplit.connect( "size_allocate", G_CALLBACK( hpaned_allocate ), &g_hpaned ); |
| 57 | hsplit.connect( "notify::position", G_CALLBACK( paned_position ), &g_hpaned ); |
| 58 | |
| 59 | { |
| 60 | auto vsplit = ui::VPaned(ui::New); |
| 61 | vsplit1 = vsplit; |
| 62 | gtk_paned_pack1( GTK_PANED( hsplit ), GTK_WIDGET( vsplit ), TRUE, TRUE ); |
| 63 | gtk_widget_show( GTK_WIDGET( vsplit ) ); |
| 64 | |
| 65 | vsplit.connect( "size_allocate", G_CALLBACK( vpaned_allocate ), &g_vpaned1 ); |
| 66 | vsplit.connect( "notify::position", G_CALLBACK( paned_position ), &g_vpaned1 ); |
| 67 | |
| 68 | gtk_paned_pack1( GTK_PANED( vsplit ), GTK_WIDGET( create_framed_widget( topleft ) ), TRUE, TRUE ); |
| 69 | gtk_paned_pack2( GTK_PANED( vsplit ), GTK_WIDGET( create_framed_widget( botleft ) ), TRUE, TRUE ); |
| 70 | } |
| 71 | { |
| 72 | auto vsplit = ui::VPaned(ui::New); |
| 73 | vsplit2 = vsplit; |
| 74 | gtk_paned_pack2( GTK_PANED( hsplit ), GTK_WIDGET( vsplit ), TRUE, TRUE ); |
| 75 | gtk_widget_show( GTK_WIDGET( vsplit ) ); |
| 76 | |
| 77 | vsplit.connect( "size_allocate", G_CALLBACK( vpaned_allocate ), &g_vpaned2 ); |
| 78 | vsplit.connect( "notify::position", G_CALLBACK( paned_position ), &g_vpaned2 ); |
| 79 | |
| 80 | gtk_paned_pack1( GTK_PANED( vsplit ), GTK_WIDGET( create_framed_widget( topright ) ), TRUE, TRUE ); |
| 81 | gtk_paned_pack2( GTK_PANED( vsplit ), GTK_WIDGET( create_framed_widget( botright ) ), TRUE, TRUE ); |
| 82 | } |
| 83 | return hsplit; |
| 84 | } |