1 /***********************************************************************
2     created:    Thu Jul 7 2005
3     author:     Paul D Turner <paul@cegui.org.uk>
4 *************************************************************************/
5 /***************************************************************************
6  *   Copyright (C) 2004 - 2006 Paul D Turner & The CEGUI Development Team
7  *
8  *   Permission is hereby granted, free of charge, to any person obtaining
9  *   a copy of this software and associated documentation files (the
10  *   "Software"), to deal in the Software without restriction, including
11  *   without limitation the rights to use, copy, modify, merge, publish,
12  *   distribute, sublicense, and/or sell copies of the Software, and to
13  *   permit persons to whom the Software is furnished to do so, subject to
14  *   the following conditions:
15  *
16  *   The above copyright notice and this permission notice shall be
17  *   included in all copies or substantial portions of the Software.
18  *
19  *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  *   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  *   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  *   IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  *   OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  *   ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  *   OTHER DEALINGS IN THE SOFTWARE.
26  ***************************************************************************/
27 #ifndef _FalMultiLineEditbox_h_
28 #define _FalMultiLineEditbox_h_
29 
30 #include "CEGUI/WindowRendererSets/Core/Module.h"
31 #include "CEGUI/widgets/MultiLineEditbox.h"
32 
33 #if defined(_MSC_VER)
34 #	pragma warning(push)
35 #	pragma warning(disable : 4251)
36 #endif
37 
38 // Start of CEGUI namespace section
39 namespace CEGUI
40 {
41 /*!
42 \brief
43     MultiLineEditbox class for the FalagardBase module.
44 
45     This class requires LookNFeel to be assigned.  The LookNFeel should provide the following:
46 
47     States:
48         - Enabled    - Rendering for when the editbox is in enabled and is in read-write mode.
49         - ReadOnly  - Rendering for when the editbox is in enabled and is in read-only mode.
50         - Disabled  - Rendering for when the editbox is disabled.
51 
52     NamedAreas:
53         TextArea         - area where text, selection, and caret imagery will appear.
54         TextAreaHScroll  - TextArea when only horizontal scrollbar is visible.
55         TextAreaVScroll  - TextArea when only vertical scrollbar is visible.
56         TextAreaHVScroll - TextArea when both horizontal and vertical scrollbar is visible.
57 
58     PropertyDefinitions (optional, defaults will be black):
59         - NormalTextColour        - property that accesses a colour value to be used to render normal unselected text.
60         - SelectedTextColour      - property that accesses a colour value to be used to render selected text.
61         - ActiveSelectionColour   - property that accesses a colour value to be used to render active selection highlight.
62         - InactiveSelectionColour - property that accesses a colour value to be used to render inactive selection highlight.
63 
64     Imagery Sections:
65         - Caret
66 
67     Child Widgets:
68         Scrollbar based widget with name suffix "__auto_vscrollbar__"
69         Scrollbar based widget with name suffix "__auto_hscrollbar__"
70 
71 */
72 class COREWRSET_API FalagardMultiLineEditbox : public MultiLineEditboxWindowRenderer
73 {
74 public:
75     static const String TypeName;     //! type name for this widget.
76 
77     //! Name of the optional property to access for the unselected text colour.
78     static const String UnselectedTextColourPropertyName;
79     //! Name of the optional property to access for the selected text colour.
80     static const String SelectedTextColourPropertyName;
81     //! Name of the optional property to access to obtain active selection rendering colour.
82     static const String ActiveSelectionColourPropertyName;
83     //! Name of the optional property to access to obtain inactive selection rendering colour.
84     static const String InactiveSelectionColourPropertyName;
85     //! The default timeout (in seconds) used when blinking the caret.
86     static const float DefaultCaretBlinkTimeout;
87 
88     /*!
89     \brief
90         Constructor
91     */
92     FalagardMultiLineEditbox(const String& type);
93 
94     // overridden from base classes.
95     Rectf getTextRenderArea(void) const;
96     void render();
97     void update(float elapsed);
98 
99     //! return whether the blinking caret is enabled.
100     bool isCaretBlinkEnabled() const;
101     //! return the caret blink timeout period (only used if blink is enabled).
102     float getCaretBlinkTimeout() const;
103     //! set whether the blinking caret is enabled.
104     void setCaretBlinkEnabled(bool enable);
105     //! set the caret blink timeout period (only used if blink is enabled).
106     void setCaretBlinkTimeout(float seconds);
107 
108     // overridden from base class
109     bool handleFontRenderSizeChange(const Font* const font);
110 
111 protected:
112     /*!
113     \brief
114         Perform rendering of the widget control frame and other 'static' areas.  This
115         method should not render the actual text.  Note that the text will be rendered
116         to layer 4 and the selection brush to layer 3, other layers can be used for
117         rendering imagery behind and infront of the text & selection..
118 
119     \return
120         Nothing.
121     */
122     void cacheEditboxBaseImagery();
123 
124     /*!
125     \brief
126         Render the caret.
127 
128     \return
129         Nothing
130     */
131     void cacheCaretImagery(const Rectf& textArea);
132 
133     /*!
134     \brief
135         Render text lines.
136     */
137     void cacheTextLines(const Rectf& dest_area);
138 
139     /*!
140     \brief
141         Set the given ColourRect to the colour to be used for rendering Editbox
142         text oustside of the selected region.
143     */
144     void setColourRectToUnselectedTextColour(ColourRect& colour_rect) const;
145 
146     /*!
147     \brief
148         Set the given ColourRect to the colour to be used for rendering Editbox
149         text falling within the selected region.
150     */
151     void setColourRectToSelectedTextColour(ColourRect& colour_rect) const;
152 
153     /*!
154     \brief
155         Set the given ColouRect to the colours to be used for rendering the
156         selection highlight when the editbox is active.
157     */
158     void setColourRectToActiveSelectionColour(ColourRect& colour_rect) const;
159 
160     /*!
161     \brief
162         set the given ColourRect to the colours to be used for rendering the
163         selection highlight when the editbox is inactive.
164     */
165     void setColourRectToInactiveSelectionColour(ColourRect& colour_rect) const;
166 
167     /*!
168     \brief
169         Set the given ColourRect to the colour(s) fetched from the named
170         property if it exists, else the default colour of black.
171 
172     \param propertyName
173         String object holding the name of the property to be accessed if it
174         exists.
175 
176     \param colour_rect
177         Reference to a ColourRect that will be set.
178     */
179     void setColourRectToOptionalPropertyColour(const String& propertyName,
180                                                ColourRect& colour_rect) const;
181 
182     //! true if the caret imagery should blink.
183     bool d_blinkCaret;
184     //! time-out in seconds used for blinking the caret.
185     float d_caretBlinkTimeout;
186     //! current time elapsed since last caret blink state change.
187     float d_caretBlinkElapsed;
188     //! true if caret should be shown.
189     bool d_showCaret;
190 };
191 
192 } // End of  CEGUI namespace section
193 
194 
195 #if defined(_MSC_VER)
196 #	pragma warning(pop)
197 #endif
198 
199 #endif  // end of guard _FalMultiLineEditbox_h_
200