]>
git.saurik.com Git - wxWidgets.git/blob - utils/screenshotgen/src/screenshot_main.cpp
165f71441455e005ddc2b1dd10ffd0b776d1ca07
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 // Check the first item in wxCheckListBox
118 m_checkList1
-> Check ( 0 );
120 // Load richtext.xml into wxRichtextCtrl
121 m_richText1
-> LoadFile ( _T ( "richtext.xml" ));
122 //m_richText1->ShowPosition(335);
124 // select first page in the main notebook ctrl
125 m_notebook1
-> ChangeSelection ( 0 );
127 // set minimum size hints
128 GetSizer ()-> SetSizeHints ( this );
130 // add bitmaps to the menus
131 m_menuCapRect
-> SetBitmaps ( wxIcon ( play_xpm
) );
132 m_menuEndCapRect
-> SetBitmaps ( wxIcon ( stop_xpm
) );
137 // ----------------------------------------------------------------------------
138 // ScreenshotFrame - event handlers
139 // ----------------------------------------------------------------------------
141 void ScreenshotFrame :: OnClose ( wxCloseEvent
& WXUNUSED ( event
))
146 void ScreenshotFrame :: OnQuit ( wxCommandEvent
& WXUNUSED ( event
))
151 void ScreenshotFrame :: OnSeeScreenshots ( wxCommandEvent
& WXUNUSED ( event
))
153 wxString defaultDir
= m_maskout
-> GetDefaultDirectory ();
155 // Check if defaultDir already existed
156 if (! wxDirExists ( defaultDir
))
159 // Use the native file browser to open defaultDir
160 wxLaunchDefaultBrowser ( wxFileSystem :: FileNameToURL ( defaultDir
));
163 void ScreenshotFrame :: OnAbout ( wxCommandEvent
& WXUNUSED ( event
))
165 wxAboutDialogInfo info
;
166 info
. SetName ( _ ( "Automatic Screenshot Generator" ));
167 info
. SetVersion ( _ ( "1.0" ));
168 info
. SetDescription ( _ ( "This utility automatically creates screenshots of wxWidgets controls for ues in wxWidgets documentation." ));
169 info
. SetCopyright ( _T ( "(C) 2008 Utensil Candel" ));
174 void ScreenshotFrame :: OnCaptureFullScreen ( wxCommandEvent
& WXUNUSED ( event
))
176 // Create a DC for the whole screen area
179 // Get the size of the screenDC
180 wxCoord screenWidth
, screenHeight
;
181 dcScreen
. GetSize (& screenWidth
, & screenHeight
);
183 m_maskout
-> Capture ( 0 , 0 , screenWidth
, screenHeight
, _T ( "fullscreen" ));
186 wxMessageBox ( _ ( "A screenshot of the entire screen was saved as: \n\n " ) +
187 m_maskout
-> GetDefaultDirectoryAbsPath () + wxFileName :: GetPathSeparator () + "fullscreen.png" ,
188 _ ( "Full screen capture" ), wxICON_INFORMATION
| wxOK
, this );
191 void ScreenshotFrame :: OnCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
193 capturingRect
= true ;
194 wxMenuBar
* menubar
= this -> GetMenuBar ();
195 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( false );
196 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( true );
198 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
200 thePage
-> Connect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
201 thePage
-> Connect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
202 thePage
-> Connect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
205 void ScreenshotFrame :: OnEndCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
207 capturingRect
= false ;
208 wxMenuBar
* menubar
= this -> GetMenuBar ();
209 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( true );
210 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( false );
212 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
214 thePage
-> Disconnect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
215 thePage
-> Disconnect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
216 thePage
-> Disconnect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
219 void ScreenshotFrame :: OnNotebookPageChanging (
220 #if SCREENSHOTGEN_USE_AUI
221 wxAuiNotebookEvent
& event
223 wxNotebookEvent
& event
233 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetOldSelection ());
235 thePage
-> Disconnect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
236 thePage
-> Disconnect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
237 thePage
-> Disconnect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
242 void ScreenshotFrame :: OnNotebookPageChanged (
243 #if SCREENSHOTGEN_USE_AUI
244 wxAuiNotebookEvent
& event
246 wxNotebookEvent
& event
256 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetSelection ());
258 thePage
-> Connect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
259 thePage
-> Connect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
260 thePage
-> Connect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
265 void ScreenshotFrame :: OnCaptureAllControls ( wxCommandEvent
& WXUNUSED ( event
))
267 wxString dir
= m_maskout
-> GetDefaultDirectoryAbsPath ();
269 // check if there are other screenshots taken before
270 if ( wxFileName :: DirExists ( dir
))
272 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." ),
273 _ ( "Delete existing screenshots?" ),
274 wxYES_NO
| wxCANCEL
| wxICON_QUESTION
, this );
280 wxDir :: GetAllFiles ( dir
, & files
, wxT ( "*.png" ), wxDIR_FILES
);
282 // remove all PNG files from the screenshots folder
283 int n
= files
. GetCount ();
284 for ( int i
= 0 ; i
< n
; ++ i
)
285 wxRemoveFile ( files
[ i
]);
290 case wxCANCEL
: return ;
294 // proceed with the automatic screenshot capture
298 AutoCaptureMechanism
auto_cap ( m_notebook1
);
300 auto_cap
. RegisterControl ( m_button1
);
301 auto_cap
. RegisterControl ( m_staticText1
);
302 auto_cap
. RegisterControl ( m_checkBox1
, AJ_Union
);
303 auto_cap
. RegisterControl ( m_checkBox2
, AJ_UnionEnd
);
304 auto_cap
. RegisterControl ( m_radioBtn1
, AJ_Union
);
305 auto_cap
. RegisterControl ( m_radioBtn2
, AJ_UnionEnd
);
306 auto_cap
. RegisterControl ( m_bpButton1
);
307 auto_cap
. RegisterControl ( m_bitmap1
);
308 auto_cap
. RegisterControl ( m_gauge1
, wxT ( "wxGauge" ));
309 auto_cap
. RegisterControl ( m_slider1
);
310 auto_cap
. RegisterControl ( m_toggleBtn1
, AJ_Union
);
311 auto_cap
. RegisterControl ( m_toggleBtn2
, AJ_UnionEnd
);
312 auto_cap
. RegisterControl ( m_hyperlink1
);
313 auto_cap
. RegisterControl ( m_spinCtrl1
, AJ_RegionAdjust
);
314 auto_cap
. RegisterControl ( m_spinBtn1
);
315 auto_cap
. RegisterControl ( m_scrollBar1
);
317 auto_cap
. RegisterPageTurn ();
319 auto_cap
. RegisterControl ( m_checkList1
);
320 auto_cap
. RegisterControl ( m_listBox1
);
321 auto_cap
. RegisterControl ( m_radioBox1
);
322 auto_cap
. RegisterControl ( m_staticBox1
);
323 auto_cap
. RegisterControl ( m_treeCtrl1
);
324 auto_cap
. RegisterControl ( m_listCtrl1
, wxT ( "wxListCtrl" ));
326 auto_cap
. RegisterControl ( m_animationCtrl1
);
327 auto_cap
. RegisterControl ( m_collPane1
, wxT ( "wxCollapsiblePane" ), AJ_Union
);
328 auto_cap
. RegisterControl ( m_collPane2
, AJ_UnionEnd
);
330 auto_cap
. RegisterPageTurn ();
332 auto_cap
. RegisterControl ( m_textCtrl1
, AJ_Union
);
333 auto_cap
. RegisterControl ( m_textCtrl2
, AJ_UnionEnd
);
334 auto_cap
. RegisterControl ( m_richText1
);
336 auto_cap
. RegisterPageTurn ();
338 auto_cap
. RegisterControl ( m_colourPicker1
, wxT ( "wxColourPickerCtrl" ));
339 auto_cap
. RegisterControl ( m_fontPicker1
, wxT ( "wxFontPickerCtrl" ));
340 auto_cap
. RegisterControl ( m_filePicker1
, wxT ( "wxFilePickerCtrl" ), AJ_RegionAdjust
);
341 auto_cap
. RegisterControl ( m_calendar1
, wxT ( "wxCalendarCtrl" ), AJ_RegionAdjust
);
342 auto_cap
. RegisterControl ( m_datePicker1
, wxT ( "wxDatePickerCtrl" ));
343 auto_cap
. RegisterControl ( m_genericDirCtrl1
, wxT ( "wxGenericDirCtrl" ));
344 auto_cap
. RegisterControl ( m_dirPicker1
, wxT ( "wxDirPickerCtrl" ), AJ_RegionAdjust
);
346 auto_cap
. RegisterPageTurn ();
348 auto_cap
. RegisterControl ( m_choice1
, AJ_Dropdown
);
349 auto_cap
. RegisterControl ( m_comboBox1
, AJ_Dropdown
);
350 auto_cap
. RegisterControl ( m_bmpComboBox1
, AJ_Dropdown
);
351 auto_cap
. RegisterControl ( m_ownerDrawnComboBox1
, AJ_Dropdown
);
352 auto_cap
. RegisterControl ( m_comboCtrl1
, AJ_Dropdown
| AJ_Union
);
353 auto_cap
. RegisterControl ( m_comboCtrl2
, AJ_Dropdown
| AJ_UnionEnd
);
355 auto_cap
. CaptureAll ();
357 wxMessageBox ( _ ( "All screenshots were generated successfully in the folder: \n " ) + dir
,
358 _ ( "Success" ), wxOK
| wxICON_INFORMATION
, this );