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 #ifndef _SV_LSTBOX_HXX 25 #define _SV_LSTBOX_HXX 26 27 #include <vcl/dllapi.h> 28 #include <vcl/ctrl.hxx> 29 #include <vcl/lstbox.h> 30 31 class Image; 32 class ImplListBox; 33 class ImplListBoxFloatingWindow; 34 class ImplBtn; 35 class ImplWin; 36 37 // -------------------------------------------------------------------- 38 // - ListBox - 39 // -------------------------------------------------------------------- 40 41 class VCL_DLLPUBLIC ListBox : public Control 42 { 43 private: 44 ImplListBox* mpImplLB; 45 ImplListBoxFloatingWindow* mpFloatWin; 46 ImplWin* mpImplWin; 47 ImplBtn* mpBtn; 48 sal_uInt16 mnDDHeight; 49 sal_uInt16 mnSaveValue; 50 Link maSelectHdl; 51 Link maDoubleClickHdl; 52 sal_uInt16 mnLineCount; 53 54 /// bitfield 55 bool mbDDAutoSize : 1; 56 bool mbEdgeBlending : 1; 57 58 //#if 0 // _SOLAR__PRIVATE 59 private: 60 SAL_DLLPRIVATE void ImplInitListBoxData(); 61 62 DECL_DLLPRIVATE_LINK( ImplSelectHdl, void* ); 63 DECL_DLLPRIVATE_LINK( ImplScrollHdl, void* ); 64 DECL_DLLPRIVATE_LINK( ImplCancelHdl, void* ); 65 DECL_DLLPRIVATE_LINK( ImplDoubleClickHdl, void* ); 66 DECL_DLLPRIVATE_LINK( ImplClickBtnHdl, void* ); 67 DECL_DLLPRIVATE_LINK( ImplPopupModeEndHdl, void* ); 68 DECL_DLLPRIVATE_LINK( ImplSelectionChangedHdl, void* ); 69 DECL_DLLPRIVATE_LINK( ImplUserDrawHdl, UserDrawEvent* ); 70 DECL_DLLPRIVATE_LINK( ImplFocusHdl, void* ); 71 DECL_DLLPRIVATE_LINK( ImplListItemSelectHdl , void* ); 72 protected: 73 using Window::ImplInit; 74 SAL_DLLPRIVATE void ImplInit( Window* pParent, WinBits nStyle ); 75 SAL_DLLPRIVATE WinBits ImplInitStyle( WinBits nStyle ); 76 SAL_DLLPRIVATE void ImplLoadRes( const ResId& rResId ); 77 //#endif IsDropDownBox() const78 sal_Bool IsDropDownBox() const { return mpFloatWin ? sal_True : sal_False; } 79 80 protected: 81 ListBox( WindowType nType ); 82 83 virtual void FillLayoutData() const; 84 85 public: 86 explicit ListBox( Window* pParent, WinBits nStyle = WB_BORDER ); 87 explicit ListBox( Window* pParent, const ResId& ); 88 virtual ~ListBox(); 89 90 virtual void Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ); 91 virtual void Resize(); 92 virtual long PreNotify( NotifyEvent& rNEvt ); 93 virtual void StateChanged( StateChangedType nType ); 94 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 95 virtual void UserDraw( const UserDrawEvent& rUDEvt ); 96 97 virtual void Select(); 98 virtual void DoubleClick(); 99 virtual void GetFocus(); 100 virtual void LoseFocus(); 101 virtual Window* GetPreferredKeyInputWindow(); 102 103 virtual const Wallpaper& GetDisplayBackground() const; 104 105 virtual void SetPosSizePixel( long nX, long nY, 106 long nWidth, long nHeight, sal_uInt16 nFlags = WINDOW_POSSIZE_ALL ); SetPosSizePixel(const Point & rNewPos,const Size & rNewSize)107 void SetPosSizePixel( const Point& rNewPos, const Size& rNewSize ) 108 { Control::SetPosSizePixel( rNewPos, rNewSize ); } SetDropDownSizePixel(const Size & rNewSize)109 void SetDropDownSizePixel( const Size& rNewSize ) 110 { if( IsDropDownBox() ) SetPosSizePixel( 0, 0, rNewSize.Width(), rNewSize.Height(), WINDOW_POSSIZE_SIZE | WINDOW_POSSIZE_DROPDOWN ); } 111 112 Rectangle GetDropDownPosSizePixel() const; 113 114 void AdaptDropDownLineCountToMaximum(); 115 void SetDropDownLineCount( sal_uInt16 nLines ); 116 sal_uInt16 GetDropDownLineCount() const; 117 118 void EnableAutoSize( bool bAuto ); IsAutoSizeEnabled() const119 bool IsAutoSizeEnabled() const { return mbDDAutoSize; } 120 121 void EnableDDAutoWidth( sal_Bool b ); 122 sal_Bool IsDDAutoWidthEnabled() const; 123 124 virtual sal_uInt16 InsertEntry( const XubString& rStr, sal_uInt16 nPos = LISTBOX_APPEND ); 125 virtual sal_uInt16 InsertEntry( const Image& rImage, sal_uInt16 nPos = LISTBOX_APPEND ); 126 virtual sal_uInt16 InsertEntry( const XubString& rStr, const Image& rImage, sal_uInt16 nPos = LISTBOX_APPEND ); 127 virtual void RemoveEntry( const XubString& rStr ); 128 virtual void RemoveEntry( sal_uInt16 nPos ); 129 130 virtual void Clear(); 131 132 virtual sal_uInt16 GetEntryPos( const XubString& rStr ) const; 133 virtual sal_uInt16 GetEntryPos( const void* pData ) const; 134 Image GetEntryImage( sal_uInt16 nPos ) const; 135 virtual XubString GetEntry( sal_uInt16 nPos ) const; 136 virtual sal_uInt16 GetEntryCount() const; 137 138 virtual void SelectEntry( const XubString& rStr, sal_Bool bSelect = sal_True ); 139 virtual void SelectEntryPos( sal_uInt16 nPos, sal_Bool bSelect = sal_True ); 140 141 virtual sal_uInt16 GetSelectEntryCount() const; 142 virtual XubString GetSelectEntry( sal_uInt16 nSelIndex = 0 ) const; 143 virtual sal_uInt16 GetSelectEntryPos( sal_uInt16 nSelIndex = 0 ) const; 144 145 virtual sal_Bool IsEntrySelected( const XubString& rStr ) const; 146 virtual sal_Bool IsEntryPosSelected( sal_uInt16 nPos ) const; 147 virtual void SetNoSelection(); 148 149 void SetEntryData( sal_uInt16 nPos, void* pNewData ); 150 void* GetEntryData( sal_uInt16 nPos ) const; 151 152 /** this methods stores a combination of flags from the 153 LISTBOX_ENTRY_FLAG_* defines at the given entry. 154 See description of the possible LISTBOX_ENTRY_FLAG_* flags 155 for details. 156 Do not use these flags for user data as they are reserved 157 to change the internal behaviour of the ListBox implementation 158 for specific entries. 159 */ 160 void SetEntryFlags( sal_uInt16 nPos, long nFlags ); 161 162 /** this methods gets the current combination of flags from the 163 LISTBOX_ENTRY_FLAG_* defines from the given entry. 164 See description of the possible LISTBOX_ENTRY_FLAG_* flags 165 for details. 166 */ 167 long GetEntryFlags( sal_uInt16 nPos ) const; 168 169 void SetTopEntry( sal_uInt16 nPos ); 170 void ShowProminentEntry( sal_uInt16 nPos ); 171 void SetTopEntryStr( const XubString& rStr ); 172 sal_uInt16 GetTopEntry() const; 173 174 void SetProminentEntryType( ProminentEntry eType ); 175 ProminentEntry GetProminentEntryType() const; 176 SaveValue()177 void SaveValue() { mnSaveValue = GetSelectEntryPos(); } GetSavedValue() const178 sal_uInt16 GetSavedValue() const { return mnSaveValue; } 179 180 void SetSeparatorPos( sal_uInt16 n ); 181 void SetSeparatorPos(); 182 sal_uInt16 GetSeparatorPos() const; 183 184 sal_Bool IsTravelSelect() const; 185 sal_Bool IsInDropDown() const; 186 void ToggleDropDown(); 187 188 void EnableMultiSelection( sal_Bool bMulti, sal_Bool bStackSelection ); 189 void EnableMultiSelection( sal_Bool bMulti ); 190 sal_Bool IsMultiSelectionEnabled() const; 191 192 void SetReadOnly( sal_Bool bReadOnly = sal_True ); 193 sal_Bool IsReadOnly() const; 194 195 long CalcWindowSizePixel( sal_uInt16 nLines ) const; 196 Rectangle GetBoundingRectangle( sal_uInt16 nItem ) const; 197 198 void SetUserItemSize( const Size& rSz ); 199 const Size& GetUserItemSize() const; 200 201 void EnableUserDraw( sal_Bool bUserDraw ); 202 sal_Bool IsUserDrawEnabled() const; 203 204 void DrawEntry( const UserDrawEvent& rEvt, sal_Bool bDrawImage, sal_Bool bDrawText, sal_Bool bDrawTextAtImagePos = sal_False ); 205 SetSelectHdl(const Link & rLink)206 void SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; } GetSelectHdl() const207 const Link& GetSelectHdl() const { return maSelectHdl; } SetDoubleClickHdl(const Link & rLink)208 void SetDoubleClickHdl( const Link& rLink ) { maDoubleClickHdl = rLink; } GetDoubleClickHdl() const209 const Link& GetDoubleClickHdl() const { return maDoubleClickHdl; } 210 211 Size CalcMinimumSize() const; 212 virtual Size GetOptimalSize(WindowSizeType eType) const; 213 Size CalcAdjustedSize( const Size& rPrefSize ) const; 214 Size CalcSize( sal_uInt16 nColumns, sal_uInt16 nLines ) const; 215 void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const; 216 217 void SetMRUEntries( const XubString& rEntries, xub_Unicode cSep = ';' ); 218 XubString GetMRUEntries( xub_Unicode cSep = ';' ) const; 219 void SetMaxMRUCount( sal_uInt16 n ); 220 sal_uInt16 GetMaxMRUCount() const; 221 sal_uInt16 GetMRUCount() const; 222 sal_uInt16 GetDisplayLineCount() const; 223 224 void EnableMirroring(); 225 GetEdgeBlending() const226 bool GetEdgeBlending() const { return mbEdgeBlending; } 227 void SetEdgeBlending(bool bNew); 228 229 /** checks whether a certain point lies within the bounds of 230 a listbox item and returns the item as well as the character position 231 the point is at. 232 233 <p>If the point is inside an item the item pos is put into <code>rPos</code> and 234 the item-relative character index is returned. If the point is not inside 235 an item -1 is returned and rPos is unchanged.</p> 236 237 @param rPoint 238 tells the point for which an item is requested. 239 240 @param rPos 241 gets the item at the specified point <code>rPoint</code> 242 243 @returns 244 the item-relative character index at point <code>rPos</code> or -1 245 if no item is at that point. 246 */ 247 using Control::GetIndexForPoint; 248 long GetIndexForPoint( const Point& rPoint, sal_uInt16& rPos ) const; 249 }; 250 251 // ---------------- 252 // - MultiListBox - 253 // ---------------- 254 255 class VCL_DLLPUBLIC MultiListBox : public ListBox 256 { 257 public: 258 using ListBox::SaveValue; 259 using ListBox::GetSavedValue; 260 private: 261 // Bei MultiListBox nicht erlaubt... 262 void SaveValue(); 263 sal_uInt16 GetSavedValue(); 264 265 public: 266 explicit MultiListBox( Window* pParent, WinBits nStyle = 0 ); 267 explicit MultiListBox( Window* pParent, const ResId& ); 268 }; 269 270 #endif // _SV_LSTBOX_HXX 271 272