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