Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

winbookmarks.h File Reference

#include <windows.h>
#include <commctrl.h>
#include "favorites.h"
#include "celestiacore.h"
#include "odmenu.h"

Include dependency graph for winbookmarks.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void AddNewBookmarkFolderInTree (HWND, CelestiaCore *, char *)
void BuildFavoritesMenu (HMENU, CelestiaCore *, HINSTANCE, ODMenu *)
void DeleteBookmarkFromFavorites (HWND, CelestiaCore *)
void DragDropAutoScroll (HWND)
void InsertBookmarkInFavorites (HWND, char *, CelestiaCore *)
bool isOrganizeBookmarksDragDropActive ()
void MoveBookmarkInFavorites (HWND, CelestiaCore *)
void OrganizeBookmarksOnBeginDrag (HWND, LPNMTREEVIEW)
void OrganizeBookmarksOnLButtonUp (HWND)
void OrganizeBookmarksOnMouseMove (HWND, LONG, LONG)
HTREEITEM PopulateBookmarkFolders (HWND, CelestiaCore *, HINSTANCE)
HTREEITEM PopulateBookmarksTree (HWND, CelestiaCore *, HINSTANCE)
void RenameBookmarkInFavorites (HWND, char *, CelestiaCore *)
void SyncTreeFoldersWithFavoriteFolders (HWND, CelestiaCore *)


Function Documentation

void AddNewBookmarkFolderInTree HWND  ,
CelestiaCore ,
char * 
 

Definition at line 364 of file winbookmarks.cpp.

References FavoritesEntry::isFolder, FavoritesEntry::name, and StdItemMask.

Referenced by AddBookmarkFolderProc().

00365 {
00366     // Add new item to bookmark item after other folders but before root items
00367     HTREEITEM hParent, hItem, hInsertAfter;
00368     TVINSERTSTRUCT tvis;
00369     TVITEM tvItem;
00370 
00371     hParent = TreeView_GetChild(hTree, TVI_ROOT);
00372     if (hParent)
00373     {
00374         // Find last "folder" in children of hParent
00375         hItem = TreeView_GetChild(hTree, hParent);
00376         while (hItem)
00377         {
00378             // Is this a "folder"
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             // Make sure root tree item is open and newly
00407             // added item is visible.
00408             TreeView_Expand(hTree, hParent, TVE_EXPAND);
00409 
00410             // Select the item
00411             TreeView_SelectItem(hTree, hItem);
00412         }
00413     }
00414 }

void BuildFavoritesMenu HMENU  ,
CelestiaCore ,
HINSTANCE  ,
ODMenu
 

Definition at line 207 of file winbookmarks.cpp.

References AppendMenu(), appInstance, ID_BOOKMARKS_FIRSTBOOKMARK, IDB_BOOKMARK, IDB_FOLDERCLOSED, FavoritesEntry::isFolder, isTopLevel(), FavoritesEntry::name, and FavoritesEntry::parentFolder.

Referenced by AddBookmarkProc(), OrganizeBookmarksProc(), and WinMain().

00211 {
00212     // Add item to bookmarks menu
00213     int numStaticItems = 2; // The number of items defined in the .rc file.
00214 
00215     // Ugly dependence on menu defined in celestia.rc; this needs to change
00216     // if the bookmarks menu is moved, or if another item is added to the
00217     // menu bar.
00218     // TODO: Fix this dependency
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         // First, tear down existing menu beyond separator.
00233         while (DeleteMenu(bookmarksMenu, numStaticItems, MF_BYPOSITION))
00234             odMenu->DeleteItem(bookmarksMenu, numStaticItems);
00235 
00236         // Don't continue if there are no items in favorites
00237         if (favorites->size() == 0)
00238             return;
00239 
00240         // Insert separator
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         // Add folders and their sub items
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             // Is this a folder?
00260             if (fav->isFolder)
00261             {
00262                 // Create a submenu
00263                 HMENU subMenu;
00264                 if (subMenu = CreatePopupMenu())
00265                 {
00266                     // Create a menu item that displays a popup sub menu
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                         // Now iterate through all Favorites and add items
00285                         // to this folder where parentFolder == folderName
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                                 // Add item to sub menu
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                         // Add a disabled "(empty)" item if no items
00315                         // were added to sub menu
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         // Add root bookmark items
00337         iter = favorites->begin();
00338         rootResIndex = 0;
00339         while (iter != favorites->end())
00340         {
00341             FavoritesEntry* fav = *iter;
00342 
00343             // Is this a non folder item?
00344             if (!fav->isFolder && isTopLevel(fav))
00345             {
00346                 // Append to bookmarksMenu
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 }

void DeleteBookmarkFromFavorites HWND  ,
CelestiaCore
 

Definition at line 536 of file winbookmarks.cpp.

References FavoritesEntry::isFolder, and FavoritesEntry::parentFolder.

Referenced by OrganizeBookmarksProc().

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     // Get the selected item text (which is the bookmark name)
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     // Delete the item from the tree view; give up if this fails for some
00560     // reason (it shouldn't . . .)
00561     if (!TreeView_DeleteItem(hTree, hItem))
00562         return;
00563 
00564     // Delete item in favorites, as well as all of it's children
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             // delete *iter;
00576         }
00577         else
00578         {
00579             iter++;
00580         }
00581     }
00582 }

void DragDropAutoScroll HWND   ) 
 

