]> git.saurik.com Git - wxWidgets.git/blame - src/generic/collpaneg.cpp
Add GetPageText to MSW IE and to GTK WebKit. Add stub for OSX and document.
[wxWidgets.git] / src / generic / collpaneg.cpp
CommitLineData
3c1f8cb1
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/generic/collpaneg.cpp
3// Purpose: wxGenericCollapsiblePane
4// Author: Francesco Montorsi
5// Modified By:
6// Created: 8/10/2006
7// Id: $Id$
8// Copyright: (c) Francesco Montorsi
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12
13// ----------------------------------------------------------------------------
14// headers
15// ----------------------------------------------------------------------------
16
17// For compilers that support precompilation, includes "wx.h".
18#include "wx/wxprec.h"
b4715d08
VZ
19
20#ifdef __BORLANDC__
21 #pragma hdrstop
22#endif
23
912c3932 24#include "wx/defs.h"
2cbf7014 25
912c3932 26#if wxUSE_COLLPANE && wxUSE_BUTTON && wxUSE_STATLINE
360c6a85 27
912c3932 28#include "wx/collpane.h"
687b91d2 29
2cbf7014 30#ifndef WX_PRECOMP
360c6a85 31 #include "wx/toplevel.h"
2cbf7014 32 #include "wx/button.h"
4ec3100a 33 #include "wx/sizer.h"
42a2ba5e 34 #include "wx/panel.h"
2cbf7014
VZ
35#endif // !WX_PRECOMP
36
3c1f8cb1
VZ
37#include "wx/statline.h"
38
2cbf7014
VZ
39// ----------------------------------------------------------------------------
40// constants
41// ----------------------------------------------------------------------------
42
3c1f8cb1
VZ
43// ============================================================================
44// implementation
45// ============================================================================
46
23318a53 47const char wxCollapsiblePaneNameStr[] = "collapsiblePane";
3c1f8cb1
VZ
48
49//-----------------------------------------------------------------------------
50// wxGenericCollapsiblePane
51//-----------------------------------------------------------------------------
52
9b11752c 53wxDEFINE_EVENT( wxEVT_COMMAND_COLLPANE_CHANGED, wxCollapsiblePaneEvent );
3c1f8cb1
VZ
54IMPLEMENT_DYNAMIC_CLASS(wxGenericCollapsiblePane, wxControl)
55IMPLEMENT_DYNAMIC_CLASS(wxCollapsiblePaneEvent, wxCommandEvent)
56
57BEGIN_EVENT_TABLE(wxGenericCollapsiblePane, wxControl)
2cbf7014 58 EVT_BUTTON(wxID_ANY, wxGenericCollapsiblePane::OnButton)
3c1f8cb1 59 EVT_SIZE(wxGenericCollapsiblePane::OnSize)
68b1c878
VZ
60
61 WX_EVENT_TABLE_CONTROL_CONTAINER(wxGenericCollapsiblePane)
3c1f8cb1
VZ
62END_EVENT_TABLE()
63
68b1c878
VZ
64WX_DELEGATE_TO_CONTROL_CONTAINER(wxGenericCollapsiblePane, wxControl)
65
66void wxGenericCollapsiblePane::Init()
67{
68 WX_INIT_CONTROL_CONTAINER();
69
70 m_pButton = NULL;
71 m_pPane = NULL;
72 m_pStaticLine = NULL;
73 m_sz = NULL;
74}
3c1f8cb1 75
2cbf7014
VZ
76bool wxGenericCollapsiblePane::Create(wxWindow *parent,
77 wxWindowID id,
78 const wxString& label,
79 const wxPoint& pos,
80 const wxSize& size,
81 long style,
82 const wxValidator& val,
83 const wxString& name)
3c1f8cb1
VZ
84{
85 if ( !wxControl::Create(parent, id, pos, size, style, val, name) )
86 return false;
87
88 m_strLabel = label;
89
73b1b996
VZ
90 // sizer containing the expand button and possibly a static line
91 m_sz = new wxBoxSizer(wxHORIZONTAL);
92
96f04e1d 93#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
73b1b996 94 // on Mac we use the special disclosure triangle button
47922888 95 m_pStaticLine = NULL;
73b1b996
VZ
96 m_pButton = new wxDisclosureTriangle(this, wxID_ANY, GetBtnLabel());
97 m_sz->Add(m_pButton);
47922888 98#else
912c3932
VZ
99 // create children and lay them out using a wxBoxSizer
100 // (so that we automatically get RTL features)
2cbf7014 101 m_pButton = new wxButton(this, wxID_ANY, GetBtnLabel(), wxPoint(0, 0),
3c1f8cb1 102 wxDefaultSize, wxBU_EXACTFIT);
912c3932 103 m_pStaticLine = new wxStaticLine(this, wxID_ANY);
73b1b996 104
912c3932 105 // on other platforms we put the static line and the button horizontally
912c3932
VZ
106 m_sz->Add(m_pButton, 0, wxLEFT|wxTOP|wxBOTTOM, GetBorder());
107 m_sz->Add(m_pStaticLine, 1, wxALIGN_CENTER|wxLEFT|wxRIGHT, GetBorder());
108#endif
109
56eebcda
VZ
110 // FIXME: at least under wxCE and wxGTK1 the background is black if we don't do
111 // this, no idea why...
ff654490 112#if defined(__WXWINCE__) || defined(__WXGTK__)
948f4c37
WS
113 SetBackgroundColour(parent->GetBackgroundColour());
114#endif
115
912c3932 116 // do not set sz as our sizers since we handle the pane window without using sizers
037c7b4c 117 m_pPane = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
04443021 118 wxTAB_TRAVERSAL|wxNO_BORDER, wxT("wxCollapsiblePanePane") );
3c1f8cb1
VZ
119
120 // start as collapsed:
121 m_pPane->Hide();
122
3c1f8cb1
VZ
123 return true;
124}
125
912c3932 126wxGenericCollapsiblePane::~wxGenericCollapsiblePane()
3c1f8cb1 127{
47922888 128 if (m_pButton)
912c3932 129 m_pButton->SetContainingSizer(NULL);
23318a53 130
47922888 131 if (m_pStaticLine)
912c3932 132 m_pStaticLine->SetContainingSizer(NULL);
23318a53 133
47922888
RR
134 // our sizer is not deleted automatically since we didn't use SetSizer()!
135 wxDELETE(m_sz);
912c3932
VZ
136}
137
138wxSize wxGenericCollapsiblePane::DoGetBestSize() const
139{
140 // NB: do not use GetSize() but rather GetMinSize()
141 wxSize sz = m_sz->GetMinSize();
3c1f8cb1
VZ
142
143 // when expanded, we need more vertical space
550d433e 144 if ( IsExpanded() )
912c3932
VZ
145 {
146 sz.SetWidth(wxMax( sz.GetWidth(), m_pPane->GetBestSize().x ));
147 sz.SetHeight(sz.y + GetBorder() + m_pPane->GetBestSize().y);
148 }
3c1f8cb1
VZ
149
150 return sz;
151}
152
153wxString wxGenericCollapsiblePane::GetBtnLabel() const
154{
f2412e6a
SC
155 // on mac the triangle indicates the state, no string change
156#ifdef __WXMAC__
157 return m_strLabel;
158#else
550d433e 159 return m_strLabel + (IsCollapsed() ? wxT(" >>") : wxT(" <<"));
f2412e6a 160#endif
3c1f8cb1
VZ
161}
162
4223cec5 163void wxGenericCollapsiblePane::OnStateChange(const wxSize& sz)
3c1f8cb1 164{
3c1f8cb1 165 // minimal size has priority over the best size so set here our min size
fcdb9540 166// SetMinSize(sz);
3c1f8cb1
VZ
167 SetSize(sz);
168
912c3932
VZ
169 if (this->HasFlag(wxCP_NO_TLW_RESIZE))
170 {
4c51a665 171 // the user asked to explicitly handle the resizing itself...
912c3932
VZ
172 return;
173 }
174
175
ed6008f4
VS
176 wxTopLevelWindow *top =
177 wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow);
178 if ( !top )
179 return;
180
181 wxSizer *sizer = top->GetSizer();
182 if ( !sizer )
183 return;
184
185 const wxSize newBestSize = sizer->ComputeFittingClientSize(top);
186 top->SetMinClientSize(newBestSize);
187
188 // we shouldn't attempt to resize a maximized window, whatever happens
189 if ( !top->IsMaximized() )
190 top->SetClientSize(newBestSize);
3c1f8cb1
VZ
191}
192
4223cec5
VZ
193void wxGenericCollapsiblePane::Collapse(bool collapse)
194{
195 // optimization
196 if ( IsCollapsed() == collapse )
197 return;
198
199 // update our state
200 m_pPane->Show(!collapse);
201
202 // update button label
96f04e1d 203#if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__)
f2412e6a 204 m_pButton->SetOpen( !collapse );
47922888 205#else
4223cec5
VZ
206 // NB: this must be done after updating our "state"
207 m_pButton->SetLabel(GetBtnLabel());
47922888
RR
208#endif
209
4223cec5
VZ
210
211 OnStateChange(GetBestSize());
212}
213
3c1f8cb1
VZ
214void wxGenericCollapsiblePane::SetLabel(const wxString &label)
215{
216 m_strLabel = label;
47922888
RR
217#ifdef __WXMAC__
218 m_pButton->SetLabel(GetBtnLabel());
219#else
3c1f8cb1 220 m_pButton->SetLabel(GetBtnLabel());
170acdc9 221 m_pButton->SetInitialSize();
47922888 222#endif
3c1f8cb1 223
912c3932 224 Layout();
3c1f8cb1
VZ
225}
226
912c3932 227bool wxGenericCollapsiblePane::Layout()
3c1f8cb1 228{
47922888
RR
229#ifdef __WXMAC__
230 if (!m_pButton || !m_pPane || !m_sz)
231 return false; // we need to complete the creation first!
232#else
912c3932
VZ
233 if (!m_pButton || !m_pStaticLine || !m_pPane || !m_sz)
234 return false; // we need to complete the creation first!
47922888 235#endif
912c3932
VZ
236
237 wxSize oursz(GetSize());
3c1f8cb1 238
912c3932
VZ
239 // move & resize the button and the static line
240 m_sz->SetDimension(0, 0, oursz.GetWidth(), m_sz->GetMinSize().GetHeight());
241 m_sz->Layout();
3c1f8cb1 242
912c3932
VZ
243 if ( IsExpanded() )
244 {
245 // move & resize the container window
246 int yoffset = m_sz->GetSize().GetHeight() + GetBorder();
247 m_pPane->SetSize(0, yoffset,
248 oursz.x, oursz.y - yoffset);
249
250 // this is very important to make the pane window layout show correctly
251 m_pPane->Layout();
252 }
3c1f8cb1 253
912c3932
VZ
254 return true;
255}
256
257int wxGenericCollapsiblePane::GetBorder() const
258{
259#if defined( __WXMAC__ )
260 return 6;
912c3932
VZ
261#elif defined(__WXMSW__)
262 wxASSERT(m_pButton);
263 return m_pButton->ConvertDialogToPixels(wxSize(2, 0)).x;
264#else
265 return 5;
266#endif
3c1f8cb1
VZ
267}
268
269
270
271//-----------------------------------------------------------------------------
272// wxGenericCollapsiblePane - event handlers
273//-----------------------------------------------------------------------------
274
2cbf7014 275void wxGenericCollapsiblePane::OnButton(wxCommandEvent& event)
3c1f8cb1 276{
2cbf7014
VZ
277 if ( event.GetEventObject() != m_pButton )
278 {
279 event.Skip();
280 return;
281 }
282
3c1f8cb1
VZ
283 Collapse(!IsCollapsed());
284
285 // this change was generated by the user - send the event
286 wxCollapsiblePaneEvent ev(this, GetId(), IsCollapsed());
287 GetEventHandler()->ProcessEvent(ev);
288}
289
290void wxGenericCollapsiblePane::OnSize(wxSizeEvent& WXUNUSED(event))
291{
292#if 0 // for debug only
293 wxClientDC dc(this);
294 dc.SetPen(*wxBLACK_PEN);
295 dc.SetBrush(*wxTRANSPARENT_BRUSH);
296 dc.DrawRectangle(wxPoint(0,0), GetSize());
297 dc.SetPen(*wxRED_PEN);
298 dc.DrawRectangle(wxPoint(0,0), GetBestSize());
299#endif
300
912c3932 301 Layout();
3c1f8cb1 302}
687b91d2 303
912c3932 304#endif // wxUSE_COLLPANE && wxUSE_BUTTON && wxUSE_STATLINE