summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorleo2005-12-22 21:29:18 +0000
committerleo2005-12-22 21:29:18 +0000
commitb87afd4fe89cef28e5d1e0527aeec74a4d93e4aa (patch)
tree9244249ba0bf1245ea5c08592186ee82ca24f7ab
parent2e854ed61c1aa804e0d373ca5af1d87882511a11 (diff)
Fixed the pieces combobox to select items in the tree control when using auto-complete.
git-svn-id: http://svn.leocad.org/trunk@446 c7d43263-9d01-0410-8a33-9dba5d9f93d6
-rwxr-xr-xcommon/library.cpp95
-rwxr-xr-xcommon/library.h6
-rw-r--r--common/pieceinf.h18
-rw-r--r--win/Piecebar.cpp77
-rw-r--r--win/Piecebar.h1
-rw-r--r--win/Piececmb.cpp79
-rw-r--r--win/piececmb.h4
7 files changed, 166 insertions, 114 deletions
diff --git a/common/library.cpp b/common/library.cpp
index b2bed83..e6638e2 100755
--- a/common/library.cpp
+++ b/common/library.cpp
@@ -490,16 +490,54 @@ bool PiecesLibrary::DoSaveCategories(bool AskName)
// =============================================================================
-void PiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces)
+// Check if the piece belongs to a category.
+bool PiecesLibrary::PieceInCategory(PieceInfo* Info, const String& CategoryKeywords) const
+{
+ String PieceName = Info->m_strDescription;
+ PieceName.MakeLower();
+
+ String Keywords = CategoryKeywords;
+ Keywords.MakeLower();
+
+ const char* p = Keywords;
+
+ while (*p)
+ {
+ const char* k = p;
+
+ while (*k && (*k != ',') && (*k != ';'))
+ k++;
+
+ String Search = Keywords.Mid(p - (const char*)Keywords, k - p);
+
+ if (PieceName.Find(Search) != -1)
+ return true;
+
+ if (*k)
+ p = k + 1;
+ else
+ break;
+ }
+
+ return false;
+}
+
+int PiecesLibrary::GetFirstCategory(PieceInfo* Info) const
+{
+ for (int i = 0; i < m_Categories.GetSize(); i++)
+ if (PieceInCategory(Info, m_Categories[i].Keywords))
+ return i;
+
+ return -1;
+}
+
+void PiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces) const
{
bool m_bSubParts = false;
SinglePieces.RemoveAll();
GroupedPieces.RemoveAll();
- String Keywords = m_Categories[CategoryIndex].Keywords;
- Keywords.MakeLower();
-
// Don't group entries in the search results category.
if (m_Categories[CategoryIndex].Name == "Search Results")
GroupPieces = false;
@@ -512,35 +550,7 @@ void PiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrA
if ((Info->m_strDescription[0] == '~') && !m_bSubParts)
continue;
- // Check if the piece belongs to this category.
- String PieceName = Info->m_strDescription;
- PieceName.MakeLower();
-
- const char* p = Keywords;
- bool Match = false;
-
- while (*p)
- {
- const char* k = p;
-
- while (*k && (*k != ',') && (*k != ';'))
- k++;
-
- String Search = Keywords.Mid(p - (const char*)Keywords, k - p);
-
- if (PieceName.Find(Search) != -1)
- {
- Match = true;
- break;
- }
-
- if (*k)
- p = k + 1;
- else
- break;
- }
-
- if (!Match)
+ if (!PieceInCategory(Info, m_Categories[CategoryIndex].Keywords))
continue;
if (!GroupPieces)
@@ -550,27 +560,14 @@ void PiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrA
}
// Check if it's a patterned piece.
- const char* Name = Info->m_strName;
-
- while (*Name)
- {
- if (!*Name || *Name < '0' || *Name > '9')
- break;
-
- if (*Name == 'P')
- break;
-
- Name++;
- }
-
- if (*Name == 'P')
+ if (Info->IsPatterned())
{
PieceInfo* Parent;
// Find the parent of this patterned piece.
char ParentName[9];
strcpy(ParentName, Info->m_strName);
- ParentName[Name - Info->m_strName] = '\0';
+ *strchr(ParentName, 'P') = '\0';
Parent = FindPieceInfo(ParentName);
@@ -604,7 +601,7 @@ void PiecesLibrary::GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrA
}
}
-void PiecesLibrary::GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces)
+void PiecesLibrary::GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces) const
{
char Name[9];
strcpy(Name, Parent->m_strName);
diff --git a/common/library.h b/common/library.h
index a8ba118..41ccbdd 100755
--- a/common/library.h
+++ b/common/library.h
@@ -32,8 +32,10 @@ public:
{ return m_nTextureCount; }
// Categories.
- void GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces);
- void GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces);
+ bool PieceInCategory(PieceInfo* Info, const String& CategoryKeywords) const;
+ int GetFirstCategory(PieceInfo* Info) const;
+ void GetCategoryEntries(int CategoryIndex, bool GroupPieces, PtrArray<PieceInfo>& SinglePieces, PtrArray<PieceInfo>& GroupedPieces) const;
+ void GetPatternedPieces(PieceInfo* Parent, PtrArray<PieceInfo>& Pieces) const;
void SetCategory(int Index, const String& Name, const String& Keywords);
void AddCategory(const String& Name, const String& Keywords);
void RemoveCategory(int Index);
diff --git a/common/pieceinf.h b/common/pieceinf.h
index a1e73a3..1124db1 100644
--- a/common/pieceinf.h
+++ b/common/pieceinf.h
@@ -49,6 +49,24 @@ class PieceInfo
PieceInfo ();
~PieceInfo ();
+ bool IsPatterned() const
+ {
+ const char* Name = m_strName;
+
+ while (*Name)
+ {
+ if (*Name < '0' || *Name > '9')
+ break;
+
+ Name++;
+ }
+
+ if (*Name == 'P')
+ return true;
+
+ return false;
+ }
+
// Operations
void ZoomExtents(float Fov, float Aspect);
void RenderOnce(int nColor);
diff --git a/win/Piecebar.cpp b/win/Piecebar.cpp
index fd70ad6..87ac3f5 100644
--- a/win/Piecebar.cpp
+++ b/win/Piecebar.cpp
@@ -688,7 +688,7 @@ int CPiecesBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (CControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
- m_PiecesTree.Create(WS_VISIBLE|WS_TABSTOP|WS_BORDER|TVS_HASBUTTONS|TVS_DISABLEDRAGDROP|TVS_HASLINES|TVS_LINESATROOT,
+ m_PiecesTree.Create(WS_VISIBLE|WS_TABSTOP|WS_BORDER|TVS_SHOWSELALWAYS|TVS_HASBUTTONS|TVS_DISABLEDRAGDROP|TVS_HASLINES|TVS_LINESATROOT,
CRect(0,0,0,0), this, IDW_PIECESTREE);
m_wndPiecesList.Create(LVS_SINGLESEL|LVS_SHOWSELALWAYS|LVS_AUTOARRANGE|
@@ -968,6 +968,81 @@ void CPiecesBar::OnContextMenu(CWnd* pWnd, CPoint point)
}
}
+void CPiecesBar::SelectPiece(const char* Category, PieceInfo* Info)
+{
+ HTREEITEM Item = m_PiecesTree.GetChildItem(TVI_ROOT);
+ const char* PieceName = Info->m_strDescription;
+
+ // Find the category and make sure it's expanded.
+ while (Item != NULL)
+ {
+ CString Name = m_PiecesTree.GetItemText(Item);
+
+ if (Name == Category)
+ {
+ m_PiecesTree.Expand(Item, TVE_EXPAND);
+ break;
+ }
+
+ Item = m_PiecesTree.GetNextSiblingItem(Item);
+ }
+
+ if (Item == NULL)
+ return;
+
+ // Expand the piece group if it's patterned.
+ if (Info->IsPatterned())
+ {
+ PieceInfo* Parent;
+
+ // Find the parent of this patterned piece and expand it.
+ char ParentName[9];
+ strcpy(ParentName, Info->m_strName);
+ *strchr(ParentName, 'P') = '\0';
+
+ Parent = project->GetPiecesLibrary()->FindPieceInfo(ParentName);
+
+ if (Parent)
+ {
+ Item = m_PiecesTree.GetChildItem(Item);
+
+ while (Item != NULL)
+ {
+ CString Name = m_PiecesTree.GetItemText(Item);
+
+ if (Name == Parent->m_strDescription)
+ {
+ m_PiecesTree.Expand(Item, TVE_EXPAND);
+
+ // If both descriptions begin with the same text, only show the difference.
+ if (!strncmp(Info->m_strDescription, Parent->m_strDescription, strlen(Parent->m_strDescription)))
+ PieceName = Info->m_strDescription + strlen(Parent->m_strDescription) + 1;
+
+ break;
+ }
+
+ Item = m_PiecesTree.GetNextSiblingItem(Item);
+ }
+ }
+ }
+
+ // Find the piece.
+ Item = m_PiecesTree.GetChildItem(Item);
+
+ while (Item != NULL)
+ {
+ CString Name = m_PiecesTree.GetItemText(Item);
+
+ if (Name == PieceName)
+ {
+ m_PiecesTree.SelectItem(Item);
+ return;
+ }
+
+ Item = m_PiecesTree.GetNextSiblingItem(Item);
+ }
+}
+
void CPiecesBar::UpdatePiecesTree(const char* OldCategory, const char* NewCategory)
{
if (OldCategory && NewCategory)
diff --git a/win/Piecebar.h b/win/Piecebar.h
index 48d7e32..c5e9775 100644
--- a/win/Piecebar.h
+++ b/win/Piecebar.h
@@ -98,6 +98,7 @@ public:
void UpdatePiecesTree(bool SearchOnly);
void UpdatePiecesTree(const char* OldCategory, const char* NewCategory);
+ void SelectPiece(const char* Category, PieceInfo* Info);
// Generated message map functions
protected:
diff --git a/win/Piececmb.cpp b/win/Piececmb.cpp
index 4da474d..ecefb8d 100644
--- a/win/Piececmb.cpp
+++ b/win/Piececmb.cpp
@@ -45,7 +45,7 @@ void CPiecesCombo::OnEditupdate()
return;
char str[66];
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
+ PiecesLibrary *pLib = project->GetPiecesLibrary ();
CPiecesBar* pBar = (CPiecesBar*)GetParent();
PieceInfo* pInfo;
@@ -81,38 +81,12 @@ void CPiecesCombo::OnEditupdate()
}
if (sel >= 0)
- {
- pInfo = pLib->GetPieceInfo(sel);
-
- if ((pBar->m_bGroups) && (pInfo->m_nGroups != 0))
- if ((pInfo->m_nGroups & (1 << pBar->m_nCurGroup)) == 0)
- {
- DWORD d = 1;
- for (int k = 1; k < 32; k++)
- {
- if ((pInfo->m_nGroups & d) != 0)
- {
- pBar->m_nCurGroup = k-1;
- pBar->m_wndPiecesList.UpdateList();
- k = 32;
- }
- else
- d *= 2;
- }
- }
+ SelectPiece(pLib->GetPieceInfo(sel));
- LV_FINDINFO lvfi;
- lvfi.flags = LVFI_PARAM;
- lvfi.lParam = (LPARAM)pInfo;
-
- sel = pBar->m_wndPiecesList.FindItem (&lvfi);
- pBar->m_wndPiecesList.SetItemState (sel, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
- pBar->m_wndPiecesList.EnsureVisible (sel, FALSE);
- }
if (strlen (newstr) > 1)
{
- SetWindowText (newstr);
- SetEditSel (n, -1);
+ SetWindowText(newstr);
+ SetEditSel(n, -1);
}
}
}
@@ -139,13 +113,9 @@ BOOL CPiecesCombo::PreTranslateMessage(MSG* pMsg)
int Index = Lib->FindCategoryIndex("Search Results");
if (Index == -1)
- {
Lib->AddCategory("Search Results", (const char*)str);
- }
else
- {
Lib->SetCategory(Index, "Search Results", (const char*)str);
- }
}
}
@@ -156,7 +126,7 @@ void CPiecesCombo::OnSelchange()
{
char str[66];
CPiecesBar* pBar = (CPiecesBar*)GetParent();
- PiecesLibrary *pLib = project->GetPiecesLibrary ();
+ PiecesLibrary *pLib = project->GetPiecesLibrary();
if (!GetLBText (GetCurSel(), str))
return;
@@ -165,33 +135,18 @@ void CPiecesCombo::OnSelchange()
{
PieceInfo* pInfo = pLib->GetPieceInfo(i);
- if (strcmp (str, pInfo->m_strDescription) == 0)
- {
- if ((pBar->m_bGroups) && (pInfo->m_nGroups != 0))
- if ((pInfo->m_nGroups & (1 << pBar->m_nCurGroup)) == 0)
- {
- DWORD d = 1;
- for (int k = 1; k < 32; k++)
- {
- if ((pInfo->m_nGroups & d) != 0)
- {
- pBar->m_nCurGroup = k-1;
- pBar->m_wndPiecesList.UpdateList();
- k = 32;
- }
- else
- d *= 2;
- }
- }
+ if (strcmp(str, pInfo->m_strDescription) == 0)
+ SelectPiece(pInfo);
+ }
+}
- LV_FINDINFO lvfi;
- lvfi.flags = LVFI_PARAM;
- lvfi.lParam = (LPARAM)pInfo;
+void CPiecesCombo::SelectPiece(PieceInfo* Info)
+{
+ PiecesLibrary *Lib = project->GetPiecesLibrary();
+ CPiecesBar* Bar = (CPiecesBar*)GetParent();
- i = pBar->m_wndPiecesList.FindItem (&lvfi);
- pBar->m_wndPiecesList.SetItemState(i,LVIS_SELECTED | LVIS_FOCUSED , LVIS_SELECTED | LVIS_FOCUSED);
- pBar->m_wndPiecesList.EnsureVisible (i, FALSE);
- return;
- }
- }
+ int Index = Lib->GetFirstCategory(Info);
+
+ if (Index != -1)
+ Bar->SelectPiece(Lib->GetCategoryName(Index), Info);
}
diff --git a/win/piececmb.h b/win/piececmb.h
index be6dfe1..00f4f1d 100644
--- a/win/piececmb.h
+++ b/win/piececmb.h
@@ -7,6 +7,8 @@
// PieceCmb.h : header file
//
+class PieceInfo;
+
/////////////////////////////////////////////////////////////////////////////
// CPiecesCombo window
@@ -36,6 +38,8 @@ public:
// Generated message map functions
protected:
BOOL m_bAutoComplete;
+ void SelectPiece(PieceInfo* Info);
+
//{{AFX_MSG(CPiecesCombo)
afx_msg void OnEditupdate();
afx_msg void OnSelchange();