PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
PTextBox Class Reference

This class is the basic generic text box. More...

#include <PTextBox.h>

Inheritance diagram for PTextBox:
PTextObject PWidget PEBLObjectBase PlatformTextBox PlatformTextBox

Public Member Functions

 PTextBox ()
 
 PTextBox (std::string text, int width, int height)
 
 PTextBox (PTextBox &textbox)
 
virtual ~PTextBox ()
 
virtual bool SetProperty (std::string, Variant v)
 
virtual Variant GetProperty (std::string) const
 
virtual ObjectValidationError ValidateProperty (std::string, Variant v) const
 
virtual ObjectValidationError ValidateProperty (std::string) const
 
virtual void SetHeight (int h)
 
virtual void SetWidth (int w)
 
virtual void InsertText (const std::string character)
 
virtual void DeleteText (int length)
 
virtual void SetEditable (bool val)
 
virtual bool GetEditable ()
 
virtual void SetCursorPosition (unsigned long int pos)
 
virtual unsigned long int GetCursorPosition ()
 
virtual long unsigned int IncrementCursor ()
 
virtual long unsigned int DecrementCursor ()
 
virtual void SetLineWrap (bool state)
 
virtual void SetJustify (Variant j)
 
virtual void HandleKeyPress (int keycode, int modkeys, Uint16 unicode)
 
virtual void HandleTextInput (std::string text)
 
virtual bool AtPrintableCharacter (unsigned long int x)
 
virtual std::string ObjectName () const
 
- Public Member Functions inherited from PTextObject
 PTextObject ()
 
 PTextObject (const std::string &text)
 
 PTextObject (PTextObject &object)
 
virtual ~PTextObject ()
 
virtual void SetText (const std::string &text)
 
virtual void SetDirection (int i)
 
virtual std::string GetText () const
 
virtual unsigned long int GetNumCharacters ()
 
- Public Member Functions inherited from PWidget
 PWidget ()
 
 PWidget (const PWidget &pw)
 
 PWidget (pInt x, pInt y, pInt width, pInt height, bool visible)
 
virtual ~PWidget ()
 
virtual bool RotoZoom (pDouble angle, pDouble zoomx, pDouble zoomy, pInt smooth)
 
virtual bool SetPoint (pInt x, pInt y, PColor col)
 
virtual PColor GetPixel (pInt x, pInt y)
 
virtual void SetParent (PWidget *widget)
 This unconditionally sets the parent widget.
 
virtual PWidgetGetParent ()
 
virtual bool IsParent (PWidget *parent)
 
virtual bool Draw ()
 
virtual void SetPosition (pInt x, pInt y)
 This sets the widget's position on its parent widget.
 
virtual void SetZoomX (pDouble x)
 This sets the widget's position on its parent widget.
 
virtual void SetZoomY (pDouble x)
 This sets the widget's position on its parent widget.
 
virtual void SetRotation (pDouble x)
 This sets the widget's position on its parent widget.
 
virtual void SetWidth (pInt w)
 
virtual void SetHeight (pInt h)
 
virtual pInt GetX () const
 
virtual pInt GetY () const
 
virtual pInt GetWidth () const
 
virtual pInt GetHeight () const
 
virtual void SetBackgroundColor (const PColor &color)
 
virtual PColor GetBackgroundColor ()
 
virtual bool AddSubWidget (PWidget *widget)
 
virtual bool RemoveSubWidget (PWidget *widget)
 
virtual bool RemoveSubWidgets ()
 
virtual bool RemoveLastSubWidget ()
 This is probably pretty useless.
 
virtual void Show ()
 
virtual void Hide ()
 
virtual bool IsVisible () const
 
- Public Member Functions inherited from PEBLObjectBase
 PEBLObjectBase ()
 Standard Constructor.
 
 PEBLObjectBase (ComplexDataType cdt)
 Standard Constructor.
 
 PEBLObjectBase (const PEBLObjectBase &pob)
 
virtual ~PEBLObjectBase ()
 Standard Destructor.
 
virtual bool InitializeProperty (std::string name, Variant v)
 
Variant GetProperty (std::string) const
 
