Crazy Eddies GUI System 0.7.6
|
00001 /*********************************************************************** 00002 filename: CEGUIEditbox.h 00003 created: 13/4/2004 00004 author: Paul D Turner 00005 00006 purpose: Interface to base class for Editbox widget 00007 *************************************************************************/ 00008 /*************************************************************************** 00009 * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team 00010 * 00011 * Permission is hereby granted, free of charge, to any person obtaining 00012 * a copy of this software and associated documentation files (the 00013 * "Software"), to deal in the Software without restriction, including 00014 * without limitation the rights to use, copy, modify, merge, publish, 00015 * distribute, sublicense, and/or sell copies of the Software, and to 00016 * permit persons to whom the Software is furnished to do so, subject to 00017 * the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be 00020 * included in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00023 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00024 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00025 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00026 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00027 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00028 * OTHER DEALINGS IN THE SOFTWARE. 00029 ***************************************************************************/ 00030 #ifndef _CEGUIEditbox_h_ 00031 #define _CEGUIEditbox_h_ 00032 00033 #include "../CEGUIBase.h" 00034 #include "../CEGUIWindow.h" 00035 #include "CEGUIEditboxProperties.h" 00036 00037 #if defined(_MSC_VER) 00038 # pragma warning(push) 00039 # pragma warning(disable : 4251) 00040 #endif 00041 00042 // Start of CEGUI namespace section 00043 namespace CEGUI 00044 { 00046 class CEGUIEXPORT EditboxWindowRenderer : public WindowRenderer 00047 { 00048 public: 00050 EditboxWindowRenderer(const String& name); 00051 00064 virtual size_t getTextIndexFromPosition(const Point& pt) const = 0; 00065 }; 00066 00067 //----------------------------------------------------------------------------// 00068 00070 class CEGUIEXPORT Editbox : public Window 00071 { 00072 public: 00074 static const String EventNamespace; 00076 static const String WidgetTypeName; 00082 static const String EventReadOnlyModeChanged; 00088 static const String EventMaskedRenderingModeChanged; 00095 static const String EventMaskCodePointChanged; 00101 static const String EventValidationStringChanged; 00107 static const String EventMaximumTextLengthChanged; 00113 static const String EventTextInvalidated; 00120 static const String EventInvalidEntryAttempted; 00126 static const String EventCaratMoved; 00132 static const String EventTextSelectionChanged; 00138 static const String EventEditboxFull; 00145 static const String EventTextAccepted; 00146 00155 bool hasInputFocus(void) const; 00156 00165 bool isReadOnly(void) const 00166 {return d_readOnly;} 00167 00177 bool isTextMasked(void) const 00178 {return d_maskText;} 00179 00200 bool isTextValid(void) const; 00201 00214 const String& getValidationString(void) const 00215 {return d_validationString;} 00216 00224 size_t getCaratIndex(void) const; 00225 00235 size_t getSelectionStartIndex(void) const; 00236 00245 size_t getSelectionEndIndex(void) const; 00246 00256 size_t getSelectionLength(void) const; 00257 00266 utf32 getMaskCodePoint(void) const 00267 {return d_maskCodePoint;} 00268 00282 size_t getMaxTextLength(void) const 00283 {return d_maxTextLen;} 00284 00296 void setReadOnly(bool setting); 00297 00310 void setTextMasked(bool setting); 00311 00327 void setValidationString(const String& validation_string); 00328 00341 void setCaratIndex(size_t carat_pos); 00342 00360 void setSelection(size_t start_pos, size_t end_pos); 00361 00373 void setMaskCodePoint(utf32 code_point); 00374 00391 void setMaxTextLength(size_t max_len); 00392 00394 Editbox(const String& type, const String& name); 00395 00397 virtual ~Editbox(void); 00398 00399 protected: 00412 size_t getTextIndexFromPosition(const Point& pt) const; 00413 00415 void clearSelection(void); 00416 00425 void eraseSelectedText(bool modify_text = true); 00426 00432 bool isStringValid(const String& str) const; 00433 00435 void handleBackspace(void); 00436 00438 void handleDelete(void); 00439 00441 void handleCharLeft(uint sysKeys); 00442 00444 void handleWordLeft(uint sysKeys); 00445 00447 void handleCharRight(uint sysKeys); 00448 00450 void handleWordRight(uint sysKeys); 00451 00453 void handleHome(uint sysKeys); 00454 00456 void handleEnd(uint sysKeys); 00457 00470 virtual bool testClassName_impl(const String& class_name) const 00471 { 00472 if (class_name=="Editbox") return true; 00473 return Window::testClassName_impl(class_name); 00474 } 00475 00477 virtual bool validateWindowRenderer(const String& name) const 00478 { 00479 return (name == "Editbox"); 00480 } 00481 00486 virtual void onReadOnlyChanged(WindowEventArgs& e); 00487 00493 virtual void onMaskedRenderingModeChanged(WindowEventArgs& e); 00494 00500 virtual void onMaskCodePointChanged(WindowEventArgs& e); 00501 00506 virtual void onValidationStringChanged(WindowEventArgs& e); 00507 00512 virtual void onMaximumTextLengthChanged(WindowEventArgs& e); 00513 00522 virtual void onTextInvalidatedEvent(WindowEventArgs& e); 00523 00529 virtual void onInvalidEntryAttempted(WindowEventArgs& e); 00530 00535 virtual void onCaratMoved(WindowEventArgs& e); 00536 00541 virtual void onTextSelectionChanged(WindowEventArgs& e); 00542 00548 virtual void onEditboxFullEvent(WindowEventArgs& e); 00549 00555 virtual void onTextAcceptedEvent(WindowEventArgs& e); 00556 00557 // Overridden event handlers 00558 void onMouseButtonDown(MouseEventArgs& e); 00559 void onMouseButtonUp(MouseEventArgs& e); 00560 void onMouseDoubleClicked(MouseEventArgs& e); 00561 void onMouseTripleClicked(MouseEventArgs& e); 00562 void onMouseMove(MouseEventArgs& e); 00563 void onCaptureLost(WindowEventArgs& e); 00564 void onCharacter(KeyEventArgs& e); 00565 void onKeyDown(KeyEventArgs& e); 00566 void onTextChanged(WindowEventArgs& e); 00567 00569 bool d_readOnly; 00571 bool d_maskText; 00573 utf32 d_maskCodePoint; 00575 size_t d_maxTextLen; 00577 size_t d_caratPos; 00579 size_t d_selectionStart; 00581 size_t d_selectionEnd; 00583 String d_validationString; 00585 RegexMatcher* d_validator; 00587 bool d_dragging; 00589 size_t d_dragAnchorIdx; 00590 00591 private: 00592 static EditboxProperties::ReadOnly d_readOnlyProperty; 00593 static EditboxProperties::MaskText d_maskTextProperty; 00594 static EditboxProperties::MaskCodepoint d_maskCodepointProperty; 00595 static EditboxProperties::ValidationString d_validationStringProperty; 00596 static EditboxProperties::CaratIndex d_caratIndexProperty; 00597 static EditboxProperties::SelectionStart d_selectionStartProperty; 00598 static EditboxProperties::SelectionLength d_selectionLengthProperty; 00599 static EditboxProperties::MaxTextLength d_maxTextLengthProperty; 00600 00601 void addEditboxProperties(void); 00602 }; 00603 00604 } // End of CEGUI namespace section 00605 00606 #if defined(_MSC_VER) 00607 # pragma warning(pop) 00608 #endif 00609 00610 #endif // end of guard _CEGUIEditbox_h_