]>
git.saurik.com Git - wxWidgets.git/blob - utils/screenshotgen/src/screenshot_main.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: screenshot_main.cpp
3 // Purpose: Implements the window containing all controls.
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 wxWidgets headers)
21 #include "wx/aboutdlg.h"
23 #include "wx/filesys.h"
25 #include "screenshot_main.h"
26 #include "ctrlmaskout.h"
27 #include "autocapture.h"
29 #include "bitmaps/play.xpm"
30 #include "bitmaps/stop.xpm"
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 ScreenshotFrame :: ScreenshotFrame ( wxFrame
* frame
)
38 #if SCREENSHOTGEN_USE_AUI
45 statusBar
-> SetStatusText ( _ ( "Welcome to the Automatic Screenshot Generator!" ), 0 );
48 // We will hold one ctrlmaskout during the whole life time of the main frame
49 m_maskout
= new CtrlMaskOut ();
51 // At the begining, we are not specifying the rect region
52 capturingRect
= false ;
54 // Do some further customization on some controls generated by wxFormBuilder
56 #if SCREENSHOTGEN_USE_AUI
57 // Somehow it will be very small after I move to Aui
63 ScreenshotFrame ::~ ScreenshotFrame ()
69 Do some further customization on some controls.
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.
75 void ScreenshotFrame :: InitFBControls ()
77 m_scrollBar1
-> SetScrollbar ( 50 , 1 , 100 , 1 );
79 // Do the default selection for wxComboBox
80 m_comboBox1
-> Select ( 0 );
82 // To look better under gtk
84 m_comboBox1
-> Delete ( 4 );
87 // Add a root and some nodes for wxTreeCtrl
88 wxTreeItemId root
= m_treeCtrl1
-> AddRoot ( _ ( "wxTreeCtrl" ));
89 m_treeCtrl1
-> AppendItem ( root
, _ ( "Node1" ));
90 wxTreeItemId node2
= m_treeCtrl1
-> AppendItem ( root
, _ ( "Node2" ));
91 m_treeCtrl1
-> AppendItem ( node2
, _ ( "Node3" ));
92 m_treeCtrl1
-> ExpandAll ();
94 // Add items into wxListCtrl
95 m_listCtrl1
-> InsertColumn ( 0 , "Names" );
96 m_listCtrl1
-> InsertColumn ( 1 , "Values" );
97 for ( long index
= 0 ; index
< 5 ; index
++) {
98 m_listCtrl1
-> InsertItem ( index
, wxString :: Format ( _ ( "Item %d " ), index
));
99 m_listCtrl1
-> SetItem ( index
, 1 , wxString :: Format ( " %d " , index
));
102 // Init file and dir pickers
104 #if defined(__WXMSW__)
105 file
= "C: \\ Windows \\ explorer.exe" ;
111 m_filePicker1
-> SetPath ( file
);
112 m_dirPicker1
-> SetPath ( dir
);
114 // Check the first item in wxCheckListBox
115 m_checkList1
-> Check ( 0 );
117 // Load richtext.xml into wxRichtextCtrl
118 m_richText1
-> LoadFile ( _T ( "richtext.xml" ));
119 //m_richText1->ShowPosition(335);
121 // select first page in the main notebook ctrl
122 m_notebook1
-> ChangeSelection ( 0 );
124 // set minimum size hints
125 GetSizer ()-> SetSizeHints ( this );
127 // add bitmaps to the menus
128 m_menuCapRect
-> SetBitmap ( wxIcon ( play_xpm
) );
129 m_menuEndCapRect
-> SetBitmap ( wxIcon ( stop_xpm
) );
134 // ----------------------------------------------------------------------------
135 // ScreenshotFrame - event handlers
136 // ----------------------------------------------------------------------------
138 void ScreenshotFrame :: OnClose ( wxCloseEvent
& WXUNUSED ( event
))
143 void ScreenshotFrame :: OnQuit ( wxCommandEvent
& WXUNUSED ( event
))
148 void ScreenshotFrame :: OnSeeScreenshots ( wxCommandEvent
& WXUNUSED ( event
))
150 wxString defaultDir
= m_maskout
-> GetDefaultDirectory ();
152 // Check if defaultDir already existed
153 if (! wxDirExists ( defaultDir
))
156 // Use the native file browser to open defaultDir
157 wxLaunchDefaultBrowser ( wxFileSystem :: FileNameToURL ( defaultDir
));
160 void ScreenshotFrame :: OnAbout ( wxCommandEvent
& WXUNUSED ( event
))
162 wxAboutDialogInfo info
;
163 info
. SetName ( _ ( "Automatic Screenshot Generator" ));
164 info
. SetVersion ( _ ( "1.0" ));
165 info
. SetDescription ( _ ( "This utility automatically creates screenshots of wxWidgets controls for use in wxWidgets documentation." ));
166 info
. SetCopyright ( _T ( "(C) 2008 Utensil Candel" ));
171 void ScreenshotFrame :: OnCaptureFullScreen ( wxCommandEvent
& WXUNUSED ( event
))
173 // Create a DC for the whole screen area
176 // Get the size of the screenDC
177 wxCoord screenWidth
, screenHeight
;
178 dcScreen
. GetSize (& screenWidth
, & screenHeight
);
180 m_maskout
-> Capture ( 0 , 0 , screenWidth
, screenHeight
, _T ( "fullscreen" ));
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 );
188 void ScreenshotFrame :: OnCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
190 capturingRect
= true ;
191 wxMenuBar
* menubar
= this -> GetMenuBar ();
192 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( false );
193 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( true );
195 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
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
);
202 void ScreenshotFrame :: OnEndCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
204 capturingRect
= false ;
205 wxMenuBar
* menubar
= this -> GetMenuBar ();
206 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( true );
207 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( false );
209 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
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
);
216 void ScreenshotFrame :: OnNotebookPageChanging (
217 #if SCREENSHOTGEN_USE_AUI
218 wxAuiNotebookEvent
& event
220 wxNotebookEvent
& event
230 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetOldSelection ());
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
);
239 void ScreenshotFrame :: OnNotebookPageChanged (
240 #if SCREENSHOTGEN_USE_AUI
241 wxAuiNotebookEvent
& event
243 wxNotebookEvent
& event
253 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetSelection ());
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
);
262 void ScreenshotFrame :: OnCaptureAllControls ( wxCommandEvent
& WXUNUSED ( event
))
264 wxString dir
= m_maskout
-> GetDefaultDirectoryAbsPath ();
266 // check if there are other screenshots taken before
267 if ( wxFileName :: DirExists ( dir
))
269 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." ),
270 _ ( "Delete existing screenshots?" ),
271 wxYES_NO
| wxCANCEL
| wxICON_QUESTION
, this );
277 wxDir :: GetAllFiles ( dir
, & files
, wxT ( "*.png" ), wxDIR_FILES
);
279 // remove all PNG files from the screenshots folder
280 int n
= files
. GetCount ();
281 for ( int i
= 0 ; i
< n
; ++ i
)
282 wxRemoveFile ( files
[ i
]);
287 case wxCANCEL
: return ;
291 // proceed with the automatic screenshot capture
295 AutoCaptureMechanism
auto_cap ( m_notebook1
);
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
);
309 auto_cap
. RegisterControl ( m_hyperlink1
, wxT ( "wxHyperlinkCtrl" ));
310 auto_cap
. RegisterControl ( m_spinCtrl1
, AJ_RegionAdjust
);
311 auto_cap
. RegisterControl ( m_spinBtn1
);
312 auto_cap
. RegisterControl ( m_scrollBar1
);
314 auto_cap
. RegisterPageTurn ();
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" ));
323 auto_cap
. RegisterControl ( m_animationCtrl1
);
324 auto_cap
. RegisterControl ( m_collPane1
, wxT ( "wxCollapsiblePane" ), AJ_Union
);
325 auto_cap
. RegisterControl ( m_collPane2
, AJ_UnionEnd
);
327 auto_cap
. RegisterPageTurn ();
329 auto_cap
. RegisterControl ( m_textCtrl1
, AJ_Union
);
330 auto_cap
. RegisterControl ( m_textCtrl2
, AJ_UnionEnd
);
331 auto_cap
. RegisterControl ( m_richText1
);
333 auto_cap
. RegisterPageTurn ();
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
);
343 auto_cap
. RegisterPageTurn ();
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
);
352 auto_cap
. CaptureAll ();
354 wxMessageBox ( _ ( "All screenshots were generated successfully in the folder: \n " ) + dir
,
355 _ ( "Success" ), wxOK
| wxICON_INFORMATION
, this );