| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "xfa/fwl/basewidget/fwl_comboboximp.h" | |
| 8 | |
| 9 #include "xfa/fde/cfde_txtedtengine.h" | |
| 10 #include "xfa/fde/tto/fde_textout.h" | |
| 11 #include "xfa/fwl/basewidget/fwl_editimp.h" | |
| 12 #include "xfa/fwl/basewidget/fwl_formproxyimp.h" | |
| 13 #include "xfa/fwl/basewidget/fwl_listboximp.h" | |
| 14 #include "xfa/fwl/basewidget/fwl_scrollbarimp.h" | |
| 15 #include "xfa/fwl/core/cfwl_message.h" | |
| 16 #include "xfa/fwl/core/cfwl_themebackground.h" | |
| 17 #include "xfa/fwl/core/cfwl_themepart.h" | |
| 18 #include "xfa/fwl/core/cfwl_themetext.h" | |
| 19 #include "xfa/fwl/core/cfwl_widgetmgr.h" | |
| 20 #include "xfa/fwl/core/fwl_formimp.h" | |
| 21 #include "xfa/fwl/core/fwl_noteimp.h" | |
| 22 #include "xfa/fwl/core/fwl_widgetimp.h" | |
| 23 #include "xfa/fwl/core/ifwl_app.h" | |
| 24 #include "xfa/fwl/core/ifwl_themeprovider.h" | |
| 25 | |
| 26 // static | |
| 27 IFWL_ComboBox* IFWL_ComboBox::Create( | |
| 28 const CFWL_WidgetImpProperties& properties) { | |
| 29 IFWL_ComboBox* pComboBox = new IFWL_ComboBox; | |
| 30 CFWL_ComboBoxImp* pComboBoxImpl = new CFWL_ComboBoxImp(properties, nullptr); | |
| 31 pComboBox->SetImpl(pComboBoxImpl); | |
| 32 pComboBoxImpl->SetInterface(pComboBox); | |
| 33 return pComboBox; | |
| 34 } | |
| 35 IFWL_ComboBox::IFWL_ComboBox() {} | |
| 36 int32_t IFWL_ComboBox::GetCurSel() { | |
| 37 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->GetCurSel(); | |
| 38 } | |
| 39 FWL_Error IFWL_ComboBox::SetCurSel(int32_t iSel) { | |
| 40 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->SetCurSel(iSel); | |
| 41 } | |
| 42 FWL_Error IFWL_ComboBox::SetEditText(const CFX_WideString& wsText) { | |
| 43 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->SetEditText(wsText); | |
| 44 } | |
| 45 int32_t IFWL_ComboBox::GetEditTextLength() const { | |
| 46 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->GetEditTextLength(); | |
| 47 } | |
| 48 FWL_Error IFWL_ComboBox::GetEditText(CFX_WideString& wsText, | |
| 49 int32_t nStart, | |
| 50 int32_t nCount) const { | |
| 51 return static_cast<CFWL_ComboBoxImp*>(GetImpl()) | |
| 52 ->GetEditText(wsText, nStart, nCount); | |
| 53 } | |
| 54 FWL_Error IFWL_ComboBox::SetEditSelRange(int32_t nStart, int32_t nCount) { | |
| 55 return static_cast<CFWL_ComboBoxImp*>(GetImpl()) | |
| 56 ->SetEditSelRange(nStart, nCount); | |
| 57 } | |
| 58 int32_t IFWL_ComboBox::GetEditSelRange(int32_t nIndex, int32_t& nStart) { | |
| 59 return static_cast<CFWL_ComboBoxImp*>(GetImpl()) | |
| 60 ->GetEditSelRange(nIndex, nStart); | |
| 61 } | |
| 62 int32_t IFWL_ComboBox::GetEditLimit() { | |
| 63 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->GetEditLimit(); | |
| 64 } | |
| 65 FWL_Error IFWL_ComboBox::SetEditLimit(int32_t nLimit) { | |
| 66 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->SetEditLimit(nLimit); | |
| 67 } | |
| 68 FWL_Error IFWL_ComboBox::EditDoClipboard(int32_t iCmd) { | |
| 69 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditDoClipboard(iCmd); | |
| 70 } | |
| 71 FX_BOOL IFWL_ComboBox::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { | |
| 72 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditRedo(pRecord); | |
| 73 } | |
| 74 FX_BOOL IFWL_ComboBox::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { | |
| 75 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditUndo(pRecord); | |
| 76 } | |
| 77 IFWL_ListBox* IFWL_ComboBox::GetListBoxt() { | |
| 78 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->GetListBoxt(); | |
| 79 } | |
| 80 FX_BOOL IFWL_ComboBox::AfterFocusShowDropList() { | |
| 81 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->AfterFocusShowDropList(); | |
| 82 } | |
| 83 FWL_Error IFWL_ComboBox::OpenDropDownList(FX_BOOL bActivate) { | |
| 84 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->OpenDropDownList(bActivate); | |
| 85 } | |
| 86 FX_BOOL IFWL_ComboBox::EditCanUndo() { | |
| 87 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditCanUndo(); | |
| 88 } | |
| 89 FX_BOOL IFWL_ComboBox::EditCanRedo() { | |
| 90 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditCanRedo(); | |
| 91 } | |
| 92 FX_BOOL IFWL_ComboBox::EditUndo() { | |
| 93 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditUndo(); | |
| 94 } | |
| 95 FX_BOOL IFWL_ComboBox::EditRedo() { | |
| 96 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditRedo(); | |
| 97 } | |
| 98 FX_BOOL IFWL_ComboBox::EditCanCopy() { | |
| 99 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditCanCopy(); | |
| 100 } | |
| 101 FX_BOOL IFWL_ComboBox::EditCanCut() { | |
| 102 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditCanCut(); | |
| 103 } | |
| 104 FX_BOOL IFWL_ComboBox::EditCanSelectAll() { | |
| 105 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditCanSelectAll(); | |
| 106 } | |
| 107 FX_BOOL IFWL_ComboBox::EditCopy(CFX_WideString& wsCopy) { | |
| 108 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditCopy(wsCopy); | |
| 109 } | |
| 110 FX_BOOL IFWL_ComboBox::EditCut(CFX_WideString& wsCut) { | |
| 111 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditCut(wsCut); | |
| 112 } | |
| 113 FX_BOOL IFWL_ComboBox::EditPaste(const CFX_WideString& wsPaste) { | |
| 114 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditPaste(wsPaste); | |
| 115 } | |
| 116 FX_BOOL IFWL_ComboBox::EditSelectAll() { | |
| 117 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditSelectAll(); | |
| 118 } | |
| 119 FX_BOOL IFWL_ComboBox::EditDelete() { | |
| 120 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditDelete(); | |
| 121 } | |
| 122 FX_BOOL IFWL_ComboBox::EditDeSelect() { | |
| 123 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->EditDeSelect(); | |
| 124 } | |
| 125 FWL_Error IFWL_ComboBox::GetBBox(CFX_RectF& rect) { | |
| 126 return static_cast<CFWL_ComboBoxImp*>(GetImpl())->GetBBox(rect); | |
| 127 } | |
| 128 FWL_Error IFWL_ComboBox::EditModifyStylesEx(uint32_t dwStylesExAdded, | |
| 129 uint32_t dwStylesExRemoved) { | |
| 130 return static_cast<CFWL_ComboBoxImp*>(GetImpl()) | |
| 131 ->EditModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
| 132 } | |
| 133 | |
| 134 CFWL_ComboEditImp::CFWL_ComboEditImp(const CFWL_WidgetImpProperties& properties, | |
| 135 IFWL_Widget* pOuter) | |
| 136 : CFWL_EditImp(properties, pOuter) { | |
| 137 m_pOuter = static_cast<CFWL_ComboBoxImp*>(pOuter->GetImpl()); | |
| 138 } | |
| 139 | |
| 140 CFWL_ComboEditImpDelegate::CFWL_ComboEditImpDelegate(CFWL_ComboEditImp* pOwner) | |
| 141 : CFWL_EditImpDelegate(pOwner), m_pOwner(pOwner) {} | |
| 142 | |
| 143 void CFWL_ComboEditImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 144 if (!pMessage) | |
| 145 return; | |
| 146 | |
| 147 FX_BOOL backDefault = TRUE; | |
| 148 switch (pMessage->GetClassID()) { | |
| 149 case CFWL_MessageType::SetFocus: { | |
| 150 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | |
| 151 backDefault = FALSE; | |
| 152 break; | |
| 153 } | |
| 154 case CFWL_MessageType::KillFocus: { | |
| 155 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | |
| 156 backDefault = FALSE; | |
| 157 break; | |
| 158 } | |
| 159 case CFWL_MessageType::Mouse: { | |
| 160 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 161 if ((pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) && | |
| 162 ((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)) { | |
| 163 m_pOwner->SetSelected(); | |
| 164 m_pOwner->SetComboBoxFocus(TRUE); | |
| 165 } | |
| 166 break; | |
| 167 } | |
| 168 default: | |
| 169 break; | |
| 170 } | |
| 171 if (backDefault) | |
| 172 CFWL_EditImpDelegate::OnProcessMessage(pMessage); | |
| 173 } | |
| 174 | |
| 175 void CFWL_ComboEditImp::ClearSelected() { | |
| 176 ClearSelections(); | |
| 177 Repaint(&m_rtClient); | |
| 178 } | |
| 179 void CFWL_ComboEditImp::SetSelected() { | |
| 180 FlagFocus(TRUE); | |
| 181 EndCaret(); | |
| 182 AddSelRange(0); | |
| 183 } | |
| 184 void CFWL_ComboEditImp::EndCaret() { | |
| 185 m_pEdtEngine->MoveCaretPos(MC_End); | |
| 186 } | |
| 187 void CFWL_ComboEditImp::FlagFocus(FX_BOOL bSet) { | |
| 188 if (bSet) { | |
| 189 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | |
| 190 } else { | |
| 191 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | |
| 192 ShowCaret(FALSE); | |
| 193 } | |
| 194 } | |
| 195 void CFWL_ComboEditImp::SetComboBoxFocus(FX_BOOL bSet) { | |
| 196 m_pOuter->SetFocus(bSet); | |
| 197 } | |
| 198 CFWL_ComboListImp::CFWL_ComboListImp(const CFWL_WidgetImpProperties& properties, | |
| 199 IFWL_Widget* pOuter) | |
| 200 : CFWL_ListBoxImp(properties, pOuter), m_bNotifyOwner(TRUE) { | |
| 201 ASSERT(pOuter); | |
| 202 } | |
| 203 FWL_Error CFWL_ComboListImp::Initialize() { | |
| 204 if (CFWL_ListBoxImp::Initialize() != FWL_Error::Succeeded) | |
| 205 return FWL_Error::Indefinite; | |
| 206 delete m_pDelegate; | |
| 207 m_pDelegate = new CFWL_ComboListImpDelegate(this); | |
| 208 return FWL_Error::Succeeded; | |
| 209 } | |
| 210 FWL_Error CFWL_ComboListImp::Finalize() { | |
| 211 delete m_pDelegate; | |
| 212 m_pDelegate = nullptr; | |
| 213 return CFWL_ListBoxImp::Finalize(); | |
| 214 } | |
| 215 int32_t CFWL_ComboListImp::MatchItem(const CFX_WideString& wsMatch) { | |
| 216 if (wsMatch.IsEmpty()) { | |
| 217 return -1; | |
| 218 } | |
| 219 if (!m_pProperties->m_pDataProvider) | |
| 220 return -1; | |
| 221 IFWL_ListBoxDP* pData = | |
| 222 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | |
| 223 int32_t iCount = pData->CountItems(m_pInterface); | |
| 224 for (int32_t i = 0; i < iCount; i++) { | |
| 225 IFWL_ListItem* hItem = pData->GetItem(m_pInterface, i); | |
| 226 CFX_WideString wsText; | |
| 227 pData->GetItemText(m_pInterface, hItem, wsText); | |
| 228 FX_STRSIZE pos = wsText.Find(wsMatch.c_str()); | |
| 229 if (!pos) { | |
| 230 return i; | |
| 231 } | |
| 232 } | |
| 233 return -1; | |
| 234 } | |
| 235 void CFWL_ComboListImp::ChangeSelected(int32_t iSel) { | |
| 236 if (!m_pProperties->m_pDataProvider) | |
| 237 return; | |
| 238 IFWL_ListBoxDP* pData = | |
| 239 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | |
| 240 IFWL_ListItem* hItem = pData->GetItem(m_pInterface, iSel); | |
| 241 CFX_RectF rtInvalidate; | |
| 242 rtInvalidate.Reset(); | |
| 243 IFWL_ListItem* hOld = GetSelItem(0); | |
| 244 int32_t iOld = pData->GetItemIndex(m_pInterface, hOld); | |
| 245 if (iOld == iSel) { | |
| 246 return; | |
| 247 } else if (iOld > -1) { | |
| 248 GetItemRect(iOld, rtInvalidate); | |
| 249 SetSelItem(hOld, FALSE); | |
| 250 } | |
| 251 if (hItem) { | |
| 252 CFX_RectF rect; | |
| 253 GetItemRect(iSel, rect); | |
| 254 rtInvalidate.Union(rect); | |
| 255 IFWL_ListItem* hSel = pData->GetItem(m_pInterface, iSel); | |
| 256 SetSelItem(hSel, TRUE); | |
| 257 } | |
| 258 if (!rtInvalidate.IsEmpty()) { | |
| 259 Repaint(&rtInvalidate); | |
| 260 } | |
| 261 } | |
| 262 int32_t CFWL_ComboListImp::CountItems() { | |
| 263 IFWL_ListBoxDP* pData = | |
| 264 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | |
| 265 return pData ? pData->CountItems(m_pInterface) : 0; | |
| 266 } | |
| 267 void CFWL_ComboListImp::GetItemRect(int32_t nIndex, CFX_RectF& rtItem) { | |
| 268 IFWL_ListBoxDP* pData = | |
| 269 static_cast<IFWL_ListBoxDP*>(m_pProperties->m_pDataProvider); | |
| 270 IFWL_ListItem* hItem = pData->GetItem(m_pInterface, nIndex); | |
| 271 pData->GetItemRect(m_pInterface, hItem, rtItem); | |
| 272 } | |
| 273 void CFWL_ComboListImp::ClientToOuter(FX_FLOAT& fx, FX_FLOAT& fy) { | |
| 274 fx += m_pProperties->m_rtWidget.left, fy += m_pProperties->m_rtWidget.top; | |
| 275 IFWL_Widget* pOwner = GetOwner(); | |
| 276 if (!pOwner) | |
| 277 return; | |
| 278 pOwner->TransformTo(m_pOuter, fx, fy); | |
| 279 } | |
| 280 void CFWL_ComboListImp::SetFocus(FX_BOOL bSet) { | |
| 281 CFWL_WidgetImp::SetFocus(bSet); | |
| 282 } | |
| 283 | |
| 284 CFWL_ComboListImpDelegate::CFWL_ComboListImpDelegate(CFWL_ComboListImp* pOwner) | |
| 285 : CFWL_ListBoxImpDelegate(pOwner), m_pOwner(pOwner) {} | |
| 286 | |
| 287 void CFWL_ComboListImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 288 if (!pMessage) | |
| 289 return; | |
| 290 | |
| 291 CFWL_MessageType dwHashCode = pMessage->GetClassID(); | |
| 292 FX_BOOL backDefault = TRUE; | |
| 293 if (dwHashCode == CFWL_MessageType::SetFocus || | |
| 294 dwHashCode == CFWL_MessageType::KillFocus) { | |
| 295 OnDropListFocusChanged(pMessage, dwHashCode == CFWL_MessageType::SetFocus); | |
| 296 } else if (dwHashCode == CFWL_MessageType::Mouse) { | |
| 297 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 298 if (m_pOwner->IsShowScrollBar(TRUE) && m_pOwner->m_pVertScrollBar) { | |
| 299 CFX_RectF rect; | |
| 300 m_pOwner->m_pVertScrollBar->GetWidgetRect(rect); | |
| 301 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 302 pMsg->m_fx -= rect.left; | |
| 303 pMsg->m_fy -= rect.top; | |
| 304 IFWL_WidgetDelegate* pDelegate = | |
| 305 m_pOwner->m_pVertScrollBar->SetDelegate(nullptr); | |
| 306 pDelegate->OnProcessMessage(pMsg); | |
| 307 return; | |
| 308 } | |
| 309 } | |
| 310 switch (pMsg->m_dwCmd) { | |
| 311 case FWL_MouseCommand::Move: { | |
| 312 backDefault = FALSE; | |
| 313 OnDropListMouseMove(pMsg); | |
| 314 break; | |
| 315 } | |
| 316 case FWL_MouseCommand::LeftButtonDown: { | |
| 317 backDefault = FALSE; | |
| 318 OnDropListLButtonDown(pMsg); | |
| 319 break; | |
| 320 } | |
| 321 case FWL_MouseCommand::LeftButtonUp: { | |
| 322 backDefault = FALSE; | |
| 323 OnDropListLButtonUp(pMsg); | |
| 324 break; | |
| 325 } | |
| 326 default: | |
| 327 break; | |
| 328 } | |
| 329 } else if (dwHashCode == CFWL_MessageType::Key) { | |
| 330 backDefault = !OnDropListKey(static_cast<CFWL_MsgKey*>(pMessage)); | |
| 331 } | |
| 332 if (backDefault) | |
| 333 CFWL_ListBoxImpDelegate::OnProcessMessage(pMessage); | |
| 334 } | |
| 335 | |
| 336 void CFWL_ComboListImpDelegate::OnDropListFocusChanged(CFWL_Message* pMsg, | |
| 337 FX_BOOL bSet) { | |
| 338 if (!bSet) { | |
| 339 CFWL_MsgKillFocus* pKill = static_cast<CFWL_MsgKillFocus*>(pMsg); | |
| 340 CFWL_ComboBoxImp* pOuter = | |
| 341 static_cast<CFWL_ComboBoxImp*>(m_pOwner->m_pOuter->GetImpl()); | |
| 342 if (pKill->m_pSetFocus == m_pOwner->m_pOuter || | |
| 343 pKill->m_pSetFocus == pOuter->m_pEdit.get()) { | |
| 344 pOuter->ShowDropList(FALSE); | |
| 345 } | |
| 346 } | |
| 347 } | |
| 348 int32_t CFWL_ComboListImpDelegate::OnDropListMouseMove(CFWL_MsgMouse* pMsg) { | |
| 349 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 350 if (m_pOwner->m_bNotifyOwner) { | |
| 351 m_pOwner->m_bNotifyOwner = FALSE; | |
| 352 } | |
| 353 if (m_pOwner->IsShowScrollBar(TRUE) && m_pOwner->m_pVertScrollBar) { | |
| 354 CFX_RectF rect; | |
| 355 m_pOwner->m_pVertScrollBar->GetWidgetRect(rect); | |
| 356 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 357 return 1; | |
| 358 } | |
| 359 } | |
| 360 IFWL_ListItem* hItem = m_pOwner->GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | |
| 361 if (hItem) { | |
| 362 if (!m_pOwner->m_pProperties->m_pDataProvider) | |
| 363 return 0; | |
| 364 IFWL_ListBoxDP* pData = static_cast<IFWL_ListBoxDP*>( | |
| 365 m_pOwner->m_pProperties->m_pDataProvider); | |
| 366 int32_t iSel = pData->GetItemIndex(m_pOwner->m_pInterface, hItem); | |
| 367 CFWL_EvtCmbHoverChanged event; | |
| 368 event.m_pSrcTarget = m_pOwner->m_pOuter; | |
| 369 event.m_iCurHover = iSel; | |
| 370 m_pOwner->DispatchEvent(&event); | |
| 371 m_pOwner->ChangeSelected(iSel); | |
| 372 } | |
| 373 } else if (m_pOwner->m_bNotifyOwner) { | |
| 374 m_pOwner->ClientToOuter(pMsg->m_fx, pMsg->m_fy); | |
| 375 CFWL_ComboBoxImp* pOuter = | |
| 376 static_cast<CFWL_ComboBoxImp*>(m_pOwner->m_pOuter->GetImpl()); | |
| 377 pOuter->m_pDelegate->OnProcessMessage(pMsg); | |
| 378 } | |
| 379 return 1; | |
| 380 } | |
| 381 int32_t CFWL_ComboListImpDelegate::OnDropListLButtonDown(CFWL_MsgMouse* pMsg) { | |
| 382 if (m_pOwner->m_rtClient.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 383 return 0; | |
| 384 } | |
| 385 CFWL_ComboBoxImp* pOuter = | |
| 386 static_cast<CFWL_ComboBoxImp*>(m_pOwner->m_pOuter->GetImpl()); | |
| 387 pOuter->ShowDropList(FALSE); | |
| 388 return 1; | |
| 389 } | |
| 390 int32_t CFWL_ComboListImpDelegate::OnDropListLButtonUp(CFWL_MsgMouse* pMsg) { | |
| 391 CFWL_ComboBoxImp* pOuter = | |
| 392 static_cast<CFWL_ComboBoxImp*>(m_pOwner->m_pOuter->GetImpl()); | |
| 393 if (m_pOwner->m_bNotifyOwner) { | |
| 394 m_pOwner->ClientToOuter(pMsg->m_fx, pMsg->m_fy); | |
| 395 pOuter->m_pDelegate->OnProcessMessage(pMsg); | |
| 396 } else { | |
| 397 if (m_pOwner->IsShowScrollBar(TRUE) && m_pOwner->m_pVertScrollBar) { | |
| 398 CFX_RectF rect; | |
| 399 m_pOwner->m_pVertScrollBar->GetWidgetRect(rect); | |
| 400 if (rect.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 401 return 1; | |
| 402 } | |
| 403 } | |
| 404 pOuter->ShowDropList(FALSE); | |
| 405 IFWL_ListItem* hItem = m_pOwner->GetItemAtPoint(pMsg->m_fx, pMsg->m_fy); | |
| 406 if (hItem) { | |
| 407 pOuter->ProcessSelChanged(TRUE); | |
| 408 } | |
| 409 } | |
| 410 return 1; | |
| 411 } | |
| 412 int32_t CFWL_ComboListImpDelegate::OnDropListKey(CFWL_MsgKey* pKey) { | |
| 413 CFWL_ComboBoxImp* pOuter = | |
| 414 static_cast<CFWL_ComboBoxImp*>(m_pOwner->m_pOuter->GetImpl()); | |
| 415 FX_BOOL bPropagate = FALSE; | |
| 416 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { | |
| 417 uint32_t dwKeyCode = pKey->m_dwKeyCode; | |
| 418 switch (dwKeyCode) { | |
| 419 case FWL_VKEY_Return: | |
| 420 case FWL_VKEY_Escape: { | |
| 421 pOuter->ShowDropList(FALSE); | |
| 422 return 1; | |
| 423 } | |
| 424 case FWL_VKEY_Up: | |
| 425 case FWL_VKEY_Down: { | |
| 426 OnDropListKeyDown(pKey); | |
| 427 pOuter->SetDelegate(nullptr); | |
| 428 pOuter->ProcessSelChanged(FALSE); | |
| 429 return 1; | |
| 430 } | |
| 431 default: { bPropagate = TRUE; } | |
| 432 } | |
| 433 } else if (pKey->m_dwCmd == FWL_KeyCommand::Char) { | |
| 434 bPropagate = TRUE; | |
| 435 } | |
| 436 if (bPropagate) { | |
| 437 pKey->m_pDstTarget = m_pOwner->m_pOuter; | |
| 438 pOuter->m_pDelegate->OnProcessMessage(pKey); | |
| 439 return 1; | |
| 440 } | |
| 441 return 0; | |
| 442 } | |
| 443 void CFWL_ComboListImpDelegate::OnDropListKeyDown(CFWL_MsgKey* pKey) { | |
| 444 uint32_t dwKeyCode = pKey->m_dwKeyCode; | |
| 445 switch (dwKeyCode) { | |
| 446 case FWL_VKEY_Up: | |
| 447 case FWL_VKEY_Down: | |
| 448 case FWL_VKEY_Home: | |
| 449 case FWL_VKEY_End: { | |
| 450 CFWL_ComboBoxImp* pOuter = | |
| 451 static_cast<CFWL_ComboBoxImp*>(m_pOwner->m_pOuter->GetImpl()); | |
| 452 IFWL_ListBoxDP* pData = static_cast<IFWL_ListBoxDP*>( | |
| 453 m_pOwner->m_pProperties->m_pDataProvider); | |
| 454 IFWL_ListItem* hItem = | |
| 455 pData->GetItem(m_pOwner->m_pInterface, pOuter->m_iCurSel); | |
| 456 hItem = m_pOwner->GetItem(hItem, dwKeyCode); | |
| 457 if (!hItem) { | |
| 458 break; | |
| 459 } | |
| 460 m_pOwner->SetSelection(hItem, hItem, TRUE); | |
| 461 m_pOwner->ScrollToVisible(hItem); | |
| 462 CFX_RectF rtInvalidate; | |
| 463 rtInvalidate.Set(0, 0, m_pOwner->m_pProperties->m_rtWidget.width, | |
| 464 m_pOwner->m_pProperties->m_rtWidget.height); | |
| 465 m_pOwner->Repaint(&rtInvalidate); | |
| 466 break; | |
| 467 } | |
| 468 default: {} | |
| 469 } | |
| 470 } | |
| 471 CFWL_ComboBoxImp::CFWL_ComboBoxImp(const CFWL_WidgetImpProperties& properties, | |
| 472 IFWL_Widget* pOuter) | |
| 473 : CFWL_WidgetImp(properties, pOuter), | |
| 474 m_pForm(nullptr), | |
| 475 m_bLButtonDown(FALSE), | |
| 476 m_iCurSel(-1), | |
| 477 m_iBtnState(CFWL_PartState_Normal), | |
| 478 m_fComboFormHandler(0), | |
| 479 m_bNeedShowList(FALSE) { | |
| 480 m_rtClient.Reset(); | |
| 481 m_rtBtn.Reset(); | |
| 482 m_rtHandler.Reset(); | |
| 483 } | |
| 484 | |
| 485 CFWL_ComboBoxImp::~CFWL_ComboBoxImp() {} | |
| 486 | |
| 487 FWL_Error CFWL_ComboBoxImp::GetClassName(CFX_WideString& wsClass) const { | |
| 488 wsClass = FWL_CLASS_ComboBox; | |
| 489 return FWL_Error::Succeeded; | |
| 490 } | |
| 491 | |
| 492 FWL_Type CFWL_ComboBoxImp::GetClassID() const { | |
| 493 return FWL_Type::ComboBox; | |
| 494 } | |
| 495 | |
| 496 FWL_Error CFWL_ComboBoxImp::Initialize() { | |
| 497 if (m_pWidgetMgr->IsFormDisabled()) | |
| 498 return DisForm_Initialize(); | |
| 499 | |
| 500 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) | |
| 501 return FWL_Error::Indefinite; | |
| 502 | |
| 503 m_pDelegate = new CFWL_ComboBoxImpDelegate(this); | |
| 504 CFWL_WidgetImpProperties prop; | |
| 505 prop.m_pThemeProvider = m_pProperties->m_pThemeProvider; | |
| 506 prop.m_dwStyles |= FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; | |
| 507 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemIconText) | |
| 508 prop.m_dwStyleExes |= FWL_STYLEEXT_LTB_Icon; | |
| 509 | |
| 510 prop.m_pDataProvider = m_pProperties->m_pDataProvider; | |
| 511 m_pListBox.reset(IFWL_ListBox::CreateComboList(prop, m_pInterface)); | |
| 512 m_pListBox->Initialize(); | |
| 513 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown) && !m_pEdit) { | |
| 514 CFWL_WidgetImpProperties prop2; | |
| 515 m_pEdit.reset(IFWL_Edit::CreateComboEdit(prop2, m_pInterface)); | |
| 516 m_pEdit->Initialize(); | |
| 517 static_cast<CFWL_EditImp*>(m_pEdit->GetImpl())->SetOuter(m_pInterface); | |
| 518 } | |
| 519 if (m_pEdit) | |
| 520 m_pEdit->SetParent(m_pInterface); | |
| 521 | |
| 522 SetStates(m_pProperties->m_dwStates); | |
| 523 return FWL_Error::Succeeded; | |
| 524 } | |
| 525 | |
| 526 FWL_Error CFWL_ComboBoxImp::Finalize() { | |
| 527 if (m_pEdit) { | |
| 528 m_pEdit->Finalize(); | |
| 529 } | |
| 530 m_pListBox->Finalize(); | |
| 531 delete m_pDelegate; | |
| 532 m_pDelegate = nullptr; | |
| 533 return CFWL_WidgetImp::Finalize(); | |
| 534 } | |
| 535 FWL_Error CFWL_ComboBoxImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) { | |
| 536 if (bAutoSize) { | |
| 537 rect.Reset(); | |
| 538 FX_BOOL bIsDropDown = IsDropDownStyle(); | |
| 539 if (bIsDropDown && m_pEdit) { | |
| 540 m_pEdit->GetWidgetRect(rect, TRUE); | |
| 541 } else { | |
| 542 rect.width = 100; | |
| 543 rect.height = 16; | |
| 544 } | |
| 545 if (!m_pProperties->m_pThemeProvider) { | |
| 546 ReSetTheme(); | |
| 547 } | |
| 548 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | |
| 549 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | |
| 550 if (!pFWidth) | |
| 551 return FWL_Error::Indefinite; | |
| 552 rect.Inflate(0, 0, *pFWidth, 0); | |
| 553 CFWL_WidgetImp::GetWidgetRect(rect, TRUE); | |
| 554 } else { | |
| 555 rect = m_pProperties->m_rtWidget; | |
| 556 } | |
| 557 return FWL_Error::Succeeded; | |
| 558 } | |
| 559 FWL_Error CFWL_ComboBoxImp::ModifyStylesEx(uint32_t dwStylesExAdded, | |
| 560 uint32_t dwStylesExRemoved) { | |
| 561 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 562 return DisForm_ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
| 563 } | |
| 564 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); | |
| 565 bool bRemoveDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); | |
| 566 if (bAddDropDown && !m_pEdit) { | |
| 567 CFWL_WidgetImpProperties prop; | |
| 568 m_pEdit.reset(IFWL_Edit::CreateComboEdit(prop, nullptr)); | |
| 569 m_pEdit->Initialize(); | |
| 570 static_cast<CFWL_EditImp*>(m_pEdit->GetImpl())->SetOuter(m_pInterface); | |
| 571 m_pEdit->SetParent(m_pInterface); | |
| 572 } else if (bRemoveDropDown && m_pEdit) { | |
| 573 m_pEdit->SetStates(FWL_WGTSTATE_Invisible, TRUE); | |
| 574 } | |
| 575 return CFWL_WidgetImp::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
| 576 } | |
| 577 FWL_Error CFWL_ComboBoxImp::Update() { | |
| 578 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 579 return DisForm_Update(); | |
| 580 } | |
| 581 if (IsLocked()) { | |
| 582 return FWL_Error::Indefinite; | |
| 583 } | |
| 584 ReSetTheme(); | |
| 585 FX_BOOL bDropDown = IsDropDownStyle(); | |
| 586 if (bDropDown && m_pEdit) { | |
| 587 ReSetEditAlignment(); | |
| 588 } | |
| 589 if (!m_pProperties->m_pThemeProvider) { | |
| 590 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | |
| 591 } | |
| 592 Layout(); | |
| 593 CFWL_ThemePart part; | |
| 594 part.m_pWidget = m_pInterface; | |
| 595 m_fComboFormHandler = | |
| 596 *static_cast<FX_FLOAT*>(m_pProperties->m_pThemeProvider->GetCapacity( | |
| 597 &part, CFWL_WidgetCapacity::ComboFormHandler)); | |
| 598 return FWL_Error::Succeeded; | |
| 599 } | |
| 600 FWL_WidgetHit CFWL_ComboBoxImp::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | |
| 601 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 602 return DisForm_HitTest(fx, fy); | |
| 603 } | |
| 604 return CFWL_WidgetImp::HitTest(fx, fy); | |
| 605 } | |
| 606 FWL_Error CFWL_ComboBoxImp::DrawWidget(CFX_Graphics* pGraphics, | |
| 607 const CFX_Matrix* pMatrix) { | |
| 608 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 609 return DisForm_DrawWidget(pGraphics, pMatrix); | |
| 610 } | |
| 611 if (!pGraphics) | |
| 612 return FWL_Error::Indefinite; | |
| 613 if (!m_pProperties->m_pThemeProvider) | |
| 614 return FWL_Error::Indefinite; | |
| 615 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
| 616 FX_BOOL bIsDropDown = IsDropDownStyle(); | |
| 617 if (HasBorder()) { | |
| 618 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | |
| 619 } | |
| 620 if (HasEdge()) { | |
| 621 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | |
| 622 } | |
| 623 if (!bIsDropDown) { | |
| 624 CFX_RectF rtTextBk(m_rtClient); | |
| 625 rtTextBk.width -= m_rtBtn.width; | |
| 626 CFWL_ThemeBackground param; | |
| 627 param.m_pWidget = m_pInterface; | |
| 628 param.m_iPart = CFWL_Part::Background; | |
| 629 param.m_pGraphics = pGraphics; | |
| 630 if (pMatrix) { | |
| 631 param.m_matrix.Concat(*pMatrix); | |
| 632 } | |
| 633 param.m_rtPart = rtTextBk; | |
| 634 if (m_iCurSel >= 0) { | |
| 635 IFWL_ListBoxDP* pData = static_cast<IFWL_ListBoxDP*>( | |
| 636 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl()) | |
| 637 ->m_pProperties->m_pDataProvider); | |
| 638 void* p = pData->GetItemData(m_pListBox.get(), | |
| 639 pData->GetItem(m_pListBox.get(), m_iCurSel)); | |
| 640 if (p) { | |
| 641 param.m_pData = p; | |
| 642 } | |
| 643 } | |
| 644 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | |
| 645 param.m_dwStates = CFWL_PartState_Disabled; | |
| 646 } else if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && | |
| 647 (m_iCurSel >= 0)) { | |
| 648 param.m_dwStates = CFWL_PartState_Selected; | |
| 649 } else { | |
| 650 param.m_dwStates = CFWL_PartState_Normal; | |
| 651 } | |
| 652 pTheme->DrawBackground(¶m); | |
| 653 if (m_iCurSel >= 0) { | |
| 654 if (!m_pListBox) | |
| 655 return FWL_Error::Indefinite; | |
| 656 CFX_WideString wsText; | |
| 657 IFWL_ComboBoxDP* pData = | |
| 658 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | |
| 659 IFWL_ListItem* hItem = pData->GetItem(m_pInterface, m_iCurSel); | |
| 660 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl()) | |
| 661 ->GetItemText(hItem, wsText); | |
| 662 CFWL_ThemeText theme_text; | |
| 663 theme_text.m_pWidget = m_pInterface; | |
| 664 theme_text.m_iPart = CFWL_Part::Caption; | |
| 665 theme_text.m_dwStates = m_iBtnState; | |
| 666 theme_text.m_pGraphics = pGraphics; | |
| 667 theme_text.m_matrix.Concat(*pMatrix); | |
| 668 theme_text.m_rtPart = rtTextBk; | |
| 669 theme_text.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) | |
| 670 ? CFWL_PartState_Selected | |
| 671 : CFWL_PartState_Normal; | |
| 672 theme_text.m_wsText = wsText; | |
| 673 theme_text.m_dwTTOStyles = FDE_TTOSTYLE_SingleLine; | |
| 674 theme_text.m_iTTOAlign = FDE_TTOALIGNMENT_CenterLeft; | |
| 675 pTheme->DrawText(&theme_text); | |
| 676 } | |
| 677 } | |
| 678 { | |
| 679 CFWL_ThemeBackground param; | |
| 680 param.m_pWidget = m_pInterface; | |
| 681 param.m_iPart = CFWL_Part::DropDownButton; | |
| 682 param.m_dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | |
| 683 ? CFWL_PartState_Disabled | |
| 684 : m_iBtnState; | |
| 685 param.m_pGraphics = pGraphics; | |
| 686 param.m_matrix.Concat(*pMatrix); | |
| 687 param.m_rtPart = m_rtBtn; | |
| 688 pTheme->DrawBackground(¶m); | |
| 689 } | |
| 690 return FWL_Error::Succeeded; | |
| 691 } | |
| 692 FWL_Error CFWL_ComboBoxImp::SetThemeProvider( | |
| 693 IFWL_ThemeProvider* pThemeProvider) { | |
| 694 if (!pThemeProvider) | |
| 695 return FWL_Error::Indefinite; | |
| 696 m_pProperties->m_pThemeProvider = pThemeProvider; | |
| 697 if (m_pListBox) | |
| 698 m_pListBox->SetThemeProvider(pThemeProvider); | |
| 699 if (m_pEdit) | |
| 700 m_pEdit->SetThemeProvider(pThemeProvider); | |
| 701 return FWL_Error::Succeeded; | |
| 702 } | |
| 703 int32_t CFWL_ComboBoxImp::GetCurSel() { | |
| 704 return m_iCurSel; | |
| 705 } | |
| 706 FWL_Error CFWL_ComboBoxImp::SetCurSel(int32_t iSel) { | |
| 707 int32_t iCount = | |
| 708 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl())->CountItems(); | |
| 709 FX_BOOL bClearSel = iSel < 0 || iSel >= iCount; | |
| 710 FX_BOOL bDropDown = IsDropDownStyle(); | |
| 711 if (bDropDown && m_pEdit) { | |
| 712 if (bClearSel) { | |
| 713 m_pEdit->SetText(CFX_WideString()); | |
| 714 } else { | |
| 715 CFX_WideString wsText; | |
| 716 IFWL_ComboBoxDP* pData = | |
| 717 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | |
| 718 IFWL_ListItem* hItem = pData->GetItem(m_pInterface, iSel); | |
| 719 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl()) | |
| 720 ->GetItemText(hItem, wsText); | |
| 721 m_pEdit->SetText(wsText); | |
| 722 } | |
| 723 m_pEdit->Update(); | |
| 724 } | |
| 725 m_iCurSel = bClearSel ? -1 : iSel; | |
| 726 return FWL_Error::Succeeded; | |
| 727 } | |
| 728 | |
| 729 void CFWL_ComboBoxImp::SetStates(uint32_t dwStates, FX_BOOL bSet) { | |
| 730 FX_BOOL bIsDropDown = IsDropDownStyle(); | |
| 731 if (bIsDropDown && m_pEdit) | |
| 732 m_pEdit->SetStates(dwStates, bSet); | |
| 733 if (m_pListBox) | |
| 734 m_pListBox->SetStates(dwStates, bSet); | |
| 735 CFWL_WidgetImp::SetStates(dwStates, bSet); | |
| 736 } | |
| 737 | |
| 738 FWL_Error CFWL_ComboBoxImp::SetEditText(const CFX_WideString& wsText) { | |
| 739 if (!m_pEdit) | |
| 740 return FWL_Error::Indefinite; | |
| 741 m_pEdit->SetText(wsText); | |
| 742 return m_pEdit->Update(); | |
| 743 } | |
| 744 int32_t CFWL_ComboBoxImp::GetEditTextLength() const { | |
| 745 if (!m_pEdit) | |
| 746 return -1; | |
| 747 return m_pEdit->GetTextLength(); | |
| 748 } | |
| 749 FWL_Error CFWL_ComboBoxImp::GetEditText(CFX_WideString& wsText, | |
| 750 int32_t nStart, | |
| 751 int32_t nCount) const { | |
| 752 if (m_pEdit) { | |
| 753 return m_pEdit->GetText(wsText, nStart, nCount); | |
| 754 } else if (m_pListBox) { | |
| 755 IFWL_ComboBoxDP* pData = | |
| 756 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | |
| 757 IFWL_ListItem* hItem = pData->GetItem(m_pInterface, m_iCurSel); | |
| 758 return m_pListBox->GetItemText(hItem, wsText); | |
| 759 } | |
| 760 return FWL_Error::Indefinite; | |
| 761 } | |
| 762 FWL_Error CFWL_ComboBoxImp::SetEditSelRange(int32_t nStart, int32_t nCount) { | |
| 763 if (!m_pEdit) | |
| 764 return FWL_Error::Indefinite; | |
| 765 static_cast<CFWL_ComboEditImp*>(m_pEdit->GetImpl())->ClearSelected(); | |
| 766 m_pEdit->AddSelRange(nStart, nCount); | |
| 767 return FWL_Error::Succeeded; | |
| 768 } | |
| 769 int32_t CFWL_ComboBoxImp::GetEditSelRange(int32_t nIndex, int32_t& nStart) { | |
| 770 if (!m_pEdit) | |
| 771 return -1; | |
| 772 return m_pEdit->GetSelRange(nIndex, nStart); | |
| 773 } | |
| 774 int32_t CFWL_ComboBoxImp::GetEditLimit() { | |
| 775 if (!m_pEdit) | |
| 776 return -1; | |
| 777 return m_pEdit->GetLimit(); | |
| 778 } | |
| 779 FWL_Error CFWL_ComboBoxImp::SetEditLimit(int32_t nLimit) { | |
| 780 if (!m_pEdit) | |
| 781 return FWL_Error::Indefinite; | |
| 782 return m_pEdit->SetLimit(nLimit); | |
| 783 } | |
| 784 FWL_Error CFWL_ComboBoxImp::EditDoClipboard(int32_t iCmd) { | |
| 785 if (!m_pEdit) | |
| 786 return FWL_Error::Indefinite; | |
| 787 return m_pEdit->DoClipboard(iCmd); | |
| 788 } | |
| 789 | |
| 790 FX_BOOL CFWL_ComboBoxImp::EditRedo(const IFDE_TxtEdtDoRecord* pRecord) { | |
| 791 return m_pEdit && m_pEdit->Redo(pRecord); | |
| 792 } | |
| 793 | |
| 794 FX_BOOL CFWL_ComboBoxImp::EditUndo(const IFDE_TxtEdtDoRecord* pRecord) { | |
| 795 return m_pEdit && m_pEdit->Undo(pRecord); | |
| 796 } | |
| 797 | |
| 798 IFWL_ListBox* CFWL_ComboBoxImp::GetListBoxt() { | |
| 799 return m_pListBox.get(); | |
| 800 } | |
| 801 FX_BOOL CFWL_ComboBoxImp::AfterFocusShowDropList() { | |
| 802 if (!m_bNeedShowList) { | |
| 803 return FALSE; | |
| 804 } | |
| 805 if (m_pEdit) { | |
| 806 MatchEditText(); | |
| 807 } | |
| 808 ShowDropList(TRUE); | |
| 809 m_bNeedShowList = FALSE; | |
| 810 return TRUE; | |
| 811 } | |
| 812 FWL_Error CFWL_ComboBoxImp::OpenDropDownList(FX_BOOL bActivate) { | |
| 813 ShowDropList(bActivate); | |
| 814 return FWL_Error::Succeeded; | |
| 815 } | |
| 816 FX_BOOL CFWL_ComboBoxImp::EditCanUndo() { | |
| 817 return m_pEdit->CanUndo(); | |
| 818 } | |
| 819 FX_BOOL CFWL_ComboBoxImp::EditCanRedo() { | |
| 820 return m_pEdit->CanRedo(); | |
| 821 } | |
| 822 FX_BOOL CFWL_ComboBoxImp::EditUndo() { | |
| 823 return m_pEdit->Undo(); | |
| 824 } | |
| 825 FX_BOOL CFWL_ComboBoxImp::EditRedo() { | |
| 826 return m_pEdit->Redo(); | |
| 827 } | |
| 828 FX_BOOL CFWL_ComboBoxImp::EditCanCopy() { | |
| 829 return m_pEdit->CountSelRanges() > 0; | |
| 830 } | |
| 831 FX_BOOL CFWL_ComboBoxImp::EditCanCut() { | |
| 832 if (m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly) { | |
| 833 return FALSE; | |
| 834 } | |
| 835 return m_pEdit->CountSelRanges() > 0; | |
| 836 } | |
| 837 FX_BOOL CFWL_ComboBoxImp::EditCanSelectAll() { | |
| 838 return m_pEdit->GetTextLength() > 0; | |
| 839 } | |
| 840 FX_BOOL CFWL_ComboBoxImp::EditCopy(CFX_WideString& wsCopy) { | |
| 841 return m_pEdit->Copy(wsCopy); | |
| 842 } | |
| 843 FX_BOOL CFWL_ComboBoxImp::EditCut(CFX_WideString& wsCut) { | |
| 844 return m_pEdit->Cut(wsCut); | |
| 845 } | |
| 846 FX_BOOL CFWL_ComboBoxImp::EditPaste(const CFX_WideString& wsPaste) { | |
| 847 return m_pEdit->Paste(wsPaste); | |
| 848 } | |
| 849 FX_BOOL CFWL_ComboBoxImp::EditSelectAll() { | |
| 850 return m_pEdit->AddSelRange(0) == FWL_Error::Succeeded; | |
| 851 } | |
| 852 FX_BOOL CFWL_ComboBoxImp::EditDelete() { | |
| 853 return m_pEdit->ClearText() == FWL_Error::Succeeded; | |
| 854 } | |
| 855 FX_BOOL CFWL_ComboBoxImp::EditDeSelect() { | |
| 856 return m_pEdit->ClearSelections() == FWL_Error::Succeeded; | |
| 857 } | |
| 858 FWL_Error CFWL_ComboBoxImp::GetBBox(CFX_RectF& rect) { | |
| 859 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 860 return DisForm_GetBBox(rect); | |
| 861 } | |
| 862 rect = m_pProperties->m_rtWidget; | |
| 863 if (m_pListBox && IsDropListShowed()) { | |
| 864 CFX_RectF rtList; | |
| 865 m_pListBox->GetWidgetRect(rtList); | |
| 866 rtList.Offset(rect.left, rect.top); | |
| 867 rect.Union(rtList); | |
| 868 } | |
| 869 return FWL_Error::Succeeded; | |
| 870 } | |
| 871 | |
| 872 FWL_Error CFWL_ComboBoxImp::EditModifyStylesEx(uint32_t dwStylesExAdded, | |
| 873 uint32_t dwStylesExRemoved) { | |
| 874 if (!m_pEdit) | |
| 875 return FWL_Error::ParameterInvalid; | |
| 876 return m_pEdit->ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
| 877 } | |
| 878 | |
| 879 FX_FLOAT CFWL_ComboBoxImp::GetListHeight() { | |
| 880 return static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider) | |
| 881 ->GetListHeight(m_pInterface); | |
| 882 } | |
| 883 void CFWL_ComboBoxImp::DrawStretchHandler(CFX_Graphics* pGraphics, | |
| 884 const CFX_Matrix* pMatrix) { | |
| 885 CFWL_ThemeBackground param; | |
| 886 param.m_pGraphics = pGraphics; | |
| 887 param.m_iPart = CFWL_Part::StretchHandler; | |
| 888 param.m_dwStates = CFWL_PartState_Normal; | |
| 889 param.m_pWidget = m_pInterface; | |
| 890 if (pMatrix) { | |
| 891 param.m_matrix.Concat(*pMatrix); | |
| 892 } | |
| 893 param.m_rtPart = m_rtHandler; | |
| 894 m_pProperties->m_pThemeProvider->DrawBackground(¶m); | |
| 895 } | |
| 896 void CFWL_ComboBoxImp::ShowDropList(FX_BOOL bActivate) { | |
| 897 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 898 return DisForm_ShowDropList(bActivate); | |
| 899 } | |
| 900 FX_BOOL bDropList = IsDropListShowed(); | |
| 901 if (bDropList == bActivate) { | |
| 902 return; | |
| 903 } | |
| 904 if (!m_pForm) { | |
| 905 InitProxyForm(); | |
| 906 } | |
| 907 m_pListProxyDelegate->Reset(); | |
| 908 if (bActivate) { | |
| 909 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl()) | |
| 910 ->ChangeSelected(m_iCurSel); | |
| 911 ReSetListItemAlignment(); | |
| 912 uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & | |
| 913 (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); | |
| 914 m_pListBox->ModifyStylesEx(dwStyleAdd, 0); | |
| 915 m_pListBox->GetWidgetRect(m_rtList, TRUE); | |
| 916 FX_FLOAT fHeight = GetListHeight(); | |
| 917 if (fHeight > 0) { | |
| 918 if (m_rtList.height > GetListHeight()) { | |
| 919 m_rtList.height = GetListHeight(); | |
| 920 m_pListBox->ModifyStyles(FWL_WGTSTYLE_VScroll, 0); | |
| 921 } | |
| 922 } | |
| 923 CFX_RectF rtAnchor; | |
| 924 rtAnchor.Set(0, 0, m_pProperties->m_rtWidget.width, | |
| 925 m_pProperties->m_rtWidget.height); | |
| 926 FX_FLOAT fMinHeight = 0; | |
| 927 if (m_rtList.width < m_rtClient.width) { | |
| 928 m_rtList.width = m_rtClient.width; | |
| 929 } | |
| 930 m_rtProxy = m_rtList; | |
| 931 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) { | |
| 932 m_rtProxy.height += m_fComboFormHandler; | |
| 933 } | |
| 934 GetPopupPos(fMinHeight, m_rtProxy.height, rtAnchor, m_rtProxy); | |
| 935 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListDrag) { | |
| 936 FX_FLOAT fx = 0; | |
| 937 FX_FLOAT fy = m_rtClient.top + m_rtClient.height / 2; | |
| 938 TransformTo(nullptr, fx, fy); | |
| 939 m_bUpFormHandler = fy > m_rtProxy.top; | |
| 940 if (m_bUpFormHandler) { | |
| 941 m_rtHandler.Set(0, 0, m_rtList.width, m_fComboFormHandler); | |
| 942 m_rtList.top = m_fComboFormHandler; | |
| 943 } else { | |
| 944 m_rtHandler.Set(0, m_rtList.height, m_rtList.width, | |
| 945 m_fComboFormHandler); | |
| 946 } | |
| 947 } | |
| 948 m_pForm->SetWidgetRect(m_rtProxy); | |
| 949 m_pForm->Update(); | |
| 950 m_pListBox->SetWidgetRect(m_rtList); | |
| 951 m_pListBox->Update(); | |
| 952 CFWL_EvtCmbPreDropDown ev; | |
| 953 ev.m_pSrcTarget = m_pInterface; | |
| 954 DispatchEvent(&ev); | |
| 955 m_fItemHeight = | |
| 956 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl())->m_fItemHeight; | |
| 957 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl())->SetFocus(TRUE); | |
| 958 m_pForm->DoModal(); | |
| 959 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl())->SetFocus(FALSE); | |
| 960 } else { | |
| 961 m_pForm->EndDoModal(); | |
| 962 CFWL_EvtCmbCloseUp ev; | |
| 963 ev.m_pSrcTarget = m_pInterface; | |
| 964 DispatchEvent(&ev); | |
| 965 m_bLButtonDown = FALSE; | |
| 966 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl())->m_bNotifyOwner = | |
| 967 TRUE; | |
| 968 SetFocus(TRUE); | |
| 969 } | |
| 970 } | |
| 971 FX_BOOL CFWL_ComboBoxImp::IsDropListShowed() { | |
| 972 return m_pForm && !(m_pForm->GetStates() & FWL_WGTSTATE_Invisible); | |
| 973 } | |
| 974 FX_BOOL CFWL_ComboBoxImp::IsDropDownStyle() const { | |
| 975 return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown; | |
| 976 } | |
| 977 void CFWL_ComboBoxImp::MatchEditText() { | |
| 978 CFX_WideString wsText; | |
| 979 m_pEdit->GetText(wsText); | |
| 980 int32_t iMatch = | |
| 981 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl())->MatchItem(wsText); | |
| 982 if (iMatch != m_iCurSel) { | |
| 983 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl()) | |
| 984 ->ChangeSelected(iMatch); | |
| 985 if (iMatch >= 0) { | |
| 986 SynchrEditText(iMatch); | |
| 987 } | |
| 988 } else if (iMatch >= 0) { | |
| 989 static_cast<CFWL_ComboEditImp*>(m_pEdit->GetImpl())->SetSelected(); | |
| 990 } | |
| 991 m_iCurSel = iMatch; | |
| 992 } | |
| 993 void CFWL_ComboBoxImp::SynchrEditText(int32_t iListItem) { | |
| 994 CFX_WideString wsText; | |
| 995 IFWL_ComboBoxDP* pData = | |
| 996 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | |
| 997 IFWL_ListItem* hItem = pData->GetItem(m_pInterface, iListItem); | |
| 998 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl()) | |
| 999 ->GetItemText(hItem, wsText); | |
| 1000 m_pEdit->SetText(wsText); | |
| 1001 m_pEdit->Update(); | |
| 1002 static_cast<CFWL_ComboEditImp*>(m_pEdit->GetImpl())->SetSelected(); | |
| 1003 } | |
| 1004 void CFWL_ComboBoxImp::Layout() { | |
| 1005 if (m_pWidgetMgr->IsFormDisabled()) { | |
| 1006 return DisForm_Layout(); | |
| 1007 } | |
| 1008 GetClientRect(m_rtClient); | |
| 1009 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | |
| 1010 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | |
| 1011 if (!pFWidth) | |
| 1012 return; | |
| 1013 FX_FLOAT fBtn = *pFWidth; | |
| 1014 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top, fBtn, | |
| 1015 m_rtClient.height); | |
| 1016 FX_BOOL bIsDropDown = IsDropDownStyle(); | |
| 1017 if (bIsDropDown && m_pEdit) { | |
| 1018 CFX_RectF rtEdit; | |
| 1019 rtEdit.Set(m_rtClient.left, m_rtClient.top, m_rtClient.width - fBtn, | |
| 1020 m_rtClient.height); | |
| 1021 m_pEdit->SetWidgetRect(rtEdit); | |
| 1022 if (m_iCurSel >= 0) { | |
| 1023 CFX_WideString wsText; | |
| 1024 IFWL_ComboBoxDP* pData = | |
| 1025 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | |
| 1026 IFWL_ListItem* hItem = pData->GetItem(m_pInterface, m_iCurSel); | |
| 1027 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl()) | |
| 1028 ->GetItemText(hItem, wsText); | |
| 1029 m_pEdit->LockUpdate(); | |
| 1030 m_pEdit->SetText(wsText); | |
| 1031 m_pEdit->UnlockUpdate(); | |
| 1032 } | |
| 1033 m_pEdit->Update(); | |
| 1034 } | |
| 1035 } | |
| 1036 void CFWL_ComboBoxImp::ReSetTheme() { | |
| 1037 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
| 1038 if (!pTheme) { | |
| 1039 pTheme = GetAvailableTheme(); | |
| 1040 m_pProperties->m_pThemeProvider = pTheme; | |
| 1041 } | |
| 1042 if (m_pListBox && !m_pListBox->GetThemeProvider()) | |
| 1043 m_pListBox->SetThemeProvider(pTheme); | |
| 1044 if (m_pEdit && !m_pEdit->GetThemeProvider()) | |
| 1045 m_pEdit->SetThemeProvider(pTheme); | |
| 1046 } | |
| 1047 void CFWL_ComboBoxImp::ReSetEditAlignment() { | |
| 1048 if (!m_pEdit) | |
| 1049 return; | |
| 1050 uint32_t dwStylExes = m_pProperties->m_dwStyleExes; | |
| 1051 uint32_t dwAdd = 0; | |
| 1052 switch (dwStylExes & FWL_STYLEEXT_CMB_EditHAlignMask) { | |
| 1053 case FWL_STYLEEXT_CMB_EditHCenter: { | |
| 1054 dwAdd |= FWL_STYLEEXT_EDT_HCenter; | |
| 1055 break; | |
| 1056 } | |
| 1057 case FWL_STYLEEXT_CMB_EditHFar: { | |
| 1058 dwAdd |= FWL_STYLEEXT_EDT_HFar; | |
| 1059 break; | |
| 1060 } | |
| 1061 default: { dwAdd |= FWL_STYLEEXT_EDT_HNear; } | |
| 1062 } | |
| 1063 switch (dwStylExes & FWL_STYLEEXT_CMB_EditVAlignMask) { | |
| 1064 case FWL_STYLEEXT_CMB_EditVCenter: { | |
| 1065 dwAdd |= FWL_STYLEEXT_EDT_VCenter; | |
| 1066 break; | |
| 1067 } | |
| 1068 case FWL_STYLEEXT_CMB_EditVFar: { | |
| 1069 dwAdd |= FWL_STYLEEXT_EDT_VFar; | |
| 1070 break; | |
| 1071 } | |
| 1072 default: { dwAdd |= FWL_STYLEEXT_EDT_VNear; } | |
| 1073 } | |
| 1074 if (dwStylExes & FWL_STYLEEXT_CMB_EditJustified) { | |
| 1075 dwAdd |= FWL_STYLEEXT_EDT_Justified; | |
| 1076 } | |
| 1077 if (dwStylExes & FWL_STYLEEXT_CMB_EditDistributed) { | |
| 1078 dwAdd |= FWL_STYLEEXT_EDT_Distributed; | |
| 1079 } | |
| 1080 m_pEdit->ModifyStylesEx(dwAdd, FWL_STYLEEXT_EDT_HAlignMask | | |
| 1081 FWL_STYLEEXT_EDT_HAlignModeMask | | |
| 1082 FWL_STYLEEXT_EDT_VAlignMask); | |
| 1083 } | |
| 1084 void CFWL_ComboBoxImp::ReSetListItemAlignment() { | |
| 1085 if (!m_pListBox) | |
| 1086 return; | |
| 1087 uint32_t dwStylExes = m_pProperties->m_dwStyleExes; | |
| 1088 uint32_t dwAdd = 0; | |
| 1089 switch (dwStylExes & FWL_STYLEEXT_CMB_ListItemAlignMask) { | |
| 1090 case FWL_STYLEEXT_CMB_ListItemCenterAlign: { | |
| 1091 dwAdd |= FWL_STYLEEXT_LTB_CenterAlign; | |
| 1092 } | |
| 1093 case FWL_STYLEEXT_CMB_ListItemRightAlign: { | |
| 1094 dwAdd |= FWL_STYLEEXT_LTB_RightAlign; | |
| 1095 } | |
| 1096 default: { dwAdd |= FWL_STYLEEXT_LTB_LeftAlign; } | |
| 1097 } | |
| 1098 m_pListBox->ModifyStylesEx(dwAdd, FWL_STYLEEXT_CMB_ListItemAlignMask); | |
| 1099 } | |
| 1100 void CFWL_ComboBoxImp::ProcessSelChanged(FX_BOOL bLButtonUp) { | |
| 1101 IFWL_ComboBoxDP* pDatas = | |
| 1102 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | |
| 1103 m_iCurSel = pDatas->GetItemIndex(m_pInterface, m_pListBox->GetSelItem(0)); | |
| 1104 FX_BOOL bDropDown = IsDropDownStyle(); | |
| 1105 if (bDropDown) { | |
| 1106 IFWL_ComboBoxDP* pData = | |
| 1107 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | |
| 1108 IFWL_ListItem* hItem = pData->GetItem(m_pInterface, m_iCurSel); | |
| 1109 if (hItem) { | |
| 1110 CFX_WideString wsText; | |
| 1111 pData->GetItemText(m_pInterface, hItem, wsText); | |
| 1112 if (m_pEdit) { | |
| 1113 m_pEdit->SetText(wsText); | |
| 1114 m_pEdit->Update(); | |
| 1115 static_cast<CFWL_ComboEditImp*>(m_pEdit->GetImpl())->SetSelected(); | |
| 1116 } | |
| 1117 CFWL_EvtCmbSelChanged ev; | |
| 1118 ev.bLButtonUp = bLButtonUp; | |
| 1119 ev.m_pSrcTarget = m_pInterface; | |
| 1120 ev.iArraySels.Add(m_iCurSel); | |
| 1121 DispatchEvent(&ev); | |
| 1122 } | |
| 1123 } else { | |
| 1124 Repaint(&m_rtClient); | |
| 1125 } | |
| 1126 } | |
| 1127 | |
| 1128 void CFWL_ComboBoxImp::InitProxyForm() { | |
| 1129 if (m_pForm) | |
| 1130 return; | |
| 1131 if (!m_pListBox) | |
| 1132 return; | |
| 1133 | |
| 1134 CFWL_WidgetImpProperties propForm; | |
| 1135 propForm.m_pOwner = m_pInterface; | |
| 1136 propForm.m_dwStyles = FWL_WGTSTYLE_Popup; | |
| 1137 propForm.m_dwStates = FWL_WGTSTATE_Invisible; | |
| 1138 CFX_WideString className; | |
| 1139 m_pForm = IFWL_Form::CreateFormProxy(propForm, &className, m_pListBox.get()); | |
| 1140 m_pForm->Initialize(); | |
| 1141 m_pProxy = static_cast<CFWL_FormProxyImp*>(m_pForm->GetImpl()); | |
| 1142 m_pListBox->SetParent(m_pForm); | |
| 1143 m_pListProxyDelegate = new CFWL_ComboProxyImpDelegate(m_pForm, this); | |
| 1144 m_pProxy->SetDelegate(m_pListProxyDelegate); | |
| 1145 } | |
| 1146 | |
| 1147 FWL_Error CFWL_ComboBoxImp::DisForm_Initialize() { | |
| 1148 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded) | |
| 1149 return FWL_Error::Indefinite; | |
| 1150 | |
| 1151 m_pDelegate = new CFWL_ComboBoxImpDelegate(this); | |
| 1152 DisForm_InitComboList(); | |
| 1153 DisForm_InitComboEdit(); | |
| 1154 return FWL_Error::Succeeded; | |
| 1155 } | |
| 1156 | |
| 1157 void CFWL_ComboBoxImp::DisForm_InitComboList() { | |
| 1158 if (m_pListBox) | |
| 1159 return; | |
| 1160 | |
| 1161 CFWL_WidgetImpProperties prop; | |
| 1162 prop.m_pParent = m_pInterface; | |
| 1163 prop.m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; | |
| 1164 prop.m_dwStates = FWL_WGTSTATE_Invisible; | |
| 1165 prop.m_pDataProvider = m_pProperties->m_pDataProvider; | |
| 1166 prop.m_pThemeProvider = m_pProperties->m_pThemeProvider; | |
| 1167 m_pListBox.reset(IFWL_ListBox::CreateComboList(prop, m_pInterface)); | |
| 1168 m_pListBox->Initialize(); | |
| 1169 } | |
| 1170 void CFWL_ComboBoxImp::DisForm_InitComboEdit() { | |
| 1171 if (m_pEdit) { | |
| 1172 return; | |
| 1173 } | |
| 1174 CFWL_WidgetImpProperties prop; | |
| 1175 prop.m_pParent = m_pInterface; | |
| 1176 prop.m_pThemeProvider = m_pProperties->m_pThemeProvider; | |
| 1177 m_pEdit.reset(IFWL_Edit::CreateComboEdit(prop, m_pInterface)); | |
| 1178 m_pEdit->Initialize(); | |
| 1179 static_cast<CFWL_ComboEditImp*>(m_pEdit->GetImpl())->SetOuter(m_pInterface); | |
| 1180 } | |
| 1181 void CFWL_ComboBoxImp::DisForm_ShowDropList(FX_BOOL bActivate) { | |
| 1182 FX_BOOL bDropList = DisForm_IsDropListShowed(); | |
| 1183 if (bDropList == bActivate) { | |
| 1184 return; | |
| 1185 } | |
| 1186 if (bActivate) { | |
| 1187 CFWL_EvtCmbPreDropDown preEvent; | |
| 1188 preEvent.m_pSrcTarget = m_pInterface; | |
| 1189 DispatchEvent(&preEvent); | |
| 1190 CFWL_ComboListImp* pComboList = | |
| 1191 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl()); | |
| 1192 int32_t iItems = pComboList->CountItems(); | |
| 1193 if (iItems < 1) { | |
| 1194 return; | |
| 1195 } | |
| 1196 ReSetListItemAlignment(); | |
| 1197 pComboList->ChangeSelected(m_iCurSel); | |
| 1198 FX_FLOAT fItemHeight = pComboList->GetItemHeigt(); | |
| 1199 FX_FLOAT fBorder = GetBorderSize(); | |
| 1200 FX_FLOAT fPopupMin = 0.0f; | |
| 1201 if (iItems > 3) { | |
| 1202 fPopupMin = fItemHeight * 3 + fBorder * 2; | |
| 1203 } | |
| 1204 FX_FLOAT fPopupMax = fItemHeight * iItems + fBorder * 2; | |
| 1205 CFX_RectF rtList; | |
| 1206 rtList.left = m_rtClient.left; | |
| 1207 rtList.width = m_pProperties->m_rtWidget.width; | |
| 1208 rtList.top = 0; | |
| 1209 rtList.height = 0; | |
| 1210 GetPopupPos(fPopupMin, fPopupMax, m_pProperties->m_rtWidget, rtList); | |
| 1211 m_pListBox->SetWidgetRect(rtList); | |
| 1212 m_pListBox->Update(); | |
| 1213 } else { | |
| 1214 SetFocus(TRUE); | |
| 1215 } | |
| 1216 m_pListBox->SetStates(FWL_WGTSTATE_Invisible, !bActivate); | |
| 1217 if (bActivate) { | |
| 1218 CFWL_EvtCmbPostDropDown postEvent; | |
| 1219 postEvent.m_pSrcTarget = m_pInterface; | |
| 1220 DispatchEvent(&postEvent); | |
| 1221 } | |
| 1222 CFX_RectF rect; | |
| 1223 m_pListBox->GetWidgetRect(rect); | |
| 1224 rect.Inflate(2, 2); | |
| 1225 Repaint(&rect); | |
| 1226 } | |
| 1227 FX_BOOL CFWL_ComboBoxImp::DisForm_IsDropListShowed() { | |
| 1228 return !(m_pListBox->GetStates() & FWL_WGTSTATE_Invisible); | |
| 1229 } | |
| 1230 FWL_Error CFWL_ComboBoxImp::DisForm_ModifyStylesEx(uint32_t dwStylesExAdded, | |
| 1231 uint32_t dwStylesExRemoved) { | |
| 1232 if (!m_pEdit) { | |
| 1233 DisForm_InitComboEdit(); | |
| 1234 } | |
| 1235 bool bAddDropDown = !!(dwStylesExAdded & FWL_STYLEEXT_CMB_DropDown); | |
| 1236 bool bDelDropDown = !!(dwStylesExRemoved & FWL_STYLEEXT_CMB_DropDown); | |
| 1237 dwStylesExRemoved &= ~FWL_STYLEEXT_CMB_DropDown; | |
| 1238 m_pProperties->m_dwStyleExes |= FWL_STYLEEXT_CMB_DropDown; | |
| 1239 if (bAddDropDown) { | |
| 1240 m_pEdit->ModifyStylesEx(0, FWL_STYLEEXT_EDT_ReadOnly); | |
| 1241 } else if (bDelDropDown) { | |
| 1242 m_pEdit->ModifyStylesEx(FWL_STYLEEXT_EDT_ReadOnly, 0); | |
| 1243 } | |
| 1244 return CFWL_WidgetImp::ModifyStylesEx(dwStylesExAdded, dwStylesExRemoved); | |
| 1245 } | |
| 1246 FWL_Error CFWL_ComboBoxImp::DisForm_Update() { | |
| 1247 if (m_iLock) { | |
| 1248 return FWL_Error::Indefinite; | |
| 1249 } | |
| 1250 if (m_pEdit) { | |
| 1251 ReSetEditAlignment(); | |
| 1252 } | |
| 1253 ReSetTheme(); | |
| 1254 Layout(); | |
| 1255 return FWL_Error::Succeeded; | |
| 1256 } | |
| 1257 FWL_WidgetHit CFWL_ComboBoxImp::DisForm_HitTest(FX_FLOAT fx, FX_FLOAT fy) { | |
| 1258 CFX_RectF rect; | |
| 1259 rect.Set(0, 0, m_pProperties->m_rtWidget.width - m_rtBtn.width, | |
| 1260 m_pProperties->m_rtWidget.height); | |
| 1261 if (rect.Contains(fx, fy)) | |
| 1262 return FWL_WidgetHit::Edit; | |
| 1263 if (m_rtBtn.Contains(fx, fy)) | |
| 1264 return FWL_WidgetHit::Client; | |
| 1265 if (DisForm_IsDropListShowed()) { | |
| 1266 m_pListBox->GetWidgetRect(rect); | |
| 1267 if (rect.Contains(fx, fy)) | |
| 1268 return FWL_WidgetHit::Client; | |
| 1269 } | |
| 1270 return FWL_WidgetHit::Unknown; | |
| 1271 } | |
| 1272 FWL_Error CFWL_ComboBoxImp::DisForm_DrawWidget(CFX_Graphics* pGraphics, | |
| 1273 const CFX_Matrix* pMatrix) { | |
| 1274 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | |
| 1275 CFX_Matrix mtOrg; | |
| 1276 mtOrg.Set(1, 0, 0, 1, 0, 0); | |
| 1277 if (pMatrix) { | |
| 1278 mtOrg = *pMatrix; | |
| 1279 } | |
| 1280 FX_BOOL bListShowed = m_pListBox && DisForm_IsDropListShowed(); | |
| 1281 pGraphics->SaveGraphState(); | |
| 1282 pGraphics->ConcatMatrix(&mtOrg); | |
| 1283 if (!m_rtBtn.IsEmpty(0.1f)) { | |
| 1284 CFWL_ThemeBackground param; | |
| 1285 param.m_pWidget = m_pInterface; | |
| 1286 param.m_iPart = CFWL_Part::DropDownButton; | |
| 1287 param.m_dwStates = m_iBtnState; | |
| 1288 param.m_pGraphics = pGraphics; | |
| 1289 param.m_rtPart = m_rtBtn; | |
| 1290 pTheme->DrawBackground(¶m); | |
| 1291 } | |
| 1292 pGraphics->RestoreGraphState(); | |
| 1293 if (m_pEdit) { | |
| 1294 CFX_RectF rtEdit; | |
| 1295 m_pEdit->GetWidgetRect(rtEdit); | |
| 1296 CFX_Matrix mt; | |
| 1297 mt.Set(1, 0, 0, 1, rtEdit.left, rtEdit.top); | |
| 1298 mt.Concat(mtOrg); | |
| 1299 m_pEdit->DrawWidget(pGraphics, &mt); | |
| 1300 } | |
| 1301 if (bListShowed) { | |
| 1302 CFX_RectF rtList; | |
| 1303 m_pListBox->GetWidgetRect(rtList); | |
| 1304 CFX_Matrix mt; | |
| 1305 mt.Set(1, 0, 0, 1, rtList.left, rtList.top); | |
| 1306 mt.Concat(mtOrg); | |
| 1307 m_pListBox->DrawWidget(pGraphics, &mt); | |
| 1308 } | |
| 1309 return FWL_Error::Succeeded; | |
| 1310 } | |
| 1311 FWL_Error CFWL_ComboBoxImp::DisForm_GetBBox(CFX_RectF& rect) { | |
| 1312 rect = m_pProperties->m_rtWidget; | |
| 1313 if (m_pListBox && DisForm_IsDropListShowed()) { | |
| 1314 CFX_RectF rtList; | |
| 1315 m_pListBox->GetWidgetRect(rtList); | |
| 1316 rtList.Offset(rect.left, rect.top); | |
| 1317 rect.Union(rtList); | |
| 1318 } | |
| 1319 return FWL_Error::Succeeded; | |
| 1320 } | |
| 1321 void CFWL_ComboBoxImp::DisForm_Layout() { | |
| 1322 GetClientRect(m_rtClient); | |
| 1323 m_rtContent = m_rtClient; | |
| 1324 FX_FLOAT* pFWidth = static_cast<FX_FLOAT*>( | |
| 1325 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | |
| 1326 if (!pFWidth) | |
| 1327 return; | |
| 1328 FX_FLOAT borderWidth = 1; | |
| 1329 FX_FLOAT fBtn = *pFWidth; | |
| 1330 if (!(GetStylesEx() & FWL_STYLEEXT_CMB_ReadOnly)) { | |
| 1331 m_rtBtn.Set(m_rtClient.right() - fBtn, m_rtClient.top + borderWidth, | |
| 1332 fBtn - borderWidth, m_rtClient.height - 2 * borderWidth); | |
| 1333 } | |
| 1334 CFX_RectF* pUIMargin = | |
| 1335 static_cast<CFX_RectF*>(GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); | |
| 1336 if (pUIMargin) { | |
| 1337 m_rtContent.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, | |
| 1338 pUIMargin->height); | |
| 1339 } | |
| 1340 FX_BOOL bIsDropDown = IsDropDownStyle(); | |
| 1341 if (bIsDropDown && m_pEdit) { | |
| 1342 CFX_RectF rtEdit; | |
| 1343 rtEdit.Set(m_rtContent.left, m_rtContent.top, m_rtContent.width - fBtn, | |
| 1344 m_rtContent.height); | |
| 1345 m_pEdit->SetWidgetRect(rtEdit); | |
| 1346 if (m_iCurSel >= 0) { | |
| 1347 CFX_WideString wsText; | |
| 1348 IFWL_ComboBoxDP* pData = | |
| 1349 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); | |
| 1350 IFWL_ListItem* hItem = pData->GetItem(m_pInterface, m_iCurSel); | |
| 1351 static_cast<CFWL_ComboListImp*>(m_pListBox->GetImpl()) | |
| 1352 ->GetItemText(hItem, wsText); | |
| 1353 m_pEdit->LockUpdate(); | |
| 1354 m_pEdit->SetText(wsText); | |
| 1355 m_pEdit->UnlockUpdate(); | |
| 1356 } | |
| 1357 m_pEdit->Update(); | |
| 1358 } | |
| 1359 } | |
| 1360 | |
| 1361 CFWL_ComboBoxImpDelegate::CFWL_ComboBoxImpDelegate(CFWL_ComboBoxImp* pOwner) | |
| 1362 : m_pOwner(pOwner) {} | |
| 1363 | |
| 1364 void CFWL_ComboBoxImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 1365 if (m_pOwner->m_pWidgetMgr->IsFormDisabled()) { | |
| 1366 DisForm_OnProcessMessage(pMessage); | |
| 1367 return; | |
| 1368 } | |
| 1369 if (!pMessage) | |
| 1370 return; | |
| 1371 | |
| 1372 switch (pMessage->GetClassID()) { | |
| 1373 case CFWL_MessageType::SetFocus: { | |
| 1374 OnFocusChanged(pMessage, TRUE); | |
| 1375 break; | |
| 1376 } | |
| 1377 case CFWL_MessageType::KillFocus: { | |
| 1378 OnFocusChanged(pMessage, FALSE); | |
| 1379 break; | |
| 1380 } | |
| 1381 case CFWL_MessageType::Mouse: { | |
| 1382 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 1383 switch (pMsg->m_dwCmd) { | |
| 1384 case FWL_MouseCommand::LeftButtonDown: { | |
| 1385 OnLButtonDown(pMsg); | |
| 1386 break; | |
| 1387 } | |
| 1388 case FWL_MouseCommand::LeftButtonUp: { | |
| 1389 OnLButtonUp(pMsg); | |
| 1390 break; | |
| 1391 } | |
| 1392 case FWL_MouseCommand::Move: { | |
| 1393 OnMouseMove(pMsg); | |
| 1394 break; | |
| 1395 } | |
| 1396 case FWL_MouseCommand::Leave: { | |
| 1397 OnMouseLeave(pMsg); | |
| 1398 break; | |
| 1399 } | |
| 1400 default: | |
| 1401 break; | |
| 1402 } | |
| 1403 break; | |
| 1404 } | |
| 1405 case CFWL_MessageType::Key: { | |
| 1406 OnKey(static_cast<CFWL_MsgKey*>(pMessage)); | |
| 1407 break; | |
| 1408 } | |
| 1409 default: { | |
| 1410 break; | |
| 1411 } | |
| 1412 } | |
| 1413 | |
| 1414 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | |
| 1415 } | |
| 1416 | |
| 1417 void CFWL_ComboBoxImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { | |
| 1418 CFWL_EventType dwFlag = pEvent->GetClassID(); | |
| 1419 if (dwFlag == CFWL_EventType::DrawItem) { | |
| 1420 CFWL_EvtLtbDrawItem* pDrawItemEvent = | |
| 1421 static_cast<CFWL_EvtLtbDrawItem*>(pEvent); | |
| 1422 CFWL_EvtCmbDrawItem pTemp; | |
| 1423 pTemp.m_pSrcTarget = m_pOwner->m_pInterface; | |
| 1424 pTemp.m_pGraphics = pDrawItemEvent->m_pGraphics; | |
| 1425 pTemp.m_index = pDrawItemEvent->m_index; | |
| 1426 pTemp.m_rtItem = pDrawItemEvent->m_rect; | |
| 1427 m_pOwner->DispatchEvent(&pTemp); | |
| 1428 } else if (dwFlag == CFWL_EventType::Scroll) { | |
| 1429 CFWL_EvtScroll* pScrollEvent = static_cast<CFWL_EvtScroll*>(pEvent); | |
| 1430 CFWL_EvtScroll pScrollEv; | |
| 1431 pScrollEv.m_pSrcTarget = m_pOwner->m_pInterface; | |
| 1432 pScrollEv.m_iScrollCode = pScrollEvent->m_iScrollCode; | |
| 1433 pScrollEv.m_fPos = pScrollEvent->m_fPos; | |
| 1434 m_pOwner->DispatchEvent(&pScrollEv); | |
| 1435 } else if (dwFlag == CFWL_EventType::TextChanged) { | |
| 1436 CFWL_EvtEdtTextChanged* pTextChangedEvent = | |
| 1437 static_cast<CFWL_EvtEdtTextChanged*>(pEvent); | |
| 1438 CFWL_EvtCmbEditChanged pTemp; | |
| 1439 pTemp.m_pSrcTarget = m_pOwner->m_pInterface; | |
| 1440 pTemp.wsInsert = pTextChangedEvent->wsInsert; | |
| 1441 pTemp.wsDelete = pTextChangedEvent->wsDelete; | |
| 1442 pTemp.nChangeType = pTextChangedEvent->nChangeType; | |
| 1443 m_pOwner->DispatchEvent(&pTemp); | |
| 1444 } | |
| 1445 } | |
| 1446 | |
| 1447 void CFWL_ComboBoxImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 1448 const CFX_Matrix* pMatrix) { | |
| 1449 m_pOwner->DrawWidget(pGraphics, pMatrix); | |
| 1450 } | |
| 1451 | |
| 1452 void CFWL_ComboBoxImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | |
| 1453 FX_BOOL bSet) { | |
| 1454 IFWL_Widget* pDstTarget = pMsg->m_pDstTarget; | |
| 1455 IFWL_Widget* pSrcTarget = pMsg->m_pSrcTarget; | |
| 1456 FX_BOOL bDropDown = m_pOwner->IsDropDownStyle(); | |
| 1457 if (bSet) { | |
| 1458 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | |
| 1459 if (bDropDown && pSrcTarget != m_pOwner->m_pListBox.get()) { | |
| 1460 if (!m_pOwner->m_pEdit) | |
| 1461 return; | |
| 1462 static_cast<CFWL_ComboEditImp*>(m_pOwner->m_pEdit->GetImpl()) | |
| 1463 ->SetSelected(); | |
| 1464 } else { | |
| 1465 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1466 } | |
| 1467 } else { | |
| 1468 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | |
| 1469 if (bDropDown && pDstTarget != m_pOwner->m_pListBox.get()) { | |
| 1470 if (!m_pOwner->m_pEdit) | |
| 1471 return; | |
| 1472 static_cast<CFWL_ComboEditImp*>(m_pOwner->m_pEdit->GetImpl()) | |
| 1473 ->FlagFocus(FALSE); | |
| 1474 static_cast<CFWL_ComboEditImp*>(m_pOwner->m_pEdit->GetImpl()) | |
| 1475 ->ClearSelected(); | |
| 1476 } else { | |
| 1477 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1478 } | |
| 1479 } | |
| 1480 } | |
| 1481 void CFWL_ComboBoxImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | |
| 1482 if (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | |
| 1483 return; | |
| 1484 } | |
| 1485 FX_BOOL bDropDown = m_pOwner->IsDropDownStyle(); | |
| 1486 CFX_RectF& rtBtn = bDropDown ? m_pOwner->m_rtBtn : m_pOwner->m_rtClient; | |
| 1487 FX_BOOL bClickBtn = rtBtn.Contains(pMsg->m_fx, pMsg->m_fy); | |
| 1488 if (bClickBtn) { | |
| 1489 if (bDropDown && m_pOwner->m_pEdit) { | |
| 1490 m_pOwner->MatchEditText(); | |
| 1491 } | |
| 1492 m_pOwner->m_bLButtonDown = TRUE; | |
| 1493 m_pOwner->m_iBtnState = CFWL_PartState_Pressed; | |
| 1494 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1495 m_pOwner->ShowDropList(TRUE); | |
| 1496 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | |
| 1497 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1498 } | |
| 1499 } | |
| 1500 void CFWL_ComboBoxImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | |
| 1501 m_pOwner->m_bLButtonDown = FALSE; | |
| 1502 if (m_pOwner->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1503 m_pOwner->m_iBtnState = CFWL_PartState_Hovered; | |
| 1504 } else { | |
| 1505 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | |
| 1506 } | |
| 1507 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | |
| 1508 } | |
| 1509 void CFWL_ComboBoxImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) { | |
| 1510 int32_t iOldState = m_pOwner->m_iBtnState; | |
| 1511 if (m_pOwner->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1512 m_pOwner->m_iBtnState = m_pOwner->m_bLButtonDown ? CFWL_PartState_Pressed | |
| 1513 : CFWL_PartState_Hovered; | |
| 1514 } else { | |
| 1515 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | |
| 1516 } | |
| 1517 if ((iOldState != m_pOwner->m_iBtnState) && | |
| 1518 !((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == | |
| 1519 FWL_WGTSTATE_Disabled)) { | |
| 1520 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | |
| 1521 } | |
| 1522 } | |
| 1523 void CFWL_ComboBoxImpDelegate::OnMouseLeave(CFWL_MsgMouse* pMsg) { | |
| 1524 if (!m_pOwner->IsDropListShowed() && | |
| 1525 !((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == | |
| 1526 FWL_WGTSTATE_Disabled)) { | |
| 1527 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | |
| 1528 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | |
| 1529 } | |
| 1530 } | |
| 1531 void CFWL_ComboBoxImpDelegate::OnKey(CFWL_MsgKey* pMsg) { | |
| 1532 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | |
| 1533 if (dwKeyCode == FWL_VKEY_Tab) { | |
| 1534 m_pOwner->DispatchKeyEvent(pMsg); | |
| 1535 return; | |
| 1536 } | |
| 1537 if (pMsg->m_pDstTarget == m_pOwner->m_pInterface) | |
| 1538 DoSubCtrlKey(pMsg); | |
| 1539 } | |
| 1540 void CFWL_ComboBoxImpDelegate::DoSubCtrlKey(CFWL_MsgKey* pMsg) { | |
| 1541 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | |
| 1542 const bool bUp = dwKeyCode == FWL_VKEY_Up; | |
| 1543 const bool bDown = dwKeyCode == FWL_VKEY_Down; | |
| 1544 if (bUp || bDown) { | |
| 1545 int32_t iCount = | |
| 1546 static_cast<CFWL_ComboListImp*>(m_pOwner->m_pListBox->GetImpl()) | |
| 1547 ->CountItems(); | |
| 1548 if (iCount < 1) { | |
| 1549 return; | |
| 1550 } | |
| 1551 FX_BOOL bMatchEqual = FALSE; | |
| 1552 int32_t iCurSel = m_pOwner->m_iCurSel; | |
| 1553 FX_BOOL bDropDown = m_pOwner->IsDropDownStyle(); | |
| 1554 if (bDropDown && m_pOwner->m_pEdit) { | |
| 1555 CFX_WideString wsText; | |
| 1556 m_pOwner->m_pEdit->GetText(wsText); | |
| 1557 iCurSel = static_cast<CFWL_ComboListImp*>(m_pOwner->m_pListBox->GetImpl()) | |
| 1558 ->MatchItem(wsText); | |
| 1559 if (iCurSel >= 0) { | |
| 1560 CFX_WideString wsTemp; | |
| 1561 IFWL_ComboBoxDP* pData = static_cast<IFWL_ComboBoxDP*>( | |
| 1562 m_pOwner->m_pProperties->m_pDataProvider); | |
| 1563 IFWL_ListItem* hItem = pData->GetItem(m_pOwner->m_pInterface, iCurSel); | |
| 1564 static_cast<CFWL_ComboListImp*>(m_pOwner->m_pListBox->GetImpl()) | |
| 1565 ->GetItemText(hItem, wsTemp); | |
| 1566 bMatchEqual = wsText == wsTemp; | |
| 1567 } | |
| 1568 } | |
| 1569 if (iCurSel < 0) { | |
| 1570 iCurSel = 0; | |
| 1571 } else if (!bDropDown || bMatchEqual) { | |
| 1572 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) { | |
| 1573 return; | |
| 1574 } | |
| 1575 if (bUp) { | |
| 1576 iCurSel--; | |
| 1577 } else { | |
| 1578 iCurSel++; | |
| 1579 } | |
| 1580 } | |
| 1581 m_pOwner->m_iCurSel = iCurSel; | |
| 1582 if (bDropDown && m_pOwner->m_pEdit) { | |
| 1583 m_pOwner->SynchrEditText(m_pOwner->m_iCurSel); | |
| 1584 } else { | |
| 1585 m_pOwner->Repaint(&m_pOwner->m_rtClient); | |
| 1586 } | |
| 1587 return; | |
| 1588 } | |
| 1589 FX_BOOL bDropDown = m_pOwner->IsDropDownStyle(); | |
| 1590 if (bDropDown) { | |
| 1591 IFWL_WidgetDelegate* pDelegate = m_pOwner->m_pEdit->SetDelegate(nullptr); | |
| 1592 pDelegate->OnProcessMessage(pMsg); | |
| 1593 } | |
| 1594 } | |
| 1595 void CFWL_ComboBoxImpDelegate::DisForm_OnProcessMessage( | |
| 1596 CFWL_Message* pMessage) { | |
| 1597 if (!pMessage) | |
| 1598 return; | |
| 1599 | |
| 1600 FX_BOOL backDefault = TRUE; | |
| 1601 switch (pMessage->GetClassID()) { | |
| 1602 case CFWL_MessageType::SetFocus: { | |
| 1603 backDefault = FALSE; | |
| 1604 DisForm_OnFocusChanged(pMessage, TRUE); | |
| 1605 break; | |
| 1606 } | |
| 1607 case CFWL_MessageType::KillFocus: { | |
| 1608 backDefault = FALSE; | |
| 1609 DisForm_OnFocusChanged(pMessage, FALSE); | |
| 1610 break; | |
| 1611 } | |
| 1612 case CFWL_MessageType::Mouse: { | |
| 1613 backDefault = FALSE; | |
| 1614 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 1615 switch (pMsg->m_dwCmd) { | |
| 1616 case FWL_MouseCommand::LeftButtonDown: { | |
| 1617 DisForm_OnLButtonDown(pMsg); | |
| 1618 break; | |
| 1619 } | |
| 1620 case FWL_MouseCommand::LeftButtonUp: { | |
| 1621 OnLButtonUp(pMsg); | |
| 1622 break; | |
| 1623 } | |
| 1624 default: | |
| 1625 break; | |
| 1626 } | |
| 1627 break; | |
| 1628 } | |
| 1629 case CFWL_MessageType::Key: { | |
| 1630 backDefault = FALSE; | |
| 1631 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | |
| 1632 if (pKey->m_dwCmd == FWL_KeyCommand::KeyUp) | |
| 1633 break; | |
| 1634 if (m_pOwner->DisForm_IsDropListShowed() && | |
| 1635 pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { | |
| 1636 FX_BOOL bListKey = pKey->m_dwKeyCode == FWL_VKEY_Up || | |
| 1637 pKey->m_dwKeyCode == FWL_VKEY_Down || | |
| 1638 pKey->m_dwKeyCode == FWL_VKEY_Return || | |
| 1639 pKey->m_dwKeyCode == FWL_VKEY_Escape; | |
| 1640 if (bListKey) { | |
| 1641 IFWL_WidgetDelegate* pDelegate = | |
| 1642 m_pOwner->m_pListBox->SetDelegate(nullptr); | |
| 1643 pDelegate->OnProcessMessage(pMessage); | |
| 1644 break; | |
| 1645 } | |
| 1646 } | |
| 1647 DisForm_OnKey(pKey); | |
| 1648 break; | |
| 1649 } | |
| 1650 default: | |
| 1651 break; | |
| 1652 } | |
| 1653 if (backDefault) | |
| 1654 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | |
| 1655 } | |
| 1656 | |
| 1657 void CFWL_ComboBoxImpDelegate::DisForm_OnLButtonDown(CFWL_MsgMouse* pMsg) { | |
| 1658 FX_BOOL bDropDown = m_pOwner->DisForm_IsDropListShowed(); | |
| 1659 CFX_RectF& rtBtn = bDropDown ? m_pOwner->m_rtBtn : m_pOwner->m_rtClient; | |
| 1660 FX_BOOL bClickBtn = rtBtn.Contains(pMsg->m_fx, pMsg->m_fy); | |
| 1661 if (bClickBtn) { | |
| 1662 if (m_pOwner->DisForm_IsDropListShowed()) { | |
| 1663 m_pOwner->DisForm_ShowDropList(FALSE); | |
| 1664 return; | |
| 1665 } | |
| 1666 { | |
| 1667 if (m_pOwner->m_pEdit) { | |
| 1668 m_pOwner->MatchEditText(); | |
| 1669 } | |
| 1670 m_pOwner->DisForm_ShowDropList(TRUE); | |
| 1671 } | |
| 1672 } | |
| 1673 } | |
| 1674 void CFWL_ComboBoxImpDelegate::DisForm_OnFocusChanged(CFWL_Message* pMsg, | |
| 1675 FX_BOOL bSet) { | |
| 1676 if (bSet) { | |
| 1677 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | |
| 1678 if ((m_pOwner->m_pEdit->GetStates() & FWL_WGTSTATE_Focused) == 0) { | |
| 1679 CFWL_MsgSetFocus msg; | |
| 1680 msg.m_pDstTarget = m_pOwner->m_pEdit.get(); | |
| 1681 msg.m_pSrcTarget = nullptr; | |
| 1682 IFWL_WidgetDelegate* pDelegate = m_pOwner->m_pEdit->SetDelegate(nullptr); | |
| 1683 pDelegate->OnProcessMessage(&msg); | |
| 1684 } | |
| 1685 } else { | |
| 1686 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | |
| 1687 m_pOwner->DisForm_ShowDropList(FALSE); | |
| 1688 CFWL_MsgKillFocus msg; | |
| 1689 msg.m_pDstTarget = nullptr; | |
| 1690 msg.m_pSrcTarget = m_pOwner->m_pEdit.get(); | |
| 1691 IFWL_WidgetDelegate* pDelegate = m_pOwner->m_pEdit->SetDelegate(nullptr); | |
| 1692 pDelegate->OnProcessMessage(&msg); | |
| 1693 } | |
| 1694 } | |
| 1695 void CFWL_ComboBoxImpDelegate::DisForm_OnKey(CFWL_MsgKey* pMsg) { | |
| 1696 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | |
| 1697 const bool bUp = dwKeyCode == FWL_VKEY_Up; | |
| 1698 const bool bDown = dwKeyCode == FWL_VKEY_Down; | |
| 1699 if (bUp || bDown) { | |
| 1700 CFWL_ComboListImp* pComboList = | |
| 1701 static_cast<CFWL_ComboListImp*>(m_pOwner->m_pListBox->GetImpl()); | |
| 1702 int32_t iCount = pComboList->CountItems(); | |
| 1703 if (iCount < 1) { | |
| 1704 return; | |
| 1705 } | |
| 1706 FX_BOOL bMatchEqual = FALSE; | |
| 1707 int32_t iCurSel = m_pOwner->m_iCurSel; | |
| 1708 if (m_pOwner->m_pEdit) { | |
| 1709 CFX_WideString wsText; | |
| 1710 m_pOwner->m_pEdit->GetText(wsText); | |
| 1711 iCurSel = pComboList->MatchItem(wsText); | |
| 1712 if (iCurSel >= 0) { | |
| 1713 CFX_WideString wsTemp; | |
| 1714 IFWL_ListItem* item = m_pOwner->m_pListBox->GetSelItem(iCurSel); | |
| 1715 m_pOwner->m_pListBox->GetItemText(item, wsTemp); | |
| 1716 bMatchEqual = wsText == wsTemp; | |
| 1717 } | |
| 1718 } | |
| 1719 if (iCurSel < 0) { | |
| 1720 iCurSel = 0; | |
| 1721 } else if (bMatchEqual) { | |
| 1722 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) { | |
| 1723 return; | |
| 1724 } | |
| 1725 if (bUp) { | |
| 1726 iCurSel--; | |
| 1727 } else { | |
| 1728 iCurSel++; | |
| 1729 } | |
| 1730 } | |
| 1731 m_pOwner->m_iCurSel = iCurSel; | |
| 1732 m_pOwner->SynchrEditText(m_pOwner->m_iCurSel); | |
| 1733 return; | |
| 1734 } | |
| 1735 if (m_pOwner->m_pEdit) { | |
| 1736 IFWL_WidgetDelegate* pDelegate = m_pOwner->m_pEdit->SetDelegate(nullptr); | |
| 1737 pDelegate->OnProcessMessage(pMsg); | |
| 1738 } | |
| 1739 } | |
| 1740 | |
| 1741 CFWL_ComboProxyImpDelegate::CFWL_ComboProxyImpDelegate( | |
| 1742 IFWL_Form* pForm, | |
| 1743 CFWL_ComboBoxImp* pComboBox) | |
| 1744 : m_bLButtonDown(FALSE), | |
| 1745 m_bLButtonUpSelf(FALSE), | |
| 1746 m_fStartPos(0), | |
| 1747 m_pForm(pForm), | |
| 1748 m_pComboBox(pComboBox) {} | |
| 1749 | |
| 1750 void CFWL_ComboProxyImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
| 1751 if (!pMessage) | |
| 1752 return; | |
| 1753 | |
| 1754 switch (pMessage->GetClassID()) { | |
| 1755 case CFWL_MessageType::Mouse: { | |
| 1756 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
| 1757 switch (pMsg->m_dwCmd) { | |
| 1758 case FWL_MouseCommand::LeftButtonDown: { | |
| 1759 OnLButtonDown(pMsg); | |
| 1760 break; | |
| 1761 } | |
| 1762 case FWL_MouseCommand::LeftButtonUp: { | |
| 1763 OnLButtonUp(pMsg); | |
| 1764 break; | |
| 1765 } | |
| 1766 case FWL_MouseCommand::Move: { | |
| 1767 OnMouseMove(pMsg); | |
| 1768 break; | |
| 1769 } | |
| 1770 default: | |
| 1771 break; | |
| 1772 } | |
| 1773 break; | |
| 1774 } | |
| 1775 case CFWL_MessageType::Deactivate: { | |
| 1776 OnDeactive(static_cast<CFWL_MsgDeactivate*>(pMessage)); | |
| 1777 break; | |
| 1778 } | |
| 1779 case CFWL_MessageType::KillFocus: { | |
| 1780 OnFocusChanged(static_cast<CFWL_MsgKillFocus*>(pMessage), FALSE); | |
| 1781 break; | |
| 1782 } | |
| 1783 case CFWL_MessageType::SetFocus: { | |
| 1784 OnFocusChanged(static_cast<CFWL_MsgKillFocus*>(pMessage), TRUE); | |
| 1785 break; | |
| 1786 } | |
| 1787 default: | |
| 1788 break; | |
| 1789 } | |
| 1790 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | |
| 1791 } | |
| 1792 | |
| 1793 void CFWL_ComboProxyImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
| 1794 const CFX_Matrix* pMatrix) { | |
| 1795 m_pComboBox->DrawStretchHandler(pGraphics, pMatrix); | |
| 1796 } | |
| 1797 | |
| 1798 void CFWL_ComboProxyImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | |
| 1799 IFWL_App* pApp = m_pForm->GetOwnerApp(); | |
| 1800 if (!pApp) | |
| 1801 return; | |
| 1802 | |
| 1803 CFWL_NoteDriver* pDriver = | |
| 1804 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
| 1805 CFX_RectF rtWidget; | |
| 1806 m_pForm->GetWidgetRect(rtWidget); | |
| 1807 rtWidget.left = rtWidget.top = 0; | |
| 1808 if (rtWidget.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
| 1809 m_bLButtonDown = TRUE; | |
| 1810 pDriver->SetGrab(m_pForm, TRUE); | |
| 1811 } else { | |
| 1812 m_bLButtonDown = FALSE; | |
| 1813 pDriver->SetGrab(m_pForm, FALSE); | |
| 1814 m_pComboBox->ShowDropList(FALSE); | |
| 1815 } | |
| 1816 } | |
| 1817 void CFWL_ComboProxyImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | |
| 1818 m_bLButtonDown = FALSE; | |
| 1819 IFWL_App* pApp = m_pForm->GetOwnerApp(); | |
| 1820 if (!pApp) | |
| 1821 return; | |
| 1822 | |
| 1823 CFWL_NoteDriver* pDriver = | |
| 1824 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
| 1825 pDriver->SetGrab(m_pForm, FALSE); | |
| 1826 if (m_bLButtonUpSelf) { | |
| 1827 CFX_RectF rect; | |
| 1828 m_pForm->GetWidgetRect(rect); | |
| 1829 rect.left = rect.top = 0; | |
| 1830 if (!rect.Contains(pMsg->m_fx, pMsg->m_fy) && | |
| 1831 m_pComboBox->IsDropListShowed()) { | |
| 1832 m_pComboBox->ShowDropList(FALSE); | |
| 1833 } | |
| 1834 } else { | |
| 1835 m_bLButtonUpSelf = TRUE; | |
| 1836 } | |
| 1837 } | |
| 1838 void CFWL_ComboProxyImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) {} | |
| 1839 void CFWL_ComboProxyImpDelegate::OnDeactive(CFWL_MsgDeactivate* pMsg) { | |
| 1840 m_pComboBox->ShowDropList(FALSE); | |
| 1841 } | |
| 1842 void CFWL_ComboProxyImpDelegate::OnFocusChanged(CFWL_MsgKillFocus* pMsg, | |
| 1843 FX_BOOL bSet) { | |
| 1844 if (!bSet) { | |
| 1845 if (!pMsg->m_pSetFocus) { | |
| 1846 m_pComboBox->ShowDropList(FALSE); | |
| 1847 } | |
| 1848 } | |
| 1849 } | |
| OLD | NEW |