⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view.cpp

📁 wxGTK 是 wxWidgets 的 linux GTK+ (>2.2.3)版本。wxWidgets 是一个跨平台的 GUI 框架
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/////////////////////////////////////////////////////////////////////////////// Name:        contrib/samples/ogl/studio/view.cpp// Purpose:     Implements view functionality// Author:      Julian Smart// Modified by:// Created:     12/07/98// RCS-ID:      $Id: view.cpp,v 1.13 2006/02/10 11:59:49 ABX Exp $// Copyright:   (c) Julian Smart// Licence:     wxWindows licence/////////////////////////////////////////////////////////////////////////////// For compilers that support precompilation, includes "wx.h".#include "wx/wxprec.h"#ifdef __BORLANDC__#pragma hdrstop#endif#ifndef WX_PRECOMP#include "wx/wx.h"#endif#include "wx/colordlg.h"#if !wxUSE_DOC_VIEW_ARCHITECTURE#error You must set wxUSE_DOC_VIEW_ARCHITECTURE to 1 in wx_setup.h!#endif#include "studio.h"#include "doc.h"#include "view.h"#include "cspalette.h"#include "symbols.h"#include "dialogs.h"#include "wx/ogl/basicp.h"#include "wx/ogl/linesp.h"IMPLEMENT_DYNAMIC_CLASS(csDiagramView, wxView)BEGIN_EVENT_TABLE(csDiagramView, wxView)    EVT_MENU(wxID_CUT, csDiagramView::OnCut)    EVT_MENU(wxID_COPY, csDiagramView::OnCopy)    EVT_MENU(wxID_CLEAR, csDiagramView::OnClear)    EVT_MENU(wxID_PASTE, csDiagramView::OnPaste)    EVT_MENU(wxID_DUPLICATE, csDiagramView::OnDuplicate)    EVT_MENU(ID_CS_CHANGE_BACKGROUND_COLOUR, csDiagramView::OnChangeBackgroundColour)    EVT_MENU(ID_CS_EDIT_PROPERTIES, csDiagramView::OnEditProperties)    EVT_MENU(ID_CS_SELECT_ALL, csDiagramView::OnSelectAll)    EVT_TOOL(DIAGRAM_TOOLBAR_LINE_ARROW, csDiagramView::OnToggleArrowTool)    EVT_COMBOBOX(ID_WINDOW_POINT_SIZE_COMBOBOX, csDiagramView::OnPointSizeComboSel)    EVT_COMBOBOX(ID_WINDOW_ZOOM_COMBOBOX, csDiagramView::OnZoomSel)    EVT_TEXT(ID_WINDOW_POINT_SIZE_COMBOBOX, csDiagramView::OnPointSizeComboText)    EVT_TOOL(DIAGRAM_TOOLBAR_ALIGNL, csDiagramView::OnAlign)    EVT_TOOL(DIAGRAM_TOOLBAR_ALIGNR, csDiagramView::OnAlign)    EVT_TOOL(DIAGRAM_TOOLBAR_ALIGNB, csDiagramView::OnAlign)    EVT_TOOL(DIAGRAM_TOOLBAR_ALIGNT, csDiagramView::OnAlign)    EVT_TOOL(DIAGRAM_TOOLBAR_ALIGN_HORIZ, csDiagramView::OnAlign)    EVT_TOOL(DIAGRAM_TOOLBAR_ALIGN_VERT, csDiagramView::OnAlign)    EVT_TOOL(DIAGRAM_TOOLBAR_COPY_SIZE, csDiagramView::OnAlign)    EVT_TOOL(DIAGRAM_TOOLBAR_NEW_POINT, csDiagramView::OnNewLinePoint)    EVT_TOOL(DIAGRAM_TOOLBAR_CUT_POINT, csDiagramView::OnCutLinePoint)    EVT_TOOL(DIAGRAM_TOOLBAR_STRAIGHTEN, csDiagramView::OnStraightenLines)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_ALIGNL, csDiagramView::OnAlignUpdate)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_ALIGNR, csDiagramView::OnAlignUpdate)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_ALIGNB, csDiagramView::OnAlignUpdate)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_ALIGNT, csDiagramView::OnAlignUpdate)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_ALIGN_HORIZ, csDiagramView::OnAlignUpdate)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_ALIGN_VERT, csDiagramView::OnAlignUpdate)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_COPY_SIZE, csDiagramView::OnAlignUpdate)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_NEW_POINT, csDiagramView::OnNewLinePointUpdate)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_CUT_POINT, csDiagramView::OnCutLinePointUpdate)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_STRAIGHTEN, csDiagramView::OnStraightenLinesUpdate)    EVT_UPDATE_UI(DIAGRAM_TOOLBAR_LINE_ARROW, csDiagramView::OnToggleArrowToolUpdate)    EVT_UPDATE_UI(wxID_CUT, csDiagramView::OnCutUpdate)    EVT_UPDATE_UI(wxID_COPY, csDiagramView::OnCopyUpdate)    EVT_UPDATE_UI(wxID_CLEAR, csDiagramView::OnClearUpdate)    EVT_UPDATE_UI(wxID_PASTE, csDiagramView::OnPasteUpdate)    EVT_UPDATE_UI(wxID_DUPLICATE, csDiagramView::OnDuplicateUpdate)    EVT_UPDATE_UI(ID_CS_EDIT_PROPERTIES, csDiagramView::OnEditPropertiesUpdate)    EVT_UPDATE_UI(wxID_UNDO, csDiagramView::OnUndoUpdate)    EVT_UPDATE_UI(wxID_REDO, csDiagramView::OnRedoUpdate)END_EVENT_TABLE()// What to do when a view is created. Creates actual// windows for displaying the view.bool csDiagramView::OnCreate(wxDocument *doc, long WXUNUSED(flags)){  wxMenu* editMenu;  frame = wxGetApp().CreateChildFrame(doc, this, &editMenu);  canvas = wxGetApp().CreateCanvas(this, frame);  canvas->SetView(this);  SetFrame(frame);  Activate(true);  // Initialize the edit menu Undo and Redo items  doc->GetCommandProcessor()->SetEditMenu(editMenu);  doc->GetCommandProcessor()->Initialize();  wxShapeCanvas *shapeCanvas = (wxShapeCanvas *)canvas;  csDiagramDocument *diagramDoc = (csDiagramDocument *)doc;  shapeCanvas->SetDiagram(diagramDoc->GetDiagram());  diagramDoc->GetDiagram()->SetCanvas(shapeCanvas);  diagramDoc->GetDiagram()->SetGridSpacing((double) wxGetApp().GetGridSpacing());    switch (wxGetApp().GetGridStyle())    {        case csGRID_STYLE_NONE:        {            diagramDoc->GetDiagram()->SetSnapToGrid(false);            break;        }        case csGRID_STYLE_INVISIBLE:        {            diagramDoc->GetDiagram()->SetSnapToGrid(true);            break;        }        case csGRID_STYLE_DOTTED:        {            // TODO (not implemented in OGL)            break;        }    }  return true;}csDiagramView::~csDiagramView(void){    if (frame)    {        ((wxDocMDIChildFrame*)frame)->SetView(NULL);    }}// Sneakily gets used for default print/preview// as well as drawing on the screen.void csDiagramView::OnDraw(wxDC *WXUNUSED(dc)){}void csDiagramView::OnUpdate(wxView *WXUNUSED(sender), wxObject *WXUNUSED(hint)){  if (canvas)    canvas->Refresh();}// Clean up windows used for displaying the view.bool csDiagramView::OnClose(bool deleteWindow){  if (!GetDocument()->Close())    return false;  csDiagramDocument *diagramDoc = (csDiagramDocument *)GetDocument();  diagramDoc->GetDiagram()->SetCanvas(NULL);  canvas->ClearBackground();  canvas->SetDiagram(NULL);  canvas->SetView(NULL);  canvas = NULL;  wxMenu* fileMenu = frame->GetMenuBar()->GetMenu(0);  // Remove file menu from those managed by the command history  wxGetApp().GetDocManager()->FileHistoryRemoveMenu(fileMenu);  Activate(false);  frame->Show(false);  if (deleteWindow)  {    frame->Destroy();  }  return true;}// Adds or removes shape from m_selectionsvoid csDiagramView::SelectShape(wxShape* shape, bool select){    if (select && !m_selections.Member(shape))        m_selections.Append(shape);    else if (!select)        m_selections.DeleteObject(shape);}void csDiagramView::OnSelectAll(wxCommandEvent& WXUNUSED(event)){    SelectAll(true);}wxShape *csDiagramView::FindFirstSelectedShape(void){  csDiagramDocument *doc = (csDiagramDocument *)GetDocument();  wxObjectList::compatibility_iterator node = doc->GetDiagram()->GetShapeList()->GetFirst();  while (node)  {    wxShape *eachShape = (wxShape *)node->GetData();    if ((eachShape->GetParent() == NULL) && !eachShape->IsKindOf(CLASSINFO(wxLabelShape)) && eachShape->Selected())    {      return eachShape;    }    else node = node->GetNext();  }  return NULL;}void csDiagramView::FindSelectedShapes(wxList& selections, wxClassInfo* toFind){  csDiagramDocument *doc = (csDiagramDocument *)GetDocument();  wxObjectList::compatibility_iterator node = doc->GetDiagram()->GetShapeList()->GetFirst();  while (node)  {    wxShape *eachShape = (wxShape *)node->GetData();    if ((eachShape->GetParent() == NULL) && !eachShape->IsKindOf(CLASSINFO(wxLabelShape)) && eachShape->Selected() && ((toFind == NULL) || (eachShape->IsKindOf(toFind))))    {      selections.Append(eachShape);    }    node = node->GetNext();  }}void csDiagramView::OnUndoUpdate(wxUpdateUIEvent& event){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    event.Enable(doc->GetCommandProcessor()->CanUndo());}void csDiagramView::OnRedoUpdate(wxUpdateUIEvent& event){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    event.Enable(doc->GetCommandProcessor()->CanRedo());}void csDiagramView::OnCut(wxCommandEvent& WXUNUSED(event)){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    // Copy the shapes to the clipboard    wxGetApp().GetDiagramClipboard().Copy(doc->GetDiagram());    wxList selections;    FindSelectedShapes(selections);    DoCut(selections);}void csDiagramView::OnClear(wxCommandEvent& WXUNUSED(event)){    wxList selections;    FindSelectedShapes(selections);    DoCut(selections);}void csDiagramView::OnCopy(wxCommandEvent& WXUNUSED(event)){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    // Copy the shapes to the clipboard    if (wxGetApp().GetDiagramClipboard().Copy(doc->GetDiagram()))    {#ifdef __WXMSW__        // Copy to the Windows clipboard        wxGetApp().GetDiagramClipboard().CopyToClipboard(1.0);#endif    }}void csDiagramView::OnPaste(wxCommandEvent& WXUNUSED(event)){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    wxGetApp().GetDiagramClipboard().Paste(doc->GetDiagram());}void csDiagramView::OnDuplicate(wxCommandEvent& WXUNUSED(event)){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    // Do a copy, then a paste    wxGetApp().GetDiagramClipboard().Copy(doc->GetDiagram());    // Apply an offset. Really, this offset should keep being incremented,    // but where do we reset it again?    wxGetApp().GetDiagramClipboard().Paste(doc->GetDiagram(), NULL, 20, 20);}void csDiagramView::OnCutUpdate(wxUpdateUIEvent& event){    event.Enable( (m_selections.GetCount() > 0) );}void csDiagramView::OnClearUpdate(wxUpdateUIEvent& event){    event.Enable( (m_selections.GetCount() > 0) );}void csDiagramView::OnCopyUpdate(wxUpdateUIEvent& event){    event.Enable( (m_selections.GetCount() > 0) );}void csDiagramView::OnPasteUpdate(wxUpdateUIEvent& event){    int n = wxGetApp().GetDiagramClipboard().GetCount();    event.Enable( (n > 0) );}void csDiagramView::OnDuplicateUpdate(wxUpdateUIEvent& event){    event.Enable( (m_selections.GetCount() > 0) );}void csDiagramView::DoCut(wxList& shapes){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    if (shapes.GetCount() > 0)    {        csDiagramCommand* cmd = new csDiagramCommand(_T("Cut"), doc);        wxObjectList::compatibility_iterator node = shapes.GetFirst();        while (node)        {            wxShape *theShape = (wxShape*) node->GetData();            csCommandState* state = new csCommandState(ID_CS_CUT, NULL, theShape);            // Insert lines at the front, so they are cut first.            // Otherwise we may try to remove a shape with a line still            // attached.            if (theShape->IsKindOf(CLASSINFO(wxLineShape)))                cmd->InsertState(state);            else                cmd->AddState(state);            node = node->GetNext();        }        cmd->RemoveLines(); // Schedule any connected lines, not already mentioned,                            // to be removed first        doc->GetCommandProcessor()->Submit(cmd);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -