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

📄 configtooldoc.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{
    if (item->GetParent())
    {
        wxObjectList::compatibility_iterator node = item->GetParent()->GetChildren().Member(item);
        if (node && node->GetNext())
        {
            ctConfigItem* nextItem = (ctConfigItem*) node->GetNext()->GetData();
            return nextItem;
        }
    }
    return NULL;
}


/*
 * Implements a document editing command.
 */

ctConfigCommand::ctConfigCommand(const wxString& name, int cmdId,
        ctConfigItem* activeState, ctConfigItem* savedState,
        ctConfigItem* parent, ctConfigItem* insertBefore,
        bool ignoreFirstTime): wxCommand(true, name)
{
    m_activeState = activeState;
    m_savedState = savedState;
    m_ignoreThis = ignoreFirstTime;
    m_cmdId = cmdId;
    m_properties = NULL;
    m_parent = parent;
    m_insertBefore = insertBefore;
}

ctConfigCommand::ctConfigCommand(const wxString& name, int cmdId,
        ctConfigItem* activeState,  ctProperties* properties,
        bool ignoreFirstTime): wxCommand(true, name)
{
    m_activeState = activeState;
    m_savedState = NULL;
    m_properties = properties;
    m_ignoreThis = ignoreFirstTime;
    m_cmdId = cmdId;
    m_properties = properties;
    m_parent = NULL;
    m_insertBefore = NULL;
}

ctConfigCommand::~ctConfigCommand()
{
    if (m_savedState)
        delete m_savedState;
    if (m_properties)
        delete m_properties;
}

bool ctConfigCommand::Do()
{
    return DoAndUndo(true);
}

bool ctConfigCommand::Undo()
{
    return DoAndUndo(false);
}

