]>
git.saurik.com Git - wxWidgets.git/blob - utils/screenshotgen/src/screenshot_main.cpp
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"
37 #include "bitmaps/play.xpm"
38 #include "bitmaps/stop.xpm"
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 ScreenshotFrame :: ScreenshotFrame ( wxFrame
* frame
)
46 #if SCREENSHOTGEN_USE_AUI
53 statusBar
-> SetStatusText ( _ ( "Welcome to the Automatic Screenshot Generator!" ), 0 );
56 // We will hold one ctrlmaskout during the whole life time of the main frame
57 m_maskout
= new CtrlMaskOut ();
59 // At the begining, we are not specifying the rect region
60 capturingRect
= false ;
62 // Do some further customization on some controls generated by wxFormBuilder
64 #if SCREENSHOTGEN_USE_AUI
65 // Somehow it will be very small after I move to Aui
71 ScreenshotFrame ::~ ScreenshotFrame ()
77 Do some further customization on some controls generated by wxFormBuilder.
79 wxFormBuilder does not allow customizations on some controls;
80 e.g. you cannot load a richtext file in a wxRichtextCtrl during initialization.
82 Those customizations will be done here.
85 NB: under wxGTK for the radio button "unchecked" to be unchecked, it's
86 important to put the wxRB_GROUP style on the first wxRadioButton
87 (the one "checked") and no flags on the second one.
89 void ScreenshotFrame :: InitFBControls ()
91 // For some reason, wxFormBuilder does not set the scrollbar range
92 m_scrollBar1
-> SetScrollbar ( 50 , 1 , 100 , 1 );
94 // Do the default selection for wxComboBox
95 m_comboBox1
-> Select ( 0 );
97 // To look better under gtk
99 m_comboBox1
-> Delete ( 4 );
102 // Add a root and some nodes for wxTreeCtrl
103 wxTreeItemId root
= m_treeCtrl1
-> AddRoot ( _ ( "wxTreeCtrl" ));
104 m_treeCtrl1
-> AppendItem ( root
, _ ( "Node1" ));
105 wxTreeItemId node2
= m_treeCtrl1
-> AppendItem ( root
, _ ( "Node2" ));
106 m_treeCtrl1
-> AppendItem ( node2
, _ ( "Node3" ));
107 m_treeCtrl1
-> ExpandAll ();
109 // Add items into wxListCtrl
110 m_listCtrl1
-> InsertColumn ( 0 , "Names" );
111 m_listCtrl1
-> InsertColumn ( 1 , "Values" );
112 for ( long index
= 0 ; index
< 5 ; index
++) {
113 m_listCtrl1
-> InsertItem ( index
, wxString :: Format ( _ ( "Item %d " ), index
));
114 m_listCtrl1
-> SetItem ( index
, 1 , wxString :: Format ( " %d " , index
));
117 // Init file and dir pickers
119 #if defined(__WXMSW__)
120 file
= "C: \\ Windows \\ explorer.exe" ;
126 m_filePicker1
-> SetPath ( file
);
127 m_dirPicker1
-> SetPath ( dir
);
129 // Check the first item in wxCheckListBox
130 m_checkList1
-> Check ( 0 );
132 // Load richtext.xml into wxRichtextCtrl
133 m_richText1
-> LoadFile ( _T ( "richtext.xml" ));
134 //m_richText1->ShowPosition(335);
136 // select first page in the main notebook ctrl
137 m_notebook1
-> ChangeSelection ( 0 );
139 // set minimum size hints
140 GetSizer ()-> SetSizeHints ( this );
142 // add bitmaps to the menus
143 m_menuCapRect
-> SetBitmaps ( wxIcon ( play_xpm
) );
144 m_menuEndCapRect
-> SetBitmaps ( wxIcon ( stop_xpm
) );
149 // ----------------------------------------------------------------------------
150 // ScreenshotFrame - event handlers
151 // ----------------------------------------------------------------------------
153 void ScreenshotFrame :: OnClose ( wxCloseEvent
& WXUNUSED ( event
))
158 void ScreenshotFrame :: OnQuit ( wxCommandEvent
& WXUNUSED ( event
))
163 void ScreenshotFrame :: OnSeeScreenshots ( wxCommandEvent
& WXUNUSED ( event
))
165 wxString defaultDir
= m_maskout
-> GetDefaultDirectory ();
167 // Check if defaultDir already existed
168 if (! wxDirExists ( defaultDir
))
171 // Use the native file browser to open defaultDir
172 wxLaunchDefaultBrowser ( wxFileSystem :: FileNameToURL ( defaultDir
));
175 void ScreenshotFrame :: OnAbout ( wxCommandEvent
& WXUNUSED ( event
))
177 wxAboutDialogInfo info
;
178 info
. SetName ( _ ( "Automatic Screenshot Generator" ));
179 info
. SetVersion ( _ ( "1.0" ));
180 info
. SetDescription ( _ ( "This utility automatically creates screenshots of wxWidgets controls for use in wxWidgets documentation." ));
181 info
. SetCopyright ( _T ( "(C) 2008 Utensil Candel" ));
186 void ScreenshotFrame :: OnCaptureFullScreen ( wxCommandEvent
& WXUNUSED ( event
))
188 // Create a DC for the whole screen area
191 // Get the size of the screenDC
192 wxCoord screenWidth
, screenHeight
;
193 dcScreen
. GetSize (& screenWidth
, & screenHeight
);
195 m_maskout
-> Capture ( 0 , 0 , screenWidth
, screenHeight
, _T ( "fullscreen" ));
198 wxMessageBox ( _ ( "A screenshot of the entire screen was saved as: \n\n " ) +
199 m_maskout
-> GetDefaultDirectoryAbsPath () + wxFileName :: GetPathSeparator () + "fullscreen.png" ,
200 _ ( "Full screen capture" ), wxICON_INFORMATION
| wxOK
, this );
203 void ScreenshotFrame :: OnCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
205 capturingRect
= true ;
206 wxMenuBar
* menubar
= this -> GetMenuBar ();
207 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( false );
208 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( true );
210 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
212 thePage
-> Connect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
213 thePage
-> Connect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
214 thePage
-> Connect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
217 void ScreenshotFrame :: OnEndCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
219 capturingRect
= false ;
220 wxMenuBar
* menubar
= this -> GetMenuBar ();
221 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( true );
222 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( false );
224 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
226 thePage
-> Disconnect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
227 thePage
-> Disconnect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
228 thePage
-> Disconnect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
231 void ScreenshotFrame :: OnNotebookPageChanging (
232 #if SCREENSHOTGEN_USE_AUI
233 wxAuiNotebookEvent
& event
235 wxNotebookEvent
& event
245 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetOldSelection ());
247 thePage
-> Disconnect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
248 thePage
-> Disconnect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
249 thePage
-> Disconnect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
254 void ScreenshotFrame :: OnNotebookPageChanged (
255 #if SCREENSHOTGEN_USE_AUI
256 wxAuiNotebookEvent
& event
258 wxNotebookEvent
& event
268 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetSelection ());
270 thePage
-> Connect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
271 thePage
-> Connect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
272 thePage
-> Connect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
277 void ScreenshotFrame :: OnCaptureAllControls ( wxCommandEvent
& WXUNUSED ( event
))
279 wxString dir
= m_maskout
-> GetDefaultDirectoryAbsPath ();
281 // check if there are other screenshots taken before
282 if ( wxFileName :: DirExists ( dir
))
284 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." ),
285 _ ( "Delete existing screenshots?" ),
286 wxYES_NO
| wxCANCEL
| wxICON_QUESTION
, this );
292 wxDir :: GetAllFiles ( dir
, & files
, wxT ( "*.png" ), wxDIR_FILES
);
294 // remove all PNG files from the screenshots folder
295 int n
= files
. GetCount ();
296 for ( int i
= 0 ; i
< n
; ++ i
)
297 wxRemoveFile ( files
[ i
]);
302 case wxCANCEL
: return ;
306 // proceed with the automatic screenshot capture
310 AutoCaptureMechanism
auto_cap ( m_notebook1
);
312 auto_cap
. RegisterControl ( m_button1
);
313 auto_cap
. RegisterControl ( m_staticText1
);
314 auto_cap
. RegisterControl ( m_checkBox1
, AJ_Union
);
315 auto_cap
. RegisterControl ( m_checkBox2
, AJ_UnionEnd
);
316 auto_cap
. RegisterControl ( m_radioBtn1
, AJ_Union
);
317 auto_cap
. RegisterControl ( m_radioBtn2
, AJ_UnionEnd
);
318 auto_cap
. RegisterControl ( m_bpButton1
);
319 auto_cap
. RegisterControl ( m_bitmap1
);
320 auto_cap
. RegisterControl ( m_gauge1
, wxT ( "wxGauge" ));
321 auto_cap
. RegisterControl ( m_slider1
);
322 auto_cap
. RegisterControl ( m_toggleBtn1
, AJ_Union
);
323 auto_cap
. RegisterControl ( m_toggleBtn2
, AJ_UnionEnd
);
324 auto_cap
. RegisterControl ( m_hyperlink1
);
325 auto_cap
. RegisterControl ( m_spinCtrl1
, AJ_RegionAdjust
);
326 auto_cap
. RegisterControl ( m_spinBtn1
);
327 auto_cap
. RegisterControl ( m_scrollBar1
);
329 auto_cap
. RegisterPageTurn ();
331 auto_cap
. RegisterControl ( m_checkList1
);
332 auto_cap
. RegisterControl ( m_listBox1
);
333 auto_cap
. RegisterControl ( m_radioBox1
);
334 auto_cap
. RegisterControl ( m_staticBox1
);
335 auto_cap
. RegisterControl ( m_treeCtrl1
);
336 auto_cap
. RegisterControl ( m_listCtrl1
, wxT ( "wxListCtrl" ));
338 auto_cap
. RegisterControl ( m_animationCtrl1
);
339 auto_cap
. RegisterControl ( m_collPane1
, wxT ( "wxCollapsiblePane" ), AJ_Union
);
340 auto_cap
. RegisterControl ( m_collPane2
, AJ_UnionEnd
);
342 auto_cap
. RegisterPageTurn ();
344 auto_cap
. RegisterControl ( m_textCtrl1
, AJ_Union
);
345 auto_cap
. RegisterControl ( m_textCtrl2
, AJ_UnionEnd
);
346 auto_cap
. RegisterControl ( m_richText1
);
348 auto_cap
. RegisterPageTurn ();
350 auto_cap
. RegisterControl ( m_colourPicker1
, wxT ( "wxColourPickerCtrl" ));
351 auto_cap
. RegisterControl ( m_fontPicker1
, wxT ( "wxFontPickerCtrl" ));
352 auto_cap
. RegisterControl ( m_filePicker1
, wxT ( "wxFilePickerCtrl" ), AJ_RegionAdjust
);
353 auto_cap
. RegisterControl ( m_calendar1
, wxT ( "wxCalendarCtrl" ), AJ_RegionAdjust
);
354 auto_cap
. RegisterControl ( m_datePicker1
, wxT ( "wxDatePickerCtrl" ));
355 auto_cap
. RegisterControl ( m_genericDirCtrl1
, wxT ( "wxGenericDirCtrl" ));
356 auto_cap
. RegisterControl ( m_dirPicker1
, wxT ( "wxDirPickerCtrl" ), AJ_RegionAdjust
);
358 auto_cap
. RegisterPageTurn ();
360 auto_cap
. RegisterControl ( m_choice1
, AJ_Dropdown
);
361 auto_cap
. RegisterControl ( m_comboBox1
, AJ_Dropdown
);
362 auto_cap
. RegisterControl ( m_bmpComboBox1
, AJ_Dropdown
);
363 auto_cap
. RegisterControl ( m_ownerDrawnComboBox1
, AJ_Dropdown
);
364 auto_cap
. RegisterControl ( m_comboCtrl1
, AJ_Dropdown
| AJ_Union
);
365 auto_cap
. RegisterControl ( m_comboCtrl2
, AJ_Dropdown
| AJ_UnionEnd
);
367 auto_cap
. CaptureAll ();
369 wxMessageBox ( _ ( "All screenshots were generated successfully in the folder: \n " ) + dir
,
370 _ ( "Success" ), wxOK
| wxICON_INFORMATION
, this );