Definition at line 813 of file winbookmarks.cpp.

References dragPos, and hDropTargetItem.

Referenced by OrganizeBookmarksProc().

00814 {
00815     RECT rect;
00816     int i, count;
00817     HTREEITEM hItem;
00818 
00819     GetClientRect(hTree, &rect);
00820 
00821     ImageList_DragLeave(hTree);
00822 
00823     // See if we need to scroll.
00824     if (dragPos.y > rect.bottom - 10)
00825     {
00826         // If we are down towards the bottom but have not scrolled to the last
00827         // item, we need to scroll down.
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         // If we are up towards the top but have not scrolled to the first
00846         // item, we need to scroll up.
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 }

void InsertBookmarkInFavorites HWND  ,
char *  ,
CelestiaCore
 

Definition at line 498 of file winbookmarks.cpp.

References FavoritesEntry::isFolder.

Referenced by AddBookmarkProc().

00499 {
00500     FavoritesList* favorites = appCore->getFavorites();
00501     TVITEM tvItem;
00502     HTREEITEM hItem;
00503     char itemName[33];
00504     string newBookmark(name);
00505 
00506     // SyncTreeFoldersWithFavoriteFolders(hTree, appCore);
00507 
00508     // Determine which tree item (folder) is selected (if any)
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         // Folder not specified, add to end of favorites
00531         appCore->addFavorite(newBookmark, "");
00532     }
00533 }

bool isOrganizeBookmarksDragDropActive  ) 
 

Definition at line 714 of file winbookmarks.cpp.

References dragging.

Referenced by OrganizeBookmarksProc().

00715 {
00716     return dragging;
00717 }

void MoveBookmarkInFavorites HWND  ,
CelestiaCore
 

Definition at line 631 of file winbookmarks.cpp.

References hDragItem, hDropTargetItem, FavoritesEntry::parentFolder, and StdItemMask.

Referenced by OrganizeBookmarksProc().

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     // First get the target folder name
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     // Get the dragged item text
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         // Get the dragged item folder
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                 // Make sure drag and target folders are different
00678                 if (strcmp(dragItemFolderName, dropFolderName))
00679                 {
00680                     // Delete tree item from source bookmark
00681                     if (TreeView_DeleteItem(hTree, hDragItem))
00682                     {
00683                         // Add item to dest bookmark
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                             // Make the dropped item selected
00696                             TreeView_SelectItem(hTree, hDropItem);
00697 
00698                             bMovedInTree = true;
00699                         }
00700                     }
00701                 }
00702             }
00703         }
00704     }
00705 
00706     // Now perform the move in favorites
00707     if (bMovedInTree && draggedFav != NULL)
00708     {
00709         draggedFav->parentFolder = dropFolderName;
00710     }
00711 }

void OrganizeBookmarksOnBeginDrag HWND  ,
LPNMTREEVIEW 
 

Definition at line 720 of file winbookmarks.cpp.

References dragging, and hDragItem.

Referenced by OrganizeBookmarksProc().

