]>
git.saurik.com Git - wxWidgets.git/blob - utils/screenshotgen/src/screenshot_main.cpp
00f95ac13a5bc65d79fca4b51e1fab19e640107b
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.
81 void ScreenshotFrame :: InitFBControls ()
83 // Do the default selection for wxComboBox
84 m_comboBox1
-> Select ( 0 );
86 // To look better under gtk
88 m_comboBox1
-> Delete ( 4 );
91 // Add a root and some nodes for wxTreeCtrl
92 wxTreeItemId root
= m_treeCtrl1
-> AddRoot ( _ ( "wxTreeCtrl" ));
93 m_treeCtrl1
-> AppendItem ( root
, _ ( "Node1" ));
94 wxTreeItemId node2
= m_treeCtrl1
-> AppendItem ( root
, _ ( "Node2" ));
95 m_treeCtrl1
-> AppendItem ( node2
, _ ( "Node3" ));
96 m_treeCtrl1
-> ExpandAll ();
98 // Add items into wxListCtrl
99 for ( long index
= 0 ; index
< 5 ; index
++)
100 m_listCtrl1
-> InsertItem ( index
, wxString :: Format ( _ ( "Item \n (0, %d )" ), index
));
102 // Check the first item in wxCheckListBox
103 m_checkList1
-> Check ( 0 );
105 // Load richtext.xml into wxRichtextCtrl
106 m_richText1
-> LoadFile ( _T ( "richtext.xml" ));
107 //m_richText1->ShowPosition(335);
109 // select first page in the main notebook ctrl
110 m_notebook1
-> ChangeSelection ( 0 );
112 // set minimum size hints
113 GetSizer ()-> SetSizeHints ( this );
118 // ----------------------------------------------------------------------------
119 // ScreenshotFrame - event handlers
120 // ----------------------------------------------------------------------------
122 void ScreenshotFrame :: OnClose ( wxCloseEvent
& WXUNUSED ( event
))
127 void ScreenshotFrame :: OnQuit ( wxCommandEvent
& WXUNUSED ( event
))
132 void ScreenshotFrame :: OnSeeScreenshots ( wxCommandEvent
& WXUNUSED ( event
))
134 wxString defaultDir
= m_maskout
-> GetDefaultDirectory ();
136 // Check if defaultDir already existed
137 if (! wxDirExists ( defaultDir
))
140 // Use the native file browser to open defaultDir
141 wxLaunchDefaultBrowser ( wxFileSystem :: FileNameToURL ( defaultDir
));
144 void ScreenshotFrame :: OnAbout ( wxCommandEvent
& WXUNUSED ( event
))
146 wxAboutDialogInfo info
;
147 info
. SetName ( _ ( "Automatic Screenshot Generator" ));
148 info
. SetVersion ( _ ( "1.0" ));
149 info
. SetDescription ( _ ( "This utility automatically creates screenshots of wxWidgets controls for ues in wxWidgets documentation." ));
150 info
. SetCopyright ( _T ( "(C) 2008 Utensil Candel" ));
155 void ScreenshotFrame :: OnCaptureFullScreen ( wxCommandEvent
& WXUNUSED ( event
))
157 // Create a DC for the whole screen area
160 // Get the size of the screenDC
161 wxCoord screenWidth
, screenHeight
;
162 dcScreen
. GetSize (& screenWidth
, & screenHeight
);
164 m_maskout
-> Capture ( 0 , 0 , screenWidth
, screenHeight
, _T ( "fullscreen" ));
167 wxMessageBox ( _ ( "A screenshot of the entire screen was saved as: \n\n " ) +
168 m_maskout
-> GetDefaultDirectoryAbsPath () + wxFileName :: GetPathSeparator () + "fullscreen.png" ,
169 _ ( "Full screen capture" ), wxICON_INFORMATION
| wxOK
, this );
172 void ScreenshotFrame :: OnCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
174 capturingRect
= true ;
175 wxMenuBar
* menubar
= this -> GetMenuBar ();
176 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( false );
177 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( true );
179 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
181 thePage
-> Connect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
182 thePage
-> Connect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
183 thePage
-> Connect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
186 void ScreenshotFrame :: OnEndCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
188 capturingRect
= false ;
189 wxMenuBar
* menubar
= this -> GetMenuBar ();
190 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( true );
191 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( false );
193 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
195 thePage
-> Disconnect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
196 thePage
-> Disconnect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
197 thePage
-> Disconnect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
200 void ScreenshotFrame :: OnNotebookPageChanging (
201 #if SCREENSHOTGEN_USE_AUI
202 wxAuiNotebookEvent
& event
204 wxNotebookEvent
& event
214 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetOldSelection ());
216 thePage
-> Disconnect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
217 thePage
-> Disconnect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
218 thePage
-> Disconnect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
223 void ScreenshotFrame :: OnNotebookPageChanged (
224 #if SCREENSHOTGEN_USE_AUI
225 wxAuiNotebookEvent
& event
227 wxNotebookEvent
& event
237 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetSelection ());
239 thePage
-> Connect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
240 thePage
-> Connect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
241 thePage
-> Connect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
246 void ScreenshotFrame :: OnCaptureAllControls ( wxCommandEvent
& WXUNUSED ( event
))
248 wxString dir
= m_maskout
-> GetDefaultDirectoryAbsPath ();
250 // check if there are other screenshots taken before
251 if ( wxFileName :: DirExists ( dir
))
253 int choice
= wxMessageBox ( _ ( "It seems that you have already generated some screenshots. \n Click YES to delete them all (recommended) or NO to preserve them. \n Click CANCEL to cancel this auto-capture operation." ),
254 _ ( "Delete existing screenshots?" ),
255 wxYES_NO
| wxCANCEL
| wxICON_QUESTION
, this );
261 wxDir :: GetAllFiles ( dir
, & files
, wxT ( "*.png" ), wxDIR_FILES
);
263 // remove all PNG files from the screenshots folder
264 int n
= files
. GetCount ();
265 for ( int i
= 0 ; i
< n
; ++ i
)
266 wxRemoveFile ( files
[ i
]);
271 case wxCANCEL
: return ;
275 // proceed with the automatic screenshot capture
279 AutoCaptureMechanism
auto_cap ( m_notebook1
);
281 auto_cap
. RegisterControl ( m_button1
);
282 auto_cap
. RegisterControl ( m_staticText1
);
283 auto_cap
. RegisterControl ( m_checkBox1
, AJ_Union
);
284 auto_cap
. RegisterControl ( m_checkBox2
, AJ_UnionEnd
);
285 auto_cap
. RegisterControl ( m_radioBtn1
, AJ_Union
);
286 auto_cap
. RegisterControl ( m_radioBtn2
, AJ_UnionEnd
);
287 auto_cap
. RegisterControl ( m_bpButton1
);
288 auto_cap
. RegisterControl ( m_bitmap1
);
289 auto_cap
. RegisterControl ( m_gauge1
, wxT ( "wxGauge" ));
290 auto_cap
. RegisterControl ( m_slider1
);
291 auto_cap
. RegisterControl ( m_toggleBtn1
, AJ_Union
);
292 auto_cap
. RegisterControl ( m_toggleBtn2
, AJ_UnionEnd
);
293 auto_cap
. RegisterControl ( m_hyperlink1
);
294 auto_cap
. RegisterControl ( m_spinCtrl1
, AJ_RegionAdjust
);
295 auto_cap
. RegisterControl ( m_spinBtn1
);
296 auto_cap
. RegisterControl ( m_scrollBar1
);
298 auto_cap
. RegisterPageTurn ();
300 auto_cap
. RegisterControl ( m_checkList1
);
301 auto_cap
. RegisterControl ( m_listBox1
);
302 auto_cap
. RegisterControl ( m_radioBox1
);
303 auto_cap
. RegisterControl ( m_staticBox1
);
304 auto_cap
. RegisterControl ( m_treeCtrl1
);
305 auto_cap
. RegisterControl ( m_listCtrl1
, wxT ( "wxListCtrl" ));
307 auto_cap
. RegisterControl ( m_animationCtrl1
);
308 auto_cap
. RegisterControl ( m_collPane1
, wxT ( "wxCollapsiblePane" ), AJ_Union
);
309 auto_cap
. RegisterControl ( m_collPane2
, AJ_UnionEnd
);
311 auto_cap
. RegisterPageTurn ();
313 auto_cap
. RegisterControl ( m_textCtrl1
, AJ_Union
);
314 auto_cap
. RegisterControl ( m_textCtrl2
, AJ_UnionEnd
);
315 auto_cap
. RegisterControl ( m_richText1
);
317 auto_cap
. RegisterPageTurn ();
319 auto_cap
. RegisterControl ( m_colourPicker1
, wxT ( "wxColourPickerCtrl" ));
320 auto_cap
. RegisterControl ( m_fontPicker1
, wxT ( "wxFontPickerCtrl" ));
321 auto_cap
. RegisterControl ( m_filePicker1
, wxT ( "wxFilePickerCtrl" ), AJ_RegionAdjust
);
322 auto_cap
. RegisterControl ( m_calendar1
, wxT ( "wxCalendarCtrl" ), AJ_RegionAdjust
);
323 auto_cap
. RegisterControl ( m_datePicker1
, wxT ( "wxDatePickerCtrl" ));
324 auto_cap
. RegisterControl ( m_genericDirCtrl1
, wxT ( "wxGenericDirCtrl" ));
325 auto_cap
. RegisterControl ( m_dirPicker1
, wxT ( "wxDirPickerCtrl" ), AJ_RegionAdjust
);
327 auto_cap
. RegisterPageTurn ();
329 auto_cap
. RegisterControl ( m_choice1
, AJ_Dropdown
);
330 auto_cap
. RegisterControl ( m_comboBox1
, AJ_Dropdown
);
331 auto_cap
. RegisterControl ( m_bmpComboBox1
, AJ_Dropdown
);
332 auto_cap
. RegisterControl ( m_ownerDrawnComboBox1
, AJ_Dropdown
);
333 auto_cap
. RegisterControl ( m_comboCtrl1
, AJ_Dropdown
| AJ_Union
);
334 auto_cap
. RegisterControl ( m_comboCtrl2
, AJ_Dropdown
| AJ_UnionEnd
);
336 auto_cap
. CaptureAll ();
338 wxMessageBox ( _ ( "All screenshots were generated successfully in the folder: \n " ) + dir
,
339 _ ( "Success" ), wxOK
| wxICON_INFORMATION
, this );