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