// Combine Do and Undo into one
bool ctConfigCommand::DoAndUndo(bool doCmd)
{
    switch (m_cmdId)
    {
    case ctCMD_CUT:
        {
            if (doCmd)
            {
                wxASSERT(m_savedState == NULL);
                wxASSERT(m_activeState != NULL);

                ctConfigItem* newItem = m_activeState->DeepClone();
                ctConfigToolDoc* doc = m_activeState->GetDocument();

                // This will delete the old clipboard contents, if any.
                doc->SetClipboardItem(newItem);

                m_parent = m_activeState->GetParent();
                m_insertBefore = m_activeState->FindNextSibling();

                m_activeState->Detach();
                m_savedState = m_activeState;
                m_activeState = NULL;

                m_savedState->GetDocument()->Modify(true);
                ctConfigToolView* view = (ctConfigToolView*) m_savedState->GetDocument()->GetFirstView();
                view->OnChangeFilename();
            }
            else
            {
                wxASSERT(m_savedState != NULL);
                wxASSERT(m_activeState == NULL);

                m_savedState->GetDocument()->Modify(true);
                m_savedState->Attach(m_parent, m_insertBefore);
                ctConfigToolView* view = (ctConfigToolView*) m_savedState->GetDocument()->GetFirstView();
                view->AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), m_savedState);
                m_activeState = m_savedState;
                m_savedState = NULL;
                m_parent = NULL;
                m_insertBefore = NULL;
                view->OnChangeFilename();
            }
            break;
        }
    case ctCMD_PASTE:
        {
            if (doCmd)
            {
                wxASSERT(m_savedState != NULL);
                wxASSERT(m_activeState == NULL);

                m_savedState->GetDocument()->Modify(true);
                m_savedState->Attach(m_parent, m_insertBefore);
                ctConfigToolView* view = (ctConfigToolView*) m_savedState->GetDocument()->GetFirstView();
                view->AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), m_savedState);
                wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->SelectItem(m_savedState->GetTreeItemId());
                m_activeState = m_savedState;
                m_savedState = NULL;
                view->OnChangeFilename();
            }
            else
            {
                wxASSERT(m_savedState == NULL);
                wxASSERT(m_activeState != NULL);

                m_activeState->GetDocument()->Modify(true);
                ctConfigToolView* view = (ctConfigToolView*) m_activeState->GetDocument()->GetFirstView();
                m_activeState->Detach();
                m_savedState = m_activeState;
                m_activeState = NULL;
                view->OnChangeFilename();
            }
            break;
        }
    case ctCMD_NEW_ELEMENT:
        {
            if (doCmd)
            {
                wxASSERT(m_savedState != NULL);
                wxASSERT(m_activeState == NULL);

                m_savedState->GetDocument()->Modify(true);
                m_savedState->Attach(m_parent, m_insertBefore);
                ctConfigToolView* view = (ctConfigToolView*) m_savedState->GetDocument()->GetFirstView();
                view->AddItems(wxGetApp().GetMainFrame()->GetConfigTreeCtrl(), m_savedState);
                wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->SelectItem(m_savedState->GetTreeItemId());

                m_activeState = m_savedState;
                m_savedState = NULL;
            }
            else
            {
                wxASSERT(m_savedState == NULL);
                wxASSERT(m_activeState != NULL);

                m_activeState->GetDocument()->Modify(true);
                m_activeState->Detach();
                m_savedState = m_activeState;
                m_activeState = NULL;
            }
            break;
        }
    case ctCMD_APPLY_PROPERTY:
        {
            wxASSERT(m_properties != NULL);
            wxASSERT(m_activeState != NULL);

            // Don't update the properties editor first time
            // around since it will be done one property at a time
            // initially (and no property editor update required)
            if (!m_ignoreThis)
            {
                // Just swap the saved and current properties.
                ctProperties propsTemp = m_activeState->GetProperties() ;
                m_activeState->GetProperties() = (* m_properties);
                (* m_properties) = propsTemp;

                // Apply only those that need applying
                // (those properties in activeState that are not in propsTemp)
                wxObjectList::compatibility_iterator node = m_activeState->GetProperties().GetList().GetFirst();
                while (node)
                {
                    ctProperty* prop = (ctProperty*) node->GetData();
                    ctProperty* otherProp = propsTemp.FindProperty(prop->GetName());
                    if (otherProp && ((*prop) != (*otherProp)))
                    {
                        m_activeState->ApplyProperty(prop, otherProp->GetVariant());
                    }
                    node = node->GetNext();
                }
                m_activeState->GetDocument()->Modify(true);
                ctConfigToolView* view = (ctConfigToolView*) m_activeState->GetDocument()->GetFirstView();
                if (view)
                {
                    ctConfigToolHint hint(NULL, ctValueChanged);
                    m_activeState->GetDocument()->UpdateAllViews (NULL, & hint);
                }
            }
            m_ignoreThis = false;

            break;
        }
    }
    return true;
}

IMPLEMENT_CLASS(ctConfiguration, wxObject)

ctConfiguration::ctConfiguration()
{
    m_treeItemId = wxTreeItemId();
    m_parent = NULL;
    m_topItem = NULL;
}

ctConfiguration::ctConfiguration(ctConfiguration* parent, const wxString& name)
{
    m_treeItemId = wxTreeItemId();
    SetName(name);
    m_parent = parent;
    if (parent)
        parent->AddChild(this);
}

ctConfiguration::~ctConfiguration()
{
/*
    ctConfigTreeCtrl* treeCtrl = wxGetApp().GetMainFrame()->GetConfigTreeCtrl();
    if (m_treeItemId.IsOk() && treeCtrl)
    {
        ctTreeItemData* data = (ctTreeItemData*) treeCtrl->GetItemData(m_treeItemId);
        if (data)
            data->SetConfigItem(NULL);
    }
    if (GetParent())
        GetParent()->RemoveChild(this);
    else
    {
        if (wxGetApp().GetMainFrame()->GetDocument() &&
            wxGetApp().GetMainFrame()->GetDocument()->GetTopItem() == this)
            wxGetApp().GetMainFrame()->GetDocument()->SetTopItem(NULL);
    }
*/

    Clear();
}

/// Assignment operator.
void ctConfiguration::operator= (const ctConfiguration& configuration)
{
    m_name = configuration.m_name;
    m_description = configuration.m_description;
}

