Home | History | Annotate | Download | only in include
      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 _FWL_LISTBOX_IMP_H
      8 #define _FWL_LISTBOX_IMP_H
      9 
     10 #include <memory>
     11 
     12 class CFWL_WidgetImp;
     13 class CFWL_WidgetImpProperties;
     14 class CFWL_WidgetImpDelegate;
     15 class CFWL_ScrollBarImp;
     16 class IFWL_Widget;
     17 class CFWL_ListBoxImp;
     18 class CFWL_ListBoxImpDelegate;
     19 class CFWL_ListBoxImp : public CFWL_WidgetImp {
     20  public:
     21   CFWL_ListBoxImp(const CFWL_WidgetImpProperties& properties,
     22                   IFWL_Widget* pOuter);
     23   ~CFWL_ListBoxImp();
     24   virtual FWL_ERR GetClassName(CFX_WideString& wsClass) const;
     25   virtual FX_DWORD GetClassID() const;
     26   virtual FWL_ERR Initialize();
     27   virtual FWL_ERR Finalize();
     28   virtual FWL_ERR GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize = FALSE);
     29   virtual FWL_ERR Update();
     30   virtual FX_DWORD HitTest(FX_FLOAT fx, FX_FLOAT fy);
     31   virtual FWL_ERR DrawWidget(CFX_Graphics* pGraphics,
     32                              const CFX_Matrix* pMatrix = NULL);
     33   virtual FWL_ERR SetThemeProvider(IFWL_ThemeProvider* pThemeProvider);
     34   virtual int32_t CountSelItems();
     35   virtual FWL_HLISTITEM GetSelItem(int32_t nIndexSel);
     36   virtual int32_t GetSelIndex(int32_t nIndex);
     37   virtual FWL_ERR SetSelItem(FWL_HLISTITEM hItem, FX_BOOL bSelect = TRUE);
     38   virtual FWL_ERR GetItemText(FWL_HLISTITEM hItem, CFX_WideString& wsText);
     39   virtual FWL_ERR GetScrollPos(FX_FLOAT& fPos, FX_BOOL bVert = TRUE);
     40   virtual FWL_ERR* Sort(IFWL_ListBoxCompare* pCom);
     41 
     42  protected:
     43   FWL_HLISTITEM GetItem(FWL_HLISTITEM hItem, FX_DWORD dwKeyCode);
     44   void SetSelection(FWL_HLISTITEM hStart,
     45                     FWL_HLISTITEM hEnd,
     46                     FX_BOOL bSelected);
     47   void SetSelectionDirect(FWL_HLISTITEM hItem, FX_BOOL bSelect);
     48   FX_BOOL IsItemSelected(FWL_HLISTITEM hItem);
     49   void ClearSelection();
     50   void SelectAll();
     51   FWL_HLISTITEM GetFocusedItem();
     52   void SetFocusItem(FWL_HLISTITEM hItem);
     53   FWL_HLISTITEM GetItemAtPoint(FX_FLOAT fx, FX_FLOAT fy);
     54   FX_BOOL GetItemCheckRect(FWL_HLISTITEM hItem, CFX_RectF& rtCheck);
     55   FX_BOOL SetItemChecked(FWL_HLISTITEM hItem, FX_BOOL bChecked);
     56   FX_BOOL GetItemChecked(FWL_HLISTITEM hItem);
     57   FX_BOOL ScrollToVisible(FWL_HLISTITEM hItem);
     58   void DrawBkground(CFX_Graphics* pGraphics,
     59                     IFWL_ThemeProvider* pTheme,
     60                     const CFX_Matrix* pMatrix = NULL);
     61   void DrawItems(CFX_Graphics* pGraphics,
     62                  IFWL_ThemeProvider* pTheme,
     63                  const CFX_Matrix* pMatrix = NULL);
     64   void DrawItem(CFX_Graphics* pGraphics,
     65                 IFWL_ThemeProvider* pTheme,
     66                 FWL_HLISTITEM hItem,
     67                 int32_t Index,
     68                 const CFX_RectF& rtItem,
     69                 const CFX_Matrix* pMatrix = NULL);
     70   void DrawStatic(CFX_Graphics* pGraphics, IFWL_ThemeProvider* pTheme);
     71   CFX_SizeF CalcSize(FX_BOOL bAutoSize = FALSE);
     72   void GetItemSize(CFX_SizeF& size,
     73                    FWL_HLISTITEM hItem,
     74                    FX_FLOAT fWidth,
     75                    FX_FLOAT fHeight,
     76                    FX_BOOL bAutoSize = FALSE);
     77   FX_FLOAT GetMaxTextWidth();
     78   FX_FLOAT GetScrollWidth();
     79   FX_FLOAT GetItemHeigt();
     80   void InitScrollBar(FX_BOOL bVert = TRUE);
     81   void SortItem();
     82   FX_BOOL IsShowScrollBar(FX_BOOL bVert);
     83   void ProcessSelChanged();
     84 
     85  protected:
     86   CFX_RectF m_rtClient;
     87   CFX_RectF m_rtStatic;
     88   CFX_RectF m_rtConent;
     89   std::unique_ptr<IFWL_ScrollBar> m_pHorzScrollBar;
     90   std::unique_ptr<IFWL_ScrollBar> m_pVertScrollBar;
     91   FX_DWORD m_dwTTOStyles;
     92   int32_t m_iTTOAligns;
     93   FWL_HLISTITEM m_hAnchor;
     94   FX_FLOAT m_fItemHeight;
     95   FX_FLOAT m_fScorllBarWidth;
     96   FX_BOOL m_bLButtonDown;
     97   IFWL_ThemeProvider* m_pScrollBarTP;
     98   friend class CFWL_ListBoxImpDelegate;
     99 };
    100 class CFWL_ListBoxImpDelegate : public CFWL_WidgetImpDelegate {
    101  public:
    102   CFWL_ListBoxImpDelegate(CFWL_ListBoxImp* pOwner);
    103   int32_t OnProcessMessage(CFWL_Message* pMessage) override;
    104   FWL_ERR OnProcessEvent(CFWL_Event* pEvent) override;
    105   FWL_ERR OnDrawWidget(CFX_Graphics* pGraphics,
    106                        const CFX_Matrix* pMatrix = NULL) override;
    107 
    108  protected:
    109   void OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet = TRUE);
    110   void OnLButtonDown(CFWL_MsgMouse* pMsg);
    111   void OnLButtonUp(CFWL_MsgMouse* pMsg);
    112   void OnMouseWheel(CFWL_MsgMouseWheel* pMsg);
    113   void OnKeyDown(CFWL_MsgKey* pMsg);
    114   void OnVK(FWL_HLISTITEM hItem, FX_BOOL bShift, FX_BOOL bCtrl);
    115   FX_BOOL OnScroll(IFWL_ScrollBar* pScrollBar, FX_DWORD dwCode, FX_FLOAT fPos);
    116   void DispatchSelChangedEv();
    117   CFWL_ListBoxImp* m_pOwner;
    118 };
    119 #endif
    120