]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: tree.cpp | |
3 | // Purpose: Minimal wxWindows sample | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | #ifdef __GNUG__ | |
20 | #pragma implementation "tree.cpp" | |
21 | #pragma interface "tree.cpp" | |
22 | #endif | |
23 | ||
24 | // For compilers that support precompilation, includes "wx/wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | // for all others, include the necessary headers (this file is usually all you | |
32 | // need because it includes almost all "standard" wxWindows headers) | |
33 | #ifndef WX_PRECOMP | |
34 | #include "wx/wx.h" | |
35 | #endif | |
36 | ||
37 | #include "wx/imaglist.h" | |
38 | #include "tree.h" | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // resources | |
42 | // ---------------------------------------------------------------------------- | |
43 | // the application icon | |
44 | #if defined(__WXGTK__) || defined(__WXMOTIF__) | |
45 | #include "mondrian.xpm" | |
46 | #endif | |
47 | ||
48 | // ---------------------------------------------------------------------------- | |
49 | // event tables and other macros for wxWindows | |
50 | // ---------------------------------------------------------------------------- | |
51 | ||
52 | // the event tables connect the wxWindows events with the functions (event | |
53 | // handlers) which process them. It can be also done at run-time, but for the | |
54 | // simple menu events like this the static method is much simpler. | |
55 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) | |
56 | EVT_MENU(Minimal_Quit, MyFrame::OnQuit) | |
57 | EVT_MENU(Minimal_About, MyFrame::OnAbout) | |
58 | END_EVENT_TABLE() | |
59 | ||
60 | // Create a new application object: this macro will allow wxWindows to create | |
61 | // the application object during program execution (it's better than using a | |
62 | // static object for many reasons) and also declares the accessor function | |
63 | // wxGetApp() which will return the reference of the right type (i.e. MyApp and | |
64 | // not wxApp) | |
65 | IMPLEMENT_APP(MyApp) | |
66 | ||
67 | // ============================================================================ | |
68 | // implementation | |
69 | // ============================================================================ | |
70 | ||
71 | // ---------------------------------------------------------------------------- | |
72 | // the application class | |
73 | // ---------------------------------------------------------------------------- | |
74 | ||
75 | // 'Main program' equivalent: the program execution "starts" here | |
76 | bool MyApp::OnInit() | |
77 | { | |
78 | // create the main application window | |
79 | MyFrame *frame = new MyFrame("Tree Testing", | |
80 | wxPoint(50, 50), wxSize(450, 340)); | |
81 | ||
82 | // and show it (the frames, unlike simple controls, are not shown when | |
83 | // created initially) | |
84 | frame->Show(TRUE); | |
85 | ||
86 | // success: wxApp::OnRun() will be called which will enter the main message | |
87 | // loop and the application will run. If we returned FALSE here, the | |
88 | // application would exit immediately. | |
89 | return TRUE; | |
90 | } | |
91 | ||
92 | // ---------------------------------------------------------------------------- | |
93 | // main frame | |
94 | // ---------------------------------------------------------------------------- | |
95 | ||
96 | // frame constructor | |
97 | MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) | |
98 | : wxFrame((wxFrame *)NULL, idMAIN_FRAME, title, pos, size) | |
99 | { | |
100 | m_splitter = NULL; | |
101 | m_scrolledWindow = NULL; | |
102 | m_tree = NULL; | |
103 | m_valueWindow = NULL; | |
104 | #ifdef __WXMAC__ | |
105 | // we need this in order to allow the about menu relocation, since ABOUT is | |
106 | // not the default id of the about menu | |
107 | wxApp::s_macAboutMenuItemId = Minimal_About; | |
108 | #endif | |
109 | ||
110 | m_scrolledWindow = new wxSplitterScrolledWindow(this, idSCROLLED_WINDOW, wxDefaultPosition, | |
111 | wxDefaultSize, wxNO_BORDER | wxCLIP_CHILDREN | wxVSCROLL); | |
112 | m_splitter = new wxThinSplitterWindow(m_scrolledWindow, idSPLITTER_WINDOW, wxDefaultPosition, | |
113 | wxDefaultSize, wxSP_3DBORDER | wxCLIP_CHILDREN /* | wxSP_LIVE_UPDATE */); | |
114 | m_splitter->SetSashSize(2); | |
115 | m_tree = new TestTree(m_splitter, idTREE_CTRL, wxDefaultPosition, | |
116 | wxDefaultSize, wxTR_HAS_BUTTONS | wxTR_NO_LINES | wxNO_BORDER ); | |
117 | m_valueWindow = new TestValueWindow(m_splitter, idVALUE_WINDOW, wxDefaultPosition, | |
118 | wxDefaultSize, wxNO_BORDER); | |
119 | m_splitter->SplitVertically(m_tree, m_valueWindow); | |
120 | //m_splitter->AdjustScrollbars(); | |
121 | m_splitter->SetSashPosition(200); | |
122 | m_scrolledWindow->SetTargetWindow(m_tree); | |
123 | ||
124 | m_scrolledWindow->EnableScrolling(FALSE, FALSE); | |
125 | ||
126 | // set the frame icon | |
127 | SetIcon(wxICON(mondrian)); | |
128 | ||
129 | // create a menu bar | |
130 | wxMenu *menuFile = new wxMenu("", wxMENU_TEAROFF); | |
131 | ||
132 | // the "About" item should be in the help menu | |
133 | wxMenu *helpMenu = new wxMenu; | |
134 | helpMenu->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog"); | |
135 | ||
136 | menuFile->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program"); | |
137 | ||
138 | // now append the freshly created menu to the menu bar... | |
139 | wxMenuBar *menuBar = new wxMenuBar(); | |
140 | menuBar->Append(menuFile, "&File"); | |
141 | menuBar->Append(helpMenu, "&Help"); | |
142 | ||
143 | // ... and attach this menu bar to the frame | |
144 | SetMenuBar(menuBar); | |
145 | } | |
146 | ||
147 | ||
148 | // event handlers | |
149 | ||
150 | void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) | |
151 | { | |
152 | // TRUE is to force the frame to close | |
153 | Close(TRUE); | |
154 | } | |
155 | ||
156 | void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) | |
157 | { | |
158 | wxString msg; | |
159 | msg.Printf( _T("This is the about dialog of tree sample.\n") | |
160 | _T("Welcome to %s"), wxVERSION_STRING); | |
161 | ||
162 | wxMessageBox(msg, "About Tree Test", wxOK | wxICON_INFORMATION, this); | |
163 | } | |
164 | ||
165 | /* | |
166 | * TesTree | |
167 | */ | |
168 | ||
169 | IMPLEMENT_CLASS(TestTree, wxRemotelyScrolledTreeCtrl) | |
170 | ||
171 | BEGIN_EVENT_TABLE(TestTree, wxRemotelyScrolledTreeCtrl) | |
172 | END_EVENT_TABLE() | |
173 | ||
174 | TestTree::TestTree(wxWindow* parent, wxWindowID id, const wxPoint& pt, | |
175 | const wxSize& sz, long style): | |
176 | wxRemotelyScrolledTreeCtrl(parent, id, pt, sz, style) | |
177 | { | |
178 | m_imageList = new wxImageList(16, 16, TRUE); | |
179 | #if !defined(__WXMSW__) // || wxUSE_XPM_IN_MSW | |
180 | m_imageList->Add(wxIcon(icon1_xpm)); | |
181 | m_imageList->Add(wxIcon(icon2_xpm)); | |
182 | m_imageList->Add(wxIcon(icon3_xpm)); | |
183 | m_imageList->Add(wxIcon(icon4_xpm)); | |
184 | m_imageList->Add(wxIcon(icon5_xpm)); | |
185 | m_imageList->Add(wxIcon(icon6_xpm)); | |
186 | m_imageList->Add(wxIcon(icon7_xpm)); | |
187 | m_imageList->Add(wxIcon(icon8_xpm)); | |
188 | #elif defined(__WXMSW__) | |
189 | m_imageList->Add(wxIcon(wxT("wxICON_SMALL_CLOSED_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE)); | |
190 | m_imageList->Add(wxIcon(wxT("wxICON_SMALL_OPEN_FOLDER"), wxBITMAP_TYPE_ICO_RESOURCE)); | |
191 | m_imageList->Add(wxIcon(wxT("wxICON_SMALL_FILE"), wxBITMAP_TYPE_ICO_RESOURCE)); | |
192 | m_imageList->Add(wxIcon(wxT("wxICON_SMALL_COMPUTER"), wxBITMAP_TYPE_ICO_RESOURCE)); | |
193 | m_imageList->Add(wxIcon(wxT("wxICON_SMALL_DRIVE"), wxBITMAP_TYPE_ICO_RESOURCE)); | |
194 | m_imageList->Add(wxIcon(wxT("wxICON_SMALL_CDROM"), wxBITMAP_TYPE_ICO_RESOURCE)); | |
195 | m_imageList->Add(wxIcon(wxT("wxICON_SMALL_FLOPPY"), wxBITMAP_TYPE_ICO_RESOURCE)); | |
196 | m_imageList->Add(wxIcon(wxT("wxICON_SMALL_REMOVEABLE"), wxBITMAP_TYPE_ICO_RESOURCE)); | |
197 | #else | |
198 | #error "Sorry, we don't have icons available for this platforms." | |
199 | #endif | |
200 | SetImageList(m_imageList); | |
201 | ||
202 | ||
203 | // Add some dummy items | |
204 | wxTreeItemId rootId = AddRoot(_("Root"), 3, -1); | |
205 | int i; | |
206 | for (i = 1; i <= 20; i++) | |
207 | { | |
208 | wxString label; | |
209 | label.Printf(wxT("Item %d"), i); | |
210 | wxTreeItemId id = AppendItem(rootId, label, 0); | |
211 | SetItemImage( id, 1, wxTreeItemIcon_Expanded ); | |
212 | ||
213 | int j; | |
214 | for (j = 0; j < 10; j++) | |
215 | AppendItem(id, _("Child"), 2); | |
216 | } | |
217 | Expand(rootId); | |
218 | } | |
219 | ||
220 | TestTree::~TestTree() | |
221 | { | |
222 | SetImageList(NULL); | |
223 | delete m_imageList; | |
224 | } | |
225 | ||
226 | /* | |
227 | * TestValueWindow | |
228 | */ | |
229 | ||
230 | //IMPLEMENT_CLASS(TestValueWindow, wxWindow) | |
231 | ||
232 | BEGIN_EVENT_TABLE(TestValueWindow, wxWindow) | |
233 | EVT_SIZE(TestValueWindow::OnSize) | |
234 | END_EVENT_TABLE() | |
235 | ||
236 | TestValueWindow::TestValueWindow(wxWindow* parent, wxWindowID id, | |
237 | const wxPoint& pos, | |
238 | const wxSize& sz, | |
239 | long style): | |
240 | wxWindow(parent, id, pos, sz, style) | |
241 | { | |
242 | SetBackgroundColour(* wxWHITE); | |
243 | } | |
244 | ||
245 | void TestValueWindow::OnSize(wxSizeEvent& event) | |
246 | { | |
247 | } |