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