00721 {
00722     HIMAGELIST himl;    // handle to image list
00723     RECT rcItem;        // bounding rectangle of item
00724     DWORD dwLevel;      // heading level of item
00725     DWORD dwIndent;     // amount that child items are indented
00726 
00727     //Clear any selected item
00728     TreeView_SelectItem(hTree, NULL);
00729 
00730     // Tell the tree-view control to create an image to use
00731     // for dragging.
00732     hDragItem = lpnmtv->itemNew.hItem;
00733     himl = TreeView_CreateDragImage(hTree, hDragItem);
00734 
00735     // Get the bounding rectangle of the item being dragged.
00736     TreeView_GetItemRect(hTree, hDragItem, &rcItem, TRUE);
00737 
00738     // Get the heading level and the amount that the child items are
00739     // indented.
00740     dwLevel = lpnmtv->itemNew.lParam;
00741     dwIndent = (DWORD) SendMessage(hTree, TVM_GETINDENT, 0, 0);
00742 
00743     ImageList_DragShowNolock(TRUE);
00744 
00745     // Start the drag operation.
00746     ImageList_BeginDrag(himl, 0, 7, 7);
00747 
00748     // Hide the mouse pointer, and direct mouse input to the
00749     // parent window.
00750     ShowCursor(FALSE);
00751     SetCapture(GetParent(hTree));
00752     dragging = true;
00753 }

void OrganizeBookmarksOnLButtonUp HWND   ) 
 

Definition at line 797 of file winbookmarks.cpp.

References dragging.

Referenced by OrganizeBookmarksProc().

00798 {
00799     if (dragging)
00800     {
00801         ImageList_EndDrag();
00802         ImageList_DragLeave(hTree);
00803         ReleaseCapture();
00804         ShowCursor(TRUE);
00805         dragging = false;
00806 
00807         // Remove TVIS_DROPHILITED state from drop target item
00808         TreeView_SelectDropTarget(hTree, NULL);
00809     }
00810 }

void OrganizeBookmarksOnMouseMove HWND  ,
LONG  ,
LONG 
 

Definition at line 756 of file winbookmarks.cpp.

References dragging, dragPos, hDropTargetItem, and FavoritesEntry::isFolder.

Referenced by OrganizeBookmarksProc().

