]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/screenshotgen/src/screenshot_main.cpp
using scan-line polygon conversion for constructing wxregion
[wxWidgets.git] / utils / screenshotgen / src / screenshot_main.cpp
index a8697bdbae959dbf480a57948e6e177770227e5e..9dd085e648546b8c30799ac6f8cd27e7ad173bb7 100644 (file)
 /////////////////////////////////////////////////////////////////////////////
 // Name:        screenshot_main.cpp
 /////////////////////////////////////////////////////////////////////////////
 // Name:        screenshot_main.cpp
-// Purpose:     Implement the Application Frame
+// Purpose:     Implements the window containing all controls.
 // Author:      Utensil Candel (UtensilCandel@@gmail.com)
 // RCS-ID:      $Id$
 // Author:      Utensil Candel (UtensilCandel@@gmail.com)
 // RCS-ID:      $Id$
-// Licence:     wxWindows license
+// Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
 /////////////////////////////////////////////////////////////////////////////
 
 // For compilers that support precompilation, includes "wx/wx.h".
 #include "wx/wxprec.h"
 
 #ifdef __BORLANDC__
-    #pragma hdrstop
+#pragma hdrstop
 #endif
 
 #endif
 
-// for all others, include the necessary headers
+// for all others, include the necessary headers wxWidgets headers)
 #ifndef WX_PRECOMP
 #ifndef WX_PRECOMP
-    #include <wx/filename.h>
-    #include <wx/dcbuffer.h>
-    #include <wx/colordlg.h>
-    #include <wx/fontdlg.h>
-    #include <wx/filedlg.h>
-    #include <wx/dirdlg.h>
+#include "wx/wx.h"
 #endif
 
 #endif
 
-#include <wx/dir.h>
-#include <wx/aboutdlg.h>
-#include <wx/msgdlg.h>
-#include <wx/dcscreen.h>
-#include <wx/filesys.h>
-#include <wx/utils.h>
+#include "wx/aboutdlg.h"
+#include "wx/dir.h"
 
 #include "screenshot_main.h"
 
 #include "screenshot_main.h"
-#include "ctrlmaskout.h"
 #include "autocapture.h"
 
 #include "autocapture.h"
 
-
 // ----------------------------------------------------------------------------
 // ScreenshotFrame
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 // ScreenshotFrame
 // ----------------------------------------------------------------------------
 
-ScreenshotFrame::ScreenshotFrame(wxFrame *frame)
-#if SCREENSHOTGEN_USE_AUI
-: AuiGUIFrame(frame)
-#else
-: GUIFrame(frame)
-#endif
+ScreenshotFrame::ScreenshotFrame(wxFrame *frame) : GUIFrame(frame)
 {
 #if wxUSE_STATUSBAR
     statusBar->SetStatusText(_("Welcome to the Automatic Screenshot Generator!"), 0);
 #endif
 
 {
 #if wxUSE_STATUSBAR
     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();
-#if SCREENSHOTGEN_USE_AUI
-    // Somehow it will be very small after I move to Aui
-    SetSize(600, 600);
-    // Maximize(true);
-#endif
-}
-
-ScreenshotFrame::~ScreenshotFrame()
-{
-    delete m_maskout;
-}
-
-/*
-    Do some further customization on some controls generated by wxFormBuilder.
-
-    wxFormBuilder does not allow customizations on some controls;
-    e.g. you cannot load a richtext file in a wxRichtextCtrl during initialization.
-
-    Those customizations will be done here.
-*/
-void ScreenshotFrame::InitFBControls()
-{
-    // explicitely uncheck radio button:
-    m_radioBtn2->SetValue(false);
-
-    // For some reason, wxFormBuilder does not set the scrollbar range
-    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
-    for(long index = 0; index < 5; index++)
-        m_listCtrl1->InsertItem( index, wxString::Format(_("Item\n(0,%d)"),index));
-
-    // 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);
 }
 
     // set minimum size hints
     GetSizer()->SetSizeHints(this);
 }
 
-
-
 // ----------------------------------------------------------------------------
 // ScreenshotFrame - event handlers
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // ScreenshotFrame - event handlers
 // ----------------------------------------------------------------------------
