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

📄 view.cpp

📁 wxGTK 是 wxWidgets 的 linux GTK+ (>2.2.3)版本。wxWidgets 是一个跨平台的 GUI 框架
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// Generalised commandvoid csDiagramView::DoCmd(wxList& shapes, wxList& oldShapes, int cmd, const wxString& op){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    if (shapes.GetCount() > 0)    {        csDiagramCommand* command = new csDiagramCommand(op, doc);        wxObjectList::compatibility_iterator node = shapes.GetFirst();        wxObjectList::compatibility_iterator node1 = oldShapes.GetFirst();        while (node && node1)        {            wxShape *theShape = (wxShape*) node->GetData();            wxShape *oldShape = (wxShape*) node1->GetData();            csCommandState* state = new csCommandState(cmd, theShape, oldShape);            command->AddState(state);            node = node->GetNext();            node1 = node1->GetNext();        }        doc->GetCommandProcessor()->Submit(command);    }}void csDiagramView::OnChangeBackgroundColour(wxCommandEvent& WXUNUSED(event)){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    wxList selections;    FindSelectedShapes(selections);    if (selections.GetCount() > 0)    {        wxColourData data;        data.SetChooseFull(true);        if (selections.GetCount() == 1)        {            wxShape* firstShape = (wxShape*) selections.GetFirst()->GetData();            data.SetColour(firstShape->GetBrush()->GetColour());        }        wxColourDialog *dialog = new wxColourDialog(frame, &data);        wxBrush *theBrush = NULL;        if (dialog->ShowModal() == wxID_OK)        {          wxColourData retData = dialog->GetColourData();          wxColour col = retData.GetColour();          theBrush = wxTheBrushList->FindOrCreateBrush(col, wxSOLID);        }        dialog->Close(true);        if (!theBrush)            return;        csDiagramCommand* cmd = new csDiagramCommand(_T("Change colour"), doc);        wxObjectList::compatibility_iterator node = selections.GetFirst();        while (node)        {            wxShape *theShape = (wxShape*) node->GetData();            wxShape* newShape = theShape->CreateNewCopy();            newShape->SetBrush(theBrush);            csCommandState* state = new csCommandState(ID_CS_CHANGE_BACKGROUND_COLOUR, newShape, theShape);            cmd->AddState(state);            node = node->GetNext();        }        doc->GetCommandProcessor()->Submit(cmd);    }}void csDiagramView::OnEditProperties(wxCommandEvent& WXUNUSED(event)){      wxShape *theShape = FindFirstSelectedShape();      if (theShape)        ((csEvtHandler *)theShape->GetEventHandler())->EditProperties();}void csDiagramView::OnEditPropertiesUpdate(wxUpdateUIEvent& event){    wxList selections;    FindSelectedShapes(selections);    event.Enable( (selections.GetCount() > 0) );}void csDiagramView::OnPointSizeComboSel(wxCommandEvent& event){    wxComboBox* combo = (wxComboBox*) event.GetEventObject();    wxASSERT( combo != NULL );    int newPointSize = (combo->GetSelection() + 1);    ApplyPointSize(newPointSize);}// TODO: must find out how to intercept the Return key, rather than// every key stroke. But for now, do every key stroke.void csDiagramView::OnPointSizeComboText(wxCommandEvent& event){    wxComboBox* combo = (wxComboBox*) event.GetEventObject();    wxASSERT( combo != NULL );    wxString str(combo->GetValue());    long newPointSize;    str.ToLong( &newPointSize );    if (newPointSize < 2)        return;    ApplyPointSize(newPointSize);}void csDiagramView::ApplyPointSize(int pointSize){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    wxList selections;    FindSelectedShapes(selections);    if (selections.GetCount() > 0)    {        csDiagramCommand* cmd = new csDiagramCommand(_T("Point size"), doc);        wxObjectList::compatibility_iterator node = selections.GetFirst();        while (node)        {            wxShape *theShape = (wxShape*) node->GetData();            wxShape *newShape = theShape->CreateNewCopy();            wxFont* newFont = wxTheFontList->FindOrCreateFont(pointSize,                theShape->GetFont()->GetFamily(),                theShape->GetFont()->GetStyle(),                theShape->GetFont()->GetWeight(),                theShape->GetFont()->GetUnderlined(),                theShape->GetFont()->GetFaceName());            newShape->SetFont(newFont);            csCommandState* state = new csCommandState(ID_CS_FONT_CHANGE, newShape, theShape);            cmd->AddState(state);            node = node->GetNext();        }        doc->GetCommandProcessor()->Submit(cmd);    }}void csDiagramView::OnZoomSel(wxCommandEvent& event){    int maxZoom = 200;    int minZoom = 5;    int inc = 5;    int noStrings = (maxZoom - minZoom)/inc ;    wxComboBox* combo = (wxComboBox*) event.GetEventObject();    wxASSERT( combo != NULL );    int scale = (int) ((noStrings - combo->GetSelection() - 1)*inc + minZoom);    canvas->SetScale((double) (scale/100.0), (double) (scale/100.0));    canvas->Refresh();}// Select or deselect allvoid csDiagramView::SelectAll(bool select){    wxClientDC dc(canvas);    canvas->PrepareDC(dc);    if (!select)    {        wxList selections;        FindSelectedShapes(selections);        wxObjectList::compatibility_iterator node = selections.GetFirst();        while (node)        {            wxShape *theShape = (wxShape*) node->GetData();            theShape->Select(false, &dc);            SelectShape(theShape, false);            node = node->GetNext();        }    }    else    {        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(wxControlPoint)) &&                !eachShape->IsKindOf(CLASSINFO(wxLabelShape)))            {                eachShape->Select(true, &dc);                SelectShape(eachShape, true);            }            node = node->GetNext();        }    }}void csDiagramView::OnToggleArrowTool(wxCommandEvent& WXUNUSED(event)){    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    bool state = wxGetApp().GetDiagramToolBar()->GetToolState(DIAGRAM_TOOLBAR_LINE_ARROW);    wxString stateName;    if (state)        stateName = _T("Arrow on");    else        stateName = _T("Arrow off");    wxList selections;    FindSelectedShapes(selections, CLASSINFO(wxLineShape));    if (selections.GetCount() > 0)    {        csDiagramCommand* cmd = new csDiagramCommand(stateName, doc);        wxObjectList::compatibility_iterator node = selections.GetFirst();        while (node)        {            wxLineShape *theShape = (wxLineShape*) node->GetData();            wxLineShape *newShape = NULL;            if (state)            {                // Add arrow                if (theShape->GetArrows().GetCount() == 0)                {                    newShape = (wxLineShape*) theShape->CreateNewCopy();                    newShape->AddArrow(ARROW_ARROW, ARROW_POSITION_MIDDLE, 10.0, 0.0, _T("Normal arrowhead"));                }            }            else            {                if (theShape->GetArrows().GetCount() > 0)                {                    newShape = (wxLineShape*) theShape->CreateNewCopy();                    newShape->ClearArrowsAtPosition();                }            }            // If the new state is the same as the old, don't bother adding it to the command state.            if (newShape)            {                csCommandState* state = new csCommandState(ID_CS_ARROW_CHANGE, newShape, theShape);                cmd->AddState(state);            }            node = node->GetNext();        }        doc->GetCommandProcessor()->Submit(cmd);    }}void csDiagramView::OnToggleArrowToolUpdate(wxUpdateUIEvent& event){    wxList selections;    FindSelectedShapes(selections, CLASSINFO(wxLineShape));    event.Enable( (selections.GetCount() > 0) );}// Make the point size combobox reflect thisvoid csDiagramView::ReflectPointSize(int pointSize){    wxComboBox* comboBox = wxGetApp().GetPointSizeComboBox();    comboBox->SetSelection(pointSize -1);}// Make the arrow toggle button reflect the state of the linevoid csDiagramView::ReflectArrowState(wxLineShape* lineShape){    bool haveArrow = false;    wxObjectList::compatibility_iterator node = lineShape->GetArrows().GetFirst();    while (node)    {      wxArrowHead *arrow = (wxArrowHead *)node->GetData();      if (ARROW_POSITION_MIDDLE == arrow->GetArrowEnd())        haveArrow = true;      node = node->GetNext();    }    wxGetApp().GetDiagramToolBar()->ToggleTool(DIAGRAM_TOOLBAR_LINE_ARROW, haveArrow);}void csDiagramView::OnAlign(wxCommandEvent& event){    // Make a copy of the selections, keeping only those shapes    // that are top-level non-line shapes.    wxList selections;    wxObjectList::compatibility_iterator node = GetSelectionList().GetFirst();    while (node)    {        wxShape* shape = (wxShape*) node->GetData();        if ((shape->GetParent() == NULL) && (!shape->IsKindOf(CLASSINFO(wxLineShape))))        {            selections.Append(shape);        }        node = node->GetNext();    }    if (selections.GetCount() == 0)        return;    csDiagramDocument *doc = (csDiagramDocument *)GetDocument();    csDiagramCommand* cmd = new csDiagramCommand(_T("Align"), doc);    node = selections.GetFirst();    wxShape* firstShape = (wxShape*) node->GetData();    double x = firstShape->GetX();    double y = firstShape->GetY();    double width, height;    firstShape->GetBoundingBoxMax(&width, &height);    node = selections.GetFirst();    while (node)    {        wxShape* shape = (wxShape*) node->GetData();        if (shape != firstShape)        {            /* double x1 = */ shape->GetX();            /* double y1 = */ shape->GetY();            double width1, height1;            shape->GetBoundingBoxMax(& width1, & height1);            wxShape* newShape = shape->CreateNewCopy();            switch (event.GetId())            {                case DIAGRAM_TOOLBAR_ALIGNL:                {                    double x2 = (double)(x - (width/2.0) + (width1/2.0));                    newShape->SetX(x2);                    break;                }                case DIAGRAM_TOOLBAR_ALIGNR:                {                    double x2 = (double)(x + (width/2.0) - (width1/2.0));

⌨️ 快捷键说明

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