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