tbx  0.7.5
window.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010-2013 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 #ifndef TBX_WINDOW_H
26 #define TBX_WINDOW_H
27 
28 #include "showfullobject.h"
29 #include "pollinfo.h"
30 #include "visiblearea.h"
31 #include "colour.h"
32 #include "showsubwindowspec.h"
33 
34 namespace tbx
35 {
36  class Gadget;
37  class Listener;
38  class AboutToBeShownListener;
39  class HasBeenHiddenListener;
40  class RedrawListener;
41  class OpenWindowListener;
42  class CloseWindowListener;
43  class PointerEnteringListener;
44  class PointerLeavingListener;
45  class MouseClickListener;
46  class KeyListener;
47  class LoseCaretListener;
48  class GainCaretListener;
49  class ScrollRequestListener;
50 
51  class WindowOpenInfo;
52  class WindowState;
53  class WindowInfo;
54  class Loader;
55  class DragHandler;
56  class Sprite;
57 
58  namespace res
59  {
60  class ResWindow;
61  class ResGadget;
62  class ResShortcut;
63  }
64 
69  class Window : public ShowFullObject
70  {
71  public:
72  enum { TOOLBOX_CLASS = 0x82880 };
73 
79  Window() {};
88  Window(const Window &other) : ShowFullObject(other._handle) {}
99  Window(const Object &other) : ShowFullObject(other) {check_toolbox_class(Window::TOOLBOX_CLASS);}
107  Window(const std::string &template_name) : ShowFullObject(template_name) {check_toolbox_class(Window::TOOLBOX_CLASS);}
114  Window(const res::ResWindow &object_template);
115 
124  Window &operator=(const Window &other) {_handle = other.handle(); return *this;}
136  Window &operator=(const Object &other) {_handle = other.handle(); check_toolbox_class(TOOLBOX_CLASS); return *this;}
144  bool operator==(const Object &other) const {return (_handle == other.handle());}
152  bool operator!=(const Object &other) const {return (_handle != other.handle());}
153 
154  void show_as_subwindow(const ShowSubWindowSpec &spec);
155 
156  Gadget gadget(ComponentId component_id);
157 
158  static Window from_handle(WindowHandle window_handle);
159  static Gadget from_handle(WindowHandle window_handle, IconHandle icon_handle, Window *window = 0);
160 
161  // Properties
165  WindowHandle window_handle() const {return (WindowHandle)int_property(0);}
166 
167  Gadget add_gadget(const res::ResGadget &gadget_template);
168  void remove_gadget(ComponentId component_id);
169 
170  void menu(Menu menu);
171  Menu menu() const;
172  void remove_menu();
173  //TODO: set_pointer
174  //TODO: get_pointer
175 
181  void help_message(const std::string &message) {string_property(7, message);}
187  std::string help_message() const {return string_property(8);}
188 
189  void add_shorcut(const res::ResShortcut &shortcut);
190  void add_shortcuts(const res::ResShortcut *shortcuts, int num);
191  void remove_all_shortcuts();
192  void remove_shortcuts(const res::ResShortcut *shortcuts, int num);
193 
199  std::string title() const {return string_property(12);}
205  void title(std::string new_title) {string_property(11, new_title);}
206 
207  //TODO: Gadget default_focus()
208  //TODO: default_focus(Gadget gadget)
209 
210  void set_toolbars(Window *internal_bottom_left, Window *internal_top_left, Window *external_bottom_left, Window *external_top_left);
211  void get_toolbars(Window *internal_bottom_left, Window *internal_top_left, Window *external_bottom_left, Window *external_top_left);
212 
213  void ibl_toolbar(Window window);
214  Window ibl_toolbar() const;
215  void itl_toolbar(Window window);
216  Window itl_toolbar() const;
217  void ebl_toolbar(Window window);
218  Window ebl_toolbar() const;
219  void etl_toolbar(Window window);
220  Window etl_toolbar() const;
221 
222 
223 
224  void extent(const BBox &new_extent);
225  BBox extent() const;
226 
227  // Methods
228  void force_redraw(const BBox &work_area);
229  void update(const BBox &bounds, RedrawListener *background = 0);
230  void update(const BBox &bounds, RedrawListener **redrawers, int redrawer_count);
231  void get_state(WindowState &state) const;
232  void get_state(WindowState &state, Window &parent, int &align_flags) const;
233  void get_info(WindowInfo &info) const;
234  void open_window(const WindowOpenInfo &open_info);
235 
236  void open_subwindow(const WindowOpenInfo &open_info , Window &parent, unsigned int align_flags = 0);
237  void scroll(int x, int y);
238  void scroll(const Point &pos);
239  Point scroll() const;
240  void size(int width, int height);
241  void size(const Size &size);
242  Size size() const;
243  void top_left(int x, int y);
244  void top_left(const Point &pos);
245  Point top_left() const;
246  void bounds(const BBox &bounds);
247  BBox bounds() const;
248  BBox outline() const;
249 
250  void block_copy(const BBox &bounds, const Point &to);
251 
252  // Listeners - toolbox events
253  void add_about_to_be_shown_listener(AboutToBeShownListener *listener);
254  void remove_about_to_be_shown_listener(AboutToBeShownListener *listener);
255 
256  void add_has_been_hidden_listener(HasBeenHiddenListener *listener);
257  void remove_has_been_hidden_listener(HasBeenHiddenListener *listener);
258 
259  // Listeners - WIMP events
260  void add_redraw_listener(RedrawListener *listener);
261  void remove_redraw_listener(RedrawListener *listener);
262  void add_open_window_listener(OpenWindowListener *listener);
263  void remove_open_window_listener(OpenWindowListener *listener);
264  void add_close_window_listener(CloseWindowListener *listener);
265  void remove_close_window_listener(CloseWindowListener *listener);
266  void add_pointer_leaving_listener(PointerLeavingListener *listener);
267  void remove_pointer_leaving_listener(PointerLeavingListener *listener);
268  void add_pointer_entering_listener(PointerEnteringListener *listener);
269  void remove_pointer_entering_listener(PointerEnteringListener *listener);
270  void add_mouse_click_listener(MouseClickListener *listener);
271  void remove_mouse_click_listener(MouseClickListener *listener);
272  void add_key_listener(KeyListener *listener);
273  void remove_key_listener(KeyListener *listener);
274  void add_lose_caret_listener(LoseCaretListener *listener);
275  void remove_lose_caret_listener(LoseCaretListener *listener);
276  void add_gain_caret_listener(GainCaretListener *listener);
277  void remove_gain_caret_listener(GainCaretListener *listener);
278  void add_scroll_request_listener(ScrollRequestListener *listener);
279  void remove_scroll_request_listener(ScrollRequestListener *listener);
280 
281  // Listeners - drag and drop between applications
282  void add_loader(Loader *loader, int file_type = -2);
283  void remove_loader(Loader *loader, int file_type = -2);
284 
285  // Drags from the application
286  void drag_point(DragHandler *handler) const;
287  void drag_point_local(DragHandler *handler) const;
288  void drag_point(const BBox &bounds, DragHandler *handler) const;
289 
290  void drag_box(const BBox &box, DragHandler *handler) const;
291  void drag_box_local(const BBox &box, DragHandler *handler) const;
292  void drag_box(const BBox &box, const BBox &bounds, DragHandler *handler) const;
293 
294  void drag_rubber_box(const Point &start, DragHandler *handler) const;
295  void drag_rubber_box_local(const Point &start, DragHandler *handler) const;
296  void drag_rubber_box(const Point &start, const BBox &bounds, DragHandler *handler) const;
297  void cancel_drag() const;
298 
302  enum DragSpriteFlags {DSFLAG_NONE = 0, //- No flags set sprite is in bottom left of box
303  DSFLAG_HCENTRE, //- Sprite is horizontally centred in box
304  DSFLAG_RIGHT, //- Sprite is on the right of the box
305  DSFLAG_VCENTRE = 4, //- Sprite is vertically centred in box
306  DSFLAG_TOP = 8, //- Sprite it at top of box
307  DSFLAG_BOUND_POINT = 64, //- Point is set to bounds, otherwise box
308  DSFLAG_DROP_SHADOW = 128, //- Sprite has drop shadow
309  DSFLAG_SOLID = 256 //- Do no dither the sprite
310  };
311 
312  void drag_sprite(const Sprite &sprite, const BBox &box, DragHandler *handler, int flags = 0) const;
313  void drag_sprite_local(const Sprite &sprite, const BBox &box, DragHandler *handler, int flags = 0) const;
314  void drag_sprite(const Sprite &sprite, const BBox &box, const BBox &bounds, DragHandler *handler, int flags = 0) const;
315  };
316 
323  {
324  protected:
328  friend class Window;
329 
330  public:
334  WindowHandle window_handle() const {return _window_handle;}
335 
339  const VisibleArea &visible_area() const {return _visible_area;}
340 
344  VisibleArea &visible_area() {return _visible_area;}
345 
349  WindowHandle window_handle_in_front() const {return _window_handle_in_front;}
350  };
351 
356  {
357  private:
358  unsigned int _flags;
359 
360  friend class Window;
361 
362  public:
363 
370  unsigned int flags() const {return _flags;}
371 
375  bool open() const {return (_flags & (1<<16));}
376 
382  bool fully_visible() const {return (_flags & (1<<17));}
383 
387  bool full_size() const {return (_flags & (1<<17));}
388 
392  bool toggle_size() const {return (_flags & (1<<19));}
393 
397  bool input_focus() const {return (_flags & (1<<20));}
398 
402  bool force_to_screen() const {return (_flags & (1<<21));}
403  };
404 
409  {
410  BUTTONTYPE_IGNORE_CLICKS,
411  BUTTONTYPE_ALWAYS,
412  BUTTONTYPE_CLICK_AUTO,
413  BUTTONTYPE_CLICK_ONCE,
414  BUTTONTYPE_RELEASE,
415  BUTTONTYPE_DOUBLE,
416  BUTTONTYPE_CLICK_DRAG,
417  BUTTONTYPE_RELEASE_DRAG,
418  BUTTONTYPE_DOUBLE_DRAG,
419  BUTTONTYPE_CLICK_ONCE9,
420  BUTTONTYPE_DOUBLE_CLICK_DRAG,
421  BUTTONTYPE_CLICK_DRAG11,
422  BUTTONTYPE_RESERVED12,
423  BUTTONTYPE_RESERVED13,
424  BUTTONTYPE_RESERVED14,
425  BUTTONTYPE_GAIN_FOCUS
426  };
427 
431  class WindowInfo : public WindowOpenInfo
432  {
433  private:
434  unsigned int _flags;
435  char _title_foreground;
436  char _title_background;
437  char _work_area_foreground;
438  char _work_area_background;
439  char _scroll_outer;
440  char _scroll_inner;
441  char _title_highlight;
442  char _reserved; /* Unused - must be 0 */
443  BBox _work_area;
444  unsigned int _title_bar_flags;
445  unsigned int _work_area_flags;
446  unsigned int _sprite_area_pointer;
447  unsigned int _min_width_and_height;
448  unsigned int _title_data[3];
449  unsigned int _initial_icon_count;
450 
451  friend class Window;
452 
453  public:
460  unsigned int flags() const {return _flags;}
461 
467  unsigned int work_area_flags() const {return _work_area_flags;}
468 
472  ButtonType button_type() const {return ButtonType((_work_area_flags>>12) & 15);}
473 
477  const BBox &work_area() const {return _work_area;}
478 
485  WimpColour title_foreground() const {return WimpColour(_title_foreground);}
491  WimpColour title_background() const {return WimpColour(_title_background);}
492 
498  WimpColour work_area_foreground() const {return WimpColour(_work_area_foreground);}
505  WimpColour work_area_background() const {return WimpColour(_work_area_background);}
511  WimpColour scroll_outer() const {return WimpColour(_scroll_outer);}
517  WimpColour scroll_inner() const {return WimpColour(_scroll_inner);}
523  WimpColour title_highlight() const {return WimpColour(_title_highlight);}
524 
533  int min_width() const {return (_min_width_and_height & 0xFFFF);}
539  int min_height() const {return (_min_width_and_height >> 16);}
540 
541  };
542 }
543 
544 #endif
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
bool fully_visible() const
Window is fully visible.
Definition: window.h:382
Class representing a toolbox menu.
Definition: menu.h:49
Class to represent a two-dimensional size.
Definition: size.h:34
std::string help_message() const
Get the help message for the window.
Definition: window.h:187
Base class for gadget memory resources.
Definition: resgadget.h:42
Window(const Object &other)
Construct a Window from an Object that refers to a Window.
Definition: window.h:99
int min_height() const
Minimum height of the window.
Definition: window.h:539
std::string message(const std::string &token)
Shortcut to the tbx::app()->messages().message(...)
Definition: message.cc:41
WimpColour title_highlight() const
Title background highlight colour.
Definition: window.h:523
This is the base class for all Gadgets.
Definition: gadget.h:48
Listener for about to be shown event.
Definition: abouttobeshownlistener.h:76
Scroll request listener.
Definition: scrollrequestlistener.h:103
Class to represent a two dimensional bounding box.
Definition: bbox.h:37
WindowHandle window_handle() const
Return the underlying WIMP windows handle of the window.
Definition: window.h:165
WindowHandle window_handle() const
WIMP window handle of this window.
Definition: window.h:334
WindowHandle _window_handle
WIMP window handle.
Definition: window.h:325
Listener for gain caret Wimp event.
Definition: caretlistener.h:144
int ComponentId
Type for underlying toolbox component id.
Definition: handles.h:33
ButtonType
Enumeration of the button types for the work area.
Definition: window.h:408
unsigned int flags() const
Window flags.
Definition: window.h:370
WimpColour title_foreground() const
Title foreground and frame colour.
Definition: window.h:485
Classes to use/edit toolbox resources in memory.
const BBox & work_area() const
Work area.
Definition: window.h:477
int min_width() const
Minimum width of the window.
Definition: window.h:533
WimpColour title_background() const
Title background colour.
Definition: window.h:491
Window & operator=(const Object &other)
Assign this Window from an Object that refers to a SaveAs.
Definition: window.h:136
int WindowHandle
Type for WIMP windows handle.
Definition: handles.h:35
WindowHandle window_handle_in_front() const
WIMP handle of window on top of this window or -1 for none.
Definition: window.h:349
Window resource object.
Definition: reswindow.h:48
Class to represent a standard desktop WIMP colour.
Definition: colour.h:146
void title(std::string new_title)
Set the title (caption) of the window.
Definition: window.h:205
Class to report status of a drag started on a window.
Definition: draghandler.h:35
Keyboard short cut.
Definition: resshortcut.h:43
Common base class for the UserSprite and WimpSprite classes.
Definition: sprite.h:299
Window(const Window &other)
Construct a Window from another Window.
Definition: window.h:88
bool operator==(const Object &other) const
Check if this Window refers to the same underlying toolbox object as another.
Definition: window.h:144
unsigned int flags() const
Window flags.
Definition: window.h:460
bool operator!=(const Object &other) const
Check if this Window does not refers to the same underlying toolbox object as another.
Definition: window.h:152
Class to represent a position in two dimensional space.
Definition: point.h:36
Window()
Construct creates an unassigned Window.
Definition: window.h:79
unsigned int work_area_flags() const
Work area flags.
Definition: window.h:467
VisibleArea & visible_area()
Visible area of this window.
Definition: window.h:344
WimpColour scroll_outer() const
Scroll bar outer colour.
Definition: window.h:511
Class to store information for the Visible area of a window and provide work area to screen conversio...
Definition: visiblearea.h:36
Class to handle file/data loading from the filer or an external application.
Definition: loader.h:179
Listener for the pointer entering the window.
Definition: pointerlistener.h:62
Listener for the pointer leaving the window.
Definition: pointerlistener.h:44
Window(const std::string &template_name)
Create a Window from the named template.
Definition: window.h:107
Listener for mouse clicks on a Window.
Definition: mouseclicklistener.h:129
int IconHandle
Type for WIMP icon handle.
Definition: handles.h:37
bool input_focus() const
window has the input focus
Definition: window.h:397
bool open() const
Window is open.
Definition: window.h:375
The Window object represents a toolbox window.
Definition: window.h:69
Redraw event listener.
Definition: redrawlistener.h:75
WindowHandle _window_handle_in_front
Handle of window in front of this one.
Definition: window.h:327
DragSpriteFlags
Flags for drag_sprite.
Definition: window.h:302
WimpColour scroll_inner() const
Scroll bar inner colour.
Definition: window.h:517
bool force_to_screen() const
force window to screen once on the next Open_Window
Definition: window.h:402
std::string title() const
Get the title (caption) of the window.
Definition: window.h:199
Listener for an object has been hidden event.
Definition: hasbeenhiddenlistener.h:36
Structure used to show a window as a subwindow.
Definition: showsubwindowspec.h:58
Class with details of window location on screen.
Definition: window.h:322
Window state structure for the Window get_state method.
Definition: window.h:355
ButtonType button_type() const
Button type.
Definition: window.h:472
Listener for Wimp Open Window Request events.
Definition: openwindowlistener.h:97
Objects derived from this class can be shown with there full location and size specified as well as t...
Definition: showfullobject.h:40
Window & operator=(const Window &other)
Assign this Window from another.
Definition: window.h:124
Class to manipulate a toolbox object.
Definition: object.h:50
void help_message(const std::string &message)
Set the help message for the Window.
Definition: window.h:181
const VisibleArea & visible_area() const
Visible area of this window.
Definition: window.h:339
bool toggle_size() const
the current Open_Window_Request was caused by a click on the Toggle Size icon
Definition: window.h:392
WimpColour work_area_background() const
Work area background colour.
Definition: window.h:505
bool full_size() const
window has been toggled to full size
Definition: window.h:387
VisibleArea _visible_area
Position on screen and scroll settings.
Definition: window.h:326
Window Information structure for the Window get_info method.
Definition: window.h:431
WimpColour work_area_foreground() const
Work area foreground colour.
Definition: window.h:498
Listener for KeyPressed WIMP event.
Definition: keylistener.h:178
ObjectId handle() const
Return the underlying toolbox object id this object references.
Definition: object.h:93
Listener for the close window request message.
Definition: closewindowlistener.h:45
Listener for LoseCaret Wimp event.
Definition: caretlistener.h:126