ComplexDataType GetType ()
 
virtual std::ostream & PrintProperties (std::ostream &out)
 
virtual Variant GetPropertyList ()
 

Protected Member Functions

virtual std::ostream & SendToStream (std::ostream &out) const
 An inheritable printing class used by PEBLObjectBase::operator<<.
 

Protected Attributes

bool mEditable
 
unsigned long int mCursorPos
 
bool mCursorChanged
 
bool mLineWrap
 
Variant mJustify
 
- Protected Attributes inherited from PTextObject
bool mChanged
 
std::string mText
 
int mDirection
 
- Protected Attributes inherited from PWidget
pInt mX
 
pInt mY
 
pInt mDrawX
 
pInt mDrawY
 
pInt mWidth
 
pInt mHeight
 
pDouble mZoomX
 
pDouble mZoomY
 
pDouble mRotation
 
PColor mBackgroundColor
 The background color of the widget. if alpha = 0, will not be painted.
 
std::list< PWidget * > mSubWidgets
 
bool mIsVisible
 
PWidgetmParent
 
- Protected Attributes inherited from PEBLObjectBase
ComplexDataType mCDT
 
std::map< std::string, VariantmProperties
 

Detailed Description

This class is the basic generic text box.

Definition at line 39 of file PTextBox.h.

Constructor & Destructor Documentation

◆ PTextBox() [1/3]

PTextBox::PTextBox ( )

Definition at line 43 of file PTextBox.cpp.

43 :
44 PTextObject(""),
45 mEditable(false),
46 mCursorPos(0),
47 mCursorChanged(true),
48 mLineWrap(true),
49 mJustify(1)
50{
51 InitializeProperty("TEXT",Variant(""));
52 InitializeProperty("WIDTH",Variant(0));
53 InitializeProperty("HEIGHT",Variant(0));
54 InitializeProperty("EDITABLE",Variant(false));
55 InitializeProperty("CURSORPOS",Variant(0));
56 InitializeProperty("NAME",Variant("<TEXTBOX>"));
57 InitializeProperty("LINEWRAP",Variant(1));
58 InitializeProperty("LINEHEIGHT",Variant(0));
59 InitializeProperty("NUMTEXTLINES",Variant(0));
60 InitializeProperty("TEXTCOMPLETE",Variant(0));
61 InitializeProperty("JUSTIFY",Variant("LEFT"));
62 InitializeProperty("ISADAPTIVE",Variant(false));
63 InitializeProperty("ADAPTIVEMODE",Variant("scalefont"));
64 InitializeProperty("REQUESTEDFONTSIZE",Variant(0));
65 InitializeProperty("FORMATTED",Variant(0));
66}
virtual bool InitializeProperty(std::string name, Variant v)
Variant mJustify
Definition PTextBox.h:94
unsigned long int mCursorPos
Definition PTextBox.h:91
bool mLineWrap
Definition PTextBox.h:93
bool mCursorChanged
Definition PTextBox.h:92
bool mEditable
Definition PTextBox.h:90

References PEBLObjectBase::InitializeProperty().

◆ PTextBox() [2/3]

PTextBox::PTextBox ( std::string  text,
int  width,
int  height 
)

Definition at line 70 of file PTextBox.cpp.

70 :
71 PTextObject(text),
72 mEditable(false),
73 mCursorPos(0),
74 mCursorChanged(true),
75 mLineWrap(true),
76 mJustify(1)
77{
78 InitializeProperty("TEXT",Variant(text));
79 InitializeProperty("WIDTH",Variant(width));
80 InitializeProperty("HEIGHT",Variant(height));
81 InitializeProperty("EDITABLE",Variant(false));
82 InitializeProperty("CURSORPOS",Variant(0));
83 InitializeProperty("NAME",Variant("<TEXTBOX>"));
84 InitializeProperty("LINEWRAP",Variant(1));
85 InitializeProperty("LINEHEIGHT",Variant(0));
86 InitializeProperty("NUMTEXTLINES",Variant(0));
87 InitializeProperty("TEXTCOMPLETE",Variant(0));
88 InitializeProperty("JUSTIFY",Variant("LEFT"));
89 InitializeProperty("ISADAPTIVE",Variant(false));
90 InitializeProperty("ADAPTIVEMODE",Variant("scalefont"));
91 InitializeProperty("REQUESTEDFONTSIZE",Variant(0));
92 InitializeProperty("FORMATTED",Variant(0));
93}

