Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

bmsgwin.cpp

Go to the documentation of this file.
00001 //**********************************************************************
00002 //                                                                     *
00003 //    Filename:      bmsgwin.cpp                                       *
00004 //    Date:          30 Mar 2002                                       *
00005 //    File Version:  1                                                 *
00006 //                                                                     *
00007 //    Description:   Window to display list of signalmen from which    *
00008 //                   the user makes a single selection.                *
00009 //                                                                     *
00010 //    Author:        Chris White (whitecf@bcs.org.uk)                  *
00011 //    Company:       Monitor Computing Services Ltd.                   *
00012 //                                                                     *
00013 //**********************************************************************
00014 //                                                                     *
00015 //    Copyright (C) 2002  Monitor Computing Services Ltd.              *
00016 //                                                                     *
00017 //    This program is free software; you can redistribute it and/or    *
00018 //    modify it under the terms of the GNU General Public License      *
00019 //    as published by the Free Software Foundation; either version 2   *
00020 //    of the License, or any later version.                            *
00021 //                                                                     *
00022 //    This program is distributed in the hope that it will be useful,  *
00023 //    but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00024 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00025 //    GNU General Public License for more details.                     *
00026 //                                                                     *
00027 //    You should have received a copy of the GNU General Public        *
00028 //    License (http://www.gnu.org/copyleft/gpl.html) along with this   *
00029 //    program; if not, write to:                                       *
00030 //       The Free Software Foundation Inc.,                            *
00031 //       59 Temple Place - Suite 330,                                  *
00032 //       Boston, MA  02111-1307,                                       *
00033 //       USA.                                                          *
00034 //                                                                     *
00035 //**********************************************************************
00036 //                                                                     *
00037 //    Notes:                                                           *
00038 //                                                                     *
00039 //**********************************************************************
00040 
00041 #define Uses_TButton
00042 #define Uses_TEvent
00043 #define Uses_TRect
00044 #define Uses_TScrollBar
00045 
00046 #include "sgnlman.h"
00047 #include "sgmlist.h"
00048 #include "mytrace.h"
00049 
00050 #include "bmsgwin.h"
00051 
00052 
00053 using namespace Monitor::BellMaster;
00054 
00055 
00056 
00057 SignalmanWindow::ListView::ListView(const SignalmanList&    newSignalmen,
00058                                     const TRect&            bounds,
00059                                     TScrollBar              *aVScrollBar) :
00060     TListViewer(bounds, 1, 0, aVScrollBar), signalmen(newSignalmen)
00061 {
00062     _USEMYTRACE_("SignalmanWindow::ListView::ListView")
00063 
00064     growMode = gfGrowHiX | gfGrowHiY;
00065     options = options | ofFramed;
00066     setRange(signalmen.size());
00067 }
00068 
00069 
00070 
00071 void
00072 SignalmanWindow::ListView::getText(char     *dest,
00073                                      short    item,
00074                                      short    maxLen)
00075 {
00076     _USEMYTRACE_("SignalmanWindow::ListView::getText")
00077 
00078     dest[0] = '\0';
00079 
00080     if ((0 <= item) && (signalmen.size() > item))
00081     {
00082         strncpy(dest, signalmen[item].getName().c_str(), maxLen);
00083         dest[maxLen] = '\0';
00084     }
00085 }
00086 
00087 
00088 
00089 SignalmanWindow::SignalmanWindow(const SignalmanList&    newSignalmen,
00090                                      TRect&                  bounds) :
00091     TDialog(bounds, "Select Signalman"),
00092     TWindowInit(&SignalmanWindow::initFrame),
00093     listView(0)
00094 {
00095     _USEMYTRACE_("SignalmanWindow::SignalmanWindow")
00096 
00097     options |= ofCentered;
00098 
00099     bounds = getExtent();
00100 
00101     TRect    scrollBarBounds(bounds.b.x - 1,
00102                              bounds.a.y + 1,
00103                              bounds.b.x,
00104                              bounds.b.y - 4);
00105 
00106     TScrollBar    *vScrollBar = new TScrollBar(scrollBarBounds);
00107 
00108     if (vScrollBar == 0)
00109     {
00110         cerr << "vScrollBar init error" << endl;
00111         exit(1);
00112     }
00113 
00114     vScrollBar->options |= ofPostProcess;
00115     insert(vScrollBar);
00116 
00117     TRect    listViewBounds(bounds.a.x + 1,
00118                             bounds.a.y + 1,
00119                             bounds.b.x - 1,
00120                             bounds.b.y - 4);
00121     listView = new ListView(newSignalmen, listViewBounds, vScrollBar);
00122 
00123     insert(listView);
00124 
00125     int    midX         = (bounds.b.x - bounds.a.x) / 2;
00126     int    buttonBottom = bounds.b.y - 1;
00127     int    buttonTop    = buttonBottom - 2;
00128 
00129     insert(new TButton(TRect(midX - 15, buttonTop, midX - 5, buttonBottom),
00130                        "~S~elect",
00131                        cmOK,
00132                        bfDefault));
00133 
00134     insert(new TButton(TRect(midX + 5, buttonTop, midX + 15, buttonBottom),
00135                        "~C~ancel",
00136                        cmCancel,
00137                        bfNormal));
00138 }
00139 
00140 
00141 
00142 void
00143 SignalmanWindow::handleEvent(TEvent&    event)
00144 {
00145     if ((event.what == evBroadcast) &&
00146         (event.message.command == cmListItemSelected))
00147     {
00148         event.what            = evCommand;
00149         event.message.command = cmOK;
00150     }
00151 
00152     TDialog::handleEvent(event);
00153 }
00154 
00155 
00156 
00157 Signalman*
00158 SignalmanWindow::getSelectedSignalman()
00159 {
00160     Signalman    *selectedSignalman = 0;
00161 
00162     if (listView)
00163     {
00164         int    codeI = listView->focused;
00165 
00166         if ((0 <= codeI) && (listView->signalmen.size() > codeI))
00167         {
00168             selectedSignalman = &(listView->signalmen[codeI]);
00169         }
00170     }
00171 
00172     return selectedSignalman;
00173 }
00174 

Generated on Wed Oct 29 20:55:43 2003 for Bellmaster BC Turbo Vision by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002