void CLeftView::OnEditCopy() { CGeorgesEditDoc *doc = (CGeorgesEditDoc*)GetDocument( ); if (doc) { // What is selected ? HTREEITEM item = TreeCtrl.GetSelectedItem (); if (item != NULL) { // Edit the label ? CEdit *edit = TreeCtrl.GetEditControl(); if (edit) { edit->SendMessage (WM_COPY); } else { // Get the sub data CGeorgesEditDocSub *subData = (CGeorgesEditDocSub*)TreeCtrl.GetItemData (item); if (subData) { // Get thte node type CGeorgesEditDocSub::TSub subType = subData->getType (); // Good type for copy ? if (subType == CGeorgesEditDocSub::Form) { theApp.SerialIntoMemStream (subData->getFormName ().c_str(), doc, subData->getSlot (), true); } } } } } }
void CLeftView::OnDelete() { // Get tree selection HTREEITEM item = TreeCtrl.GetSelectedItem (); if (item) { // Edit the label ? CEdit *edit = TreeCtrl.GetEditControl(); if (edit) { edit->SetWindowText (""); } else { // Get the sub object CGeorgesEditDocSub *subObject = (CGeorgesEditDocSub*)TreeCtrl.GetItemData (item); if (subObject) { // Editable ? if (subObject->isEditable ()) { // Get some information about the current node bool deleteInsert = false; // Is a form child ? CGeorgesEditDocSub *parent = subObject->getParent (); if (parent && parent->getType () == CGeorgesEditDocSub::Form) { // Does the node in the same form ? CGeorgesEditDoc *doc = GetDocument (); if (doc) { // Get the parent node const CFormDfn *parentDfn; uint indexDfn; const CFormDfn *nodeDfn; const CType *nodeType; CFormElm *parentNode; UFormDfn::TEntryType type; bool array; bool parentVDfnArray; CForm *form=doc->getFormPtr (); CFormElm *elm = (CFormElm *)doc->getRootNode (subObject->getSlot ()); nlverify ( elm->getNodeByName (parent->getFormName ().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &parentNode, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) ); // Is a non empty array ? if (array && parentNode) { // Document modified doc->modify (new CActionBuffer (IAction::FormArrayDelete, NULL, 0, *doc, subObject->getFormName ().c_str (), toString (subObject->getIdInParent ()).c_str (), doc->getLeftView ()->getCurrentSelectionId (), subObject->getSlot ())); } } } } } } } }
bool CGeorgesEditDoc::getActiveNode (std::string &dfnName) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CGeorgesEditDocSub *sub = getSelectedObject (); if (sub && (sub->getFormName () != "NULL")) { dfnName = getSelectedObject ()->getFormName (); return true; } else { return false; } }
// --------------------------------------------------------------------------- void CGeorgesImpl::PutText (const std::string& _sText) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CMainFrame *pWnd = dynamic_cast< CMainFrame* >( theApp.m_pMainWnd ); CChildFrame *pChild = (CChildFrame*)pWnd->MDIGetActive (); if (pChild == NULL) return; // Get active document CGeorgesEditDoc *doc = (CGeorgesEditDoc *)pChild->GetActiveDocument(); if (doc) { // Get the left view CLeftView* pView = doc->getLeftView (); // Check type CGeorgesEditDocSub *subDoc = doc->getSelectedObject (); if (subDoc) { // Get the node const CFormDfn *parentDfn; uint indexDfn; const CFormDfn *nodeDfn; const CType *nodeType; CFormElm *node; UFormDfn::TEntryType type; bool array; bool parentVDfnArray; CForm *form=doc->getFormPtr (); CFormElm *elm = doc->getRootNode (subDoc->getSlot ()); nlverify ( elm->getNodeByName (subDoc->getFormName ().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) ); // It is an array ? if (array&&(type == UFormDfn::EntryType)) { // Modify the node doc->modify (new CActionString (IAction::FormTypeValue, _sText.c_str(), *doc, subDoc->getFormName ().c_str (), "", doc->getLeftView ()->getCurrentSelectionId (), subDoc->getSlot ())); doc->modify (new CActionString (IAction::FormArrayRename, _sText.c_str(), *doc, subDoc->getFormName ().c_str (), toString (subDoc->getIdInParent ()).c_str (), doc->getLeftView ()->getCurrentSelectionId (), subDoc->getSlot ())); doc->updateDocumentStructure (); doc->UpdateAllViews (pView); } else if ((UFormDfn::EntryDfn)&&(!array)) { // Get the right view CGeorgesEditView* view = doc->getRightView (); if (view->FormDialog.WidgetFocused != 0xffffffff) { // Set the string doc->modify (new CActionString (IAction::FormValue, _sText.c_str(), *doc, view->FormDialog.Widgets[view->FormDialog.WidgetFocused]->getFormName ().c_str (), "", doc->getLeftView ()->getCurrentSelectionId (), subDoc->getSlot ())); doc->updateDocumentStructure (); doc->UpdateAllViews (pView); } } } } }
CGeorgesEditDocSub *CGeorgesEditDoc::addArray (CGeorgesEditDocSub *parent, CFormElmArray *array, CFormDfn *rootDfn, const char *name, uint structId, const char *formName, uint slot) { // Add the new node CGeorgesEditDocSub *newNode = parent->add (CGeorgesEditDocSub::Form, name, structId, formName, slot); // The array exist if (array) { // For each array element for (uint elm=0; elm<array->Elements.size(); elm++) { // The form name char formArrayElmName[512]; smprintf (formArrayElmName, 512, "%s[%d]", formName, elm); // The name char formArrayName[512]; if (array->Elements[elm].Name.empty ()) { smprintf (formArrayName, 512, "#%d", elm); } else { smprintf (formArrayName, 512, "%s", array->Elements[elm].Name.c_str()); } // Is a struct if (rootDfn) { // Get struct ptr CFormElmStruct *elmPtr = array->Elements[elm].Element ? safe_cast<CFormElmStruct*>(array->Elements[elm].Element) : NULL; addStruct (newNode, elmPtr, rootDfn, formArrayName, elm, formArrayElmName, slot); } else newNode->add (CGeorgesEditDocSub::Form, formArrayName, elm, formArrayElmName, slot); } } return newNode; }
void CLeftView::OnEditPaste() { CGeorgesEditDoc *doc = (CGeorgesEditDoc*)GetDocument( ); if (doc) { // What is selected ? HTREEITEM item = TreeCtrl.GetSelectedItem (); if (item != NULL) { // Edit the label ? CEdit *edit = TreeCtrl.GetEditControl(); if (edit) { edit->SendMessage (WM_PASTE); } else { // Get the sub data CGeorgesEditDocSub *subData = (CGeorgesEditDocSub*)TreeCtrl.GetItemData (item); if (subData) { // Get thte node type CGeorgesEditDocSub::TSub subType = subData->getType (); // Good type for copy ? if (subType == CGeorgesEditDocSub::Form) { // Document is modified by this view if (theApp.FillMemStreamWithClipboard (subData->getFormName ().c_str(), doc, subData->getSlot ())) { doc->modify (new CActionBuffer (IAction::FormPaste, theApp.MemStream.buffer (), theApp.MemStream.length(), *doc, subData->getFormName ().c_str(), "", doc->getLeftView ()->getCurrentSelectionId (), subData->getSlot ())); } } } } } } }
// --------------------------------------------------------------------------- void CGeorgesImpl::LineDown () { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CMainFrame* pWnd = dynamic_cast< CMainFrame* >( theApp.m_pMainWnd ); CMDIChildWnd *pChild = pWnd->MDIGetActive (); if (pChild == NULL) return; // Get active document CGeorgesEditDoc *doc = (CGeorgesEditDoc *)pChild->GetActiveDocument (); if (doc) { // Get the left view CLeftView* pView = doc->getLeftView (); // Check type CGeorgesEditDocSub *subDoc = doc->getSelectedObject (); if (subDoc) { // Get the node const CFormDfn *parentDfn; uint indexDfn; const CFormDfn *nodeDfn; const CType *nodeType; CFormElm *node; UFormDfn::TEntryType type; bool array; bool parentVDfnArray; CForm *form=doc->getFormPtr (); CFormElm *elm = doc->getRootNode (subDoc->getSlot ()); nlverify ( elm->getNodeByName (subDoc->getFormName ().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) ); // Is a type entry ? if ( (type == UFormDfn::EntryType) && !array ) { // Select next if ((subDoc->getIdInParent ()+1) < subDoc->getParent ()->getChildrenCount ()) doc->changeSubSelection (subDoc->getParent ()->getChild (subDoc->getIdInParent ()+1), pView); } } } }
BOOL CLeftView::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) { // Selection change ? NMHDR *pnmh = (LPNMHDR) lParam; switch (pnmh->code) { case TVN_BEGINLABELEDIT: { // Get tree selection LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO) lParam; if (ptvdi->item.hItem) { // Get the sub object CGeorgesEditDocSub *subObject = (CGeorgesEditDocSub*)TreeCtrl.GetItemData (ptvdi->item.hItem); if (subObject) { // Editable ? if (subObject->isEditable ()) { // Get some information about the current node bool deleteInsert = false; // Is a form child ? CGeorgesEditDocSub *parent = subObject->getParent (); if (parent && parent->getType () == CGeorgesEditDocSub::Form) { // Does the node in the same form ? CGeorgesEditDoc *doc = GetDocument (); if (doc) { // Get the parent node const CFormDfn *parentDfn; uint indexDfn; const CFormDfn *nodeDfn; const CType *nodeType; CFormElm *parentNode; UFormDfn::TEntryType type; bool array; bool parentVDfnArray; CForm *form=doc->getFormPtr (); CFormElm *elm = (CFormElm *)doc->getRootNode (subObject->getSlot ()); nlverify ( elm->getNodeByName (parent->getFormName ().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &parentNode, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) ); // Is a non empty array ? if (array && parentNode) { // Edit the tree *pResult = 0; return TRUE; } } } } } } *pResult = 1; return TRUE; } break; case TVN_ENDLABELEDIT: { // Get tree selection LPNMTVDISPINFO ptvdi = (LPNMTVDISPINFO) lParam; if (ptvdi->item.hItem) { // Get the sub object CGeorgesEditDocSub *subObject = (CGeorgesEditDocSub*)TreeCtrl.GetItemData (ptvdi->item.hItem); if (subObject) { // Editable ? if (subObject->isEditable ()) { // Get some information about the current node bool deleteInsert = false; // Is a form child ? CGeorgesEditDocSub *parent = subObject->getParent (); if (parent && parent->getType () == CGeorgesEditDocSub::Form) { // Does the node in the same form ? CGeorgesEditDoc *doc = GetDocument (); if (doc) { // Get the parent node const CFormDfn *parentDfn; uint indexDfn; const CFormDfn *nodeDfn; const CType *nodeType; CFormElm *parentNode; UFormDfn::TEntryType type; bool array; bool parentVDfnArray; CForm *form=doc->getFormPtr (); CFormElm *elm = (CFormElm *)doc->getRootNode (subObject->getSlot ()); nlverify ( elm->getNodeByName (parent->getFormName ().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &parentNode, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) ); // Is a non empty array ? if (array && parentNode && (ptvdi->item.mask & TVIF_TEXT)) { // Change the node name TreeCtrl.SetItemText (ptvdi->item.hItem, ptvdi->item.pszText); doc->modify (new CActionString (IAction::FormArrayRename, ptvdi->item.pszText, *doc, subObject->getFormName ().c_str (), toString (subObject->getIdInParent ()).c_str(), doc->getLeftView ()->getCurrentSelectionId (), subObject->getSlot ())); return TRUE; } } } } } } *pResult = 1; return TRUE; } break; case TVN_SELCHANGED: { LPNMTREEVIEW itemData = (LPNMTREEVIEW) lParam; // Unbold old item if (itemData->itemOld.hItem) TreeCtrl.SetItemState(itemData->itemOld.hItem, 0, TVIS_BOLD); CGeorgesEditDoc *doc = GetDocument(); if (doc) { CGeorgesEditDocSub *data = (CGeorgesEditDocSub *)TreeCtrl.GetItemData (itemData->itemNew.hItem); nlassert (data); doc->changeSubSelection (data, this); TreeCtrl.SetFocus (); } } break; case NM_RCLICK: { // Get item clicked TVHITTESTINFO tvhti; GetCursorPos(&tvhti.pt); ::ScreenToClient(TreeCtrl, &tvhti.pt); tvhti.flags = LVHT_NOWHERE; TreeView_HitTest(TreeCtrl, &tvhti); // Item clicked ? if(TVHT_ONITEM & tvhti.flags) { // Select the item if (TreeCtrl.GetSelectedItem ()) TreeCtrl.SetItemState(TreeCtrl.GetSelectedItem (), 0, TVIS_BOLD); TreeCtrl.SelectItem (tvhti.hItem); TreeCtrl.SetItemState(tvhti.hItem, TVIS_BOLD, TVIS_BOLD); // Get the sub object CGeorgesEditDocSub *subObject = (CGeorgesEditDocSub*)TreeCtrl.GetItemData (tvhti.hItem); if (subObject) { // Editable ? if (subObject->isEditable ()) { // Get some information about the current node bool deleteInsert = false; // Is a form child ? CGeorgesEditDocSub *parent = subObject->getParent (); if (parent && parent->getType () == CGeorgesEditDocSub::Form) { // Does the node in the same form ? CGeorgesEditDoc *doc = GetDocument (); if (doc) { // Get the node const CFormDfn *parentDfn; uint indexDfn; const CFormDfn *nodeDfn; const CType *nodeType; CFormElm *node; UFormDfn::TEntryType type; bool array; bool parentVDfnArray; CForm *form=doc->getFormPtr (); CFormElm *elm = (CFormElm *)doc->getRootNode (subObject->getSlot ()); nlverify ( elm->getNodeByName (parent->getFormName ().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) ); // Is the parent array ? deleteInsert = array; } } // Show right click menu // Create menu CMenu mainMenu; mainMenu.LoadMenu (IDR_LEFT_VIEW_CONTEXT); CMenu *popup = mainMenu.GetSubMenu (0); // Enable disable items popup->EnableMenuItem (4, MF_BYPOSITION|(deleteInsert?MF_ENABLED:MF_GRAYED)); popup->EnableMenuItem (5, MF_BYPOSITION|(deleteInsert?MF_ENABLED:MF_GRAYED)); popup->EnableMenuItem (6, MF_BYPOSITION|(deleteInsert?MF_ENABLED:MF_GRAYED)); ::ClientToScreen(TreeCtrl, &tvhti.pt); popup->TrackPopupMenu (TPM_LEFTALIGN | TPM_RIGHTBUTTON, tvhti.pt.x, tvhti.pt.y, this, NULL); } } } } break; } return CView::OnNotify(wParam, lParam, pResult); }
// --------------------------------------------------------------------------- void CGeorgesImpl::PutGroupText (const std::vector<std::string>& _vText, bool append) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); CMainFrame *pWnd = dynamic_cast< CMainFrame* >( theApp.m_pMainWnd ); CChildFrame *pChild = (CChildFrame*)pWnd->MDIGetActive (); if (pChild == NULL) return; // Get active document CGeorgesEditDoc *doc = (CGeorgesEditDoc *)pChild->GetActiveDocument(); if (doc) { // Get the left view CLeftView* pView = doc->getLeftView (); // Check type CGeorgesEditDocSub *subDoc = doc->getSelectedObject (); if (subDoc) { // Get the node const CFormDfn *parentDfn; uint indexDfn; const CFormDfn *nodeDfn; const CType *nodeType; CFormElm *node; UFormDfn::TEntryType type; bool array; bool parentVDfnArray; CForm *form=doc->getFormPtr (); CFormElm *elm = doc->getRootNode (subDoc->getSlot ()); nlverify ( elm->getNodeByName (subDoc->getFormName ().c_str (), &parentDfn, indexDfn, &nodeDfn, &nodeType, &node, type, array, parentVDfnArray, true, NLGEORGES_FIRST_ROUND) ); // Is a type entry ? if ((type == UFormDfn::EntryType) && array) { std::string formName = subDoc->getFormName (); uint slot = subDoc->getSlot (); // Current node size uint size = 0; if (node) { CFormElmArray *arrayPtr = safe_cast<CFormElmArray*>(node); nlverify (arrayPtr->getArraySize (size)); } // Modify the size of the array char value[512]; smprintf (value, 512, "%d", _vText.size () + ((append)?size:0)); doc->modify (new CActionBuffer (IAction::FormArraySize, NULL, 0, *doc, formName.c_str (), value, doc->getLeftView ()->getCurrentSelectionId (), slot)); uint i; for (i=0; i<_vText.size (); i++) { uint index = i + ((append)?size:0); std::string formNameAtom = formName + "[" + toString (index) + "]"; doc->modify (new CActionString (IAction::FormTypeValue, _vText[i].c_str (), *doc, formNameAtom.c_str (), "", doc->getLeftView ()->getCurrentSelectionId (), slot)); doc->modify (new CActionString (IAction::FormArrayRename, _vText[i].c_str(), *doc, formNameAtom.c_str (), toString (index).c_str (), doc->getLeftView ()->getCurrentSelectionId (), slot)); } } } } }