References PEBLObjectBase::InitializeProperty().

◆ PTextBox() [3/3]

PTextBox::PTextBox ( PTextBox textbox)

Definition at line 96 of file PTextBox.cpp.

96 :
97 PTextObject(text.GetText()),
98 mEditable(false),
99 mCursorPos(0),
100 mCursorChanged(true),
101 mLineWrap(true),
102 mJustify(1)
103{
104 mChanged = true;
105 InitializeProperty("NAME",Variant("<TEXTBOX>"));
106 InitializeProperty("LINEWRAP",Variant(1));
107 InitializeProperty("LINEHEIGHT",Variant(0));
108 InitializeProperty("NUMTEXTLINES",Variant(0));
109 InitializeProperty("TEXTCOMPLETE",Variant(0));
110 InitializeProperty("JUSTIFY",Variant("LEFT"));
111 InitializeProperty("ISADAPTIVE",Variant(false));
112 InitializeProperty("ADAPTIVEMODE",Variant("scalefont"));
113 InitializeProperty("REQUESTEDFONTSIZE",Variant(0));
114 InitializeProperty("FORMATTED",Variant(0));
115}

References PEBLObjectBase::InitializeProperty(), and PTextObject::mChanged.

◆ ~PTextBox()

PTextBox::~PTextBox ( )
virtual

Definition at line 117 of file PTextBox.cpp.

118{
119}

Member Function Documentation

◆ AtPrintableCharacter()

bool PTextBox::AtPrintableCharacter ( unsigned long int  x)
virtual

Definition at line 424 of file PTextBox.cpp.

425{
426 unsigned long int pos=x;
427
428 if(x> mText.length())
429 pos = mText.length();
430
431 if (mText[pos] == 10
432 || mText[pos] == 13
433 || mText[pos] == 18
434 )
435 return false;
436 else
437 return true;
438}
std::string mText
Definition PTextObject.h:70

References PTextObject::mText.

Referenced by PlatformTextBox::FindCursorPosition().

◆ DecrementCursor()

long unsigned int PTextBox::DecrementCursor ( )
virtual

Definition at line 334 of file PTextBox.cpp.

335{
336
337
338 if(mCursorPos>=1)
339 {
340
341
342 bool cont = true;
343 std::string::iterator start = mText.begin()+mCursorPos;
344 std::string::iterator end = start;
345 mCursorPos--;
346 start--;
347 while(!utf8::is_valid(start,end))
348 {
349 mCursorPos -= 1;
350 start--;
351 }
352
353 }
354
355
356// if(AtPrintableCharacter(mCursorPos -1))
357// mCursorPos --;
358// else
359// mCursorPos -= 1;
360
361 mCursorChanged = true;
362 return mCursorPos;
363}

References mCursorChanged, mCursorPos, and PTextObject::mText.

Referenced by PlatformTextBox::HandleKeyPress().

◆ DeleteText()

void PTextBox::DeleteText ( int  length)
virtual

Definition at line 210 of file PTextBox.cpp.

