LibreOffice Module dbaccess (master) 1
AppView.cxx
Go to the documentation of this file.
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#include "AppView.hxx"
21#include <strings.hrc>
23#include <vcl/event.hxx>
24#include <vcl/weld.hxx>
25#include <com/sun/star/sdbcx/XTablesSupplier.hpp>
26#include <com/sun/star/sdb/XQueriesSupplier.hpp>
27#include "AppDetailView.hxx"
28#include "AppSwapWindow.hxx"
29#include <vcl/settings.hxx>
30#include "AppTitleWindow.hxx"
31#include "AppController.hxx"
32
33using namespace ::dbaui;
34using namespace ::com::sun::star::uno;
35using namespace ::com::sun::star::ucb;
36using namespace ::com::sun::star::beans;
37using namespace ::com::sun::star::sdb;
38using namespace ::com::sun::star::sdbc;
39using namespace ::com::sun::star::sdbcx;
41using namespace ::com::sun::star::lang;
42using namespace ::com::sun::star::container;
43using ::com::sun::star::sdb::application::NamedDatabaseObject;
44
45OAppBorderWindow::OAppBorderWindow(OApplicationView* pParent, PreviewMode ePreviewMode)
46 : InterimItemWindow(pParent, "dbaccess/ui/appborderwindow.ui", "AppBorderWindow", false)
47 , m_xPanelParent(m_xBuilder->weld_container("panel"))
48 , m_xDetailViewParent(m_xBuilder->weld_container("detail"))
49 , m_xView(pParent)
50{
52
53 m_xPanel.reset(new OTitleWindow(m_xPanelParent.get(), STR_DATABASE));
54 std::shared_ptr<OChildWindow> xSwap = std::make_shared<OApplicationSwapWindow>(m_xPanel->getChildContainer(), *this);
55
56 m_xPanel->setChildWindow(xSwap);
57
58 m_xDetailView.reset(new OApplicationDetailView(m_xDetailViewParent.get(), *this, ePreviewMode));
59
61}
62
64{
66}
67
69{
70 // destroy children
71 m_xPanel.reset();
72 m_xDetailView.reset();
73 m_xPanelParent.reset();
74 m_xDetailViewParent.reset();
75 m_xView.clear();
77}
78
80{
81 if (m_xPanel)
82 m_xPanel->GrabFocus();
83}
84
86{
87 return static_cast<OApplicationSwapWindow*>(m_xPanel->getChildWindow());
88}
89
92 ,OApplicationController& _rAppController
93 ,PreviewMode _ePreviewMode
94 ) :
95 ODataView( pParent, _rAppController, _rxOrb, WB_DIALOGCONTROL )
96 ,m_rAppController( _rAppController )
97{
98 m_pWin = VclPtr<OAppBorderWindow>::Create(this,_ePreviewMode);
99 m_pWin->Show();
100
102}
103
105{
106 disposeOnce();
107}
108
110{
112 m_xObject.clear();
113 m_pWin->Hide();
114 m_pWin.disposeAndClear();
116}
117
119{
120 if ( m_pWin && m_pWin->getPanel() )
121 m_pWin->getPanel()->createIconAutoMnemonics( _rMnemonics );
122}
123
125{
126 if ( m_pWin && m_pWin->getDetailView() )
127 m_pWin->getDetailView()->setTaskExternalMnemonics( _rMnemonics );
128}
129
131{
132 ODataView::DataChanged( rDCEvt );
133
134 if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
135 (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
136 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
137 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
138 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
139 {
141 Invalidate();
142 }
143}
144
146{
147 if ( m_pWin && !_rPlayground.IsEmpty() )
148 {
149 Size aFLSize = LogicToPixel(Size(3, 3), MapMode(MapUnit::MapAppFont));
150 _rPlayground.Move( aFLSize.Width(),aFLSize.Height() );
151 Size aOldSize = _rPlayground.GetSize();
152 _rPlayground.SetSize( Size(aOldSize.Width() - 2*aFLSize.Width(), aOldSize.Height() - 2*aFLSize.Height()) );
153
154 m_pWin->SetPosSizePixel(_rPlayground.TopLeft() , _rPlayground.GetSize() );
155 }
156 // just for completeness: there is no space left, we occupied it all ...
157 _rPlayground.SetPos( _rPlayground.BottomRight() );
158 _rPlayground.SetSize( Size( 0, 0 ) );
159}
160
162{
163 ChildFocusState eChildFocus;
164 if( m_pWin && getPanel() && getPanel()->HasChildPathFocus() )
165 eChildFocus = PANELSWAP;
166 else if ( m_pWin && getDetailView() && getDetailView()->HasChildPathFocus() )
167 eChildFocus = DETAIL;
168 else
169 eChildFocus = NONE;
170 return eChildFocus;
171}
172
174{
175 switch(rNEvt.GetType())
176 {
177 case NotifyEventType::KEYINPUT:
178 {
179 const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
180 // give the pane the chance to intercept mnemonic accelerators
181 // #i34790#
182 if ( getPanel() && getPanel()->interceptKeyInput( *pKeyEvent ) )
183 return true;
184 }
185 break;
186 default:
187 break;
188 }
189
190 return ODataView::PreNotify(rNEvt);
191}
192
194{
195 IClipboardTest* pTest = nullptr;
196 if (getChildFocus() == DETAIL)
197 pTest = getDetailView();
198 return pTest;
199}
200
202{
204 return pTest && pTest->isCopyAllowed();
205}
206
208{
210 return pTest && pTest->isCutAllowed();
211}
212
214{
216 return pTest && pTest->isPasteAllowed();
217}
218
220{
222 if ( pTest )
223 pTest->copy();
224}
225
227{
229 if ( pTest )
230 pTest->cut();
231}
232
234{
236 if ( pTest )
237 pTest->paste();
238}
239
241{
242 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
243 return getDetailView()->getQualifiedName( _pEntry );
244}
245
246bool OApplicationView::isLeaf(const weld::TreeView& rTreeView, const weld::TreeIter& rEntry) const
247{
248 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
249 return OApplicationDetailView::isLeaf(rTreeView, rEntry);
250}
251
253{
254 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
255 return getDetailView()->isALeafSelected();
256}
257
259{
260 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
262}
263
265{
266 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
267 return getDetailView()->isSortUp();
268}
269
271{
272 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
274}
275
277{
278 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
280}
281
283{
284 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
285 return getDetailView()->isFilled();
286}
287
289{
290 OSL_ENSURE(m_pWin && getDetailView() && getPanel(),"Detail view is NULL! -> GPF");
292}
293
295{
296 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
298}
299
301{
302 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
303 return getDetailView()->getElementCount();
304}
305
306void OApplicationView::getSelectionElementNames( std::vector< OUString>& _rNames ) const
307{
308 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
310}
311
313{
314 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
315 getDetailView()->describeCurrentSelectionForControl(rControl, out_rSelectedObjects);
316}
317
319{
320 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
321 return getDetailView()->getMenuParent();
322}
323
325{
326 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
327 return getDetailView()->adjustMenuPosition(rControl, rPos);
328}
329
331{
332 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
333 getDetailView()->describeCurrentSelectionForType( _eType, _out_rSelectedObjects );
334}
335
337{
338 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
339 getDetailView()->selectElements( _aNames );
340}
341
342std::unique_ptr<weld::TreeIter> OApplicationView::elementAdded(ElementType eType,const OUString& _rName, const Any& _rObject )
343{
344 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
345 return getDetailView()->elementAdded(eType,_rName,_rObject);
346}
347
349{
350 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
352}
353
355 ,const OUString& _rOldName
356 ,const OUString& _rNewName )
357{
358 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
359 getDetailView()->elementReplaced(_eType, _rOldName, _rNewName );
360}
361
363{
364 OSL_ENSURE(m_pWin && getDetailView() && getPanel(),"Detail view is NULL! -> GPF");
367}
368
370{
371 OSL_ENSURE(m_pWin && getPanel(),"Detail view is NULL! -> GPF");
373 getPanel()->selectContainer(_eType);
374}
375
376std::unique_ptr<weld::TreeIter> OApplicationView::getEntry(const Point& rPosPixel) const
377{
378 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
379 return getDetailView()->getEntry(rPosPixel);
380}
381
383{
384 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
385 return getDetailView()->getPreviewMode();
386}
387
389{
390 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
392}
393
395{
396 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
397 getDetailView()->switchPreview(_eMode);
398}
399
401{
402 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
404 m_xObject = nullptr;
405 getDetailView()->showPreview(_xContent);
406}
407
408void OApplicationView::showPreview( const OUString& _sDataSourceName,
409 const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
410 const OUString& _sName,
411 bool _bTable)
412{
413 OSL_ENSURE(m_pWin && getDetailView(),"Detail view is NULL! -> GPF");
414 if ( !isPreviewEnabled() )
415 return;
416
418 m_xObject = nullptr;
419 try
420 {
421 Reference<XNameAccess> xNameAccess;
422 if ( _bTable )
423 {
424 Reference<XTablesSupplier> xSup(_xConnection,UNO_QUERY);
425 if ( xSup.is() )
426 xNameAccess = xSup->getTables();
427 }
428 else
429 {
430 Reference<XQueriesSupplier> xSup(_xConnection,UNO_QUERY);
431 if ( xSup.is() )
432 xNameAccess = xSup->getQueries();
433 }
434 if ( xNameAccess.is() && xNameAccess->hasByName(_sName) )
435 m_xObject.set(xNameAccess->getByName(_sName),UNO_QUERY);
436 }
437 catch( const Exception& )
438 {
439 DBG_UNHANDLED_EXCEPTION("dbaccess");
440 }
441 if ( m_xObject.is() )
443 getDetailView()->showPreview(_sDataSourceName,_sName,_bTable);
444}
445
447{
448 if (m_pWin && getChildFocus() == NONE)
449 m_pWin->GrabFocus();
450}
451
452void OApplicationView::_disposing( const css::lang::EventObject& /*_rSource*/ )
453{
454 if ( m_pWin && getDetailView() )
455 showPreview(nullptr);
456}
457
459{
460 // FIXME RenderContext
461 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
462
463 vcl::Font aFont = rStyleSettings.GetFieldFont();
464 aFont.SetColor( rStyleSettings.GetWindowTextColor() );
465 SetPointFont(*GetOutDev(), aFont);
466
467 SetTextColor( rStyleSettings.GetFieldTextColor() );
469
470 SetBackground( rStyleSettings.GetFieldColor() );
471}
472
473/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
void ImplInitSettings()
DataChangedEventType GetType() const
AllSettingsFlags GetFlags() const
virtual void dispose() override
const KeyEvent * GetKeyEvent() const
NotifyEventType GetType() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Color & GetFieldTextColor() const
const Color & GetFieldColor() const
const vcl::Font & GetFieldFont() const
const Color & GetWindowTextColor() const
static VclPtr< reference_type > Create(Arg &&... arg)
virtual void copy()=0
virtual bool isCutAllowed()=0
virtual void cut()=0
virtual bool isPasteAllowed()=0
virtual void paste()=0
virtual bool isCopyAllowed()=0
std::unique_ptr< weld::Container > m_xPanelParent
Definition: AppView.hxx:45
std::unique_ptr< weld::Container > m_xDetailViewParent
Definition: AppView.hxx:46
virtual void GetFocus() override
Definition: AppView.cxx:79
OApplicationSwapWindow * getPanel() const
Definition: AppView.cxx:85
std::unique_ptr< OTitleWindow > m_xPanel
Definition: AppView.hxx:47
virtual ~OAppBorderWindow() override
Definition: AppView.cxx:63
VclPtr< OApplicationView > m_xView
Definition: AppView.hxx:49
std::unique_ptr< OApplicationDetailView > m_xDetailView
Definition: AppView.hxx:48
virtual void dispose() override
Definition: AppView.cxx:68
sal_Int32 getElementCount() const
returns the count of entries
std::unique_ptr< weld::TreeIter > getEntry(const Point &rPosPixel) const
static bool isLeaf(const weld::TreeView &rTreeView, const weld::TreeIter &rEntry)
returns if an entry is a leaf
void selectAll()
select all entries in the detail page
OUString getQualifiedName(const weld::TreeIter *_pEntry) const
return the qualified name.
sal_Int32 getSelectionCount()
returns the count of selected entries
void elementRemoved(ElementType _eType, const OUString &_rName)
removes an element from the detail page.
void sortUp()
sort the entries in the detail page up
PreviewMode getPreviewMode() const
returns the preview mode
ElementType getElementType() const
return the element of currently select entry
std::unique_ptr< weld::TreeIter > elementAdded(ElementType eType, const OUString &rName, const css::uno::Any &rObject)
adds a new object to the detail page.
vcl::Window * getMenuParent() const
get the menu parent window for the given control
void selectElements(const css::uno::Sequence< OUString > &_aNames)
select all names on the currently selected container.
void describeCurrentSelectionForControl(const weld::TreeView &rControl, css::uno::Sequence< css::sdb::application::NamedDatabaseObject > &_out_rSelectedObjects)
describes the current selection for the given control
bool isALeafSelected() const
returns if one of the selected entries is a leaf
bool isPreviewEnabled() const
<TRUE> if the preview is enabled
bool isFilled() const
returns <TRUE> when a detail page was filled
void clearPages(bool _bTaskAlso=true)
clears the detail pages.
void showPreview(const css::uno::Reference< css::ucb::XContent > &_xContent)
shows the Preview of the content when it is enabled.
void describeCurrentSelectionForType(const ElementType _eType, css::uno::Sequence< css::sdb::application::NamedDatabaseObject > &_out_rSelectedObjects)
describes the current selection for the given ElementType
void elementReplaced(ElementType eType, const OUString &_rOldName, const OUString &_rNewName)
replaces an objects name with a new one
bool isSortUp() const
returns <TRUE> if it sorts ascending
void sortDown()
sort the entries in the detail page down
void switchPreview(PreviewMode _eMode)
switches to the given preview mode
void adjustMenuPosition(const weld::TreeView &rControl, ::Point &rPos) const
void getSelectionElementNames(std::vector< OUString > &_rNames) const
returns the element names which are selected
ElementType getElementType() const
return the element of currently select entry
void selectContainer(ElementType _eType)
changes the container which should be displayed.
void clearSelection()
clears the selection in the icon choice control and calls the handler
sal_Int32 getSelectionCount() const
returns the count of selected entries
Definition: AppView.cxx:294
OApplicationDetailView * getDetailView() const
get the detail page
Definition: AppView.hxx:127
bool isALeafSelected() const
returns if one of the selected entries is a leaf
Definition: AppView.cxx:252
bool isFilled() const
returns <TRUE> when a detail page was filled
Definition: AppView.cxx:282
virtual bool isPasteAllowed() override
Definition: AppView.cxx:213
std::unique_ptr< weld::TreeIter > elementAdded(ElementType eType, const OUString &rName, const css::uno::Any &rObject)
adds a new object to the detail page.
Definition: AppView.cxx:342
OApplicationView(vcl::Window *pParent, const css::uno::Reference< css::uno::XComponentContext > &, OApplicationController &_rAppController, PreviewMode _ePreviewMode)
Definition: AppView.cxx:90
PreviewMode getPreviewMode() const
returns the preview mode
Definition: AppView.cxx:382
OUString getQualifiedName(const weld::TreeIter *_pEntry) const
return the qualified name.
Definition: AppView.cxx:240
void showPreview(const css::uno::Reference< css::ucb::XContent > &_xContent)
shows the Preview of the content when it is enabled.
void elementReplaced(ElementType eType, const OUString &_rOldName, const OUString &_rNewName)
replaces an objects name with a new one
Definition: AppView.cxx:354
bool isPreviewEnabled() const
<TRUE> if the preview is enabled
Definition: AppView.cxx:388
void selectElements(const css::uno::Sequence< OUString > &_aNames)
select all names on the currently selected container.
Definition: AppView.cxx:336
virtual void GetFocus() override
Definition: AppView.cxx:446
virtual void dispose() override
Definition: AppView.cxx:109
void clearPages()
clears the detail page and the selection on the left side.
Definition: AppView.cxx:362
void getSelectionElementNames(std::vector< OUString > &_rNames) const
returns the element names which are selected
Definition: AppView.cxx:306
virtual bool isCopyAllowed() override
Definition: AppView.cxx:201
void selectAll()
select all entries in the detail page
Definition: AppView.cxx:258
css::uno::Reference< css::lang::XComponent > m_xObject
Definition: AppView.hxx:77
void switchPreview(PreviewMode _eMode)
switches to the given preview mode
Definition: AppView.cxx:394
bool isSortUp() const
returns <TRUE> if it sorts ascending
Definition: AppView.cxx:264
void elementRemoved(ElementType _eType, const OUString &_rName)
removes an element from the detail page.
Definition: AppView.cxx:348
virtual bool PreNotify(NotifyEvent &rNEvt) override
Definition: AppView.cxx:173
ElementType getElementType() const
return the element of currently select entry
Definition: AppView.cxx:288
void sortDown()
sort the entries in the detail page down
Definition: AppView.cxx:270
virtual void resizeDocumentView(tools::Rectangle &rRect) override
Definition: AppView.cxx:145
sal_Int32 getElementCount() const
returns the count of entries
Definition: AppView.cxx:300
void selectContainer(ElementType _eType)
changes the container which should be displayed.
Definition: AppView.cxx:369
void createIconAutoMnemonics(MnemonicGenerator &_rMnemonics)
automatically creates mnemonics for the icon/texts in our left hand side panel
Definition: AppView.cxx:118
vcl::Window * getMenuParent() const
get the menu parent window for the given control
Definition: AppView.cxx:318
void describeCurrentSelectionForType(const ElementType _eType, css::uno::Sequence< css::sdb::application::NamedDatabaseObject > &_out_rSelectedObjects)
describes the current selection for the given ElementType
Definition: AppView.cxx:330
virtual void paste() override
Definition: AppView.cxx:233
void sortUp()
sort the entries in the detail page up
Definition: AppView.cxx:276
IClipboardTest * getActiveChild() const
Definition: AppView.cxx:193
virtual void cut() override
Definition: AppView.cxx:226
virtual void _disposing(const css::lang::EventObject &_rSource) override
Definition: AppView.cxx:452
void adjustMenuPosition(const weld::TreeView &rControl, ::Point &rPos) const
adjust rPos relative to rControl to instead relative to getMenuParent
Definition: AppView.cxx:324
void describeCurrentSelectionForControl(const weld::TreeView &rControl, css::uno::Sequence< css::sdb::application::NamedDatabaseObject > &_out_rSelectedObjects)
describes the current selection for the given control
Definition: AppView.cxx:312
virtual void copy() override
Definition: AppView.cxx:219
std::unique_ptr< weld::TreeIter > getEntry(const Point &rPosPixel) const
Definition: AppView.cxx:376
ChildFocusState getChildFocus() const
Definition: AppView.cxx:161
OApplicationSwapWindow * getPanel() const
get the left panel
Definition: AppView.hxx:125
virtual bool isCutAllowed() override
Definition: AppView.cxx:207
VclPtr< OAppBorderWindow > m_pWin
Definition: AppView.hxx:78
bool isLeaf(const weld::TreeView &rTreeView, const weld::TreeIter &rEntry) const
returns if an entry is a leaf
Definition: AppView.cxx:246
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: AppView.cxx:130
virtual ~OApplicationView() override
Definition: AppView.cxx:104
void setTaskExternalMnemonics(MnemonicGenerator const &_rMnemonics)
automatically creates mnemonics for the texts in our task pane
Definition: AppView.cxx:124
virtual void dispose() override
Definition: dataview.cxx:58
virtual bool PreNotify(NotifyEvent &rNEvt) override
Definition: dataview.cxx:96
void SetSize(const Size &)
constexpr Point TopLeft() const
void SetPos(const Point &rPoint)
constexpr Size GetSize() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
constexpr Point BottomRight() const
constexpr bool IsEmpty() const
void startComponentListening(const css::uno::Reference< css::lang::XComponent > &_rxComp)
void stopComponentListening(const css::uno::Reference< css::lang::XComponent > &_rxComp)
void SetColor(const Color &)
void SetStyle(WinBits nStyle)
bool HasChildPathFocus(bool bSystemWindow=false) const
Point LogicToPixel(const Point &rLogicPt) const
WinBits GetStyle() const
const AllSettings & GetSettings() const
void SetTextFillColor()
::OutputDevice const * GetOutDev() const
virtual void DataChanged(const DataChangedEvent &rDCEvt)
void SetPointFont(vcl::RenderContext &rRenderContext, const vcl::Font &rFont)
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
weld::Window * GetFrameWeld() const
void SetTextColor(const Color &rColor)
void SetBackground()
#define DBG_UNHANDLED_EXCEPTION(...)
OUString eType
Definition: generalpage.cxx:78
@ Exception
WinBits const WB_DIALOGCONTROL