1 /////////////////////////////////////////
2 //
3 //             OpenLieroX
4 //
5 // code under LGPL, based on JasonBs work,
6 // enhanced by Dark Charlie and Albert Zeyer
7 //
8 //
9 /////////////////////////////////////////
10 
11 
12 // Text box
13 // Created 30/6/02
14 // Jason Boettcher
15 
16 
17 #ifndef __CTEXTBOX_H__DEPRECATED_GUI__
18 #define __CTEXTBOX_H__DEPRECATED_GUI__
19 
20 
21 #include "InputEvents.h"
22 #include "Cursor.h"
23 #include "Timer.h"
24 #include "Event.h"
25 
26 
27 namespace DeprecatedGUI {
28 
29 // Event types
30 enum {
31 	TXT_NONE=-1,
32 	TXT_CHANGE=0,
33 	TXT_MOUSEOVER,
34 	TXT_ENTER,
35 	TXT_TAB
36 };
37 
38 
39 // Messages
40 enum {
41 	TXS_GETTEXT=0,
42 	TXS_SETTEXT,
43 	TXM_SETFLAGS,
44 	TXM_SETMAX,
45 	TXM_GETTEXTLENGTH
46 };
47 
48 
49 // Flags
50 enum {
51 	TXF_PASSWORD = 0x0001,
52 	TXF_NOUNICODE = 0x0002
53 };
54 
55 
56 class CTextbox : public CWidget {
57 public:
58 	// Constructor
CTextbox()59 	CTextbox() {
60 		iType = wid_Textbox;
61 		iFlags = 0;
62 		bDrawCursor = true;
63 		iScrollPos = 0;
64 		iSelLength = 0;
65 		iSelStart = 0;
66 		sSelectedText = "";
67 		bHolding = false;
68 		bHoldingMouse = false;
69 		iLastCurpos = 0;
70 		fTimeHolding = TimeDiff();
71 		iLastMouseX = 0;
72 		fLastRepeat = AbsTime();
73 		fLastClick = AbsTime();
74 		fScrollTime = TimeDiff();  // We can scroll
75 		bVar = NULL;
76 		iVar = NULL;
77 		fVar = NULL;
78 		sVar = NULL;
79 	}
80 
~CTextbox()81 	~CTextbox()  {
82 		Destroy();
83 	}
84 
85 
86 private:
87 	// Attributes
88 
89 	std::string	sText;
90 	std::string sAltKey;  // if user is pressing Alt + Numbers, we remember the numbers and insert unicode character
91 
92 	// these are related to the size of the string (sText.size()), NOT the displayed size
93 	size_t	iScrollPos;
94 	size_t	iCurpos;
95 	int		iSelLength; // if < 0, selection to the left, otherwise to the right
96 	size_t	iSelStart;
97 
98 	Uint32	iFlags;
99 	std::string	sSelectedText;
100 
101 	size_t	iMax;
102 
103 	bool	bHolding;
104 	AbsTime	fTimePushed;
105 	UnicodeChar		iLastchar;
106 	int		iLastKeysym;
107 
108 	bool	bHoldingMouse;
109 	TimeDiff	fTimeHolding;
110 	size_t	iLastCurpos;
111 	int		iLastMouseX;
112 	TimeDiff	fScrollTime;
113 	AbsTime	fLastRepeat;
114 	AbsTime	fLastClick;
115 
116 	bool	bDrawCursor;
117 
118 	bool		*bVar;
119 	int			*iVar;
120 	float		*fVar;
121 	std::string	*sVar;
122 
123 
124 public:
125 	// Methods
126 
127 	void	Create();
128 	void	Destroy();
129 
130 	//These events return an event id, otherwise they return -1
131 	int		MouseOver(mouse_t *tMouse);
132 	int		MouseUp(mouse_t *tMouse, int nDown);
133 	int		MouseDown(mouse_t *tMouse, int nDown);
MouseWheelDown(mouse_t * tMouse)134 	int		MouseWheelDown(mouse_t *tMouse)		{ return TXT_NONE; }
MouseWheelUp(mouse_t * tMouse)135 	int		MouseWheelUp(mouse_t *tMouse)		{ return TXT_NONE; }
136 	int		KeyDown(UnicodeChar c, int keysym, const ModifiersState& modstate);
137 	int		KeyUp(UnicodeChar c, int keysym, const ModifiersState& modstate);
138 
139 	void	Draw(SDL_Surface * bmpDest);
140 
141 	DWORD	SendMessage(int iMsg, DWORD Param1, DWORD Param2);
142 	DWORD	SendMessage(int iMsg, const std::string& sStr, DWORD Param);
143 	DWORD	SendMessage(int iMsg, std::string *sStr, DWORD Param);
144 
145 	void	Backspace();
146 	void	Delete();
147 	void	SelectWord();
148 	void	Insert(UnicodeChar c);
149 
getText()150 	std::string	getText()						{ return sText; }
151 	void	setText(const std::string& buf);
setFlag(Uint32 flag)152 	void	setFlag(Uint32 flag) { iFlags |= flag; }
unsetFlag(Uint32 flag)153 	void	unsetFlag(Uint32 flag) { iFlags &= ~flag; }
setCurPos(size_t pos)154 	void	setCurPos(size_t pos)  { iCurpos = (pos > sText.size() ? sText.size() : pos); }
155 
156     void    PasteText();
157 	void	CopyText();
158 
159 	void OnTimerEvent(Timer::EventData ev);
160 };
161 
162 }; // namespace DeprecatedGUI
163 
164 #endif  //  __CTEXTBOX_H__DEPRECATED_GUI__
165