]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/screenshotgen/src/screenshot_main.cpp
remove misleaing mentions of wxEXEC_ASYNC from wxExecute() overloads always executing...
[wxWidgets.git] / utils / screenshotgen / src / screenshot_main.cpp
index 13cb06d85e4015a5b92e09f1716918f5b23c9508..365518ade8bf6f881c042fdd6b86484342c2e882 100644 (file)
 
 #include "wx/aboutdlg.h"
 #include "wx/dir.h"
-#include "wx/filesys.h"
 
 #include "screenshot_main.h"
-#include "ctrlmaskout.h"
 #include "autocapture.h"
 
-#include "bitmaps/play.xpm"
-#include "bitmaps/stop.xpm"
-
-
 // ----------------------------------------------------------------------------
 // ScreenshotFrame
 // ----------------------------------------------------------------------------
@@ -40,87 +34,10 @@ ScreenshotFrame::ScreenshotFrame(wxFrame *frame) : GUIFrame(frame)
     statusBar->SetStatusText(_("Welcome to the Automatic Screenshot Generator!"), 0);
 #endif
 
-    // We will hold one ctrlmaskout during the whole life time of the main frame
-    m_maskout = new CtrlMaskOut();
-
-    // At the begining, we are not specifying the rect region
-    capturingRect = false;
-
-    // Do some further customization on some controls generated by wxFormBuilder
-    InitFBControls();
-}
-
-ScreenshotFrame::~ScreenshotFrame()
-{
-    delete m_maskout;
-}
-
-/*
-    Do some further customization on some controls.
-
-    NB: under wxGTK for the radio button "unchecked" to be unchecked, it's
-        important to put the wxRB_GROUP style on the first wxRadioButton
-        (the one "checked") and no flags on the second one.
-*/
-void ScreenshotFrame::InitFBControls()
-{
-    m_scrollBar1->SetScrollbar(50, 1, 100, 1);
-
-    // Do the default selection for wxComboBox
-    m_comboBox1->Select(0);
-
-    // To look better under gtk
-#ifdef __WXGTK__
-    m_comboBox1->Delete(4);
-#endif
-
-    // Add a root and some nodes for wxTreeCtrl
-    wxTreeItemId root = m_treeCtrl1->AddRoot(_("wxTreeCtrl"));
-    m_treeCtrl1->AppendItem(root, _("Node1"));
-    wxTreeItemId node2 = m_treeCtrl1->AppendItem(root, _("Node2"));
-    m_treeCtrl1->AppendItem(node2, _("Node3"));
-    m_treeCtrl1->ExpandAll();
-
-    // Add items into wxListCtrl
-    m_listCtrl1->InsertColumn(0, "Names");
-    m_listCtrl1->InsertColumn(1, "Values");
-    for(long index = 0; index < 5; index++) {
-        m_listCtrl1->InsertItem( index, wxString::Format(_("Item%d"),index));
-        m_listCtrl1->SetItem(index, 1, wxString::Format("%d", index));
-    }
-
-    // Init file and dir pickers
-    wxString file, dir;
-#if defined(__WXMSW__)
-    file = "C:\\Windows\\explorer.exe";
-    dir = "C:\\Windows";
-#else
-    file = "/bin/bash";
-    dir = "/home";
-#endif
-    m_filePicker1->SetPath(file);
-    m_dirPicker1->SetPath(dir);
-
-    // Check the first item in wxCheckListBox
-    m_checkList1->Check(0);
-
-    // Load richtext.xml into wxRichtextCtrl
-    m_richText1->LoadFile(_T("richtext.xml"));
-    //m_richText1->ShowPosition(335);
-
-    // select first page in the main notebook ctrl
-    m_notebook1->ChangeSelection(0);
-
     // set minimum size hints
     GetSizer()->SetSizeHints(this);
-
-    // add bitmaps to the menus
-    m_menuCapRect->SetBitmap( wxIcon(play_xpm) );
-    m_menuEndCapRect->SetBitmap( wxIcon(stop_xpm) );
 }
 
-
-
 // ----------------------------------------------------------------------------
 // ScreenshotFrame - event handlers
 // ----------------------------------------------------------------------------
