1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #pragma once 21 22 #if !defined(VCL_DLLIMPLEMENTATION) && !defined(TOOLKIT_DLLIMPLEMENTATION) && !defined(VCL_INTERNALS) 23 #error "don't use this in new code" 24 #endif 25 26 #include <memory> 27 #include <vcl/dllapi.h> 28 #include <vcl/ctrl.hxx> 29 #include <tools/link.hxx> 30 #include <vcl/image.hxx> 31 #include <o3tl/deleter.hxx> 32 #include <o3tl/typed_flags_set.hxx> 33 34 class SvxIconChoiceCtrl_Impl; 35 36 enum class SvxIconViewFlags 37 { 38 NONE = 0x0000, 39 POS_LOCKED = 0x0001, 40 SELECTED = 0x0002, 41 FOCUSED = 0x0004, 42 POS_MOVED = 0x0008, // Moved by Drag and Drop, but not logged 43 }; 44 namespace o3tl 45 { 46 template<> struct typed_flags<SvxIconViewFlags> : is_typed_flags<SvxIconViewFlags, 0x000f> {}; 47 } 48 49 enum class SvxIconChoiceCtrlTextMode 50 { 51 Full = 1, // Enlarge BoundRect southwards 52 Short // Shorten with "..." 53 }; 54 55 enum class SvxIconChoiceCtrlPositionMode 56 { 57 Free, // Free pixel-perfect positioning 58 AutoArrange, // Auto arrange 59 }; 60 61 class SvxIconChoiceCtrlEntry 62 { 63 Image aImage; 64 65 OUString aText; 66 OUString aQuickHelpText; 67 68 friend class SvxIconChoiceCtrl_Impl; 69 friend class IcnCursor_Impl; 70 friend class EntryList_Impl; 71 friend class IcnGridMap_Impl; 72 73 tools::Rectangle aRect; // Bounding-Rectangle of the entry 74 tools::Rectangle aGridRect; // Only valid in Grid-mode 75 sal_Int32 nPos; 76 77 /* 78 The insert position in the Insertlist is equal to the (sort) order stated at the Insert 79 (-> Order of the anchors in the anchors-list!). In "AutoArrange" mode the visible order 80 can differ. The entries will be linked because of this. 81 */ 82 SvxIconChoiceCtrlEntry* pblink; // backward (linker neighbour) 83 SvxIconChoiceCtrlEntry* pflink; // forward (rechter neighbour) 84 85 SvxIconChoiceCtrlTextMode eTextMode; 86 sal_uInt16 nX,nY; // for keyboard control 87 SvxIconViewFlags nFlags; 88 ClearFlags(SvxIconViewFlags nMask)89 void ClearFlags( SvxIconViewFlags nMask ) { nFlags &= ~nMask; } SetFlags(SvxIconViewFlags nMask)90 void SetFlags( SvxIconViewFlags nMask ) { nFlags |= nMask; } AssignFlags(SvxIconViewFlags _nFlags)91 void AssignFlags( SvxIconViewFlags _nFlags ) { nFlags = _nFlags; } 92 93 // set left neighbour (A <-> B ==> A <-> this <-> B) SetBacklink(SvxIconChoiceCtrlEntry * pA)94 void SetBacklink( SvxIconChoiceCtrlEntry* pA ) 95 { 96 pA->pflink->pblink = this; // X <- B 97 this->pflink = pA->pflink; // X -> B 98 this->pblink = pA; // A <- X 99 pA->pflink = this; // A -> X 100 } 101 // Unlink (A <-> this <-> B ==> A <-> B) Unlink()102 void Unlink() 103 { 104 this->pblink->pflink = this->pflink; 105 this->pflink->pblink = this->pblink; 106 this->pflink = nullptr; 107 this->pblink = nullptr; 108 } 109 110 public: 111 SvxIconChoiceCtrlEntry( const OUString& rText, const Image& rImage ); 112 GetImage() const113 const Image& GetImage () const { return aImage; } SetText(const OUString & rText)114 void SetText ( const OUString& rText ) { aText = rText; } GetText() const115 const OUString& GetText () const { return aText; } 116 OUString VCL_DLLPUBLIC GetDisplayText() const; SetQuickHelpText(const OUString & rText)117 void SetQuickHelpText( const OUString& rText ) { aQuickHelpText = rText; } GetQuickHelpText() const118 const OUString& GetQuickHelpText() const { return aQuickHelpText; } 119 GetTextMode() const120 SvxIconChoiceCtrlTextMode GetTextMode() const { return eTextMode; } GetFlags() const121 SvxIconViewFlags GetFlags() const { return nFlags; } IsSelected() const122 bool IsSelected() const { return bool(nFlags & SvxIconViewFlags::SELECTED); } IsFocused() const123 bool IsFocused() const { return bool(nFlags & SvxIconViewFlags::FOCUSED); } IsPosLocked() const124 bool IsPosLocked() const { return bool(nFlags & SvxIconViewFlags::POS_LOCKED); } 125 }; 126 127 class SvxIconChoiceCtrlColumnInfo 128 { 129 tools::Long nWidth; 130 131 public: SvxIconChoiceCtrlColumnInfo()132 SvxIconChoiceCtrlColumnInfo() : 133 nWidth( 100 ) {} 134 SvxIconChoiceCtrlColumnInfo( const SvxIconChoiceCtrlColumnInfo& ); 135 SetWidth(tools::Long nWd)136 void SetWidth( tools::Long nWd ) { nWidth = nWd; } GetWidth() const137 tools::Long GetWidth() const { return nWidth; } 138 }; 139 140 141 /* 142 Window-Bits: 143 WB_ICON // Text beneath the icon 144 WB_SMALL_ICON // Text right to the icon, position does not mind 145 WB_DETAILS // Text right to the icon, limited positioning 146 WB_BORDER 147 WB_NOHIDESELECTION // Draw selection inactively, if not focused. 148 WB_NOHSCROLL 149 WB_NOVSCROLL 150 WB_NOSELECTION 151 WB_SMART_ARRANGE // Keep Visible-Area at arrange 152 WB_ALIGN_TOP // Align line vy line LTR 153 WB_ALIGN_LEFT // Align columns from top to bottom 154 WB_NODRAGSELECTION // No selection with tracking rectangle 155 WB_NOCOLUMNHEADER // No Headerbar in Details view (Headerbar not implemented) 156 WB_NOPOINTERFOCUS // No GrabFocus at MouseButtonDown 157 WB_HIGHLIGHTFRAME // The entry beneath the mouse will be highlighted 158 WB_NOASYNCSELECTHDL // Do not collect events -> Selection handlers will be called synchronously 159 */ 160 161 #define WB_ICON WB_RECTSTYLE 162 #define WB_SMALLICON WB_SMALLSTYLE 163 #define WB_DETAILS WB_VCENTER 164 #define WB_NOHSCROLL WB_SPIN 165 #define WB_NOVSCROLL WB_DRAG 166 #define WB_NOSELECTION WB_REPEAT 167 #define WB_NODRAGSELECTION WB_PATHELLIPSIS 168 #define WB_SMART_ARRANGE 0x01000000 // used to be WB_PASSWORD 169 #define WB_ALIGN_TOP WB_TOP 170 #define WB_ALIGN_LEFT WB_LEFT 171 #define WB_NOCOLUMNHEADER WB_CENTER 172 #define WB_HIGHLIGHTFRAME WB_IGNORETAB 173 #define WB_NOASYNCSELECTHDL WB_NOLABEL 174 175 class MnemonicGenerator; 176 177 class VCL_DLLPUBLIC SvtIconChoiceCtrl : public Control 178 { 179 friend class SvxIconChoiceCtrl_Impl; 180 181 Link<SvtIconChoiceCtrl*,void> _aClickIconHdl; 182 std::unique_ptr<SvxIconChoiceCtrl_Impl, o3tl::default_delete<SvxIconChoiceCtrl_Impl>> _pImpl; 183 184 protected: 185 186 virtual void KeyInput( const KeyEvent& rKEvt ) override; 187 virtual void Command( const CommandEvent& rCEvt ) override; 188 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; 189 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; 190 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; 191 virtual void MouseMove( const MouseEvent& rMEvt ) override; 192 virtual void Resize() override; 193 virtual void GetFocus() override; 194 virtual void LoseFocus() override; 195 void ClickIcon(); 196 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; 197 virtual void RequestHelp( const HelpEvent& rHEvt ) override; 198 static void DrawEntryImage( 199 SvxIconChoiceCtrlEntry const * pEntry, 200 const Point& rPos, 201 OutputDevice& rDev ); 202 203 static OUString GetEntryText( SvxIconChoiceCtrlEntry const * pEntry ); 204 205 virtual void FillLayoutData() const override; 206 207 void CallImplEventListeners(VclEventId nEvent, void* pData); 208 209 public: 210 211 SvtIconChoiceCtrl( vcl::Window* pParent, WinBits nWinStyle ); 212 virtual ~SvtIconChoiceCtrl() override; 213 virtual void dispose() override; 214 215 WinBits GetStyle() const; 216 void SetSelectionMode(SelectionMode eMode); 217 218 void SetFont( const vcl::Font& rFont ); 219 void SetPointFont( const vcl::Font& rFont ); 220 SetClickHdl(const Link<SvtIconChoiceCtrl *,void> & rLink)221 void SetClickHdl( const Link<SvtIconChoiceCtrl*,void>& rLink ) { _aClickIconHdl = rLink; } 222 223 using Window::SetBackground; 224 void SetBackground( const Wallpaper& rWallpaper ); 225 226 void ArrangeIcons(); 227 228 229 SvxIconChoiceCtrlEntry* InsertEntry( const OUString& rText, 230 const Image& rImage); 231 232 void RemoveEntry(sal_Int32 nEntryListPos); 233 234 bool DoKeyInput( const KeyEvent& rKEvt ); 235 236 sal_Int32 GetEntryCount() const; 237 SvxIconChoiceCtrlEntry* GetEntry( sal_Int32 nPos ) const; 238 sal_Int32 GetEntryListPos( SvxIconChoiceCtrlEntry const * pEntry ) const; 239 using Window::SetCursor; 240 void SetCursor( SvxIconChoiceCtrlEntry* pEntry ); 241 SvxIconChoiceCtrlEntry* GetCursor() const; 242 243 // sal_uLong is the position of the selected element in the list 244 SvxIconChoiceCtrlEntry* GetSelectedEntry() const; 245 246 #ifdef DBG_UTIL 247 void SetEntryTextMode( SvxIconChoiceCtrlTextMode eMode, SvxIconChoiceCtrlEntry* pEntry ); 248 #endif 249 250 tools::Rectangle GetBoundingBox( SvxIconChoiceCtrlEntry* pEntry ) const; 251 tools::Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const; 252 253 void SetNoSelection(); 254 255 // ACCESSIBILITY ========================================================== 256 257 /** Creates and returns the accessible object of the Box. */ 258 virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override; 259 }; 260 261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 262