summaryrefslogtreecommitdiff
path: root/win/Piececmb.cpp
diff options
context:
space:
mode:
authordocwhat1999-11-14 06:43:18 +0000
committerdocwhat1999-11-14 06:43:18 +0000
commitd71eec8062e852e56f03102ba4b4e87dc485821d (patch)
tree452368ad0e7e24627e517a0c88c2508d02cea6dc /win/Piececmb.cpp
parent2046090b7ce8dd901ce43e650be5acf44016d714 (diff)
Initial revision
git-svn-id: http://svn.leocad.org/trunk@2 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'win/Piececmb.cpp')
-rw-r--r--win/Piececmb.cpp172
1 files changed, 172 insertions, 0 deletions
diff --git a/win/Piececmb.cpp b/win/Piececmb.cpp
new file mode 100644
index 0000000..a1dafe2
--- /dev/null
+++ b/win/Piececmb.cpp
@@ -0,0 +1,172 @@
+// PieceCmb.cpp : implementation file
+//
+
+#include "stdafx.h"
+#include "leocad.h"
+#include "PieceCmb.h"
+#include "PieceBar.h"
+#include "pieceinf.h"
+#include "project.h"
+#include "globals.h"
+
+#ifdef _DEBUG
+#define new DEBUG_NEW
+#undef THIS_FILE
+static char THIS_FILE[] = __FILE__;
+#endif
+
+/////////////////////////////////////////////////////////////////////////////
+// CPiecesCombo
+
+CPiecesCombo::CPiecesCombo()
+{
+ m_bAutoComplete = TRUE;
+}
+
+CPiecesCombo::~CPiecesCombo()
+{
+}
+
+
+BEGIN_MESSAGE_MAP(CPiecesCombo, CComboBox)
+ //{{AFX_MSG_MAP(CPiecesCombo)
+ ON_CONTROL_REFLECT(CBN_EDITUPDATE, OnEditupdate)
+ ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange)
+ //}}AFX_MSG_MAP
+END_MESSAGE_MAP()
+
+/////////////////////////////////////////////////////////////////////////////
+// CPiecesCombo message handlers
+
+void CPiecesCombo::OnEditupdate()
+{
+ if (!m_bAutoComplete)
+ return;
+
+ char str[66];
+ CPiecesBar* pBar = (CPiecesBar*)GetParent();
+ PieceInfo* pInfo;
+
+ if (int n = GetWindowText(str, 65))
+ {
+ char newstr[66];
+ int sel = -1;
+ strcpy (newstr, "Z");
+ for (int i = 0; i < project->GetPieceLibraryCount(); i++)
+ {
+ pInfo = project->GetPieceInfo(i);
+
+ if (_strnicmp (str, pInfo->m_strDescription, n) == 0)
+ {
+ if (_stricmp (newstr, pInfo->m_strDescription) > 0)
+ {
+ strcpy (newstr, pInfo->m_strDescription);
+ sel = i;
+ }
+ }
+ else
+ if (_strnicmp (str, pInfo->m_strName, n) == 0)
+ {
+ if (_stricmp (newstr, pInfo->m_strName) > 0)
+ {
+ strcpy (newstr, pInfo->m_strName);
+ sel = i;
+ }
+ }
+ }
+
+ if (sel >= 0)
+ {
+ pInfo = project->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;
+ }
+ }
+
+ 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);
+ }
+ }
+}
+
+BOOL CPiecesCombo::PreTranslateMessage(MSG* pMsg)
+{
+ if (pMsg->message == WM_KEYDOWN)
+ {
+ m_bAutoComplete = TRUE;
+ int nVirtKey = (int) pMsg->wParam;
+ if (nVirtKey == VK_DELETE || nVirtKey == VK_BACK)
+ {
+// if enter pressed, add piece (postmessage to mainwnd)
+ m_bAutoComplete = FALSE;
+ }
+ }
+
+ return CComboBox::PreTranslateMessage(pMsg);
+}
+
+void CPiecesCombo::OnSelchange()
+{
+ char str[66];
+ CPiecesBar* pBar = (CPiecesBar*)GetParent();
+
+ if (!GetLBText (GetCurSel(), str))
+ return;
+
+ for (int i = 0; i < project->GetPieceLibraryCount(); i++)
+ {
+ PieceInfo* pInfo = project->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;
+ }
+ }
+
+ LV_FINDINFO lvfi;
+ lvfi.flags = LVFI_PARAM;
+ lvfi.lParam = (LPARAM)pInfo;
+
+ 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;
+ }
+ }
+}