@@ -137,14 +54,12 @@ void ScreenshotFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 
 void ScreenshotFrame::OnSeeScreenshots(wxCommandEvent& WXUNUSED(event))
 {
-    wxString defaultDir = m_maskout->GetDefaultDirectory();
-
-    // Check if defaultDir already existed
-    if (!wxDirExists(defaultDir))
-        wxMkdir(defaultDir);
+    wxString defaultDir = AutoCaptureMechanism::GetDefaultDirectoryAbsPath();
 
-    // Use the native file browser to open defaultDir
-    wxLaunchDefaultBrowser(wxFileSystem::FileNameToURL(defaultDir));
+    if (wxFileName::DirExists(defaultDir))
+        wxLaunchDefaultBrowser(defaultDir);
+    else
+        wxMessageBox(_("There isn't any screenshots yet."));
 }
 
 void ScreenshotFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
@@ -167,79 +82,18 @@ void ScreenshotFrame::OnCaptureFullScreen(wxCommandEvent& WXUNUSED(event))
     wxCoord screenWidth, screenHeight;
     dcScreen.GetSize(&screenWidth, &screenHeight);
 
-    m_maskout->Capture(0, 0, screenWidth, screenHeight, _T("fullscreen"));
+    wxBitmap fullscreen = AutoCaptureMechanism::Capture(0, 0, screenWidth, screenHeight);
 
-    // Inform the user
-    wxMessageBox(_("A screenshot of the entire screen was saved as:\n\n  ") +
-                 m_maskout->GetDefaultDirectoryAbsPath() + wxFileName::GetPathSeparator() + "fullscreen.png",
-                 _("Full screen capture"), wxICON_INFORMATION|wxOK, this);
-}
-
-void ScreenshotFrame::OnCaptureRect(wxCommandEvent& WXUNUSED(event))
-{
-    capturingRect = true;
-    wxMenuBar * menubar = this->GetMenuBar();
-    menubar->FindItem(idMenuCapRect)->Enable(false);
-    menubar->FindItem(idMenuEndCapRect)->Enable(true);
-
-    wxWindow * thePage = m_notebook1->GetPage(m_notebook1->GetSelection());
-
-    thePage->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout);
-    thePage->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout);
-    thePage->Connect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout);
-}
-
-void ScreenshotFrame::OnEndCaptureRect(wxCommandEvent& WXUNUSED(event))
-{
-    capturingRect = false;
-    wxMenuBar * menubar = this->GetMenuBar();
-    menubar->FindItem(idMenuCapRect)->Enable(true);
-    menubar->FindItem(idMenuEndCapRect)->Enable(false);
-
-    wxWindow * thePage = m_notebook1->GetPage(m_notebook1->GetSelection());
-
-    thePage->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout);
-    thePage->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout);
-    thePage->Disconnect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout);
-}
-
-void ScreenshotFrame::OnNotebookPageChanging(wxNotebookEvent& event)
-{
-    if (!capturingRect)
-    {
-        event.Skip();
-        return;
-    }
-
-    wxWindow * thePage = m_notebook1->GetPage(event.GetOldSelection());
-
-    thePage->Disconnect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout);
-    thePage->Disconnect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout);
-    thePage->Disconnect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout);
+    AutoCaptureMechanism::Save(fullscreen, _T("fullscreen"));
 
