1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
25 // configtoolview.cpp :
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
31 // Contact(s): julians
35 // Description: Implementation file for the ecConfigToolView class
42 //####DESCRIPTIONEND####
44 //===========================================================================
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 #pragma implementation "configtoolview.h"
57 // Includes other headers for precompiled compilation
64 #include "configtoolview.h"
65 #include "configtooldoc.h"
66 #include "configtree.h"
67 #include "configtool.h"
68 #include "shortdescrwin.h"
70 #include "propertywin.h"
73 IMPLEMENT_DYNAMIC_CLASS(ecConfigToolView, wxView)
75 BEGIN_EVENT_TABLE(ecConfigToolView, wxView)
78 ecConfigToolView::ecConfigToolView()
80 m_expandedForFind = wxTreeItemId();
83 // What to do when a view is created. Creates actual
84 // windows for displaying the view.
85 bool ecConfigToolView::OnCreate(wxDocument *doc, long WXUNUSED(flags) )
87 wxGetApp().GetDocManager()->ActivateView(this, TRUE);
91 m_frame = GetMainFrame();
93 // Associate the appropriate frame with this view.
96 // Make sure the document manager knows that this is the
100 // Initialize the edit menu Undo and Redo items
101 doc->GetCommandProcessor()->SetEditMenu(((pzMainFrame *)m_frame)->editMenu);
102 doc->GetCommandProcessor()->Initialize();
108 void ecConfigToolView::OnDraw(wxDC *dc)
112 void ecConfigToolView::OnUpdate(wxView *WXUNUSED(sender), wxObject *hintObj)
114 ecConfigToolDoc* pDoc = (ecConfigToolDoc*) GetDocument();
115 ecConfigTreeCtrl* treeCtrl = wxGetApp().GetTreeCtrl();
119 ecConfigItem* selItem = NULL;
121 wxTreeItemId sel = treeCtrl->GetSelection();
124 ecTreeItemData* data = (ecTreeItemData*) treeCtrl->GetItemData(sel);
126 selItem = data->GetConfigItem() ;
129 ecConfigToolHint* hint = (ecConfigToolHint*) hintObj;
130 int hintOp = ecNoHint;
139 // Note that we're cheating a bit here, since we're using the tree view
140 // to update another view, instead of having a view per control as in the MFC
141 // version. However, it doesn't seem to be worth the extra machinery.
142 // Update the description window
145 wxGetApp().GetMainFrame()->GetShortDescriptionWindow()->SetValue(selItem->GetDescription());
147 // Update the properties window
148 wxGetApp().GetMainFrame()->GetPropertyListWindow()->Fill(selItem);
152 wxGetApp().GetMainFrame()->GetShortDescriptionWindow()->Clear();
153 wxGetApp().GetMainFrame()->GetPropertyListWindow()->ClearAll();
162 for(nItem=0;nItem<pDoc->GetItems().Number();nItem++)
164 ecConfigItem *pItem = (ecConfigItem*) pDoc->GetItems()[nItem];
165 wxTreeItemId treeItem = pItem->GetTreeItem();
167 treeCtrl->SetItemText(treeItem, pItem->GetItemNameOrMacro());
172 // Update the properties window
175 wxGetApp().GetMainFrame()->GetPropertyListWindow()->Fill(selItem);
178 wxGetApp().GetMainFrame()->UpdateFrameTitle();
180 // Update the value pane
181 wxGetApp().GetMainFrame()->GetValueWindow()->Refresh();
184 case ecFilenameChanged:
187 // Update the properties window
190 wxGetApp().GetMainFrame()->GetPropertyListWindow()->Fill(selItem);
192 wxGetApp().GetMainFrame()->UpdateFrameTitle();
195 case ecNameFormatChanged:
198 for(nItem=0;nItem<pDoc->GetItems().Number();nItem++)
200 ecConfigItem *pItem = (ecConfigItem*) pDoc->GetItems()[nItem];
201 wxString strName(pItem->GetItemNameOrMacro());
202 if(pItem->Modified()){
205 treeCtrl->SetItemText(pItem->GetTreeItem(), strName);
211 case ecIntFormatChanged:
213 if (selItem && selItem->GetOptionType() == ecLong)
215 wxGetApp().GetMainFrame()->GetPropertyListWindow()->SetItem(ecPropertyListCtrl::ecValue, selItem->StringValue());
216 wxGetApp().GetMainFrame()->GetPropertyListWindow()->SetItem(ecPropertyListCtrl::ecDefaultValue, ecUtils::IntToStr(selItem->DefaultValue(), wxGetApp().GetSettings().m_bHex));
223 m_expandedForFind = wxTreeItemId();
225 treeCtrl->DeleteAllItems();
227 wxGetApp().GetMainFrame()->GetShortDescriptionWindow()->Clear();
228 wxGetApp().GetMainFrame()->GetPropertyListWindow()->Fill(NULL);
229 wxGetApp().GetMainFrame()->GetValueWindow()->Refresh();
235 ecConfigItem& ti = *(ecConfigItem *)hint->m_item;
237 // Update the tree item
239 ti.UpdateTreeItem(* treeCtrl);
241 // Update the value cell
242 ecValueWindow* valueWindow = wxGetApp().GetMainFrame()->GetValueWindow();
245 wxRect rect = valueWindow->GetItemRect(& ti);
247 valueWindow->Refresh(TRUE, & rect);
249 // For some reason, on Linux, the value window gets
250 // blanked out if a dialog pops up as a result of the value change.
251 valueWindow->Refresh();
258 wxGetApp().GetMainFrame()->GetPropertyListWindow()->RefreshValue();
260 wxGetApp().GetMainFrame()->UpdateFrameTitle();
264 case ecExternallyChanged:
267 for(nItem=0;nItem<pDoc->GetItems().Number();nItem++)
269 ecConfigItem *pItem = (ecConfigItem*) pDoc->GetItems()[nItem];
270 pItem->UpdateTreeItem(* treeCtrl);
272 wxGetApp().GetMainFrame()->UpdateFrameTitle();
276 break; // not for us, apparently
280 // Clean up windows used for displaying the view.
281 bool ecConfigToolView::OnClose(bool deleteWindow)
283 ecConfigToolHint hint(NULL, ecClear);
284 GetDocument()->UpdateAllViews (NULL, & hint);
286 if (!GetDocument()->Close())
289 wxGetApp().GetDocManager()->ActivateView(this, FALSE);
291 // TODO: Set any pointers to this view to NULL
294 wxString s(wxTheApp->GetAppName());
296 m_frame->SetTitle(s);
298 SetFrame((wxFrame *) NULL);
306 void ecConfigToolView::OnChangeFilename()
308 if (wxGetApp().GetTopWindow() && GetDocument())
310 wxString docTitle(wxFileNameFromPath(GetDocument()->GetFilename()));
311 wxStripExtension(docTitle);
312 GetDocument()->SetTitle(docTitle);
314 wxString name(GetDocument()->GetFilename());
315 wxStripExtension(name);
317 ((ecConfigToolDoc*) GetDocument())->SetInstallTree(name + wxT("_install"));
318 ((ecConfigToolDoc*) GetDocument())->SetBuildTree(name + wxT("_build"));
322 wxString modifiedMarker;
323 if (GetDocument()->IsModified())
324 modifiedMarker = wxT("*");
326 title = docTitle + modifiedMarker + wxString(wxT(" - ")) + wxGetApp().GetSettings().GetAppName();
328 ((wxFrame*) wxGetApp().GetTopWindow())->SetTitle(title);
333 void ecConfigToolView::OnUpdateDisable(wxUpdateUIEvent& event)
335 event.Enable( FALSE );
338 void ecConfigToolView::Refresh(const wxString& macroName)
340 ecConfigItem * pItem=wxGetApp().GetConfigToolDoc()->Find(macroName);
342 if (pItem) // will be NULL if item has been removed
344 pItem->ConvertFromCdl();
346 if (wxGetApp().GetTreeCtrl())
347 pItem->UpdateTreeItem(* wxGetApp().GetTreeCtrl());
349 // Update the cell contents.
350 if (wxGetApp().GetMainFrame() && wxGetApp().GetMainFrame()->GetValueWindow())
352 wxRect rect = wxGetApp().GetMainFrame()->GetValueWindow()->GetItemRect(pItem);
353 wxGetApp().GetMainFrame()->GetValueWindow()->Refresh(TRUE, & rect);
358 void ecConfigToolView::Refresh (wxTreeItemId h)
362 // TODO Not sure if we need this
365 // Invalidate the labels of the affected items
367 GetItemRect(h, rect, TRUE );
368 rect.left+=m_TreeXOffsetAdjustment;
369 InvalidateRect(rect);
370 // Do the same for the cell view
372 CConfigTool::GetCellView()->GetClientRect(rcBuddyClient);
373 rect.left=rcBuddyClient.left;
374 rect.right=rcBuddyClient.right;
375 CConfigTool::GetCellView()->InvalidateRect(rect);
380 ecConfigItem *ecConfigToolView::DoFind(const wxString& what, wxWindow* parent)
382 ecConfigToolDoc *pDoc = wxGetApp().GetConfigToolDoc();
386 int nCount = pDoc->GetItems().Number();
388 // static LPCTSTR arWhereImage[]={_T("name"),_T("macro"),_T("description string"),_T("current value"),_T("default value")};
390 wxString strFind(what);
392 if(! wxGetApp().GetSettings().m_findMatchCase)
397 wxTreeItemId h = wxGetApp().GetTreeCtrl()->GetSelection();
403 for (nItem=nCount-1;nItem>=0;--nItem) {
404 if(h==pDoc->GetItem(nItem)->GetTreeItem())
412 ecConfigItem *pItem = NULL;
415 for (i=0 ; i < nCount ; i++)
417 if(wxGetApp().GetSettings().m_findDirection)
419 nItem=(nItem+1)%nCount;
421 nItem=(nCount+nItem-1)%nCount;
423 pItem = pDoc->GetItem(nItem);
425 ecWhereType where = ecConfigItem::WhereStringToType(wxGetApp().GetSettings().m_findSearchWhat);
427 wxString strName (pItem->StringValue(where));
429 if (!wxGetApp().GetSettings().m_findMatchCase)
434 int nIndex = strName.Find(strFind);
437 if (wxGetApp().GetSettings().m_findMatchWholeWord)
439 // Enforce whole-word semantics: to left and right
440 if(nIndex>0 && IsWordChar(strName[(unsigned) (nIndex-1)])){
443 nIndex += strFind.Length();
444 if (nIndex < strName.Length() && IsWordChar(strName[(unsigned) nIndex])){
454 if(m_expandedForFind)
456 wxGetApp().GetTreeCtrl()->Collapse(m_expandedForFind);
459 wxTreeItemId h=pItem->GetTreeItem();
462 for(hv=wxGetApp().GetTreeCtrl()->GetFirstVisibleItem();hv;hv=wxGetApp().GetTreeCtrl()->GetNextVisible(hv))
471 // we want to record the highest unexpanded item
472 for(hv=wxGetApp().GetTreeCtrl()->GetParent(h);hv;hv=wxGetApp().GetTreeCtrl()->GetParent(hv))
474 if (!wxGetApp().GetTreeCtrl()->IsExpanded( hv))
476 m_expandedForFind = hv;
480 wxGetApp().GetTreeCtrl()->EnsureVisible(h);
481 wxGetApp().GetTreeCtrl()->SelectItem(h);
486 msg.Printf(_("Cannot find '%s' in %s"), (const wxChar*) what, (const wxChar*) wxGetApp().GetSettings().m_findSearchWhat );
487 wxMessageBox(msg, _("Find"), wxOK|wxICON_INFORMATION, parent);
493 bool ecConfigToolView::IsWordChar(wxChar c)
495 return wxIsalnum(c) || wxT('_')==c;