xref: /aosp_15_r20/external/pdfium/xfa/fwl/cfwl_comboedit.cpp (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2016 The PDFium Authors
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 "xfa/fde/cfde_texteditengine.h"
10 #include "xfa/fwl/cfwl_combobox.h"
11 #include "xfa/fwl/cfwl_messagemouse.h"
12 
CFWL_ComboEdit(CFWL_App * app,const Properties & properties,CFWL_Widget * pOuter)13 CFWL_ComboEdit::CFWL_ComboEdit(CFWL_App* app,
14                                const Properties& properties,
15                                CFWL_Widget* pOuter)
16     : CFWL_Edit(app, properties, pOuter) {}
17 
18 CFWL_ComboEdit::~CFWL_ComboEdit() = default;
19 
ClearSelected()20 void CFWL_ComboEdit::ClearSelected() {
21   ClearSelection();
22   RepaintRect(GetRTClient());
23 }
24 
SetSelected()25 void CFWL_ComboEdit::SetSelected() {
26   m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
27   SelectAll();
28 }
29 
OnProcessMessage(CFWL_Message * pMessage)30 void CFWL_ComboEdit::OnProcessMessage(CFWL_Message* pMessage) {
31   bool backDefault = true;
32   switch (pMessage->GetType()) {
33     case CFWL_Message::Type::kSetFocus: {
34       m_Properties.m_dwStates |= FWL_STATE_WGT_Focused;
35       backDefault = false;
36       break;
37     }
38     case CFWL_Message::Type::kKillFocus: {
39       m_Properties.m_dwStates &= ~FWL_STATE_WGT_Focused;
40       backDefault = false;
41       break;
42     }
43     case CFWL_Message::Type::kMouse: {
44       CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
45       if ((pMsg->m_dwCmd == CFWL_MessageMouse::MouseCommand::kLeftButtonDown) &&
46           ((m_Properties.m_dwStates & FWL_STATE_WGT_Focused) == 0)) {
47         SetSelected();
48       }
49       break;
50     }
51     default:
52       break;
53   }
54   if (backDefault)
55     CFWL_Edit::OnProcessMessage(pMessage);
56 }
57