summaryrefslogtreecommitdiff
path: root/win
diff options
context:
space:
mode:
authorleo2005-12-22 21:29:18 +0000
committerleo2005-12-22 21:29:18 +0000
commitb87afd4fe89cef28e5d1e0527aeec74a4d93e4aa (patch)
tree9244249ba0bf1245ea5c08592186ee82ca24f7ab /win
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
Diffstat (limited to 'win')
-rw-r--r--win/Piecebar.cpp77
-rw-r--r--win/Piecebar.h1
-rw-r--r--win/Piececmb.cpp79
-rw-r--r--win/piececmb.h4
4 files changed, 98 insertions, 63 deletions
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();