-    event.Skip();
-}
-
-void ScreenshotFrame::OnNotebookPageChanged(wxNotebookEvent& event)
-{
-    if (!capturingRect)
-    {
-        event.Skip();
-        return;
-    }
-
-    wxWindow *thePage = m_notebook1->GetPage(event.GetSelection());
-
-    thePage->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonDown ), NULL, m_maskout);
-    thePage->Connect( wxEVT_LEFT_UP, wxMouseEventHandler( CtrlMaskOut::OnLeftButtonUp ), NULL, m_maskout);
-    thePage->Connect( wxEVT_MOTION, wxMouseEventHandler( CtrlMaskOut::OnMouseMoving ), NULL, m_maskout);
-
-    event.Skip();
+    wxMessageBox(_("A screenshot of the entire screen was saved as:\n\n  ")
+                + AutoCaptureMechanism::GetDefaultDirectoryAbsPath() + _T("fullscreen.png"),
+                 _("Full screen capture"), wxICON_INFORMATION|wxOK, this);
 }
 
 void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
 {
-    wxString dir = m_maskout->GetDefaultDirectoryAbsPath();
+    wxString dir = AutoCaptureMechanism::GetDefaultDirectoryAbsPath();
 
     // check if there are other screenshots taken before
     if (wxFileName::DirExists(dir))
@@ -252,7 +106,7 @@ void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
             case wxYES:
             {
                 wxArrayString files;
-                wxDir::GetAllFiles(dir, &files, wxT("*.png"), wxDIR_FILES);
+                wxDir::GetAllFiles(dir, &files, _T("*.png"), wxDIR_FILES);
 
                 // remove all PNG files from the screenshots folder
                 int n = files.GetCount();
@@ -280,11 +134,11 @@ void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
     auto_cap.RegisterControl(m_radioBtn2, AJ_UnionEnd);
     auto_cap.RegisterControl(m_bpButton1);
     auto_cap.RegisterControl(m_bitmap1);
-    auto_cap.RegisterControl(m_gauge1, wxT("wxGauge"));
+    auto_cap.RegisterControl(m_gauge1, _T("wxGauge"));
     auto_cap.RegisterControl(m_slider1);
     auto_cap.RegisterControl(m_toggleBtn1, AJ_Union);
     auto_cap.RegisterControl(m_toggleBtn2, AJ_UnionEnd);
-    auto_cap.RegisterControl(m_hyperlink1, wxT("wxHyperlinkCtrl"));
+    auto_cap.RegisterControl(m_hyperlink1, _T("wxHyperlinkCtrl"));
     auto_cap.RegisterControl(m_spinCtrl1, AJ_RegionAdjust);
     auto_cap.RegisterControl(m_spinBtn1);
     auto_cap.RegisterControl(m_scrollBar1);
@@ -296,10 +150,10 @@ void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
     auto_cap.RegisterControl(m_radioBox1);
     auto_cap.RegisterControl(m_staticBox1);
     auto_cap.RegisterControl(m_treeCtrl1);
-    auto_cap.RegisterControl(m_listCtrl1, wxT("wxListCtrl"));
+    auto_cap.RegisterControl(m_listCtrl1, _T("wxListCtrl"));
 
     auto_cap.RegisterControl(m_animationCtrl1);
-    auto_cap.RegisterControl(m_collPane1, wxT("wxCollapsiblePane"), AJ_Union);
+    auto_cap.RegisterControl(m_collPane1, _T("wxCollapsiblePane"), AJ_Union);
     auto_cap.RegisterControl(m_collPane2, AJ_UnionEnd);
 
     auto_cap.RegisterPageTurn();
@@ -310,13 +164,13 @@ void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
 
     auto_cap.RegisterPageTurn();
 
-    auto_cap.RegisterControl(m_colourPicker1, wxT("wxColourPickerCtrl"));
-    auto_cap.RegisterControl(m_fontPicker1, wxT("wxFontPickerCtrl"));
-    auto_cap.RegisterControl(m_filePicker1, wxT("wxFilePickerCtrl"), AJ_RegionAdjust);
-    auto_cap.RegisterControl(m_calendar1, wxT("wxCalendarCtrl"), AJ_RegionAdjust);
-    auto_cap.RegisterControl(m_datePicker1, wxT("wxDatePickerCtrl"));
-    auto_cap.RegisterControl(m_genericDirCtrl1, wxT("wxGenericDirCtrl"));
-    auto_cap.RegisterControl(m_dirPicker1, wxT("wxDirPickerCtrl"), AJ_RegionAdjust);
+    auto_cap.RegisterControl(m_colourPicker1, _T("wxColourPickerCtrl"));
+    auto_cap.RegisterControl(m_fontPicker1, _T("wxFontPickerCtrl"));
+    auto_cap.RegisterControl(m_filePicker1, _T("wxFilePickerCtrl"), AJ_RegionAdjust);
+    auto_cap.RegisterControl(m_calendar1, _T("wxCalendarCtrl"), AJ_RegionAdjust);
+    auto_cap.RegisterControl(m_datePicker1, _T("wxDatePickerCtrl"));
+    auto_cap.RegisterControl(m_genericDirCtrl1, _T("wxGenericDirCtrl"));
+    auto_cap.RegisterControl(m_dirPicker1, _T("wxDirPickerCtrl"), AJ_RegionAdjust);
 
     auto_cap.RegisterPageTurn();