tbx  0.7.5
resproginfo.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_ProgInfo_H
26 #define TBX_RES_ProgInfo_H
27 
28 #include "resobject.h"
29 
30 #include <stdexcept>
31 
32 namespace tbx
33 {
34 namespace res
35 {
36 
42 class ResProgInfo : public ResObject
43 {
44  public:
45  enum { CLASS_ID = 0x82b40 };
46 
52  ResProgInfo(std::string name, bool has_web_button = false ) :
53  ResObject(name, CLASS_ID, has_web_button ? 101 : 100, 36 + (has_web_button ? 40 : 32))
54  {
55  if (has_web_button) flags(24);
56  init_message(4, 0) ; // Title - default
57  init_message(12, 0) ; // Purpose
58  init_message(16, 0) ; // Author
59  licence_type(-1);
60  init_message(24, 0) ; // Version
61  init_string(28, 0); ; // Alternative window
62  if (has_web_button)
63  {
64  init_message(32,0);
65  }
66  }
67 
73  ResProgInfo(const ResProgInfo &other) : ResObject(other) {}
74 
80  ResProgInfo(const ResObject &other) : ResObject(other) {check_class_id(CLASS_ID);}
81 
88  {
89  ResObject::operator=(other);
90  return *this;
91  }
92 
99  {
100  other.check_class_id(CLASS_ID);
101  ResObject::operator =(other);
102  return *this;
103  }
104 
112  unsigned int flags() const {return uint_value(0);}
113 
120  void flags(unsigned int value) {uint_value(0, value);}
126  bool generate_about_to_be_shown() const {return flag(0, 1<<0);}
132  void generate_about_to_be_shown(bool value) {flag(0,1<<0,value);}
138  bool generate_dialogue_completed() const {return flag(0, 1<<1);}
144  void generate_dialogue_completed(bool value) {flag(0,1<<1,value);}
145 
151  bool include_licence_type() const {return flag(0,4);}
157  void include_licence_type(bool value) {flag(0,4,value);}
158 
167  bool include_web_page_button() const {return flag(0, 8);}
176  bool generate_web_page_click() const {return flag(0, 16);}
177 
183  const char *title() const {return message(4);}
191  void title(const char *value, int max_length = -1) {message_with_length(4, value, max_length);}
199  void title(const std::string &value, int max_length = -1) {message_with_length(4, value, max_length);}
203  int max_title() const {return int_value(8);}
204 
208  const char *purpose() const {return message(12);}
209 
215  void purpose(const char *value) {message(12, value);}
221  void purpose(const std::string &value) {message(12, value);}
222 
226  const char *author() const {return message(16);}
227 
233  void author(const char *value) {message(16, value);}
239  void author(const std::string &value) {message(16, value);}
240 
246  int licence_type() const {return int_value(20);}
247 
261  void licence_type(int type) {int_value(20, type);}
262 
266  const char *version() const {return message(24);}
267 
273  void version(const char *value) {message(24, value);}
279  void version(const std::string &value) {message(24, value);}
280 
287  const char *window() const {return string(28);}
294  void window(const char *value) {string(28, value);}
301  void window(const std::string &value) {string(28, value);}
302 
310  const char *uri() const {return (object_version() >= 101) ? string(32) : "";}
319  void uri(const char *value)
320  {
321  //TODO: upgrading object if necessary rather than throw an exception
322  if (object_version() < 101) throw std::invalid_argument("ProgInfo version not high enough for URI");
323  message(32, value);
324  }
333  void uri(const std::string &value)
334  {
335  //TODO: set upgrading object if necessary
336  if (object_version() < 101) throw std::invalid_argument("ProgInfo version not high enough for URI");
337  message(32, value);
338  }
339 
345  int web_event() const {return (object_version() >= 101) ? int_value(36) : -1;}
352  void web_event(int event_id)
353  {
354  //TODO: set upgrading object if necessary
355  if (object_version() < 101) throw std::invalid_argument("ProgInfo version not high enough for URI");
356  int_value(36, event_id);
357  }
358 };
359 
360 }
361 
362 }
363 #endif // TBX_RES_ProgInfo_H
bool include_web_page_button() const
Check if the web page button is included on the dialogue.
Definition: resproginfo.h:167
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
void licence_type(int type)
Set the licence type.
Definition: resproginfo.h:261
int object_version() const
Return version number * 100.
Definition: resobject.h:93
bool generate_dialogue_completed() const
Check if the dialogue completed event should be generated.
Definition: resproginfo.h:138
void version(const std::string &value)
Set the version of the application.
Definition: resproginfo.h:279
const char * uri() const
Get URI.
Definition: resproginfo.h:310
void init_string(int offset, const char *value)
Initialise a string in a constructor helper.
Definition: resbase.cc:1725
void generate_about_to_be_shown(bool value)
Set if the about to be shown event should be generated.
Definition: resproginfo.h:132
const char * author() const
Get the author.
Definition: resproginfo.h:226
const char * title() const
Get the title of the dialogue.
Definition: resproginfo.h:183
void message_with_length(int offset, const char *value, int length=-1)
Assign a message where the length is at offset+4.
Definition: resbase.cc:1639
bool flag(int offset, int mask) const
Check if any of the bits in a mask are set.
Definition: resbase.h:352
int web_event() const
Get the event generated for web page click added with version 1.01.
Definition: resproginfo.h:345
void web_event(int event_id)
Set the event generated for web page click added with version 1.01.
Definition: resproginfo.h:352
void uri(const std::string &value)
Set URI.
Definition: resproginfo.h:333
bool generate_web_page_click() const
Check if the web page button generates a click event.
Definition: resproginfo.h:176
void flags(unsigned int value)
Set all flags as a word.
Definition: resproginfo.h:120
unsigned int uint_value(int offset) const
Get an unsigned integer value.
Definition: resbase.h:324
void check_class_id(int class_id) const
Check if this objects class id is as specified.
Definition: resobject.cc:383
Classes to use/edit toolbox resources in memory.
ResProgInfo & operator=(const ResObject &other)
Assignment from ResObject.
Definition: resproginfo.h:98
void author(const std::string &value)
Set the author of the application.
Definition: resproginfo.h:239
void include_licence_type(bool value)
Set if licence type is included on the dialogue.
Definition: resproginfo.h:157
void window(const std::string &value)
Set the name of the window template that provides the window for this object.
Definition: resproginfo.h:301
int int_value(int offset) const
Get an integer value.
Definition: resbase.h:316
const char * string(int offset) const
Return a string at the given offset.
Definition: resbase.cc:1555
ResProgInfo(const ResObject &other)
Construct from a ResObject.
Definition: resproginfo.h:80
void generate_dialogue_completed(bool value)
Set if the dialogue completed event should be generated.
Definition: resproginfo.h:144
void title(const std::string &value, int max_length=-1)
Set the title of the dialogue.
Definition: resproginfo.h:199
void version(const char *value)
Set the version of the application.
Definition: resproginfo.h:273
int licence_type() const
Get the licence type.
Definition: resproginfo.h:246
const char * message(int offset) const
Get the message string at the given offset.
Definition: resbase.cc:1602
const char * name() const
Return pointer to name of object.
Definition: resobject.h:79
bool include_licence_type() const
Check if licence type is included on the dialogue.
Definition: resproginfo.h:151
ResObject & operator=(const ResObject &other)
Assignment.
Definition: resobject.cc:109
ResProgInfo(const ResProgInfo &other)
Copy constructor.
Definition: resproginfo.h:73
const char * version() const
Get the version.
Definition: resproginfo.h:266
bool generate_about_to_be_shown() const
Check if the about to be shown event should be generated.
Definition: resproginfo.h:126
void purpose(const char *value)
Set the purpose of the application.
Definition: resproginfo.h:215
void title(const char *value, int max_length=-1)
Set the title of the dialogue.
Definition: resproginfo.h:191
Base class for a resource object that can be edited.
Definition: resobject.h:52
const char * purpose() const
Get the purpose.
Definition: resproginfo.h:208
ResProgInfo(std::string name, bool has_web_button=false)
Constructor and empty ResProgInfo.
Definition: resproginfo.h:52
const char * window() const
Get the name of the window template that provides the window for this object.
Definition: resproginfo.h:287
void uri(const char *value)
Set URI.
Definition: resproginfo.h:319
ResProgInfo & operator=(const ResProgInfo &other)
Assignment.
Definition: resproginfo.h:87
int max_title() const
Get the maximum size the title can be.
Definition: resproginfo.h:203
Class to represent a ProgInfo resource.
Definition: resproginfo.h:42
void purpose(const std::string &value)
Set the purpose of the application.
Definition: resproginfo.h:221
unsigned int flags() const
Get all flags as a word raw access.
Definition: resproginfo.h:112
void window(const char *value)
Set the name of the window template that provides the window for this object.
Definition: resproginfo.h:294
void author(const char *value)
Set the author of the application.
Definition: resproginfo.h:233
void init_message(int offset, const char *value)
Initialise a message in a constructor helper.
Definition: resbase.cc:1736