]>
Commit | Line | Data |
---|---|---|
0d5eda9c FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: screenshot_main.cpp | |
f978831f | 3 | // Purpose: Implements the window containing all controls. |
0d5eda9c FM |
4 | // Author: Utensil Candel (UtensilCandel@@gmail.com) |
5 | // RCS-ID: $Id$ | |
6 | // Licence: wxWindows license | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | // For compilers that support precompilation, includes "wx/wx.h". | |
10 | #include "wx/wxprec.h" | |
11 | ||
12 | #ifdef __BORLANDC__ | |
f978831f | 13 | #pragma hdrstop |
0d5eda9c FM |
14 | #endif |
15 | ||
f978831f | 16 | // for all others, include the necessary headers wxWidgets headers) |
0d5eda9c | 17 | #ifndef WX_PRECOMP |
f978831f | 18 | #include "wx/wx.h" |
0d5eda9c FM |
19 | #endif |
20 | ||
f978831f BP |
21 | #include "wx/aboutdlg.h" |
22 | #include "wx/dir.h" | |
23 | #include "wx/filesys.h" | |
4bae10bd | 24 | |
0d5eda9c FM |
25 | #include "screenshot_main.h" |
26 | #include "ctrlmaskout.h" | |
27 | #include "autocapture.h" | |
28 | ||
1bda8399 FM |
29 | #include "bitmaps/play.xpm" |
30 | #include "bitmaps/stop.xpm" | |
31 | ||
0d5eda9c FM |
32 | |
33 | // ---------------------------------------------------------------------------- | |
4bae10bd | 34 | // ScreenshotFrame |
0d5eda9c FM |
35 | // ---------------------------------------------------------------------------- |
36 | ||
4bae10bd | 37 | ScreenshotFrame::ScreenshotFrame(wxFrame *frame) |
0d5eda9c FM |
38 | #if SCREENSHOTGEN_USE_AUI |
39 | : AuiGUIFrame(frame) | |
40 | #else | |
41 | : GUIFrame(frame) | |
42 | #endif | |
43 | { | |
44 | #if wxUSE_STATUSBAR | |
60a2264d | 45 | statusBar->SetStatusText(_("Welcome to the Automatic Screenshot Generator!"), 0); |
0d5eda9c FM |
46 | #endif |
47 | ||
60a2264d | 48 | // We will hold one ctrlmaskout during the whole life time of the main frame |
4bae10bd | 49 | m_maskout = new CtrlMaskOut(); |
0d5eda9c FM |
50 | |
51 | // At the begining, we are not specifying the rect region | |
52 | capturingRect = false; | |
53 | ||
54 | // Do some further customization on some controls generated by wxFormBuilder | |
55 | InitFBControls(); | |
56 | #if SCREENSHOTGEN_USE_AUI | |
57 | // Somehow it will be very small after I move to Aui | |
58 | SetSize(600, 600); | |
59 | // Maximize(true); | |
60 | #endif | |
61 | } | |
62 | ||
4bae10bd | 63 | ScreenshotFrame::~ScreenshotFrame() |
0d5eda9c FM |
64 | { |
65 | delete m_maskout; | |
66 | } | |
67 | ||
68 | /* | |
f978831f | 69 | Do some further customization on some controls. |
57ea8997 FM |
70 | |
71 | NB: under wxGTK for the radio button "unchecked" to be unchecked, it's | |
72 | important to put the wxRB_GROUP style on the first wxRadioButton | |
73 | (the one "checked") and no flags on the second one. | |
0d5eda9c | 74 | */ |
4bae10bd | 75 | void ScreenshotFrame::InitFBControls() |
0d5eda9c | 76 | { |
6cd1aa9d FM |
77 | m_scrollBar1->SetScrollbar(50, 1, 100, 1); |
78 | ||
0d5eda9c FM |
79 | // Do the default selection for wxComboBox |
80 | m_comboBox1->Select(0); | |
81 | ||
82 | // To look better under gtk | |
83 | #ifdef __WXGTK__ | |
84 | m_comboBox1->Delete(4); | |
85 | #endif | |
86 | ||
87 | // Add a root and some nodes for wxTreeCtrl | |
88 | wxTreeItemId root = m_treeCtrl1->AddRoot(_("wxTreeCtrl")); | |
0d5eda9c | 89 | m_treeCtrl1->AppendItem(root, _("Node1")); |
0d5eda9c FM |
90 | wxTreeItemId node2 = m_treeCtrl1->AppendItem(root, _("Node2")); |
91 | m_treeCtrl1->AppendItem(node2, _("Node3")); | |
0d5eda9c FM |
92 | m_treeCtrl1->ExpandAll(); |
93 | ||
94 | // Add items into wxListCtrl | |
f978831f BP |
95 | m_listCtrl1->InsertColumn(0, "Names"); |
96 | m_listCtrl1->InsertColumn(1, "Values"); | |
97 | for(long index = 0; index < 5; index++) { | |
1bda8399 | 98 | m_listCtrl1->InsertItem( index, wxString::Format(_("Item%d"),index)); |
f978831f BP |
99 | m_listCtrl1->SetItem(index, 1, wxString::Format("%d", index)); |
100 | } | |
0d5eda9c | 101 | |
f978831f BP |
102 | // Init file and dir pickers |
103 | wxString file, dir; | |
b85e7dcf | 104 | #if defined(__WXMSW__) |
f978831f BP |
105 | file = "C:\\Windows\\explorer.exe"; |
106 | dir = "C:\\Windows"; | |
b85e7dcf | 107 | #else |
f978831f BP |
108 | file = "/bin/bash"; |
109 | dir = "/home"; | |
b85e7dcf | 110 | #endif |
f978831f BP |
111 | m_filePicker1->SetPath(file); |
112 | m_dirPicker1->SetPath(dir); | |
b85e7dcf | 113 | |
0d5eda9c FM |
114 | // Check the first item in wxCheckListBox |
115 | m_checkList1->Check(0); | |
116 | ||
117 | // Load richtext.xml into wxRichtextCtrl | |
118 | m_richText1->LoadFile(_T("richtext.xml")); | |
60a2264d FM |
119 | //m_richText1->ShowPosition(335); |
120 | ||
121 | // select first page in the main notebook ctrl | |
122 | m_notebook1->ChangeSelection(0); | |
123 | ||
124 | // set minimum size hints | |
125 | GetSizer()->SetSizeHints(this); | |
1bda8399 | 126 | |
60d7250b FM |
127 | // add bitmaps to the menus |
128 | m_menuCapRect->SetBitmap( wxIcon(play_xpm) ); | |
129 | m_menuEndCapRect->SetBitmap( wxIcon(stop_xpm) ); | |
0d5eda9c FM |
130 | } |
131 | ||
132 | ||
133 | ||
134 | // ---------------------------------------------------------------------------- | |
4bae10bd | 135 | // ScreenshotFrame - event handlers |
0d5eda9c FM |
136 | // ---------------------------------------------------------------------------- |
137 | ||
4bae10bd | 138 | void ScreenshotFrame::OnClose(wxCloseEvent& WXUNUSED(event)) |
0d5eda9c FM |
139 | { |
140 | Destroy(); | |
141 | } | |
142 | ||
4bae10bd | 143 | void ScreenshotFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c FM |
144 | { |
145 | Destroy(); | |
146 | } | |
147 | ||
4bae10bd | 148 | void ScreenshotFrame::OnSeeScreenshots(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c FM |
149 | { |
150 | wxString defaultDir = m_maskout->GetDefaultDirectory(); | |
151 | ||
152 | // Check if defaultDir already existed | |
60a2264d | 153 | if (!wxDirExists(defaultDir)) |
0d5eda9c FM |
154 | wxMkdir(defaultDir); |
155 | ||
156 | // Use the native file browser to open defaultDir | |
60a2264d | 157 | wxLaunchDefaultBrowser(wxFileSystem::FileNameToURL(defaultDir)); |
0d5eda9c FM |
158 | } |
159 | ||
4bae10bd | 160 | void ScreenshotFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c | 161 | { |
4bae10bd FM |
162 | wxAboutDialogInfo info; |
163 | info.SetName(_("Automatic Screenshot Generator")); | |
164 | info.SetVersion(_("1.0")); | |
416fddd3 | 165 | info.SetDescription(_("This utility automatically creates screenshots of wxWidgets controls for use in wxWidgets documentation.")); |
4bae10bd FM |
166 | info.SetCopyright(_T("(C) 2008 Utensil Candel")); |
167 | ||
168 | wxAboutBox(info); | |
0d5eda9c FM |
169 | } |
170 | ||
4bae10bd | 171 | void ScreenshotFrame::OnCaptureFullScreen(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c FM |
172 | { |
173 | // Create a DC for the whole screen area | |
174 | wxScreenDC dcScreen; | |
175 | ||
176 | // Get the size of the screenDC | |
177 | wxCoord screenWidth, screenHeight; | |
178 | dcScreen.GetSize(&screenWidth, &screenHeight); | |
179 | ||
180 | m_maskout->Capture(0, 0, screenWidth, screenHeight, _T("fullscreen")); | |
60a2264d FM |
181 | |
182 | // Inform the user | |
183 | wxMessageBox(_("A screenshot of the entire screen was saved as:\n\n ") + | |
184 | m_maskout->GetDefaultDirectoryAbsPath() + wxFileName::GetPathSeparator() + "fullscreen.png", | |
185 | _("Full screen capture"), wxICON_INFORMATION|wxOK, this); | |
0d5eda9c FM |
186 | } |
187 | ||
4bae10bd | 188 | void ScreenshotFrame::OnCaptureRect(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c FM |
189 | { |
190 | capturingRect = true; | |
191 | wxMenuBar * menubar = this->GetMenuBar(); | |
192 | menubar->FindItem(idMenuCapRect)->Enable(false); | |
193 | menubar->FindItem(idMenuEndCapRect)->Enable(true); | |
194 | ||
195 | wxWindow * thePage = m_notebook1->GetPage(m_notebook1->GetSelection()); | |
196 | ||
4bae10bd FM |
197 | thePage->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout); |
198 | thePage->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout); | |
199 | thePage->Connect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout); | |
0d5eda9c FM |
200 | } |
201 | ||
4bae10bd | 202 | void ScreenshotFrame::OnEndCaptureRect(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c FM |
203 | { |
204 | capturingRect = false; | |
205 | wxMenuBar * menubar = this->GetMenuBar(); | |
206 | menubar->FindItem(idMenuCapRect)->Enable(true); | |
207 | menubar->FindItem(idMenuEndCapRect)->Enable(false); | |
208 | ||
209 | wxWindow * thePage = m_notebook1->GetPage(m_notebook1->GetSelection()); | |
210 | ||
4bae10bd FM |
211 | thePage->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout); |
212 | thePage->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout); | |
213 | thePage->Disconnect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout); | |
0d5eda9c FM |
214 | } |
215 | ||
4bae10bd | 216 | void ScreenshotFrame::OnNotebookPageChanging( |
0d5eda9c FM |
217 | #if SCREENSHOTGEN_USE_AUI |
218 | wxAuiNotebookEvent& event | |
219 | #else | |
220 | wxNotebookEvent& event | |
221 | #endif | |
222 | ) | |
223 | { | |
224 | if (!capturingRect) | |
225 | { | |
226 | event.Skip(); | |
227 | return; | |
228 | } | |
229 | ||
230 | wxWindow * thePage = m_notebook1->GetPage(event.GetOldSelection()); | |
231 | ||
4bae10bd FM |
232 | thePage->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout); |
233 | thePage->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout); | |
234 | thePage->Disconnect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout); | |
0d5eda9c FM |
235 | |
236 | event.Skip(); | |
237 | } | |
238 | ||
4bae10bd | 239 | void ScreenshotFrame::OnNotebookPageChanged( |
0d5eda9c FM |
240 | #if SCREENSHOTGEN_USE_AUI |
241 | wxAuiNotebookEvent& event | |
242 | #else | |
243 | wxNotebookEvent& event | |
244 | #endif | |
245 | ) | |
246 | { | |
60a2264d | 247 | if (!capturingRect) |
0d5eda9c FM |
248 | { |
249 | event.Skip(); | |
250 | return; | |
251 | } | |
252 | ||
253 | wxWindow *thePage = m_notebook1->GetPage(event.GetSelection()); | |
254 | ||
4bae10bd FM |
255 | thePage->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout); |
256 | thePage->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout); | |
257 | thePage->Connect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout); | |
0d5eda9c FM |
258 | |
259 | event.Skip(); | |
260 | } | |
261 | ||
4bae10bd | 262 | void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c | 263 | { |
60a2264d | 264 | wxString dir = m_maskout->GetDefaultDirectoryAbsPath(); |
0d5eda9c | 265 | |
60a2264d | 266 | // check if there are other screenshots taken before |
0d5eda9c FM |
267 | if (wxFileName::DirExists(dir)) |
268 | { | |
6cd1aa9d | 269 | int choice = wxMessageBox(_("It seems that you have already generated some screenshots.\n\nClick YES to delete them all (recommended) or NO to preserve them.\nClick CANCEL to cancel this auto-capture operation."), |
60a2264d | 270 | _("Delete existing screenshots?"), |
0d5eda9c FM |
271 | wxYES_NO|wxCANCEL|wxICON_QUESTION, this); |
272 | switch(choice) | |
273 | { | |
60a2264d | 274 | case wxYES: |
0d5eda9c FM |
275 | { |
276 | wxArrayString files; | |
277 | wxDir::GetAllFiles(dir, &files, wxT("*.png"), wxDIR_FILES); | |
278 | ||
60a2264d | 279 | // remove all PNG files from the screenshots folder |
0d5eda9c FM |
280 | int n = files.GetCount(); |
281 | for (int i = 0; i < n; ++i) | |
282 | wxRemoveFile(files[i]); | |
283 | } | |
284 | break; | |
285 | ||
60a2264d FM |
286 | case wxNO: break; |
287 | case wxCANCEL: return; | |
0d5eda9c FM |
288 | } |
289 | } | |
290 | ||
60a2264d FM |
291 | // proceed with the automatic screenshot capture |
292 | ||
0d5eda9c FM |
293 | this->Maximize(); |
294 | ||
295 | AutoCaptureMechanism auto_cap(m_notebook1); | |
296 | ||
297 | auto_cap.RegisterControl(m_button1); | |
298 | auto_cap.RegisterControl(m_staticText1); | |
299 | auto_cap.RegisterControl(m_checkBox1, AJ_Union); | |
300 | auto_cap.RegisterControl(m_checkBox2, AJ_UnionEnd); | |
301 | auto_cap.RegisterControl(m_radioBtn1, AJ_Union); | |
302 | auto_cap.RegisterControl(m_radioBtn2, AJ_UnionEnd); | |
303 | auto_cap.RegisterControl(m_bpButton1); | |
304 | auto_cap.RegisterControl(m_bitmap1); | |
305 | auto_cap.RegisterControl(m_gauge1, wxT("wxGauge")); | |
306 | auto_cap.RegisterControl(m_slider1); | |
307 | auto_cap.RegisterControl(m_toggleBtn1, AJ_Union); | |
308 | auto_cap.RegisterControl(m_toggleBtn2, AJ_UnionEnd); | |
88300af4 | 309 | auto_cap.RegisterControl(m_hyperlink1, wxT("wxHyperlinkCtrl")); |
0d5eda9c FM |
310 | auto_cap.RegisterControl(m_spinCtrl1, AJ_RegionAdjust); |
311 | auto_cap.RegisterControl(m_spinBtn1); | |
312 | auto_cap.RegisterControl(m_scrollBar1); | |
313 | ||
314 | auto_cap.RegisterPageTurn(); | |
315 | ||
316 | auto_cap.RegisterControl(m_checkList1); | |
317 | auto_cap.RegisterControl(m_listBox1); | |
318 | auto_cap.RegisterControl(m_radioBox1); | |
319 | auto_cap.RegisterControl(m_staticBox1); | |
320 | auto_cap.RegisterControl(m_treeCtrl1); | |
321 | auto_cap.RegisterControl(m_listCtrl1, wxT("wxListCtrl")); | |
322 | ||
323 | auto_cap.RegisterControl(m_animationCtrl1); | |
324 | auto_cap.RegisterControl(m_collPane1, wxT("wxCollapsiblePane"), AJ_Union); | |
325 | auto_cap.RegisterControl(m_collPane2, AJ_UnionEnd); | |
326 | ||
327 | auto_cap.RegisterPageTurn(); | |
328 | ||
329 | auto_cap.RegisterControl(m_textCtrl1, AJ_Union); | |
330 | auto_cap.RegisterControl(m_textCtrl2, AJ_UnionEnd); | |
331 | auto_cap.RegisterControl(m_richText1); | |
332 | ||
333 | auto_cap.RegisterPageTurn(); | |
334 | ||
335 | auto_cap.RegisterControl(m_colourPicker1, wxT("wxColourPickerCtrl")); | |
336 | auto_cap.RegisterControl(m_fontPicker1, wxT("wxFontPickerCtrl")); | |
337 | auto_cap.RegisterControl(m_filePicker1, wxT("wxFilePickerCtrl"), AJ_RegionAdjust); | |
338 | auto_cap.RegisterControl(m_calendar1, wxT("wxCalendarCtrl"), AJ_RegionAdjust); | |
339 | auto_cap.RegisterControl(m_datePicker1, wxT("wxDatePickerCtrl")); | |
340 | auto_cap.RegisterControl(m_genericDirCtrl1, wxT("wxGenericDirCtrl")); | |
341 | auto_cap.RegisterControl(m_dirPicker1, wxT("wxDirPickerCtrl"), AJ_RegionAdjust); | |
342 | ||
343 | auto_cap.RegisterPageTurn(); | |
344 | ||
345 | auto_cap.RegisterControl(m_choice1, AJ_Dropdown); | |
346 | auto_cap.RegisterControl(m_comboBox1, AJ_Dropdown); | |
347 | auto_cap.RegisterControl(m_bmpComboBox1, AJ_Dropdown); | |
348 | auto_cap.RegisterControl(m_ownerDrawnComboBox1, AJ_Dropdown); | |
349 | auto_cap.RegisterControl(m_comboCtrl1, AJ_Dropdown|AJ_Union); | |
350 | auto_cap.RegisterControl(m_comboCtrl2, AJ_Dropdown|AJ_UnionEnd); | |
351 | ||
352 | auto_cap.CaptureAll(); | |
353 | ||
60a2264d FM |
354 | wxMessageBox(_("All screenshots were generated successfully in the folder:\n ") + dir, |
355 | _("Success"), wxOK|wxICON_INFORMATION, this); | |
0d5eda9c | 356 | } |