00757 {
00758     TVHITTESTINFO tvht;  // hit test information
00759     TVITEM tvItem;
00760     HTREEITEM hItem;
00761 
00762     //Store away last drag position so timer can perform auto-scrolling.
00763     dragPos.x = xCur;
00764     dragPos.y = yCur;
00765 
00766     if (dragging)
00767     {
00768         // Drag the item to the current position of the mouse pointer.
00769         ImageList_DragMove(xCur, yCur);
00770         ImageList_DragLeave(hTree);
00771 
00772         // Find out if the pointer is on the item. If it is,
00773         // highlight the item as a drop target.
00774         tvht.pt.x = dragPos.x;
00775         tvht.pt.y = dragPos.y;
00776         if(hItem = TreeView_HitTest(hTree, &tvht))
00777         {
00778             // Only select folder items for drop targets
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 }

HTREEITEM PopulateBookmarkFolders HWND  ,
CelestiaCore ,
HINSTANCE 
 

Definition at line 140 of file winbookmarks.cpp.

References appInstance, IDI_CLOSEDFOLDER, IDI_OPENFOLDER, IDI_ROOTFOLDER, FavoritesEntry::isFolder, FavoritesEntry::name, and StdItemMask.

Referenced by AddBookmarkProc().

00141 {
00142     // First create an image list for the icons in the control
00143     HTREEITEM hParent=NULL;
00144     HIMAGELIST himlIcons;
00145     HICON hIcon;
00146 
00147     //Create a masked image list large enough to hold the icons. 
00148     himlIcons = ImageList_Create(16, 16, ILC_MASK, 3, 0);
00149  
00150     // Load the icon resources, and add the icons to the image list.
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     // Associate the image list with the tree-view control.
00159     TreeView_SetImageList(hTree, himlIcons, TVSIL_NORMAL);
00160 
00161     FavoritesList* favorites = appCore->getFavorites();
00162     if (favorites != NULL)
00163     {
00164         // Create a subtree item called "Bookmarks"
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                     // Create a subtree item for the folder
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             // Select "Bookmarks" folder
00199             TreeView_SelectItem(hTree, hParent);
00200         }
00201     }
00202 
00203     return hParent;
00204 }

HTREEITEM PopulateBookmarksTree HWND  ,
CelestiaCore ,
HINSTANCE 
 

Definition at line 33 of file winbookmarks.cpp.

References appInstance, dragging, IDI_BOOKMARK, IDI_CLOSEDFOLDER, IDI_OPENFOLDER, IDI_ROOTFOLDER, FavoritesEntry::isFolder, isTopLevel(), FavoritesEntry::name, FavoritesEntry::parentFolder, and StdItemMask.

Referenced by OrganizeBookmarksProc().

00034 {
00035     //First create an image list for the icons in the control
00036     HIMAGELIST himlIcons;
00037     HICON hIcon;
00038     HTREEITEM hParent=NULL, hParentItem;
00039 
00040     //Create a masked image list large enough to hold the icons. 
00041     himlIcons = ImageList_Create(16, 16, ILC_MASK, 3, 0);
00042  
00043     // Load the icon resources, and add the icons to the image list.
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     // Associate the image list with the tree-view control.
00054     TreeView_SetImageList(hTree, himlIcons, TVSIL_NORMAL);
00055 
00056     FavoritesList* favorites = appCore->getFavorites();
00057     if (favorites != NULL)
00058     {
00059         // Create a subtree item called "Bookmarks"
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                 // Is this a folder?
00078                 if (fav->isFolder)
00079                 {
00080                     // Create a subtree item
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                             // See if this entry is a child
00097                             if (!child->isFolder && child->parentFolder == fav->name)
00098                             {
00099                                 // Add items to sub tree
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                         // Expand each folder to display bookmark items
00113                         TreeView_Expand(hTree, hParentItem, TVE_EXPAND);
00114                     }
00115                 }
00116                 else if (isTopLevel(fav))
00117                 {
00118                     // Add item to root "Bookmarks"
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 }

void RenameBookmarkInFavorites HWND  ,
char *  ,
CelestiaCore
 

Definition at line 585 of file winbookmarks.cpp.

References FavoritesEntry::isFolder, FavoritesEntry::name, and FavoritesEntry::parentFolder.

Referenced by RenameBookmarkProc().

00586 {
00587     FavoritesList* favorites = appCore->getFavorites();
00588     TVITEM tvItem;
00589     HTREEITEM hItem;
00590     char itemName[33];
00591 
00592     // First get the selected item
00593     hItem = TreeView_GetSelection(hTree);
00594     if (!hItem)
00595         return;
00596 
00597     // Get the item text 
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 }

void SyncTreeFoldersWithFavoriteFolders HWND  ,
CelestiaCore
 

Definition at line 417 of file winbookmarks.cpp.

Referenced by OrganizeBookmarksProc().

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         // Scan through tree control folders and add any folder that does
00429         // not exist in Favorites.
00430         if (hParent = TreeView_GetChild(hTree, TVI_ROOT))
00431         {
00432             hItem = TreeView_GetChild(hTree, hParent);
00433             do
00434             {
00435                 // Get information on item
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                     // Skip non-folders.
00443                     if(tvItem.lParam == 0)
00444                         continue;
00445 
00446                     string name(itemName);
00447                     if (favorites->size() == 0)
00448                     {
00449                         // Just append the folder
00450                         appCore->addFavoriteFolder(name);
00451                         continue;
00452                     }
00453 
00454                     // Loop through favorites to find item = itemName
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                         // If not found in favorites, add it.
00470                         // We want all folders to appear before root items so this
00471                         // new folder must be inserted after the last item of the 
00472                         // last folder.
00473                         // Locate position of last folder.
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                         //Now iterate through items until end of folder found
00484                         folderIter++;
00485                         while (folderIter != favorites->end() && (*folderIter)->parentFolder != "")
00486                             folderIter++;
00487                         
00488                         //Insert item
00489                         appCore->addFavoriteFolder(name, &folderIter);
00490                     }
00491                 }
00492             } while (hItem = TreeView_GetNextSibling(hTree, hItem));
00493         }
00494     }
00495 }


Generated on Sat Jan 14 22:32:30 2006 for Celestia by  doxygen 1.4.1