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