]>
Commit | Line | Data |
---|---|---|
eacb91fc VZ |
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 | ||
cd72551c JS |
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 | |
be5a51fb | 21 | // need because it includes almost all "standard" wxWidgets headers) |
cd72551c JS |
22 | #ifndef WX_PRECOMP |
23 | #include "wx/wx.h" | |
24 | #endif | |
25 | ||
eacb91fc | 26 | #include <wx/app.h> |
8cdb648e | 27 | #include <wx/frame.h> |
eacb91fc VZ |
28 | #include <wx/gizmos/dynamicsash.h> |
29 | #include <wx/html/htmlwin.h> | |
30 | #include <wx/image.h> | |
cd72551c | 31 | #include <wx/cmdline.h> |
eacb91fc VZ |
32 | |
33 | class Demo : public wxApp { | |
34 | public: | |
35 | bool OnInit(); | |
36 | }; | |
37 | ||
38 | class SashHtmlWindow : public wxHtmlWindow { | |
39 | public: | |
a2d49353 | 40 | SashHtmlWindow(wxWindow *parent, wxWindowID id = wxID_ANY, |
eacb91fc | 41 | const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, |
019abbf2 | 42 | long style = wxHW_SCROLLBAR_NEVER, const wxString& name = wxT("sashHtmlWindow")); |
eacb91fc VZ |
43 | |
44 | wxSize DoGetBestSize() const; | |
45 | ||
46 | private: | |
47 | void OnSplit(wxDynamicSashSplitEvent& event); | |
48 | ||
49 | wxWindow *m_dyn_sash; | |
50 | }; | |
51 | ||
52 | IMPLEMENT_APP(Demo) | |
53 | ||
019abbf2 | 54 | wxChar *HTML_content = |
ba597ca8 JS |
55 | wxT("<P><H1>wxDynamicSashWindow demo</H1>") |
56 | wxT("<P>Here is an example of how you can use <TT>wxDynamicSashWindow</TT> to allow your users to ") | |
57 | wxT("dynamically split and unify the views of your windows. Try dragging out a few splits ") | |
58 | wxT("and then reunifying the window.") | |
59 | wxT("<P>Also, see the <TT>dynsash_switch</TT> sample for an example of an application which ") | |
60 | wxT("manages the scrollbars provided by <TT>wxDynamicSashWindow</TT> itself."); | |
eacb91fc VZ |
61 | |
62 | bool Demo::OnInit() { | |
63 | wxInitAllImageHandlers(); | |
64 | ||
a2d49353 | 65 | wxFrame *frame = new wxFrame(NULL, wxID_ANY, wxT("Dynamic Sash Demo")); |
eacb91fc VZ |
66 | frame->SetSize(480, 480); |
67 | ||
a2d49353 WS |
68 | wxDynamicSashWindow *sash = new wxDynamicSashWindow(frame, wxID_ANY); |
69 | wxHtmlWindow *html = new SashHtmlWindow(sash, wxID_ANY); | |
eacb91fc VZ |
70 | html->SetPage(HTML_content); |
71 | ||
72 | frame->Show(); | |
73 | ||
a2d49353 | 74 | return true; |
eacb91fc VZ |
75 | } |
76 | ||
77 | ||
78 | SashHtmlWindow::SashHtmlWindow(wxWindow *parent, wxWindowID id, | |
79 | const wxPoint& pos, const wxSize& size, long style, const wxString& name) : | |
80 | wxHtmlWindow(parent, id, pos, size, style, name) { | |
a2d49353 | 81 | Connect(wxID_ANY, wxEVT_DYNAMIC_SASH_SPLIT, (wxObjectEventFunction) |
ba597ca8 JS |
82 | (wxEventFunction) |
83 | (wxDynamicSashSplitEventFunction)&SashHtmlWindow::OnSplit); | |
eacb91fc VZ |
84 | |
85 | m_dyn_sash = parent; | |
86 | } | |
87 | ||
88 | wxSize SashHtmlWindow::DoGetBestSize() const { | |
89 | wxHtmlContainerCell *cell = GetInternalRepresentation(); | |
90 | wxSize size = GetSize(); | |
91 | ||
92 | if (cell) { | |
93 | cell->Layout(size.GetWidth()); | |
94 | return wxSize(cell->GetWidth(), cell->GetHeight()); | |
95 | } else | |
96 | return wxHtmlWindow::GetBestSize(); | |
97 | } | |
98 | ||
ba597ca8 | 99 | void SashHtmlWindow::OnSplit(wxDynamicSashSplitEvent& WXUNUSED(event)) { |
a2d49353 | 100 | wxHtmlWindow *html = new SashHtmlWindow(m_dyn_sash, wxID_ANY); |
eacb91fc VZ |
101 | html->SetPage(HTML_content); |
102 | } |