211{
212
213 int count = 0;
214 int bytecount = 1;
215
216 if(length > 0)
217 {
218
219 std::string::iterator start = mText.begin();
220 std::string::iterator end = start+mCursorPos+1;
221
222 while(count < length)
223 {
224
225 while(!utf8::is_valid(start,end) && end < mText.end())
226 {
227
228 end++;
229 bytecount++;
230 }
231 count++;
232 bytecount++;
233 }
234
235 //We need to watch deleting at the end. If we try to bite off too much at
236 //the end, just don't do it.
237 if(bytecount+mCursorPos<mText.length())
238 {
239 mText.erase(mCursorPos, bytecount-1);
240 mChanged= true;
241 }
242 }
243 else if (length < 0)
244 {
245
246 //Delete before the cursor.
247 std::string::iterator start = mText.begin();
248 std::string::iterator end = start+mCursorPos-1;
249
250
251 //Delete before the cursor.
252 while(count < (-length))
253 {
254
255 //crash happens here when deleting from the beginning
256
257
258
259 while(!utf8::is_valid(start,end) && start < end)
260 {
261
262 bytecount++;
263 end--; //delete backward to the end of the remaining
264
265 }
266 count++;
267 bytecount++;
268 }
269
270
271 bytecount--; //back off one byte because it got double-incremented
272
273
274 if((int)mCursorPos - bytecount < 0)
275 {
276
277 mText.erase(0,mCursorPos);
278 mChanged= true;
279 mCursorPos = 0;
280
281 }
282 else
283 {
284
285 mText.erase(mCursorPos-bytecount, bytecount);
286 mChanged= true;
287 mCursorPos -= bytecount;
288
289 }
290 }
291
292 SetProperty("TEXT",mText);
293}
virtual bool SetProperty(std::string, Variant v)
Definition PTextBox.cpp:124
int count
Definition test.cpp:12

References count, PTextObject::mChanged, mCursorPos, PTextObject::mText, and SetProperty().

Referenced by PlatformTextBox::HandleKeyPress().

◆ GetCursorPosition()

virtual unsigned long int PTextBox::GetCursorPosition ( )
inlinevirtual

Definition at line 65 of file PTextBox.h.

65{return mCursorPos;};

References mCursorPos.

◆ GetEditable()

virtual bool PTextBox::GetEditable ( )
inlinevirtual

Definition at line 62 of file PTextBox.h.

62{return mEditable;};

References mEditable.

◆ GetProperty()

Variant PTextBox::GetProperty ( std::string  name) const
virtual

Reimplemented from PTextObject.

Reimplemented in PlatformTextBox.

Definition at line 154 of file PTextBox.cpp.

155{
156 return PTextObject::GetProperty(name);
157}
virtual Variant GetProperty(std::string) const

References PTextObject::GetProperty().

Referenced by PlatformTextBox::GetProperty().

◆ HandleKeyPress()

void PTextBox::HandleKeyPress ( int  keycode,
int  modkeys,
Uint16  unicode 
)
virtual

Reimplemented in PlatformTextBox.

Definition at line 394 of file PTextBox.cpp.

395{
396
397 //First, handle special keys
398 switch(keycode)
399 {
400#if 0
401 if(0)
402 {
404 }
405#endif
406 break;
407 }
408 mCursorChanged=true;
409}
PEBL_Keycode
Definition PKeyboard.h:78
virtual void InsertText(const std::string character)
Definition PTextBox.cpp:189
std::string TranslateKeycode(const PEBL_Keycode key, int modkeys)

References InsertText(), mCursorChanged, and PEBLUtility::TranslateKeycode().

◆ HandleTextInput()

void PTextBox::HandleTextInput ( std::string  text)
virtual

Reimplemented in PlatformTextBox.

Definition at line 414 of file PTextBox.cpp.

415{
416
417
418 InsertText(text);
419 //we may need to adjust cursor position.
420 mCursorChanged=true;
421}

References InsertText(), and mCursorChanged.

Referenced by PlatformTextBox::HandleTextInput().

◆ IncrementCursor()

long unsigned int PTextBox::IncrementCursor ( )
virtual

AtPrintableCharacter(mCursorPos))

Definition at line 295 of file PTextBox.cpp.

296{
297
298
299 //this just checks for end-of-line stuff.
300 if(0)
301 {
302 mCursorPos ++;
303 }
304 else
305 {
306
307
308 if(mCursorPos > (int)(mText.length()))
309 mCursorPos = mText.length();
310
311
312
313 bool cont = true;
314 std::string::iterator start = mText.begin()+mCursorPos;
315 std::string::iterator end = start+1;
316 mCursorPos++;
317
318 while(!utf8::is_valid(start,end))
319 {
320
321 mCursorPos += 1;
322 end++;
323 }
324
325 }
326
327
328 mCursorChanged = true;
329
330
331 return mCursorPos;
332}

