Garmin Fleet Management Controller  2.19.0
CCannedTxtMsgDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CCannedTxtMsgDlg.cpp
5 *
6 * Copyright 2008-2009 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 #include "stdafx.h"
11 #include "CCannedTxtMsgDlg.h"
12 #include "Event.h"
13 
14 using namespace std;
15 
16 IMPLEMENT_DYNAMIC( CCannedTxtMsgDlg, CDialog )
17 
18 BEGIN_MESSAGE_MAP( CCannedTxtMsgDlg, CDialog )
19  ON_BN_CLICKED( IDC_CANMSG_BTN_DELETE, OnBnClickedDelete )
20  ON_BN_CLICKED( IDC_CANMSG_BTN_SEND, OnBnClickedSend )
21  ON_BN_CLICKED( IDOK, OnBnClickedOk )
22  ON_EN_CHANGE( IDC_CANMSG_EDIT_ID, OnEnChangeEditBoxes )
23  ON_EN_CHANGE( IDC_CANMSG_EDIT_TEXT, OnEnChangeEditBoxes )
24  ON_LBN_SELCHANGE( IDC_CANMSG_LST_MESSAGES, OnLbnSelchangeMsglist )
25  ON_LBN_SETFOCUS( IDC_CANMSG_LST_MESSAGES, OnLbnSetfocusList )
26  ON_LBN_KILLFOCUS( IDC_CANMSG_LST_MESSAGES, OnLbnKillfocusMsgList )
27  ON_EN_SETFOCUS( IDC_CANMSG_EDIT_TEXT, OnEnSetfocusMessageEdit )
28  ON_EN_KILLFOCUS( IDC_CANMSG_EDIT_TEXT, OnEnKillfocusMessageEdit )
29  ON_EN_SETFOCUS( IDC_CANMSG_EDIT_ID, OnEnSetfocusMessageEdit )
30  ON_EN_KILLFOCUS( IDC_CANMSG_EDIT_ID, OnEnKillfocusMessageEdit )
31  ON_MESSAGE( WM_EVENT( EVENT_FMI_CANNED_MSG_LIST_CHANGED ), OnCannedMsgListChanged )
32 END_MESSAGE_MAP()
33 
34 //----------------------------------------------------------------------
38 //----------------------------------------------------------------------
39 CCannedTxtMsgDlg::CCannedTxtMsgDlg
40  (
41  CWnd * aParent,
42  FmiApplicationLayer & aCom
43  )
44  : CDialog( IDD_CANNED_TXT_MSG, aParent )
45  , mCom( aCom )
46  , mMessageId( _T("") )
47  , mMessageText( _T("") )
48  , mSelectedIndex( 0 )
49 {
50 }
51 
52 //----------------------------------------------------------------------
55 //----------------------------------------------------------------------
57 {
58 }
59 
60 //----------------------------------------------------------------------
63 //----------------------------------------------------------------------
65  (
66  CDataExchange * aDataExchange
67  )
68 {
69  CDialog::DoDataExchange( aDataExchange );
70  DDX_Control( aDataExchange, IDC_CANMSG_LST_MESSAGES, mCannedMessageList );
71  DDX_Text( aDataExchange, IDC_CANMSG_EDIT_ID, mMessageId );
72  DDX_Text( aDataExchange, IDC_CANMSG_EDIT_TEXT, mMessageText );
73  DDX_LBIndex( aDataExchange, IDC_CANMSG_LST_MESSAGES, mSelectedIndex );
74 }
75 
76 //----------------------------------------------------------------------
81 //----------------------------------------------------------------------
83 {
84  CDialog::OnInitDialog();
85  updateListBox();
86  SetWindowPos( NULL, 700, 625, 0, 0, SWP_NOSIZE | SWP_NOZORDER );
87  return TRUE;
88 } /* OnInitDialog() */
89 
90 //----------------------------------------------------------------------
93 //----------------------------------------------------------------------
95 {
96  CString listItem;
97 
98  //must keep track of where the list was scrolled to
99  //since we reset content we must reinitialize these
100  int selectedIndex = mCannedMessageList.GetCurSel();
101  int topIndex = mCannedMessageList.GetTopIndex();
102 
103  //reset content and add current canned messages to list
104  mCannedMessageList.ResetContent();
106 
107  for( iter = mCom.mCannedMessages.begin();
108  iter != mCom.mCannedMessages.end();
109  iter++ )
110  {
111  if( iter->second.isValid() )
112  {
113  listItem.Format( _T("%d - %s"), iter->first, iter->second.getCurrentName() );
114  mCannedMessageList.AddString( listItem );
115  }
116  }
117  //reset scroll and selection
118  mCannedMessageList.SetCurSel( selectedIndex );
119  mCannedMessageList.SetTopIndex( topIndex );
120 } /* updateListBox() */
121 
122 //----------------------------------------------------------------------
126 //----------------------------------------------------------------------
127 afx_msg LPARAM CCannedTxtMsgDlg::OnCannedMsgListChanged( WPARAM, LPARAM )
128 {
129  updateListBox();
130  return 0;
131 } /* OnCannedMsgListChanged() */
132 
133 //----------------------------------------------------------------------
137 //----------------------------------------------------------------------
139 {
140  UpdateData( TRUE );
141  if( mMessageText != "" && mMessageId != "" )
142  {
143  GetDlgItem( IDC_CANMSG_BTN_SEND )->EnableWindow( TRUE );
144  }
145  else
146  {
147  GetDlgItem( IDC_CANMSG_BTN_SEND )->EnableWindow( FALSE );
148  }
149 } /* OnEnChangeEditBoxes */
150 
151 //----------------------------------------------------------------------
156 //----------------------------------------------------------------------
158 {
159  CListBox * messageListBox = (CListBox *)GetDlgItem( IDC_CANMSG_LST_MESSAGES );
160  int selectedIndex = messageListBox->GetCurSel();
161  if( selectedIndex >= 0 && selectedIndex < messageListBox->GetCount() )
162  {
163  int index = 0;
164  CString str;
165  messageListBox->GetText( selectedIndex, str );
166  index = str.Find( _T("-"), 0 );
167  if( index > 0 )
168  {
169  TCHAR * itemBuffer = str.GetBuffer();
170  TCHAR * messageId = new TCHAR[index];
171  memcpy( messageId, itemBuffer, ( index - 1 ) * sizeof( TCHAR ) );
172  messageId[index-1] = '\0';
173  mMessageId.Format( _T("%s"), messageId );
174  int messageTextLength = str.GetLength()-index-1;
175  TCHAR * messageText = new TCHAR[messageTextLength];
176  memcpy( messageText, itemBuffer + index + 2, ( messageTextLength - 1 ) * sizeof( TCHAR ) );
177  messageText[messageTextLength - 1] = '\0';
178  mMessageText.Format( _T("%s"), messageText );
179  str.ReleaseBuffer();
180  delete[] messageId;
181  delete[] messageText;
182  UpdateData( FALSE );
183  }
184  }
185  messageListBox->SetCurSel( selectedIndex );
186 }
187 
188 //----------------------------------------------------------------------
192 //----------------------------------------------------------------------
194 {
195  UpdateData( TRUE );
196  if( mSelectedIndex >= 0 )
197  {
198  mCom.sendDeleteCannedMessageRequest( mCom.mCannedMessages.getKeyAt( mSelectedIndex ) );
199  }
200 } /* OnBnClickedDelete() */
201 
202 //----------------------------------------------------------------------
207 //----------------------------------------------------------------------
209 {
210  UpdateData( TRUE );
211  uint32 messageId = _ttoi( mMessageId.GetBuffer() );
212 
213  mCom.sendCannedMessage( messageId, mMessageText );
214 } /* OnBnClickedSend() */
215 
216 //----------------------------------------------------------------------
219 //----------------------------------------------------------------------
221 {
222  DestroyWindow();
223 } /* OnBnClickedOk () */
224 
225 //----------------------------------------------------------------------
228 //----------------------------------------------------------------------
230 {
231  DestroyWindow();
232 } /* OnCancel() */
233 
234 //----------------------------------------------------------------------
243 //----------------------------------------------------------------------
245 {
247  CDialog::PostNcDestroy();
248 } /* PostNcDestroy() */
249 
250 //----------------------------------------------------------------------
255 //----------------------------------------------------------------------
257 {
258  SendMessage( DM_SETDEFID, IDC_CANMSG_BTN_SEND );
259 } /* OnEnSetfocusMessageEdit */
260 
261 //----------------------------------------------------------------------
266 //----------------------------------------------------------------------
268 {
269  SendMessage( DM_SETDEFID, IDOK );
270 } /* OnEnKillfocusMessageEdit */
271 
272 //----------------------------------------------------------------------
276 //----------------------------------------------------------------------
278 {
279  SendMessage( DM_SETDEFID, IDC_CANMSG_BTN_DELETE );
280 } /* OnLbnSetfocusList */
281 
282 //----------------------------------------------------------------------
286 //----------------------------------------------------------------------
288 {
289  SendMessage( DM_SETDEFID, IDOK );
290 } /* OnLbnKillfocusList */
void updateListBox()
Update the canned message list box from the canned message map owned by FmiApplicationLayer.
afx_msg void OnEnSetfocusMessageEdit()
Handles the set focus event for the Message ID and Message Text edit boxes.
afx_msg void OnLbnSetfocusList()
Handles the set focus event for the Message List box.
#define IDC_CANMSG_BTN_SEND
Definition: resource.h:154
afx_msg void OnLbnKillfocusMsgList()
Handles the kill focus event for the Message list box.
const_iterator begin()
Iterator positioned at the first element in the map.
Definition: FileBackedMap.h:59
#define IDC_CANMSG_LST_MESSAGES
Definition: resource.h:162
afx_msg void OnBnClickedOk()
Button handler for the OK button.
afx_msg void OnCancel()
Handler for the Cancel action.
Dialog allowing the user to manage the list of canned messages on the client.
STL namespace.
#define IDC_CANMSG_EDIT_TEXT
Definition: resource.h:156
afx_msg void OnEnChangeEditBoxes()
Edit handler for the Message ID and Message Text boxes.
afx_msg void OnBnClickedDelete()
Handles the Delete button clicked event.
const_iterator end()
Iterator positioned after the last element in the map.
Definition: FileBackedMap.h:67
void PostNcDestroy()
Called by MFC after the window has been destroyed; performs final termination activities.
#define FALSE
Definition: garmin_types.h:46
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
afx_msg void OnLbnSelchangeMsglist()
Selection Changed handler for the Message List box.
#define TRUE
Definition: garmin_types.h:45
afx_msg LPARAM OnCannedMsgListChanged(WPARAM, LPARAM)
Handler for the FMI_EVENT_CANNED_MSG_LIST_CHANGED event.
Serial communication controller for Garmin and FMI packets.
BOOL OnInitDialog()
Initialize the dialog.
afx_msg void OnEnKillfocusMessageEdit()
Handles the kill focus event for the Message ID and Message Text edit boxes.
Map whose contents are also saved to a file.
Definition: FileBackedMap.h:32
#define IDC_CANMSG_EDIT_ID
Definition: resource.h:155
#define IDC_CANMSG_BTN_DELETE
Definition: resource.h:153
#define WM_EVENT(_event)
Translation from an application event to the corresponding Windows message.
#define IDD_CANNED_TXT_MSG
Definition: resource.h:22
afx_msg void OnBnClickedSend()
Button handler for the Send button.
unsigned long int uint32
32-bit unsigned integer
Definition: garmin_types.h:66
virtual ~CCannedTxtMsgDlg()
[Brief description of the method]
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