diff options
author | Bryan O'Sullivan <bos@lindenlab.com> | 2009-08-31 13:47:47 -0700 |
---|---|---|
committer | Bryan O'Sullivan <bos@lindenlab.com> | 2009-08-31 13:47:47 -0700 |
commit | 30ff6cabd61f2f083df5df1e6e70cc94742af477 (patch) | |
tree | 631935f1cf59d19a91cdad65e9a75fe825afda7d /indra/llui/lllineeditor.h | |
parent | ff11d74820c89822cd067b51727d9df1dc87d0d0 (diff) | |
parent | 3ac3a4b206c08ed06b889bdaa24074b6aa0e020a (diff) |
Merge with trunk
Diffstat (limited to 'indra/llui/lllineeditor.h')
-rw-r--r-- | indra/llui/lllineeditor.h | 186 |
1 files changed, 92 insertions, 94 deletions
diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h index fc5fcc5b90..0986ce5a87 100644 --- a/indra/llui/lllineeditor.h +++ b/indra/llui/lllineeditor.h @@ -51,39 +51,72 @@ #include "llviewborder.h" #include "llpreeditor.h" +#include <boost/function.hpp> class LLFontGL; class LLLineEditorRollback; class LLButton; -typedef BOOL (*LLLinePrevalidateFunc)(const LLWString &wstr); - +typedef boost::function<BOOL (const LLWString &wstr)> LLLinePrevalidateFunc; class LLLineEditor : public LLUICtrl, public LLEditMenuHandler, protected LLPreeditor { - public: - LLLineEditor(const std::string& name, - const LLRect& rect, - const std::string& default_text = LLStringUtil::null, - const LLFontGL* glfont = NULL, - S32 max_length_bytes = 254, - void (*commit_callback)(LLUICtrl* caller, void* user_data) = NULL, - void (*keystroke_callback)(LLLineEditor* caller, void* user_data) = NULL, - void (*focus_lost_callback)(LLFocusableElement* caller, void* user_data) = NULL, - void* userdata = NULL, - LLLinePrevalidateFunc prevalidate_func = NULL, - LLViewBorder::EBevel border_bevel = LLViewBorder::BEVEL_IN, - LLViewBorder::EStyle border_style = LLViewBorder::STYLE_LINE, - S32 border_thickness = 1); - virtual ~LLLineEditor(); + struct PrevalidateNamedFuncs + : public LLInitParam::TypeValuesHelper<LLLinePrevalidateFunc, PrevalidateNamedFuncs> - virtual LLXMLNodePtr getXML(bool save_children = true) const; - void setColorParameters(LLXMLNodePtr node); - static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); - static void cleanupLineEditor(); + { + static void declareValues(); + }; + + typedef boost::function<void (LLLineEditor* caller)> keystroke_callback_t; + + struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> + { + Optional<std::string> default_text; + Optional<S32> max_length_bytes; + + Optional<keystroke_callback_t> keystroke_callback; + + Optional<LLLinePrevalidateFunc, PrevalidateNamedFuncs> prevalidate_callback; + + Optional<LLViewBorder::Params> border; + + Optional<LLUIImage*> background_image, + background_image_disabled, + background_image_focused; + + Optional<bool> select_on_focus, + handle_edit_keys_directly, + commit_on_focus_lost, + ignore_tab; + + // colors + Optional<LLUIColor> cursor_color, + text_color, + text_readonly_color, + text_tentative_color, + highlight_color, + preedit_bg_color; + + Optional<S32> text_pad_left, + text_pad_right; + + Ignored is_unicode, + drop_shadow_visible, + border_drop_shadow_visible, + bg_visible; + + Params(); + }; +protected: + LLLineEditor(const Params&); + friend class LLUICtrlFactory; + friend class LLFloaterEditUI; +public: + virtual ~LLLineEditor(); // mousehandler overrides /*virtual*/ BOOL handleMouseDown(S32 x, S32 y, MASK mask); @@ -131,12 +164,12 @@ public: virtual void setRect(const LLRect& rect); virtual BOOL acceptsTextInput() const; virtual void onCommit(); - virtual BOOL isDirty() const { return mText.getString() != mPrevText; } // Returns TRUE if user changed value at all - virtual void resetDirty() { mPrevText = mText.getString(); } // Clear dirty state + virtual BOOL isDirty() const; // Returns TRUE if user changed value at all + virtual void resetDirty(); // Clear dirty state // assumes UTF8 text - virtual void setValue(const LLSD& value ) { setText(value.asString()); } - virtual LLSD getValue() const { return LLSD(getText()); } + virtual void setValue(const LLSD& value ); + virtual LLSD getValue() const; virtual BOOL setTextArg( const std::string& key, const LLStringExplicit& text ); virtual BOOL setLabelArg( const std::string& key, const LLStringExplicit& text ); @@ -144,7 +177,7 @@ public: void setText(const LLStringExplicit &new_text); const std::string& getText() const { return mText.getString(); } - const LLWString& getWText() const { return mText.getWString(); } + LLWString getWText() const { return mText.getWString(); } LLWString getConvertedText() const; // trimmed text with paragraphs converted to newlines S32 getLength() const { return mText.length(); } @@ -160,21 +193,15 @@ public: void setRevertOnEsc( BOOL b ) { mRevertOnEsc = b; } void setCursorColor(const LLColor4& c) { mCursorColor = c; } - const LLColor4& getCursorColor() const { return mCursorColor; } + const LLColor4& getCursorColor() const { return mCursorColor.get(); } void setFgColor( const LLColor4& c ) { mFgColor = c; } void setReadOnlyFgColor( const LLColor4& c ) { mReadOnlyFgColor = c; } void setTentativeFgColor(const LLColor4& c) { mTentativeFgColor = c; } - void setWriteableBgColor( const LLColor4& c ) { mWriteableBgColor = c; } - void setReadOnlyBgColor( const LLColor4& c ) { mReadOnlyBgColor = c; } - void setFocusBgColor(const LLColor4& c) { mFocusBgColor = c; } - const LLColor4& getFgColor() const { return mFgColor; } - const LLColor4& getReadOnlyFgColor() const { return mReadOnlyFgColor; } - const LLColor4& getTentativeFgColor() const { return mTentativeFgColor; } - const LLColor4& getWriteableBgColor() const { return mWriteableBgColor; } - const LLColor4& getReadOnlyBgColor() const { return mReadOnlyBgColor; } - const LLColor4& getFocusBgColor() const { return mFocusBgColor; } + const LLColor4& getFgColor() const { return mFgColor.get(); } + const LLColor4& getReadOnlyFgColor() const { return mReadOnlyFgColor.get(); } + const LLColor4& getTentativeFgColor() const { return mTentativeFgColor.get(); } void setIgnoreArrowKeys(BOOL b) { mIgnoreArrowKeys = b; } void setIgnoreTab(BOOL b) { mIgnoreTab = b; } @@ -193,14 +220,14 @@ public: void setHandleEditKeysDirectly( BOOL b ) { mHandleEditKeysDirectly = b; } void setSelectAllonFocusReceived(BOOL b); - - void setKeystrokeCallback(void (*keystroke_callback)(LLLineEditor* caller, void* user_data)); + + typedef boost::function<void (LLLineEditor* caller, void* user_data)> callback_t; + void setKeystrokeCallback(callback_t callback, void* user_data); void setMaxTextLength(S32 max_text_length); - void setTextPadding(S32 left, S32 right); // Used to specify room for children before or after text. // Prevalidation controls which keystrokes can affect the editor - void setPrevalidate( BOOL (*func)(const LLWString &) ); + void setPrevalidate( LLLinePrevalidateFunc func ); static BOOL prevalidateFloat(const LLWString &str ); static BOOL prevalidateInt(const LLWString &str ); static BOOL prevalidatePositiveS32(const LLWString &str); @@ -233,6 +260,10 @@ private: BOOL handleSelectionKey(KEY key, MASK mask); BOOL handleControlKey(KEY key, MASK mask); S32 handleCommitKey(KEY key, MASK mask); + void updateTextPadding(); + + // Draw the background image depending on enabled/focused state. + void drawBackground(); // // private data members @@ -273,7 +304,7 @@ protected: BOOL mCommitOnFocusLost; BOOL mRevertOnEsc; - void (*mKeystrokeCallback)( LLLineEditor* caller, void* userdata ); + keystroke_callback_t mKeystrokeCallback; BOOL mIsSelecting; // Selection for clipboard operations S32 mSelectionStart; @@ -283,18 +314,17 @@ protected: S32 mLastSelectionStart; S32 mLastSelectionEnd; - S32 (*mPrevalidateFunc)(const LLWString &str); + LLLinePrevalidateFunc mPrevalidateFunc; LLFrameTimer mKeystrokeTimer; + LLTimer mTripleClickTimer; - LLColor4 mCursorColor; - - LLColor4 mFgColor; - LLColor4 mReadOnlyFgColor; - LLColor4 mTentativeFgColor; - LLColor4 mWriteableBgColor; - LLColor4 mReadOnlyBgColor; - LLColor4 mFocusBgColor; + LLUIColor mCursorColor; + LLUIColor mFgColor; + LLUIColor mReadOnlyFgColor; + LLUIColor mTentativeFgColor; + LLUIColor mHighlightColor; // background for selected text + LLUIColor mPreeditBgColor; // preedit marker background color S32 mBorderThickness; @@ -314,13 +344,10 @@ protected: LLPreeditor::standouts_t mPreeditStandouts; private: - // Utility on top of LLUI::getUIImage, looks up a named image in a given XML node and returns it if possible - // or returns a given default image if anything in the process fails. - static LLPointer<LLUIImage> parseImage(std::string name, LLXMLNodePtr from, LLPointer<LLUIImage> def); - // Global instance used as default for member instance below. - static LLPointer<LLUIImage> sImage; // Instances that by default point to the statics but can be overidden in XML. - LLPointer<LLUIImage> mImage; + LLPointer<LLUIImage> mBgImage; + LLPointer<LLUIImage> mBgImageDisabled; + LLPointer<LLUIImage> mBgImageFocused; BOOL mReplaceNewlinesWithSpaces; // if false, will replace pasted newlines with paragraph symbol. @@ -364,44 +391,15 @@ private: }; // end class LLLineEditor - -/* - * @brief A line editor with a button to clear it and a callback to call on every edit event. - */ -class LLSearchEditor : public LLUICtrl +namespace LLInitParam { -public: - LLSearchEditor(const std::string& name, - const LLRect& rect, - S32 max_length_bytes, - void (*search_callback)(const std::string& search_string, void* user_data), - void* userdata); - - virtual ~LLSearchEditor() {} - - /*virtual*/ void draw(); - - static LLView* fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory *factory); - - void setText(const LLStringExplicit &new_text) { mSearchEdit->setText(new_text); } - - void setSearchCallback(void (*search_callback)(const std::string& search_string, void* user_data), void* data) { mSearchCallback = search_callback; mCallbackUserData = data; } - - // LLUICtrl interface - virtual void setValue(const LLSD& value ); - virtual LLSD getValue() const; - virtual BOOL setTextArg( const std::string& key, const LLStringExplicit& text ); - virtual BOOL setLabelArg( const std::string& key, const LLStringExplicit& text ); - virtual void clear(); - -private: - static void onSearchEdit(LLLineEditor* caller, void* user_data ); - static void onClearSearch(void* user_data); - - LLLineEditor* mSearchEdit; - class LLButton* mClearSearchButton; - void (*mSearchCallback)(const std::string& search_string, void* user_data); - -}; + template<> + bool ParamCompare<LLLinePrevalidateFunc>::equals( + const LLLinePrevalidateFunc &a, const LLLinePrevalidateFunc &b); + + template<> + bool ParamCompare<boost::function<void (LLLineEditor *)> >::equals( + const boost::function<void (LLLineEditor *)> &a, const boost::function<void (LLLineEditor *)> &b); +} #endif // LL_LINEEDITOR_ |