+ return Capture(origin.x, origin.y, rect.GetWidth(), rect.GetHeight(), delay);
+}
+
+void AutoCaptureMechanism::CaptureAll()
+{
+ // start from the first page
+ m_notebook->SetSelection(0);
+ wxYield();
+
+ for (ControlList::iterator it = m_controlList.begin();
+ it != m_controlList.end();
+ ++it)
+ {
+ Control &ctrl = *it;
+
+ if (ctrl.flag == AJ_TurnPage) // Turn to next page
+ {
+ m_notebook->SetSelection(m_notebook->GetSelection() + 1);
+ wxYield();
+ continue;
+ }
+
+ // create the screenshot
+ wxBitmap screenshot = Capture(ctrl);
+ if (ctrl.flag & AJ_Union)
+ screenshot = Union(screenshot, Capture(*(++it)));
+
+ // and save it
+ Save(screenshot, ctrl.name);
+ }
+}
+
+wxBitmap AutoCaptureMechanism::Capture(Control& ctrl)
+{
+ if (ctrl.name == wxT("")) // no manual specification for the control name
+ {
+ // Get its name from wxRTTI
+ ctrl.name = ctrl.ctrl->GetClassInfo()->GetClassName();
+ }
+
+ int choice = wxNO;
+
+ // for drop-down controls we need the help of the user
+ if (ctrl.flag & AJ_Dropdown)
+ {
+ wxString caption = _("Drop-down screenshot...");
+ wxString msg =
+ wxString::Format(_("Do you wish to capture the drop-down list of '%s' ?\n\nIf you click YES you must drop-down the list of '%s' in 3 seconds after closing this message box.\nIf you click NO the screenshot for this control won't contain its drop-down list."),
+ ctrl.name, ctrl.name);
+
+ choice = wxMessageBox(msg, caption, wxYES_NO, m_notebook);
+
+ #ifndef __WXMAC__ //not __WXMAC__
+ if (choice == wxYES) Delay(3);
+ #endif
+ }
+
+ wxRect rect = GetRect(ctrl.ctrl, ctrl.flag);
+
+ // Do some rect adjust so it can include the dropdown list;
+ // currently this only works well under MSW; not adjusted for Linux and Mac OS
+ if (ctrl.flag & AJ_Dropdown && choice == wxYES)
+ {
+// #ifdef __WXMSW__
+ int h = rect.GetHeight();
+ rect.SetHeight(h * 4);
+// #endif
+ }
+
+ // cut off "wx" and change the name into lowercase.
+ // e.g. wxButton will have a name of "button" at the end
+ ctrl.name.StartsWith(_T("wx"), &(ctrl.name));
+ ctrl.name.MakeLower();
+
+ // take the screenshot
+ wxBitmap screenshot = Capture(rect);
+
+ if (ctrl.flag & AJ_RegionAdjust)
+ PutBack(ctrl.ctrl);
+
+ return screenshot;
+}
+
+wxBitmap AutoCaptureMechanism::Union(wxBitmap pic1, wxBitmap pic2)
+{
+ int w1, w2, h1, h2, w, h;
+ w1 = pic1.GetWidth();
+ w2 = pic2.GetWidth();
+ h1 = pic1.GetHeight();
+ h2 = pic2.GetHeight();
+
+ const int gap_between = 20;
+
+ w = (w1 >= w2) ? w1 : w2;
+ h = h1 + h2 + gap_between;
+
+ wxBitmap result(w, h, -1);
+
+ wxMemoryDC dstDC;
+ dstDC.SelectObject(result);
+
+ dstDC.DrawBitmap(pic1, 0, 0, false);
+ dstDC.DrawBitmap(pic2, 0, h1 + gap_between, false);
+
+ dstDC.SelectObject(wxNullBitmap);
+
+ wxMemoryDC maskDC;
+ wxBitmap mask(w, h, 1);
+ maskDC.SelectObject(mask);
+
+ maskDC.SetPen(*wxTRANSPARENT_PEN);
+ maskDC.SetBrush(*wxBLACK_BRUSH);
+ maskDC.DrawRectangle(0, 0, w + 1, h + 1);
+
+ maskDC.SetBrush(*wxWHITE_BRUSH);
+ maskDC.DrawRectangle(0, 0, w1, h1);
+ maskDC.DrawRectangle(0, h1 + gap_between, w2, h2);
+ maskDC.SelectObject(wxNullBitmap);
+
+ result.SetMask(new wxMask(mask));
+
+ return result;