tbx  0.7.5
textview.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  * TextView.h
27  *
28  * Created on: 31-Jul-2009
29  * Author: alanb
30  */
31 
32 #ifndef TBX_TEXTVIEW_H_
33 #define TBX_TEXTVIEW_H_
34 
35 #include "../window.h"
36 #include "../redrawlistener.h"
37 #include "../openwindowlistener.h"
38 #include "../margin.h"
39 #include "../colour.h"
40 #include <vector>
41 
42 namespace tbx
43 {
44 namespace view
45 {
49 class TextView :
50  public tbx::RedrawListener,
52 {
53 private:
54  tbx::Window _window;
55  tbx::Margin _margin;
56  bool _wrap;
57  char *_text;
58  unsigned int _size;
59  std::vector<unsigned int> _line_end;
60  unsigned int _width;
61  tbx::Colour _foreground;
62  tbx::Colour _background;
63 
64 public:
65  TextView(tbx::Window window, bool wrap = false);
66  virtual ~TextView();
67 
68  void update_window_extent();
69  void refresh();
70 
76  tbx::Window &window() {return _window;}
77 
84  const tbx::Margin &margin() const {return _margin;}
85  void margin(const tbx::Margin &margin);
86 
92  const char *text() const {return _text;}
93  void text(const char *text);
94  void text(const std::string &text);
95 
101  unsigned int size() const {return _size;}
102 
108  tbx::Colour background() const {return _background;}
114  void background(tbx::Colour colour);
120  tbx::Colour foreground() const {return _foreground;}
126  void foreground(tbx::Colour colour);
127 
128 
129  bool load_file(const std::string &file_name);
130 
136  bool wrap() const {return _wrap;}
137  void wrap(bool w);
138 
139  // Redraw listener override
140  virtual void redraw(const tbx::RedrawEvent &event);
141  virtual void open_window(tbx::OpenWindowEvent &event);
142 
143 private:
144  void update_window_extent(const BBox &visible_bounds);
145  void recalc_layout();
146  void recalc_layout(const BBox &visible_bounds);
147 };
148 
149 }
150 }
151 #endif /* TBX_TEXTVIEW_H_ */
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
virtual void redraw(const tbx::RedrawEvent &event)
Redraw the window.
Definition: textview.cc:216
Helper classes to display and edit data.
void refresh()
Refresh the whole report view.
Definition: textview.cc:204
Class to represent a two dimensional bounding box.
Definition: bbox.h:37
tbx::Colour background() const
Get current background colour for the text.
Definition: textview.h:108
TextView(tbx::Window window, bool wrap=false)
Construct a text view.
Definition: textview.cc:52
tbx::Window & window()
Get the window the text view is on.
Definition: textview.h:76
Class to represent a margin around an area.
Definition: margin.h:34
Event passed to redraw listener to give details on the area that needs a redraw.
Definition: redrawlistener.h:43
void update_window_extent()
Update the Window extent after a change in size of text.
Definition: textview.cc:172
const char * text() const
Get a pointer to the text.
Definition: textview.h:92
virtual void open_window(tbx::OpenWindowEvent &event)
Window has been opened or resized, so re do layout.
Definition: textview.cc:257
unsigned int size() const
Get the current size of the text.
Definition: textview.h:101
bool load_file(const std::string &file_name)
Load text for view from file.
Definition: textview.cc:345
The Window object represents a toolbox window.
Definition: window.h:69
const tbx::Margin & margin() const
Get the margin between the text view contents and the edge of the Window.
Definition: textview.h:84
Redraw event listener.
Definition: redrawlistener.h:75
Class to display text in a window.
Definition: textview.h:49
Class to represent a RGB colour.
Definition: colour.h:43
bool wrap() const
Check it text view is set to wrap text.
Definition: textview.h:136
Listener for Wimp Open Window Request events.
Definition: openwindowlistener.h:97
Event data for open window request listener.
Definition: openwindowlistener.h:39
tbx::Colour foreground() const
Get current foreground colour for the text.
Definition: textview.h:120
virtual ~TextView()
Destructor removes listeners from window and deletes the text.
Definition: textview.cc:68