00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "winbookmarks.h"
00013 #include "res/resource.h"
00014 #include <celutil/winutil.h>
00015 #include <iostream>
00016
00017 using namespace std;
00018
00019 bool dragging;
00020 HTREEITEM hDragItem;
00021 HTREEITEM hDropTargetItem;
00022 POINT dragPos;
00023
00024 static const unsigned int StdItemMask = (TVIF_TEXT | TVIF_PARAM |
00025 TVIF_IMAGE | TVIF_SELECTEDIMAGE);
00026
00027 static bool isTopLevel(const FavoritesEntry* fav)
00028 {
00029 return fav->parentFolder == "";
00030 }
00031
00032
00033 HTREEITEM PopulateBookmarksTree(HWND hTree, CelestiaCore* appCore, HINSTANCE appInstance)
00034 {
00035
00036 HIMAGELIST himlIcons;
00037 HICON hIcon;
00038 HTREEITEM hParent=NULL, hParentItem;
00039
00040
00041 himlIcons = ImageList_Create(16, 16, ILC_MASK, 3, 0);
00042
00043
00044 hIcon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_CLOSEDFOLDER));
00045 ImageList_AddIcon(himlIcons, hIcon);
00046 hIcon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_OPENFOLDER));
00047 ImageList_AddIcon(himlIcons, hIcon);
00048 hIcon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_ROOTFOLDER));
00049 ImageList_AddIcon(himlIcons, hIcon);
00050 hIcon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_BOOKMARK));
00051 ImageList_AddIcon(himlIcons, hIcon);
00052
00053
00054 TreeView_SetImageList(hTree, himlIcons, TVSIL_NORMAL);
00055
00056 FavoritesList* favorites = appCore->getFavorites();
00057 if (favorites != NULL)
00058 {
00059
00060 TVINSERTSTRUCT tvis;
00061
00062 tvis.hParent = TVI_ROOT;
00063 tvis.hInsertAfter = TVI_LAST;
00064 tvis.item.mask = StdItemMask;
00065 tvis.item.pszText = "Bookmarks";
00066 tvis.item.lParam = NULL;
00067 tvis.item.iImage = 2;
00068 tvis.item.iSelectedImage = 2;
00069 if (hParent = TreeView_InsertItem(hTree, &tvis))
00070 {
00071 FavoritesList::iterator iter = favorites->begin();
00072 while (iter != favorites->end())
00073 {
00074 TVINSERTSTRUCT tvis;
00075 FavoritesEntry* fav = *iter;
00076
00077
00078 if (fav->isFolder)
00079 {
00080
00081 tvis.hParent = hParent;
00082 tvis.hInsertAfter = TVI_LAST;
00083 tvis.item.mask = StdItemMask;
00084 tvis.item.pszText = const_cast<char*>(fav->name.c_str());
00085 tvis.item.lParam = reinterpret_cast<LPARAM>(fav);
00086 tvis.item.iImage = 0;
00087 tvis.item.iSelectedImage = 1;
00088
00089 if (hParentItem = TreeView_InsertItem(hTree, &tvis))
00090 {
00091 FavoritesList::iterator subIter = favorites->begin();
00092 while (subIter != favorites->end())
00093 {
00094 FavoritesEntry* child = *subIter;
00095
00096
00097 if (!child->isFolder && child->parentFolder == fav->name)
00098 {
00099
00100 tvis.hParent = hParentItem;
00101 tvis.hInsertAfter = TVI_LAST;
00102 tvis.item.mask = StdItemMask;
00103 tvis.item.pszText = const_cast<char*>(child->name.c_str());
00104 tvis.item.lParam = reinterpret_cast<LPARAM>(child);
00105 tvis.item.iImage = 3;
00106 tvis.item.iSelectedImage = 3;
00107 TreeView_InsertItem(hTree, &tvis);
00108 }
00109 subIter++;
00110 }
00111
00112
00113 TreeView_Expand(hTree, hParentItem, TVE_EXPAND);
00114 }
00115 }
00116 else if (isTopLevel(fav))
00117 {
00118
00119 tvis.hParent = hParent;
00120 tvis.hInsertAfter = TVI_LAST;
00121 tvis.item.mask = StdItemMask;
00122 tvis.item.pszText = const_cast<char*>((*iter)->name.c_str());
00123 tvis.item.lParam = reinterpret_cast<LPARAM>(fav);
00124 tvis.item.iImage = 3;
00125 tvis.item.iSelectedImage = 3;
00126 TreeView_InsertItem(hTree, &tvis);
00127 }
00128
00129 iter++;
00130 }
00131 }
00132 }
00133
00134 dragging = false;
00135
00136 return hParent;
00137 }
00138
00139
00140 HTREEITEM PopulateBookmarkFolders(HWND hTree, CelestiaCore* appCore, HINSTANCE appInstance)
00141 {
00142
00143 HTREEITEM hParent=NULL;
00144 HIMAGELIST himlIcons;
00145 HICON hIcon;
00146
00147
00148 himlIcons = ImageList_Create(16, 16, ILC_MASK, 3, 0);
00149
00150
00151 hIcon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_CLOSEDFOLDER));
00152 ImageList_AddIcon(himlIcons, hIcon);
00153 hIcon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_OPENFOLDER));
00154 ImageList_AddIcon(himlIcons, hIcon);
00155 hIcon = LoadIcon(appInstance, MAKEINTRESOURCE(IDI_ROOTFOLDER));
00156 ImageList_AddIcon(himlIcons, hIcon);
00157
00158
00159 TreeView_SetImageList(hTree, himlIcons, TVSIL_NORMAL);
00160
00161 FavoritesList* favorites = appCore->getFavorites();
00162 if (favorites != NULL)
00163 {
00164
00165 TVINSERTSTRUCT tvis;
00166
00167 tvis.hParent = TVI_ROOT;
00168 tvis.hInsertAfter = TVI_LAST;
00169 tvis.item.mask = TVIF_TEXT | TVIF_PARAM | TVIF_IMAGE | TVIF_SELECTEDIMAGE;
00170 tvis.item.pszText = "Bookmarks";
00171 tvis.item.lParam = 0;
00172 tvis.item.iImage = 2;
00173 tvis.item.iSelectedImage = 2;
00174 if (hParent = TreeView_InsertItem(hTree, &tvis))
00175 {
00176 FavoritesList::iterator iter = favorites->begin();
00177 while (iter != favorites->end())
00178 {
00179 FavoritesEntry* fav = *iter;
00180
00181 if (fav->isFolder)
00182 {
00183
00184 TVINSERTSTRUCT tvis;
00185 tvis.hParent = hParent;
00186 tvis.hInsertAfter = TVI_LAST;
00187 tvis.item.mask = StdItemMask;
00188 tvis.item.pszText = const_cast<char*>(fav->name.c_str());
00189 tvis.item.lParam = reinterpret_cast<LPARAM>(fav);
00190 tvis.item.iImage = 0;
00191 tvis.item.iSelectedImage = 1;
00192 TreeView_InsertItem(hTree, &tvis);
00193 }
00194
00195 iter++;
00196 }
00197
00198
00199 TreeView_SelectItem(hTree, hParent);
00200 }
00201 }
00202
00203 return hParent;
00204 }
00205
00206
00207 void BuildFavoritesMenu(HMENU menuBar,
00208 CelestiaCore* appCore,
00209 HINSTANCE appInstance,
00210 ODMenu* odMenu)
00211 {
00212
00213 int numStaticItems = 2;
00214
00215
00216
00217
00218
00219 UINT bookmarksMenuPosition = 5;
00220
00221 FavoritesList* favorites = appCore->getFavorites();
00222 if (favorites == NULL)
00223 return;
00224
00225 MENUITEMINFO menuInfo;
00226 menuInfo.cbSize = sizeof(MENUITEMINFO);
00227 menuInfo.fMask = MIIM_SUBMENU;
00228 if (GetMenuItemInfo(menuBar, bookmarksMenuPosition, TRUE, &menuInfo))
00229 {
00230 HMENU bookmarksMenu = menuInfo.hSubMenu;
00231
00232
00233 while (DeleteMenu(bookmarksMenu, numStaticItems, MF_BYPOSITION))
00234 odMenu->DeleteItem(bookmarksMenu, numStaticItems);
00235
00236
00237 if (favorites->size() == 0)
00238 return;
00239
00240
00241 menuInfo.cbSize = sizeof MENUITEMINFO;
00242 menuInfo.fMask = MIIM_TYPE | MIIM_STATE;
00243 menuInfo.fType = MFT_SEPARATOR;
00244 menuInfo.fState = MFS_UNHILITE;
00245 if (InsertMenuItem(bookmarksMenu, numStaticItems, TRUE, &menuInfo))
00246 {
00247 odMenu->AddItem(bookmarksMenu, numStaticItems);
00248 numStaticItems++;
00249 }
00250
00251
00252 int rootMenuIndex = numStaticItems;
00253 int rootResIndex = 0;
00254 FavoritesList::iterator iter = favorites->begin();
00255 while (iter != favorites->end())
00256 {
00257 FavoritesEntry* fav = *iter;
00258
00259
00260 if (fav->isFolder)
00261 {
00262
00263 HMENU subMenu;
00264 if (subMenu = CreatePopupMenu())
00265 {
00266
00267 menuInfo.cbSize = sizeof MENUITEMINFO;
00268 menuInfo.fMask = MIIM_SUBMENU | MIIM_TYPE | MIIM_ID;
00269 menuInfo.fType = MFT_STRING;
00270 menuInfo.wID = ID_BOOKMARKS_FIRSTBOOKMARK + rootResIndex;
00271 menuInfo.hSubMenu = subMenu;
00272 menuInfo.dwTypeData = const_cast<char*>(fav->name.c_str());
00273
00274 if (InsertMenuItem(bookmarksMenu,
00275 rootMenuIndex,
00276 TRUE,
00277 &menuInfo))
00278 {
00279 odMenu->AddItem(bookmarksMenu, rootMenuIndex);
00280 odMenu->SetItemImage(appInstance, menuInfo.wID,
00281 IDB_FOLDERCLOSED);
00282 rootMenuIndex++;
00283
00284
00285
00286 int subMenuIndex = 0;
00287 int childResIndex = 0;
00288 string folderName = fav->name;
00289
00290 for (FavoritesList::iterator childIter = favorites->begin();
00291 childIter != favorites->end();
00292 childIter++, childResIndex++)
00293 {
00294 FavoritesEntry* child = *childIter;
00295 if (!child->isFolder &&
00296 child->parentFolder == folderName)
00297 {
00298 clog << " " << child->name << '\n';
00299
00300 menuInfo.cbSize = sizeof MENUITEMINFO;
00301 menuInfo.fMask = MIIM_TYPE | MIIM_ID;
00302 menuInfo.fType = MFT_STRING;
00303 menuInfo.wID = ID_BOOKMARKS_FIRSTBOOKMARK + childResIndex;
00304 menuInfo.dwTypeData = const_cast<char*>(child->name.c_str());
00305 if (InsertMenuItem(subMenu, subMenuIndex, TRUE, &menuInfo))
00306 {
00307 odMenu->AddItem(subMenu, subMenuIndex);
00308 odMenu->SetItemImage(appInstance, menuInfo.wID, IDB_BOOKMARK);
00309 subMenuIndex++;
00310 }
00311 }
00312 }
00313
00314
00315
00316 if (subMenuIndex == 0)
00317 {
00318 menuInfo.cbSize = sizeof MENUITEMINFO;
00319 menuInfo.fMask = MIIM_TYPE | MIIM_STATE;
00320 menuInfo.fType = MFT_STRING;
00321 menuInfo.fState = MFS_DISABLED;
00322 menuInfo.dwTypeData = "(empty)";
00323 if (InsertMenuItem(subMenu, subMenuIndex, TRUE, &menuInfo))
00324 {
00325 odMenu->AddItem(subMenu, subMenuIndex);
00326 }
00327 }
00328 }
00329 }
00330 }
00331
00332 rootResIndex++;
00333 iter++;
00334 }
00335
00336
00337 iter = favorites->begin();
00338 rootResIndex = 0;
00339 while (iter != favorites->end())
00340 {
00341 FavoritesEntry* fav = *iter;
00342
00343
00344 if (!fav->isFolder && isTopLevel(fav))
00345 {
00346
00347 AppendMenu(bookmarksMenu, MF_STRING,
00348 ID_BOOKMARKS_FIRSTBOOKMARK + rootResIndex,
00349 const_cast<char*>(fav->name.c_str()));
00350
00351 odMenu->AddItem(bookmarksMenu, rootMenuIndex);
00352 odMenu->SetItemImage(appInstance,
00353 ID_BOOKMARKS_FIRSTBOOKMARK + rootResIndex,
00354 IDB_BOOKMARK);
00355 rootMenuIndex++;
00356 }
00357 iter++;
00358 rootResIndex++;
00359 }
00360 }
00361 }
00362
00363
00364 void AddNewBookmarkFolderInTree(HWND hTree, CelestiaCore* appCore, char* folderName)
00365 {
00366
00367 HTREEITEM hParent, hItem, hInsertAfter;
00368 TVINSERTSTRUCT tvis;
00369 TVITEM tvItem;
00370
00371 hParent = TreeView_GetChild(hTree, TVI_ROOT);
00372 if (hParent)
00373 {
00374
00375 hItem = TreeView_GetChild(hTree, hParent);
00376 while (hItem)
00377 {
00378
00379 tvItem.hItem = hItem;
00380 tvItem.mask = TVIF_HANDLE | TVIF_PARAM;
00381 if (TreeView_GetItem(hTree, &tvItem))
00382 {
00383 FavoritesEntry* fav = reinterpret_cast<FavoritesEntry*>(tvItem.lParam);
00384 if (fav == NULL || fav->isFolder)
00385 hInsertAfter = hItem;
00386 }
00387 hItem = TreeView_GetNextSibling(hTree, hItem);
00388 }
00389
00390 FavoritesEntry* folderFav = new FavoritesEntry();
00391 folderFav->isFolder = true;
00392 folderFav->name = folderName;
00393
00394 FavoritesList* favorites = appCore->getFavorites();
00395 favorites->insert(favorites->end(), folderFav);
00396
00397 tvis.hParent = hParent;
00398 tvis.hInsertAfter = hInsertAfter;
00399 tvis.item.mask = StdItemMask;
00400 tvis.item.pszText = folderName;
00401 tvis.item.lParam = reinterpret_cast<LPARAM>(folderFav);
00402 tvis.item.iImage = 2;
00403 tvis.item.iSelectedImage = 1;
00404 if (hItem = TreeView_InsertItem(hTree, &tvis))
00405 {
00406
00407
00408 TreeView_Expand(hTree, hParent, TVE_EXPAND);
00409
00410
00411 TreeView_SelectItem(hTree, hItem);
00412 }
00413 }
00414 }
00415
00416
00417 void SyncTreeFoldersWithFavoriteFolders(HWND hTree, CelestiaCore* appCore)
00418 {
00419 FavoritesList* favorites = appCore->getFavorites();
00420 FavoritesList::iterator iter;
00421 TVITEM tvItem;
00422 HTREEITEM hItem, hParent;
00423 char itemName[33];
00424 bool found;
00425
00426 if (favorites != NULL)
00427 {
00428
00429
00430 if (hParent = TreeView_GetChild(hTree, TVI_ROOT))
00431 {
00432 hItem = TreeView_GetChild(hTree, hParent);
00433 do
00434 {
00435
00436 tvItem.hItem = hItem;
00437 tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_HANDLE;
00438 tvItem.pszText = itemName;
00439 tvItem.cchTextMax = sizeof(itemName);
00440 if (TreeView_GetItem(hTree, &tvItem))
00441 {
00442
00443 if(tvItem.lParam == 0)
00444 continue;
00445
00446 string name(itemName);
00447 if (favorites->size() == 0)
00448 {
00449
00450 appCore->addFavoriteFolder(name);
00451 continue;
00452 }
00453
00454
00455 found = false;
00456 iter = favorites->begin();
00457 while (iter != favorites->end())
00458 {
00459 if ((*iter)->isFolder && (*iter)->name == itemName)
00460 {
00461 found = true;
00462 break;
00463 }
00464 iter++;
00465 }
00466
00467 if (!found)
00468 {
00469
00470
00471
00472
00473
00474 FavoritesList::iterator folderIter = favorites->begin();
00475 iter = favorites->begin();
00476 while (iter != favorites->end())
00477 {
00478 if ((*iter)->isFolder)
00479 folderIter = iter;
00480
00481 iter++;
00482 }
00483
00484 folderIter++;
00485 while (folderIter != favorites->end() && (*folderIter)->parentFolder != "")
00486 folderIter++;
00487
00488
00489 appCore->addFavoriteFolder(name, &folderIter);
00490 }
00491 }
00492 } while (hItem = TreeView_GetNextSibling(hTree, hItem));
00493 }
00494 }
00495 }
00496
00497
00498 void InsertBookmarkInFavorites(HWND hTree, char* name, CelestiaCore* appCore)
00499 {
00500 FavoritesList* favorites = appCore->getFavorites();
00501 TVITEM tvItem;
00502 HTREEITEM hItem;
00503 char itemName[33];
00504 string newBookmark(name);
00505
00506
00507
00508
00509 hItem = TreeView_GetSelection(hTree);
00510 if (!TreeView_GetParent(hTree, hItem))
00511 hItem = NULL;
00512
00513 if (hItem)
00514 {
00515 tvItem.hItem = hItem;
00516 tvItem.mask = TVIF_TEXT | TVIF_HANDLE;
00517 tvItem.pszText = itemName;
00518 tvItem.cchTextMax = sizeof(itemName);
00519 if (TreeView_GetItem(hTree, &tvItem))
00520 {
00521 FavoritesEntry* fav = reinterpret_cast<FavoritesEntry*>(tvItem.lParam);
00522 if (fav != NULL && fav->isFolder)
00523 {
00524 appCore->addFavorite(newBookmark, string(itemName));
00525 }
00526 }
00527 }
00528 else
00529 {
00530
00531 appCore->addFavorite(newBookmark, "");
00532 }
00533 }
00534
00535
00536 void DeleteBookmarkFromFavorites(HWND hTree, CelestiaCore* appCore)
00537 {
00538 FavoritesList* favorites = appCore->getFavorites();
00539 TVITEM tvItem;
00540 HTREEITEM hItem;
00541 char itemName[33];
00542
00543 hItem = TreeView_GetSelection(hTree);
00544 if (!hItem)
00545 return;
00546
00547
00548 tvItem.hItem = hItem;
00549 tvItem.mask = TVIF_TEXT | TVIF_PARAM | TVIF_HANDLE;
00550 tvItem.pszText = itemName;
00551 tvItem.cchTextMax = sizeof(itemName);
00552 if (!TreeView_GetItem(hTree, &tvItem))
00553 return;
00554
00555 FavoritesEntry* fav = reinterpret_cast<FavoritesEntry*>(tvItem.lParam);
00556 if (!fav)
00557 return;
00558
00559
00560
00561 if (!TreeView_DeleteItem(hTree, hItem))
00562 return;
00563
00564
00565 FavoritesList::iterator iter = favorites->begin();
00566 while (iter != favorites->end())
00567 {
00568 if (*iter == fav)
00569 {
00570 favorites->erase(iter);
00571 }
00572 else if (fav->isFolder && (*iter)->parentFolder == itemName)
00573 {
00574 favorites->erase(iter);
00575
00576 }
00577 else
00578 {
00579 iter++;
00580 }
00581 }
00582 }
00583
00584
00585 void RenameBookmarkInFavorites(HWND hTree, char* newName, CelestiaCore* appCore)
00586 {
00587 FavoritesList* favorites = appCore->getFavorites();
00588 TVITEM tvItem;
00589 HTREEITEM hItem;
00590 char itemName[33];
00591
00592
00593 hItem = TreeView_GetSelection(hTree);
00594 if (!hItem)
00595 return;
00596
00597
00598 tvItem.hItem = hItem;
00599 tvItem.mask = TVIF_TEXT | TVIF_HANDLE;
00600 tvItem.pszText = itemName;
00601 tvItem.cchTextMax = sizeof(itemName);
00602 if (!TreeView_GetItem(hTree, &tvItem))
00603 return;
00604
00605 FavoritesEntry* fav = reinterpret_cast<FavoritesEntry*>(tvItem.lParam);
00606 if (fav == NULL)
00607 return;
00608
00609 tvItem.hItem = hItem;
00610 tvItem.mask = TVIF_TEXT | TVIF_HANDLE;
00611 tvItem.pszText = newName;
00612 if (!TreeView_SetItem(hTree, &tvItem))
00613 return;
00614
00615 string oldName = fav->name;
00616 fav->name = newName;
00617
00618 if (fav->isFolder)
00619 {
00620 FavoritesList::iterator iter = favorites->begin();
00621 while (iter != favorites->end())
00622 {
00623 if ((*iter)->parentFolder == oldName)
00624 (*iter)->parentFolder = newName;
00625 iter++;
00626 }
00627 }
00628 }
00629
00630
00631 void MoveBookmarkInFavorites(HWND hTree, CelestiaCore* appCore)
00632 {
00633 FavoritesList* favorites = appCore->getFavorites();
00634 TVITEM tvItem;
00635 TVINSERTSTRUCT tvis;
00636 HTREEITEM hDragItemFolder, hDropItem;
00637 char dragItemName[33];
00638 char dragItemFolderName[33];
00639 char dropFolderName[33];
00640 bool bMovedInTree = false;
00641 FavoritesEntry* draggedFav = NULL;
00642 FavoritesEntry* dropFolderFav = NULL;
00643
00644
00645 tvItem.hItem = hDropTargetItem;
00646 tvItem.mask = TVIF_TEXT | TVIF_HANDLE;
00647 tvItem.pszText = dropFolderName;
00648 tvItem.cchTextMax = sizeof(dropFolderName);
00649 if (!TreeView_GetItem(hTree, &tvItem))
00650 return;
00651
00652 if (!TreeView_GetParent(hTree, hDropTargetItem))
00653 dropFolderName[0] = '\0';
00654
00655
00656 tvItem.lParam = NULL;
00657 tvItem.hItem = hDragItem;
00658 tvItem.mask = TVIF_TEXT | TVIF_HANDLE;
00659 tvItem.pszText = dragItemName;
00660 tvItem.cchTextMax = sizeof(dragItemName);
00661 if (TreeView_GetItem(hTree, &tvItem))
00662 {
00663 draggedFav = reinterpret_cast<FavoritesEntry*>(tvItem.lParam);
00664
00665
00666 if (hDragItemFolder = TreeView_GetParent(hTree, hDragItem))
00667 {
00668 tvItem.hItem = hDragItemFolder;
00669 tvItem.mask = TVIF_TEXT | TVIF_HANDLE;
00670 tvItem.pszText = dragItemFolderName;
00671 tvItem.cchTextMax = sizeof(dragItemFolderName);
00672 if (TreeView_GetItem(hTree, &tvItem))
00673 {
00674 if (!TreeView_GetParent(hTree, hDragItemFolder))
00675 dragItemFolderName[0] = '\0';
00676
00677
00678 if (strcmp(dragItemFolderName, dropFolderName))
00679 {
00680
00681 if (TreeView_DeleteItem(hTree, hDragItem))
00682 {
00683
00684 tvis.hParent = hDropTargetItem;
00685 tvis.hInsertAfter = TVI_LAST;
00686 tvis.item.mask = StdItemMask;
00687 tvis.item.pszText = dragItemName;
00688 tvis.item.lParam = reinterpret_cast<LPARAM>(draggedFav);
00689 tvis.item.iImage = 3;
00690 tvis.item.iSelectedImage = 3;
00691 if (hDropItem = TreeView_InsertItem(hTree, &tvis))
00692 {
00693 TreeView_Expand(hTree, hDropTargetItem, TVE_EXPAND);
00694
00695
00696 TreeView_SelectItem(hTree, hDropItem);
00697
00698 bMovedInTree = true;
00699 }
00700 }
00701 }
00702 }
00703 }
00704 }
00705
00706
00707 if (bMovedInTree && draggedFav != NULL)
00708 {
00709 draggedFav->parentFolder = dropFolderName;
00710 }
00711 }
00712
00713
00714 bool isOrganizeBookmarksDragDropActive()
00715 {
00716 return dragging;
00717 }
00718
00719
00720 void OrganizeBookmarksOnBeginDrag(HWND hTree, LPNMTREEVIEW lpnmtv)
00721 {
00722 HIMAGELIST himl;
00723 RECT rcItem;
00724 DWORD dwLevel;
00725 DWORD dwIndent;
00726
00727
00728 TreeView_SelectItem(hTree, NULL);
00729
00730
00731
00732 hDragItem = lpnmtv->itemNew.hItem;
00733 himl = TreeView_CreateDragImage(hTree, hDragItem);
00734
00735
00736 TreeView_GetItemRect(hTree, hDragItem, &rcItem, TRUE);
00737
00738
00739
00740 dwLevel = lpnmtv->itemNew.lParam;
00741 dwIndent = (DWORD) SendMessage(hTree, TVM_GETINDENT, 0, 0);
00742
00743 ImageList_DragShowNolock(TRUE);
00744
00745
00746 ImageList_BeginDrag(himl, 0, 7, 7);
00747
00748
00749
00750 ShowCursor(FALSE);
00751 SetCapture(GetParent(hTree));
00752 dragging = true;
00753 }
00754
00755
00756 void OrganizeBookmarksOnMouseMove(HWND hTree, LONG xCur, LONG yCur)
00757 {
00758 TVHITTESTINFO tvht;
00759 TVITEM tvItem;
00760 HTREEITEM hItem;
00761
00762
00763 dragPos.x = xCur;
00764 dragPos.y = yCur;
00765
00766 if (dragging)
00767 {
00768
00769 ImageList_DragMove(xCur, yCur);
00770 ImageList_DragLeave(hTree);
00771
00772
00773
00774 tvht.pt.x = dragPos.x;
00775 tvht.pt.y = dragPos.y;
00776 if(hItem = TreeView_HitTest(hTree, &tvht))
00777 {
00778
00779 tvItem.hItem = hItem;
00780 tvItem.mask = TVIF_PARAM | TVIF_HANDLE;
00781 if (TreeView_GetItem(hTree, &tvItem))
00782 {
00783 FavoritesEntry* fav = reinterpret_cast<FavoritesEntry*>(tvItem.lParam);
00784 if (fav != NULL && fav->isFolder)
00785 {
00786 hDropTargetItem = hItem;
00787 TreeView_SelectDropTarget(hTree, hDropTargetItem);
00788 }
00789 }
00790 }
00791
00792 ImageList_DragEnter(hTree, xCur, yCur);
00793 }
00794 }
00795
00796
00797 void OrganizeBookmarksOnLButtonUp(HWND hTree)
00798 {
00799 if (dragging)
00800 {
00801 ImageList_EndDrag();
00802 ImageList_DragLeave(hTree);
00803 ReleaseCapture();
00804 ShowCursor(TRUE);
00805 dragging = false;
00806
00807
00808 TreeView_SelectDropTarget(hTree, NULL);
00809 }
00810 }
00811
00812
00813 void DragDropAutoScroll(HWND hTree)
00814 {
00815 RECT rect;
00816 int i, count;
00817 HTREEITEM hItem;
00818
00819 GetClientRect(hTree, &rect);
00820
00821 ImageList_DragLeave(hTree);
00822
00823
00824 if (dragPos.y > rect.bottom - 10)
00825 {
00826
00827
00828 if (dragPos.x > rect.left && dragPos.x < rect.right)
00829 {
00830 SendMessage(hTree, WM_VSCROLL, SB_LINEDOWN, 0);
00831 count = TreeView_GetVisibleCount(hTree);
00832 hItem = TreeView_GetFirstVisible(hTree);
00833 for (i = 0; i < count - 1; i++)
00834 hItem = TreeView_GetNextVisible(hTree, hItem);
00835
00836 if (hItem)
00837 {
00838 hDropTargetItem = hItem;
00839 TreeView_SelectDropTarget(hTree, hDropTargetItem);
00840 }
00841 }
00842 }
00843 else if (dragPos.y < rect.top + 10)
00844 {
00845
00846
00847 if (dragPos.x > rect.left && dragPos.x < rect.right)
00848 {
00849 SendMessage(hTree, WM_VSCROLL, SB_LINEUP, 0);
00850 hItem = TreeView_GetFirstVisible(hTree);
00851 if(hItem)
00852 {
00853 hDropTargetItem = hItem;
00854 TreeView_SelectDropTarget(hTree, hDropTargetItem);
00855 }
00856 }
00857 }
00858
00859 ImageList_DragEnter(hTree, dragPos.x, dragPos.y);
00860 }
00861
00862
00864
00865
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914