+
+ // cut off "wx" and change the name into lowercase.
+ // e.g. wxButton will have a name of "button" at the end
+ ctrl.name.StartsWith(wxT("wx"), &(ctrl.name));
+ ctrl.name.MakeLower();
+
+ // take the screenshot
+ Capture(bitmap, rect, (choice == wxYES)?5:0);
+
+ if (choice == wxYES) ctrl.ctrl->SetCursor(wxNullCursor);
+
+ if (ctrl.flag & AJ_RegionAdjust)
+ PutBack(ctrl.ctrl);
+
+ return true;
+}
+
+/* static */
+bool AutoCaptureMechanism::Union(wxBitmap* top, wxBitmap* bottom, wxBitmap* result)
+{
+ int w1, w2, h1, h2, w, h;
+ w1 = top->GetWidth();
+ w2 = bottom->GetWidth();
+ h1 = top->GetHeight();
+ h2 = bottom->GetHeight();
+
+ const int gap_between = 20;
+
+ w = (w1 >= w2) ? w1 : w2;
+ h = h1 + h2 + gap_between;
+
+ result->Create(w, h);
+
+ wxMemoryDC dstDC;
+ dstDC.SelectObject((*result));
+
+ dstDC.SetBrush(*wxWHITE_BRUSH);
+ dstDC.Clear();
+ dstDC.DrawBitmap((*top), 0, 0);
+ dstDC.DrawBitmap((*bottom), 0, h1 + gap_between);
+
+ dstDC.SelectObject(wxNullBitmap);
+
+ return true;
+}
+
+wxRect AutoCaptureMechanism::GetRect(wxWindow* ctrl, int flag)
+{
+ if( !(m_flag & AJ_DisableRegionAdjust) && (flag & AJ_RegionAdjust)
+ || (m_flag & AJ_AlwaysRegionAdjust) )
+ {
+ wxWindow * parent = ctrl->GetParent();
+ wxSizer * sizer = parent->GetSizer();
+
+ //The assertion won't fail if controls are still managed by wxSizer, and it's unlikely to
+ //change in the future.
+ wxASSERT_MSG(sizer,
+ "The GUI that AutoCaptureMechanism working with doesn't manage controls with wxSizer");
+
+ sizer->Detach(ctrl);
+
+ /*
+ +---------+-----------+---------+
+ | 0 | label | 1 |
+ +---------+-----------+---------+
+ | label | ctrl | label |
+ +---------+-----------+---------+
+ | 2 | label | 3 |
+ +---------+-----------+---------+
+ */
+
+ m_grid = new wxFlexGridSizer(3, 3, m_margin, m_margin);
+
+ wxStaticText* l[4];
+
+ for (int i = 0; i < 4; ++i)
+ l[i] = new wxStaticText(parent, wxID_ANY, wxT(" "));
+
+ m_grid->Add(l[0]);
+ m_grid->Add(new wxStaticText(parent, wxID_ANY, wxT(" ")));
+ m_grid->Add(l[1]);
+ m_grid->Add(new wxStaticText(parent, wxID_ANY, wxT(" ")));
+ m_grid->Add(ctrl, 1, wxEXPAND);
+ m_grid->Add(new wxStaticText(parent, wxID_ANY, wxT(" ")));
+ m_grid->Add(l[2]);
+ m_grid->Add(new wxStaticText(parent, wxID_ANY, wxT(" ")));
+ m_grid->Add(l[3]);
+
+ sizer->Add(m_grid);
+ parent->SetSizer(sizer);
+ parent->Layout();
+
+ parent->Refresh();
+ wxYield();
+
+ return wxRect(l[0]->GetScreenRect().GetBottomRight(),
+ l[3]->GetScreenRect().GetTopLeft());
+ }