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