]>
git.saurik.com Git - wxWidgets.git/blob - utils/screenshotgen/src/screenshot_main.cpp
c9966ff50234aec3228d6a19457ea0b284ffd00e
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>
29 #include "screenshot_main.h"
30 #include "ctrlmaskout.h"
31 #include "autocapture.h"
34 // Global helper functions
35 enum wxBuildInfoFormat
41 wxString wxbuildinfo(wxBuildInfoFormat format)
43 wxString wxbuild(wxVERSION_STRING);
45 if (format == long_f )
47 #if defined(__WXMSW__)
48 wxbuild << _T("-Windows");
49 #elif defined(__WXMAC__)
50 wxbuild << _T("-Mac");
51 #elif defined(__UNIX__)
52 wxbuild << _T("-Linux");
56 wxbuild << _T("-Unicode build");
58 wxbuild << _T("-ANSI build");
59 #endif // wxUSE_UNICODE
66 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
70 ScreenshotFrame :: ScreenshotFrame ( wxFrame
* frame
)
71 #if SCREENSHOTGEN_USE_AUI
78 statusBar
-> SetStatusText ( _ ( "Hello wxWidgets user!" ), 0 );
79 // statusBar->SetStatusText(wxbuildinfo(short_f), 1);
82 // We will hold one during the whole life time of the main frame
83 m_maskout
= new CtrlMaskOut ();
85 // At the begining, we are not specifying the rect region
86 capturingRect
= false ;
88 // Do some further customization on some controls generated by wxFormBuilder
90 #if SCREENSHOTGEN_USE_AUI
91 // Somehow it will be very small after I move to Aui
97 ScreenshotFrame ::~ ScreenshotFrame ()
103 Do some further customization on some controls generated by wxFormBuilder.
105 Some controls can only be generated by wxFormBuilder without further
106 customization, e.g. unable to load a richtext file in a wxRichtextCtrl
107 during initialization.
109 Those customizations will be done here.
111 void ScreenshotFrame :: InitFBControls ()
113 // Do the default selection for wxComboBox
114 m_comboBox1
-> Select ( 0 );
116 // To look better under gtk
118 m_comboBox1
-> Delete ( 4 );
121 // Add a root and some nodes for wxTreeCtrl
122 wxTreeItemId root
= m_treeCtrl1
-> AddRoot ( _ ( "wxTreeCtrl" ));
124 m_treeCtrl1
-> AppendItem ( root
, _ ( "Node1" ));
126 wxTreeItemId node2
= m_treeCtrl1
-> AppendItem ( root
, _ ( "Node2" ));
127 m_treeCtrl1
-> AppendItem ( node2
, _ ( "Node3" ));
129 m_treeCtrl1
-> ExpandAll ();
131 // Add items into wxListCtrl
132 for ( long index
= 0 ; index
< 5 ; index
++)
133 m_listCtrl1
-> InsertItem ( index
, wxString :: Format ( _ ( "Item \n (0, %d )" ), index
));
135 // Check the first item in wxCheckListBox
136 m_checkList1
-> Check ( 0 );
138 // Load richtext.xml into wxRichtextCtrl
139 m_richText1
-> LoadFile ( _T ( "richtext.xml" ));
140 m_richText1
-> ShowPosition ( 335 );
145 // ----------------------------------------------------------------------------
146 // ScreenshotFrame - event handlers
147 // ----------------------------------------------------------------------------
149 void ScreenshotFrame :: OnClose ( wxCloseEvent
& WXUNUSED ( event
))
154 void ScreenshotFrame :: OnQuit ( wxCommandEvent
& WXUNUSED ( event
))
159 void ScreenshotFrame :: OnSeeScreenshots ( wxCommandEvent
& WXUNUSED ( event
))
161 wxString defaultDir
= m_maskout
-> GetDefaultDirectory ();
163 // Check if defaultDir already existed
164 if (! wxDirExists ( defaultDir
))
167 // Use the native file browser to open defaultDir
168 #if defined(__WXMSW__)
169 wxExecute ( _T ( "explorer " ) + defaultDir
);
170 #elif defined(__UNIX__) // nautilus is the GNOME file browser but works also for KDE
171 wxExecute ( _T ( "nautilus " ) + defaultDir
);
172 #elif defined(_WXMAC_)
173 wxExecute ( _T ( "open " ) + defaultDir
);
175 wxMessageBox ( _ ( "Sorry, not Implemeted for this platform yet! Please open subdirectory \" " )
177 + _ ( " \" manually." ) );
181 void ScreenshotFrame :: OnAbout ( wxCommandEvent
& WXUNUSED ( event
))
183 wxAboutDialogInfo info
;
184 info
. SetName ( _ ( "Automatic Screenshot Generator" ));
185 info
. SetVersion ( _ ( "1.0" ));
186 info
. SetDescription ( _ ( "This utility automatically creates screenshots of wxWidgets controls for ues in wxWidgets documentation." ));
187 info
. SetCopyright ( _T ( "(C) 2008 Utensil Candel" ));
192 void ScreenshotFrame :: OnCaptureFullScreen ( wxCommandEvent
& WXUNUSED ( event
))
194 // Create a DC for the whole screen area
197 // Get the size of the screenDC
198 wxCoord screenWidth
, screenHeight
;
199 dcScreen
. GetSize (& screenWidth
, & screenHeight
);
201 m_maskout
-> Capture ( 0 , 0 , screenWidth
, screenHeight
, _T ( "fullscreen" ));
204 void ScreenshotFrame :: OnCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
206 capturingRect
= true ;
207 wxMenuBar
* menubar
= this -> GetMenuBar ();
208 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( false );
209 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( true );
211 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
213 thePage
-> Connect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
214 thePage
-> Connect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
215 thePage
-> Connect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
218 void ScreenshotFrame :: OnEndCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
220 capturingRect
= false ;
221 wxMenuBar
* menubar
= this -> GetMenuBar ();
222 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( true );
223 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( false );
225 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
227 thePage
-> Disconnect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
228 thePage
-> Disconnect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
229 thePage
-> Disconnect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
232 void ScreenshotFrame :: OnNotebookPageChanging (
233 #if SCREENSHOTGEN_USE_AUI
234 wxAuiNotebookEvent
& event
236 wxNotebookEvent
& event
246 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetOldSelection ());
248 thePage
-> Disconnect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
249 thePage
-> Disconnect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
250 thePage
-> Disconnect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
255 void ScreenshotFrame :: OnNotebookPageChanged (
256 #if SCREENSHOTGEN_USE_AUI
257 wxAuiNotebookEvent
& event
259 wxNotebookEvent
& event
269 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetSelection ());
271 thePage
-> Connect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
272 thePage
-> Connect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( CtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
273 thePage
-> Connect ( wxEVT_MOTION
, wxMouseEventHandler ( CtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
278 void ScreenshotFrame :: OnCaptureAllControls ( wxCommandEvent
& WXUNUSED ( event
))
280 wxString dir
= wxT ( "screenshots" );
282 if ( wxFileName :: DirExists ( dir
))
284 int choice
= wxMessageBox ( _ ( "It seems that you have already generated some screenshots. \n Click YES to delete them all(recommended), NO to preserve them \n CANCEL to cancel this auto-capture(so you can save them elsewhere)." ),
285 _ ( "Do you want to delete the existing screenshots?" ),
286 wxYES_NO
| wxCANCEL
| wxICON_QUESTION
, this );
292 wxDir :: GetAllFiles ( dir
, & files
, wxT ( "*.png" ), wxDIR_FILES
);
294 int n
= files
. GetCount ();
295 for ( int i
= 0 ; i
< n
; ++ i
)
296 wxRemoveFile ( files
[ i
]);
301 case wxCANCEL
: return ;
307 AutoCaptureMechanism
auto_cap ( m_notebook1
);
309 auto_cap
. RegisterControl ( m_button1
);
310 auto_cap
. RegisterControl ( m_staticText1
);
311 auto_cap
. RegisterControl ( m_checkBox1
, AJ_Union
);
312 auto_cap
. RegisterControl ( m_checkBox2
, AJ_UnionEnd
);
313 auto_cap
. RegisterControl ( m_radioBtn1
, AJ_Union
);
314 auto_cap
. RegisterControl ( m_radioBtn2
, AJ_UnionEnd
);
315 auto_cap
. RegisterControl ( m_bpButton1
);
316 auto_cap
. RegisterControl ( m_bitmap1
);
317 auto_cap
. RegisterControl ( m_gauge1
, wxT ( "wxGauge" ));
318 auto_cap
. RegisterControl ( m_slider1
);
319 auto_cap
. RegisterControl ( m_toggleBtn1
, AJ_Union
);
320 auto_cap
. RegisterControl ( m_toggleBtn2
, AJ_UnionEnd
);
321 auto_cap
. RegisterControl ( m_hyperlink1
);
322 auto_cap
. RegisterControl ( m_spinCtrl1
, AJ_RegionAdjust
);
323 auto_cap
. RegisterControl ( m_spinBtn1
);
324 auto_cap
. RegisterControl ( m_scrollBar1
);
326 auto_cap
. RegisterPageTurn ();
328 auto_cap
. RegisterControl ( m_checkList1
);
329 auto_cap
. RegisterControl ( m_listBox1
);
330 auto_cap
. RegisterControl ( m_radioBox1
);
331 auto_cap
. RegisterControl ( m_staticBox1
);
332 auto_cap
. RegisterControl ( m_treeCtrl1
);
333 auto_cap
. RegisterControl ( m_listCtrl1
, wxT ( "wxListCtrl" ));
335 auto_cap
. RegisterControl ( m_animationCtrl1
);
336 auto_cap
. RegisterControl ( m_collPane1
, wxT ( "wxCollapsiblePane" ), AJ_Union
);
337 auto_cap
. RegisterControl ( m_collPane2
, AJ_UnionEnd
);
339 auto_cap
. RegisterPageTurn ();
341 auto_cap
. RegisterControl ( m_textCtrl1
, AJ_Union
);
342 auto_cap
. RegisterControl ( m_textCtrl2
, AJ_UnionEnd
);
343 auto_cap
. RegisterControl ( m_richText1
);
345 auto_cap
. RegisterPageTurn ();
347 auto_cap
. RegisterControl ( m_colourPicker1
, wxT ( "wxColourPickerCtrl" ));
348 auto_cap
. RegisterControl ( m_fontPicker1
, wxT ( "wxFontPickerCtrl" ));
349 auto_cap
. RegisterControl ( m_filePicker1
, wxT ( "wxFilePickerCtrl" ), AJ_RegionAdjust
);
350 auto_cap
. RegisterControl ( m_calendar1
, wxT ( "wxCalendarCtrl" ), AJ_RegionAdjust
);
351 auto_cap
. RegisterControl ( m_datePicker1
, wxT ( "wxDatePickerCtrl" ));
352 auto_cap
. RegisterControl ( m_genericDirCtrl1
, wxT ( "wxGenericDirCtrl" ));
353 auto_cap
. RegisterControl ( m_dirPicker1
, wxT ( "wxDirPickerCtrl" ), AJ_RegionAdjust
);
355 auto_cap
. RegisterPageTurn ();
357 auto_cap
. RegisterControl ( m_choice1
, AJ_Dropdown
);
358 auto_cap
. RegisterControl ( m_comboBox1
, AJ_Dropdown
);
359 auto_cap
. RegisterControl ( m_bmpComboBox1
, AJ_Dropdown
);
360 auto_cap
. RegisterControl ( m_ownerDrawnComboBox1
, AJ_Dropdown
);
361 auto_cap
. RegisterControl ( m_comboCtrl1
, AJ_Dropdown
| AJ_Union
);
362 auto_cap
. RegisterControl ( m_comboCtrl2
, AJ_Dropdown
| AJ_UnionEnd
);
364 auto_cap
. CaptureAll ();
366 wxMessageBox ( _ ( "All screenshots are generated successfully. \n Select \" File->See screenshots \" to see them." ),
367 _ ( "Success" ), wxOK
, this );