]>
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 "screenshot_main.h"
28 #include "ctrlmaskout.h"
29 #include "autocapture.h"
32 // Global helper functions
33 enum wxBuildInfoFormat
39 wxString
wxbuildinfo ( wxBuildInfoFormat format
)
41 wxString
wxbuild ( wxVERSION_STRING
);
43 if ( format
== long_f
)
45 #if defined(__WXMSW__)
46 wxbuild
<< _T ( "-Windows" );
47 #elif defined(__WXMAC__)
48 wxbuild
<< _T ( "-Mac" );
49 #elif defined(__UNIX__)
50 wxbuild
<< _T ( "-Linux" );
54 wxbuild
<< _T ( "-Unicode build" );
56 wxbuild
<< _T ( "-ANSI build" );
57 #endif // wxUSE_UNICODE
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 wxScreenshotFrame :: wxScreenshotFrame ( wxFrame
* frame
)
69 #if SCREENSHOTGEN_USE_AUI
76 statusBar
-> SetStatusText ( _ ( "Hello wxWidgets user!" ), 0 );
77 // statusBar->SetStatusText(wxbuildinfo(short_f), 1);
80 // We will hold one during the whole life time of the main frame
81 m_maskout
= new wxCtrlMaskOut ();
83 // At the begining, we are not specifying the rect region
84 capturingRect
= false ;
86 // Do some further customization on some controls generated by wxFormBuilder
88 #if SCREENSHOTGEN_USE_AUI
89 // Somehow it will be very small after I move to Aui
95 wxScreenshotFrame ::~ wxScreenshotFrame ()
101 Do some further customization on some controls generated by wxFormBuilder.
103 Some controls can only be generated by wxFormBuilder without further
104 customization, e.g. unable to load a richtext file in a wxRichtextCtrl
105 during initialization.
107 Those customizations will be done here.
109 void wxScreenshotFrame :: InitFBControls ()
111 // Do the default selection for wxComboBox
112 m_comboBox1
-> Select ( 0 );
114 // To look better under gtk
116 m_comboBox1
-> Delete ( 4 );
119 // Add a root and some nodes for wxTreeCtrl
120 wxTreeItemId root
= m_treeCtrl1
-> AddRoot ( _ ( "wxTreeCtrl" ));
122 m_treeCtrl1
-> AppendItem ( root
, _ ( "Node1" ));
124 wxTreeItemId node2
= m_treeCtrl1
-> AppendItem ( root
, _ ( "Node2" ));
125 m_treeCtrl1
-> AppendItem ( node2
, _ ( "Node3" ));
127 m_treeCtrl1
-> ExpandAll ();
129 // Add items into wxListCtrl
130 for ( long index
= 0 ; index
< 5 ; index
++)
131 m_listCtrl1
-> InsertItem ( index
, wxString :: Format ( _ ( "Item \n (0, %d )" ), index
));
133 // Check the first item in wxCheckListBox
134 m_checkList1
-> Check ( 0 );
136 // Load richtext.xml into wxRichtextCtrl
137 m_richText1
-> LoadFile ( _T ( "richtext.xml" ));
138 m_richText1
-> ShowPosition ( 335 );
143 // ----------------------------------------------------------------------------
144 // wxScreenshotFrame - event handlers
145 // ----------------------------------------------------------------------------
147 void wxScreenshotFrame :: OnClose ( wxCloseEvent
& WXUNUSED ( event
))
152 void wxScreenshotFrame :: OnQuit ( wxCommandEvent
& WXUNUSED ( event
))
157 void wxScreenshotFrame :: OnSeeScreenshots ( wxCommandEvent
& WXUNUSED ( event
))
159 wxString defaultDir
= m_maskout
-> GetDefaultDirectory ();
161 // Check if defaultDir already existed
162 if (! wxDirExists ( defaultDir
))
165 // Use the native file browser to open defaultDir
166 #if defined(__WXMSW__)
167 wxExecute ( _T ( "explorer " ) + defaultDir
);
168 #elif defined(__UNIX__) // nautilus is the GNOME file browser but works also for KDE
169 wxExecute ( _T ( "nautilus " ) + defaultDir
);
170 #elif defined(_WXMAC_)
171 wxExecute ( _T ( "open " ) + defaultDir
);
173 wxMessageBox ( _ ( "Sorry, not Implemeted for this platform yet! Please open subdirectory \" " )
175 + _ ( " \" manually." ) );
179 void wxScreenshotFrame :: OnAbout ( wxCommandEvent
& WXUNUSED ( event
))
181 wxString msg
= wxbuildinfo ( long_f
);
182 wxMessageBox ( msg
, _ ( "Welcome to..." ));
185 void wxScreenshotFrame :: OnCaptureFullScreen ( wxCommandEvent
& WXUNUSED ( event
))
187 // Create a DC for the whole screen area
190 // Get the size of the screenDC
191 wxCoord screenWidth
, screenHeight
;
192 dcScreen
. GetSize (& screenWidth
, & screenHeight
);
194 m_maskout
-> Capture ( 0 , 0 , screenWidth
, screenHeight
, _T ( "fullscreen" ));
197 void wxScreenshotFrame :: OnCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
199 capturingRect
= true ;
200 wxMenuBar
* menubar
= this -> GetMenuBar ();
201 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( false );
202 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( true );
204 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
206 thePage
-> Connect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( wxCtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
207 thePage
-> Connect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( wxCtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
208 thePage
-> Connect ( wxEVT_MOTION
, wxMouseEventHandler ( wxCtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
211 void wxScreenshotFrame :: OnEndCaptureRect ( wxCommandEvent
& WXUNUSED ( event
))
213 capturingRect
= false ;
214 wxMenuBar
* menubar
= this -> GetMenuBar ();
215 menubar
-> FindItem ( idMenuCapRect
)-> Enable ( true );
216 menubar
-> FindItem ( idMenuEndCapRect
)-> Enable ( false );
218 wxWindow
* thePage
= m_notebook1
-> GetPage ( m_notebook1
-> GetSelection ());
220 thePage
-> Disconnect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( wxCtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
221 thePage
-> Disconnect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( wxCtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
222 thePage
-> Disconnect ( wxEVT_MOTION
, wxMouseEventHandler ( wxCtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
225 void wxScreenshotFrame :: OnNotebookPageChanging (
226 #if SCREENSHOTGEN_USE_AUI
227 wxAuiNotebookEvent
& event
229 wxNotebookEvent
& event
239 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetOldSelection ());
241 thePage
-> Disconnect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( wxCtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
242 thePage
-> Disconnect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( wxCtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
243 thePage
-> Disconnect ( wxEVT_MOTION
, wxMouseEventHandler ( wxCtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
248 void wxScreenshotFrame :: OnNotebookPageChanged (
249 #if SCREENSHOTGEN_USE_AUI
250 wxAuiNotebookEvent
& event
252 wxNotebookEvent
& event
262 wxWindow
* thePage
= m_notebook1
-> GetPage ( event
. GetSelection ());
264 thePage
-> Connect ( wxEVT_LEFT_DOWN
, wxMouseEventHandler ( wxCtrlMaskOut :: OnLeftButtonDown
), NULL
, m_maskout
);
265 thePage
-> Connect ( wxEVT_LEFT_UP
, wxMouseEventHandler ( wxCtrlMaskOut :: OnLeftButtonUp
), NULL
, m_maskout
);
266 thePage
-> Connect ( wxEVT_MOTION
, wxMouseEventHandler ( wxCtrlMaskOut :: OnMouseMoving
), NULL
, m_maskout
);
271 void wxScreenshotFrame :: OnCaptureAllControls ( wxCommandEvent
& WXUNUSED ( event
))
273 wxString dir
= wxT ( "screenshots" );
275 if ( wxFileName :: DirExists ( dir
))
277 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)." ),
278 _ ( "Do you want to delete the existing screenshots?" ),
279 wxYES_NO
| wxCANCEL
| wxICON_QUESTION
, this );
285 wxDir :: GetAllFiles ( dir
, & files
, wxT ( "*.png" ), wxDIR_FILES
);
287 int n
= files
. GetCount ();
288 for ( int i
= 0 ; i
< n
; ++ i
)
289 wxRemoveFile ( files
[ i
]);
294 case wxCANCEL
: return ;
300 AutoCaptureMechanism
auto_cap ( m_notebook1
);
302 auto_cap
. RegisterControl ( m_button1
);
303 auto_cap
. RegisterControl ( m_staticText1
);
304 auto_cap
. RegisterControl ( m_checkBox1
, AJ_Union
);
305 auto_cap
. RegisterControl ( m_checkBox2
, AJ_UnionEnd
);
306 auto_cap
. RegisterControl ( m_radioBtn1
, AJ_Union
);
307 auto_cap
. RegisterControl ( m_radioBtn2
, AJ_UnionEnd
);
308 auto_cap
. RegisterControl ( m_bpButton1
);
309 auto_cap
. RegisterControl ( m_bitmap1
);
310 auto_cap
. RegisterControl ( m_gauge1
, wxT ( "wxGauge" ));
311 auto_cap
. RegisterControl ( m_slider1
);
312 auto_cap
. RegisterControl ( m_toggleBtn1
, AJ_Union
);
313 auto_cap
. RegisterControl ( m_toggleBtn2
, AJ_UnionEnd
);
314 auto_cap
. RegisterControl ( m_hyperlink1
);
315 auto_cap
. RegisterControl ( m_spinCtrl1
, AJ_RegionAdjust
);
316 auto_cap
. RegisterControl ( m_spinBtn1
);
317 auto_cap
. RegisterControl ( m_scrollBar1
);
319 auto_cap
. RegisterPageTurn ();
321 auto_cap
. RegisterControl ( m_checkList1
);
322 auto_cap
. RegisterControl ( m_listBox1
);
323 auto_cap
. RegisterControl ( m_radioBox1
);
324 auto_cap
. RegisterControl ( m_staticBox1
);
325 auto_cap
. RegisterControl ( m_treeCtrl1
);
326 auto_cap
. RegisterControl ( m_listCtrl1
, wxT ( "wxListCtrl" ));
328 auto_cap
. RegisterControl ( m_animationCtrl1
);
329 auto_cap
. RegisterControl ( m_collPane1
, wxT ( "wxCollapsiblePane" ), AJ_Union
);
330 auto_cap
. RegisterControl ( m_collPane2
, AJ_UnionEnd
);
332 auto_cap
. RegisterPageTurn ();
334 auto_cap
. RegisterControl ( m_textCtrl1
, AJ_Union
);
335 auto_cap
. RegisterControl ( m_textCtrl2
, AJ_UnionEnd
);
336 auto_cap
. RegisterControl ( m_richText1
);
338 auto_cap
. RegisterPageTurn ();
340 auto_cap
. RegisterControl ( m_colourPicker1
, wxT ( "wxColourPickerCtrl" ));
341 auto_cap
. RegisterControl ( m_fontPicker1
, wxT ( "wxFontPickerCtrl" ));
342 auto_cap
. RegisterControl ( m_filePicker1
, wxT ( "wxFilePickerCtrl" ), AJ_RegionAdjust
);
343 auto_cap
. RegisterControl ( m_calendar1
, wxT ( "wxCalendarCtrl" ), AJ_RegionAdjust
);
344 auto_cap
. RegisterControl ( m_datePicker1
, wxT ( "wxDatePickerCtrl" ));
345 auto_cap
. RegisterControl ( m_genericDirCtrl1
, wxT ( "wxGenericDirCtrl" ));
346 auto_cap
. RegisterControl ( m_dirPicker1
, wxT ( "wxDirPickerCtrl" ), AJ_RegionAdjust
);
348 auto_cap
. RegisterPageTurn ();
350 auto_cap
. RegisterControl ( m_choice1
, AJ_Dropdown
);
351 auto_cap
. RegisterControl ( m_comboBox1
, AJ_Dropdown
);
352 auto_cap
. RegisterControl ( m_bmpComboBox1
, AJ_Dropdown
);
353 auto_cap
. RegisterControl ( m_ownerDrawnComboBox1
, AJ_Dropdown
);
354 auto_cap
. RegisterControl ( m_comboCtrl1
, AJ_Dropdown
| AJ_Union
);
355 auto_cap
. RegisterControl ( m_comboCtrl2
, AJ_Dropdown
| AJ_UnionEnd
);
357 auto_cap
. CaptureAll ();
359 wxMessageBox ( _ ( "All screenshots are generated successfully. \n Select \" File->See screenshots \" to see them." ),
360 _ ( "Success" ), wxOK
, this );