1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 25 #ifndef _SVLBOXITM_HXX 26 #define _SVLBOXITM_HXX 27 28 #include "svtools/svtdllapi.h" 29 30 #ifndef LINK_HXX 31 #include <tools/link.hxx> 32 #endif 33 34 #ifndef _IMAGE_HXX 35 #include <vcl/image.hxx> 36 #endif 37 #include <svtools/svlbox.hxx> 38 39 class SvLBoxEntry; 40 41 #define SV_ITEM_ID_LBOXSTRING 1 42 #define SV_ITEM_ID_LBOXBMP 2 43 #define SV_ITEM_ID_LBOXBUTTON 3 44 #define SV_ITEM_ID_LBOXCONTEXTBMP 4 45 //IAccessibility2 Implementation 2009----- 46 #define SV_ITEM_ID_EXTENDRLBOXSTRING 5 47 //-----IAccessibility2 Implementation 2009 48 49 enum SvButtonState { SV_BUTTON_UNCHECKED, SV_BUTTON_CHECKED, SV_BUTTON_TRISTATE }; 50 51 #define SV_BMP_UNCHECKED 0 52 #define SV_BMP_CHECKED 1 53 #define SV_BMP_TRISTATE 2 54 #define SV_BMP_HIUNCHECKED 3 55 #define SV_BMP_HICHECKED 4 56 #define SV_BMP_HITRISTATE 5 57 #define SV_BMP_STATICIMAGE 6 58 59 struct SvLBoxButtonData_Impl; 60 61 class SVT_DLLPUBLIC SvLBoxButtonData 62 { 63 private: 64 Link aLink; 65 long nWidth; 66 long nHeight; 67 SvLBoxButtonData_Impl* pImpl; 68 sal_Bool bDataOk; 69 SvButtonState eState; 70 71 SVT_DLLPRIVATE void SetWidthAndHeight(); 72 SVT_DLLPRIVATE void InitData( sal_Bool bImagesFromDefault, 73 bool _bRadioBtn, const Control* pControlForSettings = NULL ); 74 public: 75 // include creating default images (CheckBox or RadioButton) 76 SvLBoxButtonData( const Control* pControlForSettings ); 77 SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn ); 78 79 SvLBoxButtonData(); 80 ~SvLBoxButtonData(); 81 82 sal_uInt16 GetIndex( sal_uInt16 nItemState ); 83 inline long Width(); 84 inline long Height(); 85 void SetLink( const Link& rLink) { aLink=rLink; } 86 const Link& GetLink() const { return aLink; } 87 sal_Bool IsRadio(); 88 // weil Buttons nicht von LinkHdl abgeleitet sind 89 void CallLink(); 90 91 void StoreButtonState( SvLBoxEntry* pEntry, sal_uInt16 nItemFlags ); 92 SvButtonState ConvertToButtonState( sal_uInt16 nItemFlags ) const; 93 94 inline SvButtonState GetActButtonState() const; 95 SvLBoxEntry* GetActEntry() const; 96 97 Image aBmps[24]; // Indizes siehe Konstanten BMP_ .... 98 99 void SetDefaultImages( const Control* pControlForSettings = NULL ); 100 // set images acording to the color scheeme of the Control 101 // pControlForSettings == NULL: settings are taken from Application 102 sal_Bool HasDefaultImages( void ) const; 103 }; 104 105 inline long SvLBoxButtonData::Width() 106 { 107 if ( !bDataOk ) 108 SetWidthAndHeight(); 109 return nWidth; 110 } 111 112 inline long SvLBoxButtonData::Height() 113 { 114 if ( !bDataOk ) 115 SetWidthAndHeight(); 116 return nHeight; 117 } 118 119 inline SvButtonState SvLBoxButtonData::GetActButtonState() const 120 { 121 return eState; 122 } 123 124 // ********************************************************************** 125 126 class SVT_DLLPUBLIC SvLBoxString : public SvLBoxItem 127 { 128 XubString aStr; 129 public: 130 SvLBoxString( SvLBoxEntry*,sal_uInt16 nFlags,const XubString& rStr); 131 SvLBoxString(); 132 virtual ~SvLBoxString(); 133 virtual sal_uInt16 IsA(); 134 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* ); 135 XubString GetText() const { return aStr; } 136 //IAccessibility2 Implementation 2009----- 137 virtual XubString GetExtendText() const {return XubString();} 138 //-----IAccessibility2 Implementation 2009 139 void SetText( SvLBoxEntry*, const XubString& rStr ); 140 void Paint( const Point&, SvLBox& rDev, sal_uInt16 nFlags,SvLBoxEntry* ); 141 SvLBoxItem* Create() const; 142 void Clone( SvLBoxItem* pSource ); 143 }; 144 145 class SvLBoxBmp : public SvLBoxItem 146 { 147 Image aBmp; 148 public: 149 SvLBoxBmp( SvLBoxEntry*, sal_uInt16 nFlags, Image ); 150 SvLBoxBmp(); 151 virtual ~SvLBoxBmp(); 152 virtual sal_uInt16 IsA(); 153 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* ); 154 void SetBitmap( SvLBoxEntry*, Image ); 155 void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* ); 156 SvLBoxItem* Create() const; 157 void Clone( SvLBoxItem* pSource ); 158 }; 159 160 161 #define SV_ITEMSTATE_UNCHECKED 0x0001 162 #define SV_ITEMSTATE_CHECKED 0x0002 163 #define SV_ITEMSTATE_TRISTATE 0x0004 164 #define SV_ITEMSTATE_HILIGHTED 0x0008 165 #define SV_STATE_MASK 0xFFF8 // zum Loeschen von UNCHECKED,CHECKED,TRISTATE 166 167 enum SvLBoxButtonKind 168 { 169 SvLBoxButtonKind_enabledCheckbox, 170 SvLBoxButtonKind_disabledCheckbox, 171 SvLBoxButtonKind_staticImage 172 }; 173 174 class SVT_DLLPUBLIC SvLBoxButton : public SvLBoxItem 175 { 176 SvLBoxButtonData* pData; 177 SvLBoxButtonKind eKind; 178 sal_uInt16 nItemFlags; 179 sal_uInt16 nImgArrOffs; 180 sal_uInt16 nBaseOffs; 181 182 void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, Window* pParent ); 183 public: 184 // An SvLBoxButton can be of three different kinds: an 185 // enabled checkbox (the normal kind), a disabled checkbox 186 // (which cannot be modified via UI), or a static image 187 // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored 188 // for that kind). 189 SvLBoxButton( SvLBoxEntry* pEntry, 190 SvLBoxButtonKind eTheKind, sal_uInt16 nFlags, 191 SvLBoxButtonData* pBData ); 192 SvLBoxButton(); 193 virtual ~SvLBoxButton(); 194 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* ); 195 virtual sal_uInt16 IsA(); 196 void Check( SvLBox* pView, SvLBoxEntry*, sal_Bool bCheck ); 197 virtual sal_Bool ClickHdl(SvLBox* pView, SvLBoxEntry* ); 198 void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* ); 199 SvLBoxItem* Create() const; 200 void Clone( SvLBoxItem* pSource ); 201 sal_uInt16 GetButtonFlags() const { return nItemFlags; } 202 sal_Bool IsStateChecked() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_CHECKED)!=0; } 203 sal_Bool IsStateUnchecked() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_UNCHECKED)!=0; } 204 sal_Bool IsStateTristate() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_TRISTATE)!=0; } 205 sal_Bool IsStateHilighted() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_HILIGHTED)!=0; } 206 void SetStateChecked(); 207 void SetStateUnchecked(); 208 void SetStateTristate(); 209 void SetStateHilighted( sal_Bool bHilight ); 210 211 SvLBoxButtonKind GetKind() const { return eKind; } 212 213 void SetBaseOffs( sal_uInt16 nOffs ) { nBaseOffs = nOffs; } 214 sal_uInt16 GetBaseOffs() const { return nBaseOffs; } 215 216 // Check whether this button can be modified via UI, sounding a beep if it 217 // cannot be modified: 218 bool CheckModification() const; 219 //IAccessible2 implementation 2009 220 SvLBoxButtonData* GetButtonData() const{ return pData;} 221 }; 222 223 inline void SvLBoxButton::SetStateChecked() 224 { 225 nItemFlags &= SV_STATE_MASK; 226 nItemFlags |= SV_ITEMSTATE_CHECKED; 227 } 228 inline void SvLBoxButton::SetStateUnchecked() 229 { 230 nItemFlags &= SV_STATE_MASK; 231 nItemFlags |= SV_ITEMSTATE_UNCHECKED; 232 } 233 inline void SvLBoxButton::SetStateTristate() 234 { 235 nItemFlags &= SV_STATE_MASK; 236 nItemFlags |= SV_ITEMSTATE_TRISTATE; 237 } 238 inline void SvLBoxButton::SetStateHilighted( sal_Bool bHilight ) 239 { 240 if ( bHilight ) 241 nItemFlags |= SV_ITEMSTATE_HILIGHTED; 242 else 243 nItemFlags &= ~SV_ITEMSTATE_HILIGHTED; 244 } 245 246 247 struct SvLBoxContextBmp_Impl; 248 class SVT_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem 249 { 250 SvLBoxContextBmp_Impl* m_pImpl; 251 public: 252 SvLBoxContextBmp( SvLBoxEntry*,sal_uInt16 nFlags,Image,Image, 253 sal_uInt16 nEntryFlagsBmp1); 254 SvLBoxContextBmp(); 255 virtual ~SvLBoxContextBmp(); 256 virtual sal_uInt16 IsA(); 257 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* ); 258 void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* ); 259 SvLBoxItem* Create() const; 260 void Clone( SvLBoxItem* pSource ); 261 262 263 sal_Bool SetModeImages( const Image& _rBitmap1, const Image& _rBitmap2, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 264 void GetModeImages( Image& _rBitmap1, Image& _rBitmap2, BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 265 266 inline void SetBitmap1( const Image& _rImage, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 267 inline void SetBitmap2( const Image& _rImage, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 268 inline const Image& GetBitmap1( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 269 inline const Image& GetBitmap2( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 270 271 private: 272 Image& implGetImageStore( sal_Bool _bFirst, BmpColorMode _eMode ); 273 }; 274 275 inline void SvLBoxContextBmp::SetBitmap1( const Image& _rImage, BmpColorMode _eMode ) 276 { 277 implGetImageStore( sal_True, _eMode ) = _rImage; 278 } 279 280 inline void SvLBoxContextBmp::SetBitmap2( const Image& _rImage, BmpColorMode _eMode ) 281 { 282 implGetImageStore( sal_False, _eMode ) = _rImage; 283 } 284 285 inline const Image& SvLBoxContextBmp::GetBitmap1( BmpColorMode _eMode ) const 286 { 287 Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True, _eMode ); 288 if ( !rImage ) 289 // fallback to the "normal" image 290 rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True, BMP_COLOR_NORMAL ); 291 return rImage; 292 } 293 294 inline const Image& SvLBoxContextBmp::GetBitmap2( BmpColorMode _eMode ) const 295 { 296 Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_False, _eMode ); 297 if ( !rImage ) 298 // fallback to the "normal" image 299 rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True, BMP_COLOR_NORMAL ); 300 return rImage; 301 } 302 303 #endif 304