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

winssbrowser.cpp File Reference

#include <string>
#include <sstream>
#include <algorithm>
#include <set>
#include <windows.h>
#include <commctrl.h>
#include "winssbrowser.h"
#include "res/resource.h"

Include dependency graph for winssbrowser.cpp:

Go to the source code of this file.

Functions

HTREEITEM AddItemToTree (HWND hwndTV, LPSTR lpszItem, int nLevel, void *data, HTREEITEM parent)
void AddPlanetarySystemToTree (const PlanetarySystem *sys, HWND treeView, int level, HTREEITEM parent)
BOOL APIENTRY SolarSystemBrowserProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)


Function Documentation

HTREEITEM AddItemToTree HWND  hwndTV,
LPSTR  lpszItem,
int  nLevel,
void *  data,
HTREEITEM  parent
 

Definition at line 25 of file winssbrowser.cpp.

Referenced by AddPlanetarySystemToTree(), and SolarSystemBrowserProc().

00027 { 
00028     TVITEM tvi; 
00029     TVINSERTSTRUCT tvins; 
00030     static HTREEITEM hPrev = (HTREEITEM) TVI_FIRST; 
00031 
00032 #if 0 
00033     tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; 
00034 #endif
00035     tvi.mask = TVIF_TEXT | TVIF_PARAM;
00036  
00037     // Set the text of the item. 
00038     tvi.pszText = lpszItem; 
00039     tvi.cchTextMax = lstrlen(lpszItem); 
00040  
00041     // Save the heading level in the item's application-defined 
00042     // data area. 
00043     tvi.lParam = (LPARAM) data; 
00044  
00045     tvins.item = tvi; 
00046     tvins.hInsertAfter = hPrev; 
00047     tvins.hParent = parent;
00048  
00049     // Add the item to the tree view control. 
00050     hPrev = (HTREEITEM) SendMessage(hwndTV, TVM_INSERTITEM, 0, 
00051                                     (LPARAM) (LPTVINSERTSTRUCT) &tvins); 
00052  
00053 #if 0 
00054     // The new item is a child item. Give the parent item a 
00055     // closed folder bitmap to indicate it now has child items. 
00056     if (nLevel > 1)
00057     { 
00058         hti = TreeView_GetParent(hwndTV, hPrev); 
00059         tvi.mask = TVIF_IMAGE | TVIF_SELECTEDIMAGE; 
00060         tvi.hItem = hti; 
00061         // tvi.iImage = g_nClosed; 
00062         // tvi.iSelectedImage = g_nClosed; 
00063         TreeView_SetItem(hwndTV, &tvi); 
00064     }
00065 #endif 
00066  
00067     return hPrev; 
00068 }

void AddPlanetarySystemToTree const PlanetarySystem sys,
HWND  treeView,
int  level,
HTREEITEM  parent
 

Definition at line 71 of file winssbrowser.cpp.

References AddItemToTree(), Body::getName(), and Body::getSatellites().

Referenced by SolarSystemBrowserProc().

00072 {
00073     for (int i = 0; i < sys->getSystemSize(); i++)
00074     {
00075         Body* world = sys->getBody(i);
00076         HTREEITEM item;
00077         item = AddItemToTree(treeView, 
00078                              const_cast<char*>(world->getName().c_str()),
00079                              level,
00080                              static_cast<void*>(world),
00081                              parent);
00082 
00083         const PlanetarySystem* satellites = world->getSatellites();
00084         if (satellites != NULL)
00085             AddPlanetarySystemToTree(satellites, treeView, level + 1, item);
00086     }
00087 }

BOOL APIENTRY SolarSystemBrowserProc HWND  hDlg,
UINT  message,
UINT  wParam,
LONG  lParam
 

Definition at line 90 of file winssbrowser.cpp.

References AddItemToTree(), AddPlanetarySystemToTree(), SolarSystemBrowser::appCore, BOOL(), CelestiaCore::charEntered(), Simulation::getNearestSolarSystem(), SolarSystem::getPlanets(), CelestiaCore::getSimulation(), SolarSystem::getStar(), IDC_BUTTON_CENTER, IDC_BUTTON_GOTO, IDC_SSBROWSER_TREE, SolarSystemBrowser::parent, and Simulation::setSelection().

Referenced by SolarSystemBrowser::SolarSystemBrowser().

00094 {
00095     SolarSystemBrowser* browser = reinterpret_cast<SolarSystemBrowser*>(GetWindowLong(hDlg, DWL_USER));
00096 
00097     switch (message)
00098     {
00099     case WM_INITDIALOG:
00100         {
00101             SolarSystemBrowser* browser = reinterpret_cast<SolarSystemBrowser*>(lParam);
00102             if (browser == NULL)
00103                 return EndDialog(hDlg, 0);
00104             SetWindowLong(hDlg, DWL_USER, lParam);
00105 
00106             HWND hwnd = GetDlgItem(hDlg, IDC_SSBROWSER_TREE);
00107             const SolarSystem* solarSys = browser->appCore->getSimulation()->getNearestSolarSystem();
00108             if (solarSys != NULL)
00109             {
00110                 HTREEITEM rootItem = AddItemToTree(hwnd, "Sun", 1, NULL,
00111                                                    (HTREEITEM) TVI_ROOT);
00112                 const PlanetarySystem* planets = solarSys->getPlanets();
00113                 if (planets != NULL)
00114                     AddPlanetarySystemToTree(planets, hwnd, 2, rootItem);
00115 
00116                 SendMessage(hwnd, TVM_EXPAND, TVE_EXPAND, (LPARAM) rootItem); 
00117             }
00118         }
00119         return(TRUE);
00120 
00121     case WM_DESTROY:
00122         if (browser != NULL && browser->parent != NULL)
00123         {
00124             SendMessage(browser->parent, WM_COMMAND, IDCLOSE,
00125                         reinterpret_cast<LPARAM>(browser));
00126         }
00127         break;
00128 
00129     case WM_COMMAND:
00130         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
00131         {
00132             if (browser != NULL && browser->parent != NULL)
00133             {
00134                 SendMessage(browser->parent, WM_COMMAND, IDCLOSE,
00135                             reinterpret_cast<LPARAM>(browser));
00136             }
00137             EndDialog(hDlg, 0);
00138             return TRUE;
00139         }
00140         else if (LOWORD(wParam) == IDC_BUTTON_CENTER)
00141         {
00142             browser->appCore->charEntered('c');
00143         }
00144         else if (LOWORD(wParam) == IDC_BUTTON_GOTO)
00145         {
00146             browser->appCore->charEntered('G');
00147         }
00148         break;
00149 
00150     case WM_NOTIFY:
00151         {
00152             LPNMHDR hdr = (LPNMHDR) lParam;
00153             
00154             if (hdr->code == TVN_SELCHANGED)
00155             {
00156                 LPNMTREEVIEW nm = (LPNMTREEVIEW) lParam;
00157                 Body* body = reinterpret_cast<Body*>(nm->itemNew.lParam);
00158                 if (body != NULL)
00159                 {
00160                     browser->appCore->getSimulation()->setSelection(Selection(body));
00161                 }
00162                 else
00163                 {
00164                     // If the body is NULL, assume that this is the tree item for
00165                     // the sun.
00166                     const SolarSystem* solarSys = browser->appCore->getSimulation()->getNearestSolarSystem();
00167                     if (solarSys != NULL && solarSys->getStar() != NULL)
00168                         browser->appCore->getSimulation()->setSelection(Selection(const_cast<Star*>(solarSys->getStar())));
00169                 }
00170             }
00171         }
00172     }
00173 
00174     return FALSE;
00175 }


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