Home | History | Annotate | Download | only in fwl
      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 
     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   m_pOuter = static_cast<CFWL_ComboBox*>(pOuter);
     22 }
     23 
     24 void CFWL_ComboEdit::ClearSelected() {
     25   ClearSelection();
     26   RepaintRect(GetRTClient());
     27 }
     28 
     29 void CFWL_ComboEdit::SetSelected() {
     30   FlagFocus(true);
     31   SelectAll();
     32 }
     33 
     34 void CFWL_ComboEdit::FlagFocus(bool bSet) {
     35   if (bSet) {
     36     m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
     37     return;
     38   }
     39 
     40   m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
     41   HideCaret(nullptr);
     42 }
     43 
     44 void CFWL_ComboEdit::OnProcessMessage(CFWL_Message* pMessage) {
     45   if (!pMessage)
     46     return;
     47 
     48   bool backDefault = true;
     49   switch (pMessage->GetType()) {
     50     case CFWL_Message::Type::SetFocus: {
     51       m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
     52       backDefault = false;
     53       break;
     54     }
     55     case CFWL_Message::Type::KillFocus: {
     56       m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
     57       backDefault = false;
     58       break;
     59     }
     60     case CFWL_Message::Type::Mouse: {
     61       CFWL_MessageMouse* pMsg = static_cast<CFWL_MessageMouse*>(pMessage);
     62       if ((pMsg->m_dwCmd == FWL_MouseCommand::LeftButtonDown) &&
     63           ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)) {
     64         SetSelected();
     65         m_pOuter->SetFocus(true);
     66       }
     67       break;
     68     }
     69     default:
     70       break;
     71   }
     72   if (backDefault)
     73     CFWL_Edit::OnProcessMessage(pMessage);
     74 }
     75