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