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