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_svtools.hxx" 30*cdf0e10cSrcweir #include <svtools/editbrowsebox.hxx> 31*cdf0e10cSrcweir #include <vcl/decoview.hxx> 32*cdf0e10cSrcweir #include <svtools/fmtfield.hxx> 33*cdf0e10cSrcweir #include <svtools/xtextedt.hxx> 34*cdf0e10cSrcweir 35*cdf0e10cSrcweir #include <algorithm> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir // ....................................................................... 38*cdf0e10cSrcweir namespace svt 39*cdf0e10cSrcweir { 40*cdf0e10cSrcweir // ....................................................................... 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir TYPEINIT0(CellController); 43*cdf0e10cSrcweir TYPEINIT1(EditCellController, CellController); 44*cdf0e10cSrcweir TYPEINIT1(SpinCellController, CellController); 45*cdf0e10cSrcweir TYPEINIT1(CheckBoxCellController, CellController); 46*cdf0e10cSrcweir TYPEINIT1(ComboBoxCellController, CellController); 47*cdf0e10cSrcweir TYPEINIT1(ListBoxCellController, CellController); 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir TYPEINIT1( FormattedFieldCellController, EditCellController ); 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir //================================================================== 52*cdf0e10cSrcweir //= ComboBoxControl 53*cdf0e10cSrcweir //================================================================== 54*cdf0e10cSrcweir ComboBoxControl::ComboBoxControl(Window* pParent, WinBits nWinStyle) 55*cdf0e10cSrcweir :ComboBox(pParent, nWinStyle|WB_DROPDOWN|WB_NOBORDER) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir EnableAutoSize(sal_False); 58*cdf0e10cSrcweir EnableAutocomplete(sal_True); 59*cdf0e10cSrcweir SetDropDownLineCount(5); 60*cdf0e10cSrcweir } 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir //------------------------------------------------------------------ 63*cdf0e10cSrcweir long ComboBoxControl::PreNotify( NotifyEvent& rNEvt ) 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir switch (rNEvt.GetType()) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir case EVENT_KEYINPUT: 68*cdf0e10cSrcweir if (!IsInDropDown()) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir const KeyEvent *pEvt = rNEvt.GetKeyEvent(); 71*cdf0e10cSrcweir const KeyCode rKey = pEvt->GetKeyCode(); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir if ((rKey.GetCode() == KEY_UP || rKey.GetCode() == KEY_DOWN) && 74*cdf0e10cSrcweir (!pEvt->GetKeyCode().IsShift() && pEvt->GetKeyCode().IsMod1())) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir // select next resp. previous entry 77*cdf0e10cSrcweir int nPos = GetEntryPos(GetText()); 78*cdf0e10cSrcweir nPos = nPos + (rKey.GetCode() == KEY_DOWN ? 1 : -1); 79*cdf0e10cSrcweir if (nPos < 0) 80*cdf0e10cSrcweir nPos = 0; 81*cdf0e10cSrcweir if (nPos >= GetEntryCount()) 82*cdf0e10cSrcweir nPos = GetEntryCount() - 1; 83*cdf0e10cSrcweir SetText(GetEntry(sal::static_int_cast< sal_uInt16 >(nPos))); 84*cdf0e10cSrcweir return 1; 85*cdf0e10cSrcweir } 86*cdf0e10cSrcweir } 87*cdf0e10cSrcweir break; 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir return ComboBox::PreNotify(rNEvt); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir //================================================================== 93*cdf0e10cSrcweir //= ComboBoxCellController 94*cdf0e10cSrcweir //================================================================== 95*cdf0e10cSrcweir //------------------------------------------------------------------ 96*cdf0e10cSrcweir ComboBoxCellController::ComboBoxCellController(ComboBoxControl* pWin) 97*cdf0e10cSrcweir :CellController(pWin) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir //------------------------------------------------------------------ 102*cdf0e10cSrcweir sal_Bool ComboBoxCellController::MoveAllowed(const KeyEvent& rEvt) const 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir ComboBoxControl& rBox = GetComboBox(); 105*cdf0e10cSrcweir switch (rEvt.GetKeyCode().GetCode()) 106*cdf0e10cSrcweir { 107*cdf0e10cSrcweir case KEY_END: 108*cdf0e10cSrcweir case KEY_RIGHT: 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir Selection aSel = rBox.GetSelection(); 111*cdf0e10cSrcweir return !aSel && aSel.Max() == rBox.GetText().Len(); 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir case KEY_HOME: 114*cdf0e10cSrcweir case KEY_LEFT: 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir Selection aSel = rBox.GetSelection(); 117*cdf0e10cSrcweir return !aSel && aSel.Min() == 0; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir case KEY_UP: 120*cdf0e10cSrcweir case KEY_DOWN: 121*cdf0e10cSrcweir if (rBox.IsInDropDown()) 122*cdf0e10cSrcweir return sal_False; 123*cdf0e10cSrcweir if (!rEvt.GetKeyCode().IsShift() && 124*cdf0e10cSrcweir rEvt.GetKeyCode().IsMod1()) 125*cdf0e10cSrcweir return sal_False; 126*cdf0e10cSrcweir // drop down the list box 127*cdf0e10cSrcweir else if (rEvt.GetKeyCode().IsMod2() && rEvt.GetKeyCode().GetCode() == KEY_DOWN) 128*cdf0e10cSrcweir return sal_False; 129*cdf0e10cSrcweir case KEY_PAGEUP: 130*cdf0e10cSrcweir case KEY_PAGEDOWN: 131*cdf0e10cSrcweir case KEY_RETURN: 132*cdf0e10cSrcweir if (rBox.IsInDropDown()) 133*cdf0e10cSrcweir return sal_False; 134*cdf0e10cSrcweir default: 135*cdf0e10cSrcweir return sal_True; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir //------------------------------------------------------------------ 140*cdf0e10cSrcweir sal_Bool ComboBoxCellController::IsModified() const 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir return GetComboBox().GetSavedValue() != GetComboBox().GetText(); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir //------------------------------------------------------------------ 146*cdf0e10cSrcweir void ComboBoxCellController::ClearModified() 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir GetComboBox().SaveValue(); 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir //------------------------------------------------------------------ 152*cdf0e10cSrcweir void ComboBoxCellController::SetModifyHdl(const Link& rLink) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir GetComboBox().SetModifyHdl(rLink); 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir //================================================================== 158*cdf0e10cSrcweir //= ListBoxControl 159*cdf0e10cSrcweir //================================================================== 160*cdf0e10cSrcweir //------------------------------------------------------------------ 161*cdf0e10cSrcweir ListBoxControl::ListBoxControl(Window* pParent, WinBits nWinStyle) 162*cdf0e10cSrcweir :ListBox(pParent, nWinStyle|WB_DROPDOWN|WB_NOBORDER) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir EnableAutoSize(sal_False); 165*cdf0e10cSrcweir EnableMultiSelection(sal_False); 166*cdf0e10cSrcweir SetDropDownLineCount(20); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir //------------------------------------------------------------------ 170*cdf0e10cSrcweir long ListBoxControl::PreNotify( NotifyEvent& rNEvt ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir switch (rNEvt.GetType()) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir case EVENT_KEYINPUT: 175*cdf0e10cSrcweir if (!IsInDropDown()) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir const KeyEvent *pEvt = rNEvt.GetKeyEvent(); 178*cdf0e10cSrcweir const KeyCode rKey = pEvt->GetKeyCode(); 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir if ((rKey.GetCode() == KEY_UP || rKey.GetCode() == KEY_DOWN) && 181*cdf0e10cSrcweir (!pEvt->GetKeyCode().IsShift() && pEvt->GetKeyCode().IsMod1())) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir // select next resp. previous entry 184*cdf0e10cSrcweir int nPos = GetSelectEntryPos(); 185*cdf0e10cSrcweir nPos = nPos + (rKey.GetCode() == KEY_DOWN ? 1 : -1); 186*cdf0e10cSrcweir if (nPos < 0) 187*cdf0e10cSrcweir nPos = 0; 188*cdf0e10cSrcweir if (nPos >= GetEntryCount()) 189*cdf0e10cSrcweir nPos = GetEntryCount() - 1; 190*cdf0e10cSrcweir SelectEntryPos(sal::static_int_cast< sal_uInt16 >(nPos)); 191*cdf0e10cSrcweir Select(); // for calling Modify 192*cdf0e10cSrcweir return 1; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir else if (GetParent()->PreNotify(rNEvt)) 195*cdf0e10cSrcweir return 1; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir break; 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir return ListBox::PreNotify(rNEvt); 200*cdf0e10cSrcweir } 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir //================================================================== 203*cdf0e10cSrcweir //= ListBoxCellController 204*cdf0e10cSrcweir //================================================================== 205*cdf0e10cSrcweir //------------------------------------------------------------------ 206*cdf0e10cSrcweir ListBoxCellController::ListBoxCellController(ListBoxControl* pWin) 207*cdf0e10cSrcweir :CellController(pWin) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir //------------------------------------------------------------------ 212*cdf0e10cSrcweir sal_Bool ListBoxCellController::MoveAllowed(const KeyEvent& rEvt) const 213*cdf0e10cSrcweir { 214*cdf0e10cSrcweir ListBoxControl& rBox = GetListBox(); 215*cdf0e10cSrcweir switch (rEvt.GetKeyCode().GetCode()) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir case KEY_UP: 218*cdf0e10cSrcweir case KEY_DOWN: 219*cdf0e10cSrcweir if (!rEvt.GetKeyCode().IsShift() && 220*cdf0e10cSrcweir rEvt.GetKeyCode().IsMod1()) 221*cdf0e10cSrcweir return sal_False; 222*cdf0e10cSrcweir // drop down the list box 223*cdf0e10cSrcweir else 224*cdf0e10cSrcweir if (rEvt.GetKeyCode().IsMod2() && rEvt.GetKeyCode().GetCode() == KEY_DOWN) 225*cdf0e10cSrcweir return sal_False; 226*cdf0e10cSrcweir case KEY_PAGEUP: 227*cdf0e10cSrcweir case KEY_PAGEDOWN: 228*cdf0e10cSrcweir if (rBox.IsTravelSelect()) 229*cdf0e10cSrcweir return sal_False; 230*cdf0e10cSrcweir default: 231*cdf0e10cSrcweir return sal_True; 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir //------------------------------------------------------------------ 236*cdf0e10cSrcweir sal_Bool ListBoxCellController::IsModified() const 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir return GetListBox().GetSelectEntryPos() != GetListBox().GetSavedValue(); 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir //------------------------------------------------------------------ 242*cdf0e10cSrcweir void ListBoxCellController::ClearModified() 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir GetListBox().SaveValue(); 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir //------------------------------------------------------------------ 248*cdf0e10cSrcweir void ListBoxCellController::SetModifyHdl(const Link& rLink) 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir GetListBox().SetSelectHdl(rLink); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir //================================================================== 254*cdf0e10cSrcweir //= CheckBoxControl 255*cdf0e10cSrcweir //================================================================== 256*cdf0e10cSrcweir //------------------------------------------------------------------ 257*cdf0e10cSrcweir CheckBoxControl::CheckBoxControl(Window* pParent, WinBits nWinStyle) 258*cdf0e10cSrcweir :Control(pParent, nWinStyle) 259*cdf0e10cSrcweir { 260*cdf0e10cSrcweir const Wallpaper& rParentBackground = pParent->GetBackground(); 261*cdf0e10cSrcweir if ( (pParent->GetStyle() & WB_CLIPCHILDREN) || rParentBackground.IsFixed() ) 262*cdf0e10cSrcweir SetBackground( rParentBackground ); 263*cdf0e10cSrcweir else 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir SetPaintTransparent( sal_True ); 266*cdf0e10cSrcweir SetBackground(); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir EnableChildTransparentMode(); 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir pBox = new TriStateBox(this,WB_CENTER|WB_VCENTER); 272*cdf0e10cSrcweir pBox->EnableChildTransparentMode(); 273*cdf0e10cSrcweir pBox->SetPaintTransparent( sal_True ); 274*cdf0e10cSrcweir pBox->SetClickHdl( LINK( this, CheckBoxControl, OnClick ) ); 275*cdf0e10cSrcweir pBox->Show(); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir //------------------------------------------------------------------ 279*cdf0e10cSrcweir CheckBoxControl::~CheckBoxControl() 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir delete pBox; 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir //------------------------------------------------------------------ 285*cdf0e10cSrcweir IMPL_LINK( CheckBoxControl, OnClick, void*, EMPTYARG ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir m_aClickLink.Call(pBox); 288*cdf0e10cSrcweir return m_aModifyLink.Call(pBox); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir //------------------------------------------------------------------ 292*cdf0e10cSrcweir void CheckBoxControl::Resize() 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir Control::Resize(); 295*cdf0e10cSrcweir pBox->SetPosSizePixel(Point(0,0),GetSizePixel()); 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir //------------------------------------------------------------------------------ 299*cdf0e10cSrcweir void CheckBoxControl::DataChanged( const DataChangedEvent& _rEvent ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir if ( _rEvent.GetType() == DATACHANGED_SETTINGS ) 302*cdf0e10cSrcweir pBox->SetSettings( GetSettings() ); 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir //------------------------------------------------------------------------------ 306*cdf0e10cSrcweir void CheckBoxControl::StateChanged( StateChangedType nStateChange ) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir Control::StateChanged(nStateChange); 309*cdf0e10cSrcweir if ( nStateChange == STATE_CHANGE_ZOOM ) 310*cdf0e10cSrcweir pBox->SetZoom(GetZoom()); 311*cdf0e10cSrcweir } 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir //------------------------------------------------------------------ 314*cdf0e10cSrcweir void CheckBoxControl::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong nFlags ) 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir pBox->Draw(pDev,rPos,rSize,nFlags); 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir //------------------------------------------------------------------ 320*cdf0e10cSrcweir void CheckBoxControl::GetFocus() 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir pBox->GrabFocus(); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir //------------------------------------------------------------------ 326*cdf0e10cSrcweir void CheckBoxControl::Paint(const Rectangle& rClientRect) 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir Control::Paint(rClientRect); 329*cdf0e10cSrcweir if (HasFocus()) 330*cdf0e10cSrcweir ShowFocus(aFocusRect); 331*cdf0e10cSrcweir } 332*cdf0e10cSrcweir 333*cdf0e10cSrcweir //------------------------------------------------------------------ 334*cdf0e10cSrcweir long CheckBoxControl::PreNotify(NotifyEvent& rEvt) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir switch (rEvt.GetType()) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir case EVENT_GETFOCUS: 339*cdf0e10cSrcweir ShowFocus(aFocusRect); 340*cdf0e10cSrcweir break; 341*cdf0e10cSrcweir case EVENT_LOSEFOCUS: 342*cdf0e10cSrcweir HideFocus(); 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir return Control::PreNotify(rEvt); 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir //================================================================== 348*cdf0e10cSrcweir //= CheckBoxCellController 349*cdf0e10cSrcweir //================================================================== 350*cdf0e10cSrcweir //------------------------------------------------------------------ 351*cdf0e10cSrcweir sal_Bool CheckBoxCellController::WantMouseEvent() const 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir return sal_True; 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir //------------------------------------------------------------------ 357*cdf0e10cSrcweir CheckBox& CheckBoxCellController::GetCheckBox() const 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir return ((CheckBoxControl &)GetWindow()).GetBox(); 360*cdf0e10cSrcweir } 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir //------------------------------------------------------------------ 363*cdf0e10cSrcweir sal_Bool CheckBoxCellController::IsModified() const 364*cdf0e10cSrcweir { 365*cdf0e10cSrcweir return GetCheckBox().GetSavedValue() != GetCheckBox().GetState(); 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir //------------------------------------------------------------------ 369*cdf0e10cSrcweir void CheckBoxCellController::ClearModified() 370*cdf0e10cSrcweir { 371*cdf0e10cSrcweir GetCheckBox().SaveValue(); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir //------------------------------------------------------------------ 375*cdf0e10cSrcweir void CheckBoxCellController::SetModifyHdl(const Link& rLink) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir ((CheckBoxControl &)GetWindow()).SetModifyHdl(rLink); 378*cdf0e10cSrcweir } 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir //================================================================== 381*cdf0e10cSrcweir //= MultiLineEditImplementation 382*cdf0e10cSrcweir //================================================================== 383*cdf0e10cSrcweir //------------------------------------------------------------------ 384*cdf0e10cSrcweir String MultiLineEditImplementation::GetText( LineEnd aSeparator ) const 385*cdf0e10cSrcweir { 386*cdf0e10cSrcweir return const_cast< MultiLineEditImplementation* >( this )->GetEditWindow().GetText( aSeparator ); 387*cdf0e10cSrcweir } 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir //------------------------------------------------------------------ 390*cdf0e10cSrcweir String MultiLineEditImplementation::GetSelected( LineEnd aSeparator ) const 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir return const_cast< MultiLineEditImplementation* >( this )->GetEditWindow().GetSelected( aSeparator ); 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir 395*cdf0e10cSrcweir //================================================================== 396*cdf0e10cSrcweir //= EditCellController 397*cdf0e10cSrcweir //================================================================== 398*cdf0e10cSrcweir //------------------------------------------------------------------ 399*cdf0e10cSrcweir EditCellController::EditCellController( Edit* _pEdit ) 400*cdf0e10cSrcweir :CellController( _pEdit ) 401*cdf0e10cSrcweir ,m_pEditImplementation( new EditImplementation( *_pEdit ) ) 402*cdf0e10cSrcweir ,m_bOwnImplementation( sal_True ) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir //------------------------------------------------------------------ 407*cdf0e10cSrcweir EditCellController::EditCellController( MultiLineTextCell* _pEdit ) 408*cdf0e10cSrcweir :CellController( _pEdit ) 409*cdf0e10cSrcweir ,m_pEditImplementation( new MultiLineEditImplementation( *_pEdit ) ) 410*cdf0e10cSrcweir ,m_bOwnImplementation( sal_True ) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir } 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir //------------------------------------------------------------------ 415*cdf0e10cSrcweir EditCellController::EditCellController( IEditImplementation* _pImplementation ) 416*cdf0e10cSrcweir :CellController( &_pImplementation->GetControl() ) 417*cdf0e10cSrcweir ,m_pEditImplementation( _pImplementation ) 418*cdf0e10cSrcweir ,m_bOwnImplementation( sal_False ) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir //----------------------------------------------------------------------------- 423*cdf0e10cSrcweir EditCellController::~EditCellController( ) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir if ( m_bOwnImplementation ) 426*cdf0e10cSrcweir DELETEZ( m_pEditImplementation ); 427*cdf0e10cSrcweir } 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir //----------------------------------------------------------------------------- 430*cdf0e10cSrcweir void EditCellController::SetModified() 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir m_pEditImplementation->SetModified(); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir //----------------------------------------------------------------------------- 436*cdf0e10cSrcweir void EditCellController::ClearModified() 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir m_pEditImplementation->ClearModified(); 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir //------------------------------------------------------------------ 442*cdf0e10cSrcweir sal_Bool EditCellController::MoveAllowed(const KeyEvent& rEvt) const 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir sal_Bool bResult; 445*cdf0e10cSrcweir switch (rEvt.GetKeyCode().GetCode()) 446*cdf0e10cSrcweir { 447*cdf0e10cSrcweir case KEY_END: 448*cdf0e10cSrcweir case KEY_RIGHT: 449*cdf0e10cSrcweir { 450*cdf0e10cSrcweir Selection aSel = m_pEditImplementation->GetSelection(); 451*cdf0e10cSrcweir bResult = !aSel && aSel.Max() == m_pEditImplementation->GetText( LINEEND_LF ).Len(); 452*cdf0e10cSrcweir } break; 453*cdf0e10cSrcweir case KEY_HOME: 454*cdf0e10cSrcweir case KEY_LEFT: 455*cdf0e10cSrcweir { 456*cdf0e10cSrcweir Selection aSel = m_pEditImplementation->GetSelection(); 457*cdf0e10cSrcweir bResult = !aSel && aSel.Min() == 0; 458*cdf0e10cSrcweir } break; 459*cdf0e10cSrcweir default: 460*cdf0e10cSrcweir bResult = sal_True; 461*cdf0e10cSrcweir } 462*cdf0e10cSrcweir return bResult; 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir //------------------------------------------------------------------ 466*cdf0e10cSrcweir sal_Bool EditCellController::IsModified() const 467*cdf0e10cSrcweir { 468*cdf0e10cSrcweir return m_pEditImplementation->IsModified(); 469*cdf0e10cSrcweir } 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir //------------------------------------------------------------------ 472*cdf0e10cSrcweir void EditCellController::SetModifyHdl(const Link& rLink) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir m_pEditImplementation->SetModifyHdl(rLink); 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir //================================================================== 478*cdf0e10cSrcweir //= SpinCellController 479*cdf0e10cSrcweir //================================================================== 480*cdf0e10cSrcweir //------------------------------------------------------------------ 481*cdf0e10cSrcweir SpinCellController::SpinCellController(SpinField* pWin) 482*cdf0e10cSrcweir :CellController(pWin) 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir } 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir //----------------------------------------------------------------------------- 487*cdf0e10cSrcweir void SpinCellController::SetModified() 488*cdf0e10cSrcweir { 489*cdf0e10cSrcweir GetSpinWindow().SetModifyFlag(); 490*cdf0e10cSrcweir } 491*cdf0e10cSrcweir 492*cdf0e10cSrcweir //----------------------------------------------------------------------------- 493*cdf0e10cSrcweir void SpinCellController::ClearModified() 494*cdf0e10cSrcweir { 495*cdf0e10cSrcweir GetSpinWindow().ClearModifyFlag(); 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir //------------------------------------------------------------------ 499*cdf0e10cSrcweir sal_Bool SpinCellController::MoveAllowed(const KeyEvent& rEvt) const 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir sal_Bool bResult; 502*cdf0e10cSrcweir switch (rEvt.GetKeyCode().GetCode()) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir case KEY_END: 505*cdf0e10cSrcweir case KEY_RIGHT: 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir Selection aSel = GetSpinWindow().GetSelection(); 508*cdf0e10cSrcweir bResult = !aSel && aSel.Max() == GetSpinWindow().GetText().Len(); 509*cdf0e10cSrcweir } break; 510*cdf0e10cSrcweir case KEY_HOME: 511*cdf0e10cSrcweir case KEY_LEFT: 512*cdf0e10cSrcweir { 513*cdf0e10cSrcweir Selection aSel = GetSpinWindow().GetSelection(); 514*cdf0e10cSrcweir bResult = !aSel && aSel.Min() == 0; 515*cdf0e10cSrcweir } break; 516*cdf0e10cSrcweir default: 517*cdf0e10cSrcweir bResult = sal_True; 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir return bResult; 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir //------------------------------------------------------------------ 523*cdf0e10cSrcweir sal_Bool SpinCellController::IsModified() const 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir return GetSpinWindow().IsModified(); 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir //------------------------------------------------------------------ 529*cdf0e10cSrcweir void SpinCellController::SetModifyHdl(const Link& rLink) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir GetSpinWindow().SetModifyHdl(rLink); 532*cdf0e10cSrcweir } 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir //================================================================== 535*cdf0e10cSrcweir //= FormattedFieldCellController 536*cdf0e10cSrcweir //================================================================== 537*cdf0e10cSrcweir //------------------------------------------------------------------ 538*cdf0e10cSrcweir FormattedFieldCellController::FormattedFieldCellController( FormattedField* _pFormatted ) 539*cdf0e10cSrcweir :EditCellController( _pFormatted ) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir } 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir //------------------------------------------------------------------ 544*cdf0e10cSrcweir void FormattedFieldCellController::CommitModifications() 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir static_cast< FormattedField& >( GetWindow() ).Commit(); 547*cdf0e10cSrcweir } 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir //================================================================== 550*cdf0e10cSrcweir //= MultiLineTextCell 551*cdf0e10cSrcweir //================================================================== 552*cdf0e10cSrcweir //------------------------------------------------------------------ 553*cdf0e10cSrcweir void MultiLineTextCell::Modify() 554*cdf0e10cSrcweir { 555*cdf0e10cSrcweir GetTextEngine()->SetModified( sal_True ); 556*cdf0e10cSrcweir MultiLineEdit::Modify(); 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir //------------------------------------------------------------------ 560*cdf0e10cSrcweir sal_Bool MultiLineTextCell::dispatchKeyEvent( const KeyEvent& _rEvent ) 561*cdf0e10cSrcweir { 562*cdf0e10cSrcweir Selection aOldSelection( GetSelection() ); 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir sal_Bool bWasModified = IsModified(); 565*cdf0e10cSrcweir ClearModifyFlag( ); 566*cdf0e10cSrcweir 567*cdf0e10cSrcweir sal_Bool bHandled = GetTextView()->KeyInput( _rEvent ); 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir sal_Bool bIsModified = IsModified(); 570*cdf0e10cSrcweir if ( bWasModified && !bIsModified ) 571*cdf0e10cSrcweir // not sure whether this can really happen 572*cdf0e10cSrcweir SetModifyFlag(); 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir if ( bHandled ) // the view claimed it handled the key input 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir // unfortunately, KeyInput also returns <TRUE/> (means "I handled this key input") 577*cdf0e10cSrcweir // when nothing really changed. Let's care for this. 578*cdf0e10cSrcweir Selection aNewSelection( GetSelection() ); 579*cdf0e10cSrcweir if ( aNewSelection != aOldSelection // selection changed 580*cdf0e10cSrcweir || bIsModified // or some other modification 581*cdf0e10cSrcweir ) 582*cdf0e10cSrcweir return sal_True; 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir return sal_False; 585*cdf0e10cSrcweir } 586*cdf0e10cSrcweir 587*cdf0e10cSrcweir //------------------------------------------------------------------ 588*cdf0e10cSrcweir long MultiLineTextCell::PreNotify( NotifyEvent& rNEvt ) 589*cdf0e10cSrcweir { 590*cdf0e10cSrcweir if ( rNEvt.GetType() == EVENT_KEYINPUT ) 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir if ( IsWindowOrChild( rNEvt.GetWindow() ) ) 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir // give the text view a chance to handle the keys 595*cdf0e10cSrcweir // this is necessary since a lot of keys which are normally handled 596*cdf0e10cSrcweir // by this view (in KeyInput) are intercepted by the EditBrowseBox, 597*cdf0e10cSrcweir // which uses them for other reasons. An example is the KeyUp key, 598*cdf0e10cSrcweir // which is used by both the text view and the edit browse box 599*cdf0e10cSrcweir 600*cdf0e10cSrcweir const KeyEvent* pKeyEvent = rNEvt.GetKeyEvent(); 601*cdf0e10cSrcweir const KeyCode& rKeyCode = pKeyEvent->GetKeyCode(); 602*cdf0e10cSrcweir sal_uInt16 nCode = rKeyCode.GetCode(); 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir if ( ( nCode == KEY_RETURN ) && ( rKeyCode.GetModifier() == KEY_MOD1 ) ) 605*cdf0e10cSrcweir { 606*cdf0e10cSrcweir KeyEvent aEvent( pKeyEvent->GetCharCode(), 607*cdf0e10cSrcweir KeyCode( KEY_RETURN ), 608*cdf0e10cSrcweir pKeyEvent->GetRepeat() 609*cdf0e10cSrcweir ); 610*cdf0e10cSrcweir if ( dispatchKeyEvent( aEvent ) ) 611*cdf0e10cSrcweir return 1; 612*cdf0e10cSrcweir } 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir if ( ( nCode != KEY_TAB ) && ( nCode != KEY_RETURN ) ) // everything but tab and enter 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir if ( dispatchKeyEvent( *pKeyEvent ) ) 617*cdf0e10cSrcweir return 1; 618*cdf0e10cSrcweir } 619*cdf0e10cSrcweir } 620*cdf0e10cSrcweir } 621*cdf0e10cSrcweir return MultiLineEdit::PreNotify( rNEvt ); 622*cdf0e10cSrcweir } 623*cdf0e10cSrcweir 624*cdf0e10cSrcweir // ....................................................................... 625*cdf0e10cSrcweir } // namespace svt 626*cdf0e10cSrcweir // ....................................................................... 627*cdf0e10cSrcweir 628*cdf0e10cSrcweir 629