1 ///////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/msw/headerctrl.h
3 // Purpose:     wxMSW native wxHeaderCtrl
4 // Author:      Vadim Zeitlin
5 // Created:     2008-12-01
6 // Copyright:   (c) 2008 Vadim Zeitlin <vadim@wxwidgets.org>
7 // Licence:     wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
9 
10 #ifndef _WX_MSW_HEADERCTRL_H_
11 #define _WX_MSW_HEADERCTRL_H_
12 
13 class WXDLLIMPEXP_FWD_CORE wxImageList;
14 
15 // ----------------------------------------------------------------------------
16 // wxHeaderCtrl
17 // ----------------------------------------------------------------------------
18 
19 class WXDLLIMPEXP_CORE wxHeaderCtrl : public wxHeaderCtrlBase
20 {
21 public:
wxHeaderCtrl()22     wxHeaderCtrl()
23     {
24         Init();
25     }
26 
27     wxHeaderCtrl(wxWindow *parent,
28                  wxWindowID id = wxID_ANY,
29                  const wxPoint& pos = wxDefaultPosition,
30                  const wxSize& size = wxDefaultSize,
31                  long style = wxHD_DEFAULT_STYLE,
32                  const wxString& name = wxHeaderCtrlNameStr)
33     {
34         Init();
35 
36         Create(parent, id, pos, size, style, name);
37     }
38 
39     bool Create(wxWindow *parent,
40                 wxWindowID id = wxID_ANY,
41                 const wxPoint& pos = wxDefaultPosition,
42                 const wxSize& size = wxDefaultSize,
43                 long style = wxHD_DEFAULT_STYLE,
44                 const wxString& name = wxHeaderCtrlNameStr);
45 
46     virtual ~wxHeaderCtrl();
47 
48 
49 protected:
50     // override wxWindow methods which must be implemented by a new control
51     virtual wxSize DoGetBestSize() const;
52     virtual void DoSetSize(int x, int y,
53                            int width, int height,
54                            int sizeFlags = wxSIZE_AUTO);
55 
56 private:
57     // implement base class pure virtuals
58     virtual void DoSetCount(unsigned int count);
59     virtual unsigned int DoGetCount() const;
60     virtual void DoUpdate(unsigned int idx);
61 
62     virtual void DoScrollHorz(int dx);
63 
64     virtual void DoSetColumnsOrder(const wxArrayInt& order);
65     virtual wxArrayInt DoGetColumnsOrder() const;
66 
67     // override MSW-specific methods needed for new control
68     virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const;
69     virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result);
70 
71     // common part of all ctors
72     void Init();
73 
74     // wrapper around Header_InsertItem(): insert the item using information
75     // from the given column at the given index
76     void DoInsertItem(const wxHeaderColumn& col, unsigned int idx);
77 
78     // get the number of currently visible items: this is also the total number
79     // of items contained in the native control
80     int GetShownColumnsCount() const;
81 
82     // due to the discrepancy for the hidden columns which we know about but
83     // the native control does not, there can be a difference between the
84     // column indices we use and the ones used by the native control; these
85     // functions translate between them
86     //
87     // notice that MSWToNativeIdx() shouldn't be called for hidden columns and
88     // MSWFromNativeIdx() always returns an index of a visible column
89     int MSWToNativeIdx(int idx);
90     int MSWFromNativeIdx(int item);
91 
92     // this is the same as above but for order, not index
93     int MSWToNativeOrder(int order);
94     int MSWFromNativeOrder(int order);
95 
96     // get the event type corresponding to a click or double click event
97     // (depending on dblclk value) with the specified (using MSW convention)
98     // mouse button
99     wxEventType GetClickEventType(bool dblclk, int button);
100 
101 
102     // the number of columns in the control, including the hidden ones (not
103     // taken into account by the native control, see comment in DoGetCount())
104     unsigned int m_numColumns;
105 
106     // this is a lookup table allowing us to check whether the column with the
107     // given index is currently shown in the native control, in which case the
108     // value of this array element with this index is 0, or hidden
109     //
110     // notice that this may be different from GetColumn(idx).IsHidden() and in
111     // fact we need this array precisely because it will be different from it
112     // in DoUpdate() when the column hidden flag gets toggled and we need it to
113     // handle this transition correctly
114     wxArrayInt m_isHidden;
115 
116     // the order of our columns: this array contains the index of the column
117     // shown at the position n as the n-th element
118     //
119     // this is necessary only to handle the hidden columns: the native control
120     // doesn't know about them and so we can't use Header_GetOrderArray()
121     wxArrayInt m_colIndices;
122 
123     // the image list: initially NULL, created on demand
124     wxImageList *m_imageList;
125 
126     // the offset of the window used to emulate scrolling it
127     int m_scrollOffset;
128 
129     // actual column we are dragging or -1 if not dragging anything
130     int m_colBeingDragged;
131 
132     wxDECLARE_NO_COPY_CLASS(wxHeaderCtrl);
133 };
134 
135 #endif // _WX_MSW_HEADERCTRL_H_
136 
137