| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | #include "lc_global.h" |
|---|
| 5 | #include "afxpriv.h" // for CDockContext |
|---|
| 6 | #include "resource.h" |
|---|
| 7 | #include "piecebar.h" |
|---|
| 8 | #include "library.h" |
|---|
| 9 | #include "pieceinf.h" |
|---|
| 10 | #include "project.h" |
|---|
| 11 | #include "lc_colors.h" |
|---|
| 12 | #include "lc_application.h" |
|---|
| 13 | #include "preview.h" |
|---|
| 14 | |
|---|
| 15 | #ifdef _DEBUG |
|---|
| 16 | #define new DEBUG_NEW |
|---|
| 17 | #undef THIS_FILE |
|---|
| 18 | static char THIS_FILE[] = __FILE__; |
|---|
| 19 | #endif |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | int PiecesSortFunc(const PieceInfo* a, const PieceInfo* b, void* SortData) |
|---|
| 25 | { |
|---|
| 26 | if (a->IsSubPiece()) |
|---|
| 27 | { |
|---|
| 28 | if (b->IsSubPiece()) |
|---|
| 29 | { |
|---|
| 30 | return strcmp(a->m_strDescription, b->m_strDescription); |
|---|
| 31 | } |
|---|
| 32 | else |
|---|
| 33 | { |
|---|
| 34 | return 1; |
|---|
| 35 | } |
|---|
| 36 | } |
|---|
| 37 | else |
|---|
| 38 | { |
|---|
| 39 | if (b->IsSubPiece()) |
|---|
| 40 | { |
|---|
| 41 | return -1; |
|---|
| 42 | } |
|---|
| 43 | else |
|---|
| 44 | { |
|---|
| 45 | return strcmp(a->m_strDescription, b->m_strDescription); |
|---|
| 46 | } |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | return 0; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | CPiecesBar::CPiecesBar() |
|---|
| 53 | { |
|---|
| 54 | int i = AfxGetApp()->GetProfileInt("Settings", "Piecebar Options", 0); |
|---|
| 55 | m_bSubParts = (i & PIECEBAR_SUBPARTS) != 0; |
|---|
| 56 | m_bNumbers = (i & PIECEBAR_PARTNUMBERS) != 0; |
|---|
| 57 | |
|---|
| 58 | m_dwSCBStyle |= SCBS_SHOWEDGES; |
|---|
| 59 | m_nPreviewHeight = AfxGetApp()->GetProfileInt("Settings", "Preview Height", 93); |
|---|
| 60 | |
|---|
| 61 | m_szMinHorz = m_szMinVert = m_szMinFloat = CSize(228, 200); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | CPiecesBar::~CPiecesBar() |
|---|
| 65 | { |
|---|
| 66 | AfxGetApp()->WriteProfileInt("Settings", "Preview Height", m_nPreviewHeight); |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | BEGIN_MESSAGE_MAP(CPiecesBar, CSizingControlBarG) |
|---|
| 70 | |
|---|
| 71 | ON_WM_SIZE() |
|---|
| 72 | ON_WM_CREATE() |
|---|
| 73 | ON_WM_CONTEXTMENU() |
|---|
| 74 | |
|---|
| 75 | ON_MESSAGE(WM_LC_SPLITTER_MOVED, OnSplitterMoved) |
|---|
| 76 | END_MESSAGE_MAP() |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | void CPiecesBar::OnSize(UINT nType, int cx, int cy) |
|---|
| 83 | { |
|---|
| 84 | CSizingControlBarG::OnSize(nType, cx, cy); |
|---|
| 85 | |
|---|
| 86 | if (!IsWindow(m_wndColorsList.m_hWnd)) |
|---|
| 87 | return; |
|---|
| 88 | |
|---|
| 89 | int off = LC_COLORLIST_NUM_ROWS*12+2+5; |
|---|
| 90 | int ColorWidth = ((cx-2) / LC_COLORLIST_NUM_COLS) * LC_COLORLIST_NUM_COLS + 2; |
|---|
| 91 | m_wndColorsList.SetWindowPos(NULL, (cx-ColorWidth)/2, cy-off, ColorWidth, LC_COLORLIST_NUM_ROWS*12+2, SWP_NOZORDER); |
|---|
| 92 | |
|---|
| 93 | off += 30; |
|---|
| 94 | m_wndPiecesCombo.SetWindowPos (NULL, 5, cy-off, cx-10, 140, SWP_NOZORDER); |
|---|
| 95 | |
|---|
| 96 | m_wndSplitter.SetWindowPos(NULL, 5, m_nPreviewHeight+6, cx-10, 4, SWP_NOZORDER); |
|---|
| 97 | m_PiecesTree.SetWindowPos(NULL, 5, m_nPreviewHeight+10, cx-10, cy-off-15-m_nPreviewHeight, SWP_NOZORDER); |
|---|
| 98 | m_wndPiecePreview.SetWindowPos(NULL, 5, 5, cx-10, m_nPreviewHeight, 0); |
|---|
| 99 | m_wndPiecePreview.EnableWindow(TRUE); |
|---|
| 100 | m_wndPiecePreview.ShowWindow(SW_SHOW); |
|---|
| 101 | m_wndSplitter.ShowWindow(SW_SHOW); |
|---|
| 102 | |
|---|
| 103 | m_wndPiecesCombo.ShowWindow(SW_SHOW); |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | int CPiecesBar::OnCreate(LPCREATESTRUCT lpCreateStruct) |
|---|
| 107 | { |
|---|
| 108 | if (CSizingControlBarG::OnCreate(lpCreateStruct) == -1) |
|---|
| 109 | return -1; |
|---|
| 110 | |
|---|
| 111 | m_PiecesTree.Create(WS_VISIBLE|WS_TABSTOP|WS_BORDER|TVS_SHOWSELALWAYS|TVS_HASBUTTONS|TVS_HASLINES|TVS_LINESATROOT|TVS_INFOTIP, |
|---|
| 112 | CRect(0,0,0,0), this, IDW_PIECESTREE); |
|---|
| 113 | |
|---|
| 114 | m_wndPiecesCombo.Create(CBS_DROPDOWN|CBS_SORT|CBS_HASSTRINGS|WS_VISIBLE|WS_CHILD| |
|---|
| 115 | WS_VSCROLL|WS_TABSTOP, CRect(0,0,0,0), this, IDW_PIECESCOMBO); |
|---|
| 116 | |
|---|
| 117 | m_wndColorsList.Create(WS_VISIBLE|WS_TABSTOP|WS_CHILD, CRect(0, 0, 0, 0), this, IDW_COLORSLIST); |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | LOGFONT logFont; |
|---|
| 121 | memset(&logFont, 0, sizeof(logFont)); |
|---|
| 122 | |
|---|
| 123 | if (!::GetSystemMetrics(SM_DBCSENABLED)) |
|---|
| 124 | { |
|---|
| 125 | logFont.lfHeight = -10; |
|---|
| 126 | logFont.lfWeight = 0; |
|---|
| 127 | logFont.lfPitchAndFamily = VARIABLE_PITCH | FF_SWISS; |
|---|
| 128 | lstrcpy(logFont.lfFaceName, "MS Sans Serif"); |
|---|
| 129 | if (m_Font.CreateFontIndirect(&logFont)) |
|---|
| 130 | m_wndPiecesCombo.SetFont(&m_Font); |
|---|
| 131 | } |
|---|
| 132 | else |
|---|
| 133 | { |
|---|
| 134 | m_Font.Attach(::GetStockObject(SYSTEM_FONT)); |
|---|
| 135 | m_wndPiecesCombo.SetFont(&m_Font); |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | m_wndPiecePreview.Create(NULL, NULL, WS_BORDER|WS_CHILD|WS_VISIBLE, |
|---|
| 139 | CRect(0, 0, 0, 0), this, IDW_PIECEPREVIEW); |
|---|
| 140 | |
|---|
| 141 | CreateWindow("STATIC", "", WS_VISIBLE|WS_CHILD|SS_ETCHEDFRAME, 0, 0, 0, 0, |
|---|
| 142 | m_hWnd, (HMENU)IDW_PIECEBAR_SPLITTER, AfxGetInstanceHandle(), NULL); |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | m_wndSplitter.BindWithControl(this, IDW_PIECEBAR_SPLITTER); |
|---|
| 146 | m_wndSplitter.SetMinHeight(0, 0); |
|---|
| 147 | m_wndSplitter.AttachAsAbovePane(IDW_PIECEPREVIEW); |
|---|
| 148 | m_wndSplitter.AttachAsBelowPane(IDW_PIECESTREE); |
|---|
| 149 | m_wndSplitter.RecalcLayout(); |
|---|
| 150 | |
|---|
| 151 | return 0; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | LONG CPiecesBar::OnSplitterMoved(UINT lParam, LONG wParam) |
|---|
| 155 | { |
|---|
| 156 | UNREFERENCED_PARAMETER(wParam); |
|---|
| 157 | |
|---|
| 158 | if (lParam == 0) |
|---|
| 159 | m_bNoContext = TRUE; |
|---|
| 160 | else |
|---|
| 161 | m_nPreviewHeight += lParam; |
|---|
| 162 | |
|---|
| 163 | SetWindowPos(NULL, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_FRAMECHANGED); |
|---|
| 164 | |
|---|
| 165 | return TRUE; |
|---|
| 166 | } |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | void CPiecesBar::OnUpdateCmdUI(CFrameWnd * pTarget, BOOL bDisableIfNoHndler) |
|---|
| 172 | { |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | UpdateDialogControls(pTarget, FALSE); |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | void CPiecesBar::OnContextMenu(CWnd* pWnd, CPoint point) |
|---|
| 185 | { |
|---|
| 186 | UNREFERENCED_PARAMETER(pWnd); |
|---|
| 187 | |
|---|
| 188 | if (m_bNoContext) |
|---|
| 189 | m_bNoContext = FALSE; |
|---|
| 190 | else |
|---|
| 191 | { |
|---|
| 192 | CMenu menuPopups; |
|---|
| 193 | menuPopups.LoadMenu(IDR_POPUPS); |
|---|
| 194 | CMenu* pMenu = menuPopups.GetSubMenu(0); |
|---|
| 195 | |
|---|
| 196 | if (pMenu) |
|---|
| 197 | { |
|---|
| 198 | bool CategorySelected = false; |
|---|
| 199 | |
|---|
| 200 | CRect r; |
|---|
| 201 | m_PiecesTree.GetWindowRect(&r); |
|---|
| 202 | |
|---|
| 203 | if (r.PtInRect(point)) |
|---|
| 204 | { |
|---|
| 205 | HTREEITEM Item = m_PiecesTree.GetSelectedItem(); |
|---|
| 206 | |
|---|
| 207 | if (Item != NULL) |
|---|
| 208 | { |
|---|
| 209 | PiecesLibrary *Lib = lcGetPiecesLibrary(); |
|---|
| 210 | CString CategoryName = m_PiecesTree.GetItemText(Item); |
|---|
| 211 | int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName); |
|---|
| 212 | |
|---|
| 213 | if (CategoryIndex != -1) |
|---|
| 214 | CategorySelected = true; |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | pMenu->EnableMenuItem(ID_PIECEBAR_NEWCATEGORY, MF_BYCOMMAND | MF_ENABLED); |
|---|
| 218 | } |
|---|
| 219 | else |
|---|
| 220 | { |
|---|
| 221 | pMenu->EnableMenuItem(ID_PIECEBAR_NEWCATEGORY, MF_BYCOMMAND | MF_GRAYED); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | pMenu->EnableMenuItem(ID_PIECEBAR_REMOVECATEGORY, MF_BYCOMMAND | (CategorySelected ? MF_ENABLED : MF_GRAYED)); |
|---|
| 225 | pMenu->EnableMenuItem(ID_PIECEBAR_EDITCATEGORY, MF_BYCOMMAND | (CategorySelected ? MF_ENABLED : MF_GRAYED)); |
|---|
| 226 | |
|---|
| 227 | pMenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd()); |
|---|
| 228 | } |
|---|
| 229 | } |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | void CPiecesBar::SelectPiece(const char* Category, PieceInfo* Info) |
|---|
| 233 | { |
|---|
| 234 | HTREEITEM Item = m_PiecesTree.GetChildItem(TVI_ROOT); |
|---|
| 235 | const char* PieceName = Info->m_strDescription; |
|---|
| 236 | |
|---|
| 237 | |
|---|
| 238 | while (Item != NULL) |
|---|
| 239 | { |
|---|
| 240 | CString Name = m_PiecesTree.GetItemText(Item); |
|---|
| 241 | |
|---|
| 242 | if (Name == Category) |
|---|
| 243 | { |
|---|
| 244 | m_PiecesTree.Expand(Item, TVE_EXPAND); |
|---|
| 245 | break; |
|---|
| 246 | } |
|---|
| 247 | |
|---|
| 248 | Item = m_PiecesTree.GetNextSiblingItem(Item); |
|---|
| 249 | } |
|---|
| 250 | |
|---|
| 251 | if (Item == NULL) |
|---|
| 252 | return; |
|---|
| 253 | |
|---|
| 254 | |
|---|
| 255 | if (Info->IsPatterned()) |
|---|
| 256 | { |
|---|
| 257 | PieceInfo* Parent; |
|---|
| 258 | |
|---|
| 259 | |
|---|
| 260 | char ParentName[9]; |
|---|
| 261 | strcpy(ParentName, Info->m_strName); |
|---|
| 262 | *strchr(ParentName, 'P') = '\0'; |
|---|
| 263 | |
|---|
| 264 | Parent = lcGetPiecesLibrary()->FindPieceInfo(ParentName); |
|---|
| 265 | |
|---|
| 266 | if (Parent) |
|---|
| 267 | { |
|---|
| 268 | Item = m_PiecesTree.GetChildItem(Item); |
|---|
| 269 | |
|---|
| 270 | while (Item != NULL) |
|---|
| 271 | { |
|---|
| 272 | CString Name = m_PiecesTree.GetItemText(Item); |
|---|
| 273 | |
|---|
| 274 | if (Name == Parent->m_strDescription) |
|---|
| 275 | { |
|---|
| 276 | m_PiecesTree.Expand(Item, TVE_EXPAND); |
|---|
| 277 | |
|---|
| 278 | |
|---|
| 279 | if (!strncmp(Info->m_strDescription, Parent->m_strDescription, strlen(Parent->m_strDescription))) |
|---|
| 280 | PieceName = Info->m_strDescription + strlen(Parent->m_strDescription) + 1; |
|---|
| 281 | |
|---|
| 282 | break; |
|---|
| 283 | } |
|---|
| 284 | |
|---|
| 285 | Item = m_PiecesTree.GetNextSiblingItem(Item); |
|---|
| 286 | } |
|---|
| 287 | } |
|---|
| 288 | } |
|---|
| 289 | |
|---|
| 290 | |
|---|
| 291 | Item = m_PiecesTree.GetChildItem(Item); |
|---|
| 292 | |
|---|
| 293 | while (Item != NULL) |
|---|
| 294 | { |
|---|
| 295 | CString Name = m_PiecesTree.GetItemText(Item); |
|---|
| 296 | |
|---|
| 297 | if (Name == PieceName) |
|---|
| 298 | { |
|---|
| 299 | m_PiecesTree.SelectItem(Item); |
|---|
| 300 | return; |
|---|
| 301 | } |
|---|
| 302 | |
|---|
| 303 | Item = m_PiecesTree.GetNextSiblingItem(Item); |
|---|
| 304 | } |
|---|
| 305 | } |
|---|
| 306 | |
|---|
| 307 | void CPiecesBar::UpdatePiecesTree(const char* OldCategory, const char* NewCategory) |
|---|
| 308 | { |
|---|
| 309 | if (OldCategory && NewCategory) |
|---|
| 310 | { |
|---|
| 311 | HTREEITEM Item = m_PiecesTree.GetChildItem(TVI_ROOT); |
|---|
| 312 | |
|---|
| 313 | while (Item != NULL) |
|---|
| 314 | { |
|---|
| 315 | CString Name = m_PiecesTree.GetItemText(Item); |
|---|
| 316 | |
|---|
| 317 | if (Name == OldCategory) |
|---|
| 318 | break; |
|---|
| 319 | |
|---|
| 320 | Item = m_PiecesTree.GetNextSiblingItem(Item); |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | if (Item == NULL) |
|---|
| 324 | return; |
|---|
| 325 | |
|---|
| 326 | m_PiecesTree.SetItemText(Item, NewCategory); |
|---|
| 327 | |
|---|
| 328 | m_PiecesTree.EnsureVisible(Item); |
|---|
| 329 | if (m_PiecesTree.GetItemState(Item, TVIS_EXPANDED) & TVIS_EXPANDED) |
|---|
| 330 | { |
|---|
| 331 | m_PiecesTree.Expand(Item, TVE_COLLAPSE | TVE_COLLAPSERESET); |
|---|
| 332 | m_PiecesTree.Expand(Item, TVE_EXPAND); |
|---|
| 333 | } |
|---|
| 334 | } |
|---|
| 335 | else if (NewCategory) |
|---|
| 336 | { |
|---|
| 337 | HTREEITEM Item; |
|---|
| 338 | Item = m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, NewCategory, 0, 0, 0, 0, 0, TVI_ROOT, TVI_SORT); |
|---|
| 339 | m_PiecesTree.EnsureVisible(Item); |
|---|
| 340 | } |
|---|
| 341 | else if (OldCategory) |
|---|
| 342 | { |
|---|
| 343 | HTREEITEM Item = m_PiecesTree.GetChildItem(TVI_ROOT); |
|---|
| 344 | |
|---|
| 345 | while (Item != NULL) |
|---|
| 346 | { |
|---|
| 347 | CString Name = m_PiecesTree.GetItemText(Item); |
|---|
| 348 | |
|---|
| 349 | if (Name == OldCategory) |
|---|
| 350 | break; |
|---|
| 351 | |
|---|
| 352 | Item = m_PiecesTree.GetNextSiblingItem(Item); |
|---|
| 353 | } |
|---|
| 354 | |
|---|
| 355 | if (Item == NULL) |
|---|
| 356 | return; |
|---|
| 357 | |
|---|
| 358 | m_PiecesTree.DeleteItem(Item); |
|---|
| 359 | } |
|---|
| 360 | } |
|---|
| 361 | |
|---|
| 362 | void CPiecesBar::UpdatePiecesTreeSearch() |
|---|
| 363 | { |
|---|
| 364 | HTREEITEM Item = m_PiecesTree.GetChildItem(TVI_ROOT); |
|---|
| 365 | |
|---|
| 366 | while (Item != NULL) |
|---|
| 367 | { |
|---|
| 368 | CString Name = m_PiecesTree.GetItemText(Item); |
|---|
| 369 | |
|---|
| 370 | if (Name == "Search Results") |
|---|
| 371 | break; |
|---|
| 372 | |
|---|
| 373 | Item = m_PiecesTree.GetNextSiblingItem(Item); |
|---|
| 374 | } |
|---|
| 375 | |
|---|
| 376 | if (Item == NULL) |
|---|
| 377 | { |
|---|
| 378 | Item = m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, "Search Results", 0, 0, 0, 0, 0, TVI_ROOT, TVI_LAST); |
|---|
| 379 | } |
|---|
| 380 | |
|---|
| 381 | m_PiecesTree.Expand(Item, TVE_COLLAPSE | TVE_COLLAPSERESET); |
|---|
| 382 | m_PiecesTree.EnsureVisible(Item); |
|---|
| 383 | m_PiecesTree.Expand(Item, TVE_EXPAND); |
|---|
| 384 | } |
|---|
| 385 | |
|---|
| 386 | void CPiecesBar::UpdatePiecesTreeModels() |
|---|
| 387 | { |
|---|
| 388 | HTREEITEM Item = m_PiecesTree.GetChildItem(TVI_ROOT); |
|---|
| 389 | |
|---|
| 390 | while (Item != NULL) |
|---|
| 391 | { |
|---|
| 392 | CString Name = m_PiecesTree.GetItemText(Item); |
|---|
| 393 | |
|---|
| 394 | if (Name == "Models") |
|---|
| 395 | break; |
|---|
| 396 | |
|---|
| 397 | Item = m_PiecesTree.GetNextSiblingItem(Item); |
|---|
| 398 | } |
|---|
| 399 | |
|---|
| 400 | if (Item == NULL) |
|---|
| 401 | { |
|---|
| 402 | Item = m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, "Models", 0, 0, 0, 0, 0, TVI_ROOT, TVI_LAST); |
|---|
| 403 | } |
|---|
| 404 | |
|---|
| 405 | if (m_PiecesTree.GetItemState(Item, TVIS_EXPANDED) & TVIS_EXPANDED) |
|---|
| 406 | { |
|---|
| 407 | m_PiecesTree.Expand(Item, TVE_COLLAPSE | TVE_COLLAPSERESET); |
|---|
| 408 | m_PiecesTree.Expand(Item, TVE_EXPAND); |
|---|
| 409 | } |
|---|
| 410 | } |
|---|
| 411 | |
|---|
| 412 | void CPiecesBar::UpdatePiecesTree() |
|---|
| 413 | { |
|---|
| 414 | PiecesLibrary* Lib = lcGetPiecesLibrary(); |
|---|
| 415 | |
|---|
| 416 | m_PiecesTree.SetRedraw(FALSE); |
|---|
| 417 | m_PiecesTree.DeleteAllItems(); |
|---|
| 418 | |
|---|
| 419 | for (int i = 0; i < Lib->GetNumCategories(); i++) |
|---|
| 420 | { |
|---|
| 421 | if (Lib->GetCategoryName(i) == "Search Results") |
|---|
| 422 | continue; |
|---|
| 423 | |
|---|
| 424 | m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, Lib->GetCategoryName(i), 0, 0, 0, 0, 0, TVI_ROOT, TVI_SORT); |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, "Models", 0, 0, 0, 0, 0, TVI_ROOT, TVI_LAST); |
|---|
| 428 | m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, "Search Results", 0, 0, 0, 0, 0, TVI_ROOT, TVI_LAST); |
|---|
| 429 | |
|---|
| 430 | m_PiecesTree.SetRedraw(TRUE); |
|---|
| 431 | m_PiecesTree.Invalidate(); |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | void CPiecesBar::RefreshPiecesTree() |
|---|
| 435 | { |
|---|
| 436 | HTREEITEM Item = m_PiecesTree.GetChildItem(TVI_ROOT); |
|---|
| 437 | |
|---|
| 438 | while (Item != NULL) |
|---|
| 439 | { |
|---|
| 440 | if ((m_PiecesTree.GetItemState(Item, TVIF_STATE) & TVIS_EXPANDED) != 0) |
|---|
| 441 | { |
|---|
| 442 | m_PiecesTree.Expand(Item, TVE_COLLAPSE | TVE_COLLAPSERESET); |
|---|
| 443 | m_PiecesTree.Expand(Item, TVE_EXPAND); |
|---|
| 444 | } |
|---|
| 445 | |
|---|
| 446 | Item = m_PiecesTree.GetNextSiblingItem(Item); |
|---|
| 447 | } |
|---|
| 448 | } |
|---|
| 449 | |
|---|
| 450 | BOOL CPiecesBar::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) |
|---|
| 451 | { |
|---|
| 452 | if (wParam == IDW_PIECESTREE) |
|---|
| 453 | { |
|---|
| 454 | LPNMTREEVIEW Notify = (LPNMTREEVIEW)lParam; |
|---|
| 455 | |
|---|
| 456 | if (Notify->hdr.code == TVN_SELCHANGED) |
|---|
| 457 | { |
|---|
| 458 | void* Selection = (void*)Notify->itemNew.lParam; |
|---|
| 459 | |
|---|
| 460 | if (Selection) |
|---|
| 461 | g_App->m_PiecePreview->SetSelection(Selection); |
|---|
| 462 | } |
|---|
| 463 | else if (Notify->hdr.code == TVN_BEGINDRAG) |
|---|
| 464 | { |
|---|
| 465 | if (Notify->itemNew.lParam) |
|---|
| 466 | { |
|---|
| 467 | m_PiecesTree.SelectItem(Notify->itemNew.hItem); |
|---|
| 468 | |
|---|
| 469 | lcGetActiveProject()->BeginPieceDrop(); |
|---|
| 470 | |
|---|
| 471 | |
|---|
| 472 | CFrameWnd* pFrame = (CFrameWnd*)AfxGetMainWnd(); |
|---|
| 473 | CView* pView = pFrame->GetActiveView(); |
|---|
| 474 | pView->PostMessage(WM_LC_SET_CURSOR, 0, 0); |
|---|
| 475 | } |
|---|
| 476 | } |
|---|
| 477 | else if (Notify->hdr.code == TVN_GETINFOTIP) |
|---|
| 478 | { |
|---|
| 479 | LPNMTVGETINFOTIP Tip = (LPNMTVGETINFOTIP)lParam; |
|---|
| 480 | HTREEITEM Item = Tip->hItem; |
|---|
| 481 | void* Data = (void*)m_PiecesTree.GetItemData(Item); |
|---|
| 482 | |
|---|
| 483 | if (Data) |
|---|
| 484 | { |
|---|
| 485 | if (lcGetActiveProject()->m_ModelList.FindIndex((lcModel*)Data) != -1) |
|---|
| 486 | { |
|---|
| 487 | lcModel* Model = (lcModel*)Data; |
|---|
| 488 | _snprintf(Tip->pszText, Tip->cchTextMax, "%s", (const char*)Model->m_Name); |
|---|
| 489 | } |
|---|
| 490 | else |
|---|
| 491 | { |
|---|
| 492 | PieceInfo* Info = (PieceInfo*)Data; |
|---|
| 493 | _snprintf(Tip->pszText, Tip->cchTextMax, "%s (%s)", Info->m_strDescription, Info->m_strName); |
|---|
| 494 | } |
|---|
| 495 | } |
|---|
| 496 | } |
|---|
| 497 | else if (Notify->hdr.code == TVN_ITEMEXPANDING) |
|---|
| 498 | { |
|---|
| 499 | if (Notify->action == TVE_EXPAND) |
|---|
| 500 | { |
|---|
| 501 | m_PiecesTree.SetRedraw(FALSE); |
|---|
| 502 | |
|---|
| 503 | PiecesLibrary *Lib = lcGetPiecesLibrary(); |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | HTREEITEM Item = Notify->itemNew.hItem; |
|---|
| 507 | |
|---|
| 508 | if (m_PiecesTree.ItemHasChildren(Item)) |
|---|
| 509 | { |
|---|
| 510 | HTREEITEM NextItem; |
|---|
| 511 | HTREEITEM ChildItem = m_PiecesTree.GetChildItem(Item); |
|---|
| 512 | |
|---|
| 513 | while (ChildItem != NULL) |
|---|
| 514 | { |
|---|
| 515 | NextItem = m_PiecesTree.GetNextItem(ChildItem, TVGN_NEXT); |
|---|
| 516 | m_PiecesTree.DeleteItem(ChildItem); |
|---|
| 517 | ChildItem = NextItem; |
|---|
| 518 | } |
|---|
| 519 | } |
|---|
| 520 | |
|---|
| 521 | if (Notify->itemNew.lParam == NULL) |
|---|
| 522 | { |
|---|
| 523 | HTREEITEM CategoryItem = Notify->itemNew.hItem; |
|---|
| 524 | CString CategoryName = m_PiecesTree.GetItemText(CategoryItem); |
|---|
| 525 | |
|---|
| 526 | if (CategoryName == "Models") |
|---|
| 527 | { |
|---|
| 528 | |
|---|
| 529 | Project* project = lcGetActiveProject(); |
|---|
| 530 | bool Empty = true; |
|---|
| 531 | |
|---|
| 532 | for (int i = 0; i < project->m_ModelList.GetSize(); i++) |
|---|
| 533 | { |
|---|
| 534 | lcModel* Model = project->m_ModelList[i]; |
|---|
| 535 | |
|---|
| 536 | if ((Model == project->m_ActiveModel) || (Model->IsSubModel(project->m_ActiveModel))) |
|---|
| 537 | continue; |
|---|
| 538 | |
|---|
| 539 | Empty = false; |
|---|
| 540 | |
|---|
| 541 | m_PiecesTree.InsertItem(TVIF_PARAM|TVIF_TEXT, Model->m_Name, 0, 0, 0, 0, (LPARAM)Model, CategoryItem, TVI_LAST); |
|---|
| 542 | } |
|---|
| 543 | |
|---|
| 544 | if (Empty) |
|---|
| 545 | m_PiecesTree.InsertItem(TVIF_PARAM|TVIF_TEXT, "No Models", 0, 0, 0, 0, (LPARAM)NULL, CategoryItem, TVI_LAST); |
|---|
| 546 | } |
|---|
| 547 | else |
|---|
| 548 | { |
|---|
| 549 | |
|---|
| 550 | int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName); |
|---|
| 551 | |
|---|
| 552 | lcPtrArray<PieceInfo> SinglePieces, GroupedPieces; |
|---|
| 553 | |
|---|
| 554 | if (CategoryIndex != -1) |
|---|
| 555 | { |
|---|
| 556 | int i; |
|---|
| 557 | |
|---|
| 558 | Lib->GetCategoryEntries(CategoryIndex, true, SinglePieces, GroupedPieces); |
|---|
| 559 | |
|---|
| 560 | |
|---|
| 561 | SinglePieces += GroupedPieces; |
|---|
| 562 | SinglePieces.Sort(PiecesSortFunc, NULL); |
|---|
| 563 | |
|---|
| 564 | for (i = 0; i < SinglePieces.GetSize(); i++) |
|---|
| 565 | { |
|---|
| 566 | PieceInfo* Info = SinglePieces[i]; |
|---|
| 567 | |
|---|
| 568 | if (!m_bSubParts && Info->IsSubPiece()) |
|---|
| 569 | continue; |
|---|
| 570 | |
|---|
| 571 | if (GroupedPieces.FindIndex(Info) == -1) |
|---|
| 572 | m_PiecesTree.InsertItem(TVIF_PARAM|TVIF_TEXT, Info->m_strDescription, 0, 0, 0, 0, (LPARAM)Info, CategoryItem, TVI_LAST); |
|---|
| 573 | else |
|---|
| 574 | m_PiecesTree.InsertItem(TVIF_CHILDREN|TVIF_PARAM|TVIF_TEXT, Info->m_strDescription, 0, 0, 0, 0, (LPARAM)Info, CategoryItem, TVI_LAST); |
|---|
| 575 | } |
|---|
| 576 | } |
|---|
| 577 | |
|---|
| 578 | if (CategoryName == "Search Results") |
|---|
| 579 | { |
|---|
| 580 | |
|---|
| 581 | if ((SinglePieces.GetSize() == 0) && (GroupedPieces.GetSize() == 0)) |
|---|
| 582 | { |
|---|
| 583 | m_PiecesTree.InsertItem(TVIF_PARAM|TVIF_TEXT, "No pieces found", 0, 0, 0, 0, 0, CategoryItem, TVI_SORT); |
|---|
| 584 | } |
|---|
| 585 | } |
|---|
| 586 | } |
|---|
| 587 | } |
|---|
| 588 | else |
|---|
| 589 | { |
|---|
| 590 | PieceInfo* Parent = (PieceInfo*)Notify->itemNew.lParam; |
|---|
| 591 | |
|---|
| 592 | HTREEITEM CategoryItem = m_PiecesTree.GetParentItem(Notify->itemNew.hItem); |
|---|
| 593 | CString CategoryName = m_PiecesTree.GetItemText(CategoryItem); |
|---|
| 594 | int CategoryIndex = Lib->FindCategoryIndex((const char*)CategoryName); |
|---|
| 595 | |
|---|
| 596 | lcPtrArray<PieceInfo> Pieces; |
|---|
| 597 | Lib->GetPatternedPieces(Parent, Pieces); |
|---|
| 598 | |
|---|
| 599 | Pieces.Sort(PiecesSortFunc, NULL); |
|---|
| 600 | HTREEITEM ParentItem = Notify->itemNew.hItem; |
|---|
| 601 | |
|---|
| 602 | for (int i = 0; i < Pieces.GetSize(); i++) |
|---|
| 603 | { |
|---|
| 604 | PieceInfo* Info = Pieces[i]; |
|---|
| 605 | |
|---|
| 606 | if (!m_bSubParts && Info->IsSubPiece()) |
|---|
| 607 | continue; |
|---|
| 608 | |
|---|
| 609 | if (CategoryIndex != -1) |
|---|
| 610 | { |
|---|
| 611 | if (!Lib->PieceInCategory(Info, Lib->GetCategoryKeywords(CategoryIndex))) |
|---|
| 612 | continue; |
|---|
| 613 | } |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | if (!strncmp(Info->m_strDescription, Parent->m_strDescription, strlen(Parent->m_strDescription))) |
|---|
| 617 | m_PiecesTree.InsertItem(TVIF_PARAM|TVIF_TEXT, Info->m_strDescription + strlen(Parent->m_strDescription) + 1, 0, 0, 0, 0, (LPARAM)Info, ParentItem, TVI_LAST); |
|---|
| 618 | else |
|---|
| 619 | m_PiecesTree.InsertItem(TVIF_PARAM|TVIF_TEXT, Info->m_strDescription, 0, 0, 0, 0, (LPARAM)Info, ParentItem, TVI_LAST); |
|---|
| 620 | } |
|---|
| 621 | } |
|---|
| 622 | |
|---|
| 623 | m_PiecesTree.SetRedraw(TRUE); |
|---|
| 624 | m_PiecesTree.Invalidate(); |
|---|
| 625 | } |
|---|
| 626 | else if (Notify->action == TVE_COLLAPSE) |
|---|
| 627 | { |
|---|
| 628 | m_PiecesTree.Expand(Notify->itemNew.hItem, TVE_COLLAPSE | TVE_COLLAPSERESET); |
|---|
| 629 | } |
|---|
| 630 | } |
|---|
| 631 | } |
|---|
| 632 | |
|---|
| 633 | return CSizingControlBarG::OnNotify(wParam, lParam, pResult); |
|---|
| 634 | } |
|---|