Garmin Fleet Management Controller  2.19.0
CSelectCannedResponseDlg.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 *
3 * MODULE NAME:
4 * CSelectCannedResponseDlg.cpp
5 *
6 * Copyright 2008-2009 by Garmin Ltd. or its subsidiaries.
7 *---------------------------------------------------------------------
8 * $NoKeywords$
9 *********************************************************************/
10 
11 #include "stdafx.h"
12 #include "CFmiApplication.h"
14 
15 using namespace std;
16 
17 IMPLEMENT_DYNAMIC( CSelectCannedResponseDlg, CDialog )
18 
19 BEGIN_MESSAGE_MAP( CSelectCannedResponseDlg, CDialog )
20  ON_BN_CLICKED( IDOK, OnBnClickedOk )
21 END_MESSAGE_MAP()
22 
23 //----------------------------------------------------------------------
32 //----------------------------------------------------------------------
33 CSelectCannedResponseDlg::CSelectCannedResponseDlg
34  (
35  const MessageId & aMessageId,
36  char * aMessageText,
37  uint8 aMessageType,
38  CWnd * aParent,
39  FmiApplicationLayer & aCom
40  )
41  : CDialog( IDD_CANNED_RESPONSE_SELECT, aParent )
42  , mCom( aCom )
43  , mMessageId( aMessageId )
44 {
45  strcpy( mMessageText, aMessageText );
46  mMessageType = aMessageType;
47 }
48 
49 //----------------------------------------------------------------------
51 //----------------------------------------------------------------------
53 {
54 }
55 
56 //----------------------------------------------------------------------
59 //----------------------------------------------------------------------
61  (
62  CDataExchange * aDataExchange
63  )
64 {
65  CDialog::DoDataExchange( aDataExchange );
66  DDX_Control( aDataExchange, IDC_RESPSEL_LST_RESPONSES, mListBox );
67 }
68 
69 //----------------------------------------------------------------------
74 //----------------------------------------------------------------------
76 {
77  CDialog::OnInitDialog();
78 
79  CString listItem;
80 
81  FileBackedMap<ClientListItem>::const_iterator iter = mCom.mCannedResponses.begin();
82  for( ; iter != mCom.mCannedResponses.end(); iter++ )
83  {
84  if( iter->second.isValid() )
85  {
86  listItem.Format( _T("%d - %s"), iter->first, iter->second.getCurrentName() );
87  mListBox.AddString( listItem );
88  }
89  }
90  return TRUE;
91 } /* OnInitDialog() */
92 
93 //----------------------------------------------------------------------
97 //----------------------------------------------------------------------
99 {
100  UpdateData( TRUE );
101  uint32 * selectedResponseIds = new uint32[ mListBox.GetSelCount() ];
102  uint8 selectedIdCount = 0;
103  for( int i = 0; i < mListBox.GetCount(); i++ )
104  {
105  if( mListBox.GetSel( i ) > 0 )
106  {
107  selectedResponseIds[selectedIdCount++] = mCom.mCannedResponses.getKeyAt( i );
108  }
109  }
110 
111  bool success = mCom.sendCannedResponseTextMessage
112  (
113  mMessageText,
114  mMessageId,
115  selectedIdCount,
116  selectedResponseIds,
117  mMessageType
118  );
119 
120  delete [] selectedResponseIds;
121 
122  if( success )
123  {
124  OnOK();
125  }
126  else
127  {
128  MessageBox
129  (
130  _T("A long text message is already in progress. Wait until it has completed before sending another."),
131  _T("Message Already in Progress"), MB_OK
132  );
133  }
134 } /* OnBnClickedOk() */
virtual ~CSelectCannedResponseDlg()
Destructor.
#define IDD_CANNED_RESPONSE_SELECT
Definition: resource.h:20
const_iterator begin()
Iterator positioned at the first element in the map.
Definition: FileBackedMap.h:59
#define IDC_RESPSEL_LST_RESPONSES
Definition: resource.h:290
STL namespace.
const_iterator end()
Iterator positioned after the last element in the map.
Definition: FileBackedMap.h:67
#define TRUE
Definition: garmin_types.h:45
Dialog allowing the user to select the canned responses that are allowed for a particular message...
BOOL OnInitDialog()
This function is called when the window is created.
Serial communication controller for Garmin and FMI packets.
virtual void DoDataExchange(CDataExchange *aDataExchange)
Perform dialog data exchange and validation.
Map whose contents are also saved to a file.
Definition: FileBackedMap.h:32
unsigned char uint8
8-bit unsigned integer
Definition: garmin_types.h:62
afx_msg void OnBnClickedOk()
OK button handler.
unsigned long int uint32
32-bit unsigned integer
Definition: garmin_types.h:66
Encapsulation of a message ID.
Definition: MessageId.h:26