xref: /trunk/main/dbaccess/source/ui/dlg/indexfieldscontrol.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
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_INDEXFIELDSCONTROL_HXX_
28cdf0e10cSrcweir #include "indexfieldscontrol.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef _DBU_DLG_HRC_
31cdf0e10cSrcweir #include "dbu_dlg.hrc"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _OSL_DIAGNOSE_H_
34cdf0e10cSrcweir #include <osl/diagnose.h>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_
37cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //......................................................................
41cdf0e10cSrcweir namespace dbaui
42cdf0e10cSrcweir {
43cdf0e10cSrcweir //......................................................................
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #define BROWSER_STANDARD_FLAGS      BROWSER_COLUMNSELECTION | BROWSER_HLINESFULL | BROWSER_VLINESFULL | \
46cdf0e10cSrcweir                                     BROWSER_HIDECURSOR | BROWSER_HIDESELECT | BROWSER_AUTO_HSCROLL | BROWSER_AUTO_VSCROLL
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #define COLUMN_ID_FIELDNAME     1
49cdf0e10cSrcweir #define COLUMN_ID_ORDER         2
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
52cdf0e10cSrcweir     using namespace ::svt;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     //==================================================================
55cdf0e10cSrcweir     //= DbaMouseDownListBoxController
56cdf0e10cSrcweir     //==================================================================
57cdf0e10cSrcweir     class DbaMouseDownListBoxController : public ListBoxCellController
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir     protected:
60cdf0e10cSrcweir         Link    m_aOriginalModifyHdl;
61cdf0e10cSrcweir         Link    m_aAdditionalModifyHdl;
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     public:
DbaMouseDownListBoxController(ListBoxControl * _pParent)64cdf0e10cSrcweir         DbaMouseDownListBoxController(ListBoxControl* _pParent)
65cdf0e10cSrcweir             :ListBoxCellController(_pParent)
66cdf0e10cSrcweir         {
67cdf0e10cSrcweir         }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir         void SetAdditionalModifyHdl(const Link& _rHdl);
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     protected:
WantMouseEvent() const72cdf0e10cSrcweir         virtual sal_Bool WantMouseEvent() const { return sal_True; }
73cdf0e10cSrcweir         virtual void SetModifyHdl(const Link& _rHdl);
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     private:
76cdf0e10cSrcweir         void implCheckLinks();
77cdf0e10cSrcweir         DECL_LINK( OnMultiplexModify, void* );
78cdf0e10cSrcweir     };
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     //------------------------------------------------------------------
SetAdditionalModifyHdl(const Link & _rHdl)81cdf0e10cSrcweir     void DbaMouseDownListBoxController::SetAdditionalModifyHdl(const Link& _rHdl)
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         m_aAdditionalModifyHdl = _rHdl;
84cdf0e10cSrcweir         implCheckLinks();
85cdf0e10cSrcweir     }
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     //------------------------------------------------------------------
SetModifyHdl(const Link & _rHdl)88cdf0e10cSrcweir     void DbaMouseDownListBoxController::SetModifyHdl(const Link& _rHdl)
89cdf0e10cSrcweir     {
90cdf0e10cSrcweir         m_aOriginalModifyHdl = _rHdl;
91cdf0e10cSrcweir         implCheckLinks();
92cdf0e10cSrcweir     }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     //------------------------------------------------------------------
IMPL_LINK(DbaMouseDownListBoxController,OnMultiplexModify,void *,_pArg)95cdf0e10cSrcweir     IMPL_LINK( DbaMouseDownListBoxController, OnMultiplexModify, void*, _pArg )
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         if (m_aAdditionalModifyHdl.IsSet())
98cdf0e10cSrcweir             m_aAdditionalModifyHdl.Call(_pArg);
99cdf0e10cSrcweir         if (m_aOriginalModifyHdl.IsSet())
100cdf0e10cSrcweir             m_aOriginalModifyHdl.Call(_pArg);
101cdf0e10cSrcweir         return 0L;
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     //------------------------------------------------------------------
implCheckLinks()105cdf0e10cSrcweir     void DbaMouseDownListBoxController::implCheckLinks()
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         if (m_aAdditionalModifyHdl.IsSet() || m_aOriginalModifyHdl.IsSet())
108cdf0e10cSrcweir             ListBoxCellController::SetModifyHdl(LINK(this, DbaMouseDownListBoxController, OnMultiplexModify));
109cdf0e10cSrcweir         else
110cdf0e10cSrcweir             ListBoxCellController::SetModifyHdl(Link());
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     //==================================================================
114cdf0e10cSrcweir     //= IndexFieldsControl
115cdf0e10cSrcweir     //==================================================================
DBG_NAME(IndexFieldsControl)116cdf0e10cSrcweir DBG_NAME(IndexFieldsControl)
117cdf0e10cSrcweir //------------------------------------------------------------------
118cdf0e10cSrcweir     IndexFieldsControl::IndexFieldsControl( Window* _pParent, const ResId& _rId ,sal_Int32 _nMaxColumnsInIndex,sal_Bool _bAddIndexAppendix)
119cdf0e10cSrcweir         :EditBrowseBox(_pParent, _rId, EBBF_SMART_TAB_TRAVEL | EBBF_ACTIVATE_ON_BUTTONDOWN, BROWSER_STANDARD_FLAGS)
120cdf0e10cSrcweir         ,m_aSeekRow(m_aFields.end())
121cdf0e10cSrcweir         ,m_pSortingCell(NULL)
122cdf0e10cSrcweir         ,m_pFieldNameCell(NULL)
123cdf0e10cSrcweir         ,m_nMaxColumnsInIndex(_nMaxColumnsInIndex)
124cdf0e10cSrcweir         ,m_bAddIndexAppendix(_bAddIndexAppendix)
125cdf0e10cSrcweir     {
126cdf0e10cSrcweir         DBG_CTOR(IndexFieldsControl,NULL);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir         SetUniqueId( UID_DLGINDEX_INDEXDETAILS_BACK );
129cdf0e10cSrcweir         GetDataWindow().SetUniqueId( UID_DLGINDEX_INDEXDETAILS_MAIN );
130cdf0e10cSrcweir     }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     //------------------------------------------------------------------
~IndexFieldsControl()133cdf0e10cSrcweir     IndexFieldsControl::~IndexFieldsControl()
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         delete m_pSortingCell;
136cdf0e10cSrcweir         delete m_pFieldNameCell;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         DBG_DTOR(IndexFieldsControl,NULL);
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     //------------------------------------------------------------------
SeekRow(long nRow)142cdf0e10cSrcweir     sal_Bool IndexFieldsControl::SeekRow(long nRow)
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         if (!EditBrowseBox::SeekRow(nRow))
145cdf0e10cSrcweir             return sal_False;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir         if (nRow < 0)
148cdf0e10cSrcweir         {
149cdf0e10cSrcweir             m_aSeekRow = m_aFields.end();
150cdf0e10cSrcweir         }
151cdf0e10cSrcweir         else
152cdf0e10cSrcweir         {
153cdf0e10cSrcweir             m_aSeekRow = m_aFields.begin() + nRow;
154cdf0e10cSrcweir             OSL_ENSURE(m_aSeekRow <= m_aFields.end(), "IndexFieldsControl::SeekRow: invalid row!");
155cdf0e10cSrcweir         }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir         return sal_True;
158cdf0e10cSrcweir     }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     //------------------------------------------------------------------
PaintCell(OutputDevice & _rDev,const Rectangle & _rRect,sal_uInt16 _nColumnId) const161cdf0e10cSrcweir     void IndexFieldsControl::PaintCell( OutputDevice& _rDev, const Rectangle& _rRect, sal_uInt16 _nColumnId ) const
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         Point aPos(_rRect.TopLeft());
164cdf0e10cSrcweir         aPos.X() += 1;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         String aText = GetRowCellText(m_aSeekRow,_nColumnId);
167cdf0e10cSrcweir         Size TxtSize(GetDataWindow().GetTextWidth(aText), GetDataWindow().GetTextHeight());
168cdf0e10cSrcweir 
169cdf0e10cSrcweir         // clipping
170cdf0e10cSrcweir         if (aPos.X() < _rRect.Right() || aPos.X() + TxtSize.Width() > _rRect.Right() ||
171cdf0e10cSrcweir             aPos.Y() < _rRect.Top() || aPos.Y() + TxtSize.Height() > _rRect.Bottom())
172cdf0e10cSrcweir             _rDev.SetClipRegion( _rRect );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir         // allow for a disabled control ...
175cdf0e10cSrcweir         sal_Bool bEnabled = IsEnabled();
176cdf0e10cSrcweir         Color aOriginalColor = _rDev.GetTextColor();
177cdf0e10cSrcweir         if (!bEnabled)
178cdf0e10cSrcweir             _rDev.SetTextColor(GetSettings().GetStyleSettings().GetDisableColor());
179cdf0e10cSrcweir 
180cdf0e10cSrcweir         // draw the text
181cdf0e10cSrcweir         _rDev.DrawText(aPos, aText);
182cdf0e10cSrcweir 
183cdf0e10cSrcweir         // reset the color (if necessary)
184cdf0e10cSrcweir         if (!bEnabled)
185cdf0e10cSrcweir             _rDev.SetTextColor(aOriginalColor);
186cdf0e10cSrcweir 
187cdf0e10cSrcweir         if (_rDev.IsClipRegion())
188cdf0e10cSrcweir             _rDev.SetClipRegion();
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     //------------------------------------------------------------------
initializeFrom(const IndexFields & _rFields)192cdf0e10cSrcweir     void IndexFieldsControl::initializeFrom(const IndexFields& _rFields)
193cdf0e10cSrcweir     {
194cdf0e10cSrcweir         // copy the field descriptions
195cdf0e10cSrcweir         m_aFields = _rFields;
196cdf0e10cSrcweir         m_aSeekRow = m_aFields.end();
197cdf0e10cSrcweir 
198cdf0e10cSrcweir         SetUpdateMode(sal_False);
199cdf0e10cSrcweir         // remove all rows
200cdf0e10cSrcweir         RowRemoved(1, GetRowCount());
201*7950f2afSmseidel         // insert rows for the fields
202cdf0e10cSrcweir         RowInserted(GetRowCount(), m_aFields.size(), sal_False);
203cdf0e10cSrcweir         // insert an additional row for a new field for that index
204cdf0e10cSrcweir //      if(!m_nMaxColumnsInIndex || GetRowCount() < m_nMaxColumnsInIndex )
205cdf0e10cSrcweir         RowInserted(GetRowCount(), 1, sal_False);
206cdf0e10cSrcweir         SetUpdateMode(sal_True);
207cdf0e10cSrcweir 
208cdf0e10cSrcweir         GoToRowColumnId(0, COLUMN_ID_FIELDNAME);
209cdf0e10cSrcweir     }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     //------------------------------------------------------------------
commitTo(IndexFields & _rFields)212cdf0e10cSrcweir     void IndexFieldsControl::commitTo(IndexFields& _rFields)
213cdf0e10cSrcweir     {
214cdf0e10cSrcweir         // do not just copy the array, we may have empty field names (which should not be copied)
215cdf0e10cSrcweir         _rFields.resize(m_aFields.size());
216cdf0e10cSrcweir         ConstIndexFieldsIterator aSource = m_aFields.begin();
217cdf0e10cSrcweir         ConstIndexFieldsIterator aSourceEnd = m_aFields.end();
218cdf0e10cSrcweir         IndexFieldsIterator aDest = _rFields.begin();
219cdf0e10cSrcweir         for (; aSource < aSourceEnd; ++aSource)
220cdf0e10cSrcweir             if (0 != aSource->sFieldName.Len())
221cdf0e10cSrcweir             {
222cdf0e10cSrcweir                 *aDest = *aSource;
223cdf0e10cSrcweir                 ++aDest;
224cdf0e10cSrcweir             }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir         _rFields.resize(aDest - _rFields.begin());
227cdf0e10cSrcweir     }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     //------------------------------------------------------------------
GetTotalCellWidth(long _nRow,sal_uInt16 _nColId)230cdf0e10cSrcweir     sal_uInt32 IndexFieldsControl::GetTotalCellWidth(long _nRow, sal_uInt16 _nColId)
231cdf0e10cSrcweir     {
232cdf0e10cSrcweir         if (COLUMN_ID_ORDER == _nColId)
233cdf0e10cSrcweir         {
234cdf0e10cSrcweir             sal_Int32 nWidthAsc = GetTextWidth(m_sAscendingText) + GetSettings().GetStyleSettings().GetScrollBarSize();
235cdf0e10cSrcweir             sal_Int32 nWidthDesc = GetTextWidth(m_sDescendingText) + GetSettings().GetStyleSettings().GetScrollBarSize();
236cdf0e10cSrcweir             // maximum plus some additional space
237cdf0e10cSrcweir             return (nWidthAsc > nWidthDesc ? nWidthAsc : nWidthDesc) + GetTextWidth('0') * 2;
238cdf0e10cSrcweir         }
239cdf0e10cSrcweir         return EditBrowseBox::GetTotalCellWidth(_nRow, _nColId);
240cdf0e10cSrcweir     }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     //------------------------------------------------------------------
Init(const Sequence<::rtl::OUString> & _rAvailableFields)243cdf0e10cSrcweir     void IndexFieldsControl::Init(const Sequence< ::rtl::OUString >& _rAvailableFields)
244cdf0e10cSrcweir     {
245cdf0e10cSrcweir         RemoveColumns();
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         // for the width: both columns together should be somewhat smaller than the whole window (without the scrollbar)
248cdf0e10cSrcweir         sal_Int32 nFieldNameWidth = GetSizePixel().Width();
249cdf0e10cSrcweir 
250cdf0e10cSrcweir         if ( m_bAddIndexAppendix )
251cdf0e10cSrcweir         {
252cdf0e10cSrcweir             m_sAscendingText = String(ModuleRes(STR_ORDER_ASCENDING));
253cdf0e10cSrcweir             m_sDescendingText = String(ModuleRes(STR_ORDER_DESCENDING));
254cdf0e10cSrcweir 
255cdf0e10cSrcweir             // the "sort order" column
256cdf0e10cSrcweir             String sColumnName = String(ModuleRes(STR_TAB_INDEX_SORTORDER));
257cdf0e10cSrcweir             // the width of the order column is the maximum widths of the texts used
258cdf0e10cSrcweir             // (the title of the column)
259cdf0e10cSrcweir             sal_Int32 nSortOrderColumnWidth = GetTextWidth(sColumnName);
260cdf0e10cSrcweir             // ("ascending" + scrollbar width)
261cdf0e10cSrcweir             sal_Int32 nOther = GetTextWidth(m_sAscendingText) + GetSettings().GetStyleSettings().GetScrollBarSize();
262cdf0e10cSrcweir             nSortOrderColumnWidth = nSortOrderColumnWidth > nOther ? nSortOrderColumnWidth : nOther;
263cdf0e10cSrcweir             // ("descending" + scrollbar width)
264cdf0e10cSrcweir             nOther = GetTextWidth(m_sDescendingText) + GetSettings().GetStyleSettings().GetScrollBarSize();
265cdf0e10cSrcweir             nSortOrderColumnWidth = nSortOrderColumnWidth > nOther ? nSortOrderColumnWidth : nOther;
266cdf0e10cSrcweir             // (plus some additional space)
267cdf0e10cSrcweir             nSortOrderColumnWidth += GetTextWidth('0') * 2;
268cdf0e10cSrcweir             InsertDataColumn(COLUMN_ID_ORDER, sColumnName, nSortOrderColumnWidth, HIB_STDSTYLE, 1);
269cdf0e10cSrcweir 
270cdf0e10cSrcweir             m_pSortingCell = new ListBoxControl(&GetDataWindow());
271cdf0e10cSrcweir             m_pSortingCell->InsertEntry(m_sAscendingText);
272cdf0e10cSrcweir             m_pSortingCell->InsertEntry(m_sDescendingText);
273cdf0e10cSrcweir             m_pSortingCell->SetHelpId( HID_DLGINDEX_INDEXDETAILS_SORTORDER );
274cdf0e10cSrcweir 
275cdf0e10cSrcweir             nFieldNameWidth -= nSortOrderColumnWidth;
276cdf0e10cSrcweir         }
277cdf0e10cSrcweir         StyleSettings aSystemStyle = Application::GetSettings().GetStyleSettings();
278cdf0e10cSrcweir         nFieldNameWidth -= aSystemStyle.GetScrollBarSize();
279cdf0e10cSrcweir         nFieldNameWidth -= 8;
280cdf0e10cSrcweir         // the "field name" column
281cdf0e10cSrcweir         String sColumnName = String(ModuleRes(STR_TAB_INDEX_FIELD));
282cdf0e10cSrcweir         InsertDataColumn(COLUMN_ID_FIELDNAME, sColumnName, nFieldNameWidth, HIB_STDSTYLE, 0);
283cdf0e10cSrcweir 
284cdf0e10cSrcweir         // create the cell controllers
285cdf0e10cSrcweir         // for the field name cell
286cdf0e10cSrcweir         m_pFieldNameCell = new ListBoxControl(&GetDataWindow());
287cdf0e10cSrcweir         m_pFieldNameCell->InsertEntry(String());
288cdf0e10cSrcweir         m_pFieldNameCell->SetHelpId( HID_DLGINDEX_INDEXDETAILS_FIELD );
289cdf0e10cSrcweir         const ::rtl::OUString* pFields = _rAvailableFields.getConstArray();
290cdf0e10cSrcweir         const ::rtl::OUString* pFieldsEnd = pFields + _rAvailableFields.getLength();
291cdf0e10cSrcweir         for (;pFields < pFieldsEnd; ++pFields)
292cdf0e10cSrcweir             m_pFieldNameCell->InsertEntry(*pFields);
293cdf0e10cSrcweir     }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir     //------------------------------------------------------------------
GetController(long _nRow,sal_uInt16 _nColumnId)296cdf0e10cSrcweir     CellController* IndexFieldsControl::GetController(long _nRow, sal_uInt16 _nColumnId)
297cdf0e10cSrcweir     {
298cdf0e10cSrcweir         if (!IsEnabled())
299cdf0e10cSrcweir             return NULL;
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         ConstIndexFieldsIterator aRow;
302cdf0e10cSrcweir         sal_Bool bNewField = !implGetFieldDesc(_nRow, aRow);
303cdf0e10cSrcweir 
304cdf0e10cSrcweir         DbaMouseDownListBoxController* pReturn = NULL;
305cdf0e10cSrcweir         switch (_nColumnId)
306cdf0e10cSrcweir         {
307cdf0e10cSrcweir             case COLUMN_ID_ORDER:
308cdf0e10cSrcweir                 if (!bNewField && m_pSortingCell && 0 != aRow->sFieldName.Len())
309cdf0e10cSrcweir                     pReturn = new DbaMouseDownListBoxController(m_pSortingCell);
310cdf0e10cSrcweir                 break;
311cdf0e10cSrcweir 
312cdf0e10cSrcweir             case COLUMN_ID_FIELDNAME:
313cdf0e10cSrcweir                 pReturn = new DbaMouseDownListBoxController(m_pFieldNameCell);
314cdf0e10cSrcweir                 break;
315cdf0e10cSrcweir 
316cdf0e10cSrcweir             default:
317cdf0e10cSrcweir                 OSL_ENSURE(sal_False, "IndexFieldsControl::GetController: invalid column id!");
318cdf0e10cSrcweir         }
319cdf0e10cSrcweir 
320cdf0e10cSrcweir         if (pReturn)
321cdf0e10cSrcweir             pReturn->SetAdditionalModifyHdl(LINK(this, IndexFieldsControl, OnListEntrySelected));
322cdf0e10cSrcweir 
323cdf0e10cSrcweir         return pReturn;
324cdf0e10cSrcweir     }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir     //------------------------------------------------------------------
implGetFieldDesc(long _nRow,ConstIndexFieldsIterator & _rPos)327cdf0e10cSrcweir     sal_Bool IndexFieldsControl::implGetFieldDesc(long _nRow, ConstIndexFieldsIterator& _rPos)
328cdf0e10cSrcweir     {
329cdf0e10cSrcweir         _rPos = m_aFields.end();
330cdf0e10cSrcweir         if ((_nRow < 0) || (_nRow >= (sal_Int32)m_aFields.size()))
331cdf0e10cSrcweir             return sal_False;
332cdf0e10cSrcweir         _rPos = m_aFields.begin() + _nRow;
333cdf0e10cSrcweir         return sal_True;
334cdf0e10cSrcweir     }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     //------------------------------------------------------------------
IsModified() const337cdf0e10cSrcweir     sal_Bool IndexFieldsControl::IsModified() const
338cdf0e10cSrcweir     {
339cdf0e10cSrcweir         return EditBrowseBox::IsModified();
340cdf0e10cSrcweir     }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir     //------------------------------------------------------------------
SaveModified()343cdf0e10cSrcweir     sal_Bool IndexFieldsControl::SaveModified()
344cdf0e10cSrcweir     {
345cdf0e10cSrcweir         if (!IsModified())
346cdf0e10cSrcweir             return sal_True;
347cdf0e10cSrcweir 
348cdf0e10cSrcweir         switch (GetCurColumnId())
349cdf0e10cSrcweir         {
350cdf0e10cSrcweir             case COLUMN_ID_FIELDNAME:
351cdf0e10cSrcweir             {
352cdf0e10cSrcweir                 String sFieldSelected = m_pFieldNameCell->GetSelectEntry();
353cdf0e10cSrcweir                 sal_Bool bEmptySelected = 0 == sFieldSelected.Len();
354cdf0e10cSrcweir                 if (isNewField())
355cdf0e10cSrcweir                 {
356cdf0e10cSrcweir                     if (!bEmptySelected)
357cdf0e10cSrcweir                     {
358cdf0e10cSrcweir                         // add a new field to the collection
359cdf0e10cSrcweir                         OIndexField aNewField;
360cdf0e10cSrcweir                         aNewField.sFieldName = sFieldSelected;
361cdf0e10cSrcweir                         m_aFields.push_back(aNewField);
362cdf0e10cSrcweir                         RowInserted(GetRowCount(), 1, sal_True);
363cdf0e10cSrcweir                     }
364cdf0e10cSrcweir                 }
365cdf0e10cSrcweir                 else
366cdf0e10cSrcweir                 {
367cdf0e10cSrcweir                     sal_Int32 nRow = GetCurRow();
368cdf0e10cSrcweir                     OSL_ENSURE(nRow < (sal_Int32)m_aFields.size(), "IndexFieldsControl::SaveModified: invalid current row!");
369cdf0e10cSrcweir                     if (nRow >= 0)  // may be -1 in case the control was empty
370cdf0e10cSrcweir                     {
371cdf0e10cSrcweir                         // remove the field from the selection
372cdf0e10cSrcweir                         IndexFieldsIterator aPos = m_aFields.begin() + nRow;
373cdf0e10cSrcweir 
374cdf0e10cSrcweir                         if (bEmptySelected)
375cdf0e10cSrcweir                         {
376cdf0e10cSrcweir                             aPos->sFieldName = String();
377cdf0e10cSrcweir 
378cdf0e10cSrcweir                             // invalidate the row to force repaint
379cdf0e10cSrcweir                             Invalidate(GetRowRectPixel(nRow));
380cdf0e10cSrcweir                             return sal_True;
381cdf0e10cSrcweir                         }
382cdf0e10cSrcweir 
383cdf0e10cSrcweir                         if (sFieldSelected == aPos->sFieldName)
384cdf0e10cSrcweir                             // nothing changed
385cdf0e10cSrcweir                             return sal_True;
386cdf0e10cSrcweir 
387cdf0e10cSrcweir                         aPos->sFieldName = sFieldSelected;
388cdf0e10cSrcweir                     }
389cdf0e10cSrcweir                 }
390cdf0e10cSrcweir 
391cdf0e10cSrcweir                 Invalidate(GetRowRectPixel(GetCurRow()));
392cdf0e10cSrcweir             }
393cdf0e10cSrcweir             break;
394cdf0e10cSrcweir             case COLUMN_ID_ORDER:
395cdf0e10cSrcweir             {
396cdf0e10cSrcweir                 OSL_ENSURE(!isNewField(), "IndexFieldsControl::SaveModified: why the hell ...!!!");
397cdf0e10cSrcweir                 // selected entry
398cdf0e10cSrcweir                 sal_uInt16 nPos = m_pSortingCell->GetSelectEntryPos();
399cdf0e10cSrcweir                 OSL_ENSURE(LISTBOX_ENTRY_NOTFOUND != nPos, "IndexFieldsControl::SaveModified: how did you get this selection??");
400cdf0e10cSrcweir                 // adjust the sort flag in the index field description
401cdf0e10cSrcweir                 OIndexField& rCurrentField = m_aFields[GetCurRow()];
402cdf0e10cSrcweir                 rCurrentField.bSortAscending = (0 == nPos);
403cdf0e10cSrcweir 
404cdf0e10cSrcweir             }
405cdf0e10cSrcweir             break;
406cdf0e10cSrcweir             default:
407cdf0e10cSrcweir                 OSL_ENSURE(sal_False, "IndexFieldsControl::SaveModified: invalid column id!");
408cdf0e10cSrcweir         }
409cdf0e10cSrcweir         return sal_True;
410cdf0e10cSrcweir     }
411cdf0e10cSrcweir 
412cdf0e10cSrcweir     //------------------------------------------------------------------
InitController(CellControllerRef &,long _nRow,sal_uInt16 _nColumnId)413cdf0e10cSrcweir     void IndexFieldsControl::InitController(CellControllerRef& /*_rController*/, long _nRow, sal_uInt16 _nColumnId)
414cdf0e10cSrcweir     {
415cdf0e10cSrcweir         ConstIndexFieldsIterator aFieldDescription;
416cdf0e10cSrcweir         sal_Bool bNewField = !implGetFieldDesc(_nRow, aFieldDescription);
417cdf0e10cSrcweir 
418cdf0e10cSrcweir         switch (_nColumnId)
419cdf0e10cSrcweir         {
420cdf0e10cSrcweir             case COLUMN_ID_FIELDNAME:
421cdf0e10cSrcweir                 m_pFieldNameCell->SelectEntry(bNewField ? String() : aFieldDescription->sFieldName);
422cdf0e10cSrcweir                 m_pFieldNameCell->SaveValue();
423cdf0e10cSrcweir                 break;
424cdf0e10cSrcweir 
425cdf0e10cSrcweir             case COLUMN_ID_ORDER:
426cdf0e10cSrcweir                 m_pSortingCell->SelectEntry(aFieldDescription->bSortAscending ? m_sAscendingText : m_sDescendingText);
427cdf0e10cSrcweir                 m_pSortingCell->SaveValue();
428cdf0e10cSrcweir                 break;
429cdf0e10cSrcweir 
430cdf0e10cSrcweir             default:
431cdf0e10cSrcweir                 OSL_ENSURE(sal_False, "IndexFieldsControl::InitController: invalid column id!");
432cdf0e10cSrcweir         }
433cdf0e10cSrcweir     }
434cdf0e10cSrcweir 
435cdf0e10cSrcweir     //------------------------------------------------------------------
IMPL_LINK(IndexFieldsControl,OnListEntrySelected,ListBox *,_pBox)436cdf0e10cSrcweir     IMPL_LINK( IndexFieldsControl, OnListEntrySelected, ListBox*, _pBox )
437cdf0e10cSrcweir     {
438cdf0e10cSrcweir         if (!_pBox->IsTravelSelect() && m_aModifyHdl.IsSet())
439cdf0e10cSrcweir             m_aModifyHdl.Call(this);
440cdf0e10cSrcweir 
441cdf0e10cSrcweir         if (_pBox == m_pFieldNameCell)
442cdf0e10cSrcweir         {   // a field has been selected
443cdf0e10cSrcweir             if (GetCurRow() >= GetRowCount() - 2)
444cdf0e10cSrcweir             {   // and we're in one of the last two rows
445cdf0e10cSrcweir                 String sSelectedEntry = m_pFieldNameCell->GetSelectEntry();
446cdf0e10cSrcweir                 sal_Int32 nCurrentRow = GetCurRow();
447cdf0e10cSrcweir                 sal_Int32 rowCount = GetRowCount();
448cdf0e10cSrcweir 
449cdf0e10cSrcweir                 OSL_ENSURE(((sal_Int32)(m_aFields.size() + 1)) == rowCount, "IndexFieldsControl::OnListEntrySelected: inconsistence!");
450cdf0e10cSrcweir 
451cdf0e10cSrcweir                 if (sSelectedEntry.Len() && (nCurrentRow == rowCount - 1) /*&& (!m_nMaxColumnsInIndex || rowCount < m_nMaxColumnsInIndex )*/ )
452cdf0e10cSrcweir                 {   // in the last row, an non-empty string has been selected
453cdf0e10cSrcweir                     // -> insert a new row
454cdf0e10cSrcweir                     m_aFields.push_back(OIndexField());
455cdf0e10cSrcweir                     RowInserted(GetRowCount(), 1);
456cdf0e10cSrcweir                     Invalidate(GetRowRectPixel(nCurrentRow));
457cdf0e10cSrcweir                 }
458cdf0e10cSrcweir                 else if (!sSelectedEntry.Len() && (nCurrentRow == rowCount - 2))
459cdf0e10cSrcweir                 {   // in the (last-1)th row, an empty entry has been selected
460cdf0e10cSrcweir                     // -> remove the last row
461cdf0e10cSrcweir                     m_aFields.erase(m_aFields.end() - 1);
462cdf0e10cSrcweir                     RowRemoved(GetRowCount() - 1, 1);
463cdf0e10cSrcweir                     Invalidate(GetRowRectPixel(nCurrentRow));
464cdf0e10cSrcweir                 }
465cdf0e10cSrcweir             }
466cdf0e10cSrcweir 
467cdf0e10cSrcweir             SaveModified();
468cdf0e10cSrcweir         }
469cdf0e10cSrcweir         return 0L;
470cdf0e10cSrcweir     }
471cdf0e10cSrcweir     //------------------------------------------------------------------
GetCellText(long _nRow,sal_uInt16 nColId) const472cdf0e10cSrcweir     String IndexFieldsControl::GetCellText(long _nRow,sal_uInt16 nColId) const
473cdf0e10cSrcweir     {
474cdf0e10cSrcweir         ConstIndexFieldsIterator aRow = m_aFields.end();
475cdf0e10cSrcweir         if ( _nRow >= 0 )
476cdf0e10cSrcweir         {
477cdf0e10cSrcweir             aRow = m_aFields.begin() + _nRow;
478cdf0e10cSrcweir             OSL_ENSURE(aRow <= m_aFields.end(), "IndexFieldsControl::SeekRow: invalid row!");
479cdf0e10cSrcweir         }
480cdf0e10cSrcweir         return GetRowCellText(aRow,nColId);
481cdf0e10cSrcweir     }
482cdf0e10cSrcweir     //------------------------------------------------------------------
GetRowCellText(const ConstIndexFieldsIterator & _rRow,sal_uInt16 nColId) const483cdf0e10cSrcweir     String IndexFieldsControl::GetRowCellText(const ConstIndexFieldsIterator& _rRow,sal_uInt16 nColId) const
484cdf0e10cSrcweir     {
485cdf0e10cSrcweir         if (_rRow < m_aFields.end())
486cdf0e10cSrcweir         {
487cdf0e10cSrcweir             switch (nColId)
488cdf0e10cSrcweir             {
489cdf0e10cSrcweir                 case COLUMN_ID_FIELDNAME:
490cdf0e10cSrcweir                     return _rRow->sFieldName;
491cdf0e10cSrcweir                 case COLUMN_ID_ORDER:
492cdf0e10cSrcweir                     if (0 == _rRow->sFieldName.Len())
493cdf0e10cSrcweir                         return String();
494cdf0e10cSrcweir                     else
495cdf0e10cSrcweir                         return _rRow->bSortAscending ? m_sAscendingText : m_sDescendingText;
496cdf0e10cSrcweir                 default:
497cdf0e10cSrcweir                     OSL_ENSURE(sal_False, "IndexFieldsControl::GetCurrentRowCellText: invalid column id!");
498cdf0e10cSrcweir             }
499cdf0e10cSrcweir         }
500cdf0e10cSrcweir         return String();
501cdf0e10cSrcweir     }
502cdf0e10cSrcweir     //------------------------------------------------------------------
IsTabAllowed(sal_Bool) const503cdf0e10cSrcweir     sal_Bool IndexFieldsControl::IsTabAllowed(sal_Bool /*bForward*/) const
504cdf0e10cSrcweir     {
505cdf0e10cSrcweir         return sal_False;
506cdf0e10cSrcweir     }
507cdf0e10cSrcweir     //------------------------------------------------------------------
508cdf0e10cSrcweir 
509cdf0e10cSrcweir //......................................................................
510cdf0e10cSrcweir }   // namespace dbaui
511cdf0e10cSrcweir //......................................................................
512