tbx  0.7.3
reportview.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 
25 /*
26  * reportview.h
27  *
28  * Created on: 30 Mar 2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_REPORTVIEW_H_
33 #define TBX_REPORTVIEW_H_
34 
35 #include "itemview.h"
36 
37 namespace tbx {
38 
39 namespace view {
40 
45 class ReportView : public ItemView
46 {
47 private:
48  unsigned int _height;
49  unsigned int _width;
50  unsigned int _column_gap;
51 
52  struct ColInfo
53  {
54  ItemRenderer *renderer;
55  unsigned int width;
56  };
57  std::vector<ColInfo> _columns;
58 
59 public:
61  virtual ~ReportView();
62 
63  virtual void auto_size(bool on);
64 
65  void row_height(unsigned int height);
69  unsigned int row_height() const {return _height;}
70 
71  void column_gap(unsigned int gap);
75  unsigned int column_gap() const {return _column_gap;}
76 
77  unsigned int add_column(ItemRenderer *cr, unsigned int width = 0);
78  //TODO: void insert_column(int where, ReportViewCellRenderer *cr, int width);
79  void remove_column(unsigned int column);
80 
84  unsigned int column_count() const {return _columns.size();}
88  unsigned int row_count() const {return _count;}
89 
90  void column_width(unsigned int column, unsigned int width);
91  unsigned int column_width(unsigned int column) const;
92 
93  void size_column_to_width(unsigned int column, unsigned int min_width = 0, unsigned int max_width = 0xFFFFFFFF);
94  void size_all_to_width(unsigned int min_width = 0, unsigned int max_width = 0xFFFFFFFF);
95 
96  // Redraw listener override
97  virtual void redraw(const tbx::RedrawEvent &event);
98 
99 
104  virtual void update_window_extent();
105 
109  virtual void refresh();
110 
111 
112  virtual void inserted(unsigned int where, unsigned int how_many);
113  virtual void removing(unsigned int where, unsigned int how_many);
114  virtual void removed(unsigned int where, unsigned int how_many);
115  virtual void changing(unsigned int where, unsigned int how_many);
116  virtual void changed(unsigned int where, unsigned int how_many);
117  virtual void cleared();
118 
119  void cell_changing(unsigned int index, unsigned int column);
120  void cell_changed(unsigned int index, unsigned int column);
121 
122 
127  virtual unsigned int insert_index(const Point &scr_pt) const;
128 
129  virtual unsigned int screen_index(const Point &scr_pt) const;
130  virtual unsigned int hit_test(const Point &scr_pt) const;
131  virtual void get_bounds(BBox &bounds, unsigned int index) const;
132  virtual void get_bounds(BBox &bounds, unsigned int first, unsigned int last) const;
133  void get_cell_bounds(BBox &bounds, unsigned int row, unsigned int column) const;
134 
135  unsigned int column_from_x(int x) const;
136  int x_from_column(unsigned int column) const;
137 
138 protected:
147  virtual void process_drag_selection(const BBox &drag_box, bool adjust);
148 
149  // Helpers
150  unsigned int calc_row_height() const;
151  bool adjust_max_width(unsigned int start, unsigned int end);
152  bool adjust_min_width(unsigned int from, unsigned int end);
153 };
154 
155 }
156 
157 }
158 
159 #endif /* REPORTVIEW_H_ */
virtual void redraw(const tbx::RedrawEvent &event)
Redraw the window.
Definition: reportview.cc:800
virtual void removed(unsigned int where, unsigned int how_many)
Call after removing rows from the collection the ReportView is showing.
Definition: reportview.cc:493
virtual void changing(unsigned int where, unsigned int how_many)
Inform the view that items are about to be changed.
Definition: reportview.cc:540
Class to handle the display/interaction with a list of items presented in columns.
Definition: reportview.h:45
unsigned int add_column(ItemRenderer *cr, unsigned int width=0)
Add a column to the report view.
Definition: reportview.cc:197
void get_cell_bounds(BBox &bounds, unsigned int row, unsigned int column) const
Get the cell bounds for the specified column and row.
Definition: reportview.cc:997
virtual void update_window_extent()
Called to update the window extent needed to contain this view.
Definition: reportview.cc:154
void cell_changing(unsigned int index, unsigned int column)
Inform the view that one column has been changed.
Definition: reportview.cc:678
Class to represent a two dimensional bounding box.
Definition: bbox.h:37
tbx::Window & window()
Return the Window that this item view is attached to.
Definition: itemview.h:107
void cell_changed(unsigned int index, unsigned int column)
Inform the view that items have been changed.
Definition: reportview.cc:702
bool adjust_max_width(unsigned int start, unsigned int end)
Adjust column widths and total width if any items in the given range exceed the current widths...
Definition: reportview.cc:343
Base class for views that show an indexed list of items.
Definition: itemview.h:63
virtual void inserted(unsigned int where, unsigned int how_many)
Call after inserting rows into the collection the ReportView is showing.
Definition: reportview.cc:417
bool adjust_min_width(unsigned int from, unsigned int end)
Check if any of the column widths have been reduced and adjust columns if necessary.
Definition: reportview.cc:380
virtual void process_drag_selection(const BBox &drag_box, bool adjust)
Override this method to process selection by dragging.
Definition: reportview.cc:1014
unsigned int column_from_x(int x) const
Get column from position on window.
Definition: reportview.cc:762
int x_from_column(unsigned int column) const
Return x coordinate relative to window of column.
Definition: reportview.cc:781
ReportView(tbx::Window window)
Construct a report view for a window.
Definition: reportview.cc:43
virtual ~ReportView()
Destructor of report view.
Definition: reportview.cc:52
void column_width(unsigned int column, unsigned int width)
Set the column width.
Definition: reportview.cc:242
Base class to render an indexed item.
Definition: itemrenderer.h:53
virtual void refresh()
Called to refresh the entire views contents.
Definition: reportview.cc:178
Class to represent a position in two dimensional space.
Definition: point.h:36
virtual void changed(unsigned int where, unsigned int how_many)
Inform the view that items have been changed.
Definition: reportview.cc:573
Event passed to redraw listener to give details on the area that needs a redraw.
Definition: redrawlistener.h:43
bool auto_size() const
Returns true if auto size is on.
Definition: itemview.h:128
virtual void get_bounds(BBox &bounds, unsigned int index) const
Get bounding box of the given index in work area coordinates.
Definition: reportview.cc:964
unsigned int calc_row_height() const
Calculate the row height from the first row of the report.
Definition: reportview.cc:88
unsigned int column_gap() const
Get the gap between columns in the report.
Definition: reportview.h:75
virtual unsigned int hit_test(const Point &scr_pt) const
Return the index under the screen point, checks if it hits content of the item renderer.
Definition: reportview.cc:918
The Window object represents a toolbox window.
Definition: window.h:69
virtual unsigned int screen_index(const Point &scr_pt) const
Return the index under the screen point, does not check if it hits content of the item renderer...
Definition: reportview.cc:894
virtual unsigned int insert_index(const Point &scr_pt) const
Return the index for inserting an item from a screen point.
Definition: reportview.cc:870
unsigned int _count
Number of items displayed in this view.
Definition: itemview.h:75
void remove_column(unsigned int column)
Remove column from report.
Definition: reportview.cc:223
virtual void cleared()
Whole view has been cleared.
Definition: reportview.cc:636
virtual void removing(unsigned int where, unsigned int how_many)
Inform the view that items are about to be removed.
Definition: reportview.cc:458
unsigned int row_height() const
Get the height of one row of the report.
Definition: reportview.h:69
unsigned int column_count() const
Get the number of columns in the report view.
Definition: reportview.h:84
void size_column_to_width(unsigned int column, unsigned int min_width=0, unsigned int max_width=0xFFFFFFFF)
Size column to content.
Definition: reportview.cc:282
unsigned int row_count() const
Get the number of rows in the report view.
Definition: reportview.h:88
void size_all_to_width(unsigned int min_width=0, unsigned int max_width=0xFFFFFFFF)
Size all columns to content.
Definition: reportview.cc:306