• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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/cfwl_comboedit.h"
8 
9 #include <memory>
10 #include <utility>
11 
12 #include "xfa/fde/cfde_texteditengine.h"
13 #include "xfa/fwl/cfwl_combobox.h"
14 #include "xfa/fwl/cfwl_messagemouse.h"
15 
CFWL_ComboEdit(const CFWL_App * app,std::unique_ptr<CFWL_WidgetProperties> properties,CFWL_Widget * pOuter)16 CFWL_ComboEdit::CFWL_ComboEdit(
17     const CFWL_App* app,
18     std::unique_ptr<CFWL_WidgetProperties> properties,
19     CFWL_Widget* pOuter)
20     : CFWL_Edit(app, std::move(properties), pOuter) {
21 }
22 
23 CFWL_ComboEdit::~CFWL_ComboEdit() = default;
24 
ClearSelected()25 void CFWL_ComboEdit::ClearSelected() {
26   ClearSelection();
27   RepaintRect(GetRTClient());
28 }
29 
SetSelected()30 void CFWL_ComboEdit::SetSelected() {
31   FlagFocus(true);
32   SelectAll();
33 }
34 
FlagFocus(bool bSet)35 void CFWL_ComboEdit::FlagFocus(bool bSet) {
36   if (bSet) {
37     m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
38     return;
39   }
40 
41   m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
42   HideCaret(nullptr);
43 }
44 
OnProcessMessage(CFWL_Message * pMessage)45 void CFWL_ComboEdit::OnProcessMessage(CFWL_Message* pMessage) {
46   if (!pMessage)
47     return;
48 
49   bool backDefault = true;
50   switch (pMessage->GetType()) {
51     case CFWL_Message::Type::SetFocus: {
52       m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
53       backDefault = false;
54       break;
55     }
56     case CFWL_Message::Type::KillFocus: {
57       m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
58       backDefault = false;
59       break;
60     }
61     case CFWL_Message::Type::Mouse: {
62       CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
63       if ((pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) &&
64           ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)) {
65         SetSelected();
66       }
67       break;
68     }
69     default:
70       break;
71   }
72   if (backDefault)
73     CFWL_Edit::OnProcessMessage(pMessage);
74 }
75