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