References mCursorChanged, mCursorPos, and PTextObject::mText.

Referenced by PlatformTextBox::HandleKeyPress().

◆ InsertText()

void PTextBox::InsertText ( const std::string  character)
virtual

Definition at line 189 of file PTextBox.cpp.

190{
191
192
193 if(mCursorPos>mText.length())
194 mCursorPos=mText.length();
195
196 mText.insert(mCursorPos, text);
197 mCursorPos += text.length();
198
199 mChanged= true;
200 mCursorChanged = true;
201 SetProperty("TEXT",mText);
202
203}

References PTextObject::mChanged, mCursorChanged, mCursorPos, PTextObject::mText, and SetProperty().

Referenced by HandleKeyPress(), PlatformTextBox::HandleKeyPress(), and HandleTextInput().

◆ ObjectName()

std::string PTextBox::ObjectName ( ) const
virtual

Reimplemented from PTextObject.

Reimplemented in PlatformTextBox, and PlatformTextBox.

Definition at line 441 of file PTextBox.cpp.

442{
443 return "TextBox";
444}

◆ SendToStream()

virtual std::ostream & PTextBox::SendToStream ( std::ostream &  out) const
inlineprotectedvirtual

An inheritable printing class used by PEBLObjectBase::operator<<.

Reimplemented from PTextObject.

Reimplemented in PlatformTextBox, and PlatformTextBox.

Definition at line 87 of file PTextBox.h.

87{return out;};

◆ SetCursorPosition()

virtual void PTextBox::SetCursorPosition ( unsigned long int  pos)
inlinevirtual

Definition at line 64 of file PTextBox.h.

64{mCursorChanged = true; mCursorPos = pos;};

References mCursorChanged, and mCursorPos.

Referenced by SetProperty().

◆ SetEditable()

virtual void PTextBox::SetEditable ( bool  val)
inlinevirtual

Reimplemented in PlatformTextBox.

Definition at line 61 of file PTextBox.h.

61{mEditable = val; mCursorChanged=true;};

References mCursorChanged, and mEditable.

Referenced by PlatformTextBox::SetEditable(), and SetProperty().

◆ SetHeight()

void PTextBox::SetHeight ( int  h)
virtual

Reimplemented in PlatformTextBox.

Definition at line 367 of file PTextBox.cpp.

368{
369 mHeight = h;
370 mChanged = true;
371}
pInt mHeight
Definition PWidget.h:136

References PTextObject::mChanged, and PWidget::mHeight.

Referenced by PlatformTextBox::SetHeight(), and SetProperty().

◆ SetJustify()

void PTextBox::SetJustify ( Variant  j)
virtual

Definition at line 386 of file PTextBox.cpp.

387{
388
389 mJustify =j;
390 mChanged = true;
391}

References PTextObject::mChanged, and mJustify.

Referenced by SetProperty().

◆ SetLineWrap()

void PTextBox::SetLineWrap ( bool  state)
virtual

Definition at line 380 of file PTextBox.cpp.

381{
382 mLineWrap = state;
383}

References mLineWrap.

Referenced by SetProperty().

◆ SetProperty()

bool PTextBox::SetProperty ( std::string  name,
Variant  v 
)
virtual

Reimplemented from PTextObject.

Reimplemented in PlatformTextBox, and PlatformTextBox.

Definition at line 124 of file PTextBox.cpp.

