]> git.saurik.com Git - wxWidgets.git/blob - src/common/sizer.cpp
541fcf3fb2b1161e6998971a5c19173378c39ad5
[wxWidgets.git] / src / common / sizer.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: sizer.cpp
3 // Purpose: provide wxSizer class for layounting
4 // Author: Robert Roebling and Robin Dunn
5 // Modified by:
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: (c) Robin Dunn, Dirk Holtwick and Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __WXSIZERS_H__
13 #define __WXSIZERS_H__
14
15 #ifdef __GNUG__
16 #pragma interface "sizers.h"
17 #endif
18
19 #include "wx/sizer.h"
20
21
22 //---------------------------------------------------------------------------
23 // wxSizerItem
24 //---------------------------------------------------------------------------
25
26 wxSizerItem::wxSizerItem( int width, int height, int option )
27 {
28 m_window = (wxWindow *) NULL;
29 m_sizer = (wxSizer *) NULL;
30 m_minSize.x = width;
31 m_minSize.h = height;
32 m_option = option;
33 }
34
35 wxSizerItem::wxSizerItem( wxWindow *window, int option )
36 {
37 m_window = window;
38 m_sizer = (wxSizer *) NULL;
39 m_minSize = window->GetSize();
40 m_option = option;
41 }
42
43 wxSizerItem::wxSizerItem( wxSizer *sizer, int option )
44 {
45 m_window = (wxWindow *) NULL;
46 m_sizer = sizer;
47 m_minSize.x = -1;
48 m_minSize.h = -1;
49 m_option = option;
50 }
51
52 wxSize wxSizerItem::GetMinSize()
53 {
54 if (IsSizer())
55 return m_sizer->GetMinSize();
56 else
57 return m_minSize;
58 }
59
60 bool wxSizerItem::IsWindow()
61 {
62 return (m_window != NULL);
63 }
64
65 bool wxSizerItem::IsSizer()
66 {
67 return (m_sizer != NULL);
68 }
69
70 bool wxSizerItem::IsSpacer()
71 {
72 return (m_window == NULL) && (m_sizer == NULL);
73 }
74
75 //---------------------------------------------------------------------------
76 // wxSizer
77 //---------------------------------------------------------------------------
78
79 wxSizer::wxSizer()
80 {
81 m_children.DeleteContents( TRUE );
82 }
83
84 wxSizer::~wxSizer()
85 {
86 }
87
88 void wxSizer::Add( wxWindow *window, int option )
89 {
90 m_children.Append( new wxSizerItem( window, option ) );
91 }
92
93 void wxSizer::Add( wxSizer *sizer, int option )
94 {
95 m_children.Append( new wxSizerItem( sizer, option ) );
96 }
97
98 void wxSizer::Add( int width, int height, int option )
99 {
100 m_children.Append( new wxSizerItem( width, height, option ) );
101 }
102
103 void wxSizer::Fit( wxWindow *window );
104 {
105 window->SetSize( GetMinWindowSize( window ) );
106 }
107
108 void wxSizer::SetSizeHints( wxWindow *window );
109 {
110 wxSize size( GetMinWindowSize( window ) );
111 window->SetSizeHints( size.x, size.y );
112 }
113
114 wxSize wxSizer::GetMinWindowSize( wxWindow *window )
115 {
116 wxSize min( GetMinSize() );
117 wxSize size( window->GetSize() );
118 wxSize client_size( window->GetClientSize() );
119 return wxSize( min.x+size.x-client_size.x, min.y+size.y-client_size.y );
120 }
121
122 void wxSizer::DoSetDimension( int x, int y, int width, int height )
123 {
124 m_position.x = x;
125 m_position.y = y;
126 m_size.x = width;
127 m_size.y = height;
128 RecalcSizes();
129 }
130
131 #endif
132 // __SIZERS_H__