summaryrefslogtreecommitdiff
path: root/osframework/source/SexyAppFramework/EditWidget.h
blob: 45c70e205b402c1679c1add3703d71f0779e3f7a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef __EDITWIDGET_H__
#define __EDITWIDGET_H__

#include "Widget.h"

namespace Sexy
{

class Font;
class EditListener;

class EditWidget : public Widget
{
public:
	enum
	{
		COLOR_BKG,
		COLOR_OUTLINE,
		COLOR_TEXT,
		COLOR_HILITE,
		COLOR_HILITE_TEXT,
		NUM_COLORS
	};

	int						mId;
	SexyString				mString;
	SexyString				mPasswordDisplayString;
	Font*					mFont;

	struct WidthCheck
	{
		Font *mFont;
		int mWidth;
	};
	typedef std::list<WidthCheck> WidthCheckList;
	WidthCheckList				mWidthCheckList;
	
	EditListener*			mEditListener;		
	bool					mShowingCursor;
	bool					mDrawSelOverride; // set this to true to draw selected text even when not in focus
	bool					mHadDoubleClick;	// Used to fix a bug with double clicking to hilite a word after the widget manager started calling mouse drag before mouse down/up events
	int						mCursorPos;
	int						mHilitePos;
	int						mBlinkAcc;
	int						mBlinkDelay;
	int						mLeftPos;		
	int						mMaxChars;
	int						mMaxPixels;
	SexyChar				mPasswordChar;
	
	SexyString				mUndoString;
	int						mUndoCursor;
	int						mUndoHilitePos;
	int						mLastModifyIdx;


protected:
	virtual void			ProcessKey(KeyCode theKey, SexyChar theChar);
	SexyString&			GetDisplayString();
	virtual void			HiliteWord();
	void					UpdateCaretPos();

public:
	virtual void			SetFont(Font* theFont, Font* theWidthCheckFont = NULL);
	virtual void			SetText(const SexyString& theText, bool leftPosToZero = true);
	virtual bool			IsPartOfWord(SexyChar theChar);
	virtual int				GetCharAt(int x, int y);

	virtual void			Resize(int theX, int theY, int theWidth, int theHeight);
	virtual void			Draw(Graphics* g); // Already translated;

	virtual void			Update();
	virtual void			MarkDirty();

	virtual bool			WantsFocus();
	virtual void			GotFocus();
	virtual void			LostFocus();
	virtual void			FocusCursor(bool bigJump);

	virtual void			KeyDown(KeyCode theKey);
	virtual void			KeyChar(SexyChar theChar);

	virtual void			MouseDown(int x, int y, int theClickCount) { Widget::MouseDown(x, y, theClickCount); }
	virtual void			MouseDown(int x, int y, int theBtnNum, int theClickCount);
	virtual void			MouseUp(int x, int y) { Widget::MouseUp(x, y); }
	virtual void			MouseUp(int x, int y, int theClickCount) { Widget::MouseUp(x, y, theClickCount); }
	virtual void			MouseUp(int x, int y, int theBtnNum, int theClickCount);
	virtual void			MouseDrag(int x, int y);
	virtual void			MouseEnter();
	virtual void			MouseLeave();
	void					ClearWidthCheckFonts();
	void					AddWidthCheckFont(Font *theFont, int theMaxPixels = -1); // defaults to mMaxPixels
	void					EnforceMaxPixels();

public:
	EditWidget(int theId, EditListener* theEditListener);
	virtual ~EditWidget();
};

}

#endif //__EDITWIDGET_H__