tbx  0.7.3
colourdbox.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  * colourdbox.h
27  *
28  * Created on: 01-Jul-2010
29  * Author: alanb
30  */
31 
32 #ifndef TBX_COLOURDBOX_H_
33 #define TBX_COLOURDBOX_H_
34 
35 #include "showpointobject.h"
36 #include "listener.h"
37 #include "window.h"
38 
39 namespace tbx {
40 
41 // Listeners
42 class AboutToBeShownListener;
43 class HasBeenHiddenListener;
44 class ColourSelectedListener;
45 class ColourDboxDialogueCompletedListener;
46 
47 namespace res
48 {
49  class ResColourDbox;
50 }
51 
60 {
61 public:
62  enum { TOOLBOX_CLASS = 0x829C0 };
63 
69  ColourDbox() {};
78  ColourDbox(const ColourDbox &other) : ShowPointObject(other._handle) {}
89  ColourDbox(const Object &other) : ShowPointObject(other) {check_toolbox_class(ColourDbox::TOOLBOX_CLASS);}
97  ColourDbox(const std::string &template_name) : ShowPointObject(template_name) {check_toolbox_class(ColourDbox::TOOLBOX_CLASS);}
104  ColourDbox(const res::ResColourDbox &object_template);
105 
114  ColourDbox &operator=(const ColourDbox &other) {_handle = other.handle(); return *this;}
115 
127  ColourDbox &operator=(const Object &other) {_handle = other.handle(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
128 
136  bool operator==(const Object &other) const {return (_handle == other.handle());}
144  bool operator!=(const Object &other) const {return (_handle != other.handle());}
145 
146  // Properties
151 
155  int dialog_handle() const {return int_property(1);}
156 
160  enum ColourModel {RGB, CYMK, HSV};
161 
165  void none_available(bool available) {bool_property(6, available);}
169  bool none_available() const {return bool_property(7);}
170 
171  // Listeners
178 
179 };
180 
185 {
186 public:
195  virtual void colourdbox_dialogue_completed(ColourDbox colour_dbox, bool colour_selected) = 0;
196 };
197 
202 {
203  ColourDbox _colour_dbox;
204  bool _none;
205  unsigned char *_block;
206 public:
207  ColourSelectedEvent(ColourDbox cbox, bool none, const unsigned char *block);
209  ~ColourSelectedEvent() {delete _block;}
211 
215  ColourDbox colour_dbox() const {return _colour_dbox;}
216 
220  bool none() const {return _none;}
221 
225  unsigned char blue() const {return _block[1];}
229  unsigned char green() const {return _block[2];}
233  unsigned char red() const {return _block[3];}
238 };
239 
244 {
245 public:
246  virtual ~ColourSelectedListener() {};
247 
251  virtual void colour_selected(const ColourSelectedEvent &event) = 0;
252 };
253 
254 
255 }
256 
257 #endif /* TBX_COLOURDBOX_H_ */
ObjectId _handle
Handle for toolbox object.
Definition: object.h:173
ColourDbox & operator=(const Object &other)
Assign this ColourDbox from an Object that refers to a ColourDbox.
Definition: colourdbox.h:127
unsigned char blue() const
Blue amount selected.
Definition: colourdbox.h:225
ColourDbox::ColourModel model() const
Colour model selected.
Definition: colourdbox.h:237
void add_dialogue_completed_listener(ColourDboxDialogueCompletedListener *listener)
Add listener to be called when the dialogue has been completed.
Definition: colourdbox.cc:76
ColourDbox(const std::string &template_name)
Create a ColourDbox from the named template.
Definition: colourdbox.h:97
ColourModel
Enumeration for the colour models.
Definition: colourdbox.h:160
Listener for when the Colour dialogue box has been closed.
Definition: colourdbox.h:184
Listener for about to be shown event.
Definition: abouttobeshownlistener.h:76
void check_toolbox_class(int class_id) const
Check if this objects toolbox class is as specified.
Definition: object.cc:122
bool none_available() const
Return true if a no colour option is included on the dialog box.
Definition: colourdbox.h:169
void remove_colour_selected_listener(ColourSelectedListener *listener)
Remove the colour selected listener.
Definition: colourdbox.cc:118
void remove_dialogue_completed_listener(ColourDboxDialogueCompletedListener *listener)
Remove listener to be called when the dialogue has been completed.
Definition: colourdbox.cc:86
bool none() const
None colour was selected.
Definition: colourdbox.h:220
int WindowHandle
Type for WIMP windows handle.
Definition: handles.h:35
Event data for colour selected event.
Definition: colourdbox.h:201
ColourSelectedEvent(ColourDbox cbox, bool none, const unsigned char *block)
Construct a colour selected event from event data.
Definition: colourdbox.cc:130
virtual void colourdbox_dialogue_completed(ColourDbox colour_dbox, bool colour_selected)=0
Called when dialogue has be closed.
virtual void colour_selected(const ColourSelectedEvent &event)=0
Colour has been selected in ColourDbox nd OK is pressed.
bool operator!=(const Object &other) const
Check if this ColourDbox does not refers to the same underlying toolbox object as another...
Definition: colourdbox.h:144
unsigned char red() const
Red amount selected.
Definition: colourdbox.h:233
int int_property(int property_id) const
Return the value of a property that returns an integer.
Definition: object.cc:435
bool bool_property(int property_id) const
Get a boolean property from the toolbox Cobject.
Definition: object.cc:553
ColourDbox(const ColourDbox &other)
Construct a ColourDbox from another ColourDbox.
Definition: colourdbox.h:78
ColourDbox(const Object &other)
Construct a ColourDbox from an Object that refers to a ColourDbox.
Definition: colourdbox.h:89
ColourDbox()
Construct creates an unassigned ColourDbox.
Definition: colourdbox.h:69
void none_available(bool available)
Set if an option for no colour is included.
Definition: colourdbox.h:165
Event listener for colour selected event.
Definition: colourdbox.h:243
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93
ColourDbox & operator=(const ColourDbox &other)
Assign this ColourDbox from another.
Definition: colourdbox.h:114
unsigned char green() const
Green amount selected.
Definition: colourdbox.h:229
Class to show a toolbox ColourDbox object which allows a user to pick a colour using a variety of col...
Definition: colourdbox.h:59
WindowHandle wimp_handle() const
Return the underlying wimp window used by the ColourPicker module.
Definition: colourdbox.h:150
void add_about_to_be_shown_listener(AboutToBeShownListener *listener)
This event is raised just before the ColourDbox underlying window is about to be shown.
Definition: colourdbox.cc:48
Base class for all toolbox event listeners.
Definition: listener.h:33
Object that can be shown at a specific position as well as its default place.
Definition: showpointobject.h:42
ColourSelectedEvent & operator=(const ColourSelectedEvent &other)
Make this object to another ColourSelectedEvent object.
Definition: colourdbox.cc:165
void remove_about_to_be_shown_listener(AboutToBeShownListener *listener)
Remove about to be shown listener.
Definition: colourdbox.cc:58
int dialog_handle() const
Return the underlying dialogue handle used by the ColourPicker module.
Definition: colourdbox.h:155
void add_colour_selected_listener(ColourSelectedListener *listener)
Add listener to report colour select when dialog is finished with OK.
Definition: colourdbox.cc:108
Class to manipulate a toolbox object.
Definition: object.h:50
Class for ColourDbox object template.
Definition: rescolourdbox.h:36
ColourDbox colour_dbox() const
Return colour dbox that generated this event.
Definition: colourdbox.h:215
bool operator==(const Object &other) const
Check if this ColourDbox refers to the same underlying toolbox object as another. ...
Definition: colourdbox.h:136