| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | #include "lc_global.h" |
|---|
| 5 | #include "leocad.h" |
|---|
| 6 | #include "PieceCmb.h" |
|---|
| 7 | #include "PieceBar.h" |
|---|
| 8 | #include "pieceinf.h" |
|---|
| 9 | #include "project.h" |
|---|
| 10 | #include "globals.h" |
|---|
| 11 | #include "library.h" |
|---|
| 12 | #include "lc_application.h" |
|---|
| 13 | |
|---|
| 14 | #ifdef _DEBUG |
|---|
| 15 | #define new DEBUG_NEW |
|---|
| 16 | #undef THIS_FILE |
|---|
| 17 | static char THIS_FILE[] = __FILE__; |
|---|
| 18 | #endif |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | CPiecesCombo::CPiecesCombo() |
|---|
| 24 | { |
|---|
| 25 | m_bAutoComplete = TRUE; |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | CPiecesCombo::~CPiecesCombo() |
|---|
| 29 | { |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | BEGIN_MESSAGE_MAP(CPiecesCombo, CComboBox) |
|---|
| 34 | |
|---|
| 35 | ON_CONTROL_REFLECT(CBN_EDITUPDATE, OnEditupdate) |
|---|
| 36 | ON_CONTROL_REFLECT(CBN_SELCHANGE, OnSelchange) |
|---|
| 37 | |
|---|
| 38 | END_MESSAGE_MAP() |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | void CPiecesCombo::OnEditupdate() |
|---|
| 44 | { |
|---|
| 45 | if (!m_bAutoComplete) |
|---|
| 46 | return; |
|---|
| 47 | |
|---|
| 48 | char str[66]; |
|---|
| 49 | PiecesLibrary *pLib = lcGetPiecesLibrary(); |
|---|
| 50 | CPiecesBar* pBar = (CPiecesBar*)GetParent(); |
|---|
| 51 | PieceInfo* pInfo; |
|---|
| 52 | |
|---|
| 53 | if (int n = GetWindowText(str, 65)) |
|---|
| 54 | { |
|---|
| 55 | char newstr[66]; |
|---|
| 56 | int sel = -1; |
|---|
| 57 | strcpy (newstr, "Z"); |
|---|
| 58 | for (int i = 0; i < pLib->GetPieceCount(); i++) |
|---|
| 59 | { |
|---|
| 60 | pInfo = pLib->GetPieceInfo(i); |
|---|
| 61 | |
|---|
| 62 | if ((pInfo->m_strDescription[0] == '~') && !pBar->m_bSubParts) |
|---|
| 63 | continue; |
|---|
| 64 | |
|---|
| 65 | if (_strnicmp (str, pInfo->m_strDescription, n) == 0) |
|---|
| 66 | { |
|---|
| 67 | if (_stricmp (newstr, pInfo->m_strDescription) > 0) |
|---|
| 68 | { |
|---|
| 69 | strcpy (newstr, pInfo->m_strDescription); |
|---|
| 70 | sel = i; |
|---|
| 71 | } |
|---|
| 72 | } |
|---|
| 73 | else |
|---|
| 74 | if (_strnicmp (str, pInfo->m_strName, n) == 0) |
|---|
| 75 | { |
|---|
| 76 | if (_stricmp (newstr, pInfo->m_strName) > 0) |
|---|
| 77 | { |
|---|
| 78 | strcpy (newstr, pInfo->m_strName); |
|---|
| 79 | sel = i; |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | if (sel >= 0) |
|---|
| 85 | SelectPiece(pLib->GetPieceInfo(sel)); |
|---|
| 86 | |
|---|
| 87 | if (strlen (newstr) > 1) |
|---|
| 88 | { |
|---|
| 89 | SetWindowText(newstr); |
|---|
| 90 | SetEditSel(n, -1); |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | BOOL CPiecesCombo::PreTranslateMessage(MSG* pMsg) |
|---|
| 96 | { |
|---|
| 97 | if (pMsg->message == WM_KEYDOWN) |
|---|
| 98 | { |
|---|
| 99 | m_bAutoComplete = TRUE; |
|---|
| 100 | int nVirtKey = (int) pMsg->wParam; |
|---|
| 101 | if (nVirtKey == VK_DELETE || nVirtKey == VK_BACK) |
|---|
| 102 | { |
|---|
| 103 | CEdit* Edit = (CEdit*)GetWindow(GW_CHILD); |
|---|
| 104 | m_bAutoComplete = FALSE; |
|---|
| 105 | Edit->ReplaceSel(""); |
|---|
| 106 | } |
|---|
| 107 | else if (nVirtKey == VK_RETURN) |
|---|
| 108 | { |
|---|
| 109 | PiecesLibrary* Lib = lcGetPiecesLibrary(); |
|---|
| 110 | CString str; |
|---|
| 111 | |
|---|
| 112 | GetWindowText(str); |
|---|
| 113 | |
|---|
| 114 | int Index = Lib->FindCategoryIndex("Search Results"); |
|---|
| 115 | |
|---|
| 116 | if (Index == -1) |
|---|
| 117 | Lib->AddCategory("Search Results", (const char*)str); |
|---|
| 118 | else |
|---|
| 119 | Lib->SetCategory(Index, "Search Results", (const char*)str); |
|---|
| 120 | } |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | return CComboBox::PreTranslateMessage(pMsg); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | void CPiecesCombo::OnSelchange() |
|---|
| 127 | { |
|---|
| 128 | char str[66]; |
|---|
| 129 | CPiecesBar* pBar = (CPiecesBar*)GetParent(); |
|---|
| 130 | PiecesLibrary *pLib = lcGetPiecesLibrary(); |
|---|
| 131 | |
|---|
| 132 | if (!GetLBText (GetCurSel(), str)) |
|---|
| 133 | return; |
|---|
| 134 | |
|---|
| 135 | for (int i = 0; i < pLib->GetPieceCount(); i++) |
|---|
| 136 | { |
|---|
| 137 | PieceInfo* pInfo = pLib->GetPieceInfo(i); |
|---|
| 138 | |
|---|
| 139 | if (strcmp(str, pInfo->m_strDescription) == 0) |
|---|
| 140 | SelectPiece(pInfo); |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | void CPiecesCombo::SelectPiece(PieceInfo* Info) |
|---|
| 145 | { |
|---|
| 146 | PiecesLibrary *Lib = lcGetPiecesLibrary(); |
|---|
| 147 | CPiecesBar* Bar = (CPiecesBar*)GetParent(); |
|---|
| 148 | |
|---|
| 149 | int Index = Lib->GetFirstCategory(Info); |
|---|
| 150 | |
|---|
| 151 | if (Index != -1) |
|---|
| 152 | Bar->SelectPiece(Lib->GetCategoryName(Index), Info); |
|---|
| 153 | } |
|---|