Garmin Fleet Management Controller  2.19.0
CStopListDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CStopListDlg.cpp
5 *
6 * Copyright 2008-2009 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 #include "stdafx.h"
11 #include "CFmiApplication.h"
12 #include "CStopListDlg.h"
13 #include "CStopNewDlg.h"
14 #include "Event.h"
15 
16 using namespace std;
17 
18 IMPLEMENT_DYNAMIC( CStopListDlg, CDialog )
19 
20 BEGIN_MESSAGE_MAP( CStopListDlg, CDialog )
21  ON_BN_CLICKED( IDC_STOPLIST_BTN_NEW_STOP, OnBnClickedNewStop )
22  ON_BN_CLICKED( IDOK, OnBnClickedOk )
23 #if( FMI_SUPPORT_A603 )
24  ON_MESSAGE( WM_EVENT( EVENT_FMI_STOP_STATUS_CHANGED ), OnEventStopListChanged )
25  ON_MESSAGE( WM_EVENT( EVENT_FMI_ETA_RECEIVED ), OnEventEtaReceived )
26  ON_CBN_SELCHANGE( IDC_STOPLIST_CBO_UPDATE_STOP, OnCbnSelChangeUpdateOption )
27  ON_EN_CHANGE( IDC_STOPLIST_EDIT_MOVETO, OnEnChangeMoveTo )
28  ON_BN_CLICKED( IDC_STOPLIST_BTN_SEND, OnBnClickedSend )
29 #endif
30 #if( FMI_SUPPORT_A604 )
31  ON_BN_CLICKED( IDC_STOPLIST_BTN_SORT, OnBnClickedSort )
32 #endif
33 END_MESSAGE_MAP()
34 
35 //----------------------------------------------------------------------
39 //----------------------------------------------------------------------
40 CStopListDlg::CStopListDlg
41  (
42  CWnd * aParent,
43  FmiApplicationLayer & aCom )
44  : CDialog( IDD_STOP_LIST, aParent )
45  , mCom( aCom )
46 #if( FMI_SUPPORT_A603 )
47  , mSelectedStopIndex( 0 )
48  , mSelectedStopStatus( _T("") )
49  , mSelectedUpdateIndex( 0 )
50  , mMoveTo( _T("") )
51  , mEta( _T("") )
52 #endif
53 {
54 }
55 
56 //----------------------------------------------------------------------
58 //----------------------------------------------------------------------
60 {
61 }
62 
63 //----------------------------------------------------------------------
66 //----------------------------------------------------------------------
68  (
69  CDataExchange * aDataExchange
70  )
71 {
72  CDialog::DoDataExchange( aDataExchange );
73 
74 #if( FMI_SUPPORT_A603 )
75  DDX_LBIndex( aDataExchange, IDC_STOPLIST_LST_SELECT_STOP, mSelectedStopIndex );
76  DDX_Control( aDataExchange, IDC_STOPLIST_LST_SELECT_STOP, mStopListBox );
77  DDX_Text( aDataExchange, IDC_STOPLIST_TXT_STATUS, mSelectedStopStatus );
78  DDX_CBIndex( aDataExchange, IDC_STOPLIST_CBO_UPDATE_STOP, mSelectedUpdateIndex );
79  DDX_Text( aDataExchange, IDC_STOPLIST_EDIT_MOVETO, mMoveTo );
80  DDX_Text( aDataExchange, IDC_STOPLIST_TXT_ETA, mEta );
81 #endif
82 }
83 
84 //----------------------------------------------------------------------
90 //----------------------------------------------------------------------
92 {
93  CDialog::OnInitDialog();
94 
95  SetWindowPos( NULL, 700, 35, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
96 
97 #if FMI_SUPPORT_A603
98  OnEventStopListChanged( 0, NULL );
99 #endif
100 
101 #if( !FMI_SUPPORT_A603 )
102  GetDlgItem( IDC_STOPLIST_LBL_ETA )->EnableWindow( FALSE );
103  GetDlgItem( IDC_STOPLIST_LBL_SELECT_STOP )->EnableWindow( FALSE );
104  GetDlgItem( IDC_STOPLIST_LBL_STATUS )->EnableWindow( FALSE );
105  GetDlgItem( IDC_STOPLIST_LBL_MOVETO )->EnableWindow( FALSE );
106  GetDlgItem( IDC_STOPLIST_LST_SELECT_STOP )->EnableWindow( FALSE );
107  GetDlgItem( IDC_STOPLIST_BTN_SEND )->EnableWindow( FALSE );
108  GetDlgItem( IDC_STOPLIST_GRP_UPDATE_STOP )->EnableWindow( FALSE );
109  GetDlgItem( IDC_STOPLIST_TXT_ETA )->EnableWindow( FALSE );
110  GetDlgItem( IDC_STOPLIST_TXT_STATUS )->EnableWindow( FALSE );
111  GetDlgItem( IDC_STOPLIST_EDIT_MOVETO )->EnableWindow( FALSE );
112  GetDlgItem( IDC_STOPLIST_CBO_UPDATE_STOP )->EnableWindow( FALSE );
113 #endif
114 
115 #if( !FMI_SUPPORT_A604 )
116  GetDlgItem( IDC_STOPLIST_BTN_SORT )->EnableWindow( FALSE );
117 #endif
118 
119  return TRUE;
120 } /* OnInitDialog() */
121 
122 #if( FMI_SUPPORT_A603 )
123 //----------------------------------------------------------------------
128 //----------------------------------------------------------------------
129 afx_msg LRESULT CStopListDlg::OnEventStopListChanged( WPARAM, LPARAM )
130 {
131  int i = 0;
132  if( !mCom.mStopIndexInList.empty() )
133  {
134  //must keep track of where the list was scrolled to
135  //since we reset content we must reinitialize these
136  int selectedIndex = mStopListBox.GetCurSel();
137  int topIndex = mStopListBox.GetTopIndex();
138  if( selectedIndex == -1 )
139  selectedIndex = 0;
140 
141  //reset content and then add back current stops
142  mStopListBox.ResetContent();
143  uint32 stopId = mCom.mStopIndexInList[i];
144  while( stopId != INVALID32 )
145  {
146  mStopListBox.AddString( mCom.mA603Stops.get( stopId ).getCurrentName() );
147  i++;
148  stopId = mCom.mStopIndexInList[i];
149  }
150 
151  //update data
152  UpdateData( TRUE );
153  //display status
154  if( mCom.mA603Stops.contains( mCom.mStopIndexInList[selectedIndex] ) )
155  {
156  StopListItem& item = mCom.mA603Stops.get( mCom.mStopIndexInList[selectedIndex] );
157 
158  switch( item.getStopStatus() )
159  {
160  case STOP_STATUS_ACTIVE:
161  {
162  mSelectedStopStatus.Format( _T(" Active") );
163  OnEventEtaReceived( 0, NULL );
164  }
165  break;
166  case STOP_STATUS_DONE:
167  mSelectedStopStatus.Format( _T(" Done") );
168  break;
169  case STOP_STATUS_UNREAD:
170  mSelectedStopStatus.Format( _T(" Unread Inactive") );
171  break;
172  case STOP_STATUS_READ:
173  mSelectedStopStatus.Format( _T(" Read Inactive") );
174  break;
175  case STOP_STATUS_DELETED:
176  mSelectedStopStatus.Format( _T(" Deleted") );
177  break;
178  default:
179  mSelectedStopStatus.Format( _T("") );
180  break;
181  } // end of switch
182 
183  if( item.getStopStatus() == STOP_STATUS_ACTIVE )
184  {
185  //since the stop is active the ETA should be displayed
186  GetDlgItem( IDC_STOPLIST_LBL_ETA )->ShowWindow( SW_SHOW );
187  GetDlgItem( IDC_STOPLIST_TXT_ETA )->ShowWindow( SW_SHOW );
188  }
189  else
190  {
191  //all the rest aren't active...hide ETA stuff
192  GetDlgItem( IDC_STOPLIST_LBL_ETA )->ShowWindow( SW_HIDE );
193  GetDlgItem( IDC_STOPLIST_TXT_ETA )->ShowWindow( SW_HIDE );
194  }
195  }
196  UpdateData( FALSE );
197  //reset scroll and selection
198  mStopListBox.SetCurSel( selectedIndex );
199  mStopListBox.SetTopIndex( topIndex );
200  }
201  else
202  mStopListBox.ResetContent();
203 
204  return 0;
205 } /* OnEventStopListChanged() */
206 
207 //----------------------------------------------------------------------
212 //----------------------------------------------------------------------
214 {
215  UpdateData( TRUE );
216  if( mSelectedUpdateIndex == REQUEST_MOVE_STOP )
217  {
218  GetDlgItem( IDC_STOPLIST_LBL_MOVETO )->EnableWindow( TRUE );
219  GetDlgItem( IDC_STOPLIST_EDIT_MOVETO )->EnableWindow( TRUE );
220  OnEnChangeMoveTo();
221  }
222  else
223  {
224  GetDlgItem( IDC_STOPLIST_BTN_SEND )->EnableWindow( TRUE );
225  mMoveTo.Format( _T("") );
226  GetDlgItem( IDC_STOPLIST_LBL_MOVETO )->EnableWindow( FALSE );
227  GetDlgItem( IDC_STOPLIST_EDIT_MOVETO )->EnableWindow( FALSE );
228  UpdateData( FALSE );
229  }
230 } /* OnCbnSelChangeUpdateOption() */
231 
232 //----------------------------------------------------------------------
237 //----------------------------------------------------------------------
239 {
240 #if !SKIP_VALIDATION
241  UpdateData( TRUE );
242  if( mMoveTo != "" &&
243  _ttoi( mMoveTo ) < mStopListBox.GetCount() &&
244  _ttoi( mMoveTo ) >= 0 )
245  {
246  GetDlgItem( IDC_STOPLIST_BTN_SEND )->EnableWindow( TRUE );
247  }
248  else
249  {
250  GetDlgItem( IDC_STOPLIST_BTN_SEND )->EnableWindow( FALSE );
251  }
252 #else
253  GetDlgItem( IDC_STOPLIST_BTN_SEND )->EnableWindow( TRUE );
254 #endif
255 } /* OnEnChangeMoveTo() */
256 
257 //----------------------------------------------------------------------
262 //----------------------------------------------------------------------
264 {
265  UpdateData( TRUE );
266 
267  if( mStopListBox.GetCurSel() != -1 )
268  {
269  //If the update is not a move, just send the update. Even if
270  //the stop status protocol is throttled, having an out of date
271  //status is not a major issue at this point since it can be
272  //requested by the user.
273  if( mSelectedUpdateIndex != REQUEST_MOVE_STOP )
274  {
275  uint32 selectedStopId = mCom.mStopIndexInList[mSelectedStopIndex]; //in case it gets deleted
276  mCom.sendStopStatusRequest( selectedStopId, (stop_status_status_type) mSelectedUpdateIndex, INVALID16 );
277  }
278  else
279  {
280  uint16 moveTo = (uint16)_ttoi( mMoveTo );
281  mCom.sendStopMoveRequest( moveTo, (uint16)mSelectedStopIndex );
282  }
283  }
284 } /* OnBnClickedSend() */
285 #endif
286 
287 //----------------------------------------------------------------------
290 //----------------------------------------------------------------------
292 {
293  CStopNewDlg dlg( this, mCom );
294  dlg.DoModal();
295 } /* OnBnClickedNewStop */
296 
297 #if( FMI_SUPPORT_A604 )
298 //----------------------------------------------------------------------
302 //----------------------------------------------------------------------
304 {
305  mCom.sendStopSortRequest();
306 } /* OnBnClickedSort */
307 #endif
308 
309 //----------------------------------------------------------------------
312 //----------------------------------------------------------------------
314 {
315  DestroyWindow();
316 } /* OnBnClickedOk */
317 
318 //----------------------------------------------------------------------
321 //----------------------------------------------------------------------
323 {
324  DestroyWindow();
325 } /* OnCancel() */
326 
327 //----------------------------------------------------------------------
330 //----------------------------------------------------------------------
332 {
333  CDialog::PostNcDestroy();
335 } /* PostNcDestroy() */
336 
337 #if FMI_SUPPORT_A603
338 //----------------------------------------------------------------------
343 //----------------------------------------------------------------------
344 afx_msg LRESULT CStopListDlg::OnEventEtaReceived( WPARAM, LPARAM )
345 {
346  TCHAR etaTime[13];
347 
348  MultiByteToWideChar( mCom.mClientCodepage, 0, mCom.mEtaTime, -1, etaTime, 13 );
349  etaTime[12] = '\0';
350  mEta.Format( _T(" %s"), etaTime );
351  UpdateData( FALSE );
352 
353  return 0;
354 }
355 #endif
#define INVALID16
Placeholder for an invalid 16-bit value.
Definition: fmi.h:142
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
#define IDC_STOPLIST_CBO_UPDATE_STOP
Definition: resource.h:297
#define IDC_STOPLIST_BTN_NEW_STOP
Definition: resource.h:294
afx_msg LRESULT OnEventStopListChanged(WPARAM, LPARAM)
Handler for the Stop List Changed event.
Modeless dialog allowing the user to manage the A603 stops on the client device.
Definition: CStopListDlg.h:25
#define IDC_STOPLIST_BTN_SEND
Definition: resource.h:295
afx_msg void OnBnClickedOk()
Click handler for the OK button.
BOOL OnInitDialog()
Initialize the dialog.
STL namespace.
afx_msg LRESULT OnEventEtaReceived(WPARAM, LPARAM)
Handle an ETA Received event from FmiApplicationLayer.
virtual ~CStopListDlg()
Destructor.
#define FALSE
Definition: garmin_types.h:46
afx_msg void OnCancel()
Handler for the Cancel action.
Data structure to hold details of an A603 stop that the server needs to keep.
Definition: StopListItem.h:21
#define IDC_STOPLIST_LBL_ETA
Definition: resource.h:300
#define IDC_STOPLIST_LST_SELECT_STOP
Definition: resource.h:304
#define TRUE
Definition: garmin_types.h:45
afx_msg void OnBnClickedSend()
Click handler for the Send button.
afx_msg void OnBnClickedSort()
Click handler for the Sort button.
afx_msg void OnBnClickedNewStop()
Click handler for the New Stop button.
Modal dialog allowing the user to send a new stop to the client.
Definition: CStopNewDlg.h:19
#define INVALID32
Placeholder for an invalid 32-bit value.
Definition: fmi.h:139
#define IDC_STOPLIST_BTN_SORT
Definition: resource.h:296
#define IDC_STOPLIST_GRP_UPDATE_STOP
Definition: resource.h:299
#define IDD_STOP_LIST
Definition: resource.h:36
Serial communication controller for Garmin and FMI packets.
unsigned short int uint16
16-bit unsigned integer
Definition: garmin_types.h:64
afx_msg void OnCbnSelChangeUpdateOption()
Selection Change handler for the Update Stop combo box.
#define IDC_STOPLIST_LBL_SELECT_STOP
Definition: resource.h:302
#define IDC_STOPLIST_EDIT_MOVETO
Definition: resource.h:298
#define IDC_STOPLIST_LBL_MOVETO
Definition: resource.h:301
#define IDC_STOPLIST_LBL_STATUS
Definition: resource.h:303
uint16 stop_status_status_type
Enumeration for Stop Status protocol.
Definition: fmi.h:962
afx_msg void OnEnChangeMoveTo()
Edit handler for the Move To text box.
stop_status_status_type getStopStatus() const
Get the stop status.
#define IDC_STOPLIST_TXT_ETA
Definition: resource.h:305
#define IDC_STOPLIST_TXT_STATUS
Definition: resource.h:306
void PostNcDestroy()
Perform final cleanup.
#define WM_EVENT(_event)
Translation from an application event to the corresponding Windows message.
unsigned long int uint32
32-bit unsigned integer
Definition: garmin_types.h:66
static void post(EventId aEventId, uint32 aEventData=0, void *aEventDataPtr=NULL, BOOL handleNow=FALSE)
Posts a message to all windows that have registered to get events.
Definition: Event.cpp:67