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 #pragma once 20 21 #include <vector> 22 23 #include <rtl/ustring.hxx> 24 #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp> 25 #include <com/sun/star/sdbc/XConnection.hpp> 26 #include <com/sun/star/ucb/XContent.hpp> 27 #include <com/sun/star/container/XNameAccess.hpp> 28 #include <vcl/graph.hxx> 29 #include <vcl/GraphicObject.hxx> 30 #include <vcl/customweld.hxx> 31 #include <vcl/weld.hxx> 32 #include <AppElementType.hxx> 33 #include <ChildWindow.hxx> 34 #include "DocumentInfoPreview.hxx" 35 36 namespace com::sun::star::awt { class XWindow; } 37 namespace com::sun::star::frame { class XFrame2; } 38 namespace com::sun::star::io { class XPersist; } 39 40 #define ELEMENT_COUNT size_t(E_ELEMENT_TYPE_COUNT) 41 42 namespace dbaui 43 { 44 class OAppBorderWindow; 45 class ODocumentInfoPreview; 46 class DBTreeViewBase; 47 class TreeListBox; 48 49 class OPreviewWindow final : public weld::CustomWidgetController 50 { 51 GraphicObject m_aGraphicObj; 52 tools::Rectangle m_aPreviewRect; 53 54 /** gets the graphic center rect 55 @param rRenderContext 56 the context to which we are drawing 57 @param rGraphic 58 the graphic 59 @param rResultRect 60 the resulting rectangle 61 62 @return 63 <TRUE/> when successful 64 */ 65 bool ImplGetGraphicCenterRect(const vcl::RenderContext& rRenderContext, const Graphic& rGraphic, tools::Rectangle& rResultRect) const; 66 67 public: 68 OPreviewWindow(); 69 70 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; 71 setGraphic(const Graphic & _rGraphic)72 void setGraphic(const Graphic& _rGraphic ) { m_aGraphicObj.SetGraphic(_rGraphic); } 73 }; 74 75 // A helper class for the controls in the detail page. 76 // Combines general functionality. 77 class OAppDetailPageHelper final : public OChildWindow 78 { 79 std::unique_ptr<DBTreeViewBase> m_aLists[ELEMENT_COUNT]; 80 OAppBorderWindow& m_rBorderWin; 81 std::unique_ptr<weld::Container> m_xBox; 82 std::unique_ptr<weld::Widget> m_xFL; 83 std::unique_ptr<weld::MenuButton> m_xMBPreview; 84 85 std::unique_ptr<OPreviewWindow> m_xPreview; 86 std::unique_ptr<weld::CustomWeld> m_xPreviewWin; 87 88 std::unique_ptr<ODocumentInfoPreview> m_xDocumentInfo; 89 std::unique_ptr<weld::CustomWeld> m_xDocumentInfoWin; 90 91 std::unique_ptr<weld::Container> m_xTablePreview; 92 93 PreviewMode m_ePreviewMode; 94 css::uno::Reference < css::frame::XFrame2 > 95 m_xFrame; 96 css::uno::Reference< css::awt::XWindow > 97 m_xWindow; 98 99 /// returns the index of the visible control 100 int getVisibleControlIndex() const; 101 102 /** sorts the entries in the tree list box. 103 @param nPos 104 Which list should be sorted. 105 @param bAscending 106 If sort should be Ascending of Descending 107 */ 108 void sort(int nPos, bool bAscending); 109 110 /** retrieves the resource ids of the images representing elements of the given type 111 */ 112 static OUString getElementIcons(ElementType _eType); 113 114 /** fills the names in the listbox 115 @param _xContainer 116 This can either be the queries, forms or report names. 117 @param _eType 118 the type of elements which are being filled 119 @param _nImageId 120 the resource id of the image to use for non-container entries 121 @param _pParent 122 The parent of the entries to be inserted. 123 */ 124 void fillNames( const css::uno::Reference< css::container::XNameAccess >& _xContainer, 125 const ElementType _eType, 126 const OUString& rImageId, 127 const weld::TreeIter* _pParent ); 128 129 /** sets the detail page 130 @param rTreeView 131 The control which should be visible. 132 */ 133 void setDetailPage(DBTreeViewBase& rTreeView); 134 135 /** sets all HandleCallbacks 136 @param rTreeView 137 The newly created DBTreeViewBase 138 */ 139 void setupTree(DBTreeViewBase& rTreeView); 140 141 /** creates the tree and sets all HandleCallbacks 142 @param nHelpId 143 The help id of the control 144 @param eType 145 The element type of the control 146 @return 147 The new tree. 148 */ 149 std::unique_ptr<DBTreeViewBase> createSimpleTree(const OString& rHelpId, ElementType eType); 150 151 DECL_LINK( OnEntryDoubleClick, weld::TreeView&, bool ); 152 DECL_LINK( OnEntrySelChange, LinkParamNone*, void ); 153 154 DECL_LINK( OnCopyEntry, LinkParamNone*, void ); 155 DECL_LINK( OnPasteEntry, LinkParamNone*, void ); 156 DECL_LINK( OnDeleteEntry, LinkParamNone*, void ); 157 158 DECL_LINK(OnDropdownClickHdl, weld::Toggleable&, void); 159 DECL_LINK(MenuSelectHdl, const OString&, void); 160 getBorderWin() const161 OAppBorderWindow& getBorderWin() const { return m_rBorderWin; } 162 163 public: 164 OAppDetailPageHelper(weld::Container* pParent, OAppBorderWindow& rBorderWin, PreviewMode ePreviewMode); 165 virtual ~OAppDetailPageHelper() override; 166 167 virtual void GrabFocus() override; 168 virtual bool HasChildPathFocus() const override; 169 170 /** creates the tables page 171 @param _xConnection 172 The connection to get the table names 173 */ 174 void createTablesPage(const css::uno::Reference< css::sdbc::XConnection>& _xConnection); 175 176 /** creates the page for the specific type. 177 @param _eType 178 The type which should be created. E_TABLE isn't allowed. 179 @param _xContainer 180 The container of the elements to be inserted. 181 */ 182 void createPage(ElementType _eType,const css::uno::Reference< css::container::XNameAccess >& _xContainer); 183 184 /** returns the current visible tree list box 185 */ getCurrentView() const186 DBTreeViewBase* getCurrentView() const 187 { 188 ElementType eType = getElementType(); 189 return (eType != E_NONE ) ? m_aLists[static_cast<sal_Int32>(eType)].get() : nullptr; 190 } 191 192 /// select all entries in the visible control 193 void selectAll(); 194 195 /// returns <TRUE/> if it sorts ascending 196 bool isSortUp() const; 197 198 /// sorts all entries ascending 199 void sortDown(); 200 201 /// sorts all entries descending 202 void sortUp(); 203 204 /** returns the element names which are selected 205 @param _rNames 206 The list will be filled. 207 */ 208 void getSelectionElementNames( std::vector< OUString>& _rNames ) const; 209 210 /** describes the current selection for the given control 211 */ 212 void describeCurrentSelectionForControl( 213 const weld::TreeView& rControl, 214 css::uno::Sequence< css::sdb::application::NamedDatabaseObject >& _out_rSelectedObjects 215 ); 216 217 /** describes the current selection for the given ElementType 218 */ 219 void describeCurrentSelectionForType( 220 const ElementType _eType, 221 css::uno::Sequence< css::sdb::application::NamedDatabaseObject >& _out_rSelectedObjects 222 ); 223 224 /** get the menu parent window for the given control 225 */ 226 vcl::Window* getMenuParent() const; 227 void adjustMenuPosition(const weld::TreeView& rControl, ::Point& rPos) const; 228 229 /** select all names on the currently selected container. Non existence names where ignored. 230 * 231 * \param _aNames the element names 232 */ 233 void selectElements(const css::uno::Sequence< OUString>& _aNames); 234 235 /** return the qualified name. 236 @param _pEntry 237 The entry of a table, or query, form, report to get the qualified name. 238 If the entry is <NULL/>, the first selected is chosen. 239 @return 240 the qualified name 241 */ 242 OUString getQualifiedName( const weld::TreeIter* _pEntry ) const; 243 244 /// return the element of currently select entry 245 ElementType getElementType() const; 246 247 /// returns the count of selected entries 248 sal_Int32 getSelectionCount(); 249 250 /// returns the count of entries 251 sal_Int32 getElementCount() const; 252 253 /** returns if an entry is a leaf 254 @param rTreeView 255 The TreeView rEntry belongs to 256 @param rEntry 257 The entry to check 258 @return 259 <TRUE/> if the entry is a leaf, otherwise <FALSE/> 260 */ 261 static bool isLeaf(const weld::TreeView& rTreeView, const weld::TreeIter& rEntry); 262 263 /** returns if one of the selected entries is a leaf 264 @return 265 <TRUE/> if the entry is a leaf, otherwise <FALSE/> 266 */ 267 bool isALeafSelected() const; 268 269 std::unique_ptr<weld::TreeIter> getEntry(const Point& rPosPixel) const; 270 271 /// clears the detail pages 272 void clearPages(); 273 274 /// returns <TRUE/> when a detail page was filled 275 bool isFilled() const; 276 277 /** adds a new object to the detail page. 278 @param _eType 279 The type where the entry should be appended. 280 @param _rName 281 The name of the object to be inserted 282 @param _rObject 283 The object to add. 284 @param _rxConn 285 If we insert a table, the connection must be set. 286 */ 287 std::unique_ptr<weld::TreeIter> elementAdded(ElementType eType, 288 const OUString& rName, 289 const css::uno::Any& rObject); 290 291 /** replaces an objects name with a new one 292 @param _eType 293 The type where the entry should be appended. 294 @param _rOldName 295 The old name of the object to be replaced 296 @param _rNewName 297 The new name of the object to be replaced 298 @param _rxConn 299 If we insert a table, the connection must be set. 300 */ 301 void elementReplaced(ElementType eType 302 ,const OUString& _rOldName 303 ,const OUString& _rNewName ); 304 305 /** removes an element from the detail page. 306 @param _eType 307 The type where the entry should be appended. 308 @param _rName 309 The name of the element to be removed. 310 @param _rxConn 311 If we remove a table, the connection must be set. 312 */ 313 void elementRemoved(ElementType _eType 314 ,const OUString& _rName ); 315 316 /// returns the preview mode getPreviewMode() const317 PreviewMode getPreviewMode() const { return m_ePreviewMode;} 318 319 /// <TRUE/> if the preview is enabled 320 bool isPreviewEnabled() const; 321 322 /** switches to the given preview mode 323 @param _eMode 324 the mode to set for the preview 325 @param _bForce 326 Force the preview to be reset 327 */ 328 void switchPreview(PreviewMode _eMode,bool _bForce = false); 329 330 /** shows the Preview of the content when it is enabled. 331 @param _xContent 332 The content which must support the "preview" command. 333 */ 334 void showPreview(const css::uno::Reference< css::ucb::XContent >& _xContent); 335 336 /** shows the Preview of a table or query 337 @param _sDataSourceName 338 the name of the data source 339 @param _sName 340 the name of table or query 341 @param _bTable 342 <TRUE/> if it is a table, otherwise <FALSE/> 343 @return void 344 */ 345 void showPreview( const OUString& _sDataSourceName, 346 const OUString& _sName, 347 bool _bTable); 348 }; 349 } 350 351 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 352