tbx  0.7.5
resshortcut.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 #ifndef TBX_RES_SHORTCUT_H
26 #define TBX_RES_SHORTCUT_H
27 
28 #include "resbase.h"
29 #include <cstring>
30 
31 namespace tbx
32 {
33 class Window;
34 namespace res
35 {
36 
37 class ResWindow;
38 const int SHORTCUT_SIZE = 16;
39 
43 class ResShortcut : public ResBase
44 {
45  friend class ResWindow;
46 
47  ResShortcut(void *item_header, ResData *data)
48  : ResBase(new ResImpl(item_header, 0, SHORTCUT_SIZE, data))
49  {
50  }
51 
52  // Allow Window to access shortcut
53  friend class tbx::Window;
54  void *header() const {return _impl->header();}
55 
56 public:
62  ResShortcut(const ResShortcut &other) : ResBase(other)
63  {
64  }
65 
66  virtual ~ResShortcut() {}
67 
74  {
75  ResBase::operator=(other);
76  return *this;
77  }
78 
84  ResShortcut(int code)
85  : ResBase(new ResImpl(new char[SHORTCUT_SIZE], 0, SHORTCUT_SIZE, new ResData()))
86  {
87  memset(_impl->body(), 0, SHORTCUT_SIZE);
88  key_code(code);
89  init_string(12, 0); // show object
90  }
91 
92 protected:
97  {
98  if (!_impl->unique())
99  {
100  ResImpl *new_impl = new ResImpl(*_impl);
101  _impl->release();
102  _impl = new_impl;
103  }
104  }
105 
106 public:
114  unsigned int flags() const {return uint_value(0);}
115 
122  void flags(unsigned int value) {uint_value(0, value);}
123 
129  bool transient() const {return flag(0,1);}
138  void transient(bool b) {flag(0,1, b);}
139 
145  int key_code() const {return int_value(4);}
151  void key_code(int code) {int_value(4, code);}
157  int event_id() const {return int_value(8);}
163  void event_id(int id) {int_value(8, id);}
169  const char *show() const {return string(12);}
175  void show(const char *obj) {string(12, obj);}
181  void show(const std::string &obj) {string(12, obj);}
182 };
183 
184 }
185 }
186 
187 #endif
unsigned int flags() const
Get all flags as a word raw access.
Definition: resshortcut.h:114
int event_id() const
Get the event ID to be generated for key.
Definition: resshortcut.h:157
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
void init_string(int offset, const char *value)
Initialise a string in a constructor helper.
Definition: resbase.cc:1725
ResShortcut & operator=(const ResShortcut &other)
Assign this shortcut to be a copy of another.
Definition: resshortcut.h:73
Base class for objects, gadgets and menu items from ressources.
Definition: resbase.h:252
bool flag(int offset, int mask) const
Check if any of the bits in a mask are set.
Definition: resbase.h:352
unsigned int uint_value(int offset) const
Get an unsigned integer value.
Definition: resbase.h:324
Classes to use/edit toolbox resources in memory.
Window resource object.
Definition: reswindow.h:48
ResBase(ResImpl *impl)
Create from internal resource implementation.
Definition: resbase.h:262
Keyboard short cut.
Definition: resshortcut.h:43
int int_value(int offset) const
Get an integer value.
Definition: resbase.h:316
void show(const char *obj)
Set the Toolbox object to show.
Definition: resshortcut.h:175
const char * string(int offset) const
Return a string at the given offset.
Definition: resbase.cc:1555
const char * show() const
Get the Toolbox object to show.
Definition: resshortcut.h:169
void flags(unsigned int value)
Set all flags as a word.
Definition: resshortcut.h:122
The Window object represents a toolbox window.
Definition: window.h:69
void key_code(int code)
Set the WIMP key code for shortcut.
Definition: resshortcut.h:151
void show(const std::string &obj)
Set the Toolbox object to show.
Definition: resshortcut.h:181
ResShortcut(const ResShortcut &other)
Construct shortcut as a copy of another.
Definition: resshortcut.h:62
ResBase & operator=(const ResBase &other)
Assignment.
Definition: resbase.cc:1534
void make_writeable()
Make item writeable.
Definition: resshortcut.h:96
void event_id(int id)
Set the event ID to be generated for key.
Definition: resshortcut.h:163
int key_code() const
Get the WIMP key code for shortcut.
Definition: resshortcut.h:145
ResImpl * _impl
Internal Resource implementation.
Definition: resbase.h:255
ResShortcut(int code)
Construct a new shortcut for the given key code.
Definition: resshortcut.h:84