]>
git.saurik.com Git - wxWidgets.git/blob - utils/screenshotgen/src/screenshot_main.cpp
02c3ef537511c23a087a07681e3c0a5bff7d93d9
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: screenshot_main.cpp
3 // Purpose: Implement the Application Frame
4 // Author: Utensil Candel (UtensilCandel@@gmail.com)
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
9 // For compilers that support precompilation, includes "wx/wx.h".
10 #include "wx/wxprec.h"
16 // for all others, include the necessary headers
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>
27 #include <wx/aboutdlg.h>
28 #include <wx/msgdlg.h>
29 #include <wx/dcscreen.h>
30 #include <wx/filesys.h>
33 #include "screenshot_main.h"
34 #include "ctrlmaskout.h"
35 #include "autocapture.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 ScreenshotFrame :: ScreenshotFrame ( wxFrame
* frame
)
43 #if SCREENSHOTGEN_USE_AUI
50 statusBar
-> SetStatusText ( _ ( "Welcome to the Automatic Screenshot Generator!" ), 0 );
53 // We will hold one ctrlmaskout during the whole life time of the main frame
54 m_maskout
= new CtrlMaskOut ();
56 // At the begining, we are not specifying the rect region
57 capturingRect
= false ;
59 // Do some further customization on some controls generated by wxFormBuilder
61 #if SCREENSHOTGEN_USE_AUI
62 // Somehow it will be very small after I move to Aui
68 ScreenshotFrame ::~ ScreenshotFrame ()
74 Do some further customization on some controls generated by wxFormBuilder.
76 wxFormBuilder does not allow customizations on some controls;
77 e.g. you cannot load a richtext file in a wxRichtextCtrl during initialization.
79 Those customizations will be done here.
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.
86 void ScreenshotFrame :: InitFBControls ()
88 // For some reason, wxFormBuilder does not set the scrollbar range
89 m_scrollBar1
-> SetScrollbar ( 50 , 1 , 100 , 1 );
91 // Do the default selection for wxComboBox
92 m_comboBox1
-> Select ( 0 );
94 // To look better under gtk
96 m_comboBox1
-> Delete ( 4 );
99 // Add a root and some nodes for wxTreeCtrl
100 wxTreeItemId root
= m_treeCtrl1
-> AddRoot ( _ ( "wxTreeCtrl" ));
101 m_treeCtrl1
-> AppendItem ( root
, _ ( "Node1" ));
102 wxTreeItemId node2
= m_treeCtrl1
-> AppendItem ( root
, _ ( "Node2" ));
103 m_treeCtrl1
-> AppendItem ( node2
, _ ( "Node3" ));
104 m_treeCtrl1
-> ExpandAll ();
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
));
110 // Check the first item in wxCheckListBox
111 m_checkList1
-> Check ( 0 );
113 // Load richtext.xml into wxRichtextCtrl
114 m_richText1
-> LoadFile ( _T ( "richtext.xml" ));
115 //m_richText1->ShowPosition(335);
117 // select first page in the main notebook ctrl
118 m_notebook1
-> ChangeSelection ( 0 );
120 // set minimum size hints
121 GetSizer ()-> SetSizeHints ( this );
126 // ----------------------------------------------------------------------------
127 // ScreenshotFrame - event handlers
128 // ----------------------------------------------------------------------------
130 void ScreenshotFrame :: OnClose ( wxCloseEvent
& WXUNUSED ( event
))
135 void ScreenshotFrame :: OnQuit ( wxCommandEvent
& WXUNUSED ( event
))
140 void ScreenshotFrame :: OnSeeScreenshots ( wxCommandEvent
& WXUNUSED ( event
))
142 wxString defaultDir
= m_maskout
-> GetDefaultDirectory ();
144 // Check if defaultDir already existed
145 if (! wxDirExists ( defaultDir
))
148 // Use the native file browser to open defaultDir
149 wxLaunchDefaultBrowser ( wxFileSystem :: FileNameToURL ( defaultDir
));
152 void ScreenshotFrame :: OnAbout ( wxCommandEvent
& WXUNUSED ( event
))
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" ));
163 void ScreenshotFrame :: OnCaptureFullScreen ( wxCommandEvent
& WXUNUSED ( event
))
165 // Create a DC for the whole screen area
168 // Get the size of the screenDC
169 wxCoord screenWidth
, screenHeight
;
170 dcScreen
. GetSize (& screenWidth
, & screenHeight
);
172 m_maskout
-> Capture ( 0 , 0 , screenWidth
, screenHeight
, _T ( "fullscreen" ));
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 );
180 void ScreenshotFrame :: OnCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
182 capturingRect
= true ;
183 wxMenuBar
* menubar
= this -> GetMenuBar ();
184 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( false );
185 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( true );
187 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
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
);
194 void ScreenshotFrame :: OnEndCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
196 capturingRect
= false ;
197 wxMenuBar
* menubar
= this -> GetMenuBar ();
198 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( true );
199 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( false );
201 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
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
);
208 void ScreenshotFrame :: OnNotebookPageChanging (
209 #if SCREENSHOTGEN_USE_AUI
210 wxAuiNotebookEvent
& event
212 wxNotebookEvent
& event
222 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetOldSelection ());
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
);
231 void ScreenshotFrame :: OnNotebookPageChanged (
232 #if SCREENSHOTGEN_USE_AUI
233 wxAuiNotebookEvent
& event
235 wxNotebookEvent
& event
245 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetSelection ());
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
);
254 void ScreenshotFrame :: OnCaptureAllControls ( wxCommandEvent
& WXUNUSED ( event
))
256 wxString dir
= m_maskout
-> GetDefaultDirectoryAbsPath ();
258 // check if there are other screenshots taken before
259 if ( wxFileName :: DirExists ( dir
))
261 int choice
= wxMessageBox ( _ ( "It seems that you have already generated some screenshots. \n\n Click YES to delete them all (recommended) or NO to preserve them. \n Click CANCEL to cancel this auto-capture operation." ),
262 _ ( "Delete existing screenshots?" ),
263 wxYES_NO
| wxCANCEL
| wxICON_QUESTION
, this );
269 wxDir :: GetAllFiles ( dir
, & files
, wxT ( "*.png" ), wxDIR_FILES
);
271 // remove all PNG files from the screenshots folder
272 int n
= files
. GetCount ();
273 for ( int i
= 0 ; i
< n
; ++ i
)
274 wxRemoveFile ( files
[ i
]);
279 case wxCANCEL
: return ;
283 // proceed with the automatic screenshot capture
287 AutoCaptureMechanism
auto_cap ( m_notebook1
);
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
);
306 auto_cap
. RegisterPageTurn ();
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" ));
315 auto_cap
. RegisterControl ( m_animationCtrl1
);
316 auto_cap
. RegisterControl ( m_collPane1
, wxT ( "wxCollapsiblePane" ), AJ_Union
);
317 auto_cap
. RegisterControl ( m_collPane2
, AJ_UnionEnd
);
319 auto_cap
. RegisterPageTurn ();
321 auto_cap
. RegisterControl ( m_textCtrl1
, AJ_Union
);
322 auto_cap
. RegisterControl ( m_textCtrl2
, AJ_UnionEnd
);
323 auto_cap
. RegisterControl ( m_richText1
);
325 auto_cap
. RegisterPageTurn ();
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
);
335 auto_cap
. RegisterPageTurn ();
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
);
344 auto_cap
. CaptureAll ();
346 wxMessageBox ( _ ( "All screenshots were generated successfully in the folder: \n " ) + dir
,
347 _ ( "Success" ), wxOK
| wxICON_INFORMATION
, this );