/indra/newview/lltexturectrl.h
C Header | 216 lines | 136 code | 39 blank | 41 comment | 0 complexity | ffa84e85d1d3a60ee040f277b9215be5 MD5 | raw file
Possible License(s): LGPL-2.1
1/** 2 * @file lltexturectrl.h 3 * @author Richard Nelson, James Cook 4 * @brief LLTextureCtrl class header file including related functions 5 * 6 * $LicenseInfo:firstyear=2002&license=viewerlgpl$ 7 * Second Life Viewer Source Code 8 * Copyright (C) 2010, Linden Research, Inc. 9 * 10 * This library is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU Lesser General Public 12 * License as published by the Free Software Foundation; 13 * version 2.1 of the License only. 14 * 15 * This library is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * Lesser General Public License for more details. 19 * 20 * You should have received a copy of the GNU Lesser General Public 21 * License along with this library; if not, write to the Free Software 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA 25 * $/LicenseInfo$ 26 */ 27 28#ifndef LL_LLTEXTURECTRL_H 29#define LL_LLTEXTURECTRL_H 30 31#include "llcoord.h" 32#include "llfloater.h" 33#include "llstring.h" 34#include "lluictrl.h" 35#include "llpermissionsflags.h" 36#include "lltextbox.h" // for params 37#include "llviewborder.h" // for params 38 39class LLButton; 40class LLFloaterTexturePicker; 41class LLInventoryItem; 42class LLViewerFetchedTexture; 43 44// used for setting drag & drop callbacks. 45typedef boost::function<BOOL (LLUICtrl*, LLInventoryItem*)> drag_n_drop_callback; 46 47 48////////////////////////////////////////////////////////////////////////////////////////// 49// LLTextureCtrl 50 51 52class LLTextureCtrl 53: public LLUICtrl 54{ 55public: 56 typedef enum e_texture_pick_op 57 { 58 TEXTURE_CHANGE, 59 TEXTURE_SELECT, 60 TEXTURE_CANCEL 61 } ETexturePickOp; 62 63public: 64 struct Params : public LLInitParam::Block<Params, LLUICtrl::Params> 65 { 66 Optional<LLUUID> image_id; 67 Optional<LLUUID> default_image_id; 68 Optional<std::string> default_image_name; 69 Optional<bool> allow_no_texture; 70 Optional<bool> can_apply_immediately; 71 Optional<bool> no_commit_on_selection; // alternative mode: commit occurs and the widget gets dirty 72 // only on DnD or when OK is pressed in the picker 73 Optional<S32> label_width; 74 Optional<LLUIColor> border_color; 75 Optional<LLUIImage*> fallback_image; 76 77 Optional<LLTextBox::Params> multiselect_text, 78 caption_text; 79 80 Optional<LLViewBorder::Params> border; 81 82 Params() 83 : image_id("image"), 84 default_image_id("default_image_id"), 85 default_image_name("default_image_name"), 86 allow_no_texture("allow_no_texture"), 87 can_apply_immediately("can_apply_immediately"), 88 no_commit_on_selection("no_commit_on_selection", false), 89 label_width("label_width", -1), 90 border_color("border_color"), 91 fallback_image("fallback_image"), 92 multiselect_text("multiselect_text"), 93 caption_text("caption_text"), 94 border("border") 95 {} 96 }; 97protected: 98 LLTextureCtrl(const Params&); 99 friend class LLUICtrlFactory; 100public: 101 virtual ~LLTextureCtrl(); 102 103 // LLView interface 104 105 virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask); 106 virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, 107 BOOL drop, EDragAndDropType cargo_type, void *cargo_data, 108 EAcceptance *accept, 109 std::string& tooltip_msg); 110 virtual BOOL handleHover(S32 x, S32 y, MASK mask); 111 virtual BOOL handleUnicodeCharHere(llwchar uni_char); 112 113 virtual void draw(); 114 virtual void setVisible( BOOL visible ); 115 virtual void setEnabled( BOOL enabled ); 116 117 void setValid(BOOL valid); 118 119 // LLUICtrl interface 120 virtual void clear(); 121 122 // Takes a UUID, wraps get/setImageAssetID 123 virtual void setValue(const LLSD& value); 124 virtual LLSD getValue() const; 125 126 // LLTextureCtrl interface 127 void showPicker(BOOL take_focus); 128 void setLabel(const std::string& label); 129 void setLabelWidth(S32 label_width) {mLabelWidth =label_width;} 130 const std::string& getLabel() const { return mLabel; } 131 132 void setAllowNoTexture( BOOL b ) { mAllowNoTexture = b; } 133 bool getAllowNoTexture() const { return mAllowNoTexture; } 134 135 const LLUUID& getImageItemID() { return mImageItemID; } 136 137 virtual void setImageAssetName(const std::string& name); 138 139 void setImageAssetID(const LLUUID &image_asset_id); 140 const LLUUID& getImageAssetID() const { return mImageAssetID; } 141 142 void setDefaultImageAssetID( const LLUUID& id ) { mDefaultImageAssetID = id; } 143 const LLUUID& getDefaultImageAssetID() const { return mDefaultImageAssetID; } 144 145 const std::string& getDefaultImageName() const { return mDefaultImageName; } 146 147 void setCaption(const std::string& caption); 148 void setCanApplyImmediately(BOOL b); 149 150 void setImmediateFilterPermMask(PermissionMask mask) 151 { mImmediateFilterPermMask = mask; } 152 void setNonImmediateFilterPermMask(PermissionMask mask) 153 { mNonImmediateFilterPermMask = mask; } 154 PermissionMask getImmediateFilterPermMask() { return mImmediateFilterPermMask; } 155 PermissionMask getNonImmediateFilterPermMask() { return mNonImmediateFilterPermMask; } 156 157 void closeDependentFloater(); 158 159 void onFloaterClose(); 160 void onFloaterCommit(ETexturePickOp op); 161 162 // This call is returned when a drag is detected. Your callback 163 // should return TRUE if the drag is acceptable. 164 void setDragCallback(drag_n_drop_callback cb) { mDragCallback = cb; } 165 166 // This callback is called when the drop happens. Return TRUE if 167 // the drop happened - resulting in an on commit callback, but not 168 // necessariliy any other change. 169 void setDropCallback(drag_n_drop_callback cb) { mDropCallback = cb; } 170 171 void setOnCancelCallback(commit_callback_t cb) { mOnCancelCallback = cb; } 172 173 void setOnSelectCallback(commit_callback_t cb) { mOnSelectCallback = cb; } 174 175 void setShowLoadingPlaceholder(BOOL showLoadingPlaceholder); 176 177 LLViewerFetchedTexture* getTexture() { return mTexturep; } 178 179private: 180 BOOL allowDrop(LLInventoryItem* item); 181 BOOL doDrop(LLInventoryItem* item); 182 183private: 184 drag_n_drop_callback mDragCallback; 185 drag_n_drop_callback mDropCallback; 186 commit_callback_t mOnCancelCallback; 187 commit_callback_t mOnSelectCallback; 188 LLPointer<LLViewerFetchedTexture> mTexturep; 189 LLUIColor mBorderColor; 190 LLUUID mImageItemID; 191 LLUUID mImageAssetID; 192 LLUUID mDefaultImageAssetID; 193 LLUIImagePtr mFallbackImage; 194 std::string mDefaultImageName; 195 LLHandle<LLFloater> mFloaterHandle; 196 LLTextBox* mTentativeLabel; 197 LLTextBox* mCaption; 198 std::string mLabel; 199 BOOL mAllowNoTexture; // If true, the user can select "none" as an option 200 PermissionMask mImmediateFilterPermMask; 201 PermissionMask mNonImmediateFilterPermMask; 202 BOOL mCanApplyImmediately; 203 BOOL mCommitOnSelection; 204 BOOL mNeedsRawImageData; 205 LLViewBorder* mBorder; 206 BOOL mValid; 207 BOOL mShowLoadingPlaceholder; 208 std::string mLoadingPlaceholderString; 209 S32 mLabelWidth; 210}; 211 212// XUI HACK: When floaters converted, switch this file to lltexturepicker.h/cpp 213// and class to LLTexturePicker 214#define LLTexturePicker LLTextureCtrl 215 216#endif // LL_LLTEXTURECTRL_H