/// Clear children
void ctConfiguration::Clear()
{
    wxObjectList::compatibility_iterator node = m_children.GetFirst();
    while (node)
    {
        wxObjectList::compatibility_iterator next = node->GetNext();
        ctConfiguration* child = (ctConfiguration*) node->GetData();

        // This should delete 'node' too, assuming
        // child's m_parent points to 'this'. If not,
        // it'll be cleaned up by m_children.Clear().
        delete child;

        node = next;
    }
    m_children.Clear();
}

// Get the nth child
ctConfiguration* ctConfiguration::GetChild(int n) const
{
    wxASSERT ( n < GetChildCount() && n > -1 );

    if ( n < GetChildCount() && n > -1 )
    {
        ctConfiguration* child = wxDynamicCast(m_children.Item(n)->GetData(), ctConfiguration);
        return child;
    }
    else
        return NULL;
}

// Get the child count
int ctConfiguration::GetChildCount() const
{
    return m_children.GetCount();
}

/// Add a child
void ctConfiguration::AddChild(ctConfiguration* configuration)
{
    m_children.Append(configuration);
    configuration->SetParent(this);
}

/// Remove (but don't delete) a child
void ctConfiguration::RemoveChild(ctConfiguration* configuration)
{
    m_children.DeleteObject(configuration);
    configuration->SetParent(NULL);
}

/// Get the associated document (currently, assumes
/// there's only ever one document active)
ctConfigToolDoc* ctConfiguration::GetDocument()
{
    ctConfigToolDoc* doc = wxGetApp().GetMainFrame()->GetDocument();
    return doc;
}

/// Find an item in this hierarchy
// TODO: ensure that names are unique, somehow.
ctConfiguration* ctConfiguration::FindConfiguration(const wxString& name)
{
    if (GetName() == name)
        return this;

    for ( wxObjectList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext() )
    {
        ctConfiguration* child = (ctConfiguration*) node->GetData();
        ctConfiguration* found = child->FindConfiguration(name);
        if (found)
            return found;
    }
    return NULL;
}

/// Find the next sibling
ctConfiguration* ctConfiguration::FindNextSibling()
{
    if (!GetParent())
        return NULL;
    wxObjectList::compatibility_iterator node = GetParent()->GetChildren().Member(this);
    if (node && node->GetNext())
    {
        return (ctConfiguration*) node->GetNext()->GetData();
    }
    return NULL;
}

/// Find the previous sibling
ctConfiguration* ctConfiguration::FindPreviousSibling()
{
    if (!GetParent())
        return NULL;
    wxObjectList::compatibility_iterator node = GetParent()->GetChildren().Member(this);
    if (node && node->GetPrevious())
    {
        return (ctConfiguration*) node->GetPrevious()->GetData();
    }
    return NULL;
}

/// Create a clone of this and children
ctConfiguration* ctConfiguration::DeepClone()
{
    ctConfiguration* newItem = Clone();

    for ( wxObjectList::compatibility_iterator node = GetChildren().GetFirst(); node; node = node->GetNext() )
    {
        ctConfiguration* child = (ctConfiguration*) node->GetData();
        ctConfiguration* newChild = child->DeepClone();
        newItem->AddChild(newChild);
    }
    return newItem;
}

/// Detach: remove from parent, and remove tree items
void ctConfiguration::Detach()
{
    // TODO
    if (GetParent())
        GetParent()->RemoveChild(this);
    else
        GetDocument()->SetTopItem(NULL);
    SetParent(NULL);

/*
    wxTreeItemId treeItem = GetTreeItemId();

    DetachFromTree();

    // Will delete the branch, but not the config items.
    wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->Delete(treeItem);
*/
}

/// Hide from tree: make sure tree deletions won't delete
/// the config items
void ctConfiguration::DetachFromTree()
{
/*
    wxTreeItemId item = GetTreeItemId();

    // TODO
    ctTreeItemData* data = (ctTreeItemData*) wxGetApp().GetMainFrame()->GetConfigTreeCtrl()->GetItemData(item);
    data->SetConfigItem(NULL);
    m_treeItemId = wxTreeItemId();

    for ( wxNode* node = GetChildren().GetFirst(); node; node = node->GetNext() )
    {
        ctConfiguration* child = (ctConfiguration*) node->GetData();
        child->DetachFromTree();
    }
*/
}

⌨️ 快捷键说明

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