Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: 13/4/2004 00003 author: Paul D Turner 00004 00005 purpose: Interface to base class for Editbox widget 00006 *************************************************************************/ 00007 /*************************************************************************** 00008 * Copyright (C) 2004 - 2009 Paul D Turner & The CEGUI Development Team 00009 * 00010 * Permission is hereby granted, free of charge, to any person obtaining 00011 * a copy of this software and associated documentation files (the 00012 * "Software"), to deal in the Software without restriction, including 00013 * without limitation the rights to use, copy, modify, merge, publish, 00014 * distribute, sublicense, and/or sell copies of the Software, and to 00015 * permit persons to whom the Software is furnished to do so, subject to 00016 * the following conditions: 00017 * 00018 * The above copyright notice and this permission notice shall be 00019 * included in all copies or substantial portions of the Software. 00020 * 00021 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00022 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00023 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00024 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 00025 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00026 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00027 * OTHER DEALINGS IN THE SOFTWARE. 00028 ***************************************************************************/ 00029 #ifndef _CEGUIEditbox_h_ 00030 #define _CEGUIEditbox_h_ 00031 00032 #include "CEGUI/Base.h" 00033 #include "CEGUI/Window.h" 00034 #include "CEGUI/RegexMatcher.h" 00035 00036 #if defined(_MSC_VER) 00037 # pragma warning(push) 00038 # pragma warning(disable : 4251) 00039 #endif 00040 00041 // Start of CEGUI namespace section 00042 namespace CEGUI 00043 { 00045 class CEGUIEXPORT EditboxWindowRenderer : public WindowRenderer 00046 { 00047 public: 00049 EditboxWindowRenderer(const String& name); 00050 00063 virtual size_t getTextIndexFromPosition(const Vector2f& pt) const = 0; 00064 }; 00065 00066 //----------------------------------------------------------------------------// 00067 00069 class CEGUIEXPORT Editbox : public Window 00070 { 00071 public: 00072 typedef RegexMatcher::MatchState MatchState; 00073 00075 static const String EventNamespace; 00077 static const String WidgetTypeName; 00083 static const String EventReadOnlyModeChanged; 00089 static const String EventMaskedRenderingModeChanged; 00096 static const String EventMaskCodePointChanged; 00102 static const String EventValidationStringChanged; 00108 static const String EventMaximumTextLengthChanged; 00122 static const String EventTextValidityChanged; 00128 static const String EventCaretMoved; 00134 static const String EventTextSelectionChanged; 00140 static const String EventEditboxFull; 00147 static const String EventTextAccepted; 00148 00157 bool hasInputFocus(void) const; 00158 00167 bool isReadOnly(void) const 00168 {return d_readOnly;} 00169 00179 bool isTextMasked(void) const 00180 {return d_maskText;} 00181 00201 MatchState getTextMatchState() const; 00202 00221 const String& getValidationString(void) const 00222 {return d_validationString;} 00223 00231 size_t getCaretIndex(void) const; 00232 00242 size_t getSelectionStartIndex(void) const; 00243 00252 size_t getSelectionEndIndex(void) const; 00253 00263 size_t getSelectionLength(void) const; 00264 00274 String::value_type getMaskCodePoint(void) const 00275 { return d_maskCodePoint; } 00276 00290 size_t getMaxTextLength(void) const 00291 {return d_maxTextLen;} 00292 00304 void setReadOnly(bool setting); 00305 00318 void setTextMasked(bool setting); 00319 00341 void setValidationString(const String& validation_string); 00342 00355 void setCaretIndex(size_t caret_pos); 00356 00374 void setSelection(size_t start_pos, size_t end_pos); 00375 00387 void setSelectionStart(size_t start_pos); 00388 00399 void setSelectionLength(size_t length); 00400 00413 void setMaskCodePoint(String::value_type code_point); 00414 00431 void setMaxTextLength(size_t max_len); 00432 00450 void setValidator(RegexMatcher* matcher); 00451 00453 virtual bool performCopy(Clipboard& clipboard); 00454 00456 virtual bool performCut(Clipboard& clipboard); 00457 00459 virtual bool performPaste(Clipboard& clipboard); 00460 00462 Editbox(const String& type, const String& name); 00463 00465 virtual ~Editbox(void); 00466 00467 protected: 00480 size_t getTextIndexFromPosition(const Vector2f& pt) const; 00481 00483 void clearSelection(void); 00484 00493 void eraseSelectedText(bool modify_text = true); 00494 00500 MatchState getStringMatchState(const String& str) const; 00501 00510 bool handleValidityChangeForString(const String& str); 00511 00513 void handleBackspace(void); 00514 00516 void handleDelete(void); 00517 00519 void handleCharLeft(uint sysKeys); 00520 00522 void handleWordLeft(uint sysKeys); 00523 00525 void handleCharRight(uint sysKeys); 00526 00528 void handleWordRight(uint sysKeys); 00529 00531 void handleHome(uint sysKeys); 00532 00534 void handleEnd(uint sysKeys); 00535 00537 virtual bool validateWindowRenderer(const WindowRenderer* renderer) const; 00538 00543 virtual void onReadOnlyChanged(WindowEventArgs& e); 00544 00550 virtual void onMaskedRenderingModeChanged(WindowEventArgs& e); 00551 00557 virtual void onMaskCodePointChanged(WindowEventArgs& e); 00558 00563 virtual void onValidationStringChanged(WindowEventArgs& e); 00564 00569 virtual void onMaximumTextLengthChanged(WindowEventArgs& e); 00570 00576 virtual void onTextValidityChanged(RegexMatchStateEventArgs& e); 00577 00582 virtual void onCaretMoved(WindowEventArgs& e); 00583 00588 virtual void onTextSelectionChanged(WindowEventArgs& e); 00589 00595 virtual void onEditboxFullEvent(WindowEventArgs& e); 00596 00602 virtual void onTextAcceptedEvent(WindowEventArgs& e); 00603 00604 // Overridden event handlers 00605 void onMouseButtonDown(MouseEventArgs& e); 00606 void onMouseButtonUp(MouseEventArgs& e); 00607 void onMouseDoubleClicked(MouseEventArgs& e); 00608 void onMouseTripleClicked(MouseEventArgs& e); 00609 void onMouseMove(MouseEventArgs& e); 00610 void onCaptureLost(WindowEventArgs& e); 00611 void onCharacter(KeyEventArgs& e); 00612 void onKeyDown(KeyEventArgs& e); 00613 void onTextChanged(WindowEventArgs& e); 00614 00616 bool d_readOnly; 00618 bool d_maskText; 00620 String::value_type d_maskCodePoint; 00622 size_t d_maxTextLen; 00624 size_t d_caretPos; 00626 size_t d_selectionStart; 00628 size_t d_selectionEnd; 00630 String d_validationString; 00632 RegexMatcher* d_validator; 00634 bool d_weOwnValidator; 00636 bool d_dragging; 00638 size_t d_dragAnchorIdx; 00640 MatchState d_validatorMatchState; 00642 bool d_previousValidityChangeResponse; 00643 00644 private: 00645 00646 void addEditboxProperties(void); 00647 }; 00648 00649 } // End of CEGUI namespace section 00650 00651 #if defined(_MSC_VER) 00652 # pragma warning(pop) 00653 #endif 00654 00655 #endif // end of guard _CEGUIEditbox_h_