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 _VALUESET_HXX 25 #define _VALUESET_HXX 26 27 #include "svtools/svtdllapi.h" 28 29 #ifndef _CTRL_HXX 30 #include <vcl/ctrl.hxx> 31 #endif 32 #ifndef _VIRDEV_HXX 33 #include <vcl/virdev.hxx> 34 #endif 35 #include <vcl/timer.hxx> 36 37 class MouseEvent; 38 class TrackingEvent; 39 class HelpEvent; 40 class KeyEvent; 41 class DataChangedEvent; 42 class ScrollBar; 43 class ValueItemList; 44 struct ValueSetItem; 45 struct ValueSet_Impl; 46 #ifdef _SV_VALUESET_CXX 47 class ValueSetAcc; 48 class ValueItemAcc; 49 #endif 50 51 /************************************************************************* 52 53 Beschreibung 54 ============ 55 56 class ValueSet 57 58 Diese Klasse erlaubt die Auswahl eines Items. Dabei werden die Items 59 nebeneinander dargestellt. Die Auswahl der Items kann zum Beispiel bei 60 Farben oder Mustern uebersichtlicher sein, als in ListBox-Form. Es kann 61 angegeben werden, wieviele Spalten das Control anzeigen soll und ob die 62 Items umrandet werden sollen oder nicht. Optional kann auch ein 63 NoSelection-Feld oder ein Namenfeld angezeigt werden. An Items werden 64 standardmaessig Image, und Color unterstuetzt. Falls InsertItem() 65 nur mit einer ID aufgerufen wird, kann man die Items auch selber malen. 66 Dazu muss dann jedoch der UserDraw-Handler ueberlagert werden. Bei 67 UserDraw-Items, wie auch bei allen anderen Items kann der Beschreibungstext 68 auch hinterher gesetzt bzw. umgesetzt werden. 69 70 Querverweise 71 72 class ListBox 73 74 -------------------------------------------------------------------------- 75 76 WinBits 77 78 WB_RADIOSEL Wenn dieses Flag gesetzt wird, wird im ValueSet die 79 Selektion so gezeichnet, wie bei einem ImageRadioButton. 80 Dies ist jedoch nur sinnvoll, wenn die Images min. 8 Pixel 81 in horizontaler und vertikaler Richtung kleiner sind 82 als der Item-Bereich, WB_DOUBLEBORDER gesetzt ist und 83 als Color COL_WINDOWWORKSPACE gesetzt ist. 84 WB_FLATVALUESET Flat Look (if you set WB_ITEMBORDER or WB_DOUBLEBORDER, 85 then you get extra border space, but the Borders 86 aren't painted), 87 WB_ITEMBORDER Die Items werden umrandet 88 WB_DOUBLEBORDER Die Items werden doppelt umrandet. Zusaetzlich muss 89 WB_ITEMBORDER gesetzt werden, ansonsten hat dieses 90 WinBit keine Auswirkung. Gebraucht wird dies, wenn man 91 Items mit weissem Hintergrund hat, da sonst der 3D Effekt 92 nicht mehr sichtbar ist. 93 WB_NAMEFIELD Es gibt ein Namensfeld, wo der Name eines Items 94 mit angezeigt wird 95 WB_NONEFIELD Es gibt ein NoSelection-Feld. Dieses kann selektiert 96 werden, wenn bei SelectItem 0 uebergeben wird. Bei 97 GetSelectItemId() wird entsprechend 0 zurueckgegeben 98 wenn dieses Feld selektiert ist, bzw. keines selektiert 99 wurde. Dieses Feld zeigt den Text an, der mit SetText() 100 gesetzt wurde, bzw. keinen, wenn kein Text gesetzt 101 wurde. Mit SetNoSelection() kann die Selektion ganz 102 ausgeschaltet werden. 103 WB_VSCROLL Es wird immer ein ScrollBar angezeigt. Wenn dieses Flag 104 gesetzt wird, muss auch immer mit SetLineCount() die 105 sichtbare Anzahl der Zeilen eingestellt werden. 106 WB_BORDER Um das Fenster wird ein Border gezeichnet. 107 WB_NOPOINTERFOCUS Der Focus wird sich nicht geholt, wenn mit der Maus in 108 das Control geklickt wird. 109 WB_TABSTOP Mit der TabTaste kann in das ValueSet gesprungen werden. 110 WB_NOTABSTOP Mit der TabTaste kann nicht in das ValueSet gesprungen 111 werden. 112 WB_NO_DIRECTSELECT Cursor travelling doesn't call select immediately. To 113 execute the selection <RETURN> has to be pressed. 114 -------------------------------------------------------------------------- 115 116 Die Anzahl der Spalten muss entweder mit SetColCount() oder mit SetItemWidth() 117 eingestellt werden. Wenn mit SetColCount() die Anzahl der Spalten eingestellt 118 wird, wird die Breite der Items aus der sichtbaren Breite berechnet. Wenn 119 die Items eine feste Breite haben sollen, sollte die Breite der Items 120 mit SetItemWidth() eingestellt werden. Die Anzahl der Spalten wird 121 dann aus der sichtbaren Breite berechnet. 122 123 Die Anzahl der Zeilen ergibt sich durch Anzahl der Items / Anzahl der 124 Spalten. Die Anzahl der sichtbaren Zeilen muss entweder mit SetLineCount() 125 oder mit SetItemWidth() eingestellt werden. Wenn mit SetLineCount() die 126 Anzahl der sichtbaren Zeilen eingestellt wird, wird die Hoehe der Items 127 aus der sichtbaren Hoehe berechnet. Wenn die Items eine feste Hoehe haben 128 sollen, sollte die Hoehe der Items mit SetItemHeight() eingestellt werden. 129 Die Anzahl der sichtbaren Zeilen wird dann aus der sichtbaren Hoehe berechnet. 130 Wenn weder mit SetLineCount() noch mit SetItemHeight() die Anzahl der 131 sichtbaren Zeilen eingestellt wird, werden alle Zeilen dargestellt. Die 132 Hoehe der Items wird dann aus der sichtbaren Hoehe berechnet. Wenn mit 133 SetLineCount() oder mit SetItemHeight() die Anzahl der sichtbaren 134 Zeilen gesetzt wird, scrollt das ValueSet automatisch, wenn mehr Zeilen 135 vorhanden sind, als sichtbar sind. Wenn scrollen auch ueber einen 136 ScrollBar moeglich sein soll muss WB_VSCROLL gesetzt werden. 137 Mit SetFirstLine() kann die erste sichtbare Zeile eingestellt werden, wenn 138 mehr Zeilen vorhanden sind als sichtbar sind. 139 140 Mit SetExtraSpacing() kann der Abstand zwischen den Items vergroessert 141 werden. Der Abstand wird in Pixeln angegeben der zusaetzlich zwischen 2 Items 142 (sowohl in x wie auch in y) dargestellt werden soll. 143 144 Mit CalcWindowSizePixel() kann die genaue Fenstergroesse fuer eine bestimmte 145 Itemgroesse berechnet werden. Dazu muessen vorher aber alle relevanten 146 Daten (Spaltenanzahl/...) gesetzt werden und falls keine Zeilenanzahl 147 eingestellt wird, muessen auch alle Items eingefuegt werden. Falls das 148 Window mit WB_BORDER/Border=sal_True erzeugt wurde, muss die Groesse mit 149 SetOutputSizePixel() gesetzt werden, im anderen Fall koennen auch die 150 anderen Groessen-Methoden benutzt werden. Mit CalcItemSize() laesst sich 151 die innere und aeussere Groesse eines Items berechnen (dabei wird der 152 optional mit SetExtraSpacing() eingestellte Freiraum nicht mit eingerechnet). 153 154 Mit SetColor() kann die Hintergrundfarbe eingestellt werden, mit der Image 155 oder UserDraw-Items hinterlegt werden. Wenn keine Farbe eingestellt wird, 156 wird der Hintergrund in der gleichen Farbe hinterlegt wie andere 157 Fenster (WindowColor). 158 159 Mit InsertSpace() kann man ein leeres Feld einfuegen, welches weder 160 dargestellt noch selektierbar ist. 161 162 -------------------------------------------------------------------------- 163 164 Da die Ausgabeflaeche vorberechnet wird, sollten erst alle Items eingefuegt 165 werden und dann erst Show() aufgerufen werden. Wenn dies nicht gemacht wird, 166 erscheint das erste Paint etwas langsamer. Deshalb sollte, wenn dieses 167 Control aus der Resource geladen wird und das Control erst im Programm 168 mit Items versorgt wird, mit Hide = sal_True geladen werden und im Programm 169 dann mit Show() angezeigt werden. 170 171 Bei einem sichbaren Control kann die Erzeugung der neuen Ausgabeflaeche 172 vor dem Paint aktiviert werden, indem Format() aufgerufen wird. 173 174 -------------------------------------------------------------------------- 175 176 Wenn man ein Drag and Drop aus dem ValueSet heraus starten will, muss 177 der Command-Handler ueberlagert werden. Aus diesem muss dann StartDrag 178 aufgerufen werden. Wenn diese Methode sal_True zurueckliefert, kann mit 179 ExecuteDrag() der Drag-Vorgang gestartet werden, ansonsten sollte keine 180 Verarbeitung stattfinden. Diese Methode sorgt dafuer, das das ValueSet 181 seine Verarbeitung abbricht und gegebenenfalls den Eintrag selektiert. Es 182 muss daher damit gerechnet werden, das innerhalb dieser Funktion der 183 Select-Handler gerufen werden kann. 184 185 Fuer das Droppen muss man QueryDrop() und Drop() ueberlagern und sollte 186 in diesen Methoden ShowDropPos() und HideDropPos() aufrufen. Im QueryDrop- 187 Handler ruft man ShowDropPos() auf, um die Einfuegeposition anzuzeigen. 188 ShowDropPos() scollt auch gegebenenfalls das ValueSet, wenn die ueber- 189 gebene Position sich am Fensterrand befindet. Ausserdem liefert 190 ShowDropPos() die Position zurueck, an der das Item dann eingefuegt werden 191 soll, bzw. welche Einfuegeposition angezeigt wurde. Falls keine Einfuege- 192 Position ermittelt werden kann, wird VALUESET_ITEM_NOTFOUND zurueckgegeben. 193 Wenn beim Draggen das Fenster verlassen wird oder der Dragvorgang beendet 194 wird, sollte in jedem Fall HideDropPos() gerufen werden. 195 196 -------------------------------------------------------------------------- 197 198 Mit SetItemBits() koennen Flags an einem Item gesetzt werden. Folgende 199 Flags sind zur Zeit vorgesehen: 200 201 VIB_NODOUBLECLICK Jeder Klick fuehrt zu einer Select-Aktion. Der 202 Doppelklick-Handler wird in diesem Fall nie 203 gerufen. 204 205 -------------------------------------------------------------------------- 206 207 Diese Klasse befindet sich zur Zeit noch in den SV-Tools. Deshalb muss das 208 ValueSet zur Zeit als Control aus der Resource geladen werden und die 209 gewuenschten WinBits (vor Show) mit SetStyle() gesetzt werden. 210 211 *************************************************************************/ 212 213 // ----------------------- 214 // - ValueSet-Item-Typen - 215 // ----------------------- 216 217 #define VIB_NODOUBLECLICK ((sal_uInt16)0x0080) 218 219 // ------------------ 220 // - ValueSet-Typen - 221 // ------------------ 222 223 #define WB_RADIOSEL ((WinBits)0x00008000) 224 #define WB_ITEMBORDER ((WinBits)0x00010000) 225 #define WB_DOUBLEBORDER ((WinBits)0x00020000) 226 #define WB_NAMEFIELD ((WinBits)0x00040000) 227 #define WB_NONEFIELD ((WinBits)0x00080000) 228 #define WB_FLATVALUESET ((WinBits)0x02000000) 229 #define WB_NO_DIRECTSELECT ((WinBits)0x04000000) 230 #define WB_MENUSTYLEVALUESET ((WinBits)0x08000000) 231 232 // ------------ 233 // - ValueSet - 234 // ------------ 235 236 #define VALUESET_APPEND ((sal_uInt16)0xFFFF) 237 #define VALUESET_ITEM_NOTFOUND ((sal_uInt16)0xFFFF) 238 239 class SVT_DLLPUBLIC ValueSet : public Control 240 { 241 private: 242 243 VirtualDevice maVirDev; 244 Timer maTimer; 245 ValueSet_Impl* mpImpl; 246 ValueSetItem* mpNoneItem; 247 ScrollBar* mpScrBar; 248 long mnTextOffset; 249 long mnVisLines; 250 long mnLines; 251 long mnUserItemWidth; 252 long mnUserItemHeight; 253 sal_uInt16 mnOldItemId; 254 sal_uInt16 mnSelItemId; 255 sal_uInt16 mnHighItemId; 256 sal_uInt16 mnDropPos; 257 sal_uInt16 mnCols; 258 sal_uInt16 mnCurCol; 259 sal_uInt16 mnUserCols; 260 sal_uInt16 mnUserVisLines; 261 sal_uInt16 mnFirstLine; 262 sal_uInt16 mnSpacing; 263 sal_uInt16 mnFrameStyle; 264 Color maColor; 265 Link maDoubleClickHdl; 266 Link maSelectHdl; 267 268 // bitfield 269 bool mbFormat : 1; 270 bool mbHighlight : 1; 271 bool mbSelection : 1; 272 bool mbNoSelection : 1; 273 bool mbDrawSelection : 1; 274 bool mbBlackSel : 1; 275 bool mbDoubleSel : 1; 276 bool mbScroll : 1; 277 bool mbDropPos : 1; 278 bool mbFullMode : 1; 279 bool mbEdgeBlending : 1; 280 281 #ifdef _SV_VALUESET_CXX 282 friend class ValueSetAcc; 283 friend class ValueItemAcc; 284 using Control::ImplInitSettings; 285 using Window::ImplInit; 286 SVT_DLLPRIVATE void ImplInit(); 287 SVT_DLLPRIVATE void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground ); 288 SVT_DLLPRIVATE void ImplInitScrollBar(); 289 SVT_DLLPRIVATE void ImplDeleteItems(); 290 SVT_DLLPRIVATE void ImplFormatItem( ValueSetItem* pItem ); 291 SVT_DLLPRIVATE void ImplDrawItemText( const XubString& rStr ); 292 SVT_DLLPRIVATE void ImplDrawSelect(); 293 SVT_DLLPRIVATE void ImplHideSelect( sal_uInt16 nItemId ); 294 SVT_DLLPRIVATE void ImplHighlightItem( sal_uInt16 nItemId, sal_Bool bIsSelection = sal_True ); 295 SVT_DLLPRIVATE void ImplDrawDropPos( sal_Bool bShow ); 296 SVT_DLLPRIVATE void ImplDraw(); 297 using Window::ImplScroll; 298 SVT_DLLPRIVATE sal_Bool ImplScroll( const Point& rPos ); 299 SVT_DLLPRIVATE sal_uInt16 ImplGetItem( const Point& rPoint, sal_Bool bMove = sal_False ) const; 300 SVT_DLLPRIVATE ValueSetItem* ImplGetItem( sal_uInt16 nPos ); 301 SVT_DLLPRIVATE ValueSetItem* ImplGetFirstItem(); 302 SVT_DLLPRIVATE sal_uInt16 ImplGetVisibleItemCount() const; 303 SVT_DLLPRIVATE ValueSetItem* ImplGetVisibleItem( sal_uInt16 nVisiblePos ); 304 SVT_DLLPRIVATE void ImplFireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue ); 305 SVT_DLLPRIVATE sal_Bool ImplHasAccessibleListeners(); 306 SVT_DLLPRIVATE void ImplTracking( const Point& rPos, sal_Bool bRepeat ); 307 SVT_DLLPRIVATE void ImplEndTracking( const Point& rPos, sal_Bool bCancel ); 308 DECL_DLLPRIVATE_LINK( ImplScrollHdl, ScrollBar* ); 309 DECL_DLLPRIVATE_LINK( ImplTimerHdl, Timer* ); 310 #endif 311 312 // Forbidden and not implemented. 313 ValueSet (const ValueSet &); 314 ValueSet & operator= (const ValueSet &); 315 316 protected: 317 318 sal_Bool StartDrag( const CommandEvent& rCEvt, Region& rRegion ); 319 sal_uInt16 ShowDropPos( const Point& rPos ); 320 void HideDropPos(); 321 322 protected: 323 324 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible(); 325 326 public: 327 ValueSet( Window* pParent, WinBits nWinStyle = WB_ITEMBORDER, bool bDisableTransientChildren = false ); 328 ValueSet( Window* pParent, const ResId& rResId, bool bDisableTransientChildren = false ); 329 ~ValueSet(); 330 331 virtual void MouseButtonDown( const MouseEvent& rMEvt ); 332 virtual void MouseButtonUp( const MouseEvent& rMEvt ); 333 virtual void MouseMove( const MouseEvent& rMEvt ); 334 virtual void Tracking( const TrackingEvent& rMEvt ); 335 virtual void KeyInput( const KeyEvent& rKEvt ); 336 virtual void Command( const CommandEvent& rCEvt ); 337 virtual void Paint( const Rectangle& rRect ); 338 virtual void GetFocus(); 339 virtual void LoseFocus(); 340 virtual void Resize(); 341 virtual void RequestHelp( const HelpEvent& rHEvt ); 342 virtual void StateChanged( StateChangedType nStateChange ); 343 virtual void DataChanged( const DataChangedEvent& rDCEvt ); 344 345 virtual void Select(); 346 virtual void DoubleClick(); 347 virtual void UserDraw( const UserDrawEvent& rUDEvt ); 348 349 void InsertItem( sal_uInt16 nItemId, const Image& rImage, 350 sal_uInt16 nPos = VALUESET_APPEND ); 351 void InsertItem( sal_uInt16 nItemId, const Color& rColor, 352 sal_uInt16 nPos = VALUESET_APPEND ); 353 void InsertItem( sal_uInt16 nItemId, 354 const Image& rImage, const XubString& rStr, 355 sal_uInt16 nPos = VALUESET_APPEND ); 356 void InsertItem( sal_uInt16 nItemId, 357 const Color& rColor, const XubString& rStr, 358 sal_uInt16 nPos = VALUESET_APPEND ); 359 void InsertItem( sal_uInt16 nItemId, 360 sal_uInt16 nPos = VALUESET_APPEND ); 361 // IA2 implementation in 2009 - method to set accessible when the style is user draw. 362 void InsertItem( sal_uInt16 nItemId, const XubString& rStr, sal_uInt16 nPos = VALUESET_APPEND ); 363 364 void InsertSpace( sal_uInt16 nItemId, 365 sal_uInt16 nPos = VALUESET_APPEND ); 366 void RemoveItem( sal_uInt16 nItemId ); 367 368 void CopyItems( const ValueSet& rValueSet ); 369 void Clear(); 370 371 sal_uInt16 GetItemCount() const; 372 sal_uInt16 GetItemPos( sal_uInt16 nItemId ) const; 373 sal_uInt16 GetItemId( sal_uInt16 nPos ) const; 374 sal_uInt16 GetItemId( const Point& rPos ) const; 375 Rectangle GetItemRect( sal_uInt16 nItemId ) const; 376 377 void EnableFullItemMode( bool bFullMode = true ); IsFullItemModeEnabled() const378 bool IsFullItemModeEnabled() const { return mbFullMode; } 379 void SetColCount( sal_uInt16 nNewCols = 1 ); GetColCount() const380 sal_uInt16 GetColCount() const { return mnUserCols; } 381 void SetLineCount( sal_uInt16 nNewLines = 0 ); GetLineCount() const382 sal_uInt16 GetLineCount() const { return mnUserVisLines; } 383 void SetItemWidth( long nItemWidth = 0 ); GetItemWidth() const384 long GetItemWidth() const { return mnUserItemWidth; } 385 void SetItemHeight( long nLineHeight = 0 ); GetItemHeight() const386 long GetItemHeight() const { return mnUserItemHeight; } 387 void SetFirstLine( sal_uInt16 nNewLine = 0 ); GetFirstLine() const388 sal_uInt16 GetFirstLine() const { return mnFirstLine; } 389 390 void SelectItem( sal_uInt16 nItemId ); GetSelectItemId() const391 sal_uInt16 GetSelectItemId() const { return mnSelItemId; } IsItemSelected(sal_uInt16 nItemId) const392 bool IsItemSelected( sal_uInt16 nItemId ) const 393 { return (!mbNoSelection && (nItemId == mnSelItemId)); } 394 void SetNoSelection(); IsNoSelection() const395 bool IsNoSelection() const { return mbNoSelection; } 396 397 void SetItemBits( sal_uInt16 nItemId, sal_uInt16 nBits ); 398 sal_uInt16 GetItemBits( sal_uInt16 nItemId ) const; 399 void SetItemImage( sal_uInt16 nItemId, const Image& rImage ); 400 Image GetItemImage( sal_uInt16 nItemId ) const; 401 void SetItemColor( sal_uInt16 nItemId, const Color& rColor ); 402 Color GetItemColor( sal_uInt16 nItemId ) const; 403 void SetItemData( sal_uInt16 nItemId, void* pData ); 404 void* GetItemData( sal_uInt16 nItemId ) const; 405 void SetItemText( sal_uInt16 nItemId, const XubString& rStr ); 406 XubString GetItemText( sal_uInt16 nItemId ) const; 407 void SetColor( const Color& rColor ); SetColor()408 void SetColor() { SetColor( Color( COL_TRANSPARENT ) ); } GetColor() const409 Color GetColor() const { return maColor; } IsColor() const410 bool IsColor() const { return maColor.GetTransparency() == 0; } 411 412 void SetExtraSpacing( sal_uInt16 nNewSpacing ); GetExtraSpacing()413 sal_uInt16 GetExtraSpacing() { return mnSpacing; } 414 415 void Format(); 416 417 void StartSelection(); 418 void EndSelection(); 419 420 Size CalcWindowSizePixel( const Size& rItemSize, 421 sal_uInt16 nCalcCols = 0, 422 sal_uInt16 nCalcLines = 0 ); 423 Size CalcItemSizePixel( const Size& rSize, bool bOut = true ) const; 424 long GetScrollWidth() const; 425 SetSelectHdl(const Link & rLink)426 void SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; } GetSelectHdl() const427 const Link& GetSelectHdl() const { return maSelectHdl; } SetDoubleClickHdl(const Link & rLink)428 void SetDoubleClickHdl( const Link& rLink ) { maDoubleClickHdl = rLink; } GetDoubleClickHdl() const429 const Link& GetDoubleClickHdl() const { return maDoubleClickHdl; } 430 431 void SetHighlightHdl( const Link& rLink ); 432 const Link& GetHighlightHdl() const; 433 GetEdgeBlending() const434 bool GetEdgeBlending() const { return mbEdgeBlending; } 435 void SetEdgeBlending(bool bNew); 436 437 private: 438 /** Determine whether RTL (right to left writing) is active. For this 439 method to return <true/> two conditions have to be fulfilled: 440 <ol><li>RTL is active for the whole application.</li> 441 <li>RTL is enabled for the control.</li></ol> 442 @return 443 The method returns <true/> when RTL is active for the control 444 and <false/> when RTL is not active. Note then just enabling 445 RTL for the control is not enough. 446 */ 447 SVT_DLLPRIVATE bool IsRTLActive (void); 448 }; 449 450 #endif // _VALUESET_HXX 451