tbx  0.7.3
gadgetlistview.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2015 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  * tbx RISC OS toolbox library
26  *
27  * Copyright (C) 2015 Alan Buckley All Rights Reserved.
28  *
29  * Permission is hereby granted, free of charge, to any person obtaining a
30  * copy of this software and associated documentation files (the "Software"),
31  * to deal in the Software without restriction, including without limitation
32  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
33  * and/or sell copies of the Software, and to permit persons to whom the
34  * Software is furnished to do so, subject to the following conditions:
35  *
36  * The above copyright notice and this permission notice shall be included
37  * in all copies or substantial portions of the Software.
38  *
39  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
45  * THE SOFTWARE.
46  */
47 
48 #ifndef _TBX_VIEW_GADGETLISTVIEW_
49 #define _TBX_VIEW_GADGETLISTVIEW_
50 
51 #include "../window.h"
52 #include "../gadget.h"
53 #include "../margin.h"
54 #include "../res/reswindow.h"
55 
56 namespace tbx
57 {
58 namespace view
59 {
60 class GadgetListView;
61 
66 {
67  public:
69  virtual ~GadgetListCopyRow() {}
70 
81  virtual void copy_row(GadgetListView &glv, unsigned int from_row, unsigned int to_row);
82 };
83 
89 {
90 private:
91  tbx::Window _window;
92  tbx::res::ResGadget **_res_gadgets;
93  tbx::ComponentId _first_gadget_id;
94  tbx::ComponentId _last_gadget_id;
95  unsigned int _num_gadgets;
96  tbx::Margin _margin;
97  unsigned int _width;
98  unsigned int _row_height;
99  unsigned int _spacing;
100  unsigned int _count;
101  GadgetListCopyRow *_copy_interface;
102  bool _updates_enabled;
103  static GadgetListCopyRow _default_copy;
104 
105 public:
106  GadgetListView();
107  ~GadgetListView();
108 
109  void setup(tbx::Window window, tbx::res::ResWindow &res_window, tbx::ComponentId first_gadget_id, tbx::ComponentId last_gadget_id, unsigned int spacing, bool first_row_created);
110 
114  unsigned int num_gadgets() const {return _num_gadgets;}
118  unsigned int count() const {return _count;}
119 
123  tbx::Window &window() {return _window;}
124 
128  const tbx::Margin &margin() const {return _margin;}
129  void margin(const tbx::Margin &margin);
130 
132 
137  bool updates_enabled() const {return _updates_enabled;}
146  void updates_enabled(bool enabled) {_updates_enabled = enabled;}
147 
148  void update_window_extent();
149 
157  tbx::ComponentId gadget_id(int row, int col) const
158  {
159  return row * _num_gadgets + _first_gadget_id + col;
160  }
161 
166  tbx::Gadget gadget(int row, int col)
167  {
168  return _window.gadget(row * _num_gadgets + _first_gadget_id + col);
169  }
170 
171  tbx::ComponentId add(unsigned int count = 1);
172  tbx::ComponentId insert(unsigned int row, unsigned int count = 1);
173  void remove(unsigned int row, unsigned int count = 1);
174  void clear();
175 
176  void copy(unsigned int from_row, unsigned int to_row);
177 };
178 
179 
180 } /* end of view namespace */
181 } /* end of tbx namespace */
182 
183 
184 #endif
unsigned int num_gadgets() const
Return the number of gadgets in a row.
Definition: gadgetlistview.h:114
bool updates_enabled() const
Check if updating of the window extent is enabled.
Definition: gadgetlistview.h:137
Base class for gadget memory resources.
Definition: resgadget.h:42
This is the base class for all Gadgets.
Definition: gadget.h:48
void copy(unsigned int from_row, unsigned int to_row)
Use currently assigned copy function to copy from one row to another.
Definition: gadgetlistview.cc:366
tbx::ComponentId gadget_id(int row, int col) const
Return the gadget_id for a specific row and column.
Definition: gadgetlistview.h:157
unsigned int count() const
Return the number of rows.
Definition: gadgetlistview.h:118
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
Window resource object.
Definition: reswindow.h:48
Class to represent a margin around an area.
Definition: margin.h:34
virtual void copy_row(GadgetListView &glv, unsigned int from_row, unsigned int to_row)
Copy data from one row in a gadget list to another.
Definition: gadgetlistview.cc:380
tbx::Window & window()
Return the window this view is attached to.
Definition: gadgetlistview.h:123
void updates_enabled(bool enabled)
Set if updating of the window extent is enabled.
Definition: gadgetlistview.h:146
Interface for copying from one row to another.
Definition: gadgetlistview.h:65
The Window object represents a toolbox window.
Definition: window.h:69
Class to create a list view with each line made up of one or more gadgets.
Definition: gadgetlistview.h:88
void setup(tbx::Window window, tbx::res::ResWindow &res_window, tbx::ComponentId first_gadget_id, tbx::ComponentId last_gadget_id, unsigned int spacing, bool first_row_created)
Setup the gadget list view.
Definition: gadgetlistview.cc:98
void update_window_extent()
Update the windows extents to fit the current size of the list and its margin.
Definition: gadgetlistview.cc:193
void clear()
Clear all gadgets from the list.
Definition: gadgetlistview.cc:331
tbx::Gadget gadget(int row, int col)
Return the gadget for a specified row and column.
Definition: gadgetlistview.h:166
tbx::ComponentId add(unsigned int count=1)
Add row(s) to the end of the list.
Definition: gadgetlistview.cc:232
const tbx::Margin & margin() const
Return the margin around the data in the window.
Definition: gadgetlistview.h:128
void copy_interface(GadgetListCopyRow *copy)
Set object that implement the copy row interface to copy data from one row to another.
Definition: gadgetlistview.cc:219
tbx::ComponentId insert(unsigned int row, unsigned int count=1)
Insert row(s) before the given row number.
Definition: gadgetlistview.cc:269
Gadget gadget(ComponentId component_id)
Get the gadget with the given component id.
Definition: window.cc:514