cid#1640468 Dereference after null check
[LibreOffice.git] / dbaccess / source / ui / app / AppView.hxx
blob59a6d477a3676220f6bbc6f6491f59599a2571d7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
19 #pragma once
21 #include <dbaccess/dataview.hxx>
22 #include <com/sun/star/ucb/XContent.hpp>
23 #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
24 #include <com/sun/star/sdbc/XConnection.hpp>
25 #include <unotools/eventlisteneradapter.hxx>
26 #include <vcl/InterimItemWindow.hxx>
27 #include <vcl/weld.hxx>
28 #include <IClipBoardTest.hxx>
29 #include <AppElementType.hxx>
31 namespace com::sun::star::beans { class XPropertySet; }
33 class MnemonicGenerator;
35 namespace dbaui
37 class OApplicationView;
38 class OApplicationDetailView;
39 class OApplicationSwapWindow;
40 class OTitleWindow;
41 class OApplicationController;
43 class OAppBorderWindow final : public InterimItemWindow
45 std::unique_ptr<weld::Container> m_xPanelParent;
46 std::unique_ptr<weld::Container> m_xDetailViewParent;
47 std::unique_ptr<OTitleWindow> m_xPanel;
48 std::unique_ptr<OApplicationDetailView> m_xDetailView;
49 VclPtr<OApplicationView> m_xView;
51 public:
52 OAppBorderWindow(OApplicationView* pParent, PreviewMode ePreviewMode);
53 virtual ~OAppBorderWindow() override;
54 virtual void dispose() override;
56 // Window overrides
57 virtual void GetFocus() override;
59 OApplicationView* getView() const { return m_xView.get(); }
60 OApplicationSwapWindow* getPanel() const;
61 OApplicationDetailView* getDetailView() const { return m_xDetailView.get(); }
62 weld::Container& getTopLevel() { return *m_xContainer; }
65 class OApplicationView : public ODataView
66 ,public IClipboardTest
67 ,public ::utl::OEventListenerAdapter
69 enum ChildFocusState
71 PANELSWAP,
72 DETAIL,
73 NONE
75 private:
76 css::uno::Reference< css::lang::XComponent >
77 m_xObject;
78 VclPtr<OAppBorderWindow> m_pWin;
79 OApplicationController& m_rAppController;
81 ChildFocusState getChildFocus() const;
82 IClipboardTest* getActiveChild() const;
84 void ImplInitSettings();
85 protected:
87 // return the Rectangle where I can paint myself
88 virtual void resizeDocumentView(tools::Rectangle& rRect) override;
90 // OEventListenerAdapter
91 virtual void _disposing( const css::lang::EventObject& _rSource ) override;
93 // Window
94 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
95 public:
96 OApplicationView( vcl::Window* pParent
97 ,const css::uno::Reference< css::uno::XComponentContext >&
98 ,OApplicationController& _rAppController
99 ,PreviewMode _ePreviewMode
101 virtual ~OApplicationView() override;
102 virtual void dispose() override;
104 /// automatically creates mnemonics for the icon/texts in our left hand side panel
105 void createIconAutoMnemonics( MnemonicGenerator& _rMnemonics );
107 /// automatically creates mnemonics for the texts in our task pane
108 void setTaskExternalMnemonics( MnemonicGenerator const & _rMnemonics );
110 // Window overrides
111 virtual bool PreNotify( NotifyEvent& rNEvt ) override;
112 virtual void GetFocus() override;
114 OApplicationController& getAppController() const { return m_rAppController; }
116 // IClipboardTest
117 virtual bool isCutAllowed() override;
118 virtual bool isCopyAllowed() override;
119 virtual bool isPasteAllowed() override;
120 virtual void copy() override;
121 virtual void cut() override;
122 virtual void paste() override;
124 /// get the left panel
125 OApplicationSwapWindow* getPanel() const { return m_pWin->getPanel(); }
126 /// get the detail page
127 OApplicationDetailView* getDetailView() const { return m_pWin->getDetailView(); }
129 /** return the qualified name.
130 @param _pEntry
131 The entry of a table, or query, form, report to get the qualified name.
132 If the entry is <NULL/>, the first selected is chosen.
133 @return
134 the qualified name
136 OUString getQualifiedName(const weld::TreeIter* _pEntry) const;
138 /** returns if an entry is a leaf
139 @param rTreeView
140 The TreeView rEntry belongs to
141 @param rEntry
142 The entry to check
143 @return
144 <TRUE/> if the entry is a leaf, otherwise <FALSE/>
146 bool isLeaf(const weld::TreeView& rTreeView, const weld::TreeIter& rEntry) const;
148 /** returns if one of the selected entries is a leaf
149 @return
150 <TRUE/> if the entry is a leaf, otherwise <FALSE/>
152 bool isALeafSelected() const;
154 /** select all entries in the detail page
156 void selectAll();
158 /// returns <TRUE/> if it sorts ascending
159 bool isSortUp() const;
161 /// sort the entries in the detail page down
162 void sortDown();
164 /// sort the entries in the detail page up
165 void sortUp();
167 /// returns <TRUE/> when a detail page was filled
168 bool isFilled() const;
170 /// return the element of currently select entry
171 ElementType getElementType() const;
173 /// returns the count of entries
174 sal_Int32 getElementCount() const;
176 /// returns the count of selected entries
177 sal_Int32 getSelectionCount() const;
179 /** clears the detail page and the selection on the left side.
180 The task window will also be cleared.
182 void clearPages();
184 /** returns the element names which are selected
185 @param _rNames
186 The list will be filled.
188 void getSelectionElementNames( std::vector< OUString>& _rNames ) const;
190 /** describes the current selection for the given control
192 void describeCurrentSelectionForControl(
193 const weld::TreeView& rControl,
194 css::uno::Sequence< css::sdb::application::NamedDatabaseObject >& _out_rSelectedObjects
197 /** describes the current selection for the given ElementType
199 void describeCurrentSelectionForType(
200 const ElementType _eType,
201 css::uno::Sequence< css::sdb::application::NamedDatabaseObject >& _out_rSelectedObjects
204 /** get the menu parent window for the given control
206 vcl::Window* getMenuParent() const;
208 /** adjust rPos relative to rControl to instead relative to getMenuParent */
209 void adjustMenuPosition(const weld::TreeView& rControl, ::Point& rPos) const;
211 /** select all names on the currently selected container. Non existence names where ignored.
213 * \param _aNames the element names
215 void selectElements(const css::uno::Sequence< OUString>& _aNames);
217 /** adds a new object to the detail page.
218 @param _eType
219 The type where the entry should be appended.
220 @param _rName
221 The name of the object to be inserted
222 @param _rObject
223 The object to add.
224 @param _rxConn
225 If we insert a table, the connection must be set.
227 std::unique_ptr<weld::TreeIter> elementAdded(ElementType eType,
228 const OUString& rName,
229 const css::uno::Any& rObject);
231 /** replaces an objects name with a new one
232 @param _eType
233 The type where the entry should be appended.
234 @param _rOldName
235 The old name of the object to be replaced
236 @param _rNewName
237 The new name of the object to be replaced
238 @param _rxConn
239 If we insert a table, the connection must be set.
240 @param _xObject
241 The object which was replaced
243 void elementReplaced(ElementType eType
244 ,const OUString& _rOldName
245 ,const OUString& _rNewName );
247 /** removes an element from the detail page.
248 @param _eType
249 The type where the entry should be appended.
250 @param _rName
251 The name of the element to be removed.
252 @param _rxConn
253 If we remove a table, the connection must be set.
255 void elementRemoved(ElementType _eType
256 ,const OUString& _rName );
258 /** changes the container which should be displayed. The select handler will also be called.
259 @param _eType
260 Which container to show.
262 void selectContainer(ElementType _eType);
264 /// returns the preview mode
265 PreviewMode getPreviewMode() const;
267 /// <TRUE/> if the preview is enabled
268 bool isPreviewEnabled() const;
270 /** switches to the given preview mode
271 @param _eMode
272 the mode to set for the preview
274 void switchPreview(PreviewMode _eMode);
276 /** shows the Preview of the content when it is enabled.
277 @param _xContent
278 The content which must support the "preview" command.
280 void showPreview(const css::uno::Reference< css::ucb::XContent >& _xContent);
282 /** shows the Preview of a table or query
283 @param _sDataSourceName
284 the name of the data source
285 @param _xConnection
286 the connection which will be shared
287 @param _sName
288 the name of table or query
289 @param _bTable
290 <TRUE/> if it is a table, otherwise <FALSE/>
291 @return void
293 void showPreview( const OUString& _sDataSourceName,
294 const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
295 const OUString& _sName,
296 bool _bTable);
298 std::unique_ptr<weld::TreeIter> getEntry(const Point& rPosPixel) const;
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */