]>
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. | |
57ea8997 FM |
80 | |
81 | ||
82 | NB: under wxGTK for the radio button "unchecked" to be unchecked, it's | |
83 | important to put the wxRB_GROUP style on the first wxRadioButton | |
84 | (the one "checked") and no flags on the second one. | |
0d5eda9c | 85 | */ |
4bae10bd | 86 | void ScreenshotFrame::InitFBControls() |
0d5eda9c | 87 | { |
6cd1aa9d FM |
88 | // For some reason, wxFormBuilder does not set the scrollbar range |
89 | m_scrollBar1->SetScrollbar(50, 1, 100, 1); | |
90 | ||
0d5eda9c FM |
91 | // Do the default selection for wxComboBox |
92 | m_comboBox1->Select(0); | |
93 | ||
94 | // To look better under gtk | |
95 | #ifdef __WXGTK__ | |
96 | m_comboBox1->Delete(4); | |
97 | #endif | |
98 | ||
99 | // Add a root and some nodes for wxTreeCtrl | |
100 | wxTreeItemId root = m_treeCtrl1->AddRoot(_("wxTreeCtrl")); | |
0d5eda9c | 101 | m_treeCtrl1->AppendItem(root, _("Node1")); |
0d5eda9c FM |
102 | wxTreeItemId node2 = m_treeCtrl1->AppendItem(root, _("Node2")); |
103 | m_treeCtrl1->AppendItem(node2, _("Node3")); | |
0d5eda9c FM |
104 | m_treeCtrl1->ExpandAll(); |
105 | ||
106 | // Add items into wxListCtrl | |
107 | for(long index = 0; index < 5; index++) | |
108 | m_listCtrl1->InsertItem( index, wxString::Format(_("Item\n(0,%d)"),index)); | |
109 | ||
110 | // Check the first item in wxCheckListBox | |
111 | m_checkList1->Check(0); | |
112 | ||
113 | // Load richtext.xml into wxRichtextCtrl | |
114 | m_richText1->LoadFile(_T("richtext.xml")); | |
60a2264d FM |
115 | //m_richText1->ShowPosition(335); |
116 | ||
117 | // select first page in the main notebook ctrl | |
118 | m_notebook1->ChangeSelection(0); | |
119 | ||
120 | // set minimum size hints | |
121 | GetSizer()->SetSizeHints(this); | |
0d5eda9c FM |
122 | } |
123 | ||
124 | ||
125 | ||
126 | // ---------------------------------------------------------------------------- | |
4bae10bd | 127 | // ScreenshotFrame - event handlers |
0d5eda9c FM |
128 | // ---------------------------------------------------------------------------- |
129 | ||
4bae10bd | 130 | void ScreenshotFrame::OnClose(wxCloseEvent& WXUNUSED(event)) |
0d5eda9c FM |
131 | { |
132 | Destroy(); | |
133 | } | |
134 | ||
4bae10bd | 135 | void ScreenshotFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c FM |
136 | { |
137 | Destroy(); | |
138 | } | |
139 | ||
4bae10bd | 140 | void ScreenshotFrame::OnSeeScreenshots(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c FM |
141 | { |
142 | wxString defaultDir = m_maskout->GetDefaultDirectory(); | |
143 | ||
144 | // Check if defaultDir already existed | |
60a2264d | 145 | if (!wxDirExists(defaultDir)) |
0d5eda9c FM |
146 | wxMkdir(defaultDir); |
147 | ||
148 | // Use the native file browser to open defaultDir | |
60a2264d | 149 | wxLaunchDefaultBrowser(wxFileSystem::FileNameToURL(defaultDir)); |
0d5eda9c FM |
150 | } |
151 | ||
4bae10bd | 152 | void ScreenshotFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c | 153 | { |
4bae10bd FM |
154 | wxAboutDialogInfo info; |
155 | info.SetName(_("Automatic Screenshot Generator")); | |
156 | info.SetVersion(_("1.0")); | |
157 | info.SetDescription(_("This utility automatically creates screenshots of wxWidgets controls for ues in wxWidgets documentation.")); | |
158 | info.SetCopyright(_T("(C) 2008 Utensil Candel")); | |
159 | ||
160 | wxAboutBox(info); | |
0d5eda9c FM |
161 | } |
162 | ||
4bae10bd | 163 | void ScreenshotFrame::OnCaptureFullScreen(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c FM |
164 | { |
165 | // Create a DC for the whole screen area | |
166 | wxScreenDC dcScreen; | |
167 | ||
168 | // Get the size of the screenDC | |
169 | wxCoord screenWidth, screenHeight; | |
170 | dcScreen.GetSize(&screenWidth, &screenHeight); | |
171 | ||
172 | m_maskout->Capture(0, 0, screenWidth, screenHeight, _T("fullscreen")); | |
60a2264d FM |
173 | |
174 | // Inform the user | |
175 | wxMessageBox(_("A screenshot of the entire screen was saved as:\n\n ") + | |
176 | m_maskout->GetDefaultDirectoryAbsPath() + wxFileName::GetPathSeparator() + "fullscreen.png", | |
177 | _("Full screen capture"), wxICON_INFORMATION|wxOK, this); | |
0d5eda9c FM |
178 | } |
179 | ||
4bae10bd | 180 | void ScreenshotFrame::OnCaptureRect(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c FM |
181 | { |
182 | capturingRect = true; | |
183 | wxMenuBar * menubar = this->GetMenuBar(); | |
184 | menubar->FindItem(idMenuCapRect)->Enable(false); | |
185 | menubar->FindItem(idMenuEndCapRect)->Enable(true); | |
186 | ||
187 | wxWindow * thePage = m_notebook1->GetPage(m_notebook1->GetSelection()); | |
188 | ||
4bae10bd FM |
189 | thePage->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout); |
190 | thePage->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout); | |
191 | thePage->Connect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout); | |
0d5eda9c FM |
192 | } |
193 | ||
4bae10bd | 194 | void ScreenshotFrame::OnEndCaptureRect(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c FM |
195 | { |
196 | capturingRect = false; | |
197 | wxMenuBar * menubar = this->GetMenuBar(); | |
198 | menubar->FindItem(idMenuCapRect)->Enable(true); | |
199 | menubar->FindItem(idMenuEndCapRect)->Enable(false); | |
200 | ||
201 | wxWindow * thePage = m_notebook1->GetPage(m_notebook1->GetSelection()); | |
202 | ||
4bae10bd FM |
203 | thePage->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout); |
204 | thePage->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout); | |
205 | thePage->Disconnect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout); | |
0d5eda9c FM |
206 | } |
207 | ||
4bae10bd | 208 | void ScreenshotFrame::OnNotebookPageChanging( |
0d5eda9c FM |
209 | #if SCREENSHOTGEN_USE_AUI |
210 | wxAuiNotebookEvent& event | |
211 | #else | |
212 | wxNotebookEvent& event | |
213 | #endif | |
214 | ) | |
215 | { | |
216 | if (!capturingRect) | |
217 | { | |
218 | event.Skip(); | |
219 | return; | |
220 | } | |
221 | ||
222 | wxWindow * thePage = m_notebook1->GetPage(event.GetOldSelection()); | |
223 | ||
4bae10bd FM |
224 | thePage->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout); |
225 | thePage->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout); | |
226 | thePage->Disconnect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout); | |
0d5eda9c FM |
227 | |
228 | event.Skip(); | |
229 | } | |
230 | ||
4bae10bd | 231 | void ScreenshotFrame::OnNotebookPageChanged( |
0d5eda9c FM |
232 | #if SCREENSHOTGEN_USE_AUI |
233 | wxAuiNotebookEvent& event | |
234 | #else | |
235 | wxNotebookEvent& event | |
236 | #endif | |
237 | ) | |
238 | { | |
60a2264d | 239 | if (!capturingRect) |
0d5eda9c FM |
240 | { |
241 | event.Skip(); | |
242 | return; | |
243 | } | |
244 | ||
245 | wxWindow *thePage = m_notebook1->GetPage(event.GetSelection()); | |
246 | ||
4bae10bd FM |
247 | thePage->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout); |
248 | thePage->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout); | |
249 | thePage->Connect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout); | |
0d5eda9c FM |
250 | |
251 | event.Skip(); | |
252 | } | |
253 | ||
4bae10bd | 254 | void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event)) |
0d5eda9c | 255 | { |
60a2264d | 256 | wxString dir = m_maskout->GetDefaultDirectoryAbsPath(); |
0d5eda9c | 257 | |
60a2264d | 258 | // check if there are other screenshots taken before |
0d5eda9c FM |
259 | if (wxFileName::DirExists(dir)) |
260 | { | |
6cd1aa9d | 261 | 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 | 262 | _("Delete existing screenshots?"), |
0d5eda9c FM |
263 | wxYES_NO|wxCANCEL|wxICON_QUESTION, this); |
264 | switch(choice) | |
265 | { | |
60a2264d | 266 | case wxYES: |
0d5eda9c FM |
267 | { |
268 | wxArrayString files; | |
269 | wxDir::GetAllFiles(dir, &files, wxT("*.png"), wxDIR_FILES); | |
270 | ||
60a2264d | 271 | // remove all PNG files from the screenshots folder |
0d5eda9c FM |
272 | int n = files.GetCount(); |
273 | for (int i = 0; i < n; ++i) | |
274 | wxRemoveFile(files[i]); | |
275 | } | |
276 | break; | |
277 | ||
60a2264d FM |
278 | case wxNO: break; |
279 | case wxCANCEL: return; | |
0d5eda9c FM |
280 | } |
281 | } | |
282 | ||
60a2264d FM |
283 | // proceed with the automatic screenshot capture |
284 | ||
0d5eda9c FM |
285 | this->Maximize(); |
286 | ||
287 | AutoCaptureMechanism auto_cap(m_notebook1); | |
288 | ||
289 | auto_cap.RegisterControl(m_button1); | |
290 | auto_cap.RegisterControl(m_staticText1); | |
291 | auto_cap.RegisterControl(m_checkBox1, AJ_Union); | |
292 | auto_cap.RegisterControl(m_checkBox2, AJ_UnionEnd); | |
293 | auto_cap.RegisterControl(m_radioBtn1, AJ_Union); | |
294 | auto_cap.RegisterControl(m_radioBtn2, AJ_UnionEnd); | |
295 | auto_cap.RegisterControl(m_bpButton1); | |
296 | auto_cap.RegisterControl(m_bitmap1); | |
297 | auto_cap.RegisterControl(m_gauge1, wxT("wxGauge")); | |
298 | auto_cap.RegisterControl(m_slider1); | |
299 | auto_cap.RegisterControl(m_toggleBtn1, AJ_Union); | |
300 | auto_cap.RegisterControl(m_toggleBtn2, AJ_UnionEnd); | |
301 | auto_cap.RegisterControl(m_hyperlink1); | |
302 | auto_cap.RegisterControl(m_spinCtrl1, AJ_RegionAdjust); | |
303 | auto_cap.RegisterControl(m_spinBtn1); | |
304 | auto_cap.RegisterControl(m_scrollBar1); | |
305 | ||
306 | auto_cap.RegisterPageTurn(); | |
307 | ||
308 | auto_cap.RegisterControl(m_checkList1); | |
309 | auto_cap.RegisterControl(m_listBox1); | |
310 | auto_cap.RegisterControl(m_radioBox1); | |
311 | auto_cap.RegisterControl(m_staticBox1); | |
312 | auto_cap.RegisterControl(m_treeCtrl1); | |
313 | auto_cap.RegisterControl(m_listCtrl1, wxT("wxListCtrl")); | |
314 | ||
315 | auto_cap.RegisterControl(m_animationCtrl1); | |
316 | auto_cap.RegisterControl(m_collPane1, wxT("wxCollapsiblePane"), AJ_Union); | |
317 | auto_cap.RegisterControl(m_collPane2, AJ_UnionEnd); | |
318 | ||
319 | auto_cap.RegisterPageTurn(); | |
320 | ||
321 | auto_cap.RegisterControl(m_textCtrl1, AJ_Union); | |
322 | auto_cap.RegisterControl(m_textCtrl2, AJ_UnionEnd); | |
323 | auto_cap.RegisterControl(m_richText1); | |
324 | ||
325 | auto_cap.RegisterPageTurn(); | |
326 | ||
327 | auto_cap.RegisterControl(m_colourPicker1, wxT("wxColourPickerCtrl")); | |
328 | auto_cap.RegisterControl(m_fontPicker1, wxT("wxFontPickerCtrl")); | |
329 | auto_cap.RegisterControl(m_filePicker1, wxT("wxFilePickerCtrl"), AJ_RegionAdjust); | |
330 | auto_cap.RegisterControl(m_calendar1, wxT("wxCalendarCtrl"), AJ_RegionAdjust); | |
331 | auto_cap.RegisterControl(m_datePicker1, wxT("wxDatePickerCtrl")); | |
332 | auto_cap.RegisterControl(m_genericDirCtrl1, wxT("wxGenericDirCtrl")); | |
333 | auto_cap.RegisterControl(m_dirPicker1, wxT("wxDirPickerCtrl"), AJ_RegionAdjust); | |
334 | ||
335 | auto_cap.RegisterPageTurn(); | |
336 | ||
337 | auto_cap.RegisterControl(m_choice1, AJ_Dropdown); | |
338 | auto_cap.RegisterControl(m_comboBox1, AJ_Dropdown); | |
339 | auto_cap.RegisterControl(m_bmpComboBox1, AJ_Dropdown); | |
340 | auto_cap.RegisterControl(m_ownerDrawnComboBox1, AJ_Dropdown); | |
341 | auto_cap.RegisterControl(m_comboCtrl1, AJ_Dropdown|AJ_Union); | |
342 | auto_cap.RegisterControl(m_comboCtrl2, AJ_Dropdown|AJ_UnionEnd); | |
343 | ||
344 | auto_cap.CaptureAll(); | |
345 | ||
60a2264d FM |
346 | wxMessageBox(_("All screenshots were generated successfully in the folder:\n ") + dir, |
347 | _("Success"), wxOK|wxICON_INFORMATION, this); | |
0d5eda9c | 348 | } |