Crazy Eddie's GUI System
0.8.4
|
00001 /*********************************************************************** 00002 created: 30/6/2004 00003 author: Paul D Turner 00004 00005 purpose: Interface to the Multi-lien edit box base class. 00006 *************************************************************************/ 00007 /*************************************************************************** 00008 * Copyright (C) 2004 - 2006 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 _CEGUIMultiLineEditbox_h_ 00030 #define _CEGUIMultiLineEditbox_h_ 00031 00032 #include "../Base.h" 00033 #include "../Window.h" 00034 #include "../Font.h" 00035 00036 #include <vector> 00037 00038 #if defined(_MSC_VER) 00039 # pragma warning(push) 00040 # pragma warning(disable : 4251) 00041 #endif 00042 00043 00044 // Start of CEGUI namespace section 00045 namespace CEGUI 00046 { 00051 class CEGUIEXPORT MultiLineEditboxWindowRenderer : public WindowRenderer 00052 { 00053 public: 00058 MultiLineEditboxWindowRenderer(const String& name); 00059 00068 virtual Rectf getTextRenderArea(void) const = 0; 00069 00070 protected: 00071 // base class overrides 00072 void onLookNFeelAssigned(); 00073 }; 00074 00079 class CEGUIEXPORT MultiLineEditbox : public Window 00080 { 00081 public: 00082 static const String EventNamespace; 00083 static const String WidgetTypeName; 00084 00085 /************************************************************************* 00086 Constants 00087 *************************************************************************/ 00088 // event names 00094 static const String EventReadOnlyModeChanged; 00100 static const String EventWordWrapModeChanged; 00107 static const String EventMaximumTextLengthChanged; 00113 static const String EventCaretMoved; 00119 static const String EventTextSelectionChanged; 00126 static const String EventEditboxFull; 00133 static const String EventVertScrollbarModeChanged; 00140 static const String EventHorzScrollbarModeChanged; 00141 00142 /************************************************************************* 00143 Child Widget name constants 00144 *************************************************************************/ 00145 static const String VertScrollbarName; 00146 static const String HorzScrollbarName; 00147 00148 /************************************************************************* 00149 Implementation struct 00150 *************************************************************************/ 00156 struct LineInfo 00157 { 00158 size_t d_startIdx; 00159 size_t d_length; 00160 float d_extent; 00161 }; 00162 typedef std::vector<LineInfo 00163 CEGUI_VECTOR_ALLOC(LineInfo)> LineList; 00164 00165 /************************************************************************* 00166 Accessor Functions 00167 *************************************************************************/ 00176 bool hasInputFocus(void) const; 00177 00178 00187 bool isReadOnly(void) const {return d_readOnly;} 00188 00189 00197 size_t getCaretIndex(void) const {return d_caretPos;} 00198 00199 00208 size_t getSelectionStartIndex(void) const; 00209 00210 00219 size_t getSelectionEndIndex(void) const; 00220 00221 00229 size_t getSelectionLength(void) const; 00230 00231 00239 size_t getMaxTextLength(void) const {return d_maxTextLen;} 00240 00241 00250 bool isWordWrapped(void) const; 00251 00252 00264 Scrollbar* getVertScrollbar() const; 00265 00274 bool isVertScrollbarAlwaysShown(void) const; 00275 00287 Scrollbar* getHorzScrollbar() const; 00288 00289 00298 Rectf getTextRenderArea(void) const; 00299 00300 // get d_lines 00301 const LineList& getFormattedLines(void) const {return d_lines;} 00302 00308 size_t getLineNumberFromIndex(size_t index) const; 00309 00310 /************************************************************************* 00311 Manipulators 00312 *************************************************************************/ 00323 virtual void initialiseComponents(void); 00324 00325 00337 void setReadOnly(bool setting); 00338 00339 00351 void setCaretIndex(size_t caret_pos); 00352 00353 00369 void setSelection(size_t start_pos, size_t end_pos); 00370 00371 00383 void setSelectionStart(size_t start_pos); 00384 00395 void setSelectionLength(size_t length); 00396 00407 void setMaxTextLength(size_t max_len); 00408 00409 00414 void ensureCaretIsVisible(void); 00415 00416 00428 void setWordWrapping(bool setting); 00429 00441 void setShowVertScrollbar(bool setting); 00442 00443 // selection brush image property support 00444 void setSelectionBrushImage(const Image* image); 00445 const Image* getSelectionBrushImage() const; 00446 00448 virtual bool performCopy(Clipboard& clipboard); 00449 00451 virtual bool performCut(Clipboard& clipboard); 00452 00454 virtual bool performPaste(Clipboard& clipboard); 00455 00464 void formatText(const bool update_scrollbars); 00465 00466 /************************************************************************* 00467 Construction and Destruction 00468 *************************************************************************/ 00473 MultiLineEditbox(const String& type, const String& name); 00474 00475 00480 virtual ~MultiLineEditbox(void); 00481 00482 00483 protected: 00484 /************************************************************************* 00485 Implementation Methods (abstract) 00486 *************************************************************************/ 00495 //virtual Rect getTextRenderArea_impl(void) const = 0; 00496 00497 00498 /************************************************************************* 00499 Implementation Methods 00500 *************************************************************************/ 00507 void formatText(void); 00508 00519 size_t getNextTokenLength(const String& text, size_t start_idx) const; 00520 00521 00526 void configureScrollbars(void); 00527 00528 00539 size_t getTextIndexFromPosition(const Vector2f& pt) const; 00540 00541 00546 void clearSelection(void); 00547 00548 00556 void eraseSelectedText(bool modify_text = true); 00557 00558 00563 void handleBackspace(void); 00564 00565 00570 void handleDelete(void); 00571 00572 00577 void handleCharLeft(uint sysKeys); 00578 00579 00584 void handleWordLeft(uint sysKeys); 00585 00586 00591 void handleCharRight(uint sysKeys); 00592 00593 00598 void handleWordRight(uint sysKeys); 00599 00600 00605 void handleDocHome(uint sysKeys); 00606 00607 00612 void handleDocEnd(uint sysKeys); 00613 00614 00619 void handleLineHome(uint sysKeys); 00620 00621 00626 void handleLineEnd(uint sysKeys); 00627 00628 00633 void handleLineUp(uint sysKeys); 00634 00635 00640 void handleLineDown(uint sysKeys); 00641 00642 00647 void handleNewLine(uint sysKeys); 00648 00649 00654 void handlePageUp(uint sysKeys); 00655 00656 00661 void handlePageDown(uint sysKeys); 00662 00667 bool handle_scrollChange(const EventArgs& args); 00668 00669 // handler triggered when vertical scrollbar is shown or hidden 00670 bool handle_vertScrollbarVisibilityChanged(const EventArgs&); 00671 00672 // validate window renderer 00673 virtual bool validateWindowRenderer(const WindowRenderer* renderer) const; 00674 00675 /************************************************************************* 00676 New event handlers 00677 *************************************************************************/ 00682 void onReadOnlyChanged(WindowEventArgs& e); 00683 00684 00689 void onWordWrapModeChanged(WindowEventArgs& e); 00690 00691 00696 void onMaximumTextLengthChanged(WindowEventArgs& e); 00697 00698 00703 void onCaretMoved(WindowEventArgs& e); 00704 00705 00710 void onTextSelectionChanged(WindowEventArgs& e); 00711 00712 00717 void onEditboxFullEvent(WindowEventArgs& e); 00718 00719 00724 void onVertScrollbarModeChanged(WindowEventArgs& e); 00725 00726 00731 void onHorzScrollbarModeChanged(WindowEventArgs& e); 00732 00733 00734 /************************************************************************* 00735 Overridden event handlers 00736 *************************************************************************/ 00737 virtual void onMouseButtonDown(MouseEventArgs& e); 00738 virtual void onMouseButtonUp(MouseEventArgs& e); 00739 virtual void onMouseDoubleClicked(MouseEventArgs& e); 00740 virtual void onMouseTripleClicked(MouseEventArgs& e); 00741 virtual void onMouseMove(MouseEventArgs& e); 00742 virtual void onCaptureLost(WindowEventArgs& e); 00743 virtual void onCharacter(KeyEventArgs& e); 00744 virtual void onKeyDown(KeyEventArgs& e); 00745 virtual void onTextChanged(WindowEventArgs& e); 00746 virtual void onSized(ElementEventArgs& e); 00747 virtual void onMouseWheel(MouseEventArgs& e); 00748 virtual void onFontChanged(WindowEventArgs& e); 00749 00750 00751 /************************************************************************* 00752 Implementation data 00753 *************************************************************************/ 00754 bool d_readOnly; 00755 size_t d_maxTextLen; 00756 size_t d_caretPos; 00757 size_t d_selectionStart; 00758 size_t d_selectionEnd; 00759 bool d_dragging; 00760 size_t d_dragAnchorIdx; 00761 00762 static String d_lineBreakChars; 00763 bool d_wordWrap; 00764 LineList d_lines; 00765 float d_widestExtent; 00766 00767 // component widget settings 00768 bool d_forceVertScroll; 00769 bool d_forceHorzScroll; 00770 00771 // images 00772 const Image* d_selectionBrush; 00773 00774 00775 private: 00776 /************************************************************************* 00777 Private methods 00778 *************************************************************************/ 00779 void addMultiLineEditboxProperties(void); 00780 }; 00781 00782 } // End of CEGUI namespace section 00783 00784 #if defined(_MSC_VER) 00785 # pragma warning(pop) 00786 #endif 00787 00788 #endif // end of guard _CEGUIMultiLineEditbox_h_