xref: /trunk/main/dbaccess/source/ui/dlg/indexdialog.cxx (revision ca41231d9e330adbb3cff54175670d80e843e360)
196de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
396de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
496de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
596de5490SAndrew Rist  * distributed with this work for additional information
696de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
796de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
896de5490SAndrew Rist  * "License"); you may not use this file except in compliance
996de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
1196de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
1396de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1496de5490SAndrew Rist  * software distributed under the License is distributed on an
1596de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1696de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
1796de5490SAndrew Rist  * specific language governing permissions and limitations
1896de5490SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
2096de5490SAndrew Rist  *************************************************************/
2196de5490SAndrew Rist 
2296de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25b63233d8Sdamjan #include "precompiled_dbui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _DBAUI_INDEXDIALOG_HXX_
28cdf0e10cSrcweir #include "indexdialog.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_
31cdf0e10cSrcweir #include "dbu_dlg.hrc"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_
34cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _DBAUI_INDEXDIALOG_HRC_
37cdf0e10cSrcweir #include "indexdialog.hrc"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #ifndef _DBAUI_INDEXFIELDSCONTROL_HXX_
40cdf0e10cSrcweir #include "indexfieldscontrol.hxx"
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir #ifndef _DBAUI_INDEXCOLLECTION_HXX_
43cdf0e10cSrcweir #include "indexcollection.hxx"
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX
46cdf0e10cSrcweir #include <vcl/msgbox.hxx>
47cdf0e10cSrcweir #endif
48cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_
49cdf0e10cSrcweir #include <com/sun/star/sdb/SQLContext.hpp>
50cdf0e10cSrcweir #endif
51cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
52cdf0e10cSrcweir #include "UITools.hxx"
53cdf0e10cSrcweir #endif
54cdf0e10cSrcweir #ifndef _SVTOOLS_IMGDEF_HXX
55cdf0e10cSrcweir #include <svtools/imgdef.hxx>
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
58cdf0e10cSrcweir #include "browserids.hxx"
59cdf0e10cSrcweir #endif
60cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBTOOLS_HXX_
61cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
62cdf0e10cSrcweir #endif
63cdf0e10cSrcweir //......................................................................
64cdf0e10cSrcweir namespace dbaui
65cdf0e10cSrcweir {
66cdf0e10cSrcweir //......................................................................
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
69cdf0e10cSrcweir     using namespace ::com::sun::star::container;
70cdf0e10cSrcweir     using namespace ::com::sun::star::sdbc;
71cdf0e10cSrcweir     using namespace ::com::sun::star::sdb;
72cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
73cdf0e10cSrcweir     using namespace ::dbtools;
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     //==================================================================
76cdf0e10cSrcweir     //= helper
77cdf0e10cSrcweir     //==================================================================
78cdf0e10cSrcweir     //------------------------------------------------------------------
operator ==(const OIndexField & _rLHS,const OIndexField & _rRHS)79cdf0e10cSrcweir     sal_Bool operator ==(const OIndexField& _rLHS, const OIndexField& _rRHS)
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         return  (_rLHS.sFieldName == _rRHS.sFieldName)
82cdf0e10cSrcweir             &&  (_rLHS.bSortAscending == _rRHS.bSortAscending);
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     //------------------------------------------------------------------
operator !=(const OIndexField & _rLHS,const OIndexField & _rRHS)86cdf0e10cSrcweir     sal_Bool operator !=(const OIndexField& _rLHS, const OIndexField& _rRHS)
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         return !(_rLHS == _rRHS);
89cdf0e10cSrcweir     }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     //------------------------------------------------------------------
operator ==(const IndexFields & _rLHS,const IndexFields & _rRHS)92cdf0e10cSrcweir     sal_Bool operator ==(const IndexFields& _rLHS, const IndexFields& _rRHS)
93cdf0e10cSrcweir     {
94cdf0e10cSrcweir         if (_rLHS.size() != _rRHS.size())
95cdf0e10cSrcweir             return sal_False;
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         ConstIndexFieldsIterator aLeft = _rLHS.begin();
98cdf0e10cSrcweir         ConstIndexFieldsIterator aLeftEnd = _rLHS.end();
99cdf0e10cSrcweir         ConstIndexFieldsIterator aRight = _rRHS.begin();
100cdf0e10cSrcweir         for (; aLeft != aLeftEnd; ++aLeft, ++aRight)
101cdf0e10cSrcweir         {
102cdf0e10cSrcweir             if (*aLeft != *aRight)
103cdf0e10cSrcweir                 return sal_False;
104cdf0e10cSrcweir         }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         return sal_True;
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir     //------------------------------------------------------------------
operator !=(const IndexFields & _rLHS,const IndexFields & _rRHS)110cdf0e10cSrcweir     sal_Bool operator !=(const IndexFields& _rLHS, const IndexFields& _rRHS)
111cdf0e10cSrcweir     {
112cdf0e10cSrcweir         return !(_rLHS == _rRHS);
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     //==================================================================
116cdf0e10cSrcweir     //= DbaIndexList
117cdf0e10cSrcweir     //==================================================================
118cdf0e10cSrcweir     //------------------------------------------------------------------
DbaIndexList(Window * _pParent,const ResId & _rId)119cdf0e10cSrcweir     DbaIndexList::DbaIndexList(Window* _pParent, const ResId& _rId)
120cdf0e10cSrcweir         :SvTreeListBox(_pParent, _rId)
121cdf0e10cSrcweir         ,m_bSuspendSelectHdl(sal_False)
122cdf0e10cSrcweir     {
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     extern sal_Bool isCharOk(sal_Unicode _cChar,sal_Bool _bFirstChar,sal_Bool _bUpperCase,const ::rtl::OUString& _sAllowedChars);
126cdf0e10cSrcweir     //------------------------------------------------------------------
EditedEntry(SvLBoxEntry * _pEntry,const String & _rNewText)127cdf0e10cSrcweir     sal_Bool DbaIndexList::EditedEntry( SvLBoxEntry* _pEntry, const String& _rNewText )
128cdf0e10cSrcweir     {
129cdf0e10cSrcweir         // first check if this is valid SQL92 name
130cdf0e10cSrcweir         if ( isSQL92CheckEnabled(m_xConnection) )
131cdf0e10cSrcweir         {
132cdf0e10cSrcweir             Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
133cdf0e10cSrcweir             if ( xMeta.is() )
134cdf0e10cSrcweir             {
135cdf0e10cSrcweir                 ::rtl::OUString sNewName(_rNewText);
136cdf0e10cSrcweir                 ::rtl::OUString sAlias = ::dbtools::convertName2SQLName(sNewName,xMeta->getExtraNameCharacters());
137cdf0e10cSrcweir                 if ( ( xMeta->supportsMixedCaseQuotedIdentifiers() )
138cdf0e10cSrcweir                         ?
139cdf0e10cSrcweir                         sAlias != sNewName
140cdf0e10cSrcweir                         :
141cdf0e10cSrcweir                 !sNewName.equalsIgnoreAsciiCase(sAlias))
142cdf0e10cSrcweir                     return sal_False;
143cdf0e10cSrcweir             }
144cdf0e10cSrcweir         }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         if (!SvTreeListBox::EditedEntry(_pEntry, _rNewText))
147cdf0e10cSrcweir             return sal_False;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         String sOldText = GetEntryText(_pEntry);
150cdf0e10cSrcweir         SvTreeListBox::SetEntryText(_pEntry, _rNewText);
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         sal_Bool bValid = sal_True;
153cdf0e10cSrcweir         if (m_aEndEditHdl.IsSet())
154cdf0e10cSrcweir             bValid = (0 != m_aEndEditHdl.Call(_pEntry));
155cdf0e10cSrcweir 
156cdf0e10cSrcweir         if (bValid)
157cdf0e10cSrcweir             return sal_True;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir         SvTreeListBox::SetEntryText(_pEntry, sOldText);
160cdf0e10cSrcweir 
161cdf0e10cSrcweir         return sal_False;
162cdf0e10cSrcweir     }
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     //------------------------------------------------------------------
enableSelectHandler()165cdf0e10cSrcweir     void DbaIndexList::enableSelectHandler()
166cdf0e10cSrcweir     {
167cdf0e10cSrcweir         DBG_ASSERT(m_bSuspendSelectHdl, "DbaIndexList::enableSelectHandler: invalid call (this is not cumulative)!");
168cdf0e10cSrcweir         m_bSuspendSelectHdl = sal_False;
169cdf0e10cSrcweir     }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     //------------------------------------------------------------------
disableSelectHandler()172cdf0e10cSrcweir     void DbaIndexList::disableSelectHandler()
173cdf0e10cSrcweir     {
174cdf0e10cSrcweir         DBG_ASSERT(!m_bSuspendSelectHdl, "DbaIndexList::enableSelectHandler: invalid call (this is not cumulative)!");
175cdf0e10cSrcweir         m_bSuspendSelectHdl = sal_True;
176cdf0e10cSrcweir     }
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     //------------------------------------------------------------------
SelectNoHandlerCall(SvLBoxEntry * _pEntry)179cdf0e10cSrcweir     void DbaIndexList::SelectNoHandlerCall( SvLBoxEntry* _pEntry )
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         disableSelectHandler();
182cdf0e10cSrcweir         Select(_pEntry, sal_True);
183cdf0e10cSrcweir         enableSelectHandler();
184cdf0e10cSrcweir     }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     //------------------------------------------------------------------
Select(SvLBoxEntry * pEntry,sal_Bool _bSelect)187cdf0e10cSrcweir     sal_Bool DbaIndexList::Select( SvLBoxEntry* pEntry, sal_Bool _bSelect )
188cdf0e10cSrcweir     {
189cdf0e10cSrcweir         sal_Bool bReturn = SvTreeListBox::Select(pEntry, _bSelect);
190cdf0e10cSrcweir 
191cdf0e10cSrcweir         if (m_aSelectHdl.IsSet() && !m_bSuspendSelectHdl && _bSelect)
192cdf0e10cSrcweir             m_aSelectHdl.Call(this);
193cdf0e10cSrcweir 
194cdf0e10cSrcweir         return bReturn;
195cdf0e10cSrcweir     }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     //==================================================================
198cdf0e10cSrcweir     //= DbaIndexDialog
199cdf0e10cSrcweir     //==================================================================
DBG_NAME(DbaIndexDialog)200cdf0e10cSrcweir DBG_NAME(DbaIndexDialog)
201cdf0e10cSrcweir //------------------------------------------------------------------
202cdf0e10cSrcweir     DbaIndexDialog::DbaIndexDialog( Window* _pParent, const Sequence< ::rtl::OUString >& _rFieldNames,
203cdf0e10cSrcweir                                     const Reference< XNameAccess >& _rxIndexes,
204cdf0e10cSrcweir                                     const Reference< XConnection >& _rxConnection,
205cdf0e10cSrcweir                                     const Reference< XMultiServiceFactory >& _rxORB,sal_Int32 _nMaxColumnsInIndex)
206cdf0e10cSrcweir         :ModalDialog( _pParent, ModuleRes(DLG_INDEXDESIGN))
207cdf0e10cSrcweir         ,m_xConnection(_rxConnection)
208cdf0e10cSrcweir         ,m_aGeometrySettings(E_DIALOG, ::rtl::OUString::createFromAscii("dbaccess.tabledesign.indexdialog"))
209cdf0e10cSrcweir         ,m_aActions                         (this, ModuleRes(TLB_ACTIONS))
210cdf0e10cSrcweir         ,m_aIndexes                         (this, ModuleRes(CTR_INDEXLIST))
211cdf0e10cSrcweir         ,m_aIndexDetails                    (this, ModuleRes(FL_INDEXDETAILS))
212cdf0e10cSrcweir         ,m_aDescriptionLabel                (this, ModuleRes(FT_DESC_LABEL))
213cdf0e10cSrcweir         ,m_aDescription                     (this, ModuleRes(FT_DESCRIPTION))
214cdf0e10cSrcweir         ,m_aUnique                          (this, ModuleRes(CB_UNIQUE))
215cdf0e10cSrcweir         ,m_aFieldsLabel                     (this, ModuleRes(FT_FIELDS))
216cdf0e10cSrcweir         ,m_pFields(new IndexFieldsControl   (this, ModuleRes(CTR_FIELDS),_nMaxColumnsInIndex,::dbtools::getBooleanDataSourceSetting( m_xConnection, "AddIndexAppendix" )))
217cdf0e10cSrcweir         ,m_aClose                           (this, ModuleRes(PB_CLOSE))
218cdf0e10cSrcweir         ,m_aHelp                            (this, ModuleRes(HB_HELP))
219cdf0e10cSrcweir         ,m_pIndexes(NULL)
220cdf0e10cSrcweir         ,m_pPreviousSelection(NULL)
221cdf0e10cSrcweir         ,m_bEditAgain(sal_False)
222cdf0e10cSrcweir         ,m_xORB(_rxORB)
223cdf0e10cSrcweir     {
224cdf0e10cSrcweir         DBG_CTOR(DbaIndexDialog,NULL);
225cdf0e10cSrcweir 
226cdf0e10cSrcweir         FreeResource();
227cdf0e10cSrcweir 
228cdf0e10cSrcweir         m_aActions.SetSelectHdl(LINK(this, DbaIndexDialog, OnIndexAction));
229cdf0e10cSrcweir 
230cdf0e10cSrcweir         m_aIndexes.SetSelectHdl(LINK(this, DbaIndexDialog, OnIndexSelected));
231cdf0e10cSrcweir         m_aIndexes.SetEndEditHdl(LINK(this, DbaIndexDialog, OnEntryEdited));
232cdf0e10cSrcweir         m_aIndexes.SetSelectionMode(SINGLE_SELECTION);
233cdf0e10cSrcweir         m_aIndexes.SetHighlightRange();
234cdf0e10cSrcweir         m_aIndexes.setConnection(m_xConnection);
235cdf0e10cSrcweir 
236cdf0e10cSrcweir         m_pFields->Init(_rFieldNames);
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         setToolBox(&m_aActions);
239cdf0e10cSrcweir 
240cdf0e10cSrcweir         m_pIndexes = new OIndexCollection();
241cdf0e10cSrcweir         try
242cdf0e10cSrcweir         {
243cdf0e10cSrcweir             m_pIndexes->attach(_rxIndexes);
244cdf0e10cSrcweir         }
245cdf0e10cSrcweir         catch(SQLException& e)
246cdf0e10cSrcweir         {
247cdf0e10cSrcweir             ::dbaui::showError(SQLExceptionInfo(e),_pParent,_rxORB);
248cdf0e10cSrcweir         }
249cdf0e10cSrcweir         catch(Exception&)
250cdf0e10cSrcweir         {
251cdf0e10cSrcweir             OSL_ENSURE(sal_False, "DbaIndexDialog::DbaIndexDialog: could not retrieve basic information from the UNO collection!");
252cdf0e10cSrcweir         }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         fillIndexList();
255cdf0e10cSrcweir 
256cdf0e10cSrcweir         m_aUnique.SetClickHdl(LINK(this, DbaIndexDialog, OnModified));
257cdf0e10cSrcweir         m_pFields->SetModifyHdl(LINK(this, DbaIndexDialog, OnModified));
258cdf0e10cSrcweir 
259cdf0e10cSrcweir         m_aClose.SetClickHdl(LINK(this, DbaIndexDialog, OnCloseDialog));
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         // get our most recent geometry settings
262cdf0e10cSrcweir //      if (m_aGeometrySettings.Exists())
263cdf0e10cSrcweir //      {
264cdf0e10cSrcweir //          Point aPos;
265cdf0e10cSrcweir //          m_aGeometrySettings.GetPosition(aPos.X(), aPos.Y());
266cdf0e10cSrcweir //          SetPosPixel(aPos);
267cdf0e10cSrcweir //      }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         // if all of the indexes have an empty description, we're not interested in displaying it
270cdf0e10cSrcweir         Indexes::const_iterator aCheck;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         for (   aCheck = m_pIndexes->begin();
273cdf0e10cSrcweir                 aCheck != m_pIndexes->end();
274cdf0e10cSrcweir                 ++aCheck
275cdf0e10cSrcweir             )
276cdf0e10cSrcweir         {
277cdf0e10cSrcweir             if (aCheck->sDescription.getLength())
278cdf0e10cSrcweir                 break;
279cdf0e10cSrcweir         }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir         if (aCheck == m_pIndexes->end())
282cdf0e10cSrcweir         {
283cdf0e10cSrcweir             sal_Int32 nMoveUp = m_aUnique.GetPosPixel().Y() - m_aDescriptionLabel.GetPosPixel().Y();
284cdf0e10cSrcweir 
285cdf0e10cSrcweir             // hide the controls which are necessary for the description
286cdf0e10cSrcweir             m_aDescription.Hide();
287cdf0e10cSrcweir             m_aDescriptionLabel.Hide();
288cdf0e10cSrcweir 
289cdf0e10cSrcweir             // move other controls up
290cdf0e10cSrcweir             Point aPos = m_aUnique.GetPosPixel();
291cdf0e10cSrcweir             aPos.Y() -= nMoveUp;
292cdf0e10cSrcweir             m_aUnique.SetPosPixel(aPos);
293cdf0e10cSrcweir 
294cdf0e10cSrcweir             aPos = m_aFieldsLabel.GetPosPixel();
295cdf0e10cSrcweir             aPos.Y() -= nMoveUp;
296cdf0e10cSrcweir             m_aFieldsLabel.SetPosPixel(aPos);
297cdf0e10cSrcweir 
298cdf0e10cSrcweir             aPos = m_pFields->GetPosPixel();
299cdf0e10cSrcweir             aPos.Y() -= nMoveUp;
300cdf0e10cSrcweir             m_pFields->SetPosPixel(aPos);
301cdf0e10cSrcweir 
302cdf0e10cSrcweir             // and enlarge the fields list
303cdf0e10cSrcweir             Size aSize = m_pFields->GetSizePixel();
304cdf0e10cSrcweir             aSize.Height() += nMoveUp;
305cdf0e10cSrcweir             m_pFields->SetSizePixel(aSize);
306cdf0e10cSrcweir         }
307cdf0e10cSrcweir     }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir     //------------------------------------------------------------------
updateToolbox()310cdf0e10cSrcweir     void DbaIndexDialog::updateToolbox()
311cdf0e10cSrcweir     {
312cdf0e10cSrcweir         m_aActions.EnableItem(ID_INDEX_NEW, !m_aIndexes.IsEditingActive());
313cdf0e10cSrcweir 
314cdf0e10cSrcweir         SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
315cdf0e10cSrcweir         sal_Bool bSelectedAnything = NULL != pSelected;
316cdf0e10cSrcweir 
317cdf0e10cSrcweir 
318cdf0e10cSrcweir         if (pSelected)
319cdf0e10cSrcweir         {
320cdf0e10cSrcweir             // is the current entry modified?
321cdf0e10cSrcweir             Indexes::const_iterator aSelectedPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData());
322cdf0e10cSrcweir             m_aActions.EnableItem(ID_INDEX_SAVE, aSelectedPos->isModified() || aSelectedPos->isNew());
323cdf0e10cSrcweir             m_aActions.EnableItem(ID_INDEX_RESET, aSelectedPos->isModified() || aSelectedPos->isNew());
324cdf0e10cSrcweir             bSelectedAnything = bSelectedAnything && !aSelectedPos->bPrimaryKey;
325cdf0e10cSrcweir         }
326cdf0e10cSrcweir         else
327cdf0e10cSrcweir         {
328cdf0e10cSrcweir             m_aActions.EnableItem(ID_INDEX_SAVE, sal_False);
329cdf0e10cSrcweir             m_aActions.EnableItem(ID_INDEX_RESET, sal_False);
330cdf0e10cSrcweir         }
331cdf0e10cSrcweir         m_aActions.EnableItem(ID_INDEX_DROP, bSelectedAnything);
332cdf0e10cSrcweir         m_aActions.EnableItem(ID_INDEX_RENAME, bSelectedAnything);
333cdf0e10cSrcweir     }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir     //------------------------------------------------------------------
fillIndexList()336cdf0e10cSrcweir     void DbaIndexDialog::fillIndexList()
337cdf0e10cSrcweir     {
338cdf0e10cSrcweir         sal_Bool bHiContrast = GetSettings().GetStyleSettings().GetHighContrastMode();
339cdf0e10cSrcweir         Image aPKeyIcon(ModuleRes( bHiContrast ? IMG_PKEYICON_SCH : IMG_PKEYICON));
340cdf0e10cSrcweir         // fill the list with the index names
341cdf0e10cSrcweir         m_aIndexes.Clear();
342cdf0e10cSrcweir         Indexes::iterator aIndexLoop = m_pIndexes->begin();
343cdf0e10cSrcweir         Indexes::iterator aEnd = m_pIndexes->end();
344cdf0e10cSrcweir         for (; aIndexLoop != aEnd; ++aIndexLoop)
345cdf0e10cSrcweir         {
346cdf0e10cSrcweir             SvLBoxEntry* pNewEntry = NULL;
347cdf0e10cSrcweir             if (aIndexLoop->bPrimaryKey)
348cdf0e10cSrcweir                 pNewEntry = m_aIndexes.InsertEntry(aIndexLoop->sName, aPKeyIcon, aPKeyIcon);
349cdf0e10cSrcweir             else
350cdf0e10cSrcweir                 pNewEntry = m_aIndexes.InsertEntry(aIndexLoop->sName);
351cdf0e10cSrcweir 
352cdf0e10cSrcweir             pNewEntry->SetUserData(reinterpret_cast< void* >(sal_Int32(aIndexLoop - m_pIndexes->begin())));
353cdf0e10cSrcweir         }
354cdf0e10cSrcweir 
355cdf0e10cSrcweir         OnIndexSelected(&m_aIndexes);
356cdf0e10cSrcweir     }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir     //------------------------------------------------------------------
~DbaIndexDialog()359cdf0e10cSrcweir     DbaIndexDialog::~DbaIndexDialog( )
360cdf0e10cSrcweir     {
361cdf0e10cSrcweir         setToolBox(NULL);
362cdf0e10cSrcweir         delete m_pIndexes;
363cdf0e10cSrcweir         delete m_pFields;
364cdf0e10cSrcweir 
365cdf0e10cSrcweir         // save our geometry settings
366cdf0e10cSrcweir //      Point aPos = GetPosPixel();
367cdf0e10cSrcweir //      m_aGeometrySettings.SetPosition(aPos.X(), aPos.Y());
368cdf0e10cSrcweir 
369cdf0e10cSrcweir         DBG_DTOR(DbaIndexDialog,NULL);
370cdf0e10cSrcweir     }
371cdf0e10cSrcweir 
372cdf0e10cSrcweir     //------------------------------------------------------------------
implCommit(SvLBoxEntry * _pEntry)373cdf0e10cSrcweir     sal_Bool DbaIndexDialog::implCommit(SvLBoxEntry* _pEntry)
374cdf0e10cSrcweir     {
375cdf0e10cSrcweir         DBG_ASSERT(_pEntry, "DbaIndexDialog::implCommit: invalid entry!");
376cdf0e10cSrcweir 
377cdf0e10cSrcweir         Indexes::iterator aCommitPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
378cdf0e10cSrcweir 
379cdf0e10cSrcweir         // if it's not a new index, remove it
380cdf0e10cSrcweir         // (we can't modify indexes, only drop'n'insert)
381cdf0e10cSrcweir         if (!aCommitPos->isNew())
382cdf0e10cSrcweir             if (!implDropIndex(_pEntry, sal_False))
383cdf0e10cSrcweir                 return sal_False;
384cdf0e10cSrcweir 
385cdf0e10cSrcweir         // create the new index
386cdf0e10cSrcweir         SQLExceptionInfo aExceptionInfo;
387cdf0e10cSrcweir         try
388cdf0e10cSrcweir         {
389cdf0e10cSrcweir             m_pIndexes->commitNewIndex(aCommitPos);
390cdf0e10cSrcweir         }
391cdf0e10cSrcweir         catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); }
392cdf0e10cSrcweir         catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); }
393cdf0e10cSrcweir         catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir         // reflect the new selection in the toolbox
396cdf0e10cSrcweir         updateToolbox();
397cdf0e10cSrcweir 
398cdf0e10cSrcweir         if (aExceptionInfo.isValid())
399cdf0e10cSrcweir             showError(aExceptionInfo, this, m_xORB);
400cdf0e10cSrcweir         else
401cdf0e10cSrcweir         {
402cdf0e10cSrcweir             m_aUnique.SaveValue();
403cdf0e10cSrcweir             m_pFields->SaveValue();
404cdf0e10cSrcweir         }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir         return !aExceptionInfo.isValid();
407cdf0e10cSrcweir     }
408cdf0e10cSrcweir 
409cdf0e10cSrcweir     //------------------------------------------------------------------
OnNewIndex()410cdf0e10cSrcweir     void DbaIndexDialog::OnNewIndex()
411cdf0e10cSrcweir     {
412cdf0e10cSrcweir         // commit the current entry, if necessary
413cdf0e10cSrcweir         if (!implCommitPreviouslySelected())
414cdf0e10cSrcweir             return;
415cdf0e10cSrcweir 
416cdf0e10cSrcweir         // get a new unique name for the new index
417cdf0e10cSrcweir         String sNewIndexName;
418cdf0e10cSrcweir         const String sNewIndexNameBase(ModuleRes(STR_LOGICAL_INDEX_NAME));
419cdf0e10cSrcweir         sal_Int32 i;
420cdf0e10cSrcweir 
421cdf0e10cSrcweir         for ( i = 1; i < 0x7FFFFFFF; ++i )
422cdf0e10cSrcweir         {
423cdf0e10cSrcweir             sNewIndexName = sNewIndexNameBase;
424cdf0e10cSrcweir             sNewIndexName += String::CreateFromInt32(i);
425cdf0e10cSrcweir             if (m_pIndexes->end() == m_pIndexes->find(sNewIndexName))
426cdf0e10cSrcweir                 break;
427cdf0e10cSrcweir         }
428cdf0e10cSrcweir         if ((i>0x7FFFFFFF) || (i<0))
429cdf0e10cSrcweir         {
430cdf0e10cSrcweir             DBG_ERROR("DbaIndexDialog::OnNewIndex: no free index name found!");
431cdf0e10cSrcweir             // can't do anything ... of course we try another base, but this could end with the same result ...
432cdf0e10cSrcweir             return;
433cdf0e10cSrcweir         }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir         SvLBoxEntry* pNewEntry = m_aIndexes.InsertEntry(sNewIndexName);
436cdf0e10cSrcweir         m_pIndexes->insert(sNewIndexName);
437cdf0e10cSrcweir 
438cdf0e10cSrcweir         // update the user data on the entries in the list box:
439cdf0e10cSrcweir         // they're iterators of the index collection, and thus they have changed when removing the index
440cdf0e10cSrcweir         for (SvLBoxEntry* pAdjust = m_aIndexes.First(); pAdjust; pAdjust = m_aIndexes.Next(pAdjust))
441cdf0e10cSrcweir         {
442cdf0e10cSrcweir             Indexes::iterator aAfterInsertPos = m_pIndexes->find(m_aIndexes.GetEntryText(pAdjust));
443cdf0e10cSrcweir             DBG_ASSERT(aAfterInsertPos != m_pIndexes->end(), "DbaIndexDialog::OnNewIndex: problems with on of the entries!");
444cdf0e10cSrcweir             pAdjust->SetUserData(reinterpret_cast< void* >(sal_Int32(aAfterInsertPos - m_pIndexes->begin())));
445cdf0e10cSrcweir         }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir         // select the entry and start in-place editing
448cdf0e10cSrcweir         m_aIndexes.SelectNoHandlerCall(pNewEntry);
449cdf0e10cSrcweir         OnIndexSelected(&m_aIndexes);
450cdf0e10cSrcweir         m_aIndexes.EditEntry(pNewEntry);
451cdf0e10cSrcweir         updateToolbox();
452cdf0e10cSrcweir     }
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     //------------------------------------------------------------------
OnDropIndex(sal_Bool _bConfirm)455cdf0e10cSrcweir     void DbaIndexDialog::OnDropIndex(sal_Bool _bConfirm)
456cdf0e10cSrcweir     {
457cdf0e10cSrcweir         // the selected index
458cdf0e10cSrcweir         SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
459cdf0e10cSrcweir         DBG_ASSERT(pSelected, "DbaIndexDialog::OnDropIndex: invalid call!");
460cdf0e10cSrcweir         if (pSelected)
461cdf0e10cSrcweir         {
462cdf0e10cSrcweir             // let the user confirm the drop
463cdf0e10cSrcweir             if (_bConfirm)
464cdf0e10cSrcweir             {
465cdf0e10cSrcweir                 String sConfirm(ModuleRes(STR_CONFIRM_DROP_INDEX));
466cdf0e10cSrcweir                 sConfirm.SearchAndReplaceAscii("$name$", m_aIndexes.GetEntryText(pSelected));
467cdf0e10cSrcweir                 QueryBox aConfirm(this, WB_YES_NO, sConfirm);
468cdf0e10cSrcweir                 if (RET_YES != aConfirm.Execute())
469cdf0e10cSrcweir                     return;
470cdf0e10cSrcweir             }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir             // do the drop
473cdf0e10cSrcweir             implDropIndex(pSelected, sal_True);
474cdf0e10cSrcweir 
475cdf0e10cSrcweir             // reflect the new selection in the toolbox
476cdf0e10cSrcweir             updateToolbox();
477cdf0e10cSrcweir         }
478cdf0e10cSrcweir     }
479cdf0e10cSrcweir 
480cdf0e10cSrcweir     //------------------------------------------------------------------
implDropIndex(SvLBoxEntry * _pEntry,sal_Bool _bRemoveFromCollection)481cdf0e10cSrcweir     sal_Bool DbaIndexDialog::implDropIndex(SvLBoxEntry* _pEntry, sal_Bool _bRemoveFromCollection)
482cdf0e10cSrcweir     {
483cdf0e10cSrcweir         // do the drop
484cdf0e10cSrcweir         Indexes::iterator aDropPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
485cdf0e10cSrcweir         DBG_ASSERT(aDropPos != m_pIndexes->end(), "DbaIndexDialog::OnDropIndex: did not find the index in my collection!");
486cdf0e10cSrcweir 
487cdf0e10cSrcweir         SQLExceptionInfo aExceptionInfo;
488cdf0e10cSrcweir         sal_Bool bSuccess = sal_False;
489cdf0e10cSrcweir         try
490cdf0e10cSrcweir         {
491cdf0e10cSrcweir             if (_bRemoveFromCollection)
492cdf0e10cSrcweir                 bSuccess = m_pIndexes->drop(aDropPos);
493cdf0e10cSrcweir             else
494cdf0e10cSrcweir                 bSuccess = m_pIndexes->dropNoRemove(aDropPos);
495cdf0e10cSrcweir         }
496cdf0e10cSrcweir         catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); }
497cdf0e10cSrcweir         catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); }
498cdf0e10cSrcweir         catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); }
499cdf0e10cSrcweir 
500cdf0e10cSrcweir         if (aExceptionInfo.isValid())
501cdf0e10cSrcweir             showError(aExceptionInfo, this, m_xORB);
502cdf0e10cSrcweir         else if (bSuccess && _bRemoveFromCollection)
503cdf0e10cSrcweir         {
504cdf0e10cSrcweir             SvLBoxTreeList* pModel = m_aIndexes.GetModel();
505cdf0e10cSrcweir 
506cdf0e10cSrcweir             m_aIndexes.disableSelectHandler();
507cdf0e10cSrcweir             pModel->Remove(_pEntry);
508cdf0e10cSrcweir             m_aIndexes.enableSelectHandler();
509cdf0e10cSrcweir 
510cdf0e10cSrcweir             // update the user data on the entries in the list box:
511cdf0e10cSrcweir             // they're iterators of the index collection, and thus they have changed when removing the index
512cdf0e10cSrcweir             for (SvLBoxEntry* pAdjust = m_aIndexes.First(); pAdjust; pAdjust = m_aIndexes.Next(pAdjust))
513cdf0e10cSrcweir             {
514cdf0e10cSrcweir                 Indexes::iterator aAfterDropPos = m_pIndexes->find(m_aIndexes.GetEntryText(pAdjust));
515cdf0e10cSrcweir                 DBG_ASSERT(aAfterDropPos != m_pIndexes->end(), "DbaIndexDialog::OnDropIndex: problems with on of the remaining entries!");
516cdf0e10cSrcweir                 pAdjust->SetUserData(reinterpret_cast< void* >(sal_Int32(aAfterDropPos - m_pIndexes->begin())));
517cdf0e10cSrcweir             }
518cdf0e10cSrcweir 
519cdf0e10cSrcweir             // if the remvoved entry was the selected on ...
520cdf0e10cSrcweir             if (m_pPreviousSelection == _pEntry)
521cdf0e10cSrcweir                 m_pPreviousSelection = NULL;
522cdf0e10cSrcweir 
523cdf0e10cSrcweir             // the Remove automatically selected another entry (if possible), but we disabled the calling of the handler
524cdf0e10cSrcweir             // to prevent that we missed something ... call the handler directly
525cdf0e10cSrcweir             OnIndexSelected(&m_aIndexes);
526cdf0e10cSrcweir         }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir         return !aExceptionInfo.isValid();
529cdf0e10cSrcweir     }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir     //------------------------------------------------------------------
OnRenameIndex()532cdf0e10cSrcweir     void DbaIndexDialog::OnRenameIndex()
533cdf0e10cSrcweir     {
534cdf0e10cSrcweir         // the selected index
535cdf0e10cSrcweir         SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
536cdf0e10cSrcweir         DBG_ASSERT(pSelected, "DbaIndexDialog::OnRenameIndex: invalid call!");
537cdf0e10cSrcweir 
538cdf0e10cSrcweir         // save the changes made 'til here
539cdf0e10cSrcweir         // Upon leaving the edit mode, the control will be re-initialized with the
540cdf0e10cSrcweir         // settings from the current entry
541cdf0e10cSrcweir         implSaveModified(sal_False);
542cdf0e10cSrcweir 
543cdf0e10cSrcweir         m_aIndexes.EditEntry(pSelected);
544cdf0e10cSrcweir         updateToolbox();
545cdf0e10cSrcweir     }
546cdf0e10cSrcweir 
547cdf0e10cSrcweir     //------------------------------------------------------------------
OnSaveIndex()548cdf0e10cSrcweir     void DbaIndexDialog::OnSaveIndex()
549cdf0e10cSrcweir     {
550cdf0e10cSrcweir         // the selected index
551cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
552cdf0e10cSrcweir         SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
553cdf0e10cSrcweir         OSL_ENSURE( pSelected, "DbaIndexDialog::OnSaveIndex: invalid call!" );
554cdf0e10cSrcweir #endif
555cdf0e10cSrcweir 
556cdf0e10cSrcweir         implCommitPreviouslySelected();
557cdf0e10cSrcweir         updateToolbox();
558cdf0e10cSrcweir     }
559cdf0e10cSrcweir 
560cdf0e10cSrcweir     //------------------------------------------------------------------
OnResetIndex()561cdf0e10cSrcweir     void DbaIndexDialog::OnResetIndex()
562cdf0e10cSrcweir     {
563cdf0e10cSrcweir         // the selected index
564cdf0e10cSrcweir         SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
565cdf0e10cSrcweir         DBG_ASSERT(pSelected, "DbaIndexDialog::OnResetIndex: invalid call!");
566cdf0e10cSrcweir 
567cdf0e10cSrcweir         Indexes::iterator aResetPos = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData());
568cdf0e10cSrcweir 
569cdf0e10cSrcweir         if (aResetPos->isNew())
570cdf0e10cSrcweir         {
571cdf0e10cSrcweir             OnDropIndex(sal_False);
572cdf0e10cSrcweir             return;
573cdf0e10cSrcweir         }
574cdf0e10cSrcweir 
575cdf0e10cSrcweir         SQLExceptionInfo aExceptionInfo;
576cdf0e10cSrcweir         try
577cdf0e10cSrcweir         {
578cdf0e10cSrcweir             m_pIndexes->resetIndex(aResetPos);
579cdf0e10cSrcweir         }
580cdf0e10cSrcweir         catch(SQLContext& e) { aExceptionInfo = SQLExceptionInfo(e); }
581cdf0e10cSrcweir         catch(SQLWarning& e) { aExceptionInfo = SQLExceptionInfo(e); }
582cdf0e10cSrcweir         catch(SQLException& e) { aExceptionInfo = SQLExceptionInfo(e); }
583cdf0e10cSrcweir 
584cdf0e10cSrcweir         if (aExceptionInfo.isValid())
585cdf0e10cSrcweir             showError(aExceptionInfo, this, m_xORB);
586cdf0e10cSrcweir         else
587cdf0e10cSrcweir             m_aIndexes.SetEntryText(pSelected, aResetPos->sName);
588cdf0e10cSrcweir 
589cdf0e10cSrcweir         updateControls(pSelected);
590cdf0e10cSrcweir         updateToolbox();
591cdf0e10cSrcweir     }
592cdf0e10cSrcweir 
593cdf0e10cSrcweir     //------------------------------------------------------------------
594cdf0e10cSrcweir     IMPL_LINK( DbaIndexDialog, OnIndexAction, ToolBox*, /*NOTINTERESTEDIN*/ )
595cdf0e10cSrcweir     {
596cdf0e10cSrcweir         sal_uInt16 nClicked = m_aActions.GetCurItemId();
597cdf0e10cSrcweir         switch (nClicked)
598cdf0e10cSrcweir         {
599cdf0e10cSrcweir             case ID_INDEX_NEW:
600cdf0e10cSrcweir                 OnNewIndex();
601cdf0e10cSrcweir                 break;
602cdf0e10cSrcweir             case ID_INDEX_DROP:
603cdf0e10cSrcweir                 OnDropIndex();
604cdf0e10cSrcweir                 break;
605cdf0e10cSrcweir             case ID_INDEX_RENAME:
606cdf0e10cSrcweir                 OnRenameIndex();
607cdf0e10cSrcweir                 break;
608cdf0e10cSrcweir             case ID_INDEX_SAVE:
609cdf0e10cSrcweir                 OnSaveIndex();
610cdf0e10cSrcweir                 break;
611cdf0e10cSrcweir             case ID_INDEX_RESET:
612cdf0e10cSrcweir                 OnResetIndex();
613cdf0e10cSrcweir                 break;
614cdf0e10cSrcweir         }
615cdf0e10cSrcweir         return 0L;
616cdf0e10cSrcweir     }
617cdf0e10cSrcweir 
618cdf0e10cSrcweir     //------------------------------------------------------------------
619cdf0e10cSrcweir     IMPL_LINK( DbaIndexDialog, OnCloseDialog, void*, /*NOTINTERESTEDIN*/ )
620cdf0e10cSrcweir     {
621cdf0e10cSrcweir         if (m_aIndexes.IsEditingActive())
622cdf0e10cSrcweir         {
623cdf0e10cSrcweir             DBG_ASSERT(!m_bEditAgain, "DbaIndexDialog::OnCloseDialog: somebody was faster than hell!");
624cdf0e10cSrcweir                 // this means somebody entered a new name, which was invalid, which cause us to posted us an event,
625cdf0e10cSrcweir                 // and before the event arrived the user clicked onto "close". VERY fast, this user ....
626cdf0e10cSrcweir             m_aIndexes.EndEditing(sal_False);
627cdf0e10cSrcweir             if (m_bEditAgain)
628cdf0e10cSrcweir                 // could not commit the new name (started a new - asynchronous - edit trial)
629cdf0e10cSrcweir                 return 1L;
630cdf0e10cSrcweir         }
631cdf0e10cSrcweir 
632cdf0e10cSrcweir         // the currently selected entry
633cdf0e10cSrcweir         const SvLBoxEntry* pSelected = m_aIndexes.FirstSelected();
634cdf0e10cSrcweir         DBG_ASSERT(pSelected == m_pPreviousSelection, "DbaIndexDialog::OnCloseDialog: inconsistence!");
635cdf0e10cSrcweir 
636cdf0e10cSrcweir         sal_Int32 nResponse = RET_NO;
637cdf0e10cSrcweir         if (pSelected)
638cdf0e10cSrcweir         {
639cdf0e10cSrcweir             // the descriptor
640cdf0e10cSrcweir             Indexes::const_iterator aSelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(pSelected->GetUserData());
641cdf0e10cSrcweir 
642cdf0e10cSrcweir             if (aSelected->isModified() || aSelected->isNew())
643cdf0e10cSrcweir             {
644cdf0e10cSrcweir                 QueryBox aQuestion(this, ModuleRes(QUERY_SAVE_CURRENT_INDEX));
645cdf0e10cSrcweir                 nResponse = aQuestion.Execute();
646cdf0e10cSrcweir             }
647cdf0e10cSrcweir         }
648cdf0e10cSrcweir 
649cdf0e10cSrcweir         switch (nResponse)
650cdf0e10cSrcweir         {
651cdf0e10cSrcweir             case RET_YES:
652cdf0e10cSrcweir                 if (!implCommitPreviouslySelected())
653cdf0e10cSrcweir                     return 1L;
654cdf0e10cSrcweir                 break;
655cdf0e10cSrcweir             case RET_NO:
656cdf0e10cSrcweir                 break;
657cdf0e10cSrcweir             default:
658cdf0e10cSrcweir                 return 1L;
659cdf0e10cSrcweir         }
660cdf0e10cSrcweir 
661cdf0e10cSrcweir         EndDialog(RET_OK);
662cdf0e10cSrcweir 
663cdf0e10cSrcweir         return 0L;
664cdf0e10cSrcweir     }
665cdf0e10cSrcweir 
666cdf0e10cSrcweir     //------------------------------------------------------------------
IMPL_LINK(DbaIndexDialog,OnEditIndexAgain,SvLBoxEntry *,_pEntry)667cdf0e10cSrcweir     IMPL_LINK( DbaIndexDialog, OnEditIndexAgain, SvLBoxEntry*, _pEntry )
668cdf0e10cSrcweir     {
669cdf0e10cSrcweir         m_bEditAgain = sal_False;
670cdf0e10cSrcweir         m_aIndexes.EditEntry(_pEntry);
671cdf0e10cSrcweir         return 0L;
672cdf0e10cSrcweir     }
673cdf0e10cSrcweir 
674cdf0e10cSrcweir     //------------------------------------------------------------------
IMPL_LINK(DbaIndexDialog,OnEntryEdited,SvLBoxEntry *,_pEntry)675cdf0e10cSrcweir     IMPL_LINK( DbaIndexDialog, OnEntryEdited, SvLBoxEntry*, _pEntry )
676cdf0e10cSrcweir     {
677cdf0e10cSrcweir         Indexes::iterator aPosition = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
678cdf0e10cSrcweir 
679cdf0e10cSrcweir         DBG_ASSERT(aPosition >= m_pIndexes->begin() && aPosition < m_pIndexes->end(),
680cdf0e10cSrcweir             "DbaIndexDialog::OnEntryEdited: invalid entry!");
681cdf0e10cSrcweir 
682cdf0e10cSrcweir         String sNewName = m_aIndexes.GetEntryText(_pEntry);
683cdf0e10cSrcweir 
684cdf0e10cSrcweir         Indexes::const_iterator aSameName = m_pIndexes->find(sNewName);
685cdf0e10cSrcweir         if ((aSameName != aPosition) && (m_pIndexes->end() != aSameName))
686cdf0e10cSrcweir         {
687cdf0e10cSrcweir             String sError(ModuleRes(STR_INDEX_NAME_ALREADY_USED));
688cdf0e10cSrcweir             sError.SearchAndReplaceAscii("$name$", sNewName);
689cdf0e10cSrcweir             ErrorBox aError(this, WB_OK, sError);
690cdf0e10cSrcweir             aError.Execute();
691cdf0e10cSrcweir 
692cdf0e10cSrcweir             updateToolbox();
693cdf0e10cSrcweir             m_bEditAgain = sal_True;
694cdf0e10cSrcweir             PostUserEvent(LINK(this, DbaIndexDialog, OnEditIndexAgain), _pEntry);
695cdf0e10cSrcweir             return 0L;
696cdf0e10cSrcweir         }
697cdf0e10cSrcweir 
698cdf0e10cSrcweir         aPosition->sName = sNewName;
699cdf0e10cSrcweir 
700cdf0e10cSrcweir         // rename can be done by a drop/insert combination only
701cdf0e10cSrcweir         if (aPosition->isNew())
702cdf0e10cSrcweir         {
703cdf0e10cSrcweir             updateToolbox();
704cdf0e10cSrcweir             // no commitment needed here ....
705cdf0e10cSrcweir             return 1L;
706cdf0e10cSrcweir         }
707cdf0e10cSrcweir 
708cdf0e10cSrcweir         if (aPosition->sName != aPosition->getOriginalName())
709cdf0e10cSrcweir         {
710cdf0e10cSrcweir             aPosition->setModified(sal_True);
711cdf0e10cSrcweir             updateToolbox();
712cdf0e10cSrcweir         }
713cdf0e10cSrcweir 
714cdf0e10cSrcweir         return 1L;
715cdf0e10cSrcweir     }
716cdf0e10cSrcweir 
717cdf0e10cSrcweir     //------------------------------------------------------------------
implSaveModified(sal_Bool _bPlausibility)718cdf0e10cSrcweir     sal_Bool DbaIndexDialog::implSaveModified(sal_Bool _bPlausibility)
719cdf0e10cSrcweir     {
720cdf0e10cSrcweir         if (m_pPreviousSelection)
721cdf0e10cSrcweir         {
722cdf0e10cSrcweir             // try to commit the previously selected index
723cdf0e10cSrcweir             if (m_pFields->IsModified() && !m_pFields->SaveModified())
724cdf0e10cSrcweir                 return sal_False;
725cdf0e10cSrcweir 
726cdf0e10cSrcweir             Indexes::iterator aPreviouslySelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData());
727cdf0e10cSrcweir 
728cdf0e10cSrcweir             // the unique flag
729cdf0e10cSrcweir             aPreviouslySelected->bUnique = m_aUnique.IsChecked();
730cdf0e10cSrcweir             if (m_aUnique.GetSavedValue() != m_aUnique.GetState())
731cdf0e10cSrcweir                 aPreviouslySelected->setModified(sal_True);
732cdf0e10cSrcweir 
733cdf0e10cSrcweir             // the fields
734cdf0e10cSrcweir             m_pFields->commitTo(aPreviouslySelected->aFields);
735cdf0e10cSrcweir             if (m_pFields->GetSavedValue() != aPreviouslySelected->aFields)
736cdf0e10cSrcweir                 aPreviouslySelected->setModified(sal_True);
737cdf0e10cSrcweir 
738cdf0e10cSrcweir             // plausibility checks
739cdf0e10cSrcweir             if (_bPlausibility && !implCheckPlausibility(aPreviouslySelected))
740cdf0e10cSrcweir                 return sal_False;
741cdf0e10cSrcweir         }
742cdf0e10cSrcweir 
743cdf0e10cSrcweir         return sal_True;
744cdf0e10cSrcweir     }
745cdf0e10cSrcweir 
746cdf0e10cSrcweir     //------------------------------------------------------------------
implCheckPlausibility(const ConstIndexesIterator & _rPos)747cdf0e10cSrcweir     sal_Bool DbaIndexDialog::implCheckPlausibility(const ConstIndexesIterator& _rPos)
748cdf0e10cSrcweir     {
749cdf0e10cSrcweir         // need at least one field
750cdf0e10cSrcweir         if (0 == _rPos->aFields.size())
751cdf0e10cSrcweir         {
752cdf0e10cSrcweir             ErrorBox aError(this, ModuleRes(ERR_NEED_INDEX_FIELDS));
753cdf0e10cSrcweir             aError.Execute();
754cdf0e10cSrcweir             m_pFields->GrabFocus();
755cdf0e10cSrcweir             return sal_False;
756cdf0e10cSrcweir         }
757cdf0e10cSrcweir 
758cdf0e10cSrcweir         // no double fields
759cdf0e10cSrcweir         DECLARE_STL_STDKEY_SET( String, StringBag );
760cdf0e10cSrcweir         StringBag aExistentFields;
761cdf0e10cSrcweir         for (   ConstIndexFieldsIterator aFieldCheck = _rPos->aFields.begin();
762cdf0e10cSrcweir                 aFieldCheck != _rPos->aFields.end();
763cdf0e10cSrcweir                 ++aFieldCheck
764cdf0e10cSrcweir             )
765cdf0e10cSrcweir         {
766cdf0e10cSrcweir             if (aExistentFields.end() != aExistentFields.find(aFieldCheck->sFieldName))
767cdf0e10cSrcweir             {
768cdf0e10cSrcweir                 // a column is specified twice ... won't work anyway, so prevent this here and now
769cdf0e10cSrcweir                 String sMessage(ModuleRes(STR_INDEXDESIGN_DOUBLE_COLUMN_NAME));
770cdf0e10cSrcweir                 sMessage.SearchAndReplaceAscii("$name$", aFieldCheck->sFieldName);
771cdf0e10cSrcweir                 ErrorBox aError(this, WB_OK, sMessage);
772cdf0e10cSrcweir                 aError.Execute();
773cdf0e10cSrcweir                 m_pFields->GrabFocus();
774cdf0e10cSrcweir                 return sal_False;
775cdf0e10cSrcweir             }
776cdf0e10cSrcweir             aExistentFields.insert(aFieldCheck->sFieldName);
777cdf0e10cSrcweir         }
778cdf0e10cSrcweir 
779cdf0e10cSrcweir         return sal_True;
780cdf0e10cSrcweir     }
781cdf0e10cSrcweir 
782cdf0e10cSrcweir     //------------------------------------------------------------------
implCommitPreviouslySelected()783cdf0e10cSrcweir     sal_Bool DbaIndexDialog::implCommitPreviouslySelected()
784cdf0e10cSrcweir     {
785cdf0e10cSrcweir         if (m_pPreviousSelection)
786cdf0e10cSrcweir         {
787cdf0e10cSrcweir             Indexes::iterator aPreviouslySelected = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData());
788cdf0e10cSrcweir 
789cdf0e10cSrcweir             if (!implSaveModified())
790cdf0e10cSrcweir                 return sal_False;
791cdf0e10cSrcweir 
792cdf0e10cSrcweir             // commit the index (if necessary)
793cdf0e10cSrcweir             if (aPreviouslySelected->isModified() && !implCommit(m_pPreviousSelection))
794cdf0e10cSrcweir                 return sal_False;
795cdf0e10cSrcweir         }
796cdf0e10cSrcweir 
797cdf0e10cSrcweir         return sal_True;
798cdf0e10cSrcweir     }
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     //------------------------------------------------------------------
801cdf0e10cSrcweir     IMPL_LINK( DbaIndexDialog, OnModified, void*, /*NOTINTERESTEDIN*/ )
802cdf0e10cSrcweir     {
803cdf0e10cSrcweir         DBG_ASSERT(m_pPreviousSelection, "DbaIndexDialog, OnModified: invalid call!");
804cdf0e10cSrcweir         Indexes::iterator aPosition = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(m_pPreviousSelection->GetUserData());
805cdf0e10cSrcweir 
806cdf0e10cSrcweir         aPosition->setModified(sal_True);
807cdf0e10cSrcweir         updateToolbox();
808cdf0e10cSrcweir 
809cdf0e10cSrcweir         return 1L;
810cdf0e10cSrcweir     }
811cdf0e10cSrcweir 
812cdf0e10cSrcweir     //------------------------------------------------------------------
updateControls(const SvLBoxEntry * _pEntry)813cdf0e10cSrcweir     void DbaIndexDialog::updateControls(const SvLBoxEntry* _pEntry)
814cdf0e10cSrcweir     {
815cdf0e10cSrcweir         if (_pEntry)
816cdf0e10cSrcweir         {
817cdf0e10cSrcweir             // the descriptor of the selected index
818cdf0e10cSrcweir             Indexes::const_iterator aSelectedIndex = m_pIndexes->begin() + reinterpret_cast<sal_IntPtr>(_pEntry->GetUserData());
819cdf0e10cSrcweir 
820cdf0e10cSrcweir             // fill the controls
821cdf0e10cSrcweir             m_aUnique.Check(aSelectedIndex->bUnique);
822cdf0e10cSrcweir             m_aUnique.Enable(!aSelectedIndex->bPrimaryKey);
823cdf0e10cSrcweir             m_aUnique.SaveValue();
824cdf0e10cSrcweir 
825cdf0e10cSrcweir             m_pFields->initializeFrom(aSelectedIndex->aFields);
826cdf0e10cSrcweir             m_pFields->Enable(!aSelectedIndex->bPrimaryKey);
827cdf0e10cSrcweir             m_pFields->SaveValue();
828cdf0e10cSrcweir 
829cdf0e10cSrcweir             m_aDescription.SetText(aSelectedIndex->sDescription);
830cdf0e10cSrcweir             m_aDescription.Enable(!aSelectedIndex->bPrimaryKey);
831cdf0e10cSrcweir 
832cdf0e10cSrcweir             m_aDescriptionLabel.Enable(!aSelectedIndex->bPrimaryKey);
833cdf0e10cSrcweir         }
834cdf0e10cSrcweir         else
835cdf0e10cSrcweir         {
836cdf0e10cSrcweir             m_aUnique.Check(sal_False);
837cdf0e10cSrcweir             m_pFields->initializeFrom(IndexFields());
838cdf0e10cSrcweir             m_aDescription.SetText(String());
839cdf0e10cSrcweir         }
840cdf0e10cSrcweir     }
841cdf0e10cSrcweir 
842cdf0e10cSrcweir     //------------------------------------------------------------------
843cdf0e10cSrcweir     IMPL_LINK( DbaIndexDialog, OnIndexSelected, DbaIndexList*, /*NOTINTERESTEDIN*/ )
844cdf0e10cSrcweir     {
845cdf0e10cSrcweir         m_aIndexes.EndSelection();
846cdf0e10cSrcweir 
847cdf0e10cSrcweir         if (m_aIndexes.IsEditingActive())
848cdf0e10cSrcweir             m_aIndexes.EndEditing(sal_False);
849cdf0e10cSrcweir 
850cdf0e10cSrcweir         // commit the old data
851cdf0e10cSrcweir         if (m_aIndexes.FirstSelected() != m_pPreviousSelection)
852cdf0e10cSrcweir         {   // (this call may happen in case somebody ended an in-place edit with 'return', so we need to check this before committing)
853cdf0e10cSrcweir             if (!implCommitPreviouslySelected())
854cdf0e10cSrcweir             {
855cdf0e10cSrcweir                 m_aIndexes.SelectNoHandlerCall(m_pPreviousSelection);
856cdf0e10cSrcweir                 return 1L;
857cdf0e10cSrcweir             }
858cdf0e10cSrcweir         }
859cdf0e10cSrcweir 
860cdf0e10cSrcweir         sal_Bool bHaveSelection = (NULL != m_aIndexes.FirstSelected());
861cdf0e10cSrcweir 
862cdf0e10cSrcweir         // disable/enable the detail controls
863cdf0e10cSrcweir         m_aIndexDetails.Enable(bHaveSelection);
864cdf0e10cSrcweir         m_aUnique.Enable(bHaveSelection);
865cdf0e10cSrcweir         m_aDescriptionLabel.Enable(bHaveSelection);
866cdf0e10cSrcweir         m_aFieldsLabel.Enable(bHaveSelection);
867cdf0e10cSrcweir         m_pFields->Enable(bHaveSelection);
868cdf0e10cSrcweir 
869cdf0e10cSrcweir         SvLBoxEntry* pNewSelection = m_aIndexes.FirstSelected();
870cdf0e10cSrcweir         updateControls(pNewSelection);
871cdf0e10cSrcweir         if (bHaveSelection)
872cdf0e10cSrcweir             m_aIndexes.GrabFocus();
873cdf0e10cSrcweir 
874cdf0e10cSrcweir         m_pPreviousSelection = pNewSelection;
875cdf0e10cSrcweir 
876cdf0e10cSrcweir         updateToolbox();
877cdf0e10cSrcweir         return 0L;
878cdf0e10cSrcweir     }
879cdf0e10cSrcweir     // -----------------------------------------------------------------------------
StateChanged(StateChangedType nType)880cdf0e10cSrcweir     void DbaIndexDialog::StateChanged( StateChangedType nType )
881cdf0e10cSrcweir     {
882cdf0e10cSrcweir         ModalDialog::StateChanged( nType );
883cdf0e10cSrcweir 
884cdf0e10cSrcweir         if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
885cdf0e10cSrcweir         {
886cdf0e10cSrcweir             // Check if we need to get new images for normal/high contrast mode
887cdf0e10cSrcweir             checkImageList();
888cdf0e10cSrcweir         }
889cdf0e10cSrcweir         else if ( nType == STATE_CHANGE_TEXT )
890cdf0e10cSrcweir         {
891cdf0e10cSrcweir             // The physical toolbar changed its outlook and shows another logical toolbar!
892cdf0e10cSrcweir             // We have to set the correct high contrast mode on the new tbx manager.
893cdf0e10cSrcweir             //  pMgr->SetHiContrast( IsHiContrastMode() );
894cdf0e10cSrcweir             checkImageList();
895cdf0e10cSrcweir         }
896cdf0e10cSrcweir     }
897cdf0e10cSrcweir     // -----------------------------------------------------------------------------
DataChanged(const DataChangedEvent & rDCEvt)898cdf0e10cSrcweir     void DbaIndexDialog::DataChanged( const DataChangedEvent& rDCEvt )
899cdf0e10cSrcweir     {
900cdf0e10cSrcweir         ModalDialog::DataChanged( rDCEvt );
901cdf0e10cSrcweir 
902cdf0e10cSrcweir         if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS )   ||
903cdf0e10cSrcweir             ( rDCEvt.GetType() == DATACHANGED_DISPLAY   ))  &&
904cdf0e10cSrcweir             ( rDCEvt.GetFlags() & SETTINGS_STYLE        ))
905cdf0e10cSrcweir         {
906cdf0e10cSrcweir             // Check if we need to get new images for normal/high contrast mode
907cdf0e10cSrcweir             checkImageList();
908cdf0e10cSrcweir         }
909cdf0e10cSrcweir     }
910cdf0e10cSrcweir     //------------------------------------------------------------------
getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const911cdf0e10cSrcweir     ImageList DbaIndexDialog::getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const
912cdf0e10cSrcweir     {
913cdf0e10cSrcweir         sal_Int16 nN = IMG_INDEX_DLG_SC;
914cdf0e10cSrcweir         sal_Int16 nH = IMG_INDEX_DLG_SCH;
915cdf0e10cSrcweir         if ( _eBitmapSet == SFX_SYMBOLS_SIZE_LARGE )
916cdf0e10cSrcweir         {
917cdf0e10cSrcweir             nN = IMG_INDEX_DLG_LC;
918cdf0e10cSrcweir             nH = IMG_INDEX_DLG_LCH;
919cdf0e10cSrcweir         } // if ( _eBitmapSet == SFX_SYMBOLS_LARGE )
920cdf0e10cSrcweir         return ImageList(ModuleRes( _bHiContast ? nH : nN ));
921cdf0e10cSrcweir     }
922cdf0e10cSrcweir     //------------------------------------------------------------------
resizeControls(const Size & _rDiff)923cdf0e10cSrcweir     void DbaIndexDialog::resizeControls(const Size& _rDiff)
924cdf0e10cSrcweir     {
925cdf0e10cSrcweir         // we use large images so we must change them
926cdf0e10cSrcweir         Size aTbNewSize = m_aActions.GetSizePixel();
927cdf0e10cSrcweir         if ( _rDiff.Width() || _rDiff.Height() )
928cdf0e10cSrcweir         {
929cdf0e10cSrcweir             Size aDlgSize = GetSizePixel();
930cdf0e10cSrcweir             // adjust size of dlg
931cdf0e10cSrcweir             SetSizePixel(Size(aDlgSize.Width() + _rDiff.Width(),
932cdf0e10cSrcweir                               aDlgSize.Height() + _rDiff.Height())
933cdf0e10cSrcweir                         );
934cdf0e10cSrcweir             Size aIndexSize = m_aIndexes.GetSizePixel();
935cdf0e10cSrcweir             m_aIndexes.SetPosSizePixel(m_aIndexes.GetPosPixel() + Point(0,_rDiff.Height()),
936cdf0e10cSrcweir                                     Size(aIndexSize.Width() + _rDiff.Width(),
937cdf0e10cSrcweir                                          aIndexSize.Height()));
938cdf0e10cSrcweir 
939cdf0e10cSrcweir             // now move the rest to the left side
940cdf0e10cSrcweir             Point aMove(_rDiff.Width(),_rDiff.Height());
941cdf0e10cSrcweir             m_aIndexDetails.SetPosPixel(m_aIndexDetails.GetPosPixel() + aMove);
942cdf0e10cSrcweir             m_aDescriptionLabel.SetPosPixel(m_aDescriptionLabel.GetPosPixel() + aMove);
943cdf0e10cSrcweir             m_aDescription.SetPosPixel(m_aDescription.GetPosPixel() + aMove);
944cdf0e10cSrcweir             m_aUnique.SetPosPixel(m_aUnique.GetPosPixel() + aMove);
945cdf0e10cSrcweir             m_aFieldsLabel.SetPosPixel(m_aFieldsLabel.GetPosPixel() + aMove);
946cdf0e10cSrcweir             OSL_ENSURE(m_pFields,"NO valid fields!");
947cdf0e10cSrcweir             m_pFields->SetPosPixel(m_pFields->GetPosPixel() + aMove);
948cdf0e10cSrcweir             m_aClose.SetPosPixel(m_aClose.GetPosPixel() + aMove);
949cdf0e10cSrcweir             m_aHelp.SetPosPixel(m_aHelp.GetPosPixel() + aMove);
950cdf0e10cSrcweir 
951cdf0e10cSrcweir             Invalidate();
952cdf0e10cSrcweir         }
953cdf0e10cSrcweir     }
954cdf0e10cSrcweir 
955cdf0e10cSrcweir //......................................................................
956cdf0e10cSrcweir }   // namespace dbaui
957cdf0e10cSrcweir 
958*ca41231dSmseidel /* vim: set noet sw=4 ts=4: */
959