2012-03-31 15:43:01 +02:00
|
|
|
/*
|
2013-01-08 19:21:54 +01:00
|
|
|
* Copyright (c) 2010-2013 OTClient <https://github.com/edubart/otclient>
|
2012-03-31 15:43:01 +02:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2013-01-16 17:20:17 +01:00
|
|
|
#ifndef UITEXTEDIT_H
|
|
|
|
#define UITEXTEDIT_H
|
2012-03-31 15:43:01 +02:00
|
|
|
|
|
|
|
#include "uiwidget.h"
|
|
|
|
|
2012-06-22 05:14:13 +02:00
|
|
|
// @bindclass
|
2012-03-31 15:43:01 +02:00
|
|
|
class UITextEdit : public UIWidget
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
UITextEdit();
|
|
|
|
|
2012-06-08 18:58:08 +02:00
|
|
|
void drawSelf(Fw::DrawPane drawPane);
|
2012-03-31 15:43:01 +02:00
|
|
|
|
|
|
|
private:
|
2013-01-16 17:20:17 +01:00
|
|
|
void update(bool focusCursor = false);
|
2012-03-31 15:43:01 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
void setCursorPos(int pos);
|
2013-01-20 14:38:02 +01:00
|
|
|
void setSelection(int start, int end);
|
2013-01-17 12:34:13 +01:00
|
|
|
void setCursorVisible(bool enable) { m_cursorVisible = enable; }
|
2013-01-25 12:44:15 +01:00
|
|
|
void setChangeCursorImage(bool enable) { m_changeCursorImage = enable; }
|
2012-03-31 15:43:01 +02:00
|
|
|
void setTextHidden(bool hidden);
|
|
|
|
void setValidCharacters(const std::string validCharacters) { m_validCharacters = validCharacters; }
|
|
|
|
void setShiftNavigation(bool enable) { m_shiftNavigation = enable; }
|
|
|
|
void setMultiline(bool enable) { m_multiline = enable; }
|
2012-04-09 00:10:07 +02:00
|
|
|
void setMaxLength(uint maxLength) { m_maxLength = maxLength; }
|
2013-01-16 17:20:17 +01:00
|
|
|
void setTextVirtualOffset(const Point& offset);
|
|
|
|
void setEditable(bool editable) { m_editable = editable; }
|
2013-01-20 14:38:02 +01:00
|
|
|
void setSelectable(bool selectable) { m_selectable = selectable; }
|
|
|
|
void setSelectionColor(const Color& color) { m_selectionColor = color; }
|
|
|
|
void setSelectionBackgroundColor(const Color& color) { m_selectionBackgroundColor = color; }
|
2013-02-28 22:39:27 +01:00
|
|
|
void setAutoScroll(bool autoScroll) { m_autoScroll = autoScroll; }
|
2012-03-31 15:43:01 +02:00
|
|
|
|
2013-01-20 14:38:02 +01:00
|
|
|
void moveCursorHorizontally(bool right);
|
|
|
|
void moveCursorVertically(bool up);
|
2012-03-31 15:43:01 +02:00
|
|
|
void appendText(std::string text);
|
|
|
|
void appendCharacter(char c);
|
|
|
|
void removeCharacter(bool right);
|
2013-01-20 14:38:02 +01:00
|
|
|
void blinkCursor();
|
|
|
|
|
|
|
|
void del(bool right = false);
|
|
|
|
void paste(const std::string& text);
|
|
|
|
std::string copy();
|
|
|
|
std::string cut();
|
|
|
|
void selectAll() { setSelection(0, m_text.length()); }
|
|
|
|
void clearSelection() { setSelection(0, 0); }
|
2012-03-31 15:43:01 +02:00
|
|
|
|
2013-01-16 17:20:17 +01:00
|
|
|
void wrapText();
|
2012-03-31 15:43:01 +02:00
|
|
|
std::string getDisplayedText();
|
2013-01-20 14:38:02 +01:00
|
|
|
std::string getSelection();
|
2012-03-31 15:43:01 +02:00
|
|
|
int getTextPos(Point pos);
|
|
|
|
int getCursorPos() { return m_cursorPos; }
|
2013-01-16 17:20:17 +01:00
|
|
|
Point getTextVirtualOffset() { return m_textVirtualOffset; }
|
|
|
|
Size getTextVirtualSize() { return m_textVirtualSize; }
|
|
|
|
Size getTextTotalSize() { return m_textTotalSize; }
|
2012-05-01 02:20:27 +02:00
|
|
|
uint getMaxLength() { return m_maxLength; }
|
2013-01-20 14:38:02 +01:00
|
|
|
int getSelectionStart() { return m_selectionStart; }
|
|
|
|
int getSelectionEnd() { return m_selectionEnd; }
|
|
|
|
Color getSelectionColor() { return m_selectionColor; }
|
|
|
|
Color getSelectionBackgroundColor() { return m_selectionBackgroundColor; }
|
|
|
|
bool hasSelection() { return m_selectionEnd - m_selectionStart > 0; }
|
2013-01-16 17:20:17 +01:00
|
|
|
bool isCursorVisible() { return m_cursorVisible; }
|
2013-01-25 12:44:15 +01:00
|
|
|
bool isChangingCursorImage() { return m_changeCursorImage; }
|
2012-03-31 15:43:01 +02:00
|
|
|
bool isTextHidden() { return m_textHidden; }
|
|
|
|
bool isShiftNavigation() { return m_shiftNavigation; }
|
|
|
|
bool isMultiline() { return m_multiline; }
|
2013-01-16 17:20:17 +01:00
|
|
|
bool isEditable() { return m_editable; }
|
2013-01-20 14:38:02 +01:00
|
|
|
bool isSelectable() { return m_selectable; }
|
2013-02-28 22:39:27 +01:00
|
|
|
bool isAutoScrolling() { return m_autoScroll; }
|
2012-03-31 15:43:01 +02:00
|
|
|
|
|
|
|
protected:
|
2013-01-20 16:40:40 +01:00
|
|
|
void updateText();
|
|
|
|
|
2012-08-10 21:26:39 +02:00
|
|
|
virtual void onHoverChange(bool hovered);
|
2012-03-31 15:43:01 +02:00
|
|
|
virtual void onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode);
|
|
|
|
virtual void onGeometryChange(const Rect& oldRect, const Rect& newRect);
|
|
|
|
virtual void onFocusChange(bool focused, Fw::FocusReason reason);
|
|
|
|
virtual bool onKeyText(const std::string& keyText);
|
|
|
|
virtual bool onKeyPress(uchar keyCode, int keyboardModifiers, int autoRepeatTicks);
|
|
|
|
virtual bool onMousePress(const Point& mousePos, Fw::MouseButton button);
|
2013-01-20 14:38:02 +01:00
|
|
|
virtual bool onMouseRelease(const Point& mousePos, Fw::MouseButton button);
|
|
|
|
virtual bool onMouseMove(const Point& mousePos, const Point& mouseMoved);
|
2013-01-20 16:40:40 +01:00
|
|
|
virtual bool onDoubleClick(const Point& mousePos);
|
2013-01-16 17:20:17 +01:00
|
|
|
virtual void onTextAreaUpdate(const Point& vitualOffset, const Size& virtualSize, const Size& totalSize);
|
2012-03-31 15:43:01 +02:00
|
|
|
|
|
|
|
private:
|
2013-01-20 14:38:02 +01:00
|
|
|
void disableUpdates() { m_updatesEnabled = false; }
|
|
|
|
void enableUpdates() { m_updatesEnabled = true; }
|
2012-03-31 15:43:01 +02:00
|
|
|
|
|
|
|
Rect m_drawArea;
|
|
|
|
int m_cursorPos;
|
2013-01-16 17:20:17 +01:00
|
|
|
Point m_textVirtualOffset;
|
|
|
|
Size m_textVirtualSize;
|
|
|
|
Size m_textTotalSize;
|
2012-03-31 15:43:01 +02:00
|
|
|
ticks_t m_cursorTicks;
|
|
|
|
bool m_textHidden;
|
|
|
|
bool m_shiftNavigation;
|
|
|
|
bool m_multiline;
|
2013-01-16 17:20:17 +01:00
|
|
|
bool m_cursorInRange;
|
|
|
|
bool m_cursorVisible;
|
|
|
|
bool m_editable;
|
2013-01-25 12:44:15 +01:00
|
|
|
bool m_changeCursorImage;
|
2012-03-31 15:43:01 +02:00
|
|
|
std::string m_validCharacters;
|
2012-04-09 00:10:07 +02:00
|
|
|
uint m_maxLength;
|
2013-01-20 14:38:02 +01:00
|
|
|
bool m_updatesEnabled;
|
2013-02-28 22:39:27 +01:00
|
|
|
bool m_autoScroll;
|
2013-01-20 14:38:02 +01:00
|
|
|
|
|
|
|
bool m_selectable;
|
|
|
|
int m_selectionReference;
|
|
|
|
int m_selectionStart;
|
|
|
|
int m_selectionEnd;
|
|
|
|
|
|
|
|
Color m_selectionColor;
|
|
|
|
Color m_selectionBackgroundColor;
|
2012-03-31 15:43:01 +02:00
|
|
|
|
|
|
|
std::vector<Rect> m_glyphsCoords;
|
|
|
|
std::vector<Rect> m_glyphsTexCoords;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|