1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbui.hxx"
26 
27 #define ITEMID_HORJUSTIFY		SID_ATTR_ALIGN_HOR_JUSTIFY
28 #define ITEMID_VERJUSTIFY		SID_ATTR_ALIGN_VER_JUSTIFY
29 //#define ITEMID_ORIENTATION     SID_ATTR_ALIGN_ORIENTATION
30 #define ITEMID_LINEBREAK		SID_ATTR_ALIGN_LINEBREAK
31 #define ITEMID_MARGIN			SID_ATTR_ALIGN_MARGIN
32 
33 #include "FieldDescControl.hxx"
34 #include "FieldControls.hxx"
35 #include <tools/debug.hxx>
36 #include <tools/diagnose_ex.h>
37 #include "TableDesignHelpBar.hxx"
38 #include <vcl/scrbar.hxx>
39 #include <vcl/button.hxx>
40 #include <vcl/svapp.hxx>
41 #include <vcl/fixed.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <vector>
44 #include "FieldDescriptions.hxx"
45 #include "dlgattr.hxx"
46 #include <svx/numfmtsh.hxx>
47 #include <svx/svxids.hrc>
48 #include <svx/algitem.hxx>
49 #include <svl/itempool.hxx>
50 #define _ZFORLIST_DECLARE_TABLE		// ohne das bekomme ich einen Compiler-Fehler in <svl/zforlist.hxx>
51 #include <svl/zforlist.hxx>
52 #include <svl/rngitem.hxx>
53 #include <svl/intitem.hxx>
54 #include <svl/numuno.hxx>
55 #include <svtools/transfer.hxx>
56 #include <com/sun/star/lang/XUnoTunnel.hpp>
57 #include <com/sun/star/util/NumberFormat.hpp>
58 #include <com/sun/star/util/XNumberFormatPreviewer.hpp>
59 #include <com/sun/star/util/XNumberFormatTypes.hpp>
60 #include <com/sun/star/beans/XPropertySet.hpp>
61 #include "QEnumTypes.hxx"
62 #include "dbaccess_helpid.hrc"
63 #include <connectivity/dbtools.hxx>
64 #include <connectivity/dbconversion.hxx>
65 #include <comphelper/numbers.hxx>
66 #include "UITools.hxx"
67 #include <memory>
68 #include "dbu_control.hrc"
69 #include "dbu_tbl.hrc"
70 
71 
72 using namespace dbaui;
73 using namespace dbtools;
74 using namespace ::com::sun::star::uno;
75 using namespace ::com::sun::star::beans;
76 using namespace ::com::sun::star::lang;
77 using namespace ::com::sun::star::sdbc;
78 using namespace ::com::sun::star::util;
79 
80 //==================================================================
81 
82 // fuer die Controls auf der OFieldDescGenPage
83 #define CONTROL_SPACING_X	18	// 6
84 #define	CONTROL_SPACING_Y	4
85 #define CONTROL_WIDTH_1		160	// 100
86 #define CONTROL_WIDTH_2		100 // 60
87 #define CONTROL_WIDTH_3		250
88 #define CONTROL_WIDTH_4		(CONTROL_WIDTH_3 - 20 - 5)
89 
90 #define SBA_DEF_RANGEFORMAT			(100 + 143) // RangeItem
91 #define SBA_DEF_FMTVALUE			(100 + 144) // SfxULONG, Format
92 #define SBA_ATTR_ALIGN_HOR_JUSTIFY	(100 + 145) //  SvxHorJustifyItem
93 
94 #define HSCROLL_STEP		20
95 
96 
97 namespace
98 {
99 	// -----------------------------------------------------------------------------
checkDoubleForDateFormat(double _nValue,sal_Int32 _nFormatKey,const Reference<::com::sun::star::util::XNumberFormatter> & _xNumberFormatter)100 	double checkDoubleForDateFormat(double _nValue,sal_Int32 _nFormatKey,const Reference< ::com::sun::star::util::XNumberFormatter>& _xNumberFormatter)
101 	{
102 		double nValue = _nValue;
103 		sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(_xNumberFormatter,_nFormatKey);
104 		if(		(nNumberFormat & ::com::sun::star::util::NumberFormat::DATE)	== ::com::sun::star::util::NumberFormat::DATE
105 			|| (nNumberFormat & ::com::sun::star::util::NumberFormat::DATETIME) == ::com::sun::star::util::NumberFormat::DATETIME )
106 		{
107 			nValue = DBTypeConversion::toStandardDbDate(DBTypeConversion::getNULLDate(_xNumberFormatter->getNumberFormatsSupplier()),nValue);
108 		}
109 
110 		return nValue;
111 	}
112 	// -----------------------------------------------------------------------------
lcl_HideAndDeleteControl(short & _nPos,T1 ** _pControl,T2 ** _pControlText)113     template< typename T1, typename T2> void lcl_HideAndDeleteControl(short& _nPos,T1** _pControl,T2** _pControlText)
114     {
115         if ( *_pControl )
116         {
117             --_nPos;
118 	        (*_pControl)->Hide();
119 	        (*_pControlText)->Hide();
120 	        delete *_pControl;
121 	        delete *_pControlText;
122             (*_pControl) = NULL;
123             (*_pControlText) = NULL;
124         }
125     }
126 
127 }
128 
129 //==================================================================
130 // class OFieldDescControl
131 //==================================================================
132 
DBG_NAME(OFieldDescControl)133 DBG_NAME(OFieldDescControl)
134 
135 //==================================================================
136 OFieldDescControl::OFieldDescControl( Window* pParent, const ResId& rResId, OTableDesignHelpBar* pHelpBar)
137 	:TabPage( pParent, rResId )
138 	,pHelp( pHelpBar )
139 	,pLastFocusWindow(NULL)
140 	,m_pActFocusWindow(NULL)
141 	,pDefaultText(NULL)
142 	,pRequiredText(NULL)
143 	,pAutoIncrementText(NULL)
144 	,pTextLenText(NULL)
145 	,pNumTypeText(NULL)
146 	,pLengthText(NULL)
147 	,pScaleText(NULL)
148 	,pFormatText(NULL)
149 	,pBoolDefaultText(NULL)
150 	,m_pColumnNameText(NULL)
151 	,m_pTypeText(NULL)
152 	,m_pAutoIncrementValueText(NULL)
153 	,pRequired(NULL)
154 	,pNumType(NULL)
155 	,pAutoIncrement(NULL)
156 	,pDefault(NULL)
157 	,pTextLen(NULL)
158 	,pLength(NULL)
159 	,pScale(NULL)
160 	,pFormatSample(NULL)
161 	,pBoolDefault(NULL)
162 	,m_pColumnName(NULL)
163 	,m_pType(NULL)
164 	,m_pAutoIncrementValue(NULL)
165 	,pFormat(NULL)
166     ,m_pVertScroll( NULL )
167     ,m_pHorzScroll( NULL )
168     ,m_pPreviousType()
169 	,nCurChildId(1)
170 	,m_nPos(-1)
171     ,aYes(ModuleRes(STR_VALUE_YES))
172 	,aNo(ModuleRes(STR_VALUE_NO))
173     ,m_nOldVThumb( 0 )
174     ,m_nOldHThumb( 0 )
175 	,m_nWidth(50)
176     ,nDelayedGrabFocusEvent(0)
177     ,m_bAdded(sal_False)
178 	,m_bRightAligned(false)
179     ,pActFieldDescr(NULL)
180 {
181 	DBG_CTOR(OFieldDescControl,NULL);
182 
183 	Contruct();
184 }
185 //------------------------------------------------------------------------------
OFieldDescControl(Window * pParent,OTableDesignHelpBar * pHelpBar)186 OFieldDescControl::OFieldDescControl( Window* pParent, OTableDesignHelpBar* pHelpBar )
187 	:TabPage( pParent, WB_3DLOOK | WB_DIALOGCONTROL )
188 	,pHelp( pHelpBar )
189 	,pLastFocusWindow(NULL)
190 	,m_pActFocusWindow(NULL)
191 	,pDefaultText(NULL)
192 	,pRequiredText(NULL)
193 	,pAutoIncrementText(NULL)
194 	,pTextLenText(NULL)
195 	,pNumTypeText(NULL)
196 	,pLengthText(NULL)
197 	,pScaleText(NULL)
198 	,pFormatText(NULL)
199 	,pBoolDefaultText(NULL)
200 	,m_pColumnNameText(NULL)
201 	,m_pTypeText(NULL)
202 	,m_pAutoIncrementValueText(NULL)
203 	,pRequired(NULL)
204 	,pNumType(NULL)
205 	,pAutoIncrement(NULL)
206 	,pDefault(NULL)
207 	,pTextLen(NULL)
208 	,pLength(NULL)
209 	,pScale(NULL)
210 	,pFormatSample(NULL)
211 	,pBoolDefault(NULL)
212 	,m_pColumnName(NULL)
213 	,m_pType(NULL)
214 	,m_pAutoIncrementValue(NULL)
215 	,pFormat(NULL)
216     ,m_pVertScroll( NULL )
217     ,m_pHorzScroll( NULL )
218     ,m_pPreviousType()
219 	,nCurChildId(1)
220 	,m_nPos(-1)
221     ,aYes(ModuleRes(STR_VALUE_YES))
222 	,aNo(ModuleRes(STR_VALUE_NO))
223     ,m_nOldVThumb( 0 )
224     ,m_nOldHThumb( 0 )
225 	,m_nWidth(50)
226     ,nDelayedGrabFocusEvent(0)
227     ,m_bAdded(sal_False)
228 	,m_bRightAligned(false)
229     ,pActFieldDescr(NULL)
230 {
231 	DBG_CTOR(OFieldDescControl,NULL);
232     Contruct();
233 }
234 // -----------------------------------------------------------------------------
Contruct()235 void OFieldDescControl::Contruct()
236 {
237     m_pVertScroll = new ScrollBar(this, WB_VSCROLL | WB_REPEAT | WB_DRAG);
238 	m_pHorzScroll = new ScrollBar(this, WB_HSCROLL | WB_REPEAT | WB_DRAG);
239 	m_pVertScroll->SetScrollHdl(LINK(this, OFieldDescControl, OnScroll));
240 	m_pHorzScroll->SetScrollHdl(LINK(this, OFieldDescControl, OnScroll));
241 	m_pVertScroll->Show();
242 	m_pHorzScroll->Show();
243 
244 	m_pVertScroll->EnableClipSiblings();
245 	m_pHorzScroll->EnableClipSiblings();
246 
247 	m_pVertScroll->SetLineSize(1);
248 	m_pVertScroll->SetPageSize(1);
249 	m_pHorzScroll->SetLineSize(1);
250 	m_pHorzScroll->SetPageSize(1);
251 
252 	m_nOldVThumb = m_nOldHThumb = 0;
253 }
254 
255 //------------------------------------------------------------------------------
~OFieldDescControl()256 OFieldDescControl::~OFieldDescControl()
257 {
258 	DBG_DTOR(OFieldDescControl,NULL);
259 
260 	{
261 		::std::auto_ptr<Window> aTemp(m_pVertScroll);
262 		m_pVertScroll	 = NULL;
263 	}
264 	{
265 		::std::auto_ptr<Window> aTemp(m_pHorzScroll);
266 		m_pHorzScroll	 = NULL;
267 	}
268     if ( m_bAdded )
269         ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
270 	pLastFocusWindow = NULL;
271 
272 	//////////////////////////////////////////////////////////////////////
273 	// Childs zerstoeren
274 	DeactivateAggregate( tpDefault );
275 	DeactivateAggregate( tpRequired );
276 	DeactivateAggregate( tpTextLen );
277 	DeactivateAggregate( tpNumType );
278 	DeactivateAggregate( tpScale );
279 	DeactivateAggregate( tpLength );
280 	DeactivateAggregate( tpFormat );
281 	DeactivateAggregate( tpAutoIncrement );
282 	DeactivateAggregate( tpBoolDefault );
283 	DeactivateAggregate( tpColumnName );
284 	DeactivateAggregate( tpType );
285 	DeactivateAggregate( tpAutoIncrementValue );
286 
287 	if(nDelayedGrabFocusEvent)
288 		Application::RemoveUserEvent(nDelayedGrabFocusEvent);
289 }
290 
291 //------------------------------------------------------------------------------
BoolStringPersistent(const String & rUIString) const292 String OFieldDescControl::BoolStringPersistent(const String& rUIString) const
293 {
294 	static String aZero('0');
295 	static String aOne('1');
296 
297 	if (rUIString == aNo)
298 		return aZero;
299 	if (rUIString == aYes)
300 		return aOne;
301 	return String();
302 }
303 
304 //------------------------------------------------------------------------------
BoolStringUI(const String & rPersistentString) const305 String OFieldDescControl::BoolStringUI(const String& rPersistentString) const
306 {
307 	static String aZero('0');
308 	static String aOne('1');
309 	static String aNone(ModuleRes(STR_VALUE_NONE));
310 
311 	// FS - 66161 - 14.05.1999 - aeltere Versionen haben eventuell einen sprachabhaengigen String als Default gespeichert
312 	if (rPersistentString.Equals(aYes) || rPersistentString.Equals(aNo))
313 		return rPersistentString;
314 
315 	if (rPersistentString == aZero)
316 		return aNo;
317 	if (rPersistentString == aOne)
318 		return aYes;
319 
320 	return aNone;
321 }
322 
323 //------------------------------------------------------------------------------
Init()324 void OFieldDescControl::Init()
325 {
326 	Reference< ::com::sun::star::util::XNumberFormatter > xFormatter = GetFormatter();
327 	::dbaui::setEvalDateFormatForFormatter(xFormatter);
328 }
329 
330 //------------------------------------------------------------------------------
331 IMPL_LINK(OFieldDescControl, OnScroll, ScrollBar*, /*pBar*/)
332 {
333 	ScrollAllAggregates();
334 	return 0;
335 }
336 // -----------------------------------------------------------------------------
337 namespace
338 {
getMaxXPosition(Window * _pWindow,long & _rnMaxXPosition)339 	void getMaxXPosition(Window* _pWindow,long& _rnMaxXPosition)
340 	{
341 		if (_pWindow)
342 		{
343 			long nTemp = _pWindow->GetSizePixel().Width() + _pWindow->GetPosPixel().X();
344 			_rnMaxXPosition = ::std::max(_rnMaxXPosition, nTemp);
345 		}
346 	}
347 }
348 //------------------------------------------------------------------------------
CheckScrollBars()349 void OFieldDescControl::CheckScrollBars()
350 {
351 	// ein paar Berechnungen zur neuen Position der ScrollBars
352 	Size szOverallSize = GetSizePixel();
353 	long nHScrollHeight = m_pHorzScroll->GetSizePixel().Height();
354 	long nVScrollWidth = m_pVertScroll->GetSizePixel().Width();
355 
356 	long nNewHWidth = szOverallSize.Width() - nVScrollWidth;
357 	long nNewVHeight = szOverallSize.Height() - nHScrollHeight;
358 
359 	sal_Bool bNeedHScrollBar(sal_False), bNeedVScrollBar(sal_False);
360 
361 	// die Bereiche anpassen
362 	// brauche ich ScrollBars eigentlich ?
363 	// horizontal :
364 	long lMaxXPosition = 0;
365 	Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
366 	for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
367 		getMaxXPosition(ppAggregates[i],lMaxXPosition);
368 
369 	if (m_pHorzScroll)
370 		lMaxXPosition += m_pHorzScroll->GetThumbPos() * HSCROLL_STEP;
371 
372 	long lMaxXAvailable = szOverallSize.Width();
373 	bNeedHScrollBar = lMaxXPosition > lMaxXAvailable;
374 		// aendert sich vielleicht noch
375 
376 	// vertikal
377 	// wieviel Controls habe ich
378 	sal_uInt16 nActive = CountActiveAggregates();
379 	// welches ist das letzte, was ganz drauf passt ?
380 	sal_uInt16 nLastVisible;
381     const sal_Int32 nControlHeight = GetMaxControlHeight();
382     const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
383 	if (bNeedHScrollBar)
384 		nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y - nHScrollHeight) / (nControl_Spacing_y + nControlHeight));
385 	else
386 		nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y) / (nControl_Spacing_y + nControlHeight));
387 	bNeedVScrollBar = nActive>nLastVisible;
388 
389 	if (bNeedVScrollBar)
390 	{
391 		// in die urspruengliche Berechnung von lMaxXAvailable ist nicht mit eingegangen, dass ich eine VScrollBar habe, also muss ich
392 		// das nachholen
393 		lMaxXAvailable -= nVScrollWidth;
394 		if (!bNeedHScrollBar && (lMaxXPosition > lMaxXAvailable))
395 		{
396 			// durch die vertikale brauche ich jetzt ploetzlich doch eine horizontale
397 			bNeedHScrollBar = sal_True;
398 			// nLastVisible anpassen
399 			nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y - nHScrollHeight) / (nControl_Spacing_y + nControlHeight));
400 				// bNeedVScrollBar aendert sich nicht : es ist schon auf sal_True und nLastVisible wird hoechstens kleiner
401 		}
402 	}
403 
404 	// jetzt kann ich sie wirklich positionieren und ihre Parameter setzen
405 	if (bNeedVScrollBar)
406 	{
407 		m_pVertScroll->Show();
408 		m_pVertScroll->SetRangeMax(nActive - nLastVisible);
409 //		m_pVertScroll->SetThumbPos(0);
410 
411 		m_pVertScroll->SetPosSizePixel( Point(nNewHWidth, 0), Size(nVScrollWidth, szOverallSize.Height()) );
412 	}
413 	else
414 	{
415 		m_pVertScroll->Hide();
416 		m_pVertScroll->SetRangeMax(0);
417 		m_pVertScroll->SetThumbPos(0);
418 	}
419 
420 	if (bNeedHScrollBar)
421 	{
422 		m_pHorzScroll->Show();
423 		m_pHorzScroll->SetRangeMax((lMaxXPosition - lMaxXAvailable + HSCROLL_STEP - 1 )/HSCROLL_STEP);
424 //		m_pHorzScroll->SetThumbPos(0);
425 
426 		m_pHorzScroll->SetPosSizePixel( Point(0, nNewVHeight), Size(bNeedVScrollBar ? nNewHWidth : szOverallSize.Width(), nHScrollHeight) );
427 	}
428 	else
429 	{
430 		m_pHorzScroll->Hide();
431 		m_pHorzScroll->SetRangeMax(0);
432 		m_pHorzScroll->SetThumbPos(0);
433 	}
434 }
435 
436 //------------------------------------------------------------------------------
Resize()437 void OFieldDescControl::Resize()
438 {
439 	CheckScrollBars();
440 	ScrollAllAggregates();
441 }
442 
443 //------------------------------------------------------------------------------
ScrollAggregate(Control * pText,Control * pInput,Control * pButton,long nDeltaX,long nDeltaY)444 inline void OFieldDescControl::ScrollAggregate(Control* pText, Control* pInput, Control* pButton, long nDeltaX, long nDeltaY)
445 {
446 	if  (!pText)
447 		return;
448 	pText->SetPosPixel(pText->GetPosPixel() + Point(nDeltaX, nDeltaY));
449 	pInput->SetPosPixel(pInput->GetPosPixel() + Point(nDeltaX, nDeltaY));
450 	if (pButton)
451 		pButton->SetPosPixel(pButton->GetPosPixel() + Point(nDeltaX, nDeltaY));
452 }
453 
454 //------------------------------------------------------------------------------
ScrollAllAggregates()455 void OFieldDescControl::ScrollAllAggregates()
456 {
457 	long nDeltaX = 0, nDeltaY = 0;
458 	if (m_nOldHThumb != m_pHorzScroll->GetThumbPos())
459 	{
460 		nDeltaX = (m_nOldHThumb - m_pHorzScroll->GetThumbPos()) * HSCROLL_STEP;
461 		m_nOldHThumb = m_pHorzScroll->GetThumbPos();
462 	}
463 
464 	if (m_nOldVThumb != m_pVertScroll->GetThumbPos())
465 	{
466         const sal_Int32 nControlHeight = GetMaxControlHeight();
467         const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
468 		nDeltaY = (m_nOldVThumb - m_pVertScroll->GetThumbPos()) * (nControl_Spacing_y + nControlHeight);
469 		m_nOldVThumb = m_pVertScroll->GetThumbPos();
470 	}
471 
472 	if (nDeltaX || nDeltaY)
473 	{
474 		Control* ppAggregates[]		= {	  pRequired, pNumType
475 										, pAutoIncrement, pDefault
476 										, pTextLen, pLength
477 										, pScale, m_pColumnName
478 										, m_pType, m_pAutoIncrementValue};
479 		Control* ppAggregatesText[]	= {	  pRequiredText, pNumTypeText
480 										, pAutoIncrementText, pDefaultText
481 										, pTextLenText, pLengthText
482 										, pScaleText, m_pColumnNameText
483 										, m_pTypeText, m_pAutoIncrementValueText};
484 		OSL_ENSURE(sizeof(ppAggregates)/sizeof(ppAggregates[0]) == sizeof(ppAggregatesText)/sizeof(ppAggregatesText[0]),"Lists are not identical!");
485 
486 		for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
487 			ScrollAggregate(ppAggregatesText[i],ppAggregates[i],NULL,nDeltaX, nDeltaY);
488 
489 		ScrollAggregate(pFormatText,pFormatSample,pFormat,nDeltaX, nDeltaY);
490 	}
491 }
492 
493 //------------------------------------------------------------------------------
CountActiveAggregates() const494 sal_uInt16 OFieldDescControl::CountActiveAggregates() const
495 {
496 	Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
497 	sal_uInt16 nVisibleAggregates = 0;
498 	for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
499 		if (ppAggregates[i])
500 			++nVisibleAggregates;
501 	return nVisibleAggregates;
502 }
503 //------------------------------------------------------------------------------
GetMaxControlHeight() const504 sal_Int32 OFieldDescControl::GetMaxControlHeight() const
505 {
506     Size aHeight;
507     Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
508 	for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
509     {
510 		if ( ppAggregates[i] )
511         {
512             const Size aTemp( ppAggregates[i]->GetOptimalSize(WINDOWSIZE_PREFERRED) );
513             if ( aTemp.Height() > aHeight.Height() )
514                 aHeight.Height() = aTemp.Height();
515         } // if ( ppAggregates[i] )
516     }
517 
518     return aHeight.Height();
519 }
520 //------------------------------------------------------------------------------
SetReadOnly(sal_Bool bReadOnly)521 void OFieldDescControl::SetReadOnly( sal_Bool bReadOnly )
522 {
523 	DBG_CHKTHIS(OFieldDescControl,NULL);
524 	//////////////////////////////////////////////////////////////////////
525 	// Controls enablen/disablen
526 	Control* ppAggregates[]		= {	  pRequired, pNumType
527 										, pAutoIncrement, pDefault
528 										, pTextLen, pLength
529 										, pScale, m_pColumnName
530 										, m_pType, m_pAutoIncrementValue
531 										, pFormat};
532 	Control* ppAggregatesText[]	= {	  pRequiredText, pNumTypeText
533 										, pAutoIncrementText, pDefaultText
534 										, pTextLenText, pLengthText
535 										, pScaleText, m_pColumnNameText
536 										, m_pTypeText, m_pAutoIncrementValueText
537 										, pFormatText};
538 
539 	OSL_ENSURE(sizeof(ppAggregates)/sizeof(ppAggregates[0]) == sizeof(ppAggregatesText)/sizeof(ppAggregatesText[0]),"Lists are not identical!");
540 
541 	for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
542 	{
543 		if ( ppAggregatesText[i] )
544 			ppAggregatesText[i]->Enable( !bReadOnly );
545 		if ( ppAggregates[i] )
546 			ppAggregates[i]->Enable( !bReadOnly );
547 	}
548 }
549 
550 //------------------------------------------------------------------------------
GetControlText(sal_uInt16 nControlId)551 String OFieldDescControl::GetControlText( sal_uInt16 nControlId )
552 {
553 	DBG_CHKTHIS(OFieldDescControl,NULL);
554 	//////////////////////////////////////////////////////////////////////
555 	// Texte der Controls auslesen
556 	switch( nControlId )
557 	{
558 		case FIELD_PROPERTY_BOOL_DEFAULT:
559 			if (pBoolDefault)
560 				return pBoolDefault->GetSelectEntry();
561 			break;
562 		case FIELD_PROPERTY_DEFAULT:
563 			if (pDefault)
564 				return pDefault->GetText();
565 			break;
566 		case FIELD_PROPERTY_REQUIRED:
567 			if (pRequired)
568 				return pRequired->GetSelectEntry();
569 			break;
570 		case FIELD_PROPERTY_TEXTLEN:
571 			if (pTextLen)
572 				return String::CreateFromInt64(pTextLen->GetValue());
573 		case FIELD_PROPERTY_NUMTYPE:
574 			if (pNumType)
575 				return pNumType->GetSelectEntry();
576 			break;
577 		case FIELD_PROPERTY_AUTOINC:
578 			if (pAutoIncrement)
579 				return pAutoIncrement->GetSelectEntry();
580 			break;
581 		case FIELD_PROPERTY_LENGTH:
582 			if (pLength)
583 				return pLength->GetText();
584 			break;
585 		case FIELD_PROPERTY_SCALE:
586 			if (pScale)
587 				return pScale->GetText();
588 			break;
589 		case FIELD_PROPERTY_FORMAT:
590 			if (pFormatSample)
591 				return pFormatSample->GetText();
592 			break;
593 		case FIELD_PRPOERTY_COLUMNNAME:
594 			if(m_pColumnName)
595 				return m_pColumnName->GetText();
596 		case FIELD_PRPOERTY_TYPE:
597 			if(m_pType)
598 				return m_pType->GetSelectEntry();
599 			break;
600 		case FIELD_PRPOERTY_AUTOINCREMENT:
601 			if(m_pAutoIncrementValue)
602 				return m_pAutoIncrementValue->GetText();
603 	}
604 
605 	return String();
606 }
607 
608 //------------------------------------------------------------------------------
SetControlText(sal_uInt16 nControlId,const String & rText)609 void OFieldDescControl::SetControlText( sal_uInt16 nControlId, const String& rText )
610 {
611 	DBG_CHKTHIS(OFieldDescControl,NULL);
612 	//////////////////////////////////////////////////////////////////////
613 	// Texte der Controls setzen
614 	switch( nControlId )
615 	{
616 		case FIELD_PROPERTY_BOOL_DEFAULT:
617 			if (pBoolDefault)
618 			{
619 				String sOld = pBoolDefault->GetSelectEntry();
620 				pBoolDefault->SelectEntry(rText);
621 				if (!sOld.Equals(rText))
622 					LINK(this, OFieldDescControl, ChangeHdl).Call(pBoolDefault);
623 			}
624 			break;
625 		case FIELD_PROPERTY_DEFAULT:
626 			if (pDefault)
627 			{
628 				pDefault->SetText(rText);
629 				UpdateFormatSample(pActFieldDescr);
630 			}
631 			break;
632 
633 		case FIELD_PROPERTY_REQUIRED:
634 			if (pRequired)
635 				pRequired->SelectEntry(rText);
636 			break;
637 
638 
639 		case FIELD_PROPERTY_TEXTLEN:
640 			if (pTextLen)
641 				pTextLen->SetText(rText);
642 			break;
643 
644 		case FIELD_PROPERTY_NUMTYPE:
645 			if (pNumType)
646 				pNumType->SelectEntry(rText);
647 			break;
648 
649 		case FIELD_PROPERTY_AUTOINC:
650 			if (pAutoIncrement)
651 			{
652 				String sOld = pAutoIncrement->GetSelectEntry();
653 				pAutoIncrement->SelectEntry(rText);
654 				if (!sOld.Equals(rText))
655 					LINK(this, OFieldDescControl, ChangeHdl).Call(pAutoIncrement);
656 			}
657 			break;
658 
659 		case FIELD_PROPERTY_LENGTH:
660 			if (pLength)
661 				pLength->SetText(rText);
662 			break;
663 
664 		case FIELD_PROPERTY_SCALE:
665 			if (pScale)
666 				pScale->SetText(rText);
667 			break;
668 
669 		case FIELD_PROPERTY_FORMAT:
670 			if (pActFieldDescr)
671 				UpdateFormatSample(pActFieldDescr);
672 			break;
673 		case FIELD_PRPOERTY_COLUMNNAME:
674 			if(m_pColumnName)
675 				m_pColumnName->SetText(rText);
676 			break;
677 		case FIELD_PRPOERTY_TYPE:
678 			if(m_pType)
679 				m_pType->SelectEntry(rText);
680 			break;
681 		case FIELD_PRPOERTY_AUTOINCREMENT:
682 			if(m_pAutoIncrementValue)
683 				m_pAutoIncrementValue->SetText(rText);
684 			break;
685 	}
686 }
687 
688 //------------------------------------------------------------------------
689 IMPL_LINK( OFieldDescControl, FormatClickHdl, Button *, /*pButton*/ )
690 {
691 	DBG_CHKTHIS(OFieldDescControl,NULL);
692 	//////////////////////////////////////////////////////////////////////
693 	// Temporaere Column erzeugen, mit der Datenaustausch mit Dialog erfolgt
694 	if( !pActFieldDescr )
695 		return 0;
696 
697 	sal_Int32 nOldFormatKey(pActFieldDescr->GetFormatKey());
698 	SvxCellHorJustify rOldJustify = pActFieldDescr->GetHorJustify();
699 	Reference< XNumberFormatsSupplier >  xSupplier = GetFormatter()->getNumberFormatsSupplier();
700     SvNumberFormatsSupplierObj* pSupplierImpl = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
701 
702 	SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
703 	sal_uInt16 nFlags;
704 	if(::dbaui::callColumnFormatDialog(this,pFormatter,pActFieldDescr->GetType(),nOldFormatKey,rOldJustify,nFlags,sal_True))
705 	{
706 		sal_Bool bModified = sal_False;
707 		if(nOldFormatKey != pActFieldDescr->GetFormatKey())
708 		{
709 			pActFieldDescr->SetFormatKey( nOldFormatKey );
710 			bModified = sal_True;
711 		}
712 		if(rOldJustify != pActFieldDescr->GetHorJustify())
713 		{
714 			pActFieldDescr->SetHorJustify( rOldJustify );
715 			bModified = sal_True;
716 		}
717 
718 		if(bModified)
719 		{
720 			SetModified(sal_True);
721 			UpdateFormatSample(pActFieldDescr);
722 		}
723 	}
724 	return 0;
725 }
726 
727 // -----------------------------------------------------------------------
SetModified(sal_Bool)728 void OFieldDescControl::SetModified(sal_Bool /*bModified*/)
729 {
730 }
731 //------------------------------------------------------------------------
IMPL_LINK(OFieldDescControl,ChangeHdl,ListBox *,pListBox)732 IMPL_LINK( OFieldDescControl, ChangeHdl, ListBox *, pListBox )
733 {
734 	DBG_CHKTHIS(OFieldDescControl,NULL);
735 	if ( !pActFieldDescr )
736 		return 0;
737 
738     if ( pListBox->GetSavedValue() != pListBox->GetSelectEntryPos() )
739 	    SetModified(sal_True);
740 
741 	// Sonderbehandlund f"ur Bool Felder
742 	if(pListBox == pRequired && pBoolDefault )
743 	{
744 		// wenn pRequired auf sal_True gesetzt ist, dann darf das sal_Bool Feld nicht den Eintrag <<keiner>> besitzen
745 		String sDef = BoolStringUI(::comphelper::getString(pActFieldDescr->GetControlDefault()));
746 
747 		if(pRequired->GetSelectEntryPos() == 0) // JA
748 		{
749 			pBoolDefault->RemoveEntry(String(ModuleRes(STR_VALUE_NONE)));
750 			if (!sDef.Equals(aYes) && !sDef.Equals(aNo))
751 				pBoolDefault->SelectEntryPos(1);  // nein als Default
752 			else
753 				pBoolDefault->SelectEntry(sDef);
754 		}
755 		else if(pBoolDefault->GetEntryCount() < 3)
756 		{
757 			pBoolDefault->InsertEntry(String(ModuleRes(STR_VALUE_NONE)));
758 			pBoolDefault->SelectEntry(sDef);
759 		}
760 	}
761 
762 	// nur fuer AutoIncrement eine Sonderbehandlung
763 	if (pListBox == pAutoIncrement)
764 	{
765 		if(pListBox->GetSelectEntryPos() == 1)
766 		{ // no
767 			DeactivateAggregate( tpAutoIncrementValue );
768 			if(pActFieldDescr->IsPrimaryKey())
769 				DeactivateAggregate( tpRequired );
770 			else if( pActFieldDescr->getTypeInfo()->bNullable )
771 			{
772 				ActivateAggregate( tpRequired );
773 				if(pRequired)
774 				{
775 					if( pActFieldDescr->IsNullable() )
776 						pRequired->SelectEntryPos( 1 ); // no
777 					else
778 						pRequired->SelectEntryPos( 0 ); // yes
779 				}
780 			}
781 			ActivateAggregate( tpDefault );
782 		}
783 		else
784 		{
785 			DeactivateAggregate( tpRequired );
786 			DeactivateAggregate( tpDefault );
787 			ActivateAggregate( tpAutoIncrementValue );
788 		}
789 		// und jetzt alle nach oben schieben
790 		ArrangeAggregates();
791 	}
792 
793 	if(pListBox == m_pType)
794 	{
795 		TOTypeInfoSP pTypeInfo = getTypeInfo(m_pType->GetSelectEntryPos());
796 		pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False); // SetType(pTypeInfo);
797 
798 		DisplayData(pActFieldDescr);
799 		CellModified(-1, m_pType->GetPos());
800 	}
801 
802 	return 0;
803 }
804 //------------------------------------------------------------------------------
805 // alle Control neu anordnen, so dass sie in fester Reihenfolge und wirklich
806 // OBEN auf der DescriptionPage stehen
ArrangeAggregates()807 void OFieldDescControl::ArrangeAggregates()
808 {
809 	DBG_CHKTHIS(OFieldDescControl,NULL);
810 	// die Beschreibung eines Controls
811 	struct AGGREGATE_DESCRIPTION
812 	{
813 		Control*	pctrlInputControl;	// das eigentliche Control zur Eingabe
814 		Control*	pctrlTextControl;	// das Label dazu
815 		sal_uInt16		nPosSizeArgument;	// das zweite Argument fuer SetPosSize
816 	};
817 	AGGREGATE_DESCRIPTION adAggregates[] = {
818 		{ m_pColumnName, m_pColumnNameText, 1},
819 		{ m_pType, m_pTypeText, 1},
820 		{ pAutoIncrement, pAutoIncrementText, 1 },
821 		{ m_pAutoIncrementValue, m_pAutoIncrementValueText, 3 },
822 		{ pNumType, pNumTypeText, 1 },
823 		{ pRequired, pRequiredText, 1 },
824 		{ pTextLen, pTextLenText, 1 },
825 		{ pLength, pLengthText, 1 },
826 		{ pScale, pScaleText, 1 },
827 		{ pDefault, pDefaultText, 3 },
828 		{ pFormatSample, pFormatText, 4 },
829 		{ pBoolDefault, pBoolDefaultText, 1 },
830 	};
831 
832 	long nMaxWidth = 0;
833 	for (size_t i=0; i<sizeof(adAggregates)/sizeof(adAggregates[0]); i++)
834 	{
835 		if (adAggregates[i].pctrlTextControl)
836 		{
837 			nMaxWidth = ::std::max<long>(OutputDevice::GetTextWidth(adAggregates[i].pctrlTextControl->GetText()),nMaxWidth);
838 		}
839 	}
840 
841 	OSL_ENSURE(nMaxWidth != 0,"Invalid width!");
842 
843 	// und los ...
844 	int nCurrentControlPos = 0;
845 	Control* pZOrderPredecessor = NULL;
846 	for (size_t i=0; i<sizeof(adAggregates)/sizeof(adAggregates[0]); i++)
847 	{
848 		if (adAggregates[i].pctrlInputControl)
849 		{
850 			SetPosSize(&adAggregates[i].pctrlTextControl, nCurrentControlPos, 0);
851 			SetPosSize(&adAggregates[i].pctrlInputControl, nCurrentControlPos, adAggregates[i].nPosSizeArgument);
852 
853 			// die Z-Order so, dass die Controls auch wirklich in derselben Reihenfolge durchwandert werden koennen, in der sie
854 			// hier angeordnet wurden
855             adAggregates[i].pctrlTextControl->SetZOrder(pZOrderPredecessor, pZOrderPredecessor ? WINDOW_ZORDER_BEHIND : WINDOW_ZORDER_FIRST);
856 			adAggregates[i].pctrlInputControl->SetZOrder(adAggregates[i].pctrlTextControl, WINDOW_ZORDER_BEHIND );
857 			pZOrderPredecessor = adAggregates[i].pctrlInputControl;
858 
859 			if (adAggregates[i].pctrlInputControl == pFormatSample)
860 			{
861 				pFormat->SetZOrder(pZOrderPredecessor, WINDOW_ZORDER_BEHIND);
862 				pZOrderPredecessor = pFormat;
863 			}
864 
865 			++nCurrentControlPos;
866 		}
867 	}
868 
869 	// eine Sonderbehandlung fuer die Format-Controls
870 	if (pFormat)
871 	{
872 		Point ptSamplePos(pFormatSample->GetPosPixel());
873 		Size szSampleSize(pFormatSample->GetSizePixel());
874 		pFormat->SetPosPixel(Point(ptSamplePos.X() + szSampleSize.Width() + 5, ptSamplePos.Y()));
875 	}
876 
877 	// als letztes noch die ScrollBars in der ZOrder ganz nach oben
878 	m_pVertScroll->SetZOrder(NULL, WINDOW_ZORDER_FIRST);
879 	m_pHorzScroll->SetZOrder(NULL, WINDOW_ZORDER_FIRST);
880 }
881 
882 //------------------------------------------------------------------------------
ActivateAggregate(EControlType eType)883 void OFieldDescControl::ActivateAggregate( EControlType eType )
884 {
885 	DBG_CHKTHIS(OFieldDescControl,NULL);
886 	//////////////////////////////////////////////////////////////////////
887 	// Controls erzeugen
888 	switch( eType )
889 	{
890 	case tpDefault:
891 		if( pDefault )
892 			return;
893 		m_nPos++;
894         pDefaultText = CreateText(STR_DEFAULT_VALUE);
895 		pDefault = new OPropEditCtrl( this, STR_HELP_DEFAULT_VALUE, FIELD_PROPERTY_DEFAULT, WB_BORDER );
896         InitializeControl(pDefault,HID_TAB_ENT_DEFAULT,false);
897 		break;
898 	case tpAutoIncrementValue:
899 		if( m_pAutoIncrementValue || !isAutoIncrementValueEnabled() )
900 			return;
901 		m_nPos++;
902         m_pAutoIncrementValueText = CreateText(STR_AUTOINCREMENT_VALUE);
903 		m_pAutoIncrementValue = new OPropEditCtrl( this, STR_HELP_AUTOINCREMENT_VALUE, FIELD_PRPOERTY_AUTOINCREMENT, WB_BORDER );
904 		m_pAutoIncrementValue->SetText( getAutoIncrementValue() );
905         InitializeControl(m_pAutoIncrementValue,HID_TAB_AUTOINCREMENTVALUE,false);
906 		break;
907 
908 	case tpRequired:
909 	{
910 		if( pRequired )
911 			return;
912 		Reference< XDatabaseMetaData> xMetaData = getMetaData();
913 
914 		if(xMetaData.is() && xMetaData->supportsNonNullableColumns())
915 		{
916 			m_nPos++;
917             pRequiredText = CreateText(STR_FIELD_REQUIRED);
918 			pRequired = new OPropListBoxCtrl( this, STR_HELP_FIELD_REQUIRED, FIELD_PROPERTY_REQUIRED, WB_DROPDOWN);
919 
920 			pRequired->InsertEntry( aYes );
921 			pRequired->InsertEntry( aNo );
922 			pRequired->SelectEntryPos(1);
923 
924             InitializeControl(pRequired,HID_TAB_ENT_REQUIRED,true);
925 		}
926 	}
927 	break;
928 	case tpAutoIncrement:
929 	{
930 		if( pAutoIncrement )
931 			return;
932 		m_nPos++;
933         pAutoIncrementText = CreateText(STR_FIELD_AUTOINCREMENT);
934 		pAutoIncrement = new OPropListBoxCtrl( this, STR_HELP_AUTOINCREMENT, FIELD_PROPERTY_AUTOINC, WB_DROPDOWN );
935 		pAutoIncrement->InsertEntry( aYes );
936 		pAutoIncrement->InsertEntry( aNo );
937 		pAutoIncrement->SelectEntryPos(0);
938         InitializeControl(pAutoIncrement,HID_TAB_ENT_AUTOINCREMENT,true);
939 	}
940 	break;
941 	case tpTextLen:
942 		if( pTextLen )
943 			return;
944 		m_nPos++;
945         pTextLenText = CreateText(STR_TEXT_LENGTH);
946         pTextLen = CreateNumericControl(STR_HELP_TEXT_LENGTH, FIELD_PROPERTY_TEXTLEN,HID_TAB_ENT_TEXT_LEN);
947 		break;
948 
949 	case tpType:
950 		if( m_pType)
951 			return;
952 		m_nPos++;
953         m_pTypeText = CreateText(STR_TAB_FIELD_DATATYPE);
954 		m_pType = new OPropListBoxCtrl( this, STR_HELP_AUTOINCREMENT, FIELD_PRPOERTY_TYPE, WB_DROPDOWN );
955 		m_pType->SetDropDownLineCount(20);
956 		{
957 			const OTypeInfoMap* pTypeInfo = getTypeInfo();
958 			OTypeInfoMap::const_iterator aIter = pTypeInfo->begin();
959             OTypeInfoMap::const_iterator aEnd = pTypeInfo->end();
960 			for(;aIter != aEnd;++aIter)
961 				m_pType->InsertEntry( aIter->second->aUIName );
962 		}
963 		m_pType->SelectEntryPos(0);
964         InitializeControl(m_pType,HID_TAB_ENT_TYPE,true);
965 		break;
966 	case tpColumnName:
967 		if( m_pColumnName )
968 			return;
969 		m_nPos++;
970         {
971             sal_uInt32 nMax = EDIT_NOLIMIT;
972             ::rtl::OUString aTmpString;
973             try
974             {
975 			    Reference< XDatabaseMetaData> xMetaData = getMetaData();
976                 if ( xMetaData.is() )
977                 {
978 			        nMax =  xMetaData->getMaxColumnNameLength();
979                     aTmpString = xMetaData->getExtraNameCharacters();
980                 }
981             }
982             catch(Exception&)
983             {
984                 DBG_UNHANDLED_EXCEPTION();
985             }
986             m_pColumnNameText = CreateText(STR_TAB_FIELD_NAME);
987 			m_pColumnName = new OPropColumnEditCtrl( this,
988 							                        aTmpString,
989 													STR_HELP_DEFAULT_VALUE,
990 													FIELD_PRPOERTY_COLUMNNAME,
991 													WB_BORDER );
992 			m_pColumnName->SetMaxTextLen(xub_StrLen( nMax ? nMax : EDIT_NOLIMIT));
993 			m_pColumnName->setCheck( isSQL92CheckEnabled(getConnection()) );
994 		}
995 
996         InitializeControl(m_pColumnName,HID_TAB_ENT_COLUMNNAME,false);
997 		break;
998 	case tpNumType:
999 		if( pNumType )
1000 			return;
1001 		m_nPos++;
1002         pNumTypeText = CreateText(STR_NUMERIC_TYPE);
1003 
1004 		pNumType = new OPropListBoxCtrl( this, STR_HELP_NUMERIC_TYPE, FIELD_PROPERTY_NUMTYPE, WB_DROPDOWN );
1005 		pNumType->SetDropDownLineCount(5);
1006 
1007 		pNumType->InsertEntry( String::CreateFromAscii("Byte") );
1008 		pNumType->InsertEntry( String::CreateFromAscii("SmallInt") );
1009 		pNumType->InsertEntry( String::CreateFromAscii("Integer") );
1010 		pNumType->InsertEntry( String::CreateFromAscii("Single") );
1011 		pNumType->InsertEntry( String::CreateFromAscii("Double") );
1012 		pNumType->SelectEntryPos(2);
1013         InitializeControl(pNumType,HID_TAB_ENT_NUMTYP,true);
1014 		break;
1015 
1016 	case tpLength:
1017 		if( pLength )
1018 			return;
1019 		m_nPos++;
1020         pLengthText = CreateText(STR_LENGTH);
1021         pLength = CreateNumericControl(STR_HELP_LENGTH, FIELD_PROPERTY_LENGTH,HID_TAB_ENT_LEN);
1022 		break;
1023 
1024 	case tpScale:
1025 		if( pScale )
1026 			return;
1027 		m_nPos++;
1028         pScaleText = CreateText(STR_SCALE);
1029         pScale = CreateNumericControl(STR_HELP_SCALE, FIELD_PROPERTY_SCALE,HID_TAB_ENT_SCALE);
1030 		break;
1031 
1032 	case tpFormat:
1033 		if (!pFormat)
1034 		{
1035 			m_nPos++;
1036             pFormatText = CreateText(STR_FORMAT);
1037 
1038 			pFormatSample = new OPropEditCtrl( this, STR_HELP_FORMAT_CODE, -1, WB_BORDER );
1039 			pFormatSample->SetReadOnly(sal_True);
1040 			pFormatSample->Enable(sal_False);
1041             InitializeControl(pFormatSample,HID_TAB_ENT_FORMAT_SAMPLE,false);
1042 
1043 			pFormat = new PushButton( this, ModuleRes(PB_FORMAT) );
1044             const sal_Int32 nControlHeight = GetMaxControlHeight();
1045 			pFormat->SetSizePixel(Size(nControlHeight, nControlHeight));
1046 			pFormat->SetClickHdl( LINK( this, OFieldDescControl, FormatClickHdl ) );
1047             InitializeControl(pFormat,HID_TAB_ENT_FORMAT,false);
1048 		}
1049 
1050 		UpdateFormatSample(pActFieldDescr);
1051 		break;
1052 	case tpBoolDefault:
1053 		if (pBoolDefault)
1054 			return;
1055 
1056 		m_nPos++;
1057         pBoolDefaultText = CreateText(STR_DEFAULT_VALUE);
1058 		pBoolDefault = new OPropListBoxCtrl( this, STR_HELP_BOOL_DEFAULT, FIELD_PROPERTY_BOOL_DEFAULT, WB_DROPDOWN );
1059 		pBoolDefault->SetDropDownLineCount(3);
1060 		pBoolDefault->InsertEntry(String(ModuleRes(STR_VALUE_NONE)));
1061 		pBoolDefault->InsertEntry(aYes);
1062 		pBoolDefault->InsertEntry(aNo);
1063 
1064         InitializeControl(pBoolDefault,HID_TAB_ENT_BOOL_DEFAULT,false);
1065 		break;
1066 	}
1067 }
1068 // -----------------------------------------------------------------------------
InitializeControl(Control * _pControl,const::rtl::OString & _sHelpId,bool _bAddChangeHandler)1069 void OFieldDescControl::InitializeControl(Control* _pControl,const ::rtl::OString& _sHelpId,bool _bAddChangeHandler)
1070 {
1071     _pControl->SetHelpId(_sHelpId);
1072     if ( _bAddChangeHandler )
1073 	    ((OPropListBoxCtrl*)_pControl)->SetSelectHdl(LINK(this,OFieldDescControl,ChangeHdl));
1074 
1075 	_pControl->SetGetFocusHdl(LINK(this, OFieldDescControl, OnControlFocusGot));
1076 	_pControl->SetLoseFocusHdl(LINK(this, OFieldDescControl, OnControlFocusLost));
1077 	_pControl->EnableClipSiblings();
1078 }
1079 // -----------------------------------------------------------------------------
CreateText(sal_uInt16 _nTextRes)1080 FixedText* OFieldDescControl::CreateText(sal_uInt16 _nTextRes)
1081 {
1082     FixedText* pFixedText = new FixedText( this );
1083 	pFixedText->SetText( ModuleRes(_nTextRes) );
1084     pFixedText->EnableClipSiblings();
1085     return pFixedText;
1086 }
1087 // -----------------------------------------------------------------------------
CreateNumericControl(sal_uInt16 _nHelpStr,short _nProperty,const rtl::OString & _sHelpId)1088 OPropNumericEditCtrl* OFieldDescControl::CreateNumericControl(sal_uInt16 _nHelpStr,short _nProperty,const rtl::OString& _sHelpId)
1089 {
1090     OPropNumericEditCtrl* pControl = new OPropNumericEditCtrl( this, _nHelpStr, _nProperty, WB_BORDER );
1091 	pControl->SetDecimalDigits(0);
1092 	pControl->SetMin(0);
1093 	pControl->SetMax(0x7FFFFFFF);	// soll draussen geaendert werden, wenn noetig
1094 	pControl->SetStrictFormat(sal_True);
1095 
1096     InitializeControl(pControl,_sHelpId,false);
1097 
1098     return pControl;
1099 }
1100 //------------------------------------------------------------------------------
DeactivateAggregate(EControlType eType)1101 void OFieldDescControl::DeactivateAggregate( EControlType eType )
1102 {
1103 	DBG_CHKTHIS(OFieldDescControl,NULL);
1104     pLastFocusWindow = NULL;
1105 	//////////////////////////////////////////////////////////////////////
1106 	// Controls zerstoeren
1107 	switch( eType )
1108 	{
1109 	case tpDefault:
1110         lcl_HideAndDeleteControl(m_nPos,&pDefault,&pDefaultText);
1111 		break;
1112 
1113 	case tpAutoIncrementValue:
1114         lcl_HideAndDeleteControl(m_nPos,&m_pAutoIncrementValue,&m_pAutoIncrementValueText);
1115 		break;
1116 
1117 	case tpColumnName:
1118         lcl_HideAndDeleteControl(m_nPos,&m_pColumnName,&m_pColumnNameText);
1119 		break;
1120 
1121 	case tpType:
1122         lcl_HideAndDeleteControl(m_nPos,&m_pType,&m_pTypeText);
1123 		break;
1124 
1125 	case tpAutoIncrement:
1126         lcl_HideAndDeleteControl(m_nPos,&pAutoIncrement,&pAutoIncrementText);
1127 		break;
1128 
1129 	case tpRequired:
1130         lcl_HideAndDeleteControl(m_nPos,&pRequired,&pRequiredText);
1131 		break;
1132 
1133 	case tpTextLen:
1134         lcl_HideAndDeleteControl(m_nPos,&pTextLen,&pTextLenText);
1135 		break;
1136 
1137 	case tpNumType:
1138         lcl_HideAndDeleteControl(m_nPos,&pNumType,&pNumTypeText);
1139 		break;
1140 
1141 	case tpLength:
1142 		lcl_HideAndDeleteControl(m_nPos,&pLength,&pLengthText);
1143 		break;
1144 
1145 	case tpScale:
1146 		lcl_HideAndDeleteControl(m_nPos,&pScale,&pScaleText);
1147 		break;
1148 
1149 	case tpFormat:
1150         // TODO: we have to check if we have to increment m_nPos again
1151         lcl_HideAndDeleteControl(m_nPos,&pFormat,&pFormatText);
1152         if ( pFormatSample )
1153         {
1154 		    pFormatSample->Hide();
1155 		    delete pFormatSample;
1156 		    pFormatSample = NULL;
1157         }
1158 		break;
1159 	case tpBoolDefault:
1160 		lcl_HideAndDeleteControl(m_nPos,&pBoolDefault,&pBoolDefaultText);
1161 		break;
1162 	}
1163 }
1164 
1165 //------------------------------------------------------------------------------
SetPosSize(Control ** ppControl,long nRow,sal_uInt16 nCol)1166 void OFieldDescControl::SetPosSize( Control** ppControl, long nRow, sal_uInt16 nCol )
1167 {
1168 	DBG_CHKTHIS(OFieldDescControl,NULL);
1169 
1170 	//////////////////////////////////////////////////////////////////////
1171 	// Groesse ermitteln
1172     const sal_Int32 nControlHeight = GetMaxControlHeight();
1173 	Size aSize(0,nControlHeight);
1174     if ( isRightAligned() && nCol )
1175         aSize.Width() = LogicToPixel(Size(m_nWidth, 0),MAP_APPFONT).Width();
1176     else
1177     {
1178 	    switch( nCol )
1179 	    {
1180 	    case 0:
1181         default:
1182 		    aSize.Width()  = CONTROL_WIDTH_1;
1183 		    break;
1184 	    case 1:
1185 			aSize.Width()  = CONTROL_WIDTH_2;
1186 		    break;
1187 	    case 3:
1188 			aSize.Width()  = CONTROL_WIDTH_3;
1189 		    break;
1190 	    case 4:
1191 			aSize.Width()  = CONTROL_WIDTH_4;
1192 		    break;
1193 	    } // switch( nCol )
1194     }
1195 
1196 
1197 	//////////////////////////////////////////////////////////////////////
1198 	// Position ermitteln
1199 	Point aPosition;
1200 	switch( nCol )
1201 	{
1202 	case 0:
1203 		aPosition.X() = 0;
1204 		aPosition.Y() = 1;
1205 		break;
1206 	case 1:
1207 	case 3:
1208 	case 4:
1209 		if ( isRightAligned() )
1210 		{
1211 			Size aOwnSize = GetSizePixel();
1212 			aPosition.X() = aOwnSize.Width() - aSize.Width();
1213 		}
1214 		else
1215 			aPosition.X() = CONTROL_WIDTH_1 + CONTROL_SPACING_X;
1216 		break;
1217 	default:
1218 		aPosition.X() = 0;
1219 	}
1220 
1221     (*ppControl)->SetSizePixel( aSize );
1222     aSize = (*ppControl)->GetSizePixel( );
1223 
1224     const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
1225 	aPosition.Y() += ((nRow+1)*nControl_Spacing_y) +
1226 					(nRow*nControlHeight);
1227 
1228 	//////////////////////////////////////////////////////////////////////
1229 	// Control anzeigen
1230 	(*ppControl)->SetPosSizePixel( aPosition, aSize );
1231     aSize = (*ppControl)->GetSizePixel();
1232 
1233 	(*ppControl)->Show();
1234 }
1235 //------------------------------------------------------------------------------
DisplayData(OFieldDescription * pFieldDescr)1236 void OFieldDescControl::DisplayData(OFieldDescription* pFieldDescr )
1237 {
1238 	DBG_CHKTHIS(OFieldDescControl,NULL);
1239 	pActFieldDescr = pFieldDescr;
1240 	if(!pFieldDescr)
1241 	{
1242 		DeactivateAggregate( tpDefault );
1243 		DeactivateAggregate( tpRequired );
1244 		DeactivateAggregate( tpTextLen );
1245 		DeactivateAggregate( tpNumType );
1246 		DeactivateAggregate( tpScale );
1247 		DeactivateAggregate( tpLength );
1248 		DeactivateAggregate( tpFormat );
1249 		DeactivateAggregate( tpAutoIncrement );
1250 		DeactivateAggregate( tpBoolDefault );
1251 		DeactivateAggregate( tpColumnName );
1252 		DeactivateAggregate( tpType );
1253 		DeactivateAggregate( tpAutoIncrementValue );
1254 		m_pPreviousType = TOTypeInfoSP();
1255 		//////////////////////////////////////////////////////////////////////
1256 		// Zeiger des gespeicherten Focus zuruecksetzen
1257 		pLastFocusWindow = NULL;
1258         if ( m_bAdded )
1259         {
1260 		    ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
1261             m_bAdded = sal_False;
1262         }
1263 		return;
1264 	}
1265 
1266     if ( !m_bAdded )
1267     {
1268 	    ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::AddWindow));
1269         m_bAdded = sal_True;
1270     }
1271 
1272 	TOTypeInfoSP pFieldType;
1273 	if( pFieldDescr )
1274 		pFieldType = pFieldDescr->getTypeInfo();
1275 
1276 	ActivateAggregate( tpColumnName );
1277 	ActivateAggregate( tpType );
1278 
1279 	OSL_ENSURE(pFieldType.get(),"We need a type information here!");
1280 	//////////////////////////////////////////////////////////////////////
1281 	// Wenn sich der Typ geaendert hat, Controls austauschen
1282 	if( m_pPreviousType != pFieldType )
1283 	{
1284 		//////////////////////////////////////////////////////////////////////
1285 		// Zeiger des gespeicherten Focus zuruecksetzen
1286 		pLastFocusWindow = NULL;
1287 
1288 		//////////////////////////////////////////////////////////////////////
1289 		// Controls, die nicht mehr angezeigt werden duerfen
1290 		DeactivateAggregate( tpNumType );
1291 
1292 		//////////////////////////////////////////////////////////////////////
1293 		// determine which controls we should show and which not
1294 
1295 		// 1. the required control
1296 		if ( pFieldType->bNullable )
1297 			ActivateAggregate( tpRequired );
1298 		else
1299 			DeactivateAggregate( tpRequired );
1300 
1301 		// 2. the autoincrement
1302 		if ( pFieldType->bAutoIncrement )
1303 		{
1304 			DeactivateAggregate( tpRequired );
1305 			DeactivateAggregate( tpDefault );
1306 			ActivateAggregate( tpAutoIncrement );
1307 			ActivateAggregate( tpAutoIncrementValue );
1308 		}
1309 		else
1310 		{
1311 			DeactivateAggregate( tpAutoIncrement );
1312 			DeactivateAggregate( tpAutoIncrementValue );
1313 			if(pFieldType->bNullable)
1314 				ActivateAggregate( tpRequired );
1315 			else
1316 				DeactivateAggregate( tpRequired );
1317 			ActivateAggregate( tpDefault );
1318 		}
1319 		// 3. the scale and precision
1320 		if (pFieldType->nPrecision)
1321 		{
1322 			ActivateAggregate( tpLength );
1323 			pLength->SetMax(::std::max<sal_Int32>(pFieldType->nPrecision,pFieldDescr->GetPrecision()));
1324 			pLength->SetSpecialReadOnly(pFieldType->aCreateParams.getLength()==0);
1325 		}
1326 		else
1327 			DeactivateAggregate( tpLength );
1328 
1329 		if (pFieldType->nMaximumScale)
1330 		{
1331 			ActivateAggregate( tpScale );
1332 			pScale->SetMax(::std::max<sal_Int32>(pFieldType->nMaximumScale,pFieldDescr->GetScale()));
1333 			pScale->SetMin(pFieldType->nMinimumScale);
1334             static const ::rtl::OUString s_sPRECISION(RTL_CONSTASCII_USTRINGPARAM("PRECISION"));
1335 			pScale->SetSpecialReadOnly(pFieldType->aCreateParams.getLength() == 0 || pFieldType->aCreateParams == s_sPRECISION);
1336 		}
1337 		else
1338 			DeactivateAggregate( tpScale );
1339 
1340 		// and now look for type specific things
1341 		switch( pFieldType->nType )
1342 		{
1343 			case DataType::CHAR:
1344 			case DataType::VARCHAR:
1345 			case DataType::LONGVARCHAR:
1346 				DeactivateAggregate( tpLength );
1347 				DeactivateAggregate( tpBoolDefault );
1348 
1349 				ActivateAggregate( tpDefault );
1350 				ActivateAggregate( tpFormat );
1351 				if (pFieldType->nPrecision)
1352 				{
1353 					ActivateAggregate( tpTextLen );
1354 					pTextLen->SetMax(::std::max<sal_Int32>(pFieldType->nPrecision,pFieldDescr->GetPrecision()));
1355 					pTextLen->SetSpecialReadOnly(pFieldType->aCreateParams.getLength()==0);
1356 				}
1357 				else
1358 					DeactivateAggregate( tpTextLen );
1359 				break;
1360 			case DataType::DATE:
1361 			case DataType::TIME:
1362 			case DataType::TIMESTAMP:
1363 				DeactivateAggregate( tpLength ); // we don't need a length for date types
1364 				DeactivateAggregate( tpTextLen );
1365 				DeactivateAggregate( tpBoolDefault );
1366 
1367 				ActivateAggregate( tpDefault );
1368 				ActivateAggregate( tpFormat );
1369 				break;
1370 			case DataType::BIT:
1371 				if ( pFieldType->aCreateParams.getLength() )
1372 				{
1373 					DeactivateAggregate( tpFormat );
1374 					DeactivateAggregate( tpTextLen );
1375 					DeactivateAggregate( tpBoolDefault );
1376 					break;
1377 				}
1378 				// run through
1379 			case DataType::BOOLEAN:
1380 				DeactivateAggregate( tpTextLen );
1381 				DeactivateAggregate( tpFormat );
1382 				DeactivateAggregate( tpDefault );
1383 
1384 				ActivateAggregate( tpBoolDefault );
1385 				break;
1386 			case DataType::DECIMAL:
1387 			case DataType::NUMERIC:
1388 			case DataType::BIGINT:
1389 			case DataType::FLOAT:
1390 			case DataType::DOUBLE:
1391 			case DataType::TINYINT:
1392 			case DataType::SMALLINT:
1393 			case DataType::INTEGER:
1394 			case DataType::REAL:
1395 				DeactivateAggregate( tpTextLen );
1396 				DeactivateAggregate( tpBoolDefault );
1397 
1398 				ActivateAggregate( tpFormat );
1399 				break;
1400 			case DataType::BINARY:
1401 			case DataType::VARBINARY:
1402 				DeactivateAggregate( tpDefault );
1403 				DeactivateAggregate( tpRequired );
1404 				DeactivateAggregate( tpTextLen );
1405 				DeactivateAggregate( tpBoolDefault );
1406 
1407 				ActivateAggregate( tpFormat );
1408 				break;
1409 			case DataType::LONGVARBINARY:
1410 			case DataType::SQLNULL:
1411 			case DataType::OBJECT:
1412 			case DataType::DISTINCT:
1413 			case DataType::STRUCT:
1414 			case DataType::ARRAY:
1415 			case DataType::BLOB:
1416 			case DataType::CLOB:
1417 			case DataType::REF:
1418 			case DataType::OTHER:
1419 				DeactivateAggregate( tpFormat );
1420 				DeactivateAggregate( tpTextLen );
1421 				DeactivateAggregate( tpBoolDefault );
1422 
1423 				break;
1424 			default:
1425 				OSL_ENSURE(0,"Unknown type");
1426 		}
1427 		m_pPreviousType = pFieldType;
1428 	}
1429 	if(pFieldDescr)
1430 	{
1431 		if(pFieldDescr->IsPrimaryKey())
1432 		{
1433 			DeactivateAggregate( tpRequired );
1434 		}
1435 		else if ( !pAutoIncrement && pFieldType.get() )
1436 		{
1437 			if ( pFieldType->bNullable )
1438 				ActivateAggregate( tpRequired );
1439 			else
1440 				DeactivateAggregate( tpRequired );
1441 		}
1442 	}
1443 	//////////////////////////////////////////////////////////////////////
1444 	// Controls initialisieren
1445 	if( pAutoIncrement )
1446 	{
1447 		if ( pFieldDescr->IsAutoIncrement() )
1448 		{
1449 			pAutoIncrement->SelectEntryPos( 0 ); // yes
1450             ActivateAggregate( tpAutoIncrementValue );
1451 			if ( m_pAutoIncrementValue )
1452 				m_pAutoIncrementValue->SetText(pFieldDescr->GetAutoIncrementValue());
1453 			DeactivateAggregate( tpRequired );
1454 			DeactivateAggregate( tpDefault );
1455 		}
1456 		else
1457 		{
1458 			// disable autoincrement value because it should only be visible when autoincrement is to true
1459 			DeactivateAggregate( tpAutoIncrementValue );
1460 			pAutoIncrement->SelectEntryPos( 1 );		// no
1461 			ActivateAggregate( tpDefault );
1462 			// hat Auswirkungen auf pRequired
1463 			if(!pFieldDescr->IsPrimaryKey())
1464 				ActivateAggregate( tpRequired );
1465 		}
1466 	}
1467 
1468 	if( pDefault )
1469 	{
1470 		pDefault->SetText( getControlDefault(pFieldDescr) );
1471 		pDefault->ClearModifyFlag();
1472 	}
1473 
1474 	if( pBoolDefault )
1475 	{
1476 		// wenn pRequired auf sal_True gesetzt ist, dann darf das sal_Bool Feld nicht den Eintrag <<keiner>> besitzen
1477 		::rtl::OUString sValue;
1478 		pFieldDescr->GetControlDefault() >>= sValue;
1479 		String sDef = BoolStringUI(sValue);
1480 
1481 		// sicher stellen das <<keiner>> nur vorhanden ist, wenn das Feld NULL sein darf
1482 		if ( ( pFieldType.get() && !pFieldType->bNullable ) || !pFieldDescr->IsNullable() )
1483 		{
1484 			pFieldDescr->SetIsNullable(ColumnValue::NO_NULLS); // der Typ sagt das
1485 
1486 			pBoolDefault->RemoveEntry(String(ModuleRes(STR_VALUE_NONE)));
1487 			if ( !sDef.Equals(aYes) && !sDef.Equals(aNo) )
1488 				pBoolDefault->SelectEntryPos(1);  // nein als Default
1489 			else
1490 				pBoolDefault->SelectEntry(sDef);
1491 
1492 			pFieldDescr->SetControlDefault(makeAny(::rtl::OUString(BoolStringPersistent(pBoolDefault->GetSelectEntry()))));
1493 		}
1494 		else if(pBoolDefault->GetEntryCount() < 3)
1495 		{
1496 			pBoolDefault->InsertEntry(String(ModuleRes(STR_VALUE_NONE)));
1497 			pBoolDefault->SelectEntry(sDef);
1498 		}
1499 		else
1500 			pBoolDefault->SelectEntry(sDef);
1501 	}
1502 
1503 	if( pRequired )
1504 	{
1505 		if( pFieldDescr->IsNullable() )
1506 			pRequired->SelectEntryPos( 1 );	// no
1507 		else
1508 			pRequired->SelectEntryPos( 0 );	// yes
1509 	}
1510 
1511 	if( pTextLen )
1512 	{
1513 		pTextLen->SetText( String::CreateFromInt32(pFieldDescr->GetPrecision()) );
1514 		pTextLen->ClearModifyFlag();
1515 	}
1516 
1517 	if( pNumType )
1518 	{
1519 		OSL_ENSURE(sal_False, "OFieldDescControl::DisplayData: invalid num type!");
1520 	}
1521 
1522 	if( pLength )
1523 		pLength->SetText( String::CreateFromInt32(pFieldDescr->GetPrecision()) );
1524 
1525 	if( pScale )
1526 		pScale->SetText( String::CreateFromInt32(pFieldDescr->GetScale()) );
1527 
1528 	if( pFormat )
1529 		UpdateFormatSample(pFieldDescr);
1530 
1531 	if(m_pColumnName)
1532 		m_pColumnName->SetText(pFieldDescr->GetName());
1533 
1534 	if(m_pType)
1535 	{
1536 		sal_uInt16 nPos = pFieldType.get() ? m_pType->GetEntryPos(String(pFieldDescr->getTypeInfo()->aUIName)) : LISTBOX_ENTRY_NOTFOUND;
1537 		if(nPos == LISTBOX_ENTRY_NOTFOUND)
1538 		{
1539 			const OTypeInfoMap*	pMap = getTypeInfo();
1540 			OTypeInfoMap::const_iterator aIter = pMap->find(pFieldType.get() ? pFieldDescr->getTypeInfo()->nType : pFieldDescr->GetType());
1541 			if(aIter == pMap->end() && !pMap->empty())
1542 			{
1543 				aIter = pMap->begin();
1544 				if(pFieldDescr->GetPrecision() > aIter->second->nPrecision)
1545 					pFieldDescr->SetPrecision(aIter->second->nPrecision);
1546 				if(pFieldDescr->GetScale() > aIter->second->nMaximumScale)
1547 					pFieldDescr->SetScale(0);
1548 				if(!aIter->second->bNullable && pFieldDescr->IsNullable())
1549 					pFieldDescr->SetIsNullable(ColumnValue::NO_NULLS);
1550 				if(!aIter->second->bAutoIncrement && pFieldDescr->IsAutoIncrement())
1551 					pFieldDescr->SetAutoIncrement(sal_False);
1552 			}
1553 			if ( aIter != pMap->end() )
1554 			{
1555 				pFieldDescr->SetType(aIter->second);
1556 			}
1557 		}
1558 		m_pType->SelectEntry(pFieldDescr->getTypeInfo()->aUIName);
1559 	}
1560 
1561 
1562 	//////////////////////////////////////////////////////////////////////
1563 	// Controls Enablen/Disablen
1564 	sal_Bool bRead(IsReadOnly());
1565 
1566 
1567 	ArrangeAggregates();
1568 	CheckScrollBars();
1569 	ScrollAllAggregates();
1570 
1571 	SetReadOnly( bRead );
1572 }
1573 //------------------------------------------------------------------------
IMPL_LINK(OFieldDescControl,DelayedGrabFocus,Control **,ppControl)1574 IMPL_LINK(OFieldDescControl, DelayedGrabFocus, Control**, ppControl)
1575 {
1576 	nDelayedGrabFocusEvent = 0;
1577 	if (*ppControl)
1578 		(*ppControl)->GrabFocus();
1579 
1580 	return 0L;
1581 }
1582 
1583 //------------------------------------------------------------------------------
IMPL_LINK(OFieldDescControl,OnControlFocusGot,Control *,pControl)1584 IMPL_LINK(OFieldDescControl, OnControlFocusGot, Control*, pControl )
1585 {
1586 	String strHelpText;
1587     OPropNumericEditCtrl* pNumeric = dynamic_cast< OPropNumericEditCtrl* >( pControl );
1588     if ( pNumeric )
1589 	{
1590 		pNumeric->SaveValue();
1591 		strHelpText = pNumeric->GetHelp();
1592 	}
1593 
1594     OPropColumnEditCtrl* pColumn = dynamic_cast< OPropColumnEditCtrl* >( pControl );
1595     if ( pColumn )
1596 	{
1597 		pColumn->SaveValue();
1598 		strHelpText = pColumn->GetHelp();
1599 	}
1600 
1601     OPropEditCtrl* pEdit = dynamic_cast< OPropEditCtrl* >( pControl );
1602     if ( pEdit )
1603 	{
1604 		pEdit->SaveValue();
1605 		strHelpText = pEdit->GetHelp();
1606 	}
1607 
1608     OPropListBoxCtrl* pListBox = dynamic_cast< OPropListBoxCtrl* >( pControl );
1609     if ( pListBox )
1610 	{
1611 		pListBox->SaveValue();
1612 		strHelpText = pListBox->GetHelp();
1613 	}
1614 
1615     if (pControl == pFormat)
1616 		strHelpText  =String(ModuleRes(STR_HELP_FORMAT_BUTTON));
1617 
1618 	if (strHelpText.Len() && (pHelp != NULL))
1619 		pHelp->SetHelpText(strHelpText);
1620 
1621 	m_pActFocusWindow = pControl;
1622 
1623 	return 0L;
1624 }
1625 
1626 //------------------------------------------------------------------------------
IMPL_LINK(OFieldDescControl,OnControlFocusLost,Control *,pControl)1627 IMPL_LINK(OFieldDescControl, OnControlFocusLost, Control*, pControl )
1628 {
1629 	if ((pControl == pLength) || (pControl == pTextLen) || (pControl == pScale))
1630 	{
1631 		OPropNumericEditCtrl* pConverted = (OPropNumericEditCtrl*)pControl;
1632 		if (pConverted->IsModified())
1633 			CellModified(-1, pConverted->GetPos());
1634 	}
1635 	if(pControl == m_pColumnName)
1636 	{
1637 		OPropColumnEditCtrl* pConverted = (OPropColumnEditCtrl*)pControl;
1638 		if (pConverted->IsModified())
1639 			CellModified(-1, pConverted->GetPos());
1640 	}
1641 	else if ((pControl == pDefault) || (pControl == pFormatSample) || (pControl == m_pAutoIncrementValue) )
1642 	{
1643 		OPropEditCtrl* pConverted = (OPropEditCtrl*)pControl;
1644 		if (pConverted->IsModified())
1645 			CellModified(-1, pConverted->GetPos());
1646 	}
1647 	else if ((pControl == pRequired) || (pControl == pNumType) || (pControl == pAutoIncrement) || (pControl == pBoolDefault) || (pControl == m_pType))
1648 	{
1649 		OPropListBoxCtrl* pConverted = (OPropListBoxCtrl*)pControl;
1650 		if (pConverted->IsModified())
1651 			CellModified(-1, pConverted->GetPos());
1652 	}
1653 
1654 	if (pControl == pDefault)
1655 		UpdateFormatSample(pActFieldDescr);
1656 
1657 	implFocusLost(pControl);
1658 
1659 	return 0L;
1660 }
1661 //------------------------------------------------------------------------------
SaveData(OFieldDescription * pFieldDescr)1662 void OFieldDescControl::SaveData( OFieldDescription* pFieldDescr )
1663 {
1664 	DBG_CHKTHIS(OFieldDescControl,NULL);
1665 	if( !pFieldDescr )
1666 		return;
1667 
1668 	//////////////////////////////////////////////////////////////////////
1669 	// Controls auslesen
1670 	::rtl::OUString sDefault;
1671 	if (pDefault)
1672 	{
1673 		sDefault = pDefault->GetText();
1674 	}
1675 	else if (pBoolDefault)
1676 	{
1677 		sDefault = BoolStringPersistent(pBoolDefault->GetSelectEntry());
1678 	}
1679 
1680 	if ( sDefault.getLength() )
1681         pFieldDescr->SetControlDefault(makeAny(sDefault));
1682 	else
1683 		pFieldDescr->SetControlDefault(Any());
1684 
1685 	if((pRequired && pRequired->GetSelectEntryPos() == 0) || pFieldDescr->IsPrimaryKey() || (pBoolDefault && pBoolDefault->GetEntryCount() == 2))  // yes
1686 		pFieldDescr->SetIsNullable( ColumnValue::NO_NULLS );
1687 	else
1688 		pFieldDescr->SetIsNullable( ColumnValue::NULLABLE );
1689 
1690 	if ( pAutoIncrement )
1691 		pFieldDescr->SetAutoIncrement( pAutoIncrement->GetSelectEntryPos() == 0 );
1692 
1693 	if( pTextLen )
1694 		pFieldDescr->SetPrecision( static_cast<sal_Int32>(pTextLen->GetValue()) );
1695 	else if( pLength )
1696 		pFieldDescr->SetPrecision( static_cast<sal_Int32>(pLength->GetValue()) );
1697 	if( pScale )
1698 		pFieldDescr->SetScale( static_cast<sal_Int32>(pScale->GetValue()) );
1699 
1700 	if(m_pColumnName)
1701 		pFieldDescr->SetName(m_pColumnName->GetText());
1702 
1703 	if ( m_pAutoIncrementValue && isAutoIncrementValueEnabled() )
1704 		pFieldDescr->SetAutoIncrementValue(m_pAutoIncrementValue->GetText());
1705 }
1706 
1707 //------------------------------------------------------------------------------
UpdateFormatSample(OFieldDescription * pFieldDescr)1708 void OFieldDescControl::UpdateFormatSample(OFieldDescription* pFieldDescr)
1709 {
1710 	if ( pFieldDescr && pFormatSample )
1711 	    pFormatSample->SetText(getControlDefault(pFieldDescr,sal_False));
1712 }
1713 
1714 //------------------------------------------------------------------------------
GetFocus()1715 void OFieldDescControl::GetFocus()
1716 {
1717 	DBG_CHKTHIS(OFieldDescControl,NULL);
1718 	//////////////////////////////////////////////////////////////////////
1719 	// Setzt den Focus auf das zuletzt aktive Control
1720 	TabPage::GetFocus();
1721 	if( pLastFocusWindow )
1722 	{
1723 		pLastFocusWindow->GrabFocus();
1724 		pLastFocusWindow = NULL;
1725 	}
1726 }
1727 
1728 //------------------------------------------------------------------------------
implFocusLost(Window * _pWhich)1729 void OFieldDescControl::implFocusLost(Window* _pWhich)
1730 {
1731 	DBG_CHKTHIS(OFieldDescControl,NULL);
1732 	DBG_ASSERT(!_pWhich || IsChild(_pWhich), "OFieldDescControl::implFocusLost : invalid window !");
1733 
1734 	//////////////////////////////////////////////////////////////////////
1735 	// Das aktive Control merken
1736 	if (!pLastFocusWindow)
1737 		pLastFocusWindow = _pWhich;
1738 
1739 	//////////////////////////////////////////////////////////////////////
1740 	// HelpText zuruecksetzen
1741 	if (pHelp && !pHelp->HasChildPathFocus())
1742 		pHelp->SetHelpText( String() );
1743 }
1744 
1745 //------------------------------------------------------------------------------
LoseFocus()1746 void OFieldDescControl::LoseFocus()
1747 {
1748 	DBG_CHKTHIS(OFieldDescControl,NULL);
1749 
1750 	implFocusLost(NULL);
1751 
1752 	TabPage::LoseFocus();
1753 }
1754 // -----------------------------------------------------------------------------
isCopyAllowed()1755 sal_Bool OFieldDescControl::isCopyAllowed()
1756 {
1757 	sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
1758 						(m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample	||
1759 						m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength			||
1760 						m_pActFocusWindow == pScale	 || m_pActFocusWindow == m_pColumnName		||
1761 						m_pActFocusWindow == m_pAutoIncrementValue) &&
1762 						static_cast<Edit*>(m_pActFocusWindow)->GetSelected().Len() != 0;
1763 
1764 	return bAllowed;
1765 }
1766 // -----------------------------------------------------------------------------
isCutAllowed()1767 sal_Bool OFieldDescControl::isCutAllowed()
1768 {
1769 	sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
1770 						(m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample	||
1771 						m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength			||
1772 						m_pActFocusWindow == pScale	 || m_pActFocusWindow == m_pColumnName		||
1773 						m_pActFocusWindow == m_pAutoIncrementValue) &&
1774 						static_cast<Edit*>(m_pActFocusWindow)->GetSelected().Len() != 0;
1775 	return bAllowed;
1776 }
1777 // -----------------------------------------------------------------------------
isPasteAllowed()1778 sal_Bool OFieldDescControl::isPasteAllowed()
1779 {
1780 	sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
1781 						(m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample	||
1782 						m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength			||
1783 						m_pActFocusWindow == pScale	 || m_pActFocusWindow == m_pColumnName		||
1784 						m_pActFocusWindow == m_pAutoIncrementValue);
1785 	if ( bAllowed )
1786 	{
1787 		TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
1788 		bAllowed = aTransferData.HasFormat(SOT_FORMAT_STRING);
1789 	}
1790 	return bAllowed;
1791 }
1792 // -----------------------------------------------------------------------------
cut()1793 void OFieldDescControl::cut()
1794 {
1795 	if(isCutAllowed())
1796 		static_cast<Edit*>(m_pActFocusWindow)->Cut();
1797 }
1798 // -----------------------------------------------------------------------------
copy()1799 void OFieldDescControl::copy()
1800 {
1801 	if(isCopyAllowed()) // this only checks if the focus window is valid
1802 		static_cast<Edit*>(m_pActFocusWindow)->Copy();
1803 }
1804 // -----------------------------------------------------------------------------
paste()1805 void OFieldDescControl::paste()
1806 {
1807 	if(m_pActFocusWindow) // this only checks if the focus window is valid
1808 		static_cast<Edit*>(m_pActFocusWindow)->Paste();
1809 }
1810 // -----------------------------------------------------------------------------
isTextFormat(const OFieldDescription * _pFieldDescr,sal_uInt32 & _nFormatKey) const1811 sal_Bool OFieldDescControl::isTextFormat(const OFieldDescription* _pFieldDescr,sal_uInt32& _nFormatKey) const
1812 {
1813 	_nFormatKey = _pFieldDescr->GetFormatKey();
1814 	sal_Bool bTextFormat = sal_True;
1815 
1816 	try
1817 	{
1818 		if (!_nFormatKey)
1819 		{
1820 			Reference< ::com::sun::star::util::XNumberFormatTypes> xNumberTypes(GetFormatter()->getNumberFormatsSupplier()->getNumberFormats(),UNO_QUERY);
1821 			OSL_ENSURE(xNumberTypes.is(),"XNumberFormatTypes is null!");
1822 
1823 			_nFormatKey = ::dbtools::getDefaultNumberFormat( _pFieldDescr->GetType(),
1824 				_pFieldDescr->GetScale(),
1825 				_pFieldDescr->IsCurrency(),
1826 				xNumberTypes,
1827 				GetLocale());
1828 		}
1829 		sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(GetFormatter(),_nFormatKey);
1830 		bTextFormat = (nNumberFormat == ::com::sun::star::util::NumberFormat::TEXT);
1831 	}
1832 	catch(const Exception&)
1833 	{
1834 
1835 	}
1836 
1837 	return bTextFormat;
1838 }
1839 // -----------------------------------------------------------------------------
getControlDefault(const OFieldDescription * _pFieldDescr,sal_Bool _bCheck) const1840 String OFieldDescControl::getControlDefault( const OFieldDescription* _pFieldDescr ,sal_Bool _bCheck) const
1841 {
1842 	::rtl::OUString sDefault;
1843 	sal_Bool bCheck = !_bCheck || _pFieldDescr->GetControlDefault().hasValue();
1844 	if ( bCheck )
1845 	{
1846 		sal_uInt32 nFormatKey;
1847 		sal_Bool bTextFormat = sal_False;
1848 		double nValue = 0.0;
1849 
1850 		try
1851 		{
1852 			bTextFormat = isTextFormat(_pFieldDescr,nFormatKey);
1853 			if ( _pFieldDescr->GetControlDefault() >>= sDefault )
1854 			{
1855 				if ( !bTextFormat )
1856 				{
1857 					if ( sDefault.getLength() )
1858 					{
1859 						try
1860 						{
1861 							nValue = GetFormatter()->convertStringToNumber(nFormatKey,sDefault);
1862 						}
1863 						catch(const Exception&)
1864 						{
1865 							return ::rtl::OUString(); // return empty string for format example
1866 						}
1867 					}
1868 				}
1869 			}
1870 			else
1871 				_pFieldDescr->GetControlDefault() >>= nValue;
1872 
1873 
1874 			Reference< ::com::sun::star::util::XNumberFormatter> xNumberFormatter = GetFormatter();
1875 			Reference<XPropertySet> xFormSet = xNumberFormatter->getNumberFormatsSupplier()->getNumberFormats()->getByKey(nFormatKey);
1876 			OSL_ENSURE(xFormSet.is(),"XPropertySet is null!");
1877 			::rtl::OUString sFormat;
1878 			xFormSet->getPropertyValue(::rtl::OUString::createFromAscii("FormatString")) >>= sFormat;
1879 
1880 			if ( !bTextFormat )
1881 			{
1882 				Locale aLocale;
1883 				::comphelper::getNumberFormatProperty(xNumberFormatter,nFormatKey,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Locale"))) >>= aLocale;
1884 
1885 				sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(xNumberFormatter,nFormatKey);
1886 				if(		(nNumberFormat & ::com::sun::star::util::NumberFormat::DATE)	== ::com::sun::star::util::NumberFormat::DATE
1887 					|| (nNumberFormat & ::com::sun::star::util::NumberFormat::DATETIME) == ::com::sun::star::util::NumberFormat::DATETIME )
1888 				{
1889 					nValue = DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter->getNumberFormatsSupplier()),nValue);
1890 				}
1891 
1892 
1893 
1894 				Reference< ::com::sun::star::util::XNumberFormatPreviewer> xPreViewer(xNumberFormatter,UNO_QUERY);
1895 				OSL_ENSURE(xPreViewer.is(),"XNumberFormatPreviewer is null!");
1896 				sDefault = xPreViewer->convertNumberToPreviewString(sFormat,nValue,aLocale,sal_True);
1897 			}
1898 			else if ( !_bCheck || (sDefault.getLength() != 0) )
1899 				sDefault = xNumberFormatter->formatString(nFormatKey,(sDefault.getLength() != 0 )? sDefault : sFormat);
1900 		}
1901 		catch(const Exception&)
1902 		{
1903 
1904 		}
1905 	}
1906 
1907 	return sDefault;
1908 }
1909 // -----------------------------------------------------------------------------
1910