xref: /AOO41X/main/svtools/inc/svtools/addresstemplate.hxx (revision 01aa44aa134af97080e2cf8e8bf3a0a4cd1cffe0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _SVT_ADDRESSTEMPLATE_HXX_
25 #define _SVT_ADDRESSTEMPLATE_HXX_
26 
27 #include "svtools/svtdllapi.h"
28 #include <vcl/dialog.hxx>
29 #include <vcl/group.hxx>
30 #include <vcl/fixed.hxx>
31 #include <vcl/combobox.hxx>
32 #include <vcl/button.hxx>
33 #include <vcl/lstbox.hxx>
34 #include <vcl/scrbar.hxx>
35 #include <com/sun/star/container/XNameAccess.hpp>
36 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP_
37 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
38 #endif
39 #include <com/sun/star/util/AliasProgrammaticPair.hpp>
40 #include <com/sun/star/sdbc/XDataSource.hpp>
41 #include <unotools/configitem.hxx>
42 
43 // .......................................................................
44 namespace svt
45 {
46 // .......................................................................
47 
48     // ===================================================================
49     // = AddressBookSourceDialog
50     // ===================================================================
51     struct AddressBookSourceDialogData;
52     class SVT_DLLPUBLIC AddressBookSourceDialog : public ModalDialog
53     {
54     protected:
55         // Controls
56         FixedLine       m_aDatasourceFrame;
57         FixedText       m_aDatasourceLabel;
58         ComboBox        m_aDatasource;
59         PushButton      m_aAdministrateDatasources;
60         FixedText       m_aTableLabel;
61         ComboBox        m_aTable;
62 
63         FixedText       m_aFieldsTitle;
64         Window          m_aFieldsFrame;
65 
66         ScrollBar       m_aFieldScroller;
67         OKButton        m_aOK;
68         CancelButton    m_aCancel;
69         HelpButton      m_aHelp;
70 
71         // string to display for "no selection"
72         const String    m_sNoFieldSelection;
73 
74         /// the DatabaseContext for selecting data sources
75         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
76                         m_xDatabaseContext;
77         // the ORB for creating objects
78         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
79                         m_xORB;
80         ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
81                         m_xCurrentDatasourceTables;
82 
83         AddressBookSourceDialogData*
84                         m_pImpl;
85 
86     public:
87         AddressBookSourceDialog( Window* _pParent,
88             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB );
89 
90         /** if you use this ctor, the dialog
91             <ul><li>will not store it's data in the configuration (nor initially retrieve it from there)</li>
92                 <li>will not allow to change the data source name</li>
93                 <li>will not allow to change the table name</li>
94                 <li>will not allow to call the data source administration dialog</li>
95             </ul>
96 
97             @param _rxORB
98                 a service factory to use for various UNO related needs
99             @param _rxTransientDS
100                 the data source to obtain connections from
101             @param _rDataSourceName
102                 the to-be name of _rxTransientDS. This is only for displaying this
103                 name to the user, since the dialog completely works on _rxTransientDS,
104                 and doesn't allow to change this.
105             @param _rTable
106                 the table name to display. It must refer to a valid table, relative to a connection
107                 obtained from <arg>_rxTransientDS</arg>
108         */
109         AddressBookSourceDialog( Window* _pParent,
110             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,
111             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource >& _rxTransientDS,
112             const ::rtl::OUString& _rDataSourceName,
113             const ::rtl::OUString& _rTable,
114             const ::com::sun::star::uno::Sequence< ::com::sun::star::util::AliasProgrammaticPair >& _rMapping
115         );
116 
117         ~AddressBookSourceDialog();
118 
119         // to be used if the object was constructed for editing a field mapping only
120         void        getFieldMapping(
121             ::com::sun::star::uno::Sequence< ::com::sun::star::util::AliasProgrammaticPair >& _rMapping) const;
122 
123     protected:
124         void    implConstruct();
125 
126         // Window overridables
127         virtual long        PreNotify( NotifyEvent& _rNEvt );
128 
129         // implementations
130         void    implScrollFields(sal_Int32 _nPos, sal_Bool _bAdjustFocus, sal_Bool _bAdjustScrollbar);
131         void    implSelectField(ListBox* _pBox, const String& _rText);
132 
133         void    initalizeListBox(ListBox* _pList);
134         void    resetTables();
135         void    resetFields();
136 
137         // fill in the data sources listbox
138         void    initializeDatasources();
139 
140         // initialize the dialog from the configuration data
141         void    loadConfiguration();
142 
143         DECL_LINK(OnFieldScroll, ScrollBar*);
144         DECL_LINK(OnFieldSelect, ListBox*);
145         DECL_LINK(OnAdministrateDatasources, void*);
146         DECL_LINK(OnComboGetFocus, ComboBox*);
147         DECL_LINK(OnComboLoseFocus, ComboBox*);
148         DECL_LINK(OnComboSelect, ComboBox*);
149         DECL_LINK(OnOkClicked, Button*);
150         DECL_LINK(OnDelayedInitialize, void*);
151     };
152 
153 
154 // .......................................................................
155 }   // namespace svt
156 // .......................................................................
157 
158 #endif // _SVT_ADDRESSTEMPLATE_HXX_
159 
160