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 _EXTENSIONS_PROPCTRLR_BROWSERLISTBOX_HXX_ 25 #define _EXTENSIONS_PROPCTRLR_BROWSERLISTBOX_HXX_ 26 27 #include "browserline.hxx" 28 #ifndef _EXTENSIONS_PROPCTRLR_MODULEPRC_HXX_ 29 #include "modulepcr.hxx" 30 #endif 31 #include "pcrcommon.hxx" 32 33 /** === begin UNO includes === **/ 34 #include <com/sun/star/inspection/XPropertyControl.hpp> 35 #include <com/sun/star/inspection/XPropertyHandler.hpp> 36 /** === end UNO includes === **/ 37 #include <vcl/scrbar.hxx> 38 #include <vcl/lstbox.hxx> 39 #ifndef _SV_BUTTON_HXX 40 #include <vcl/button.hxx> 41 #endif 42 #include <tools/link.hxx> 43 #include <rtl/ref.hxx> 44 45 #include <set> 46 #include <vector> 47 #include <hash_map> 48 #include <boost/shared_ptr.hpp> 49 50 //............................................................................ 51 namespace pcr 52 { 53 //............................................................................ 54 55 class IPropertyLineListener; 56 class IPropertyControlObserver; 57 struct OLineDescriptor; 58 class InspectorHelpWindow; 59 class PropertyControlContext_Impl; 60 61 //======================================================================== 62 //= administrative structures for OBrowserListBox 63 //======================================================================== 64 typedef ::boost::shared_ptr< OBrowserLine > BrowserLinePointer; 65 struct ListBoxLine 66 { 67 BrowserLinePointer pLine; 68 ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler > 69 xHandler; 70 ListBoxLinepcr::ListBoxLine71 ListBoxLine() { } ListBoxLinepcr::ListBoxLine72 ListBoxLine( BrowserLinePointer _pLine, const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyHandler >& _rxHandler ) 73 :pLine( _pLine ) 74 ,xHandler( _rxHandler ) 75 { 76 } 77 }; 78 typedef ::std::hash_map< ::rtl::OUString, ListBoxLine, ::rtl::OUStringHash > ListBoxLines; 79 typedef ::std::vector< ListBoxLines::iterator > OrderedListBoxLines; 80 81 //======================================================================== 82 //= IControlContext 83 //======================================================================== 84 /** non-UNO version of XPropertyControlContext 85 */ 86 class SAL_NO_VTABLE IControlContext 87 { 88 public: 89 virtual void SAL_CALL focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& Control ) throw (::com::sun::star::uno::RuntimeException) = 0; 90 virtual void SAL_CALL valueChanged( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& Control ) throw (::com::sun::star::uno::RuntimeException) = 0; 91 virtual void SAL_CALL activateNextControl( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& CurrentControl ) throw (::com::sun::star::uno::RuntimeException) = 0; 92 }; 93 94 //======================================================================== 95 //= OBrowserListBox 96 //======================================================================== 97 class OBrowserListBox :public Control 98 ,public IButtonClickListener 99 ,public IControlContext 100 ,public PcrClient 101 { 102 protected: 103 Window m_aLinesPlayground; 104 ScrollBar m_aVScroll; 105 ::std::auto_ptr< InspectorHelpWindow > 106 m_pHelpWindow; 107 ListBoxLines m_aLines; 108 OrderedListBoxLines m_aOrderedLines; 109 IPropertyLineListener* m_pLineListener; 110 IPropertyControlObserver* m_pControlObserver; 111 long m_nYOffset; 112 long m_nCurrentPreferredHelpHeight; 113 ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl > 114 m_xActiveControl; 115 sal_uInt16 m_nTheNameSize; 116 sal_uInt16 m_nRowHeight; 117 ::std::set< sal_uInt16 > m_aOutOfDateLines; 118 sal_Bool m_bIsActive : 1; 119 sal_Bool m_bUpdate : 1; 120 ::rtl::Reference< PropertyControlContext_Impl > 121 m_pControlContextImpl; 122 123 protected: 124 void PositionLine( sal_uInt16 _nIndex ); 125 void UpdatePosNSize(); 126 void UpdatePlayGround(); 127 void UpdateVScroll(); 128 void ShowEntry(sal_uInt16 nPos); 129 void MoveThumbTo(sal_Int32 nNewThumbPos); 130 void Resize(); 131 132 public: 133 OBrowserListBox( Window* pParent, WinBits nWinStyle = WB_DIALOGCONTROL ); 134 135 ~OBrowserListBox(); 136 137 void UpdateAll(); 138 139 void ActivateListBox( sal_Bool _bActive ); 140 141 sal_uInt16 CalcVisibleLines(); 142 void EnableUpdate(); 143 void DisableUpdate(); 144 long Notify( NotifyEvent& _rNEvt ); 145 long PreNotify( NotifyEvent& _rNEvt ); 146 147 void SetListener( IPropertyLineListener* _pListener ); 148 void SetObserver( IPropertyControlObserver* _pObserver ); 149 150 void EnableHelpSection( bool _bEnable ); 151 bool HasHelpSection() const; 152 void SetHelpText( const ::rtl::OUString& _rHelpText ); 153 void SetHelpLineLimites( sal_Int32 _nMinLines, sal_Int32 _nMaxLines ); 154 155 void Clear(); 156 157 sal_uInt16 InsertEntry( const OLineDescriptor&, sal_uInt16 nPos = EDITOR_LIST_APPEND ); 158 sal_Bool RemoveEntry( const ::rtl::OUString& _rName ); 159 void ChangeEntry( const OLineDescriptor&, sal_uInt16 nPos ); 160 161 void SetPropertyValue( const ::rtl::OUString& rEntryName, const ::com::sun::star::uno::Any& rValue, bool _bUnknownValue ); 162 sal_uInt16 GetPropertyPos( const ::rtl::OUString& rEntryName ) const; 163 ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl > 164 GetPropertyControl( const ::rtl::OUString& rEntryName ); 165 void EnablePropertyControls( const ::rtl::OUString& _rEntryName, sal_Int16 _nControls, bool _bEnable ); 166 void EnablePropertyLine( const ::rtl::OUString& _rEntryName, bool _bEnable ); 167 168 sal_Int32 GetMinimumWidth(); 169 sal_Int32 GetMinimumHeight(); 170 171 172 sal_Bool IsModified( ) const; 173 void CommitModified( ); 174 175 protected: 176 // IControlContext 177 virtual void SAL_CALL focusGained( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& Control ) throw (::com::sun::star::uno::RuntimeException); 178 virtual void SAL_CALL valueChanged( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& Control ) throw (::com::sun::star::uno::RuntimeException); 179 virtual void SAL_CALL activateNextControl( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& CurrentControl ) throw (::com::sun::star::uno::RuntimeException); 180 181 // IButtonClickListener 182 void buttonClicked( OBrowserLine* _pLine, sal_Bool _bPrimary ); 183 184 using Window::SetHelpText; 185 private: 186 DECL_LINK( ScrollHdl, ScrollBar* ); 187 188 /** retrieves the index of a given control in our line list 189 @param _rxControl 190 The control to lookup. Must denote a control of one of the lines in ->m_aLines 191 */ 192 sal_uInt16 impl_getControlPos( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _rxControl ) const; 193 194 /** retrieves (a reference to) the ->ListBoxLine for a given control 195 @param _rxControl 196 The control to lookup. Must denote a control of one of the lines in ->m_aLines 197 */ 198 inline const ListBoxLine& impl_getControlLine(const::com::sun::star::uno::Reference<::com::sun::star::inspection::XPropertyControl> & _rxControl) const199 impl_getControlLine( const ::com::sun::star::uno::Reference< ::com::sun::star::inspection::XPropertyControl >& _rxControl ) const 200 { 201 return m_aOrderedLines[ impl_getControlPos( _rxControl ) ]->second; 202 } 203 204 /** sets the given property value at the given control, after converting it as necessary 205 @param _rLine 206 The line whose at which the value is to be set. 207 @param _rPropertyValue 208 the property value to set. If it's not compatible with the control value, 209 it will be converted, using <member>XPropertyHandler::convertToControlValue</member> 210 */ 211 void impl_setControlAsPropertyValue( const ListBoxLine& _rLine, const ::com::sun::star::uno::Any& _rPropertyValue ); 212 213 /** retrieves the value for the given control, as a property value, after converting it as necessary 214 @param _rLine 215 The line whose at which the value is to be set. 216 */ 217 ::com::sun::star::uno::Any 218 impl_getControlAsPropertyValue( const ListBoxLine& _rLine ) const; 219 220 /** retrieves the ->BrowserLinePointer for a given entry name 221 @param _rEntryName 222 the name whose line is to be looked up 223 @param _out_rpLine 224 contains, upon return, the found browser line, if any 225 @return 226 <TRUE/> if and only if a non-<NULL/> line for the given entry name could be 227 found. 228 */ 229 bool impl_getBrowserLineForName( const ::rtl::OUString& _rEntryName, BrowserLinePointer& _out_rpLine ) const; 230 231 /** returns the preferred height (in pixels) of the help section, or 0 if we 232 currently don't have a help section 233 */ 234 long impl_getPrefererredHelpHeight(); 235 236 private: 237 using Window::Activate; 238 }; 239 240 //............................................................................ 241 } // namespace pcr 242 //............................................................................ 243 244 #endif // _EXTENSIONS_PROPCTRLR_BROWSERLISTBOX_HXX_ 245 246 247