OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fwl/core/ifwl_combobox.h" | 7 #include "xfa/fwl/core/ifwl_combobox.h" |
8 | 8 |
9 #include "third_party/base/ptr_util.h" | 9 #include "third_party/base/ptr_util.h" |
10 #include "xfa/fde/cfde_txtedtengine.h" | 10 #include "xfa/fde/cfde_txtedtengine.h" |
11 #include "xfa/fde/tto/fde_textout.h" | 11 #include "xfa/fde/tto/fde_textout.h" |
12 #include "xfa/fwl/core/cfwl_message.h" | 12 #include "xfa/fwl/core/cfwl_message.h" |
13 #include "xfa/fwl/core/cfwl_themebackground.h" | 13 #include "xfa/fwl/core/cfwl_themebackground.h" |
14 #include "xfa/fwl/core/cfwl_themepart.h" | 14 #include "xfa/fwl/core/cfwl_themepart.h" |
15 #include "xfa/fwl/core/cfwl_themetext.h" | 15 #include "xfa/fwl/core/cfwl_themetext.h" |
16 #include "xfa/fwl/core/cfwl_widgetmgr.h" | 16 #include "xfa/fwl/core/cfwl_widgetmgr.h" |
17 #include "xfa/fwl/core/fwl_noteimp.h" | 17 #include "xfa/fwl/core/fwl_noteimp.h" |
18 #include "xfa/fwl/core/ifwl_app.h" | 18 #include "xfa/fwl/core/ifwl_app.h" |
| 19 #include "xfa/fwl/core/ifwl_comboboxproxy.h" |
19 #include "xfa/fwl/core/ifwl_comboedit.h" | 20 #include "xfa/fwl/core/ifwl_comboedit.h" |
20 #include "xfa/fwl/core/ifwl_combolist.h" | 21 #include "xfa/fwl/core/ifwl_combolist.h" |
21 #include "xfa/fwl/core/ifwl_formproxy.h" | 22 #include "xfa/fwl/core/ifwl_formproxy.h" |
22 #include "xfa/fwl/core/ifwl_themeprovider.h" | 23 #include "xfa/fwl/core/ifwl_themeprovider.h" |
23 | 24 |
24 IFWL_ComboBox::IFWL_ComboBox(const IFWL_App* app, | 25 IFWL_ComboBox::IFWL_ComboBox(const IFWL_App* app, |
25 const CFWL_WidgetImpProperties& properties) | 26 const CFWL_WidgetImpProperties& properties) |
26 : IFWL_Widget(app, properties, nullptr), | 27 : IFWL_Widget(app, properties, nullptr), |
27 m_pForm(nullptr), | 28 m_pComboBoxProxy(nullptr), |
28 m_bLButtonDown(FALSE), | 29 m_bLButtonDown(FALSE), |
29 m_iCurSel(-1), | 30 m_iCurSel(-1), |
30 m_iBtnState(CFWL_PartState_Normal), | 31 m_iBtnState(CFWL_PartState_Normal), |
31 m_fComboFormHandler(0), | 32 m_fComboFormHandler(0), |
32 m_bNeedShowList(FALSE) { | 33 m_bNeedShowList(FALSE) { |
33 m_rtClient.Reset(); | 34 m_rtClient.Reset(); |
34 m_rtBtn.Reset(); | 35 m_rtBtn.Reset(); |
35 m_rtHandler.Reset(); | 36 m_rtHandler.Reset(); |
36 | 37 |
37 SetDelegate(pdfium::MakeUnique<CFWL_ComboBoxImpDelegate>(this)); | |
38 | |
39 if (m_pWidgetMgr->IsFormDisabled()) { | 38 if (m_pWidgetMgr->IsFormDisabled()) { |
40 DisForm_InitComboList(); | 39 DisForm_InitComboList(); |
41 DisForm_InitComboEdit(); | 40 DisForm_InitComboEdit(); |
42 return; | 41 return; |
43 } | 42 } |
44 | 43 |
45 CFWL_WidgetImpProperties prop; | 44 CFWL_WidgetImpProperties prop; |
46 prop.m_pThemeProvider = m_pProperties->m_pThemeProvider; | 45 prop.m_pThemeProvider = m_pProperties->m_pThemeProvider; |
47 prop.m_dwStyles |= FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; | 46 prop.m_dwStyles |= FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; |
48 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemIconText) | 47 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_ListItemIconText) |
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 param.m_dwStates = CFWL_PartState_Normal; | 447 param.m_dwStates = CFWL_PartState_Normal; |
449 param.m_pWidget = this; | 448 param.m_pWidget = this; |
450 if (pMatrix) { | 449 if (pMatrix) { |
451 param.m_matrix.Concat(*pMatrix); | 450 param.m_matrix.Concat(*pMatrix); |
452 } | 451 } |
453 param.m_rtPart = m_rtHandler; | 452 param.m_rtPart = m_rtHandler; |
454 m_pProperties->m_pThemeProvider->DrawBackground(¶m); | 453 m_pProperties->m_pThemeProvider->DrawBackground(¶m); |
455 } | 454 } |
456 | 455 |
457 void IFWL_ComboBox::ShowDropList(FX_BOOL bActivate) { | 456 void IFWL_ComboBox::ShowDropList(FX_BOOL bActivate) { |
458 if (m_pWidgetMgr->IsFormDisabled()) { | 457 if (m_pWidgetMgr->IsFormDisabled()) |
459 return DisForm_ShowDropList(bActivate); | 458 return DisForm_ShowDropList(bActivate); |
460 } | 459 |
461 FX_BOOL bDropList = IsDropListShowed(); | 460 FX_BOOL bDropList = IsDropListShowed(); |
462 if (bDropList == bActivate) { | 461 if (bDropList == bActivate) |
463 return; | 462 return; |
464 } | 463 if (!m_pComboBoxProxy) |
465 if (!m_pForm) { | |
466 InitProxyForm(); | 464 InitProxyForm(); |
467 } | 465 |
468 m_pListProxyDelegate->Reset(); | 466 m_pComboBoxProxy->Reset(); |
469 if (bActivate) { | 467 if (bActivate) { |
470 m_pListBox->ChangeSelected(m_iCurSel); | 468 m_pListBox->ChangeSelected(m_iCurSel); |
471 ReSetListItemAlignment(); | 469 ReSetListItemAlignment(); |
472 uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & | 470 uint32_t dwStyleAdd = m_pProperties->m_dwStyleExes & |
473 (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); | 471 (FWL_STYLEEXT_CMB_Sort | FWL_STYLEEXT_CMB_OwnerDraw); |
474 m_pListBox->ModifyStylesEx(dwStyleAdd, 0); | 472 m_pListBox->ModifyStylesEx(dwStyleAdd, 0); |
475 m_pListBox->GetWidgetRect(m_rtList, TRUE); | 473 m_pListBox->GetWidgetRect(m_rtList, TRUE); |
476 FX_FLOAT fHeight = GetListHeight(); | 474 FX_FLOAT fHeight = GetListHeight(); |
477 if (fHeight > 0) { | 475 if (fHeight > 0) { |
478 if (m_rtList.height > GetListHeight()) { | 476 if (m_rtList.height > GetListHeight()) { |
(...skipping 19 matching lines...) Expand all Loading... |
498 TransformTo(nullptr, fx, fy); | 496 TransformTo(nullptr, fx, fy); |
499 m_bUpFormHandler = fy > m_rtProxy.top; | 497 m_bUpFormHandler = fy > m_rtProxy.top; |
500 if (m_bUpFormHandler) { | 498 if (m_bUpFormHandler) { |
501 m_rtHandler.Set(0, 0, m_rtList.width, m_fComboFormHandler); | 499 m_rtHandler.Set(0, 0, m_rtList.width, m_fComboFormHandler); |
502 m_rtList.top = m_fComboFormHandler; | 500 m_rtList.top = m_fComboFormHandler; |
503 } else { | 501 } else { |
504 m_rtHandler.Set(0, m_rtList.height, m_rtList.width, | 502 m_rtHandler.Set(0, m_rtList.height, m_rtList.width, |
505 m_fComboFormHandler); | 503 m_fComboFormHandler); |
506 } | 504 } |
507 } | 505 } |
508 m_pForm->SetWidgetRect(m_rtProxy); | 506 m_pComboBoxProxy->SetWidgetRect(m_rtProxy); |
509 m_pForm->Update(); | 507 m_pComboBoxProxy->Update(); |
510 m_pListBox->SetWidgetRect(m_rtList); | 508 m_pListBox->SetWidgetRect(m_rtList); |
511 m_pListBox->Update(); | 509 m_pListBox->Update(); |
512 CFWL_EvtCmbPreDropDown ev; | 510 CFWL_EvtCmbPreDropDown ev; |
513 ev.m_pSrcTarget = this; | 511 ev.m_pSrcTarget = this; |
514 DispatchEvent(&ev); | 512 DispatchEvent(&ev); |
515 m_fItemHeight = m_pListBox->m_fItemHeight; | 513 m_fItemHeight = m_pListBox->m_fItemHeight; |
516 m_pListBox->SetFocus(TRUE); | 514 m_pListBox->SetFocus(TRUE); |
517 m_pForm->DoModal(); | 515 m_pComboBoxProxy->DoModal(); |
518 m_pListBox->SetFocus(FALSE); | 516 m_pListBox->SetFocus(FALSE); |
519 } else { | 517 } else { |
520 m_pForm->EndDoModal(); | 518 m_pComboBoxProxy->EndDoModal(); |
521 CFWL_EvtCmbCloseUp ev; | 519 CFWL_EvtCmbCloseUp ev; |
522 ev.m_pSrcTarget = this; | 520 ev.m_pSrcTarget = this; |
523 DispatchEvent(&ev); | 521 DispatchEvent(&ev); |
524 m_bLButtonDown = FALSE; | 522 m_bLButtonDown = FALSE; |
525 m_pListBox->m_bNotifyOwner = TRUE; | 523 m_pListBox->m_bNotifyOwner = TRUE; |
526 SetFocus(TRUE); | 524 SetFocus(TRUE); |
527 } | 525 } |
528 } | 526 } |
529 | 527 |
530 FX_BOOL IFWL_ComboBox::IsDropListShowed() { | 528 FX_BOOL IFWL_ComboBox::IsDropListShowed() { |
531 return m_pForm && !(m_pForm->GetStates() & FWL_WGTSTATE_Invisible); | 529 return m_pComboBoxProxy && |
| 530 !(m_pComboBoxProxy->GetStates() & FWL_WGTSTATE_Invisible); |
532 } | 531 } |
533 | 532 |
534 FX_BOOL IFWL_ComboBox::IsDropDownStyle() const { | 533 FX_BOOL IFWL_ComboBox::IsDropDownStyle() const { |
535 return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown; | 534 return m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown; |
536 } | 535 } |
537 | 536 |
538 void IFWL_ComboBox::MatchEditText() { | 537 void IFWL_ComboBox::MatchEditText() { |
539 CFX_WideString wsText; | 538 CFX_WideString wsText; |
540 m_pEdit->GetText(wsText); | 539 m_pEdit->GetText(wsText); |
541 int32_t iMatch = m_pListBox->MatchItem(wsText); | 540 int32_t iMatch = m_pListBox->MatchItem(wsText); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 ev.m_pSrcTarget = this; | 681 ev.m_pSrcTarget = this; |
683 ev.iArraySels.Add(m_iCurSel); | 682 ev.iArraySels.Add(m_iCurSel); |
684 DispatchEvent(&ev); | 683 DispatchEvent(&ev); |
685 } | 684 } |
686 } else { | 685 } else { |
687 Repaint(&m_rtClient); | 686 Repaint(&m_rtClient); |
688 } | 687 } |
689 } | 688 } |
690 | 689 |
691 void IFWL_ComboBox::InitProxyForm() { | 690 void IFWL_ComboBox::InitProxyForm() { |
692 if (m_pForm) | 691 if (m_pComboBoxProxy) |
693 return; | 692 return; |
694 if (!m_pListBox) | 693 if (!m_pListBox) |
695 return; | 694 return; |
696 | 695 |
697 CFWL_WidgetImpProperties propForm; | 696 CFWL_WidgetImpProperties propForm; |
698 propForm.m_pOwner = this; | 697 propForm.m_pOwner = this; |
699 propForm.m_dwStyles = FWL_WGTSTYLE_Popup; | 698 propForm.m_dwStyles = FWL_WGTSTYLE_Popup; |
700 propForm.m_dwStates = FWL_WGTSTATE_Invisible; | 699 propForm.m_dwStates = FWL_WGTSTATE_Invisible; |
701 | 700 |
702 m_pForm = new IFWL_FormProxy(m_pOwnerApp, propForm, m_pListBox.get()); | 701 m_pComboBoxProxy = |
703 m_pListBox->SetParent(m_pForm); | 702 new IFWL_ComboBoxProxy(this, m_pOwnerApp, propForm, m_pListBox.get()); |
704 m_pListProxyDelegate = new CFWL_ComboProxyImpDelegate(m_pForm, this); | 703 m_pListBox->SetParent(m_pComboBoxProxy); |
705 m_pForm->SetCurrentDelegate(m_pListProxyDelegate); | |
706 } | 704 } |
707 | 705 |
708 void IFWL_ComboBox::DisForm_InitComboList() { | 706 void IFWL_ComboBox::DisForm_InitComboList() { |
709 if (m_pListBox) | 707 if (m_pListBox) |
710 return; | 708 return; |
711 | 709 |
712 CFWL_WidgetImpProperties prop; | 710 CFWL_WidgetImpProperties prop; |
713 prop.m_pParent = this; | 711 prop.m_pParent = this; |
714 prop.m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; | 712 prop.m_dwStyles = FWL_WGTSTYLE_Border | FWL_WGTSTYLE_VScroll; |
715 prop.m_dwStates = FWL_WGTSTATE_Invisible; | 713 prop.m_dwStates = FWL_WGTSTATE_Invisible; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
907 IFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); | 905 IFWL_ListItem* hItem = pData->GetItem(this, m_iCurSel); |
908 m_pListBox->GetItemText(hItem, wsText); | 906 m_pListBox->GetItemText(hItem, wsText); |
909 m_pEdit->LockUpdate(); | 907 m_pEdit->LockUpdate(); |
910 m_pEdit->SetText(wsText); | 908 m_pEdit->SetText(wsText); |
911 m_pEdit->UnlockUpdate(); | 909 m_pEdit->UnlockUpdate(); |
912 } | 910 } |
913 m_pEdit->Update(); | 911 m_pEdit->Update(); |
914 } | 912 } |
915 } | 913 } |
916 | 914 |
917 CFWL_ComboBoxImpDelegate::CFWL_ComboBoxImpDelegate(IFWL_ComboBox* pOwner) | 915 void IFWL_ComboBox::OnProcessMessage(CFWL_Message* pMessage) { |
918 : m_pOwner(pOwner) {} | 916 if (m_pWidgetMgr->IsFormDisabled()) { |
919 | |
920 void CFWL_ComboBoxImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
921 if (m_pOwner->m_pWidgetMgr->IsFormDisabled()) { | |
922 DisForm_OnProcessMessage(pMessage); | 917 DisForm_OnProcessMessage(pMessage); |
923 return; | 918 return; |
924 } | 919 } |
925 if (!pMessage) | 920 if (!pMessage) |
926 return; | 921 return; |
927 | 922 |
928 switch (pMessage->GetClassID()) { | 923 switch (pMessage->GetClassID()) { |
929 case CFWL_MessageType::SetFocus: { | 924 case CFWL_MessageType::SetFocus: |
930 OnFocusChanged(pMessage, TRUE); | 925 OnFocusChanged(pMessage, TRUE); |
931 break; | 926 break; |
932 } | 927 case CFWL_MessageType::KillFocus: |
933 case CFWL_MessageType::KillFocus: { | |
934 OnFocusChanged(pMessage, FALSE); | 928 OnFocusChanged(pMessage, FALSE); |
935 break; | 929 break; |
936 } | |
937 case CFWL_MessageType::Mouse: { | 930 case CFWL_MessageType::Mouse: { |
938 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 931 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
939 switch (pMsg->m_dwCmd) { | 932 switch (pMsg->m_dwCmd) { |
940 case FWL_MouseCommand::LeftButtonDown: { | 933 case FWL_MouseCommand::LeftButtonDown: |
941 OnLButtonDown(pMsg); | 934 OnLButtonDown(pMsg); |
942 break; | 935 break; |
943 } | 936 case FWL_MouseCommand::LeftButtonUp: |
944 case FWL_MouseCommand::LeftButtonUp: { | |
945 OnLButtonUp(pMsg); | 937 OnLButtonUp(pMsg); |
946 break; | 938 break; |
947 } | 939 case FWL_MouseCommand::Move: |
948 case FWL_MouseCommand::Move: { | |
949 OnMouseMove(pMsg); | 940 OnMouseMove(pMsg); |
950 break; | 941 break; |
951 } | 942 case FWL_MouseCommand::Leave: |
952 case FWL_MouseCommand::Leave: { | |
953 OnMouseLeave(pMsg); | 943 OnMouseLeave(pMsg); |
954 break; | 944 break; |
955 } | |
956 default: | 945 default: |
957 break; | 946 break; |
958 } | 947 } |
959 break; | 948 break; |
960 } | 949 } |
961 case CFWL_MessageType::Key: { | 950 case CFWL_MessageType::Key: |
962 OnKey(static_cast<CFWL_MsgKey*>(pMessage)); | 951 OnKey(static_cast<CFWL_MsgKey*>(pMessage)); |
963 break; | 952 break; |
964 } | 953 default: |
965 default: { break; } | 954 break; |
966 } | 955 } |
967 | 956 |
968 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | 957 IFWL_Widget::OnProcessMessage(pMessage); |
969 } | 958 } |
970 | 959 |
971 void CFWL_ComboBoxImpDelegate::OnProcessEvent(CFWL_Event* pEvent) { | 960 void IFWL_ComboBox::OnProcessEvent(CFWL_Event* pEvent) { |
972 CFWL_EventType dwFlag = pEvent->GetClassID(); | 961 CFWL_EventType dwFlag = pEvent->GetClassID(); |
973 if (dwFlag == CFWL_EventType::DrawItem) { | 962 if (dwFlag == CFWL_EventType::DrawItem) { |
974 CFWL_EvtLtbDrawItem* pDrawItemEvent = | 963 CFWL_EvtLtbDrawItem* pDrawItemEvent = |
975 static_cast<CFWL_EvtLtbDrawItem*>(pEvent); | 964 static_cast<CFWL_EvtLtbDrawItem*>(pEvent); |
976 CFWL_EvtCmbDrawItem pTemp; | 965 CFWL_EvtCmbDrawItem pTemp; |
977 pTemp.m_pSrcTarget = m_pOwner; | 966 pTemp.m_pSrcTarget = this; |
978 pTemp.m_pGraphics = pDrawItemEvent->m_pGraphics; | 967 pTemp.m_pGraphics = pDrawItemEvent->m_pGraphics; |
979 pTemp.m_index = pDrawItemEvent->m_index; | 968 pTemp.m_index = pDrawItemEvent->m_index; |
980 pTemp.m_rtItem = pDrawItemEvent->m_rect; | 969 pTemp.m_rtItem = pDrawItemEvent->m_rect; |
981 m_pOwner->DispatchEvent(&pTemp); | 970 DispatchEvent(&pTemp); |
982 } else if (dwFlag == CFWL_EventType::Scroll) { | 971 } else if (dwFlag == CFWL_EventType::Scroll) { |
983 CFWL_EvtScroll* pScrollEvent = static_cast<CFWL_EvtScroll*>(pEvent); | 972 CFWL_EvtScroll* pScrollEvent = static_cast<CFWL_EvtScroll*>(pEvent); |
984 CFWL_EvtScroll pScrollEv; | 973 CFWL_EvtScroll pScrollEv; |
985 pScrollEv.m_pSrcTarget = m_pOwner; | 974 pScrollEv.m_pSrcTarget = this; |
986 pScrollEv.m_iScrollCode = pScrollEvent->m_iScrollCode; | 975 pScrollEv.m_iScrollCode = pScrollEvent->m_iScrollCode; |
987 pScrollEv.m_fPos = pScrollEvent->m_fPos; | 976 pScrollEv.m_fPos = pScrollEvent->m_fPos; |
988 m_pOwner->DispatchEvent(&pScrollEv); | 977 DispatchEvent(&pScrollEv); |
989 } else if (dwFlag == CFWL_EventType::TextChanged) { | 978 } else if (dwFlag == CFWL_EventType::TextChanged) { |
990 CFWL_EvtEdtTextChanged* pTextChangedEvent = | 979 CFWL_EvtEdtTextChanged* pTextChangedEvent = |
991 static_cast<CFWL_EvtEdtTextChanged*>(pEvent); | 980 static_cast<CFWL_EvtEdtTextChanged*>(pEvent); |
992 CFWL_EvtCmbEditChanged pTemp; | 981 CFWL_EvtCmbEditChanged pTemp; |
993 pTemp.m_pSrcTarget = m_pOwner; | 982 pTemp.m_pSrcTarget = this; |
994 pTemp.wsInsert = pTextChangedEvent->wsInsert; | 983 pTemp.wsInsert = pTextChangedEvent->wsInsert; |
995 pTemp.wsDelete = pTextChangedEvent->wsDelete; | 984 pTemp.wsDelete = pTextChangedEvent->wsDelete; |
996 pTemp.nChangeType = pTextChangedEvent->nChangeType; | 985 pTemp.nChangeType = pTextChangedEvent->nChangeType; |
997 m_pOwner->DispatchEvent(&pTemp); | 986 DispatchEvent(&pTemp); |
998 } | 987 } |
999 } | 988 } |
1000 | 989 |
1001 void CFWL_ComboBoxImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | 990 void IFWL_ComboBox::OnDrawWidget(CFX_Graphics* pGraphics, |
1002 const CFX_Matrix* pMatrix) { | 991 const CFX_Matrix* pMatrix) { |
1003 m_pOwner->DrawWidget(pGraphics, pMatrix); | 992 DrawWidget(pGraphics, pMatrix); |
1004 } | 993 } |
1005 | 994 |
1006 void CFWL_ComboBoxImpDelegate::OnFocusChanged(CFWL_Message* pMsg, | 995 void IFWL_ComboBox::OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) { |
1007 FX_BOOL bSet) { | |
1008 IFWL_Widget* pDstTarget = pMsg->m_pDstTarget; | 996 IFWL_Widget* pDstTarget = pMsg->m_pDstTarget; |
1009 IFWL_Widget* pSrcTarget = pMsg->m_pSrcTarget; | 997 IFWL_Widget* pSrcTarget = pMsg->m_pSrcTarget; |
1010 FX_BOOL bDropDown = m_pOwner->IsDropDownStyle(); | 998 FX_BOOL bDropDown = IsDropDownStyle(); |
1011 if (bSet) { | 999 if (bSet) { |
1012 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | 1000 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
1013 if (bDropDown && pSrcTarget != m_pOwner->m_pListBox.get()) { | 1001 if (bDropDown && pSrcTarget != m_pListBox.get()) { |
1014 if (!m_pOwner->m_pEdit) | 1002 if (!m_pEdit) |
1015 return; | 1003 return; |
1016 m_pOwner->m_pEdit->SetSelected(); | 1004 m_pEdit->SetSelected(); |
1017 } else { | 1005 } else { |
1018 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 1006 Repaint(&m_rtClient); |
1019 } | 1007 } |
1020 } else { | 1008 } else { |
1021 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | 1009 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
1022 if (bDropDown && pDstTarget != m_pOwner->m_pListBox.get()) { | 1010 if (bDropDown && pDstTarget != m_pListBox.get()) { |
1023 if (!m_pOwner->m_pEdit) | 1011 if (!m_pEdit) |
1024 return; | 1012 return; |
1025 m_pOwner->m_pEdit->FlagFocus(FALSE); | 1013 m_pEdit->FlagFocus(FALSE); |
1026 m_pOwner->m_pEdit->ClearSelected(); | 1014 m_pEdit->ClearSelected(); |
1027 } else { | 1015 } else { |
1028 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 1016 Repaint(&m_rtClient); |
1029 } | 1017 } |
1030 } | 1018 } |
1031 } | 1019 } |
1032 | 1020 |
1033 void CFWL_ComboBoxImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 1021 void IFWL_ComboBox::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
1034 if (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) { | 1022 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
1035 return; | 1023 return; |
1036 } | 1024 |
1037 FX_BOOL bDropDown = m_pOwner->IsDropDownStyle(); | 1025 FX_BOOL bDropDown = IsDropDownStyle(); |
1038 CFX_RectF& rtBtn = bDropDown ? m_pOwner->m_rtBtn : m_pOwner->m_rtClient; | 1026 CFX_RectF& rtBtn = bDropDown ? m_rtBtn : m_rtClient; |
1039 FX_BOOL bClickBtn = rtBtn.Contains(pMsg->m_fx, pMsg->m_fy); | 1027 FX_BOOL bClickBtn = rtBtn.Contains(pMsg->m_fx, pMsg->m_fy); |
1040 if (bClickBtn) { | 1028 if (!bClickBtn) |
1041 if (bDropDown && m_pOwner->m_pEdit) { | 1029 return; |
1042 m_pOwner->MatchEditText(); | 1030 |
1043 } | 1031 if (bDropDown && m_pEdit) |
1044 m_pOwner->m_bLButtonDown = TRUE; | 1032 MatchEditText(); |
1045 m_pOwner->m_iBtnState = CFWL_PartState_Pressed; | 1033 |
1046 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 1034 m_bLButtonDown = TRUE; |
1047 m_pOwner->ShowDropList(TRUE); | 1035 m_iBtnState = CFWL_PartState_Pressed; |
1048 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | 1036 Repaint(&m_rtClient); |
1049 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 1037 ShowDropList(TRUE); |
1050 } | 1038 m_iBtnState = CFWL_PartState_Normal; |
1051 } | 1039 Repaint(&m_rtClient); |
1052 | 1040 } |
1053 void CFWL_ComboBoxImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | 1041 |
1054 m_pOwner->m_bLButtonDown = FALSE; | 1042 void IFWL_ComboBox::OnLButtonUp(CFWL_MsgMouse* pMsg) { |
1055 if (m_pOwner->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | 1043 m_bLButtonDown = FALSE; |
1056 m_pOwner->m_iBtnState = CFWL_PartState_Hovered; | 1044 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) |
| 1045 m_iBtnState = CFWL_PartState_Hovered; |
| 1046 else |
| 1047 m_iBtnState = CFWL_PartState_Normal; |
| 1048 |
| 1049 Repaint(&m_rtBtn); |
| 1050 } |
| 1051 |
| 1052 void IFWL_ComboBox::OnMouseMove(CFWL_MsgMouse* pMsg) { |
| 1053 int32_t iOldState = m_iBtnState; |
| 1054 if (m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { |
| 1055 m_iBtnState = |
| 1056 m_bLButtonDown ? CFWL_PartState_Pressed : CFWL_PartState_Hovered; |
1057 } else { | 1057 } else { |
1058 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | 1058 m_iBtnState = CFWL_PartState_Normal; |
1059 } | 1059 } |
1060 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | 1060 if ((iOldState != m_iBtnState) && |
1061 } | 1061 !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == |
1062 | |
1063 void CFWL_ComboBoxImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) { | |
1064 int32_t iOldState = m_pOwner->m_iBtnState; | |
1065 if (m_pOwner->m_rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
1066 m_pOwner->m_iBtnState = m_pOwner->m_bLButtonDown ? CFWL_PartState_Pressed | |
1067 : CFWL_PartState_Hovered; | |
1068 } else { | |
1069 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | |
1070 } | |
1071 if ((iOldState != m_pOwner->m_iBtnState) && | |
1072 !((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == | |
1073 FWL_WGTSTATE_Disabled)) { | 1062 FWL_WGTSTATE_Disabled)) { |
1074 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | 1063 Repaint(&m_rtBtn); |
1075 } | 1064 } |
1076 } | 1065 } |
1077 | 1066 |
1078 void CFWL_ComboBoxImpDelegate::OnMouseLeave(CFWL_MsgMouse* pMsg) { | 1067 void IFWL_ComboBox::OnMouseLeave(CFWL_MsgMouse* pMsg) { |
1079 if (!m_pOwner->IsDropListShowed() && | 1068 if (!IsDropListShowed() && |
1080 !((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == | 1069 !((m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) == |
1081 FWL_WGTSTATE_Disabled)) { | 1070 FWL_WGTSTATE_Disabled)) { |
1082 m_pOwner->m_iBtnState = CFWL_PartState_Normal; | 1071 m_iBtnState = CFWL_PartState_Normal; |
1083 m_pOwner->Repaint(&m_pOwner->m_rtBtn); | 1072 Repaint(&m_rtBtn); |
1084 } | 1073 } |
1085 } | 1074 } |
1086 | 1075 |
1087 void CFWL_ComboBoxImpDelegate::OnKey(CFWL_MsgKey* pMsg) { | 1076 void IFWL_ComboBox::OnKey(CFWL_MsgKey* pMsg) { |
1088 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | 1077 uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
1089 if (dwKeyCode == FWL_VKEY_Tab) { | 1078 if (dwKeyCode == FWL_VKEY_Tab) { |
1090 m_pOwner->DispatchKeyEvent(pMsg); | 1079 DispatchKeyEvent(pMsg); |
1091 return; | 1080 return; |
1092 } | 1081 } |
1093 if (pMsg->m_pDstTarget == m_pOwner) | 1082 if (pMsg->m_pDstTarget == this) |
1094 DoSubCtrlKey(pMsg); | 1083 DoSubCtrlKey(pMsg); |
1095 } | 1084 } |
1096 | 1085 |
1097 void CFWL_ComboBoxImpDelegate::DoSubCtrlKey(CFWL_MsgKey* pMsg) { | 1086 void IFWL_ComboBox::DoSubCtrlKey(CFWL_MsgKey* pMsg) { |
1098 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | 1087 uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
1099 const bool bUp = dwKeyCode == FWL_VKEY_Up; | 1088 const bool bUp = dwKeyCode == FWL_VKEY_Up; |
1100 const bool bDown = dwKeyCode == FWL_VKEY_Down; | 1089 const bool bDown = dwKeyCode == FWL_VKEY_Down; |
1101 if (bUp || bDown) { | 1090 if (bUp || bDown) { |
1102 int32_t iCount = m_pOwner->m_pListBox->CountItems(); | 1091 int32_t iCount = m_pListBox->CountItems(); |
1103 if (iCount < 1) { | 1092 if (iCount < 1) |
1104 return; | 1093 return; |
1105 } | 1094 |
1106 FX_BOOL bMatchEqual = FALSE; | 1095 FX_BOOL bMatchEqual = FALSE; |
1107 int32_t iCurSel = m_pOwner->m_iCurSel; | 1096 int32_t iCurSel = m_iCurSel; |
1108 FX_BOOL bDropDown = m_pOwner->IsDropDownStyle(); | 1097 FX_BOOL bDropDown = IsDropDownStyle(); |
1109 if (bDropDown && m_pOwner->m_pEdit) { | 1098 if (bDropDown && m_pEdit) { |
1110 CFX_WideString wsText; | 1099 CFX_WideString wsText; |
1111 m_pOwner->m_pEdit->GetText(wsText); | 1100 m_pEdit->GetText(wsText); |
1112 iCurSel = m_pOwner->m_pListBox->MatchItem(wsText); | 1101 iCurSel = m_pListBox->MatchItem(wsText); |
1113 if (iCurSel >= 0) { | 1102 if (iCurSel >= 0) { |
1114 CFX_WideString wsTemp; | 1103 CFX_WideString wsTemp; |
1115 IFWL_ComboBoxDP* pData = static_cast<IFWL_ComboBoxDP*>( | 1104 IFWL_ComboBoxDP* pData = |
1116 m_pOwner->m_pProperties->m_pDataProvider); | 1105 static_cast<IFWL_ComboBoxDP*>(m_pProperties->m_pDataProvider); |
1117 IFWL_ListItem* hItem = pData->GetItem(m_pOwner, iCurSel); | 1106 IFWL_ListItem* hItem = pData->GetItem(this, iCurSel); |
1118 m_pOwner->m_pListBox->GetItemText(hItem, wsTemp); | 1107 m_pListBox->GetItemText(hItem, wsTemp); |
1119 bMatchEqual = wsText == wsTemp; | 1108 bMatchEqual = wsText == wsTemp; |
1120 } | 1109 } |
1121 } | 1110 } |
1122 if (iCurSel < 0) { | 1111 if (iCurSel < 0) { |
1123 iCurSel = 0; | 1112 iCurSel = 0; |
1124 } else if (!bDropDown || bMatchEqual) { | 1113 } else if (!bDropDown || bMatchEqual) { |
1125 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) { | 1114 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) |
1126 return; | 1115 return; |
1127 } | 1116 if (bUp) |
1128 if (bUp) { | |
1129 iCurSel--; | 1117 iCurSel--; |
1130 } else { | 1118 else |
1131 iCurSel++; | 1119 iCurSel++; |
1132 } | 1120 } |
1133 } | 1121 m_iCurSel = iCurSel; |
1134 m_pOwner->m_iCurSel = iCurSel; | 1122 if (bDropDown && m_pEdit) |
1135 if (bDropDown && m_pOwner->m_pEdit) { | 1123 SynchrEditText(m_iCurSel); |
1136 m_pOwner->SynchrEditText(m_pOwner->m_iCurSel); | 1124 else |
1137 } else { | 1125 Repaint(&m_rtClient); |
1138 m_pOwner->Repaint(&m_pOwner->m_rtClient); | 1126 return; |
1139 } | 1127 } |
1140 return; | 1128 |
1141 } | 1129 FX_BOOL bDropDown = IsDropDownStyle(); |
1142 FX_BOOL bDropDown = m_pOwner->IsDropDownStyle(); | |
1143 if (bDropDown) | 1130 if (bDropDown) |
1144 m_pOwner->m_pEdit->GetCurrentDelegate()->OnProcessMessage(pMsg); | 1131 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
1145 } | 1132 } |
1146 | 1133 |
1147 void CFWL_ComboBoxImpDelegate::DisForm_OnProcessMessage( | 1134 void IFWL_ComboBox::DisForm_OnProcessMessage(CFWL_Message* pMessage) { |
1148 CFWL_Message* pMessage) { | |
1149 if (!pMessage) | 1135 if (!pMessage) |
1150 return; | 1136 return; |
1151 | 1137 |
1152 FX_BOOL backDefault = TRUE; | 1138 FX_BOOL backDefault = TRUE; |
1153 switch (pMessage->GetClassID()) { | 1139 switch (pMessage->GetClassID()) { |
1154 case CFWL_MessageType::SetFocus: { | 1140 case CFWL_MessageType::SetFocus: { |
1155 backDefault = FALSE; | 1141 backDefault = FALSE; |
1156 DisForm_OnFocusChanged(pMessage, TRUE); | 1142 DisForm_OnFocusChanged(pMessage, TRUE); |
1157 break; | 1143 break; |
1158 } | 1144 } |
1159 case CFWL_MessageType::KillFocus: { | 1145 case CFWL_MessageType::KillFocus: { |
1160 backDefault = FALSE; | 1146 backDefault = FALSE; |
1161 DisForm_OnFocusChanged(pMessage, FALSE); | 1147 DisForm_OnFocusChanged(pMessage, FALSE); |
1162 break; | 1148 break; |
1163 } | 1149 } |
1164 case CFWL_MessageType::Mouse: { | 1150 case CFWL_MessageType::Mouse: { |
1165 backDefault = FALSE; | 1151 backDefault = FALSE; |
1166 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | 1152 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); |
1167 switch (pMsg->m_dwCmd) { | 1153 switch (pMsg->m_dwCmd) { |
1168 case FWL_MouseCommand::LeftButtonDown: { | 1154 case FWL_MouseCommand::LeftButtonDown: |
1169 DisForm_OnLButtonDown(pMsg); | 1155 DisForm_OnLButtonDown(pMsg); |
1170 break; | 1156 break; |
1171 } | 1157 case FWL_MouseCommand::LeftButtonUp: |
1172 case FWL_MouseCommand::LeftButtonUp: { | |
1173 OnLButtonUp(pMsg); | 1158 OnLButtonUp(pMsg); |
1174 break; | 1159 break; |
1175 } | |
1176 default: | 1160 default: |
1177 break; | 1161 break; |
1178 } | 1162 } |
1179 break; | 1163 break; |
1180 } | 1164 } |
1181 case CFWL_MessageType::Key: { | 1165 case CFWL_MessageType::Key: { |
1182 backDefault = FALSE; | 1166 backDefault = FALSE; |
1183 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); | 1167 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage); |
1184 if (pKey->m_dwCmd == FWL_KeyCommand::KeyUp) | 1168 if (pKey->m_dwCmd == FWL_KeyCommand::KeyUp) |
1185 break; | 1169 break; |
1186 if (m_pOwner->DisForm_IsDropListShowed() && | 1170 if (DisForm_IsDropListShowed() && |
1187 pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { | 1171 pKey->m_dwCmd == FWL_KeyCommand::KeyDown) { |
1188 FX_BOOL bListKey = pKey->m_dwKeyCode == FWL_VKEY_Up || | 1172 FX_BOOL bListKey = pKey->m_dwKeyCode == FWL_VKEY_Up || |
1189 pKey->m_dwKeyCode == FWL_VKEY_Down || | 1173 pKey->m_dwKeyCode == FWL_VKEY_Down || |
1190 pKey->m_dwKeyCode == FWL_VKEY_Return || | 1174 pKey->m_dwKeyCode == FWL_VKEY_Return || |
1191 pKey->m_dwKeyCode == FWL_VKEY_Escape; | 1175 pKey->m_dwKeyCode == FWL_VKEY_Escape; |
1192 if (bListKey) { | 1176 if (bListKey) { |
1193 m_pOwner->m_pListBox->GetCurrentDelegate()->OnProcessMessage( | 1177 m_pListBox->GetDelegate()->OnProcessMessage(pMessage); |
1194 pMessage); | |
1195 break; | 1178 break; |
1196 } | 1179 } |
1197 } | 1180 } |
1198 DisForm_OnKey(pKey); | 1181 DisForm_OnKey(pKey); |
1199 break; | 1182 break; |
1200 } | 1183 } |
1201 default: | 1184 default: |
1202 break; | 1185 break; |
1203 } | 1186 } |
1204 if (backDefault) | 1187 if (backDefault) |
1205 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | 1188 IFWL_Widget::OnProcessMessage(pMessage); |
1206 } | 1189 } |
1207 | 1190 |
1208 void CFWL_ComboBoxImpDelegate::DisForm_OnLButtonDown(CFWL_MsgMouse* pMsg) { | 1191 void IFWL_ComboBox::DisForm_OnLButtonDown(CFWL_MsgMouse* pMsg) { |
1209 FX_BOOL bDropDown = m_pOwner->DisForm_IsDropListShowed(); | 1192 FX_BOOL bDropDown = DisForm_IsDropListShowed(); |
1210 CFX_RectF& rtBtn = bDropDown ? m_pOwner->m_rtBtn : m_pOwner->m_rtClient; | 1193 CFX_RectF& rtBtn = bDropDown ? m_rtBtn : m_rtClient; |
1211 FX_BOOL bClickBtn = rtBtn.Contains(pMsg->m_fx, pMsg->m_fy); | 1194 if (!rtBtn.Contains(pMsg->m_fx, pMsg->m_fy)) |
1212 if (bClickBtn) { | 1195 return; |
1213 if (m_pOwner->DisForm_IsDropListShowed()) { | 1196 |
1214 m_pOwner->DisForm_ShowDropList(FALSE); | 1197 if (DisForm_IsDropListShowed()) { |
1215 return; | 1198 DisForm_ShowDropList(FALSE); |
| 1199 return; |
| 1200 } |
| 1201 if (m_pEdit) |
| 1202 MatchEditText(); |
| 1203 DisForm_ShowDropList(TRUE); |
| 1204 } |
| 1205 |
| 1206 void IFWL_ComboBox::DisForm_OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) { |
| 1207 if (bSet) { |
| 1208 m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; |
| 1209 if ((m_pEdit->GetStates() & FWL_WGTSTATE_Focused) == 0) { |
| 1210 CFWL_MsgSetFocus msg; |
| 1211 msg.m_pDstTarget = m_pEdit.get(); |
| 1212 msg.m_pSrcTarget = nullptr; |
| 1213 m_pEdit->GetDelegate()->OnProcessMessage(&msg); |
1216 } | 1214 } |
1217 { | 1215 } else { |
1218 if (m_pOwner->m_pEdit) { | 1216 m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; |
1219 m_pOwner->MatchEditText(); | 1217 DisForm_ShowDropList(FALSE); |
1220 } | 1218 CFWL_MsgKillFocus msg; |
1221 m_pOwner->DisForm_ShowDropList(TRUE); | 1219 msg.m_pDstTarget = nullptr; |
1222 } | 1220 msg.m_pSrcTarget = m_pEdit.get(); |
| 1221 m_pEdit->GetDelegate()->OnProcessMessage(&msg); |
1223 } | 1222 } |
1224 } | 1223 } |
1225 | 1224 |
1226 void CFWL_ComboBoxImpDelegate::DisForm_OnFocusChanged(CFWL_Message* pMsg, | 1225 void IFWL_ComboBox::DisForm_OnKey(CFWL_MsgKey* pMsg) { |
1227 FX_BOOL bSet) { | |
1228 if (bSet) { | |
1229 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused; | |
1230 if ((m_pOwner->m_pEdit->GetStates() & FWL_WGTSTATE_Focused) == 0) { | |
1231 CFWL_MsgSetFocus msg; | |
1232 msg.m_pDstTarget = m_pOwner->m_pEdit.get(); | |
1233 msg.m_pSrcTarget = nullptr; | |
1234 m_pOwner->m_pEdit->GetCurrentDelegate()->OnProcessMessage(&msg); | |
1235 } | |
1236 } else { | |
1237 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused; | |
1238 m_pOwner->DisForm_ShowDropList(FALSE); | |
1239 CFWL_MsgKillFocus msg; | |
1240 msg.m_pDstTarget = nullptr; | |
1241 msg.m_pSrcTarget = m_pOwner->m_pEdit.get(); | |
1242 m_pOwner->m_pEdit->GetCurrentDelegate()->OnProcessMessage(&msg); | |
1243 } | |
1244 } | |
1245 | |
1246 void CFWL_ComboBoxImpDelegate::DisForm_OnKey(CFWL_MsgKey* pMsg) { | |
1247 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | 1226 uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
1248 const bool bUp = dwKeyCode == FWL_VKEY_Up; | 1227 const bool bUp = dwKeyCode == FWL_VKEY_Up; |
1249 const bool bDown = dwKeyCode == FWL_VKEY_Down; | 1228 const bool bDown = dwKeyCode == FWL_VKEY_Down; |
1250 if (bUp || bDown) { | 1229 if (bUp || bDown) { |
1251 IFWL_ComboList* pComboList = m_pOwner->m_pListBox.get(); | 1230 IFWL_ComboList* pComboList = m_pListBox.get(); |
1252 int32_t iCount = pComboList->CountItems(); | 1231 int32_t iCount = pComboList->CountItems(); |
1253 if (iCount < 1) { | 1232 if (iCount < 1) |
1254 return; | 1233 return; |
1255 } | 1234 |
1256 FX_BOOL bMatchEqual = FALSE; | 1235 FX_BOOL bMatchEqual = FALSE; |
1257 int32_t iCurSel = m_pOwner->m_iCurSel; | 1236 int32_t iCurSel = m_iCurSel; |
1258 if (m_pOwner->m_pEdit) { | 1237 if (m_pEdit) { |
1259 CFX_WideString wsText; | 1238 CFX_WideString wsText; |
1260 m_pOwner->m_pEdit->GetText(wsText); | 1239 m_pEdit->GetText(wsText); |
1261 iCurSel = pComboList->MatchItem(wsText); | 1240 iCurSel = pComboList->MatchItem(wsText); |
1262 if (iCurSel >= 0) { | 1241 if (iCurSel >= 0) { |
1263 CFX_WideString wsTemp; | 1242 CFX_WideString wsTemp; |
1264 IFWL_ListItem* item = m_pOwner->m_pListBox->GetSelItem(iCurSel); | 1243 IFWL_ListItem* item = m_pListBox->GetSelItem(iCurSel); |
1265 m_pOwner->m_pListBox->GetItemText(item, wsTemp); | 1244 m_pListBox->GetItemText(item, wsTemp); |
1266 bMatchEqual = wsText == wsTemp; | 1245 bMatchEqual = wsText == wsTemp; |
1267 } | 1246 } |
1268 } | 1247 } |
1269 if (iCurSel < 0) { | 1248 if (iCurSel < 0) { |
1270 iCurSel = 0; | 1249 iCurSel = 0; |
1271 } else if (bMatchEqual) { | 1250 } else if (bMatchEqual) { |
1272 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) { | 1251 if ((bUp && iCurSel == 0) || (bDown && iCurSel == iCount - 1)) |
1273 return; | 1252 return; |
1274 } | 1253 if (bUp) |
1275 if (bUp) { | |
1276 iCurSel--; | 1254 iCurSel--; |
1277 } else { | 1255 else |
1278 iCurSel++; | 1256 iCurSel++; |
1279 } | |
1280 } | 1257 } |
1281 m_pOwner->m_iCurSel = iCurSel; | 1258 m_iCurSel = iCurSel; |
1282 m_pOwner->SynchrEditText(m_pOwner->m_iCurSel); | 1259 SynchrEditText(m_iCurSel); |
1283 return; | 1260 return; |
1284 } | 1261 } |
1285 if (m_pOwner->m_pEdit) | 1262 if (m_pEdit) |
1286 m_pOwner->m_pEdit->GetCurrentDelegate()->OnProcessMessage(pMsg); | 1263 m_pEdit->GetDelegate()->OnProcessMessage(pMsg); |
1287 } | 1264 } |
1288 | |
1289 CFWL_ComboProxyImpDelegate::CFWL_ComboProxyImpDelegate(IFWL_Form* pForm, | |
1290 IFWL_ComboBox* pComboBox) | |
1291 : m_bLButtonDown(FALSE), | |
1292 m_bLButtonUpSelf(FALSE), | |
1293 m_fStartPos(0), | |
1294 m_pForm(pForm), | |
1295 m_pComboBox(pComboBox) {} | |
1296 | |
1297 void CFWL_ComboProxyImpDelegate::OnProcessMessage(CFWL_Message* pMessage) { | |
1298 if (!pMessage) | |
1299 return; | |
1300 | |
1301 switch (pMessage->GetClassID()) { | |
1302 case CFWL_MessageType::Mouse: { | |
1303 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage); | |
1304 switch (pMsg->m_dwCmd) { | |
1305 case FWL_MouseCommand::LeftButtonDown: { | |
1306 OnLButtonDown(pMsg); | |
1307 break; | |
1308 } | |
1309 case FWL_MouseCommand::LeftButtonUp: { | |
1310 OnLButtonUp(pMsg); | |
1311 break; | |
1312 } | |
1313 case FWL_MouseCommand::Move: { | |
1314 OnMouseMove(pMsg); | |
1315 break; | |
1316 } | |
1317 default: | |
1318 break; | |
1319 } | |
1320 break; | |
1321 } | |
1322 case CFWL_MessageType::Deactivate: { | |
1323 OnDeactive(static_cast<CFWL_MsgDeactivate*>(pMessage)); | |
1324 break; | |
1325 } | |
1326 case CFWL_MessageType::KillFocus: { | |
1327 OnFocusChanged(static_cast<CFWL_MsgKillFocus*>(pMessage), FALSE); | |
1328 break; | |
1329 } | |
1330 case CFWL_MessageType::SetFocus: { | |
1331 OnFocusChanged(static_cast<CFWL_MsgKillFocus*>(pMessage), TRUE); | |
1332 break; | |
1333 } | |
1334 default: | |
1335 break; | |
1336 } | |
1337 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage); | |
1338 } | |
1339 | |
1340 void CFWL_ComboProxyImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics, | |
1341 const CFX_Matrix* pMatrix) { | |
1342 m_pComboBox->DrawStretchHandler(pGraphics, pMatrix); | |
1343 } | |
1344 | |
1345 void CFWL_ComboProxyImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) { | |
1346 const IFWL_App* pApp = m_pForm->GetOwnerApp(); | |
1347 if (!pApp) | |
1348 return; | |
1349 | |
1350 CFWL_NoteDriver* pDriver = | |
1351 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
1352 CFX_RectF rtWidget; | |
1353 m_pForm->GetWidgetRect(rtWidget); | |
1354 rtWidget.left = rtWidget.top = 0; | |
1355 if (rtWidget.Contains(pMsg->m_fx, pMsg->m_fy)) { | |
1356 m_bLButtonDown = TRUE; | |
1357 pDriver->SetGrab(m_pForm, TRUE); | |
1358 } else { | |
1359 m_bLButtonDown = FALSE; | |
1360 pDriver->SetGrab(m_pForm, FALSE); | |
1361 m_pComboBox->ShowDropList(FALSE); | |
1362 } | |
1363 } | |
1364 | |
1365 void CFWL_ComboProxyImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) { | |
1366 m_bLButtonDown = FALSE; | |
1367 const IFWL_App* pApp = m_pForm->GetOwnerApp(); | |
1368 if (!pApp) | |
1369 return; | |
1370 | |
1371 CFWL_NoteDriver* pDriver = | |
1372 static_cast<CFWL_NoteDriver*>(pApp->GetNoteDriver()); | |
1373 pDriver->SetGrab(m_pForm, FALSE); | |
1374 if (m_bLButtonUpSelf) { | |
1375 CFX_RectF rect; | |
1376 m_pForm->GetWidgetRect(rect); | |
1377 rect.left = rect.top = 0; | |
1378 if (!rect.Contains(pMsg->m_fx, pMsg->m_fy) && | |
1379 m_pComboBox->IsDropListShowed()) { | |
1380 m_pComboBox->ShowDropList(FALSE); | |
1381 } | |
1382 } else { | |
1383 m_bLButtonUpSelf = TRUE; | |
1384 } | |
1385 } | |
1386 | |
1387 void CFWL_ComboProxyImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) {} | |
1388 | |
1389 void CFWL_ComboProxyImpDelegate::OnDeactive(CFWL_MsgDeactivate* pMsg) { | |
1390 m_pComboBox->ShowDropList(FALSE); | |
1391 } | |
1392 | |
1393 void CFWL_ComboProxyImpDelegate::OnFocusChanged(CFWL_MsgKillFocus* pMsg, | |
1394 FX_BOOL bSet) { | |
1395 if (!bSet) { | |
1396 if (!pMsg->m_pSetFocus) { | |
1397 m_pComboBox->ShowDropList(FALSE); | |
1398 } | |
1399 } | |
1400 } | |
OLD | NEW |