@@ -137,14 +54,12 @@ void ScreenshotFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
 
 void ScreenshotFrame::OnSeeScreenshots(wxCommandEvent& WXUNUSED(event))
 {
 
 void ScreenshotFrame::OnSeeScreenshots(wxCommandEvent& WXUNUSED(event))
 {
-    wxString defaultDir = m_maskout->GetDefaultDirectory();
+    wxString defaultDir = AutoCaptureMechanism::GetDefaultDirectoryAbsPath();
 
 
-    // Check if defaultDir already existed
-    if (!wxDirExists(defaultDir))
-        wxMkdir(defaultDir);
-
-    // 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))
 }
 
 void ScreenshotFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
@@ -152,8 +67,8 @@ void ScreenshotFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
     wxAboutDialogInfo info;
     info.SetName(_("Automatic Screenshot Generator"));
     info.SetVersion(_("1.0"));
     wxAboutDialogInfo info;
     info.SetName(_("Automatic Screenshot Generator"));
     info.SetVersion(_("1.0"));
-    info.SetDescription(_("This utility automatically creates screenshots of wxWidgets controls for ues in wxWidgets documentation."));
-    info.SetCopyright(_T("(C) 2008 Utensil Candel"));
+    info.SetDescription(_("This utility automatically creates screenshots of wxWidgets controls for use in wxWidgets documentation."));
+    info.SetCopyright(wxT("(C) 2008 Utensil Candel"));
 
     wxAboutBox(info);
 }
 
     wxAboutBox(info);
 }
@@ -167,98 +82,28 @@ void ScreenshotFrame::OnCaptureFullScreen(wxCommandEvent& WXUNUSED(event))
     wxCoord screenWidth, screenHeight;
     dcScreen.GetSize(&screenWidth, &screenHeight);
 
     wxCoord screenWidth, screenHeight;
     dcScreen.GetSize(&screenWidth, &screenHeight);
 
-    m_maskout->Capture(0, 0, screenWidth, screenHeight, _T("fullscreen"));
-
-    // 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(
-#if SCREENSHOTGEN_USE_AUI
-wxAuiNotebookEvent& event
-#else
-wxNotebookEvent& event
-#endif
-)
-{
-    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);
-
-    event.Skip();
-}
-
-void ScreenshotFrame::OnNotebookPageChanged(
-#if SCREENSHOTGEN_USE_AUI
-wxAuiNotebookEvent& event
-#else
-wxNotebookEvent& event
-#endif
-)
-{
-    if (!capturingRect)
-    {
-        event.Skip();
-        return;
-    }
+    wxBitmap fullscreen(1, 1);
+    AutoCaptureMechanism::Capture(&fullscreen, 0, 0, screenWidth, screenHeight);
 
 
-    wxWindow *thePage = m_notebook1->GetPage(event.GetSelection());
+    AutoCaptureMechanism::Save(&fullscreen, wxT("fullscreen"));
 
 
-    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() + wxT("fullscreen.png"),
+                 _("Full screen capture"), wxICON_INFORMATION|wxOK, this);
 }
 
 void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
 {
 }
 
 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))
     {
 
     // check if there are other screenshots taken before
     if (wxFileName::DirExists(dir))
     {
-        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."),
-                            _("Delete existing screenshots?"),
-                            wxYES_NO|wxCANCEL|wxICON_QUESTION, this);
+        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."),
+            _("Delete existing screenshots?"),
+            wxYES_NO | wxCANCEL | wxICON_QUESTION, this);
+
         switch(choice)
         {
             case wxYES:
         switch(choice)
         {
             case wxYES:
@@ -296,7 +141,7 @@ void ScreenshotFrame::OnCaptureAllControls(wxCommandEvent& WXUNUSED(event))
     auto_cap.RegisterControl(m_slider1);
     auto_cap.RegisterControl(m_toggleBtn1, AJ_Union);
     auto_cap.RegisterControl(m_toggleBtn2, AJ_UnionEnd);
     auto_cap.RegisterControl(m_slider1);
     auto_cap.RegisterControl(m_toggleBtn1, AJ_Union);
     auto_cap.RegisterControl(m_toggleBtn2, AJ_UnionEnd);
-    auto_cap.RegisterControl(m_hyperlink1);
+    auto_cap.RegisterControl(m_hyperlink1, wxT("wxHyperlinkCtrl"));
     auto_cap.RegisterControl(m_spinCtrl1, AJ_RegionAdjust);
     auto_cap.RegisterControl(m_spinBtn1);
     auto_cap.RegisterControl(m_scrollBar1);
     auto_cap.RegisterControl(m_spinCtrl1, AJ_RegionAdjust);
     auto_cap.RegisterControl(m_spinBtn1);
     auto_cap.RegisterControl(m_scrollBar1);