1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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"
36 namespace com::sun::star::awt
{ class XWindow
; }
37 namespace com::sun::star::frame
{ class XFrame2
; }
38 namespace com::sun::star::io
{ class XPersist
; }
42 class OAppBorderWindow
;
43 class ODocumentInfoPreview
;
47 class OPreviewWindow final
: public weld::CustomWidgetController
49 GraphicObject m_aGraphicObj
;
50 tools::Rectangle m_aPreviewRect
;
52 /** gets the graphic center rect
54 the context to which we are drawing
58 the resulting rectangle
61 <TRUE/> when successful
63 bool ImplGetGraphicCenterRect(const vcl::RenderContext
& rRenderContext
, const Graphic
& rGraphic
, tools::Rectangle
& rResultRect
) const;
68 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
70 void setGraphic(const Graphic
& _rGraphic
) { m_aGraphicObj
.SetGraphic(_rGraphic
); }
73 // A helper class for the controls in the detail page.
74 // Combines general functionality.
75 class OAppDetailPageHelper final
: public OChildWindow
77 std::unique_ptr
<DBTreeViewBase
> m_aLists
[size_t(E_ELEMENT_TYPE_COUNT
)];
78 OAppBorderWindow
& m_rBorderWin
;
79 std::unique_ptr
<weld::Container
> m_xBox
;
80 std::unique_ptr
<weld::Widget
> m_xFL
;
81 std::unique_ptr
<weld::MenuButton
> m_xMBPreview
;
83 std::unique_ptr
<OPreviewWindow
> m_xPreview
;
84 std::unique_ptr
<weld::CustomWeld
> m_xPreviewWin
;
86 std::unique_ptr
<ODocumentInfoPreview
> m_xDocumentInfo
;
87 std::unique_ptr
<weld::CustomWeld
> m_xDocumentInfoWin
;
89 std::unique_ptr
<weld::Container
> m_xTablePreview
;
91 PreviewMode m_ePreviewMode
;
92 css::uno::Reference
< css::frame::XFrame2
>
94 css::uno::Reference
< css::awt::XWindow
>
97 /// returns the index of the visible control
98 int getVisibleControlIndex() const;
100 /** sorts the entries in the tree list box.
102 Which list should be sorted.
104 If sort should be Ascending of Descending
106 void sort(int nPos
, bool bAscending
);
108 /** retrieves the resource ids of the images representing elements of the given type
110 static OUString
getElementIcons(ElementType _eType
);
112 /** fills the names in the listbox
114 This can either be the queries, forms or report names.
116 the type of elements which are being filled
118 the resource id of the image to use for non-container entries
120 The parent of the entries to be inserted.
122 void fillNames( const css::uno::Reference
< css::container::XNameAccess
>& _xContainer
,
123 const ElementType _eType
,
124 const OUString
& rImageId
,
125 const weld::TreeIter
* _pParent
);
127 /** sets the detail page
129 The control which should be visible.
131 void setDetailPage(DBTreeViewBase
& rTreeView
);
133 /** sets all HandleCallbacks
135 The newly created DBTreeViewBase
137 void setupTree(DBTreeViewBase
& rTreeView
);
139 /** creates the tree and sets all HandleCallbacks
141 The help id of the control
143 The element type of the control
147 std::unique_ptr
<DBTreeViewBase
> createSimpleTree(const OUString
& rHelpId
, ElementType eType
);
149 DECL_LINK( OnEntryDoubleClick
, weld::TreeView
&, bool );
150 DECL_LINK( OnEntrySelChange
, LinkParamNone
*, void );
152 DECL_LINK( OnCopyEntry
, LinkParamNone
*, void );
153 DECL_LINK( OnPasteEntry
, LinkParamNone
*, void );
154 DECL_LINK( OnDeleteEntry
, LinkParamNone
*, void );
156 DECL_LINK(OnDropdownClickHdl
, weld::Toggleable
&, void);
157 DECL_LINK(MenuSelectHdl
, const OUString
&, void);
159 OAppBorderWindow
& getBorderWin() const { return m_rBorderWin
; }
162 OAppDetailPageHelper(weld::Container
* pParent
, OAppBorderWindow
& rBorderWin
, PreviewMode ePreviewMode
);
163 virtual ~OAppDetailPageHelper() override
;
165 virtual void GrabFocus() override
;
166 virtual bool HasChildPathFocus() const override
;
168 /** creates the tables page
170 The connection to get the table names
172 void createTablesPage(const css::uno::Reference
< css::sdbc::XConnection
>& _xConnection
);
174 /** creates the page for the specific type.
176 The type which should be created. E_TABLE isn't allowed.
178 The container of the elements to be inserted.
180 void createPage(ElementType _eType
,const css::uno::Reference
< css::container::XNameAccess
>& _xContainer
);
182 /** returns the current visible tree list box
184 DBTreeViewBase
* getCurrentView() const
186 ElementType eType
= getElementType();
187 return (eType
!= E_NONE
) ? m_aLists
[static_cast<sal_Int32
>(eType
)].get() : nullptr;
190 /// select all entries in the visible control
193 /// returns <TRUE/> if it sorts ascending
194 bool isSortUp() const;
196 /// sorts all entries ascending
199 /// sorts all entries descending
202 /** returns the element names which are selected
204 The list will be filled.
206 void getSelectionElementNames( std::vector
< OUString
>& _rNames
) const;
208 /** describes the current selection for the given control
210 void describeCurrentSelectionForControl(
211 const weld::TreeView
& rControl
,
212 css::uno::Sequence
< css::sdb::application::NamedDatabaseObject
>& _out_rSelectedObjects
215 /** describes the current selection for the given ElementType
217 void describeCurrentSelectionForType(
218 const ElementType _eType
,
219 css::uno::Sequence
< css::sdb::application::NamedDatabaseObject
>& _out_rSelectedObjects
222 /** get the menu parent window for the given control
224 vcl::Window
* getMenuParent() const;
225 void adjustMenuPosition(const weld::TreeView
& rControl
, ::Point
& rPos
) const;
227 /** select all names on the currently selected container. Non existence names where ignored.
229 * \param _aNames the element names
231 void selectElements(const css::uno::Sequence
< OUString
>& _aNames
);
233 /** return the qualified name.
235 The entry of a table, or query, form, report to get the qualified name.
236 If the entry is <NULL/>, the first selected is chosen.
240 OUString
getQualifiedName( const weld::TreeIter
* _pEntry
) const;
242 /// return the element of currently select entry
243 ElementType
getElementType() const;
245 /// returns the count of selected entries
246 sal_Int32
getSelectionCount();
248 /// returns the count of entries
249 sal_Int32
getElementCount() const;
251 /** returns if an entry is a leaf
253 The TreeView rEntry belongs to
257 <TRUE/> if the entry is a leaf, otherwise <FALSE/>
259 static bool isLeaf(const weld::TreeView
& rTreeView
, const weld::TreeIter
& rEntry
);
261 /** returns if one of the selected entries is a leaf
263 <TRUE/> if the entry is a leaf, otherwise <FALSE/>
265 bool isALeafSelected() const;
267 std::unique_ptr
<weld::TreeIter
> getEntry(const Point
& rPosPixel
) const;
269 /// clears the detail pages
272 /// returns <TRUE/> when a detail page was filled
273 bool isFilled() const;
275 /** adds a new object to the detail page.
277 The type where the entry should be appended.
279 The name of the object to be inserted
283 If we insert a table, the connection must be set.
285 std::unique_ptr
<weld::TreeIter
> elementAdded(ElementType eType
,
286 const OUString
& rName
,
287 const css::uno::Any
& rObject
);
289 /** replaces an objects name with a new one
291 The type where the entry should be appended.
293 The old name of the object to be replaced
295 The new name of the object to be replaced
297 If we insert a table, the connection must be set.
299 void elementReplaced(ElementType eType
300 ,const OUString
& _rOldName
301 ,const OUString
& _rNewName
);
303 /** removes an element from the detail page.
305 The type where the entry should be appended.
307 The name of the element to be removed.
309 If we remove a table, the connection must be set.
311 void elementRemoved(ElementType _eType
312 ,const OUString
& _rName
);
314 /// returns the preview mode
315 PreviewMode
getPreviewMode() const { return m_ePreviewMode
;}
317 /// <TRUE/> if the preview is enabled
318 bool isPreviewEnabled() const;
320 /** switches to the given preview mode
322 the mode to set for the preview
324 Force the preview to be reset
326 void switchPreview(PreviewMode _eMode
,bool _bForce
= false);
328 /** shows the Preview of the content when it is enabled.
330 The content which must support the "preview" command.
332 void showPreview(const css::uno::Reference
< css::ucb::XContent
>& _xContent
);
334 /** shows the Preview of a table or query
335 @param _sDataSourceName
336 the name of the data source
338 the name of table or query
340 <TRUE/> if it is a table, otherwise <FALSE/>
343 void showPreview( const OUString
& _sDataSourceName
,
344 const OUString
& _sName
,
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */