NCBI C++ ToolKit
splitter.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_WX_DEMO___SPLITTER__HPP
2 #define GUI_WX_DEMO___SPLITTER__HPP
3 
4 /* $Id: splitter.hpp 25479 2012-03-27 14:55:33Z kuznets $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  * File Description:
32  * CSplitter - and extended version of splitter for wxWidgets.
33  */
34 
35 #include <corelib/ncbistd.hpp>
36 
37 #include <gui/gui_export.h>
38 
39 #include <wx/panel.h>
40 
41 
43 
44 ///////////////////////////////////////////////////////////////////////////////
45 /// CSplitter - container with resizable separators.
46 ///
47 /// CSplitter arranges child windows in to one- or two-dimensional array.
48 /// Cells in CSplitter are divided by separators that can be moved by the
49 /// mouse. Every cell in CSplitter can be occupied by a single child window
50 /// and every window can occupy only one cell.
51 
53  : public wxPanel
54 {
55  DECLARE_EVENT_TABLE()
56 public:
57  typedef wxPanel TParent;
58  typedef vector<int> TPosVector;
59  typedef vector<int> TSizeVector;
60 
61  /// ESplitMode - splitter orientation
62  enum ESplitType {
63  eVertical, /// vertical space is splitted
64  eHorizontal, /// horizontal space is splitted
65  eGrid /// cells are separated with in both directions
66  };
67 
68  CSplitter();
69 
70  CSplitter(wxWindow* parent,
71  wxWindowID id = wxID_ANY,
72  const wxPoint& pos = wxDefaultPosition,
73  const wxSize& size = wxDefaultSize,
74  long style = wxTAB_TRAVERSAL,
75  const wxString& name = wxT("panel"));
76 
77  CSplitter(wxWindow* parent,
78  wxWindowID id = wxID_ANY,
79  ESplitType type = eVertical);
80 
81  virtual ~CSplitter();
82 
83  ESplitType GetSplitType() const;
84  int GetSeparatorSize() const;
85 
86  /// Creates a splitter with a single cell
87  virtual void Split(ESplitType type);
88 
89  /// Creates a splitter with cells defined by "sizes". If mode == eGrid then
90  /// size will be used as both width and heights
91  virtual void Split(ESplitType type, const TPosVector& sizes);
92 
93  /// Creates a splitter with cells defined by "sizes". If mode == eGrid then
94  /// ar_sizes will be used as both width and heights. "ar_sizes" is -1
95  /// terminated array.
96  virtual void Split(ESplitType type, const int ar_size[]);
97 
98  /// Creates splitter, "widths" and "height" define number and sizes of
99  /// cells.
100  virtual void Split(ESplitType type, const TPosVector& widths, const TPosVector& heights);
101 
102  /// Creates splitter, "ar_w" and "ar_h" are arrays terminated by -1.
103  virtual void Split(ESplitType type, const int ar_w[], const int ar_h[]);
104 
105  virtual void Split(int col_n, int row_n);
106 
107  int GetColumnsCount() const;
108  int GetRowsCount() const;
109 
110  void GetWidths(TPosVector& widths) const;
111  void SetWidths(const TPosVector& widths);
112 
113  void GetHeights(TPosVector& heights) const;
114  void SetHeights(const TPosVector& heights);
115 
116  // is set, this cell will resize first trying to "consume" any changes in availble space
117  // caused by the splitter resizing or separator dragging
118  void SetResizableCell(int col, int row);
119 
120  virtual bool Layout();
121  virtual bool Show(bool show = true);
122 
123  virtual void BlockLayout(bool block = true);
124 
125  /// returns "true" if cell specified by (col, row) exists in the splitter
126  bool IsValidCell(int col, int row) const;
127 
128  int GetColumnWidth(int col) const { return x_GetWidth(col); }
129  int GetRowHeight(int row) const { return x_GetHeight(row); }
130 
131  /// If cell [col, row] exists and vacant - adds widget to the container.
132  /// Returns "true" if widget has been added.
133  bool InsertToCell(wxWindow* child, int col, int row);
134 
135  void AddColumn();
136  void AddRow();
137 
138  /// overriding wxWindowBase function
139  virtual void RemoveChild(wxWindowBase* child);
140 
141  virtual bool RemoveFromCell(int col, int row);
142  virtual void RemoveAll();
143 
144  wxWindow* GetCell(int col, int row);
145  const wxWindow* GetCell(int col, int row) const;
146 
147  bool FindChild(const wxWindow* child, int& col, int& row) const;
148 
149  virtual void x_PreserveNormalSize(bool preserve);
150 
151 protected:
152  virtual void x_DrawSeparator(wxDC& dc, int x, int y, int w, int h);
153  void x_SplitPositionsToSizes(const TPosVector& split_positions,
154  int total_size, TPosVector& sizes) const;
155  void x_SizesToSplitPositions(const TPosVector& sizes,
156  TPosVector& split_positions);
157 
158  void x_Init();
159 
160  void x_Split(ESplitType type, const TPosVector& widths, const TPosVector& heights);
161 
162  int x_GetCellIndex(int i_x, int i_y) const;
163  int x_GetColumn(int i_cell) const;
164  int x_GetRow(int i_cell) const;
165  int x_GetCellIndex(wxWindow* widget) const;
166 
167  int x_GetLeft(int i_x) const;
168  int x_GetRight(int i_x) const;
169  int x_GetWidth(int i_x) const;
170 
171  int x_GetTop(int i_y) const;
172  int x_GetBottom(int i_y) const;
173  int x_GetHeight(int i_y) const;
174 
175  bool x_RemoveChild(int index);
176 
177  void x_Clear();
178  void x_ResizeToCell(int i_cell);
179  void x_ResizeToCell(int i_x, int i_y);
180  void x_ResizeAllCells();
181 
182  void OnPaint(wxPaintEvent& event);
183  void OnMouseMove(wxMouseEvent& event);
184  void OnLeftDown(wxMouseEvent& event);
185  void OnLeftUp(wxMouseEvent& event);
186  void OnMouseEnter(wxMouseEvent& event);
187  void OnMouseLeave(wxMouseEvent& event);
188  void OnContextMenu(wxContextMenuEvent& event);
189  void OnKeyDown(wxKeyEvent& event);
190 
191  void x_RequestUpdate();
192 
193  /// returns Separator index if hit or -1
194  int x_HitTestSeparator(int z, TPosVector& vpos);
195  void x_HitTest(int z, TPosVector& vpos, int& i_cell, int& i_sep);
196 
197  virtual void x_StartDrag(int i_sep_x, int i_sep_y);
198  virtual void x_DoDragSeparator(wxMouseEvent& event, bool b_final);
199  virtual void x_EndDrag();
200  virtual bool x_IsDragging() const;
201 
202  void x_DistributeEvenly(bool b_x, bool b_y);
203  void x_DoDistributeEvenly(TPosVector& vSplitPos, int size);
204 
205  virtual void x_Resize(const wxSize& old_size, const wxSize& new_size, bool b_size_changes);
206 
207  static void x_ShrinkCell(TPosVector& sizes, TPosVector& min_sizes, TPosVector& norm_sizes,
208  int index, int& delta);
209  static void x_GrowCell(TPosVector& sizes, TPosVector& norm_sizes,
210  int index, int& delta, bool unlimited = false);
211 
212  void x_DoResize(TPosVector& sizes, TSizeVector& norm_sizes,
213  TPosVector& min_sizes, int size, int new_size,
214  int resizable_index);
215 
216  void x_MoveSeparator(TPosVector& sizes, TSizeVector& norm_sizes, TPosVector& min_sizes,
217  int i_sep, int delta, int resizable_index);
218 
219  void x_GetMinimized(vector<bool>& min_cols, vector<bool>& min_rows) const;
220  void x_CalculateMinSizes(TPosVector& min_widths,
221  TPosVector& min_heights) const;
222 
223  // updates cells belonging to [start_x, stop_x] or to [start_y, stop_y]
224  void x_UpdateRegion(int start_x, int stop_x, int start_y, int stop_y);
225 
226  void x_NewSplit(TPosVector& split_positions, TSizeVector& v_norm_size, int size);
227  void x_Deprecated() const { _ASSERT(false); }
228 
229 protected:
230  typedef vector<wxWindow*> TCells;
231 
233 
235  wxSize m_LayoutedSize; // previous size for which layoting has been done
236  wxSize m_SplitSize; // the size corresponding to the current separaror positions
237 
238  TPosVector m_vSplitPosX; // coordinates of first pixels of separators
239  TPosVector m_vSplitPosY; // coordinates of first pixels of separators
241  TSizeVector m_vNormSizeX; // normal (not "shrinked") sizes of cells
242  TSizeVector m_vNormSizeY; // normal (not "shrinked") sizes of cells
243 
245 
248 
249  /// members used for event handling
250  wxWindow* m_PrevFocus;
251 
252  int m_MouseDownX, m_MouseDownY; // window coordinate of last Mouse-Down
253  int m_StartPosX, m_StartPosY; // start position of separators being dragged (local)
254  int m_iDragSepX, m_iDragSepY; // index of separator being dragged or -1
255  wxPoint m_PrevSepPos;
256 
257  TPosVector m_MinWidths, m_MinHeights;
258  int m_MinSepPosX, m_MaxSepPosX; // define the range within which the seprator can be move
259  int m_MinSepPosY, m_MaxSepPosY;
260 
261  int m_HighlightCell; // index of the highlighted cell
262 };
263 
265 
266 
267 #endif // GUI_WX_DEMO___SPLITTER__HPP
CSplitter - container with resizable separators.
Definition: splitter.hpp:54
int m_MinSepPosX
Definition: splitter.hpp:258
vector< wxWindow * > TCells
Definition: splitter.hpp:230
int m_MinSepPosY
Definition: splitter.hpp:259
int m_SepSize
Definition: splitter.hpp:240
wxWindow * m_PrevFocus
members used for event handling
Definition: splitter.hpp:250
int m_StartPosY
Definition: splitter.hpp:253
vector< int > TSizeVector
Definition: splitter.hpp:59
wxSize m_LayoutedSize
Definition: splitter.hpp:235
TPosVector m_vSplitPosX
Definition: splitter.hpp:238
void x_Deprecated() const
Definition: splitter.hpp:227
int m_MouseDownY
Definition: splitter.hpp:252
TPosVector m_vSplitPosY
Definition: splitter.hpp:239
TSizeVector m_vNormSizeX
Definition: splitter.hpp:241
bool m_BlockLayout
Definition: splitter.hpp:234
wxPanel TParent
Definition: splitter.hpp:57
int GetColumnWidth(int col) const
Definition: splitter.hpp:128
int m_HighlightCell
Definition: splitter.hpp:261
TPosVector m_MinWidths
Definition: splitter.hpp:257
int m_iDragSepY
Definition: splitter.hpp:254
vector< int > TPosVector
Definition: splitter.hpp:58
wxPoint m_PrevSepPos
Definition: splitter.hpp:255
TCells m_Cells
Definition: splitter.hpp:244
int m_ResizableRow
Definition: splitter.hpp:247
wxSize m_SplitSize
Definition: splitter.hpp:236
ESplitType
ESplitMode - splitter orientation.
Definition: splitter.hpp:62
@ eHorizontal
vertical space is splitted
Definition: splitter.hpp:64
ESplitType m_Type
Definition: splitter.hpp:232
int GetRowHeight(int row) const
Definition: splitter.hpp:129
int m_ResizableColumn
Definition: splitter.hpp:246
TSizeVector m_vNormSizeY
Definition: splitter.hpp:242
Include a standard set of the NCBI C++ Toolkit most basic headers.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIWIDGETS_WX_EXPORT
Definition: gui_export.h:543
Defines to provide correct exporting from DLLs in Windows.
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
Int4 delta(size_t dimension_, const Int4 *score_)
static static static wxID_ANY
#define row(bind, expected)
Definition: string_bind.c:73
Definition: type.c:6
#define _ASSERT
Modified on Wed Apr 17 13:09:18 2024 by modify_doxy.py rev. 669887