xref: /trunk/main/extensions/source/dbpilots/gridwizard.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include "gridwizard.hxx"
27cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
28cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
29cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
30cdf0e10cSrcweir #include <tools/string.hxx>
31cdf0e10cSrcweir #include <com/sun/star/form/XGridColumnFactory.hpp>
32cdf0e10cSrcweir #include <com/sun/star/awt/MouseWheelBehavior.hpp>
33cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
34cdf0e10cSrcweir #include <tools/debug.hxx>
35cdf0e10cSrcweir #include "dbptools.hxx"
36cdf0e10cSrcweir #include "dbpilots.hrc"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #define GW_STATE_DATASOURCE_SELECTION   0
39cdf0e10cSrcweir #define GW_STATE_FIELDSELECTION         1
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //.........................................................................
42cdf0e10cSrcweir namespace dbp
43cdf0e10cSrcweir {
44cdf0e10cSrcweir //.........................................................................
45cdf0e10cSrcweir 
46cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
47cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
48cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
49cdf0e10cSrcweir     using namespace ::com::sun::star::sdbc;
50cdf0e10cSrcweir     using namespace ::com::sun::star::container;
51cdf0e10cSrcweir     using namespace ::com::sun::star::form;
52cdf0e10cSrcweir     using namespace ::com::sun::star::awt;
53cdf0e10cSrcweir     using namespace ::svt;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     //=====================================================================
56cdf0e10cSrcweir     //= OGridWizard
57cdf0e10cSrcweir     //=====================================================================
58cdf0e10cSrcweir     //---------------------------------------------------------------------
OGridWizard(Window * _pParent,const Reference<XPropertySet> & _rxObjectModel,const Reference<XMultiServiceFactory> & _rxORB)59cdf0e10cSrcweir     OGridWizard::OGridWizard( Window* _pParent,
60cdf0e10cSrcweir             const Reference< XPropertySet >& _rxObjectModel, const Reference< XMultiServiceFactory >& _rxORB )
61cdf0e10cSrcweir         :OControlWizard(_pParent, ModuleRes(RID_DLG_GRIDWIZARD), _rxObjectModel, _rxORB)
62cdf0e10cSrcweir         ,m_bHadDataSelection(sal_True)
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         initControlSettings(&m_aSettings);
65cdf0e10cSrcweir 
66cdf0e10cSrcweir         m_pPrevPage->SetHelpId(HID_GRIDWIZARD_PREVIOUS);
67cdf0e10cSrcweir         m_pNextPage->SetHelpId(HID_GRIDWIZARD_NEXT);
68cdf0e10cSrcweir         m_pCancel->SetHelpId(HID_GRIDWIZARD_CANCEL);
69cdf0e10cSrcweir         m_pFinish->SetHelpId(HID_GRIDWIZARD_FINISH);
70cdf0e10cSrcweir 
71cdf0e10cSrcweir         // if we do not need the data source selection page ...
72cdf0e10cSrcweir         if (!needDatasourceSelection())
73cdf0e10cSrcweir         {   // ... skip it!
74cdf0e10cSrcweir             skip(1);
75cdf0e10cSrcweir             m_bHadDataSelection = sal_False;
76cdf0e10cSrcweir         }
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     //---------------------------------------------------------------------
approveControl(sal_Int16 _nClassId)80cdf0e10cSrcweir     sal_Bool OGridWizard::approveControl(sal_Int16 _nClassId)
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         if (FormComponentType::GRIDCONTROL != _nClassId)
83cdf0e10cSrcweir             return sal_False;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         Reference< XGridColumnFactory > xColumnFactory(getContext().xObjectModel, UNO_QUERY);
86cdf0e10cSrcweir         if (!xColumnFactory.is())
87cdf0e10cSrcweir             return sal_False;
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         return sal_True;
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     //---------------------------------------------------------------------
implApplySettings()93cdf0e10cSrcweir     void OGridWizard::implApplySettings()
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         const OControlWizardContext& rContext = getContext();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         // the factory for the columns
98cdf0e10cSrcweir         Reference< XGridColumnFactory > xColumnFactory(rContext.xObjectModel, UNO_QUERY);
99cdf0e10cSrcweir         DBG_ASSERT(xColumnFactory.is(), "OGridWizard::implApplySettings: should never have made it 'til here!");
100cdf0e10cSrcweir             // (if we're here, what the hell happened in approveControl??)
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         // the container for the columns
103cdf0e10cSrcweir         Reference< XNameContainer > xColumnContainer(rContext.xObjectModel, UNO_QUERY);
104cdf0e10cSrcweir         DBG_ASSERT(xColumnContainer.is(), "OGridWizard::implApplySettings: no container!");
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         if (!xColumnFactory.is() || !xColumnContainer.is())
107cdf0e10cSrcweir             return;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         static const ::rtl::OUString s_sDataFieldProperty   = ::rtl::OUString::createFromAscii("DataField");
110cdf0e10cSrcweir         static const ::rtl::OUString s_sLabelProperty       = ::rtl::OUString::createFromAscii("Label");
111cdf0e10cSrcweir         static const ::rtl::OUString s_sWidthProperty       = ::rtl::OUString::createFromAscii("Width");
112cdf0e10cSrcweir         static const ::rtl::OUString s_sMouseWheelBehavior  = ::rtl::OUString::createFromAscii("MouseWheelBehavior");
113cdf0e10cSrcweir         static const ::rtl::OUString s_sEmptyString;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir         // collect "descriptors" for the to-be-created (grid)columns
116cdf0e10cSrcweir         DECLARE_STL_VECTOR( ::rtl::OUString, StringArray );
117cdf0e10cSrcweir         StringArray aColumnServiceNames;    // service names to be used with the XGridColumnFactory
118cdf0e10cSrcweir         StringArray aColumnLabelPostfixes;  // postfixes to append to the column labels
119cdf0e10cSrcweir         StringArray aFormFieldNames;        // data field names
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         aColumnServiceNames.reserve(getSettings().aSelectedFields.getLength());
122cdf0e10cSrcweir         aColumnLabelPostfixes.reserve(getSettings().aSelectedFields.getLength());
123cdf0e10cSrcweir         aFormFieldNames.reserve(getSettings().aSelectedFields.getLength());
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         // loop through the selected field names
126cdf0e10cSrcweir         const ::rtl::OUString* pSelectedFields = getSettings().aSelectedFields.getConstArray();
127cdf0e10cSrcweir         const ::rtl::OUString* pEnd = pSelectedFields + getSettings().aSelectedFields.getLength();
128cdf0e10cSrcweir         for (;pSelectedFields < pEnd; ++pSelectedFields)
129cdf0e10cSrcweir         {
130cdf0e10cSrcweir             // get the information for the selected column
131cdf0e10cSrcweir             sal_Int32 nFieldType = DataType::OTHER;
132cdf0e10cSrcweir             OControlWizardContext::TNameTypeMap::const_iterator aFind = rContext.aTypes.find(*pSelectedFields);
133cdf0e10cSrcweir             if ( aFind != rContext.aTypes.end() )
134cdf0e10cSrcweir                 nFieldType = aFind->second;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir             aFormFieldNames.push_back(*pSelectedFields);
137cdf0e10cSrcweir             switch (nFieldType)
138cdf0e10cSrcweir             {
139cdf0e10cSrcweir                 case DataType::BIT:
140cdf0e10cSrcweir                 case DataType::BOOLEAN:
141cdf0e10cSrcweir                     aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("CheckBox"));
142cdf0e10cSrcweir                     aColumnLabelPostfixes.push_back(s_sEmptyString);
143cdf0e10cSrcweir                     break;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir                 case DataType::TINYINT:
146cdf0e10cSrcweir                 case DataType::SMALLINT:
147cdf0e10cSrcweir                 case DataType::INTEGER:
148cdf0e10cSrcweir                     aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("NumericField"));
149cdf0e10cSrcweir                     aColumnLabelPostfixes.push_back(s_sEmptyString);
150cdf0e10cSrcweir                     break;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir                 case DataType::FLOAT:
153cdf0e10cSrcweir                 case DataType::REAL:
154cdf0e10cSrcweir                 case DataType::DOUBLE:
155cdf0e10cSrcweir                 case DataType::NUMERIC:
156cdf0e10cSrcweir                 case DataType::DECIMAL:
157cdf0e10cSrcweir                     aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("FormattedField"));
158cdf0e10cSrcweir                     aColumnLabelPostfixes.push_back(s_sEmptyString);
159cdf0e10cSrcweir                     break;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir                 case DataType::DATE:
162cdf0e10cSrcweir                     aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("DateField"));
163cdf0e10cSrcweir                     aColumnLabelPostfixes.push_back(s_sEmptyString);
164cdf0e10cSrcweir                     break;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir                 case DataType::TIME:
167cdf0e10cSrcweir                     aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("TimeField"));
168cdf0e10cSrcweir                     aColumnLabelPostfixes.push_back(s_sEmptyString);
169cdf0e10cSrcweir                     break;
170cdf0e10cSrcweir 
171cdf0e10cSrcweir                 case DataType::TIMESTAMP:
172cdf0e10cSrcweir                     aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("DateField"));
173cdf0e10cSrcweir                     aColumnLabelPostfixes.push_back(String(ModuleRes(RID_STR_DATEPOSTFIX)));
174cdf0e10cSrcweir 
175cdf0e10cSrcweir                     aFormFieldNames.push_back(*pSelectedFields);
176cdf0e10cSrcweir                     aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("TimeField"));
177cdf0e10cSrcweir                     aColumnLabelPostfixes.push_back(String(ModuleRes(RID_STR_TIMEPOSTFIX)));
178cdf0e10cSrcweir                     break;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir                 default:
181cdf0e10cSrcweir                     aColumnServiceNames.push_back(::rtl::OUString::createFromAscii("TextField"));
182cdf0e10cSrcweir                     aColumnLabelPostfixes.push_back(s_sEmptyString);
183cdf0e10cSrcweir             }
184cdf0e10cSrcweir         }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         DBG_ASSERT( aFormFieldNames.size() == aColumnServiceNames.size()
187cdf0e10cSrcweir                 &&  aColumnServiceNames.size() == aColumnLabelPostfixes.size(),
188cdf0e10cSrcweir                 "OGridWizard::implApplySettings: inconsistent descriptor sequences!");
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         // now loop through the descriptions and create the (grid)columns out of th descriptors
191cdf0e10cSrcweir         {
192cdf0e10cSrcweir             Reference< XNameAccess > xExistenceChecker(xColumnContainer.get());
193cdf0e10cSrcweir 
194cdf0e10cSrcweir             ConstStringArrayIterator pColumnServiceName = aColumnServiceNames.begin();
195cdf0e10cSrcweir             ConstStringArrayIterator pColumnLabelPostfix = aColumnLabelPostfixes.begin();
196cdf0e10cSrcweir             ConstStringArrayIterator pFormFieldName = aFormFieldNames.begin();
197cdf0e10cSrcweir             ConstStringArrayIterator pColumnServiceNameEnd = aColumnServiceNames.end();
198cdf0e10cSrcweir 
199cdf0e10cSrcweir             for (;pColumnServiceName < pColumnServiceNameEnd; ++pColumnServiceName, ++pColumnLabelPostfix, ++pFormFieldName)
200cdf0e10cSrcweir             {
201cdf0e10cSrcweir                 // create a (grid)column for the (resultset)column
202cdf0e10cSrcweir                 try
203cdf0e10cSrcweir                 {
204cdf0e10cSrcweir                     Reference< XPropertySet > xColumn( xColumnFactory->createColumn(*pColumnServiceName), UNO_SET_THROW );
205cdf0e10cSrcweir                     Reference< XPropertySetInfo > xColumnPSI( xColumn->getPropertySetInfo(), UNO_SET_THROW );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir                     ::rtl::OUString sColumnName(*pColumnServiceName);
208cdf0e10cSrcweir                     disambiguateName(xExistenceChecker, sColumnName);
209cdf0e10cSrcweir 
210cdf0e10cSrcweir                     // the data field the column should be bound to
211cdf0e10cSrcweir                     xColumn->setPropertyValue(s_sDataFieldProperty, makeAny(*pFormFieldName));
212cdf0e10cSrcweir                     // the label
213cdf0e10cSrcweir                     xColumn->setPropertyValue(s_sLabelProperty, makeAny(::rtl::OUString(*pFormFieldName) += *pColumnLabelPostfix));
214cdf0e10cSrcweir                     // the width (<void/> => column will be auto-sized)
215cdf0e10cSrcweir                     xColumn->setPropertyValue(s_sWidthProperty, Any());
216cdf0e10cSrcweir 
217cdf0e10cSrcweir                     if ( xColumnPSI->hasPropertyByName( s_sMouseWheelBehavior ) )
218cdf0e10cSrcweir                         xColumn->setPropertyValue( s_sMouseWheelBehavior, makeAny( MouseWheelBehavior::SCROLL_DISABLED ) );
219cdf0e10cSrcweir 
220cdf0e10cSrcweir                     // insert the column
221cdf0e10cSrcweir                     xColumnContainer->insertByName(sColumnName, makeAny(xColumn));
222cdf0e10cSrcweir                 }
223cdf0e10cSrcweir                 catch(Exception&)
224cdf0e10cSrcweir                 {
225cdf0e10cSrcweir                     DBG_ERROR(  ::rtl::OString("OGridWizard::implApplySettings: unexpected exception while creating the grid column for field ")
226cdf0e10cSrcweir                             +=  ::rtl::OString(pFormFieldName->getStr(), pFormFieldName->getLength(), gsl_getSystemTextEncoding())
227cdf0e10cSrcweir                             +=  ::rtl::OString("!"));
228cdf0e10cSrcweir                 }
229cdf0e10cSrcweir             }
230cdf0e10cSrcweir         }
231cdf0e10cSrcweir     }
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     //---------------------------------------------------------------------
createPage(WizardState _nState)234cdf0e10cSrcweir     OWizardPage* OGridWizard::createPage(WizardState _nState)
235cdf0e10cSrcweir     {
236cdf0e10cSrcweir         switch (_nState)
237cdf0e10cSrcweir         {
238cdf0e10cSrcweir             case GW_STATE_DATASOURCE_SELECTION:
239cdf0e10cSrcweir                 return new OTableSelectionPage(this);
240cdf0e10cSrcweir             case GW_STATE_FIELDSELECTION:
241cdf0e10cSrcweir                 return new OGridFieldsSelection(this);
242cdf0e10cSrcweir         }
243cdf0e10cSrcweir 
244cdf0e10cSrcweir         return NULL;
245cdf0e10cSrcweir     }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     //---------------------------------------------------------------------
determineNextState(WizardState _nCurrentState) const248cdf0e10cSrcweir     WizardTypes::WizardState OGridWizard::determineNextState( WizardState _nCurrentState ) const
249cdf0e10cSrcweir     {
250cdf0e10cSrcweir         switch (_nCurrentState)
251cdf0e10cSrcweir         {
252cdf0e10cSrcweir             case GW_STATE_DATASOURCE_SELECTION:
253cdf0e10cSrcweir                 return GW_STATE_FIELDSELECTION;
254cdf0e10cSrcweir             case GW_STATE_FIELDSELECTION:
255cdf0e10cSrcweir                 return WZS_INVALID_STATE;
256cdf0e10cSrcweir         }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir         return WZS_INVALID_STATE;
259cdf0e10cSrcweir     }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir     //---------------------------------------------------------------------
enterState(WizardState _nState)262cdf0e10cSrcweir     void OGridWizard::enterState(WizardState _nState)
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir         OControlWizard::enterState(_nState);
265cdf0e10cSrcweir 
266cdf0e10cSrcweir         enableButtons(WZB_PREVIOUS, m_bHadDataSelection ? (GW_STATE_DATASOURCE_SELECTION < _nState) : GW_STATE_FIELDSELECTION < _nState);
267cdf0e10cSrcweir         enableButtons(WZB_NEXT, GW_STATE_FIELDSELECTION != _nState);
268cdf0e10cSrcweir         if (_nState < GW_STATE_FIELDSELECTION)
269cdf0e10cSrcweir             enableButtons(WZB_FINISH, sal_False);
270cdf0e10cSrcweir 
271cdf0e10cSrcweir         if (GW_STATE_FIELDSELECTION == _nState)
272cdf0e10cSrcweir             defaultButton(WZB_FINISH);
273cdf0e10cSrcweir     }
274cdf0e10cSrcweir 
275cdf0e10cSrcweir     //---------------------------------------------------------------------
leaveState(WizardState _nState)276cdf0e10cSrcweir     sal_Bool OGridWizard::leaveState(WizardState _nState)
277cdf0e10cSrcweir     {
278cdf0e10cSrcweir         if (!OControlWizard::leaveState(_nState))
279cdf0e10cSrcweir             return sal_False;
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         if (GW_STATE_FIELDSELECTION == _nState)
282cdf0e10cSrcweir             defaultButton(WZB_NEXT);
283cdf0e10cSrcweir 
284cdf0e10cSrcweir         return sal_True;
285cdf0e10cSrcweir     }
286cdf0e10cSrcweir 
287cdf0e10cSrcweir     //---------------------------------------------------------------------
onFinish()288cdf0e10cSrcweir     sal_Bool OGridWizard::onFinish()
289cdf0e10cSrcweir     {
290cdf0e10cSrcweir         if ( !OControlWizard::onFinish() )
291cdf0e10cSrcweir             return sal_False;
292cdf0e10cSrcweir 
293cdf0e10cSrcweir         implApplySettings();
294cdf0e10cSrcweir 
295cdf0e10cSrcweir         return sal_True;
296cdf0e10cSrcweir     }
297cdf0e10cSrcweir 
298cdf0e10cSrcweir     //=====================================================================
299cdf0e10cSrcweir     //= OGridFieldsSelection
300cdf0e10cSrcweir     //=====================================================================
301cdf0e10cSrcweir     //---------------------------------------------------------------------
OGridFieldsSelection(OGridWizard * _pParent)302cdf0e10cSrcweir     OGridFieldsSelection::OGridFieldsSelection( OGridWizard* _pParent )
303cdf0e10cSrcweir         :OGridPage(_pParent, ModuleRes(RID_PAGE_GW_FIELDSELECTION))
304cdf0e10cSrcweir         ,m_aFrame               (this, ModuleRes(FL_FRAME))
305cdf0e10cSrcweir         ,m_aExistFieldsLabel    (this, ModuleRes(FT_EXISTING_FIELDS))
306cdf0e10cSrcweir         ,m_aExistFields         (this, ModuleRes(LB_EXISTING_FIELDS))
307cdf0e10cSrcweir         ,m_aSelectOne           (this, ModuleRes(PB_FIELDRIGHT))
308cdf0e10cSrcweir         ,m_aSelectAll           (this, ModuleRes(PB_ALLFIELDSRIGHT))
309cdf0e10cSrcweir         ,m_aDeselectOne         (this, ModuleRes(PB_FIELDLEFT))
310cdf0e10cSrcweir         ,m_aDeselectAll         (this, ModuleRes(PB_ALLFIELDSLEFT))
311cdf0e10cSrcweir         ,m_aSelFieldsLabel      (this, ModuleRes(FT_SELECTED_FIELDS))
312cdf0e10cSrcweir         ,m_aSelFields           (this, ModuleRes(LB_SELECTED_FIELDS))
313cdf0e10cSrcweir     {
314cdf0e10cSrcweir         FreeResource();
315cdf0e10cSrcweir 
316cdf0e10cSrcweir         enableFormDatasourceDisplay();
317cdf0e10cSrcweir 
318cdf0e10cSrcweir         m_aSelectOne.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveOneEntry));
319cdf0e10cSrcweir         m_aSelectAll.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveAllEntries));
320cdf0e10cSrcweir         m_aDeselectOne.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveOneEntry));
321cdf0e10cSrcweir         m_aDeselectAll.SetClickHdl(LINK(this, OGridFieldsSelection, OnMoveAllEntries));
322cdf0e10cSrcweir 
323cdf0e10cSrcweir         m_aExistFields.SetSelectHdl(LINK(this, OGridFieldsSelection, OnEntrySelected));
324cdf0e10cSrcweir         m_aSelFields.SetSelectHdl(LINK(this, OGridFieldsSelection, OnEntrySelected));
325cdf0e10cSrcweir         m_aExistFields.SetDoubleClickHdl(LINK(this, OGridFieldsSelection, OnEntryDoubleClicked));
326cdf0e10cSrcweir         m_aSelFields.SetDoubleClickHdl(LINK(this, OGridFieldsSelection, OnEntryDoubleClicked));
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir     //---------------------------------------------------------------------
ActivatePage()330cdf0e10cSrcweir     void OGridFieldsSelection::ActivatePage()
331cdf0e10cSrcweir     {
332cdf0e10cSrcweir         OGridPage::ActivatePage();
333cdf0e10cSrcweir         m_aExistFields.GrabFocus();
334cdf0e10cSrcweir     }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     //---------------------------------------------------------------------
canAdvance() const337cdf0e10cSrcweir     bool OGridFieldsSelection::canAdvance() const
338cdf0e10cSrcweir     {
339cdf0e10cSrcweir         return false;
340cdf0e10cSrcweir             // we're the last page in our wizard
341cdf0e10cSrcweir     }
342cdf0e10cSrcweir 
343cdf0e10cSrcweir     //---------------------------------------------------------------------
initializePage()344cdf0e10cSrcweir     void OGridFieldsSelection::initializePage()
345cdf0e10cSrcweir     {
346cdf0e10cSrcweir         OGridPage::initializePage();
347cdf0e10cSrcweir 
348cdf0e10cSrcweir         const OControlWizardContext& rContext = getContext();
349cdf0e10cSrcweir         fillListBox(m_aExistFields, rContext.aFieldNames);
350cdf0e10cSrcweir 
351cdf0e10cSrcweir         m_aSelFields.Clear();
352cdf0e10cSrcweir         const OGridSettings& rSettings = getSettings();
353cdf0e10cSrcweir         const ::rtl::OUString* pSelected = rSettings.aSelectedFields.getConstArray();
354cdf0e10cSrcweir         const ::rtl::OUString* pEnd = pSelected + rSettings.aSelectedFields.getLength();
355cdf0e10cSrcweir         for (; pSelected < pEnd; ++pSelected)
356cdf0e10cSrcweir         {
357cdf0e10cSrcweir             m_aSelFields.InsertEntry(*pSelected);
358cdf0e10cSrcweir             m_aExistFields.RemoveEntry(*pSelected);
359cdf0e10cSrcweir         }
360cdf0e10cSrcweir 
361cdf0e10cSrcweir         implCheckButtons();
362cdf0e10cSrcweir     }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir     //---------------------------------------------------------------------
commitPage(::svt::WizardTypes::CommitPageReason _eReason)365cdf0e10cSrcweir     sal_Bool OGridFieldsSelection::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
366cdf0e10cSrcweir     {
367cdf0e10cSrcweir         if (!OGridPage::commitPage(_eReason))
368cdf0e10cSrcweir             return sal_False;
369cdf0e10cSrcweir 
370cdf0e10cSrcweir         OGridSettings& rSettings = getSettings();
371cdf0e10cSrcweir         sal_uInt16 nSelected = m_aSelFields.GetEntryCount();
372cdf0e10cSrcweir 
373cdf0e10cSrcweir         rSettings.aSelectedFields.realloc(nSelected);
374cdf0e10cSrcweir         ::rtl::OUString* pSelected = rSettings.aSelectedFields.getArray();
375cdf0e10cSrcweir 
376cdf0e10cSrcweir         for (sal_uInt16 i=0; i<nSelected; ++i, ++pSelected)
377cdf0e10cSrcweir             *pSelected = m_aSelFields.GetEntry(i);
378cdf0e10cSrcweir 
379cdf0e10cSrcweir         return sal_True;
380cdf0e10cSrcweir     }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir     //---------------------------------------------------------------------
implCheckButtons()383cdf0e10cSrcweir     void OGridFieldsSelection::implCheckButtons()
384cdf0e10cSrcweir     {
385cdf0e10cSrcweir         m_aSelectOne.Enable(m_aExistFields.GetSelectEntryCount() != 0);
386cdf0e10cSrcweir         m_aSelectAll.Enable(m_aExistFields.GetEntryCount() != 0);
387cdf0e10cSrcweir 
388cdf0e10cSrcweir         m_aDeselectOne.Enable(m_aSelFields.GetSelectEntryCount() != 0);
389cdf0e10cSrcweir         m_aDeselectAll.Enable(m_aSelFields.GetEntryCount() != 0);
390cdf0e10cSrcweir 
391cdf0e10cSrcweir         getDialog()->enableButtons(WZB_FINISH, 0 != m_aSelFields.GetEntryCount());
392cdf0e10cSrcweir     }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     //---------------------------------------------------------------------
IMPL_LINK(OGridFieldsSelection,OnEntryDoubleClicked,ListBox *,_pList)395cdf0e10cSrcweir     IMPL_LINK(OGridFieldsSelection, OnEntryDoubleClicked, ListBox*, _pList)
396cdf0e10cSrcweir     {
397cdf0e10cSrcweir         PushButton* pSimulateButton = &m_aExistFields == _pList ? &m_aSelectOne : &m_aDeselectOne;
398cdf0e10cSrcweir         if (pSimulateButton->IsEnabled())
399cdf0e10cSrcweir             return OnMoveOneEntry( pSimulateButton );
400cdf0e10cSrcweir         else
401cdf0e10cSrcweir             return 1L;
402cdf0e10cSrcweir     }
403cdf0e10cSrcweir 
404cdf0e10cSrcweir     //---------------------------------------------------------------------
405cdf0e10cSrcweir     IMPL_LINK(OGridFieldsSelection, OnEntrySelected, ListBox*, /*NOTINTERESTEDIN*/)
406cdf0e10cSrcweir     {
407cdf0e10cSrcweir         implCheckButtons();
408cdf0e10cSrcweir         return 0L;
409cdf0e10cSrcweir     }
410cdf0e10cSrcweir 
411cdf0e10cSrcweir     //---------------------------------------------------------------------
IMPL_LINK(OGridFieldsSelection,OnMoveOneEntry,PushButton *,_pButton)412cdf0e10cSrcweir     IMPL_LINK(OGridFieldsSelection, OnMoveOneEntry, PushButton*, _pButton)
413cdf0e10cSrcweir     {
414cdf0e10cSrcweir         sal_Bool bMoveRight = (&m_aSelectOne == _pButton);
415cdf0e10cSrcweir         ListBox& rMoveTo = bMoveRight ? m_aSelFields : m_aExistFields;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir         // the index of the selected entry
418cdf0e10cSrcweir         sal_uInt16 nSelected = bMoveRight ? m_aExistFields.GetSelectEntryPos() : m_aSelFields.GetSelectEntryPos();
419cdf0e10cSrcweir         // the (original) relative position of the entry
420cdf0e10cSrcweir         sal_IntPtr nRelativeIndex = reinterpret_cast<sal_IntPtr>(bMoveRight ? m_aExistFields.GetEntryData(nSelected) : m_aSelFields.GetEntryData(nSelected));
421cdf0e10cSrcweir 
422cdf0e10cSrcweir         sal_uInt16 nInsertPos = LISTBOX_APPEND;
423cdf0e10cSrcweir         if (!bMoveRight)
424cdf0e10cSrcweir         {   // need to determine an insert pos which reflects the original
425cdf0e10cSrcweir             nInsertPos = 0;
426cdf0e10cSrcweir             while (nInsertPos < rMoveTo.GetEntryCount())
427cdf0e10cSrcweir             {
428cdf0e10cSrcweir                 if (reinterpret_cast<sal_IntPtr>(rMoveTo.GetEntryData(nInsertPos)) > nRelativeIndex)
429cdf0e10cSrcweir                     break;
430cdf0e10cSrcweir                 ++nInsertPos;
431cdf0e10cSrcweir             }
432cdf0e10cSrcweir         }
433cdf0e10cSrcweir 
434cdf0e10cSrcweir         // the text of the entry to move
435cdf0e10cSrcweir         String sMovingEntry = bMoveRight ? m_aExistFields.GetEntry(nSelected) : m_aSelFields.GetEntry(nSelected);
436cdf0e10cSrcweir 
437cdf0e10cSrcweir         // insert the entry
438cdf0e10cSrcweir         nInsertPos = rMoveTo.InsertEntry(sMovingEntry, nInsertPos);
439cdf0e10cSrcweir         // preserve it's "relative position" entry data
440cdf0e10cSrcweir         rMoveTo.SetEntryData(nInsertPos, reinterpret_cast<void*>(nRelativeIndex));
441cdf0e10cSrcweir 
442cdf0e10cSrcweir         // remove the entry from it's old list
443cdf0e10cSrcweir         if (bMoveRight)
444cdf0e10cSrcweir         {
445cdf0e10cSrcweir             sal_uInt16 nSelectPos = m_aExistFields.GetSelectEntryPos();
446cdf0e10cSrcweir             m_aExistFields.RemoveEntry(nSelected);
447cdf0e10cSrcweir             if ((LISTBOX_ENTRY_NOTFOUND != nSelectPos) && (nSelectPos < m_aExistFields.GetEntryCount()))
448cdf0e10cSrcweir                 m_aExistFields.SelectEntryPos(nSelectPos);
449cdf0e10cSrcweir 
450cdf0e10cSrcweir             m_aExistFields.GrabFocus();
451cdf0e10cSrcweir         }
452cdf0e10cSrcweir         else
453cdf0e10cSrcweir         {
454cdf0e10cSrcweir             sal_uInt16 nSelectPos = m_aSelFields.GetSelectEntryPos();
455cdf0e10cSrcweir             m_aSelFields.RemoveEntry(nSelected);
456cdf0e10cSrcweir             if ((LISTBOX_ENTRY_NOTFOUND != nSelectPos) && (nSelectPos < m_aSelFields.GetEntryCount()))
457cdf0e10cSrcweir                 m_aSelFields.SelectEntryPos(nSelectPos);
458cdf0e10cSrcweir 
459cdf0e10cSrcweir             m_aSelFields.GrabFocus();
460cdf0e10cSrcweir         }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir         implCheckButtons();
463cdf0e10cSrcweir         return 0;
464cdf0e10cSrcweir     }
465cdf0e10cSrcweir 
466cdf0e10cSrcweir     //---------------------------------------------------------------------
IMPL_LINK(OGridFieldsSelection,OnMoveAllEntries,PushButton *,_pButton)467cdf0e10cSrcweir     IMPL_LINK(OGridFieldsSelection, OnMoveAllEntries, PushButton*, _pButton)
468cdf0e10cSrcweir     {
469cdf0e10cSrcweir         sal_Bool bMoveRight = (&m_aSelectAll == _pButton);
470cdf0e10cSrcweir         m_aExistFields.Clear();
471cdf0e10cSrcweir         m_aSelFields.Clear();
472cdf0e10cSrcweir         fillListBox(bMoveRight ? m_aSelFields : m_aExistFields, getContext().aFieldNames);
473cdf0e10cSrcweir 
474cdf0e10cSrcweir         implCheckButtons();
475cdf0e10cSrcweir         return 0;
476cdf0e10cSrcweir     }
477cdf0e10cSrcweir 
478cdf0e10cSrcweir //.........................................................................
479cdf0e10cSrcweir }   // namespace dbp
480cdf0e10cSrcweir //.........................................................................
481