]> git.saurik.com Git - wxWidgets.git/blame_incremental - utils/screenshotgen/src/screenshot_main.cpp
Update configuration for OpenVMS
[wxWidgets.git] / utils / screenshotgen / src / screenshot_main.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: screenshot_main.cpp
3// Purpose: Implements the window containing all controls.
4// Author: Utensil Candel (UtensilCandel@@gmail.com)
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9// For compilers that support precompilation, includes "wx/wx.h".
10#include "wx/wxprec.h"
11
12#ifdef __BORLANDC__
13#pragma hdrstop
14#endif
15
16// for all others, include the necessary headers wxWidgets headers)
17#ifndef WX_PRECOMP
18#include "wx/wx.h"
19#endif
20
21#include "wx/aboutdlg.h"
22#include "wx/dir.h"
23#include "wx/filesys.h"
24
25#include "screenshot_main.h"
26#include "ctrlmaskout.h"
27#include "autocapture.h"
28
29#include "bitmaps/play.xpm"
30#include "bitmaps/stop.xpm"
31
32
33// ----------------------------------------------------------------------------
34// ScreenshotFrame
35// ----------------------------------------------------------------------------
36
37ScreenshotFrame::ScreenshotFrame(wxFrame *frame)
38#if SCREENSHOTGEN_USE_AUI
39: AuiGUIFrame(frame)
40#else
41: GUIFrame(frame)
42#endif
43{
44#if wxUSE_STATUSBAR
45 statusBar->SetStatusText(_("Welcome to the Automatic Screenshot Generator!"), 0);
46#endif
47
48 // We will hold one ctrlmaskout during the whole life time of the main frame
49 m_maskout = new CtrlMaskOut();
50
51 // At the begining, we are not specifying the rect region
52 capturingRect = false;
53
54 // Do some further customization on some controls generated by wxFormBuilder
55 InitFBControls();
56#if SCREENSHOTGEN_USE_AUI
57 // Somehow it will be very small after I move to Aui
58 SetSize(600, 600);
59 // Maximize(true);
60#endif
61}
62
63ScreenshotFrame::~ScreenshotFrame()
64{
65 delete m_maskout;
66}
67
68/*
69 Do some further customization on some controls.
70
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.
74*/
75void ScreenshotFrame::InitFBControls()
76{
77 m_scrollBar1->SetScrollbar(50, 1, 100, 1);
78
79 // Do the default selection for wxComboBox
80 m_comboBox1->Select(0);
81
82 // To look better under gtk
83#ifdef __WXGTK__
84 m_comboBox1->Delete(4);
85#endif
86
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();
93
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));
100 }
101
102 // Init file and dir pickers
103 wxString file, dir;
104#if defined(__WXMSW__)
105 file = "C:\\Windows\\explorer.exe";
106 dir = "C:\\Windows";
107#else
108 file = "/bin/bash";
109 dir = "/home";
110#endif
111 m_filePicker1->SetPath(file);
112 m_dirPicker1->SetPath(dir);
113
114 // Check the first item in wxCheckListBox
115 m_checkList1->Check(0);
116
117 // Load richtext.xml into wxRichtextCtrl
118 m_richText1->LoadFile(_T("richtext.xml"));
119 //m_richText1->ShowPosition(335);
120
121 // select first page in the main notebook ctrl
122 m_notebook1->ChangeSelection(0);
123
124 // set minimum size hints
125 GetSizer()->SetSizeHints(this);
126
127 // add bitmaps to the menus
128 m_menuCapRect->SetBitmap( wxIcon(play_xpm) );
129 m_menuEndCapRect->SetBitmap( wxIcon(stop_xpm) );
130}
131
132
133
134// ----------------------------------------------------------------------------
135// ScreenshotFrame - event handlers
136// ----------------------------------------------------------------------------
137
138void ScreenshotFrame::OnClose(wxCloseEvent& WXUNUSED(event))
139{
140 Destroy();
141}
142
143void ScreenshotFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
144{
145 Destroy();
146}
147
148void ScreenshotFrame::OnSeeScreenshots(wxCommandEvent& WXUNUSED(event))
149{
150 wxString defaultDir = m_maskout->GetDefaultDirectory();
151
152 // Check if defaultDir already existed
153 if (!wxDirExists(defaultDir))
154 wxMkdir(defaultDir);
155
156 // Use the native file browser to open defaultDir
157 wxLaunchDefaultBrowser(wxFileSystem::FileNameToURL(defaultDir));
158}
159
160void ScreenshotFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
161{
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"));
167
168 wxAboutBox(info);
169}
170
171void ScreenshotFrame::OnCaptureFullScreen(wxCommandEvent& WXUNUSED(event))
172{
173 // Create a DC for the whole screen area
174 wxScreenDC dcScreen;
175
176 // Get the size of the screenDC
177 wxCoord screenWidth, screenHeight;
178 dcScreen.GetSize(&screenWidth, &screenHeight);
179
180 m_maskout->Capture(0, 0, screenWidth, screenHeight, _T("fullscreen"));
181
182 // Inform the user
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);
186}
187
188void ScreenshotFrame::OnCaptureRect(wxCommandEvent& WXUNUSED(event))
189{
190 capturingRect = true;
191 wxMenuBar * menubar = this->GetMenuBar();
192 menubar->FindItem(idMenuCapRect)->Enable(false);
193 menubar->FindItem(idMenuEndCapRect)->Enable(true);
194
195 wxWindow * thePage = m_notebook1->GetPage(m_notebook1->GetSelection());
196
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);
200}
201
202void ScreenshotFrame::OnEndCaptureRect(wxCommandEvent& WXUNUSED(event))
203{
204 capturingRect = false;
205 wxMenuBar * menubar = this->GetMenuBar();
206 menubar->FindItem(idMenuCapRect)->Enable(true);
207 menubar->FindItem(idMenuEndCapRect)->Enable(false);
208
209 wxWindow * thePage = m_notebook1->GetPage(m_notebook1->GetSelection());
210
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);
214}
215
216void ScreenshotFrame::OnNotebookPageChanging(
217#if SCREENSHOTGEN_USE_AUI
218wxAuiNotebookEvent& event
219#else
220wxNotebookEvent& event
221#endif
222)
223{
224 if (!capturingRect)
225 {
226 event.Skip();
227 return;
228 }
229
230 wxWindow * thePage = m_notebook1->GetPage(event.GetOldSelection());
231
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);
235
236 event.Skip();
237}
238
239void ScreenshotFrame::OnNotebookPageChanged(
240#if SCREENSHOTGEN_USE_AUI
241wxAuiNotebookEvent& event
242#else
243wxNotebookEvent& event
244#endif
245)
246{
247 if (!capturingRect)
248 {
249 event.Skip();
250 return;
251 }
252
253 wxWindow *thePage = m_notebook1->GetPage(event.GetSelection());
254
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);
258
259 event.Skip();
260}
261
262void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
263{
264 wxString dir = m_maskout->GetDefaultDirectoryAbsPath();
265
266 // check if there are other screenshots taken before
267 if (wxFileName::DirExists(dir))
268 {
269 int choice = wxMessageBox(_("It seems that you have already generated some screenshots.\n\nClick YES to delete them all (recommended) or NO to preserve them.\nClick CANCEL to cancel this auto-capture operation."),
270 _("Delete existing screenshots?"),
271 wxYES_NO|wxCANCEL|wxICON_QUESTION, this);
272 switch(choice)
273 {
274 case wxYES:
275 {
276 wxArrayString files;
277 wxDir::GetAllFiles(dir, &files, wxT("*.png"), wxDIR_FILES);
278
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]);
283 }
284 break;
285
286 case wxNO: break;
287 case wxCANCEL: return;
288 }
289 }
290
291 // proceed with the automatic screenshot capture
292
293 this->Maximize();
294
295 AutoCaptureMechanism auto_cap(m_notebook1);
296
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);
313
314 auto_cap.RegisterPageTurn();
315
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"));
322
323 auto_cap.RegisterControl(m_animationCtrl1);
324 auto_cap.RegisterControl(m_collPane1, wxT("wxCollapsiblePane"), AJ_Union);
325 auto_cap.RegisterControl(m_collPane2, AJ_UnionEnd);
326
327 auto_cap.RegisterPageTurn();
328
329 auto_cap.RegisterControl(m_textCtrl1, AJ_Union);
330 auto_cap.RegisterControl(m_textCtrl2, AJ_UnionEnd);
331 auto_cap.RegisterControl(m_richText1);
332
333 auto_cap.RegisterPageTurn();
334
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);
342
343 auto_cap.RegisterPageTurn();
344
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);
351
352 auto_cap.CaptureAll();
353
354 wxMessageBox(_("All screenshots were generated successfully in the folder:\n ") + dir,
355 _("Success"), wxOK|wxICON_INFORMATION, this);
356}