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 46 enum SvButtonState { SV_BUTTON_UNCHECKED, SV_BUTTON_CHECKED, SV_BUTTON_TRISTATE }; 47 48 #define SV_BMP_UNCHECKED 0 49 #define SV_BMP_CHECKED 1 50 #define SV_BMP_TRISTATE 2 51 #define SV_BMP_HIUNCHECKED 3 52 #define SV_BMP_HICHECKED 4 53 #define SV_BMP_HITRISTATE 5 54 #define SV_BMP_STATICIMAGE 6 55 56 struct SvLBoxButtonData_Impl; 57 58 class SVT_DLLPUBLIC SvLBoxButtonData 59 { 60 private: 61 Link aLink; 62 long nWidth; 63 long nHeight; 64 SvLBoxButtonData_Impl* pImpl; 65 sal_Bool bDataOk; 66 SvButtonState eState; 67 68 SVT_DLLPRIVATE void SetWidthAndHeight(); 69 SVT_DLLPRIVATE void InitData( sal_Bool bImagesFromDefault, 70 bool _bRadioBtn, const Control* pControlForSettings = NULL ); 71 public: 72 // include creating default images (CheckBox or RadioButton) 73 SvLBoxButtonData( const Control* pControlForSettings ); 74 SvLBoxButtonData( const Control* pControlForSettings, bool _bRadioBtn ); 75 76 SvLBoxButtonData(); 77 ~SvLBoxButtonData(); 78 79 sal_uInt16 GetIndex( sal_uInt16 nItemState ); 80 inline long Width(); 81 inline long Height(); 82 void SetLink( const Link& rLink) { aLink=rLink; } 83 const Link& GetLink() const { return aLink; } 84 sal_Bool IsRadio(); 85 // weil Buttons nicht von LinkHdl abgeleitet sind 86 void CallLink(); 87 88 void StoreButtonState( SvLBoxEntry* pEntry, sal_uInt16 nItemFlags ); 89 SvButtonState ConvertToButtonState( sal_uInt16 nItemFlags ) const; 90 91 inline SvButtonState GetActButtonState() const; 92 SvLBoxEntry* GetActEntry() const; 93 94 Image aBmps[24]; // Indizes siehe Konstanten BMP_ .... 95 96 void SetDefaultImages( const Control* pControlForSettings = NULL ); 97 // set images acording to the color scheeme of the Control 98 // pControlForSettings == NULL: settings are taken from Application 99 sal_Bool HasDefaultImages( void ) const; 100 }; 101 102 inline long SvLBoxButtonData::Width() 103 { 104 if ( !bDataOk ) 105 SetWidthAndHeight(); 106 return nWidth; 107 } 108 109 inline long SvLBoxButtonData::Height() 110 { 111 if ( !bDataOk ) 112 SetWidthAndHeight(); 113 return nHeight; 114 } 115 116 inline SvButtonState SvLBoxButtonData::GetActButtonState() const 117 { 118 return eState; 119 } 120 121 // ********************************************************************** 122 123 class SVT_DLLPUBLIC SvLBoxString : public SvLBoxItem 124 { 125 XubString aStr; 126 public: 127 SvLBoxString( SvLBoxEntry*,sal_uInt16 nFlags,const XubString& rStr); 128 SvLBoxString(); 129 virtual ~SvLBoxString(); 130 virtual sal_uInt16 IsA(); 131 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* ); 132 XubString GetText() const { return aStr; } 133 void SetText( SvLBoxEntry*, const XubString& rStr ); 134 void Paint( const Point&, SvLBox& rDev, sal_uInt16 nFlags,SvLBoxEntry* ); 135 SvLBoxItem* Create() const; 136 void Clone( SvLBoxItem* pSource ); 137 }; 138 139 class SvLBoxBmp : public SvLBoxItem 140 { 141 Image aBmp; 142 public: 143 SvLBoxBmp( SvLBoxEntry*, sal_uInt16 nFlags, Image ); 144 SvLBoxBmp(); 145 virtual ~SvLBoxBmp(); 146 virtual sal_uInt16 IsA(); 147 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* ); 148 void SetBitmap( SvLBoxEntry*, Image ); 149 void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* ); 150 SvLBoxItem* Create() const; 151 void Clone( SvLBoxItem* pSource ); 152 }; 153 154 155 #define SV_ITEMSTATE_UNCHECKED 0x0001 156 #define SV_ITEMSTATE_CHECKED 0x0002 157 #define SV_ITEMSTATE_TRISTATE 0x0004 158 #define SV_ITEMSTATE_HILIGHTED 0x0008 159 #define SV_STATE_MASK 0xFFF8 // zum Loeschen von UNCHECKED,CHECKED,TRISTATE 160 161 enum SvLBoxButtonKind 162 { 163 SvLBoxButtonKind_enabledCheckbox, 164 SvLBoxButtonKind_disabledCheckbox, 165 SvLBoxButtonKind_staticImage 166 }; 167 168 class SVT_DLLPUBLIC SvLBoxButton : public SvLBoxItem 169 { 170 SvLBoxButtonData* pData; 171 SvLBoxButtonKind eKind; 172 sal_uInt16 nItemFlags; 173 sal_uInt16 nImgArrOffs; 174 sal_uInt16 nBaseOffs; 175 176 void ImplAdjustBoxSize( Size& io_rCtrlSize, ControlType i_eType, Window* pParent ); 177 public: 178 // An SvLBoxButton can be of three different kinds: an 179 // enabled checkbox (the normal kind), a disabled checkbox 180 // (which cannot be modified via UI), or a static image 181 // (see SV_BMP_STATICIMAGE; nFlags are effectively ignored 182 // for that kind). 183 SvLBoxButton( SvLBoxEntry* pEntry, 184 SvLBoxButtonKind eTheKind, sal_uInt16 nFlags, 185 SvLBoxButtonData* pBData ); 186 SvLBoxButton(); 187 virtual ~SvLBoxButton(); 188 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* ); 189 virtual sal_uInt16 IsA(); 190 void Check( SvLBox* pView, SvLBoxEntry*, sal_Bool bCheck ); 191 virtual sal_Bool ClickHdl(SvLBox* pView, SvLBoxEntry* ); 192 void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* ); 193 SvLBoxItem* Create() const; 194 void Clone( SvLBoxItem* pSource ); 195 sal_uInt16 GetButtonFlags() const { return nItemFlags; } 196 sal_Bool IsStateChecked() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_CHECKED)!=0; } 197 sal_Bool IsStateUnchecked() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_UNCHECKED)!=0; } 198 sal_Bool IsStateTristate() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_TRISTATE)!=0; } 199 sal_Bool IsStateHilighted() const { return (sal_Bool)(nItemFlags & SV_ITEMSTATE_HILIGHTED)!=0; } 200 void SetStateChecked(); 201 void SetStateUnchecked(); 202 void SetStateTristate(); 203 void SetStateHilighted( sal_Bool bHilight ); 204 205 SvLBoxButtonKind GetKind() const { return eKind; } 206 207 void SetBaseOffs( sal_uInt16 nOffs ) { nBaseOffs = nOffs; } 208 sal_uInt16 GetBaseOffs() const { return nBaseOffs; } 209 210 // Check whether this button can be modified via UI, sounding a beep if it 211 // cannot be modified: 212 bool CheckModification() const; 213 }; 214 215 inline void SvLBoxButton::SetStateChecked() 216 { 217 nItemFlags &= SV_STATE_MASK; 218 nItemFlags |= SV_ITEMSTATE_CHECKED; 219 } 220 inline void SvLBoxButton::SetStateUnchecked() 221 { 222 nItemFlags &= SV_STATE_MASK; 223 nItemFlags |= SV_ITEMSTATE_UNCHECKED; 224 } 225 inline void SvLBoxButton::SetStateTristate() 226 { 227 nItemFlags &= SV_STATE_MASK; 228 nItemFlags |= SV_ITEMSTATE_TRISTATE; 229 } 230 inline void SvLBoxButton::SetStateHilighted( sal_Bool bHilight ) 231 { 232 if ( bHilight ) 233 nItemFlags |= SV_ITEMSTATE_HILIGHTED; 234 else 235 nItemFlags &= ~SV_ITEMSTATE_HILIGHTED; 236 } 237 238 239 struct SvLBoxContextBmp_Impl; 240 class SVT_DLLPUBLIC SvLBoxContextBmp : public SvLBoxItem 241 { 242 SvLBoxContextBmp_Impl* m_pImpl; 243 public: 244 SvLBoxContextBmp( SvLBoxEntry*,sal_uInt16 nFlags,Image,Image, 245 sal_uInt16 nEntryFlagsBmp1); 246 SvLBoxContextBmp(); 247 virtual ~SvLBoxContextBmp(); 248 virtual sal_uInt16 IsA(); 249 void InitViewData( SvLBox*,SvLBoxEntry*,SvViewDataItem* ); 250 void Paint( const Point&, SvLBox& rView, sal_uInt16 nFlags,SvLBoxEntry* ); 251 SvLBoxItem* Create() const; 252 void Clone( SvLBoxItem* pSource ); 253 254 255 sal_Bool SetModeImages( const Image& _rBitmap1, const Image& _rBitmap2, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 256 void GetModeImages( Image& _rBitmap1, Image& _rBitmap2, BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 257 258 inline void SetBitmap1( const Image& _rImage, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 259 inline void SetBitmap2( const Image& _rImage, BmpColorMode _eMode = BMP_COLOR_NORMAL ); 260 inline const Image& GetBitmap1( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 261 inline const Image& GetBitmap2( BmpColorMode _eMode = BMP_COLOR_NORMAL ) const; 262 263 private: 264 Image& implGetImageStore( sal_Bool _bFirst, BmpColorMode _eMode ); 265 }; 266 267 inline void SvLBoxContextBmp::SetBitmap1( const Image& _rImage, BmpColorMode _eMode ) 268 { 269 implGetImageStore( sal_True, _eMode ) = _rImage; 270 } 271 272 inline void SvLBoxContextBmp::SetBitmap2( const Image& _rImage, BmpColorMode _eMode ) 273 { 274 implGetImageStore( sal_False, _eMode ) = _rImage; 275 } 276 277 inline const Image& SvLBoxContextBmp::GetBitmap1( BmpColorMode _eMode ) const 278 { 279 Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True, _eMode ); 280 if ( !rImage ) 281 // fallback to the "normal" image 282 rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True, BMP_COLOR_NORMAL ); 283 return rImage; 284 } 285 286 inline const Image& SvLBoxContextBmp::GetBitmap2( BmpColorMode _eMode ) const 287 { 288 Image& rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_False, _eMode ); 289 if ( !rImage ) 290 // fallback to the "normal" image 291 rImage = const_cast< SvLBoxContextBmp* >( this )->implGetImageStore( sal_True, BMP_COLOR_NORMAL ); 292 return rImage; 293 } 294 295 #endif 296