Add warning when disabling secure.enable_security (#9943)
[oweals/minetest.git] / src / gui / intlGUIEditBox.h
1 // Copyright (C) 2002-2013 Nikolaus Gebhardt
2 // This file is part of the "Irrlicht Engine".
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
4
5 #pragma once
6
7 #include "IrrCompileConfig.h"
8 //#ifdef _IRR_COMPILE_WITH_GUI_
9
10 #include <IGUIEditBox.h>
11 #include "irrArray.h"
12 #include "IOSOperator.h"
13 #include "guiScrollBar.h"
14
15 namespace irr
16 {
17 namespace gui
18 {
19         class intlGUIEditBox : public IGUIEditBox
20         {
21         public:
22
23                 //! constructor
24                 intlGUIEditBox(const wchar_t* text, bool border, IGUIEnvironment* environment,
25                         IGUIElement* parent, s32 id, const core::rect<s32>& rectangle,
26                         bool writable = true, bool has_vscrollbar = false);
27
28                 //! destructor
29                 virtual ~intlGUIEditBox();
30
31                 //! Sets another skin independent font.
32                 virtual void setOverrideFont(IGUIFont* font=0);
33
34                 //! Gets the override font (if any)
35                 /** \return The override font (may be 0) */
36                 virtual IGUIFont* getOverrideFont() const;
37
38                 //! Get the font which is used right now for drawing
39                 /** Currently this is the override font when one is set and the
40                 font of the active skin otherwise */
41                 virtual IGUIFont* getActiveFont() const;
42
43                 //! Sets another color for the text.
44                 virtual void setOverrideColor(video::SColor color);
45
46                 //! Gets the override color
47                 virtual video::SColor getOverrideColor() const;
48
49                 //! Sets if the text should use the overide color or the
50                 //! color in the gui skin.
51                 virtual void enableOverrideColor(bool enable);
52
53                 //! Checks if an override color is enabled
54                 /** \return true if the override color is enabled, false otherwise */
55                 virtual bool isOverrideColorEnabled(void) const;
56
57                 //! Sets whether to draw the background
58                 virtual void setDrawBackground(bool draw);
59
60                 virtual bool isDrawBackgroundEnabled() const { return true; }
61
62                 //! Turns the border on or off
63                 virtual void setDrawBorder(bool border);
64
65                 virtual bool isDrawBorderEnabled() const { return Border; }
66
67                 //! Enables or disables word wrap for using the edit box as multiline text editor.
68                 virtual void setWordWrap(bool enable);
69
70                 //! Checks if word wrap is enabled
71                 //! \return true if word wrap is enabled, false otherwise
72                 virtual bool isWordWrapEnabled() const;
73
74                 //! Enables or disables newlines.
75                 /** \param enable: If set to true, the EGET_EDITBOX_ENTER event will not be fired,
76                 instead a newline character will be inserted. */
77                 virtual void setMultiLine(bool enable);
78
79                 //! Checks if multi line editing is enabled
80                 //! \return true if mult-line is enabled, false otherwise
81                 virtual bool isMultiLineEnabled() const;
82
83                 //! Enables or disables automatic scrolling with cursor position
84                 //! \param enable: If set to true, the text will move around with the cursor position
85                 virtual void setAutoScroll(bool enable);
86
87                 //! Checks to see if automatic scrolling is enabled
88                 //! \return true if automatic scrolling is enabled, false if not
89                 virtual bool isAutoScrollEnabled() const;
90
91                 //! Gets the size area of the text in the edit box
92                 //! \return Returns the size in pixels of the text
93                 virtual core::dimension2du getTextDimension();
94
95                 //! Sets text justification
96                 virtual void setTextAlignment(EGUI_ALIGNMENT horizontal, EGUI_ALIGNMENT vertical);
97
98                 //! called if an event happened.
99                 virtual bool OnEvent(const SEvent& event);
100
101                 //! draws the element and its children
102                 virtual void draw();
103
104                 //! Sets the new caption of this element.
105                 virtual void setText(const wchar_t* text);
106
107                 //! Sets the maximum amount of characters which may be entered in the box.
108                 //! \param max: Maximum amount of characters. If 0, the character amount is
109                 //! infinity.
110                 virtual void setMax(u32 max);
111
112                 //! Returns maximum amount of characters, previously set by setMax();
113                 virtual u32 getMax() const;
114
115                 //! Sets whether the edit box is a password box. Setting this to true will
116                 /** disable MultiLine, WordWrap and the ability to copy with ctrl+c or ctrl+x
117                 \param passwordBox: true to enable password, false to disable
118                 \param passwordChar: the character that is displayed instead of letters */
119                 virtual void setPasswordBox(bool passwordBox, wchar_t passwordChar = L'*');
120
121                 //! Returns true if the edit box is currently a password box.
122                 virtual bool isPasswordBox() const;
123
124                 //! Updates the absolute position, splits text if required
125                 virtual void updateAbsolutePosition();
126
127                 //! set true if this EditBox is writable
128                 virtual void setWritable(bool can_write_text);
129
130                 //! Writes attributes of the element.
131                 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
132
133                 //! Reads attributes of the element
134                 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
135
136                 virtual void setCursorChar(const wchar_t cursorChar) {}
137
138                 virtual wchar_t getCursorChar() const { return L'|'; }
139
140                 virtual void setCursorBlinkTime(u32 timeMs) {}
141
142                 virtual u32 getCursorBlinkTime() const { return 500; }
143
144         protected:
145                 //! Breaks the single text line.
146                 void breakText();
147                 //! sets the area of the given line
148                 void setTextRect(s32 line);
149                 //! returns the line number that the cursor is on
150                 s32 getLineFromPos(s32 pos);
151                 //! adds a letter to the edit box
152                 void inputChar(wchar_t c);
153                 //! calculates the current scroll position
154                 void calculateScrollPos();
155                 //! send some gui event to parent
156                 void sendGuiEvent(EGUI_EVENT_TYPE type);
157                 //! set text markers
158                 void setTextMarkers(s32 begin, s32 end);
159
160                 bool processKey(const SEvent& event);
161                 bool processMouse(const SEvent& event);
162                 s32 getCursorPos(s32 x, s32 y);
163
164                 //! Create a vertical scrollbar
165                 void createVScrollBar();
166
167                 //! Update the vertical scrollbar (visibilty & scroll position)
168                 void updateVScrollBar();
169
170                 bool MouseMarking = false;
171                 bool Border;
172                 bool OverrideColorEnabled = false;
173                 s32 MarkBegin = 0;
174                 s32 MarkEnd = 0;
175
176                 video::SColor OverrideColor = video::SColor(101,255,255,255);
177                 gui::IGUIFont *OverrideFont = nullptr;
178                 gui::IGUIFont *LastBreakFont = nullptr;
179                 IOSOperator *Operator = nullptr;
180
181                 u64 BlinkStartTime = 0;
182                 s32 CursorPos = 0;
183                 s32 HScrollPos = 0;
184                 s32 VScrollPos = 0; // scroll position in characters
185                 u32 Max = 0;
186
187                 bool WordWrap = false;
188                 bool MultiLine = false;
189                 bool AutoScroll = true;
190                 bool PasswordBox = false;
191                 wchar_t PasswordChar = L'*';
192                 EGUI_ALIGNMENT HAlign = EGUIA_UPPERLEFT;
193                 EGUI_ALIGNMENT VAlign = EGUIA_CENTER;
194
195                 core::array<core::stringw> BrokenText;
196                 core::array<s32> BrokenTextPositions;
197
198                 core::rect<s32> CurrentTextRect = core::rect<s32>(0,0,1,1);
199                 core::rect<s32> FrameRect; // temporary values
200                 u32 m_scrollbar_width;
201                 GUIScrollBar *m_vscrollbar;
202                 bool m_writable;
203
204         };
205
206
207 } // end namespace gui
208 } // end namespace irr
209
210 //#endif // _IRR_COMPILE_WITH_GUI_