• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef XFA_FWL_CFWL_COMBOBOX_H_
8 #define XFA_FWL_CFWL_COMBOBOX_H_
9 
10 #include <memory>
11 
12 #include "xfa/fwl/cfwl_comboedit.h"
13 #include "xfa/fwl/cfwl_combolist.h"
14 #include "xfa/fwl/cfwl_listbox.h"
15 #include "xfa/fxgraphics/cxfa_graphics.h"
16 
17 class CFWL_WidgetProperties;
18 class CFWL_ComboBox;
19 class CFWL_ListBox;
20 class CFWL_Widget;
21 
22 #define FWL_STYLEEXT_CMB_DropDown (1L << 0)
23 #define FWL_STYLEEXT_CMB_Sort (1L << 1)
24 #define FWL_STYLEEXT_CMB_OwnerDraw (1L << 3)
25 #define FWL_STYLEEXT_CMB_EditHNear 0
26 #define FWL_STYLEEXT_CMB_EditHCenter (1L << 4)
27 #define FWL_STYLEEXT_CMB_EditVNear 0
28 #define FWL_STYLEEXT_CMB_EditVCenter (1L << 6)
29 #define FWL_STYLEEXT_CMB_EditVFar (2L << 6)
30 #define FWL_STYLEEXT_CMB_EditJustified (1L << 8)
31 #define FWL_STYLEEXT_CMB_EditHAlignMask (3L << 4)
32 #define FWL_STYLEEXT_CMB_EditVAlignMask (3L << 6)
33 #define FWL_STYLEEXT_CMB_ListItemLeftAlign 0
34 #define FWL_STYLEEXT_CMB_ListItemCenterAlign (1L << 10)
35 #define FWL_STYLEEXT_CMB_ListItemAlignMask (3L << 10)
36 #define FWL_STYLEEXT_CMB_ReadOnly (1L << 13)
37 
38 class CFWL_ComboBox final : public CFWL_Widget {
39  public:
40   explicit CFWL_ComboBox(const CFWL_App* pApp);
41   ~CFWL_ComboBox() override;
42 
43   // CFWL_Widget
44   FWL_Type GetClassID() const override;
45   void ModifyStylesEx(uint32_t dwStylesExAdded,
46                       uint32_t dwStylesExRemoved) override;
47   void SetStates(uint32_t dwStates) override;
48   void RemoveStates(uint32_t dwStates) override;
49   void Update() override;
50   FWL_WidgetHit HitTest(const CFX_PointF& point) override;
51   void DrawWidget(CXFA_Graphics* pGraphics, const CFX_Matrix& matrix) override;
52   void SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) override;
53   void OnProcessMessage(CFWL_Message* pMessage) override;
54   void OnProcessEvent(CFWL_Event* pEvent) override;
55   void OnDrawWidget(CXFA_Graphics* pGraphics,
56                     const CFX_Matrix& matrix) override;
57 
58   WideString GetTextByIndex(int32_t iIndex) const;
GetCurSel()59   int32_t GetCurSel() const { return m_iCurSel; }
60   void SetCurSel(int32_t iSel);
61 
62   void AddString(const WideString& wsText);
63   void RemoveAt(int32_t iIndex);
64   void RemoveAll();
65 
66   void SetEditText(const WideString& wsText);
67   WideString GetEditText() const;
68 
69   void OpenDropDownList(bool bActivate);
70 
EditCanUndo()71   bool EditCanUndo() const { return m_pEdit->CanUndo(); }
EditCanRedo()72   bool EditCanRedo() const { return m_pEdit->CanRedo(); }
EditUndo()73   bool EditUndo() { return m_pEdit->Undo(); }
EditRedo()74   bool EditRedo() { return m_pEdit->Redo(); }
EditCanCopy()75   bool EditCanCopy() const { return m_pEdit->HasSelection(); }
EditCanCut()76   bool EditCanCut() const {
77     if (m_pEdit->GetStylesEx() & FWL_STYLEEXT_EDT_ReadOnly)
78       return false;
79     return EditCanCopy();
80   }
EditCanSelectAll()81   bool EditCanSelectAll() const { return m_pEdit->GetTextLength() > 0; }
EditCopy()82   Optional<WideString> EditCopy() const { return m_pEdit->Copy(); }
EditCut()83   Optional<WideString> EditCut() { return m_pEdit->Cut(); }
EditPaste(const WideString & wsPaste)84   bool EditPaste(const WideString& wsPaste) { return m_pEdit->Paste(wsPaste); }
EditSelectAll()85   void EditSelectAll() { m_pEdit->SelectAll(); }
EditDelete()86   void EditDelete() { m_pEdit->ClearText(); }
EditDeSelect()87   void EditDeSelect() { m_pEdit->ClearSelection(); }
88 
89   CFX_RectF GetBBox() const;
90   void EditModifyStylesEx(uint32_t dwStylesExAdded, uint32_t dwStylesExRemoved);
91   void ShowDropList(bool bActivate);
92 
GetComboEdit()93   CFWL_ComboEdit* GetComboEdit() const { return m_pEdit.get(); }
94 
95   void ProcessSelChanged(bool bLButtonUp);
GetCurrentSelection()96   int32_t GetCurrentSelection() const { return m_iCurSel; }
97 
98  private:
IsDropDownStyle()99   bool IsDropDownStyle() const {
100     return !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_CMB_DropDown);
101   }
102   void MatchEditText();
103   void SyncEditText(int32_t iListItem);
104   void Layout();
105   void ResetTheme();
106   void ResetEditAlignment();
107   void ResetListItemAlignment();
108   void GetPopupPos(float fMinHeight,
109                    float fMaxHeight,
110                    const CFX_RectF& rtAnchor,
111                    CFX_RectF* pPopupRect);
112   void OnLButtonUp(CFWL_MessageMouse* pMsg);
113 
114   void InitComboList();
115   void InitComboEdit();
IsDropListVisible()116   bool IsDropListVisible() const { return m_pListBox->IsVisible(); }
117   void OnLButtonDown(CFWL_MessageMouse* pMsg);
118   void OnFocusChanged(CFWL_Message* pMsg, bool bSet);
119   void OnKey(CFWL_MessageKey* pMsg);
120 
121   CFX_RectF m_rtClient;
122   CFX_RectF m_rtContent;
123   CFX_RectF m_rtBtn;
124   std::unique_ptr<CFWL_ComboEdit> m_pEdit;
125   std::unique_ptr<CFWL_ComboList> m_pListBox;
126   int32_t m_iCurSel = -1;
127   int32_t m_iBtnState = CFWL_PartState_Normal;
128 };
129 
130 #endif  // XFA_FWL_CFWL_COMBOBOX_H_
131