]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/gizmos/dynsash/dynsash.cpp
Assert correction.
[wxWidgets.git] / contrib / samples / gizmos / dynsash / dynsash.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dynsash.cpp
3 // Purpose: Test the wxDynamicSash class by creating a dynamic sash which
4 // contains an HTML view
5 // Author: Matt Kimball
6 // Modified by:
7 // Created: 7/15/2001
8 // RCS-ID: $Id$
9 // Copyright: (c) 2001 Matt Kimball
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
12
13 // For compilers that support precompilation, includes "wx/wx.h".
14 #include "wx/wxprec.h"
15
16 #ifdef __BORLANDC__
17 #pragma hdrstop
18 #endif
19
20 // for all others, include the necessary headers (this file is usually all you
21 // need because it includes almost all "standard" wxWidgets headers)
22 #ifndef WX_PRECOMP
23 #include "wx/wx.h"
24 #endif
25
26 #include "wx/app.h"
27 #include "wx/frame.h"
28 #include "wx/gizmos/dynamicsash.h"
29 #include "wx/html/htmlwin.h"
30 #include "wx/image.h"
31 #include "wx/cmdline.h"
32
33 class Demo : public wxApp
34 {
35 public:
36 bool OnInit();
37 };
38
39 class SashHtmlWindow : public wxHtmlWindow
40 {
41 public:
42 SashHtmlWindow(wxWindow *parent, wxWindowID id = wxID_ANY,
43 const wxPoint& pos = wxDefaultPosition,
44 const wxSize& size = wxDefaultSize,
45 long style = wxHW_SCROLLBAR_NEVER,
46 const wxString& name = wxT("sashHtmlWindow"));
47
48 wxSize DoGetBestSize() const;
49
50 private:
51 void OnSplit(wxDynamicSashSplitEvent& event);
52
53 wxWindow *m_dyn_sash;
54 };
55
56 IMPLEMENT_APP(Demo)
57
58 const wxChar *HTML_content =
59 wxT("<P><H1>wxDynamicSashWindow demo</H1>")
60 wxT("<P>Here is an example of how you can use <TT>wxDynamicSashWindow</TT> to allow your users to ")
61 wxT("dynamically split and unify the views of your windows. Try dragging out a few splits ")
62 wxT("and then reunifying the window.")
63 wxT("<P>Also, see the <TT>dynsash_switch</TT> sample for an example of an application which ")
64 wxT("manages the scrollbars provided by <TT>wxDynamicSashWindow</TT> itself.");
65
66 bool Demo::OnInit()
67 {
68 wxInitAllImageHandlers();
69
70 wxFrame *frame = new wxFrame(NULL, wxID_ANY, wxT("Dynamic Sash Demo"));
71 frame->SetSize(480, 480);
72
73 wxDynamicSashWindow *sash = new wxDynamicSashWindow(frame, wxID_ANY);
74 wxHtmlWindow *html = new SashHtmlWindow(sash, wxID_ANY);
75 html->SetPage(HTML_content);
76
77 frame->Show();
78
79 return true;
80 }
81
82
83 SashHtmlWindow::SashHtmlWindow(wxWindow *parent, wxWindowID id,
84 const wxPoint& pos,
85 const wxSize& size,
86 long style,
87 const wxString& name)
88 : wxHtmlWindow(parent, id, pos, size, style, name)
89 {
90 Connect(wxEVT_DYNAMIC_SASH_SPLIT,
91 wxDynamicSashSplitEventHandler(SashHtmlWindow::OnSplit));
92
93 m_dyn_sash = parent;
94 }
95
96 wxSize SashHtmlWindow::DoGetBestSize() const
97 {
98 wxHtmlContainerCell *cell = GetInternalRepresentation();
99 wxSize size = GetSize();
100
101 if (cell)
102 {
103 cell->Layout(size.GetWidth());
104 return wxSize(cell->GetWidth(), cell->GetHeight());
105 }
106
107 return wxHtmlWindow::GetBestSize();
108 }
109
110 void SashHtmlWindow::OnSplit(wxDynamicSashSplitEvent& WXUNUSED(event))
111 {
112 wxHtmlWindow *html = new SashHtmlWindow(m_dyn_sash, wxID_ANY);
113 html->SetPage(HTML_content);
114 }