Line data Source code
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 : #ifndef DBAUI_APPDETAILPAGEHELPER_HXX
20 : #define DBAUI_APPDETAILPAGEHELPER_HXX
21 :
22 : #include <vector>
23 :
24 : #include <rtl/ustring.hxx>
25 : #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
26 : #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
27 : #include <com/sun/star/ucb/XContent.hpp>
28 : #include "AppElementType.hxx"
29 : #include <svtools/treelistbox.hxx>
30 : #include <svtools/DocumentInfoPreview.hxx>
31 : #include <vcl/fixed.hxx>
32 : #include <vcl/toolbox.hxx>
33 : #include <vcl/cvtgrf.hxx>
34 : #include <vcl/graph.hxx>
35 : #include <svtools/grfmgr.hxx>
36 : #include "callbacks.hxx"
37 : #include <memory>
38 :
39 : namespace com{ namespace sun { namespace star { namespace awt { class XWindow; } } } }
40 : namespace com{ namespace sun { namespace star { namespace frame { class XFrame; } } } }
41 : namespace com{ namespace sun { namespace star { namespace io { class XPersist; } } } }
42 :
43 : #define ELEMENT_COUNT size_t(E_ELEMENT_TYPE_COUNT)
44 :
45 : namespace dbaui
46 : {
47 : class OAppBorderWindow;
48 : class DBTreeListBox;
49 :
50 0 : class OPreviewWindow : public Window
51 : {
52 : GraphicObject m_aGraphicObj;
53 : Rectangle m_aPreviewRect;
54 :
55 : /** gets the graphic cnter rect
56 : @param rGraphic
57 : the graphic
58 : @param rResultRect
59 : the resulting rectangle
60 :
61 : @return
62 : <TRUE/> when successfull
63 : */
64 : sal_Bool ImplGetGraphicCenterRect( const Graphic& rGraphic, Rectangle& rResultRect ) const;
65 : void ImplInitSettings( sal_Bool bFont, sal_Bool bForeground, sal_Bool bBackground );
66 : protected:
67 : virtual void DataChanged(const DataChangedEvent& rDCEvt);
68 : public:
69 : OPreviewWindow(Window* _pParent);
70 :
71 : // window overloads
72 : virtual void Paint(const Rectangle& rRect);
73 :
74 0 : void setGraphic(const Graphic& _rGraphic ) { m_aGraphicObj.SetGraphic(_rGraphic); }
75 : };
76 : //==================================================================
77 : // A helper class for the controls in the detail page.
78 : // Combines general functionality.
79 : //==================================================================
80 : class OAppDetailPageHelper : public Window
81 : {
82 : DBTreeListBox* m_pLists[ELEMENT_COUNT];
83 : OAppBorderWindow& m_rBorderWin;
84 : FixedLine m_aFL;
85 : ToolBox m_aTBPreview;
86 : Window m_aBorder;
87 : OPreviewWindow m_aPreview;
88 : ::svtools::ODocumentInfoPreview
89 : m_aDocumentInfo;
90 : Window* m_pTablePreview;
91 : ::std::auto_ptr<PopupMenu> m_aMenu;
92 : PreviewMode m_ePreviewMode;
93 : ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame >
94 : m_xFrame;
95 : ::com::sun::star::uno::Reference < ::com::sun::star::io::XPersist >
96 : m_xDocInfo;
97 : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindow >
98 : m_xWindow;
99 :
100 : /// returns the index of the visible control
101 : int getVisibleControlIndex() const;
102 :
103 : /** sorts the entries in the tree list box.
104 : @param _nPos
105 : Which list should be sorted.
106 : @param _eSortMode
107 : How should be sorted.
108 : */
109 : void sort(int _nPos,SvSortMode _eSortMode );
110 :
111 : /** retrieves the resource ids of the images representing elements of the given type
112 : */
113 : void getElementIcons( ElementType _eType, sal_uInt16& _rImageId);
114 :
115 : /** fills the names in the listbox
116 : @param _xContainer
117 : This can either be the queries, forms or report names.
118 : @param _eType
119 : the type of elements which are being filled
120 : @param _nImageId
121 : the resource id of the image to use for non-container entries
122 : @param _pParent
123 : The parent of the entries to be inserted.
124 : */
125 : void fillNames( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xContainer,
126 : const ElementType _eType,
127 : const sal_uInt16 _nImageId,
128 : SvTreeListEntry* _pParent );
129 :
130 : /** sets the detail page
131 : @param _pWindow
132 : The control which should be visible.
133 : */
134 : void setDetailPage(Window* _pWindow);
135 :
136 : /** sets all HandleCallbacks
137 : @param _pTreeView
138 : The newly created DBTreeListBox
139 : @param _rImage
140 : the resource id of the default icon
141 : @return
142 : The new tree.
143 : */
144 : DBTreeListBox* createTree( DBTreeListBox* _pTreeView, const Image& _rImage );
145 :
146 : /** creates the tree and sets all HandleCallbacks
147 : @param _nHelpId
148 : The help id of the control
149 : @param _nCollapsedBitmap
150 : The image to use in high contrast mode.
151 : @return
152 : The new tree.
153 : */
154 : DBTreeListBox* createSimpleTree( const rtl::OString& _sHelpId, const Image& _rImage);
155 :
156 : DECL_LINK( OnEntryDoubleClick, SvTreeListBox* );
157 : DECL_LINK( OnEntrySelChange, void* );
158 :
159 : DECL_LINK( OnCutEntry, void* );
160 : DECL_LINK( OnCopyEntry, void* );
161 : DECL_LINK( OnPasteEntry, void* );
162 : DECL_LINK( OnDeleteEntry, void* );
163 :
164 : DECL_LINK(PreviewChangeHdl, void*);
165 : // click a TB slot
166 : DECL_LINK(OnDropdownClickHdl, ToolBox*);
167 :
168 0 : inline OAppBorderWindow& getBorderWin() const { return m_rBorderWin; }
169 : void ImplInitSettings();
170 :
171 : public:
172 : OAppDetailPageHelper(Window* _pParent,OAppBorderWindow& _rBorderWin,PreviewMode _ePreviewMode);
173 : virtual ~OAppDetailPageHelper();
174 :
175 : // window overloads
176 : virtual void Resize();
177 : virtual void KeyInput( const KeyEvent& rKEvt );
178 :
179 : sal_Bool isCutAllowed();
180 : sal_Bool isCopyAllowed();
181 : sal_Bool isPasteAllowed();
182 : void copy();
183 : void cut();
184 : void paste();
185 :
186 : /** creates the tables page
187 : @param _xConnection
188 : The connection to get the table names
189 : */
190 : void createTablesPage(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection);
191 :
192 : /** creates the page for the specific type.
193 : @param _eType
194 : The type which should be created. E_TABLE isn't allowed.
195 : @param _xContainer
196 : The container of the elements to be inserted.
197 : */
198 : void createPage(ElementType _eType,const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xContainer);
199 :
200 : /** returns the current visible tree list box
201 : */
202 0 : inline DBTreeListBox* getCurrentView() const
203 : {
204 0 : ElementType eType = getElementType();
205 0 : return (eType != E_NONE ) ? m_pLists[static_cast<sal_Int32>(eType)] : NULL;
206 : }
207 :
208 : /// select all entries in the visible control
209 : void selectAll();
210 :
211 : /// returns <TRUE/> if it sorts ascending
212 : sal_Bool isSortUp() const;
213 :
214 : /// sorts all entries ascending
215 : void sortDown();
216 :
217 : /// sorts all entries descending
218 : void sortUp();
219 :
220 : /** returns the element names which are selected
221 : @param _rNames
222 : The list will be filled.
223 : */
224 : void getSelectionElementNames( ::std::vector< ::rtl::OUString>& _rNames ) const;
225 :
226 : /** describes the current selection for the given control
227 : */
228 : void describeCurrentSelectionForControl(
229 : const Control& _rControl,
230 : ::com::sun::star::uno::Sequence< ::com::sun::star::sdb::application::NamedDatabaseObject >& _out_rSelectedObjects
231 : );
232 :
233 : /** describes the current selection for the given ElementType
234 : */
235 : void describeCurrentSelectionForType(
236 : const ElementType _eType,
237 : ::com::sun::star::uno::Sequence< ::com::sun::star::sdb::application::NamedDatabaseObject >& _out_rSelectedObjects
238 : );
239 :
240 : /** select all names on the currently selected container. Non existence names where ignored.
241 : *
242 : * \param _aNames the element names
243 : */
244 : void selectElements(const ::com::sun::star::uno::Sequence< ::rtl::OUString>& _aNames);
245 :
246 : /** return the qualified name.
247 : @param _pEntry
248 : The entry of a table, or query, form, report to get the qualified name.
249 : If the entry is <NULL/>, the first selected is chosen.
250 : @return
251 : the qualified name
252 : */
253 : ::rtl::OUString getQualifiedName( SvTreeListEntry* _pEntry ) const;
254 :
255 : /// return the element of currently select entry
256 : ElementType getElementType() const;
257 :
258 : /// returns the count of selected entries
259 : sal_Int32 getSelectionCount();
260 :
261 : /// returns the count of entries
262 : sal_Int32 getElementCount();
263 :
264 : /** returns if an entry is a leaf
265 : @param _pEntry
266 : The entry to check
267 : @return
268 : <TRUE/> if the entry is a leaf, otherwise <FALSE/>
269 : */
270 : bool isLeaf(SvTreeListEntry* _pEntry) const;
271 :
272 : /** returns if one of the selected entries is a leaf
273 : @return
274 : <TRUE/> if the entry is a leaf, otherwise <FALSE/>
275 : */
276 : sal_Bool isALeafSelected() const;
277 :
278 : SvTreeListEntry* getEntry( const Point& _aPosPixel ) const;
279 :
280 : /// clears the detail pages
281 : void clearPages();
282 :
283 : /// returns <TRUE/> when a detail page was filled
284 : sal_Bool isFilled() const;
285 :
286 : /** adds a new object to the detail page.
287 : @param _eType
288 : The type where the entry shold be appended.
289 : @param _rName
290 : The name of the object to be inserted
291 : @param _rObject
292 : The object to add.
293 : @param _rxConn
294 : If we insert a table, the connection must be set.
295 : */
296 : SvTreeListEntry* elementAdded(ElementType eType
297 : ,const ::rtl::OUString& _rName
298 : ,const ::com::sun::star::uno::Any& _rObject );
299 :
300 : /** replaces a objects name with a new one
301 : @param _eType
302 : The type where the entry shold be appended.
303 : @param _rOldName
304 : The old name of the object to be replaced
305 : @param _rNewName
306 : The new name of the object to be replaced
307 : @param _rxConn
308 : If we insert a table, the connection must be set.
309 : */
310 : void elementReplaced(ElementType eType
311 : ,const ::rtl::OUString& _rOldName
312 : ,const ::rtl::OUString& _rNewName );
313 :
314 : /** removes an element from the detail page.
315 : @param _eType
316 : The type where the entry shold be appended.
317 : @param _rName
318 : The name of the element to be removed.
319 : @param _rxConn
320 : If we remove a table, the connection must be set.
321 : */
322 : void elementRemoved(ElementType _eType
323 : ,const ::rtl::OUString& _rName );
324 :
325 :
326 : /// returns the preview mode
327 : PreviewMode getPreviewMode();
328 :
329 : /// <TRUE/> if the preview is enabled
330 : sal_Bool isPreviewEnabled();
331 :
332 : /** switches to the given preview mode
333 : @param _eMode
334 : the mode to set for the preview
335 : @param _bForce
336 : Force the preview to be resetted
337 : */
338 : void switchPreview(PreviewMode _eMode,sal_Bool _bForce = sal_False);
339 :
340 : /** shows the Preview of the content when it is enabled.
341 : @param _xContent
342 : The content which must support the "preview" command.
343 : */
344 : void showPreview(const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XContent >& _xContent);
345 :
346 : /** shows the Preview of a table or query
347 : @param _sDataSourceName
348 : the name of the data source
349 : @param _sName
350 : the name of table or query
351 : @param _bTable
352 : <TRUE/> if it is a table, otherwise <FALSE/>
353 : @return void
354 : */
355 : void showPreview( const ::rtl::OUString& _sDataSourceName,
356 : const ::rtl::OUString& _sName,
357 : sal_Bool _bTable);
358 :
359 : protected:
360 : void DataChanged( const DataChangedEvent& rDCEvt );
361 : };
362 : }
363 : #endif // DBAUI_APPDETAILPAGEHELPER_HXX
364 :
365 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|