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

wintourguide.cpp File Reference

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

Include dependency graph for wintourguide.cpp:

Go to the source code of this file.

Functions

BOOL APIENTRY TourGuideProc (HWND hDlg, UINT message, UINT wParam, LONG lParam)


Function Documentation

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

Definition at line 25 of file wintourguide.cpp.

References TourGuide::appCore, BOOL(), Destination::description, Destination::distance, Selection::empty(), Simulation::findObjectFromPath(), Simulation::follow(), CelestiaCore::getDestinations(), CelestiaCore::getSimulation(), Simulation::gotoSelection(), IDC_BUTTON_GOTO, IDC_COMBO_TOURGUIDE, IDC_TEXT_DESCRIPTION, Destination::name, TourGuide::parent, TourGuide::selectedDest, Simulation::setSelection(), and Destination::target.

Referenced by TourGuide::TourGuide().

00029 {
00030     TourGuide* tourGuide = reinterpret_cast<TourGuide*>(GetWindowLong(hDlg, DWL_USER));
00031 
00032     switch (message)
00033     {
00034     case WM_INITDIALOG:
00035         {
00036             TourGuide* guide = reinterpret_cast<TourGuide*>(lParam);
00037             if (guide == NULL)
00038                 return EndDialog(hDlg, 0);
00039             SetWindowLong(hDlg, DWL_USER, lParam);
00040 
00041             guide->selectedDest = NULL;
00042 
00043             HWND hwnd = GetDlgItem(hDlg, IDC_COMBO_TOURGUIDE);
00044             const DestinationList* destinations = guide->appCore->getDestinations();
00045             if (hwnd != NULL && destinations != NULL)
00046             {
00047                 for (DestinationList::const_iterator iter = destinations->begin();
00048                      iter != destinations->end(); iter++)
00049                 {
00050                     Destination* dest = *iter;
00051                     if (dest != NULL)
00052                     {
00053                         SendMessage(hwnd, CB_INSERTSTRING, -1,
00054                                     reinterpret_cast<LPARAM>(dest->name.c_str()));
00055                     }
00056                 }
00057 
00058                 if (destinations->size() > 0)
00059                 {
00060                     SendMessage(hwnd, CB_SETCURSEL, 0, 0);
00061                     SetDlgItemText(hDlg,
00062                                    IDC_TEXT_DESCRIPTION,
00063                                    (*destinations)[0]->description.c_str());
00064                 }
00065             }
00066         }
00067         return(TRUE);
00068 
00069     case WM_DESTROY:
00070         if (tourGuide != NULL && tourGuide->parent != NULL)
00071         {
00072             SendMessage(tourGuide->parent, WM_COMMAND, IDCLOSE,
00073                         reinterpret_cast<LPARAM>(tourGuide));
00074         }
00075         break;
00076 
00077     case WM_COMMAND:
00078         if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
00079         {
00080             if (tourGuide != NULL && tourGuide->parent != NULL)
00081             {
00082                 SendMessage(tourGuide->parent, WM_COMMAND, IDCLOSE,
00083                             reinterpret_cast<LPARAM>(tourGuide));
00084             }
00085             EndDialog(hDlg, 0);
00086             return TRUE;
00087         }
00088         else if (LOWORD(wParam) == IDC_BUTTON_GOTO)
00089         {
00090             Simulation* sim = tourGuide->appCore->getSimulation();
00091             if (tourGuide->selectedDest != NULL && sim != NULL)
00092             {
00093                 Selection sel = sim->findObjectFromPath(tourGuide->selectedDest->target);
00094                 if (!sel.empty())
00095                 {
00096                     sim->follow();
00097                     sim->setSelection(sel);
00098                     if (tourGuide->selectedDest->distance <= 0)
00099                     {
00100                         // Use the default distance
00101                         sim->gotoSelection(5.0,
00102                                            Vec3f(0, 1, 0),
00103                                            astro::ObserverLocal);
00104                     }
00105                     else
00106                     {
00107                         sim->gotoSelection(5.0,
00108                                            tourGuide->selectedDest->distance,
00109                                            Vec3f(0, 1, 0),
00110                                            astro::ObserverLocal);
00111                     }
00112                 }
00113             }
00114         }
00115         else if (LOWORD(wParam) == IDC_COMBO_TOURGUIDE)
00116         {
00117             if (HIWORD(wParam) == CBN_SELCHANGE)
00118             {
00119                 HWND hwnd = reinterpret_cast<HWND>(lParam);
00120                 int item = SendMessage(hwnd, CB_GETCURSEL, 0, 0);
00121                 const DestinationList* destinations = tourGuide->appCore->getDestinations();
00122                 if (item != CB_ERR && item < destinations->size())
00123                 {
00124                     Destination* dest = (*destinations)[item];
00125                     SetDlgItemText(hDlg,
00126                                    IDC_TEXT_DESCRIPTION,
00127                                    dest->description.c_str());
00128                     tourGuide->selectedDest = dest;
00129                 }
00130             }
00131         }
00132         break;
00133     }
00134 
00135     return FALSE;
00136 }


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