125{
126
127 if(PTextObject::SetProperty(name,v))
128 {
129 // If we set it at higher level, don't worry.
130 }
131 else if(name =="WIDTH") SetWidth(v);
132 else if(name == "HEIGHT") SetHeight(v);
133 else if(name == "TEXT"){
134 SetText(v.GetString());
135 mCursorChanged=true;
136 mChanged=true;}
137 else if(name == "EDITABLE")SetEditable(v);
138 else if(name == "CURSORPOS") SetCursorPosition(v);
139 else if(name == "LINEWRAP") SetLineWrap(v);
140 else if(name == "JUSTIFY") SetJustify(v);
141 else if(name == "ISADAPTIVE" || name == "ADAPTIVEMODE" || name == "REQUESTEDFONTSIZE" || name == "FORMATTED") {
142 // These properties are stored only in the property system
143 // Adaptive scaling is handled in PEBL code (UI.pbl)
144 // Formatted text rendering is handled in PlatformTextBox
145 // Store the property value and mark as changed
147 mChanged = true;
148 }
149 else return false;
150 return true;
151}
virtual bool SetProperty(std::string name, Variant v)
virtual void SetJustify(Variant j)
Definition PTextBox.cpp:386
virtual void SetWidth(int w)
Definition PTextBox.cpp:373
virtual void SetCursorPosition(unsigned long int pos)
Definition PTextBox.h:64
virtual void SetLineWrap(bool state)
Definition PTextBox.cpp:380
virtual void SetEditable(bool val)
Definition PTextBox.h:61
virtual void SetHeight(int h)
Definition PTextBox.cpp:367
virtual bool SetProperty(std::string, Variant v)
virtual void SetText(const std::string &text)
std::string GetString() const
Definition Variant.cpp:1056

References Variant::GetString(), PTextObject::mChanged, mCursorChanged, SetCursorPosition(), SetEditable(), SetHeight(), SetJustify(), SetLineWrap(), PEBLObjectBase::SetProperty(), PTextObject::SetProperty(), PTextObject::SetText(), and SetWidth().

Referenced by DeleteText(), InsertText(), PlatformTextBox::SetProperty(), and PlatformTextBox::SetProperty().

◆ SetWidth()

void PTextBox::SetWidth ( int  w)
virtual

Reimplemented in PlatformTextBox.

Definition at line 373 of file PTextBox.cpp.

374{
375 mWidth = w;
376 mChanged = true;
377}
pInt mWidth
Definition PWidget.h:136

References PTextObject::mChanged, and PWidget::mWidth.

Referenced by SetProperty(), and PlatformTextBox::SetWidth().

◆ ValidateProperty() [1/2]

ObjectValidationError PTextBox::ValidateProperty ( std::string  name) const
virtual

Reimplemented from PTextObject.

Reimplemented in PlatformTextBox.

Definition at line 176 of file PTextBox.cpp.

177{
178 if(name == "CURSORPOS"| name=="LINEWRAP"| name == "JUSTIFY" | name == "NUMTEXTLINES" | name == "TEXTCOMPLETE" | name == "ISADAPTIVE" | name == "ADAPTIVEMODE" | name == "REQUESTEDFONTSIZE" | name == "FORMATTED")
179 return OVE_VALID;
180 else
182}
@ OVE_VALID
Definition PEBLObject.h:39
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const

References OVE_VALID, and PTextObject::ValidateProperty().

◆ ValidateProperty() [2/2]

ObjectValidationError PTextBox::ValidateProperty ( std::string  name,
Variant  v 
) const
virtual

Reimplemented from PTextObject.

Reimplemented in PlatformTextBox.

Definition at line 160 of file PTextBox.cpp.

161{
162
163 if(name == "JUSTIFY")
164 {
165 if(v=="LEFT" | v == "RIGHT" | v == "CENTER")
166 {
167 return OVE_VALID;
168 }else
169 {
171 }
172 }
173 return ValidateProperty(name);
174}
@ OVE_INVALID_PROPERTY_VALUE
Definition PEBLObject.h:42
virtual ObjectValidationError ValidateProperty(std::string, Variant v) const
Definition PTextBox.cpp:160

References OVE_INVALID_PROPERTY_VALUE, OVE_VALID, and ValidateProperty().

Referenced by PlatformTextBox::ValidateProperty(), PlatformTextBox::ValidateProperty(), and ValidateProperty().

Member Data Documentation

◆ mCursorChanged

◆ mCursorPos

unsigned long int PTextBox::mCursorPos
protected

◆ mEditable

bool PTextBox::mEditable
protected

◆ mJustify

Variant PTextBox::mJustify
protected

◆ mLineWrap

bool PTextBox::mLineWrap
protected

Definition at line 93 of file PTextBox.h.

Referenced by SetLineWrap().


The documentation for this class was generated from the following files: