]> git.saurik.com Git - wxWidgets.git/blob - utils/screenshotgen/src/screenshot_main.cpp
Applied Peter Most's EVT_SPIN crash fix
[wxWidgets.git] / utils / screenshotgen / src / screenshot_main.cpp
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
24 #include "screenshot_main.h"
25 #include "autocapture.h"
26
27 // ----------------------------------------------------------------------------
28 // ScreenshotFrame
29 // ----------------------------------------------------------------------------
30
31 ScreenshotFrame::ScreenshotFrame(wxFrame *frame) : GUIFrame(frame)
32 {
33 #if wxUSE_STATUSBAR
34 statusBar->SetStatusText(_("Welcome to the Automatic Screenshot Generator!"), 0);
35 #endif
36
37 // set minimum size hints
38 GetSizer()->SetSizeHints(this);
39 }
40
41 // ----------------------------------------------------------------------------
42 // ScreenshotFrame - event handlers
43 // ----------------------------------------------------------------------------
44
45 void ScreenshotFrame::OnClose(wxCloseEvent& WXUNUSED(event))
46 {
47 Destroy();
48 }
49
50 void ScreenshotFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
51 {
52 Destroy();
53 }
54
55 void ScreenshotFrame::OnSeeScreenshots(wxCommandEvent& WXUNUSED(event))
56 {
57 wxString defaultDir = AutoCaptureMechanism::GetDefaultDirectoryAbsPath();
58
59 if (wxFileName::DirExists(defaultDir))
60 wxLaunchDefaultBrowser(defaultDir);
61 else
62 wxMessageBox(_("There isn't any screenshots yet."));
63 }
64
65 void ScreenshotFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
66 {
67 wxAboutDialogInfo info;
68 info.SetName(_("Automatic Screenshot Generator"));
69 info.SetVersion(_("1.0"));
70 info.SetDescription(_("This utility automatically creates screenshots of wxWidgets controls for use in wxWidgets documentation."));
71 info.SetCopyright(_T("(C) 2008 Utensil Candel"));
72
73 wxAboutBox(info);
74 }
75
76 void ScreenshotFrame::OnCaptureFullScreen(wxCommandEvent& WXUNUSED(event))
77 {
78 // Create a DC for the whole screen area
79 wxScreenDC dcScreen;
80
81 // Get the size of the screenDC
82 wxCoord screenWidth, screenHeight;
83 dcScreen.GetSize(&screenWidth, &screenHeight);
84
85 wxBitmap fullscreen = AutoCaptureMechanism::Capture(0, 0, screenWidth, screenHeight);
86
87 AutoCaptureMechanism::Save(fullscreen, _T("fullscreen"));
88
89 wxMessageBox(_("A screenshot of the entire screen was saved as:\n\n ")
90 + AutoCaptureMechanism::GetDefaultDirectoryAbsPath() + _T("fullscreen.png"),
91 _("Full screen capture"), wxICON_INFORMATION|wxOK, this);
92 }
93
94 void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
95 {
96 wxString dir = AutoCaptureMechanism::GetDefaultDirectoryAbsPath();
97
98 // check if there are other screenshots taken before
99 if (wxFileName::DirExists(dir))
100 {
101 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."),
102 _("Delete existing screenshots?"),
103 wxYES_NO|wxCANCEL|wxICON_QUESTION, this);
104 switch(choice)
105 {
106 case wxYES:
107 {
108 wxArrayString files;
109 wxDir::GetAllFiles(dir, &files, wxT("*.png"), wxDIR_FILES);
110
111 // remove all PNG files from the screenshots folder
112 int n = files.GetCount();
113 for (int i = 0; i < n; ++i)
114 wxRemoveFile(files[i]);
115 }
116 break;
117
118 case wxNO: break;
119 case wxCANCEL: return;
120 }
121 }
122
123 // proceed with the automatic screenshot capture
124
125 this->Maximize();
126
127 AutoCaptureMechanism auto_cap(m_notebook1);
128
129 auto_cap.RegisterControl(m_button1);
130 auto_cap.RegisterControl(m_staticText1);
131 auto_cap.RegisterControl(m_checkBox1, AJ_Union);
132 auto_cap.RegisterControl(m_checkBox2, AJ_UnionEnd);
133 auto_cap.RegisterControl(m_radioBtn1, AJ_Union);
134 auto_cap.RegisterControl(m_radioBtn2, AJ_UnionEnd);
135 auto_cap.RegisterControl(m_bpButton1);
136 auto_cap.RegisterControl(m_bitmap1);
137 auto_cap.RegisterControl(m_gauge1, wxT("wxGauge"));
138 auto_cap.RegisterControl(m_slider1);
139 auto_cap.RegisterControl(m_toggleBtn1, AJ_Union);
140 auto_cap.RegisterControl(m_toggleBtn2, AJ_UnionEnd);
141 auto_cap.RegisterControl(m_hyperlink1, wxT("wxHyperlinkCtrl"));
142 auto_cap.RegisterControl(m_spinCtrl1, AJ_RegionAdjust);
143 auto_cap.RegisterControl(m_spinBtn1);
144 auto_cap.RegisterControl(m_scrollBar1);
145
146 auto_cap.RegisterPageTurn();
147
148 auto_cap.RegisterControl(m_checkList1);
149 auto_cap.RegisterControl(m_listBox1);
150 auto_cap.RegisterControl(m_radioBox1);
151 auto_cap.RegisterControl(m_staticBox1);
152 auto_cap.RegisterControl(m_treeCtrl1);
153 auto_cap.RegisterControl(m_listCtrl1, wxT("wxListCtrl"));
154
155 auto_cap.RegisterControl(m_animationCtrl1);
156 auto_cap.RegisterControl(m_collPane1, wxT("wxCollapsiblePane"), AJ_Union);
157 auto_cap.RegisterControl(m_collPane2, AJ_UnionEnd);
158
159 auto_cap.RegisterPageTurn();
160
161 auto_cap.RegisterControl(m_textCtrl1, AJ_Union);
162 auto_cap.RegisterControl(m_textCtrl2, AJ_UnionEnd);
163 auto_cap.RegisterControl(m_richText1);
164
165 auto_cap.RegisterPageTurn();
166
167 auto_cap.RegisterControl(m_colourPicker1, wxT("wxColourPickerCtrl"));
168 auto_cap.RegisterControl(m_fontPicker1, wxT("wxFontPickerCtrl"));
169 auto_cap.RegisterControl(m_filePicker1, wxT("wxFilePickerCtrl"), AJ_RegionAdjust);
170 auto_cap.RegisterControl(m_calendar1, wxT("wxCalendarCtrl"), AJ_RegionAdjust);
171 auto_cap.RegisterControl(m_datePicker1, wxT("wxDatePickerCtrl"));
172 auto_cap.RegisterControl(m_genericDirCtrl1, wxT("wxGenericDirCtrl"));
173 auto_cap.RegisterControl(m_dirPicker1, wxT("wxDirPickerCtrl"), AJ_RegionAdjust);
174
175 auto_cap.RegisterPageTurn();
176
177 auto_cap.RegisterControl(m_choice1, AJ_Dropdown);
178 auto_cap.RegisterControl(m_comboBox1, AJ_Dropdown);
179 auto_cap.RegisterControl(m_bmpComboBox1, AJ_Dropdown);
180 auto_cap.RegisterControl(m_ownerDrawnComboBox1, AJ_Dropdown);
181 auto_cap.RegisterControl(m_comboCtrl1, AJ_Dropdown|AJ_Union);
182 auto_cap.RegisterControl(m_comboCtrl2, AJ_Dropdown|AJ_UnionEnd);
183
184 auto_cap.CaptureAll();
185
186 wxMessageBox(_("All screenshots were generated successfully in the folder:\n ") + dir,
187 _("Success"), wxOK|wxICON_INFORMATION, this);
188 }