root/apps/windows_mobile/trunk/PocketPC/TelnicPlugin/Plugin/TelnicMain/FriendsList.cpp
@
706
| Revision 706, 6.6 kB (checked in by nadya, 3 years ago) |
|---|
| Line | |
|---|---|
| 1 | /* |
| 2 | * Copyright (c) 2008, Telnic Ltd. |
| 3 | * All rights reserved. |
| 4 | * Redistribution and use in source and binary forms, with or without modification, |
| 5 | * are permitted provided that the following conditions are met: |
| 6 | * Redistributions of source code must retain the above copyright notice, |
| 7 | * this list of conditions and the following disclaimer. |
| 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and |
| 9 | * the following disclaimer in the documentation and/or other materials provided with the distribution. |
| 10 | * Neither the name of the Telnic Ltd. nor the names of its contributors may be used to endorse or promote |
| 11 | * products derived from this software without specific prior written permission. |
| 12 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED |
| 13 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 14 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 15 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED |
| 16 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 17 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 18 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 19 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 20 | */ |
| 21 | /* |
| 22 | * Filename: FriendsList.cpp |
| 23 | * Description: |
| 24 | * Implementation of the friends list dialog |
| 25 | */ |
| 26 | |
| 27 | #include "stdafx.h" |
| 28 | #include "FriendsList.h" |
| 29 | #include "IDs.h" |
| 30 | |
| 31 | |
| 32 | // CFriendsList dialog |
| 33 | |
| 34 | IMPLEMENT_DYNAMIC(CFriendsList, CDialog) |
| 35 | |
| 36 | /* |
| 37 | * Constructor |
| 38 | */ |
| 39 | CFriendsList::CFriendsList(CWnd* pParent /*=NULL*/) |
| 40 | : CDialog(CFriendsList::IDD, pParent) |
| 41 | , m_TitleVal(_T("")) |
| 42 | , PublishList(NULL) |
| 43 | { |
| 44 | |
| 45 | } |
| 46 | |
| 47 | /* |
| 48 | * destructor |
| 49 | */ |
| 50 | CFriendsList::~CFriendsList() |
| 51 | { |
| 52 | delete[] PublishList; |
| 53 | } |
| 54 | |
| 55 | /* |
| 56 | * Data exchange handler |
| 57 | */ |
| 58 | void CFriendsList::DoDataExchange(CDataExchange* pDX) |
| 59 | { |
| 60 | CDialog::DoDataExchange(pDX); |
| 61 | DDX_Control(pDX, IDC_FRIENDSLIST, m_friendslist); |
| 62 | DDX_Control(pDX, IDC_FRIENDS_TITLE, m_TitleText); |
| 63 | DDX_Text(pDX, IDC_FRIENDS_TITLE, m_TitleVal); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | /* |
| 68 | * Message mapping |
| 69 | */ |
| 70 | BEGIN_MESSAGE_MAP(CFriendsList, CDialog) |
| 71 | ON_COMMAND(IDM_FRIENDS_CANCEL, &CFriendsList::OnFriendsCancel) |
| 72 | ON_COMMAND(IDM_FRIENDS_CANCEL_OUTSIDE, &CFriendsList::OnFriendsCancelOutside) |
| 73 | ON_WM_SIZE() |
| 74 | ON_NOTIFY(NM_CLICK, IDC_FRIENDSLIST, &CFriendsList::OnNMClickFriendslist) |
| 75 | ON_NOTIFY(LVN_ITEMACTIVATE, IDC_FRIENDSLIST, &CFriendsList::OnLvnItemActivateFriendslist) |
| 76 | END_MESSAGE_MAP() |
| 77 | |
| 78 | |
| 79 | // CFriendsList message handlers |
| 80 | |
| 81 | /* |
| 82 | * message handler initdialog |
| 83 | */ |
| 84 | BOOL CFriendsList::OnInitDialog() |
| 85 | { |
| 86 | HCURSOR hPrevCursor; |
| 87 | |
| 88 | hPrevCursor = SetCursor(LoadCursor(NULL,IDC_WAIT)); |
| 89 | |
| 90 | CDialog::OnInitDialog(); |
| 91 | TelnicRegData RegTel; |
| 92 | CRect rtList; |
| 93 | int nodeCount; |
| 94 | |
| 95 | //Getting the client rect and setting the list columns |
| 96 | m_friendslist.GetClientRect(rtList); |
| 97 | |
| 98 | LV_COLUMN lvC; // list view column structure |
| 99 | |
| 100 | lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; |
| 101 | lvC.fmt = LVCFMT_LEFT; // left-align column |
| 102 | lvC.cx = rtList.Width()-13; // width of column in pixels |
| 103 | lvC.pszText = L""; |
| 104 | m_friendslist.InsertColumn(0, &lvC); |
| 105 | |
| 106 | //Loading the imagelist |
| 107 | LoadImageList(); |
| 108 | |
| 109 | //Setting the imagelist to the list |
| 110 | m_friendslist.SetImageList(&m_imgList,LVSIL_SMALL); |
| 111 | |
| 112 | //getting the login username |
| 113 | domainName = RegTel.GetTelnicId(); |
| 114 | |
| 115 | //SOAP call to retrieve the publisher list and loading the list |
| 116 | PublishList = TelnicSoap::GetInstance().GetPublisherList(nodeCount); |
| 117 | LoadList(PublishList,nodeCount); |
| 118 | |
| 119 | //Creating the menus |
| 120 | SHMENUBARINFO info; |
| 121 | info.cbSize = sizeof(info); |
| 122 | info.hwndParent = m_hWnd; |
| 123 | info.dwFlags = SHCMBF_HMENU; |
| 124 | info.nToolBarId = IDR_MENU2; |
| 125 | info.hInstRes = ::AfxGetInstanceHandle(); |
| 126 | info.nBmpId = 0; |
| 127 | info.cBmpImages = 0; |
| 128 | SHCreateMenuBar(&info); |
| 129 | |
| 130 | //Setting the title |
| 131 | CString title = CString(ID_TEXT_TITLE_FRIEND_PAGE); |
| 132 | title.Append(domainName); |
| 133 | title.Append(ID_TEXT_TITLE_TEL); |
| 134 | this->SetDlgItemTextW(IDC_FRIENDS_TITLE,title); |
| 135 | |
| 136 | SetCursor(hPrevCursor); |
| 137 | |
| 138 | return TRUE; // return TRUE unless you set the focus to a control |
| 139 | |
| 140 | } |
| 141 | /* |
| 142 | * Message handler when clicked on cancel |
| 143 | */ |
| 144 | void CFriendsList::OnFriendsCancel() |
| 145 | { |
| 146 | this->EndDialog(0); |
| 147 | } |
| 148 | /* |
| 149 | * message handler when trying to exit from outside |
| 150 | */ |
| 151 | void CFriendsList::OnFriendsCancelOutside() |
| 152 | { |
| 153 | this->EndDialog(3); |
| 154 | } |
| 155 | /* |
| 156 | * Message handler when size changes |
| 157 | */ |
| 158 | void CFriendsList::OnSize(UINT nType, int cx, int cy) |
| 159 | { |
| 160 | |
| 161 | CRect rect; |
| 162 | |
| 163 | CDialog::OnSize(nType, cx, cy); |
| 164 | |
| 165 | this->GetWindowRect(rect); |
| 166 | rect.left += 9; |
| 167 | rect.top += 10; |
| 168 | rect.right -= 10; |
| 169 | rect.bottom -= 30; |
| 170 | //Dynamically resizing the list control and the column width |
| 171 | m_friendslist.MoveWindow(rect,TRUE); |
| 172 | m_friendslist.SetColumnWidth(0,rect.right-rect.left-15); |
| 173 | |
| 174 | //Setting the title |
| 175 | CString title = CString(ID_TEXT_TITLE_FRIEND_PAGE); |
| 176 | title.Append(domainName); |
| 177 | title.Append(ID_TEXT_TITLE_TEL); |
| 178 | this->SetDlgItemTextW(IDC_FRIENDS_TITLE,title); |
| 179 | |
| 180 | |
| 181 | } |
| 182 | /* |
| 183 | * Message handler destroy window |
| 184 | */ |
| 185 | BOOL CFriendsList::DestroyWindow() |
| 186 | { |
| 187 | return CDialog::DestroyWindow(); |
| 188 | } |
| 189 | /* |
| 190 | * This method will load the lsit with all the publisher details |
| 191 | * |
| 192 | * @param publishList pointer to the arry of publisher list |
| 193 | * @param count itemcount in the array |
| 194 | */ |
| 195 | void CFriendsList::LoadList(XmlNode *publishList,int count) |
| 196 | { |
| 197 | CString item; |
| 198 | for(int i = 0; i < count; i++) |
| 199 | { |
| 200 | item = CString(publishList[i].Node1); |
| 201 | m_friendslist.InsertItem(i,item.GetString(),0); |
| 202 | } |
| 203 | } |
| 204 | /* |
| 205 | * This method will load the .tel icon in the imagelist |
| 206 | */ |
| 207 | void CFriendsList::LoadImageList() |
| 208 | { |
| 209 | m_imgList.Create(16, 16, ILC_COLOR16 | ILC_MASK, 5, 1); |
| 210 | m_imgList.Add(AfxGetApp()->LoadIcon(IDI_TEL16)); |
| 211 | } |
| 212 | /* |
| 213 | * Message handler when clicked an item in the list |
| 214 | */ |
| 215 | void CFriendsList::OnNMClickFriendslist(NMHDR *pNMHDR, LRESULT *pResult) |
| 216 | { |
| 217 | //Getting the selection mark |
| 218 | int pos = m_friendslist.GetSelectionMark(); |
| 219 | |
| 220 | if(pos != -1)//check for valid |
| 221 | { |
| 222 | selfriends = CString(PublishList[pos].Node2); |
| 223 | selfriends.Append(ID_DELIMIT_FRIENDSEL); |
| 224 | selfriends.Append(CString(PublishList[pos].Node1)); |
| 225 | this->EndDialog(2); |
| 226 | } |
| 227 | *pResult = 0; |
| 228 | } |
| 229 | /* |
| 230 | * message handler when selects an item using hardware button |
| 231 | */ |
| 232 | void CFriendsList::OnLvnItemActivateFriendslist(NMHDR *pNMHDR, LRESULT *pResult) |
| 233 | { |
| 234 | //Getting the selected item position |
| 235 | int pos = m_friendslist.GetSelectionMark(); |
| 236 | |
| 237 | if(pos != -1) //check for valid |
| 238 | { |
| 239 | selfriends = CString(PublishList[pos].Node2); |
| 240 | selfriends.Append(ID_DELIMIT_FRIENDSEL); |
| 241 | selfriends.Append(CString(PublishList[pos].Node1)); |
| 242 | this->EndDialog(2); |
| 243 | } |
| 244 | *pResult = 0; |
| 245 | } |
| 246 | //End-- |
Note: See TracBrowser
for help on using the browser.








