Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / control / FieldDescControl.cxx
blob94534b11649bfb36d6b605376be2f3f444f22965
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "FieldDescControl.hxx"
30 #include "FieldControls.hxx"
31 #include <tools/diagnose_ex.h>
32 #include "TableDesignHelpBar.hxx"
33 #include <vcl/scrbar.hxx>
34 #include <vcl/button.hxx>
35 #include <vcl/svapp.hxx>
36 #include <vcl/fixed.hxx>
37 #include <vcl/msgbox.hxx>
38 #include <vector>
39 #include "FieldDescriptions.hxx"
40 #include "dlgattr.hxx"
41 #include <svx/numfmtsh.hxx>
42 #include <svx/svxids.hrc>
43 #include <svx/algitem.hxx>
44 #include <svl/itempool.hxx>
45 #include <svl/zforlist.hxx>
46 #include <svl/rngitem.hxx>
47 #include <svl/intitem.hxx>
48 #include <svl/numuno.hxx>
49 #include <svtools/transfer.hxx>
50 #include <com/sun/star/lang/XUnoTunnel.hpp>
51 #include <com/sun/star/util/NumberFormat.hpp>
52 #include <com/sun/star/util/XNumberFormatPreviewer.hpp>
53 #include <com/sun/star/util/XNumberFormatTypes.hpp>
54 #include <com/sun/star/beans/XPropertySet.hpp>
55 #include "QEnumTypes.hxx"
56 #include "dbaccess_helpid.hrc"
57 #include <connectivity/dbtools.hxx>
58 #include <connectivity/dbconversion.hxx>
59 #include <comphelper/numbers.hxx>
60 #include "UITools.hxx"
61 #include <memory>
62 #include "dbu_control.hrc"
63 #include "dbu_tbl.hrc"
64 #include <osl/diagnose.h>
67 using namespace dbaui;
68 using namespace dbtools;
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::lang;
72 using namespace ::com::sun::star::sdbc;
73 using namespace ::com::sun::star::util;
75 //==================================================================
77 // For the Controls on the OFieldDescGenPage
78 #define CONTROL_SPACING_X 18 // 6
79 #define CONTROL_SPACING_Y 4
80 #define CONTROL_WIDTH_1 160 // 100
81 #define CONTROL_WIDTH_2 100 // 60
82 #define CONTROL_WIDTH_3 250
83 #define CONTROL_WIDTH_4 (CONTROL_WIDTH_3 - 20 - 5)
85 #define SBA_DEF_RANGEFORMAT (100 + 143) // RangeItem
86 #define SBA_DEF_FMTVALUE (100 + 144) // SfxULONG, Format
87 #define SBA_ATTR_ALIGN_HOR_JUSTIFY (100 + 145) // SvxHorJustifyItem
89 #define HSCROLL_STEP 20
92 namespace
95 template< typename T1, typename T2> void lcl_HideAndDeleteControl(short& _nPos,T1** _pControl,T2** _pControlText)
97 if ( *_pControl )
99 --_nPos;
100 (*_pControl)->Hide();
101 (*_pControlText)->Hide();
102 delete *_pControl;
103 delete *_pControlText;
104 (*_pControl) = NULL;
105 (*_pControlText) = NULL;
111 //==================================================================
112 // class OFieldDescControl
113 //==================================================================
115 DBG_NAME(OFieldDescControl)
117 //==================================================================
118 OFieldDescControl::OFieldDescControl( Window* pParent, const ResId& rResId, OTableDesignHelpBar* pHelpBar)
119 :TabPage( pParent, rResId )
120 ,pHelp( pHelpBar )
121 ,pLastFocusWindow(NULL)
122 ,m_pActFocusWindow(NULL)
123 ,pDefaultText(NULL)
124 ,pRequiredText(NULL)
125 ,pAutoIncrementText(NULL)
126 ,pTextLenText(NULL)
127 ,pNumTypeText(NULL)
128 ,pLengthText(NULL)
129 ,pScaleText(NULL)
130 ,pFormatText(NULL)
131 ,pBoolDefaultText(NULL)
132 ,m_pColumnNameText(NULL)
133 ,m_pTypeText(NULL)
134 ,m_pAutoIncrementValueText(NULL)
135 ,pRequired(NULL)
136 ,pNumType(NULL)
137 ,pAutoIncrement(NULL)
138 ,pDefault(NULL)
139 ,pTextLen(NULL)
140 ,pLength(NULL)
141 ,pScale(NULL)
142 ,pFormatSample(NULL)
143 ,pBoolDefault(NULL)
144 ,m_pColumnName(NULL)
145 ,m_pType(NULL)
146 ,m_pAutoIncrementValue(NULL)
147 ,pFormat(NULL)
148 ,m_pVertScroll( NULL )
149 ,m_pHorzScroll( NULL )
150 ,m_pPreviousType()
151 ,nCurChildId(1)
152 ,m_nPos(-1)
153 ,aYes(ModuleRes(STR_VALUE_YES))
154 ,aNo(ModuleRes(STR_VALUE_NO))
155 ,m_nOldVThumb( 0 )
156 ,m_nOldHThumb( 0 )
157 ,m_nWidth(50)
158 ,m_bAdded(sal_False)
159 ,m_bRightAligned(false)
160 ,pActFieldDescr(NULL)
162 DBG_CTOR(OFieldDescControl,NULL);
164 Contruct();
166 //------------------------------------------------------------------------------
167 OFieldDescControl::OFieldDescControl( Window* pParent, OTableDesignHelpBar* pHelpBar )
168 :TabPage( pParent, WB_3DLOOK | WB_DIALOGCONTROL )
169 ,pHelp( pHelpBar )
170 ,pLastFocusWindow(NULL)
171 ,m_pActFocusWindow(NULL)
172 ,pDefaultText(NULL)
173 ,pRequiredText(NULL)
174 ,pAutoIncrementText(NULL)
175 ,pTextLenText(NULL)
176 ,pNumTypeText(NULL)
177 ,pLengthText(NULL)
178 ,pScaleText(NULL)
179 ,pFormatText(NULL)
180 ,pBoolDefaultText(NULL)
181 ,m_pColumnNameText(NULL)
182 ,m_pTypeText(NULL)
183 ,m_pAutoIncrementValueText(NULL)
184 ,pRequired(NULL)
185 ,pNumType(NULL)
186 ,pAutoIncrement(NULL)
187 ,pDefault(NULL)
188 ,pTextLen(NULL)
189 ,pLength(NULL)
190 ,pScale(NULL)
191 ,pFormatSample(NULL)
192 ,pBoolDefault(NULL)
193 ,m_pColumnName(NULL)
194 ,m_pType(NULL)
195 ,m_pAutoIncrementValue(NULL)
196 ,pFormat(NULL)
197 ,m_pVertScroll( NULL )
198 ,m_pHorzScroll( NULL )
199 ,m_pPreviousType()
200 ,nCurChildId(1)
201 ,m_nPos(-1)
202 ,aYes(ModuleRes(STR_VALUE_YES))
203 ,aNo(ModuleRes(STR_VALUE_NO))
204 ,m_nOldVThumb( 0 )
205 ,m_nOldHThumb( 0 )
206 ,m_nWidth(50)
207 ,m_bAdded(sal_False)
208 ,m_bRightAligned(false)
209 ,pActFieldDescr(NULL)
211 DBG_CTOR(OFieldDescControl,NULL);
212 Contruct();
214 // -----------------------------------------------------------------------------
215 void OFieldDescControl::Contruct()
217 m_pVertScroll = new ScrollBar(this, WB_VSCROLL | WB_REPEAT | WB_DRAG);
218 m_pHorzScroll = new ScrollBar(this, WB_HSCROLL | WB_REPEAT | WB_DRAG);
219 m_pVertScroll->SetScrollHdl(LINK(this, OFieldDescControl, OnScroll));
220 m_pHorzScroll->SetScrollHdl(LINK(this, OFieldDescControl, OnScroll));
221 m_pVertScroll->Show();
222 m_pHorzScroll->Show();
224 m_pVertScroll->EnableClipSiblings();
225 m_pHorzScroll->EnableClipSiblings();
227 m_pVertScroll->SetLineSize(1);
228 m_pVertScroll->SetPageSize(1);
229 m_pHorzScroll->SetLineSize(1);
230 m_pHorzScroll->SetPageSize(1);
232 m_nOldVThumb = m_nOldHThumb = 0;
235 //------------------------------------------------------------------------------
236 OFieldDescControl::~OFieldDescControl()
238 DBG_DTOR(OFieldDescControl,NULL);
241 SAL_WNODEPRECATED_DECLARATIONS_PUSH
242 ::std::auto_ptr<Window> aTemp(m_pVertScroll);
243 SAL_WNODEPRECATED_DECLARATIONS_POP
244 m_pVertScroll = NULL;
247 SAL_WNODEPRECATED_DECLARATIONS_PUSH
248 ::std::auto_ptr<Window> aTemp(m_pHorzScroll);
249 SAL_WNODEPRECATED_DECLARATIONS_POP
250 m_pHorzScroll = NULL;
252 if ( m_bAdded )
253 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
254 pLastFocusWindow = NULL;
256 //////////////////////////////////////////////////////////////////////
257 // Destroy children
258 DeactivateAggregate( tpDefault );
259 DeactivateAggregate( tpRequired );
260 DeactivateAggregate( tpTextLen );
261 DeactivateAggregate( tpNumType );
262 DeactivateAggregate( tpScale );
263 DeactivateAggregate( tpLength );
264 DeactivateAggregate( tpFormat );
265 DeactivateAggregate( tpAutoIncrement );
266 DeactivateAggregate( tpBoolDefault );
267 DeactivateAggregate( tpColumnName );
268 DeactivateAggregate( tpType );
269 DeactivateAggregate( tpAutoIncrementValue );
272 //------------------------------------------------------------------------------
273 String OFieldDescControl::BoolStringPersistent(const String& rUIString) const
275 static String aZero('0');
276 static String aOne('1');
278 if (rUIString == aNo)
279 return aZero;
280 if (rUIString == aYes)
281 return aOne;
282 return String();
285 //------------------------------------------------------------------------------
286 String OFieldDescControl::BoolStringUI(const String& rPersistentString) const
288 static String aZero('0');
289 static String aOne('1');
290 static String aNone(ModuleRes(STR_VALUE_NONE));
292 // Older versions may store a language dependend string as a default
293 if (rPersistentString.Equals(aYes) || rPersistentString.Equals(aNo))
294 return rPersistentString;
296 if (rPersistentString == aZero)
297 return aNo;
298 if (rPersistentString == aOne)
299 return aYes;
301 return aNone;
304 //------------------------------------------------------------------------------
305 void OFieldDescControl::Init()
307 Reference< ::com::sun::star::util::XNumberFormatter > xFormatter = GetFormatter();
308 ::dbaui::setEvalDateFormatForFormatter(xFormatter);
311 //------------------------------------------------------------------------------
312 IMPL_LINK(OFieldDescControl, OnScroll, ScrollBar*, /*pBar*/)
314 ScrollAllAggregates();
315 return 0;
317 // -----------------------------------------------------------------------------
318 namespace
320 void getMaxXPosition(Window* _pWindow,long& _rnMaxXPosition)
322 if (_pWindow)
324 long nTemp = _pWindow->GetSizePixel().Width() + _pWindow->GetPosPixel().X();
325 _rnMaxXPosition = ::std::max(_rnMaxXPosition, nTemp);
329 //------------------------------------------------------------------------------
330 void OFieldDescControl::CheckScrollBars()
332 // Calculate the ScrollBars' new position
333 Size szOverallSize = GetSizePixel();
334 long nHScrollHeight = m_pHorzScroll->GetSizePixel().Height();
335 long nVScrollWidth = m_pVertScroll->GetSizePixel().Width();
337 long nNewHWidth = szOverallSize.Width() - nVScrollWidth;
338 long nNewVHeight = szOverallSize.Height() - nHScrollHeight;
340 sal_Bool bNeedHScrollBar(sal_False), bNeedVScrollBar(sal_False);
342 // Adjust the areas
343 // Do I actually need ScrollBars?
344 // horizontal :
345 long lMaxXPosition = 0;
346 Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
347 for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
348 getMaxXPosition(ppAggregates[i],lMaxXPosition);
350 if (m_pHorzScroll)
351 lMaxXPosition += m_pHorzScroll->GetThumbPos() * HSCROLL_STEP;
353 long lMaxXAvailable = szOverallSize.Width();
354 bNeedHScrollBar = lMaxXPosition > lMaxXAvailable;
355 // Might change
357 // Vertical
358 // How many Controls do I have?
359 sal_uInt16 nActive = CountActiveAggregates();
360 // Which one is the last one that fits?
361 sal_uInt16 nLastVisible;
362 const sal_Int32 nControlHeight = GetMaxControlHeight();
363 const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
364 if (bNeedHScrollBar)
365 nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y - nHScrollHeight) / (nControl_Spacing_y + nControlHeight));
366 else
367 nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y) / (nControl_Spacing_y + nControlHeight));
368 bNeedVScrollBar = nActive>nLastVisible;
370 if (bNeedVScrollBar)
372 // When originally calculating lMaxXAvailable we did not take into account that we have a VScrollBar, so we need to do that now
373 lMaxXAvailable -= nVScrollWidth;
374 if (!bNeedHScrollBar && (lMaxXPosition > lMaxXAvailable))
376 // The vertical one now necessitates a horizontal one
377 bNeedHScrollBar = sal_True;
378 // Adjust nLastVisible
379 nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y - nHScrollHeight) / (nControl_Spacing_y + nControlHeight));
380 // bNeedVScrollBar does NOT change: it's already set to sal_True and nLastVisible will only decrease
384 // Now we can really position them and set their parameters
385 if (bNeedVScrollBar)
387 m_pVertScroll->Show();
388 m_pVertScroll->SetRangeMax(nActive - nLastVisible);
390 m_pVertScroll->SetPosSizePixel( Point(nNewHWidth, 0), Size(nVScrollWidth, szOverallSize.Height()) );
392 else
394 m_pVertScroll->Hide();
395 m_pVertScroll->SetRangeMax(0);
396 m_pVertScroll->SetThumbPos(0);
399 if (bNeedHScrollBar)
401 m_pHorzScroll->Show();
402 m_pHorzScroll->SetRangeMax((lMaxXPosition - lMaxXAvailable + HSCROLL_STEP - 1 )/HSCROLL_STEP);
404 m_pHorzScroll->SetPosSizePixel( Point(0, nNewVHeight), Size(bNeedVScrollBar ? nNewHWidth : szOverallSize.Width(), nHScrollHeight) );
406 else
408 m_pHorzScroll->Hide();
409 m_pHorzScroll->SetRangeMax(0);
410 m_pHorzScroll->SetThumbPos(0);
414 //------------------------------------------------------------------------------
415 void OFieldDescControl::Resize()
417 CheckScrollBars();
418 ScrollAllAggregates();
421 //------------------------------------------------------------------------------
422 inline void OFieldDescControl::ScrollAggregate(Control* pText, Control* pInput, Control* pButton, long nDeltaX, long nDeltaY)
424 if (!pText)
425 return;
426 pText->SetPosPixel(pText->GetPosPixel() + Point(nDeltaX, nDeltaY));
427 pInput->SetPosPixel(pInput->GetPosPixel() + Point(nDeltaX, nDeltaY));
428 if (pButton)
429 pButton->SetPosPixel(pButton->GetPosPixel() + Point(nDeltaX, nDeltaY));
432 //------------------------------------------------------------------------------
433 void OFieldDescControl::ScrollAllAggregates()
435 long nDeltaX = 0, nDeltaY = 0;
436 if (m_nOldHThumb != m_pHorzScroll->GetThumbPos())
438 nDeltaX = (m_nOldHThumb - m_pHorzScroll->GetThumbPos()) * HSCROLL_STEP;
439 m_nOldHThumb = m_pHorzScroll->GetThumbPos();
442 if (m_nOldVThumb != m_pVertScroll->GetThumbPos())
444 const sal_Int32 nControlHeight = GetMaxControlHeight();
445 const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
446 nDeltaY = (m_nOldVThumb - m_pVertScroll->GetThumbPos()) * (nControl_Spacing_y + nControlHeight);
447 m_nOldVThumb = m_pVertScroll->GetThumbPos();
450 if (nDeltaX || nDeltaY)
452 Control* ppAggregates[] = { pRequired, pNumType
453 , pAutoIncrement, pDefault
454 , pTextLen, pLength
455 , pScale, m_pColumnName
456 , m_pType, m_pAutoIncrementValue};
457 Control* ppAggregatesText[] = { pRequiredText, pNumTypeText
458 , pAutoIncrementText, pDefaultText
459 , pTextLenText, pLengthText
460 , pScaleText, m_pColumnNameText
461 , m_pTypeText, m_pAutoIncrementValueText};
462 OSL_ENSURE(sizeof(ppAggregates)/sizeof(ppAggregates[0]) == sizeof(ppAggregatesText)/sizeof(ppAggregatesText[0]),"Lists are not identical!");
464 for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
465 ScrollAggregate(ppAggregatesText[i],ppAggregates[i],NULL,nDeltaX, nDeltaY);
467 ScrollAggregate(pFormatText,pFormatSample,pFormat,nDeltaX, nDeltaY);
471 //------------------------------------------------------------------------------
472 sal_uInt16 OFieldDescControl::CountActiveAggregates() const
474 Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
475 sal_uInt16 nVisibleAggregates = 0;
476 for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
477 if (ppAggregates[i])
478 ++nVisibleAggregates;
479 return nVisibleAggregates;
481 //------------------------------------------------------------------------------
482 sal_Int32 OFieldDescControl::GetMaxControlHeight() const
484 Size aHeight;
485 Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
486 for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
488 if ( ppAggregates[i] )
490 const Size aTemp( ppAggregates[i]->GetOptimalSize(WINDOWSIZE_PREFERRED) );
491 if ( aTemp.Height() > aHeight.Height() )
492 aHeight.Height() = aTemp.Height();
496 return aHeight.Height();
498 //------------------------------------------------------------------------------
499 void OFieldDescControl::SetReadOnly( sal_Bool bReadOnly )
501 DBG_CHKTHIS(OFieldDescControl,NULL);
502 //////////////////////////////////////////////////////////////////////
503 // Enable/disable Controls
504 Control* ppAggregates[] = { pRequired, pNumType
505 , pAutoIncrement, pDefault
506 , pTextLen, pLength
507 , pScale, m_pColumnName
508 , m_pType, m_pAutoIncrementValue
509 , pFormat};
510 Control* ppAggregatesText[] = { pRequiredText, pNumTypeText
511 , pAutoIncrementText, pDefaultText
512 , pTextLenText, pLengthText
513 , pScaleText, m_pColumnNameText
514 , m_pTypeText, m_pAutoIncrementValueText
515 , pFormatText};
517 OSL_ENSURE(sizeof(ppAggregates)/sizeof(ppAggregates[0]) == sizeof(ppAggregatesText)/sizeof(ppAggregatesText[0]),"Lists are not identical!");
519 for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
521 if ( ppAggregatesText[i] )
522 ppAggregatesText[i]->Enable( !bReadOnly );
523 if ( ppAggregates[i] )
524 ppAggregates[i]->Enable( !bReadOnly );
528 //------------------------------------------------------------------------------
529 String OFieldDescControl::GetControlText( sal_uInt16 nControlId )
531 DBG_CHKTHIS(OFieldDescControl,NULL);
532 //////////////////////////////////////////////////////////////////////
533 // Read out the Controls' texts
534 switch( nControlId )
536 case FIELD_PROPERTY_BOOL_DEFAULT:
537 if (pBoolDefault)
538 return pBoolDefault->GetSelectEntry();
539 break;
540 case FIELD_PROPERTY_DEFAULT:
541 if (pDefault)
542 return pDefault->GetText();
543 break;
544 case FIELD_PROPERTY_REQUIRED:
545 if (pRequired)
546 return pRequired->GetSelectEntry();
547 break;
548 case FIELD_PROPERTY_TEXTLEN:
549 if (pTextLen)
550 return rtl::OUString::valueOf(static_cast<sal_Int64>(pTextLen->GetValue()));
551 case FIELD_PROPERTY_NUMTYPE:
552 if (pNumType)
553 return pNumType->GetSelectEntry();
554 break;
555 case FIELD_PROPERTY_AUTOINC:
556 if (pAutoIncrement)
557 return pAutoIncrement->GetSelectEntry();
558 break;
559 case FIELD_PROPERTY_LENGTH:
560 if (pLength)
561 return pLength->GetText();
562 break;
563 case FIELD_PROPERTY_SCALE:
564 if (pScale)
565 return pScale->GetText();
566 break;
567 case FIELD_PROPERTY_FORMAT:
568 if (pFormatSample)
569 return pFormatSample->GetText();
570 break;
571 case FIELD_PRPOERTY_COLUMNNAME:
572 if(m_pColumnName)
573 return m_pColumnName->GetText();
574 case FIELD_PRPOERTY_TYPE:
575 if(m_pType)
576 return m_pType->GetSelectEntry();
577 break;
578 case FIELD_PRPOERTY_AUTOINCREMENT:
579 if(m_pAutoIncrementValue)
580 return m_pAutoIncrementValue->GetText();
583 return String();
586 //------------------------------------------------------------------------------
587 void OFieldDescControl::SetControlText( sal_uInt16 nControlId, const String& rText )
589 DBG_CHKTHIS(OFieldDescControl,NULL);
590 //////////////////////////////////////////////////////////////////////
591 // Set the Controls' texts
592 switch( nControlId )
594 case FIELD_PROPERTY_BOOL_DEFAULT:
595 if (pBoolDefault)
597 String sOld = pBoolDefault->GetSelectEntry();
598 pBoolDefault->SelectEntry(rText);
599 if (!sOld.Equals(rText))
600 LINK(this, OFieldDescControl, ChangeHdl).Call(pBoolDefault);
602 break;
603 case FIELD_PROPERTY_DEFAULT:
604 if (pDefault)
606 pDefault->SetText(rText);
607 UpdateFormatSample(pActFieldDescr);
609 break;
611 case FIELD_PROPERTY_REQUIRED:
612 if (pRequired)
613 pRequired->SelectEntry(rText);
614 break;
617 case FIELD_PROPERTY_TEXTLEN:
618 if (pTextLen)
619 pTextLen->SetText(rText);
620 break;
622 case FIELD_PROPERTY_NUMTYPE:
623 if (pNumType)
624 pNumType->SelectEntry(rText);
625 break;
627 case FIELD_PROPERTY_AUTOINC:
628 if (pAutoIncrement)
630 String sOld = pAutoIncrement->GetSelectEntry();
631 pAutoIncrement->SelectEntry(rText);
632 if (!sOld.Equals(rText))
633 LINK(this, OFieldDescControl, ChangeHdl).Call(pAutoIncrement);
635 break;
637 case FIELD_PROPERTY_LENGTH:
638 if (pLength)
639 pLength->SetText(rText);
640 break;
642 case FIELD_PROPERTY_SCALE:
643 if (pScale)
644 pScale->SetText(rText);
645 break;
647 case FIELD_PROPERTY_FORMAT:
648 if (pActFieldDescr)
649 UpdateFormatSample(pActFieldDescr);
650 break;
651 case FIELD_PRPOERTY_COLUMNNAME:
652 if(m_pColumnName)
653 m_pColumnName->SetText(rText);
654 break;
655 case FIELD_PRPOERTY_TYPE:
656 if(m_pType)
657 m_pType->SelectEntry(rText);
658 break;
659 case FIELD_PRPOERTY_AUTOINCREMENT:
660 if(m_pAutoIncrementValue)
661 m_pAutoIncrementValue->SetText(rText);
662 break;
666 //------------------------------------------------------------------------
667 IMPL_LINK( OFieldDescControl, FormatClickHdl, Button *, /*pButton*/ )
669 DBG_CHKTHIS(OFieldDescControl,NULL);
670 //////////////////////////////////////////////////////////////////////
671 // Create temporary Column, which is used for data exchange with Dialog
672 if( !pActFieldDescr )
673 return 0;
675 sal_Int32 nOldFormatKey(pActFieldDescr->GetFormatKey());
676 SvxCellHorJustify rOldJustify = pActFieldDescr->GetHorJustify();
677 Reference< XNumberFormatsSupplier > xSupplier = GetFormatter()->getNumberFormatsSupplier();
678 SvNumberFormatsSupplierObj* pSupplierImpl = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
680 SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
681 sal_uInt16 nFlags;
682 if(::dbaui::callColumnFormatDialog(this,pFormatter,pActFieldDescr->GetType(),nOldFormatKey,rOldJustify,nFlags,sal_True))
684 sal_Bool bModified = sal_False;
685 if(nOldFormatKey != pActFieldDescr->GetFormatKey())
687 pActFieldDescr->SetFormatKey( nOldFormatKey );
688 bModified = sal_True;
690 if(rOldJustify != pActFieldDescr->GetHorJustify())
692 pActFieldDescr->SetHorJustify( rOldJustify );
693 bModified = sal_True;
696 if(bModified)
698 SetModified(sal_True);
699 UpdateFormatSample(pActFieldDescr);
702 return 0;
705 // -----------------------------------------------------------------------
706 void OFieldDescControl::SetModified(sal_Bool /*bModified*/)
709 //------------------------------------------------------------------------
710 IMPL_LINK( OFieldDescControl, ChangeHdl, ListBox *, pListBox )
712 DBG_CHKTHIS(OFieldDescControl,NULL);
713 if ( !pActFieldDescr )
714 return 0;
716 if ( pListBox->GetSavedValue() != pListBox->GetSelectEntryPos() )
717 SetModified(sal_True);
719 // Special treatment for Boold fields
720 if(pListBox == pRequired && pBoolDefault )
722 // If pRequired = sal_True then the sal_Bool field must NOT contain <<none>>
723 String sDef = BoolStringUI(::comphelper::getString(pActFieldDescr->GetControlDefault()));
725 if(pRequired->GetSelectEntryPos() == 0) // Yes
727 pBoolDefault->RemoveEntry(String(ModuleRes(STR_VALUE_NONE)));
728 if (!sDef.Equals(aYes) && !sDef.Equals(aNo))
729 pBoolDefault->SelectEntryPos(1); // No as a default
730 else
731 pBoolDefault->SelectEntry(sDef);
733 else if(pBoolDefault->GetEntryCount() < 3)
735 pBoolDefault->InsertEntry(String(ModuleRes(STR_VALUE_NONE)));
736 pBoolDefault->SelectEntry(sDef);
740 // A special treatment only for AutoIncrement
741 if (pListBox == pAutoIncrement)
743 if(pListBox->GetSelectEntryPos() == 1)
744 { // no
745 DeactivateAggregate( tpAutoIncrementValue );
746 if(pActFieldDescr->IsPrimaryKey())
747 DeactivateAggregate( tpRequired );
748 else if( pActFieldDescr->getTypeInfo()->bNullable )
750 ActivateAggregate( tpRequired );
751 if(pRequired)
753 if( pActFieldDescr->IsNullable() )
754 pRequired->SelectEntryPos( 1 ); // no
755 else
756 pRequired->SelectEntryPos( 0 ); // yes
759 ActivateAggregate( tpDefault );
761 else
763 DeactivateAggregate( tpRequired );
764 DeactivateAggregate( tpDefault );
765 ActivateAggregate( tpAutoIncrementValue );
767 // Move all up
768 ArrangeAggregates();
771 if(pListBox == m_pType)
773 TOTypeInfoSP pTypeInfo = getTypeInfo(m_pType->GetSelectEntryPos());
774 pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False); // SetType(pTypeInfo);
776 DisplayData(pActFieldDescr);
777 CellModified(-1, m_pType->GetPos());
780 return 0;
782 //------------------------------------------------------------------------------
783 // Rearrange all Controls, such that they are in fixed order and really on top
784 // of the DescriptionPage
785 void OFieldDescControl::ArrangeAggregates()
787 DBG_CHKTHIS(OFieldDescControl,NULL);
788 // A Control's description
789 struct AGGREGATE_DESCRIPTION
791 Control* pctrlInputControl; // The actual Control for input
792 Control* pctrlTextControl; // The corresponding Label
793 sal_uInt16 nPosSizeArgument; // The second argument for SetPosSize
795 AGGREGATE_DESCRIPTION adAggregates[] = {
796 { m_pColumnName, m_pColumnNameText, 1},
797 { m_pType, m_pTypeText, 1},
798 { pAutoIncrement, pAutoIncrementText, 1 },
799 { m_pAutoIncrementValue, m_pAutoIncrementValueText, 3 },
800 { pNumType, pNumTypeText, 1 },
801 { pRequired, pRequiredText, 1 },
802 { pTextLen, pTextLenText, 1 },
803 { pLength, pLengthText, 1 },
804 { pScale, pScaleText, 1 },
805 { pDefault, pDefaultText, 3 },
806 { pFormatSample, pFormatText, 4 },
807 { pBoolDefault, pBoolDefaultText, 1 },
810 long nMaxWidth = 0;
811 for (size_t i=0; i<sizeof(adAggregates)/sizeof(adAggregates[0]); i++)
813 if (adAggregates[i].pctrlTextControl)
815 nMaxWidth = ::std::max<long>(OutputDevice::GetTextWidth(adAggregates[i].pctrlTextControl->GetText()),nMaxWidth);
819 OSL_ENSURE(nMaxWidth != 0,"Invalid width!");
821 // And go ...
822 int nCurrentControlPos = 0;
823 Control* pZOrderPredecessor = NULL;
824 for (size_t i=0; i<sizeof(adAggregates)/sizeof(adAggregates[0]); i++)
826 if (adAggregates[i].pctrlInputControl)
828 SetPosSize(&adAggregates[i].pctrlTextControl, nCurrentControlPos, 0);
829 SetPosSize(&adAggregates[i].pctrlInputControl, nCurrentControlPos, adAggregates[i].nPosSizeArgument);
831 // Set the z-order in a way such that the Controls can be traversed in the same sequence in which they have been arranged here
832 adAggregates[i].pctrlTextControl->SetZOrder(pZOrderPredecessor, pZOrderPredecessor ? WINDOW_ZORDER_BEHIND : WINDOW_ZORDER_FIRST);
833 adAggregates[i].pctrlInputControl->SetZOrder(adAggregates[i].pctrlTextControl, WINDOW_ZORDER_BEHIND );
834 pZOrderPredecessor = adAggregates[i].pctrlInputControl;
836 if (adAggregates[i].pctrlInputControl == pFormatSample)
838 pFormat->SetZOrder(pZOrderPredecessor, WINDOW_ZORDER_BEHIND);
839 pZOrderPredecessor = pFormat;
842 ++nCurrentControlPos;
846 // Special treatment for the Format Controls
847 if (pFormat)
849 Point ptSamplePos(pFormatSample->GetPosPixel());
850 Size szSampleSize(pFormatSample->GetSizePixel());
851 pFormat->SetPosPixel(Point(ptSamplePos.X() + szSampleSize.Width() + 5, ptSamplePos.Y()));
854 // Finally, put the ScrollBars at the top of the z-order
855 m_pVertScroll->SetZOrder(NULL, WINDOW_ZORDER_FIRST);
856 m_pHorzScroll->SetZOrder(NULL, WINDOW_ZORDER_FIRST);
859 //------------------------------------------------------------------------------
860 void OFieldDescControl::ActivateAggregate( EControlType eType )
862 DBG_CHKTHIS(OFieldDescControl,NULL);
863 //////////////////////////////////////////////////////////////////////
864 // Create Controls
865 switch( eType )
867 case tpDefault:
868 if( pDefault )
869 return;
870 m_nPos++;
871 pDefaultText = CreateText(STR_DEFAULT_VALUE);
872 pDefault = new OPropEditCtrl( this, STR_HELP_DEFAULT_VALUE, FIELD_PROPERTY_DEFAULT, WB_BORDER );
873 InitializeControl(pDefault,HID_TAB_ENT_DEFAULT,false);
874 break;
875 case tpAutoIncrementValue:
876 if( m_pAutoIncrementValue || !isAutoIncrementValueEnabled() )
877 return;
878 m_nPos++;
879 m_pAutoIncrementValueText = CreateText(STR_AUTOINCREMENT_VALUE);
880 m_pAutoIncrementValue = new OPropEditCtrl( this, STR_HELP_AUTOINCREMENT_VALUE, FIELD_PRPOERTY_AUTOINCREMENT, WB_BORDER );
881 m_pAutoIncrementValue->SetText( getAutoIncrementValue() );
882 InitializeControl(m_pAutoIncrementValue,HID_TAB_AUTOINCREMENTVALUE,false);
883 break;
885 case tpRequired:
887 if( pRequired )
888 return;
889 Reference< XDatabaseMetaData> xMetaData = getMetaData();
891 if(xMetaData.is() && xMetaData->supportsNonNullableColumns())
893 m_nPos++;
894 pRequiredText = CreateText(STR_FIELD_REQUIRED);
895 pRequired = new OPropListBoxCtrl( this, STR_HELP_FIELD_REQUIRED, FIELD_PROPERTY_REQUIRED, WB_DROPDOWN);
897 pRequired->InsertEntry( aYes );
898 pRequired->InsertEntry( aNo );
899 pRequired->SelectEntryPos(1);
901 InitializeControl(pRequired,HID_TAB_ENT_REQUIRED,true);
904 break;
905 case tpAutoIncrement:
907 if( pAutoIncrement )
908 return;
909 m_nPos++;
910 pAutoIncrementText = CreateText(STR_FIELD_AUTOINCREMENT);
911 pAutoIncrement = new OPropListBoxCtrl( this, STR_HELP_AUTOINCREMENT, FIELD_PROPERTY_AUTOINC, WB_DROPDOWN );
912 pAutoIncrement->InsertEntry( aYes );
913 pAutoIncrement->InsertEntry( aNo );
914 pAutoIncrement->SelectEntryPos(0);
915 InitializeControl(pAutoIncrement,HID_TAB_ENT_AUTOINCREMENT,true);
917 break;
918 case tpTextLen:
919 if( pTextLen )
920 return;
921 m_nPos++;
922 pTextLenText = CreateText(STR_TEXT_LENGTH);
923 pTextLen = CreateNumericControl(STR_HELP_TEXT_LENGTH, FIELD_PROPERTY_TEXTLEN,HID_TAB_ENT_TEXT_LEN);
924 break;
926 case tpType:
927 if( m_pType)
928 return;
929 m_nPos++;
930 m_pTypeText = CreateText(STR_TAB_FIELD_DATATYPE);
931 m_pType = new OPropListBoxCtrl( this, STR_HELP_AUTOINCREMENT, FIELD_PRPOERTY_TYPE, WB_DROPDOWN );
932 m_pType->SetDropDownLineCount(20);
934 const OTypeInfoMap* pTypeInfo = getTypeInfo();
935 OTypeInfoMap::const_iterator aIter = pTypeInfo->begin();
936 OTypeInfoMap::const_iterator aEnd = pTypeInfo->end();
937 for(;aIter != aEnd;++aIter)
938 m_pType->InsertEntry( aIter->second->aUIName );
940 m_pType->SelectEntryPos(0);
941 InitializeControl(m_pType,HID_TAB_ENT_TYPE,true);
942 break;
943 case tpColumnName:
944 if( m_pColumnName )
945 return;
946 m_nPos++;
948 sal_uInt32 nMax = EDIT_NOLIMIT;
949 ::rtl::OUString aTmpString;
952 Reference< XDatabaseMetaData> xMetaData = getMetaData();
953 if ( xMetaData.is() )
955 nMax = xMetaData->getMaxColumnNameLength();
956 aTmpString = xMetaData->getExtraNameCharacters();
959 catch(Exception&)
961 DBG_UNHANDLED_EXCEPTION();
963 m_pColumnNameText = CreateText(STR_TAB_FIELD_NAME);
964 m_pColumnName = new OPropColumnEditCtrl( this,
965 aTmpString,
966 STR_HELP_DEFAULT_VALUE,
967 FIELD_PRPOERTY_COLUMNNAME,
968 WB_BORDER );
969 m_pColumnName->SetMaxTextLen(xub_StrLen( nMax ? nMax : EDIT_NOLIMIT));
970 m_pColumnName->setCheck( isSQL92CheckEnabled(getConnection()) );
973 InitializeControl(m_pColumnName,HID_TAB_ENT_COLUMNNAME,false);
974 break;
975 case tpNumType:
976 if( pNumType )
977 return;
978 m_nPos++;
979 pNumTypeText = CreateText(STR_NUMERIC_TYPE);
981 pNumType = new OPropListBoxCtrl( this, STR_HELP_NUMERIC_TYPE, FIELD_PROPERTY_NUMTYPE, WB_DROPDOWN );
982 pNumType->SetDropDownLineCount(5);
984 pNumType->InsertEntry( String::CreateFromAscii("Byte") );
985 pNumType->InsertEntry( String::CreateFromAscii("SmallInt") );
986 pNumType->InsertEntry( String::CreateFromAscii("Integer") );
987 pNumType->InsertEntry( String::CreateFromAscii("Single") );
988 pNumType->InsertEntry( String::CreateFromAscii("Double") );
989 pNumType->SelectEntryPos(2);
990 InitializeControl(pNumType,HID_TAB_ENT_NUMTYP,true);
991 break;
993 case tpLength:
994 if( pLength )
995 return;
996 m_nPos++;
997 pLengthText = CreateText(STR_LENGTH);
998 pLength = CreateNumericControl(STR_HELP_LENGTH, FIELD_PROPERTY_LENGTH,HID_TAB_ENT_LEN);
999 break;
1001 case tpScale:
1002 if( pScale )
1003 return;
1004 m_nPos++;
1005 pScaleText = CreateText(STR_SCALE);
1006 pScale = CreateNumericControl(STR_HELP_SCALE, FIELD_PROPERTY_SCALE,HID_TAB_ENT_SCALE);
1007 break;
1009 case tpFormat:
1010 if (!pFormat)
1012 m_nPos++;
1013 pFormatText = CreateText(STR_FORMAT);
1015 pFormatSample = new OPropEditCtrl( this, STR_HELP_FORMAT_CODE, -1, WB_BORDER );
1016 pFormatSample->SetReadOnly(sal_True);
1017 pFormatSample->Enable(sal_False);
1018 InitializeControl(pFormatSample,HID_TAB_ENT_FORMAT_SAMPLE,false);
1020 pFormat = new PushButton( this, ModuleRes(PB_FORMAT) );
1021 const sal_Int32 nControlHeight = GetMaxControlHeight();
1022 pFormat->SetSizePixel(Size(nControlHeight, nControlHeight));
1023 pFormat->SetClickHdl( LINK( this, OFieldDescControl, FormatClickHdl ) );
1024 InitializeControl(pFormat,HID_TAB_ENT_FORMAT,false);
1027 UpdateFormatSample(pActFieldDescr);
1028 break;
1029 case tpBoolDefault:
1030 if (pBoolDefault)
1031 return;
1033 m_nPos++;
1034 pBoolDefaultText = CreateText(STR_DEFAULT_VALUE);
1035 pBoolDefault = new OPropListBoxCtrl( this, STR_HELP_BOOL_DEFAULT, FIELD_PROPERTY_BOOL_DEFAULT, WB_DROPDOWN );
1036 pBoolDefault->SetDropDownLineCount(3);
1037 pBoolDefault->InsertEntry(String(ModuleRes(STR_VALUE_NONE)));
1038 pBoolDefault->InsertEntry(aYes);
1039 pBoolDefault->InsertEntry(aNo);
1041 InitializeControl(pBoolDefault,HID_TAB_ENT_BOOL_DEFAULT,false);
1042 break;
1045 // -----------------------------------------------------------------------------
1046 void OFieldDescControl::InitializeControl(Control* _pControl,const ::rtl::OString& _sHelpId,bool _bAddChangeHandler)
1048 _pControl->SetHelpId(_sHelpId);
1049 if ( _bAddChangeHandler )
1050 ((OPropListBoxCtrl*)_pControl)->SetSelectHdl(LINK(this,OFieldDescControl,ChangeHdl));
1052 _pControl->SetGetFocusHdl(LINK(this, OFieldDescControl, OnControlFocusGot));
1053 _pControl->SetLoseFocusHdl(LINK(this, OFieldDescControl, OnControlFocusLost));
1054 _pControl->EnableClipSiblings();
1056 // -----------------------------------------------------------------------------
1057 FixedText* OFieldDescControl::CreateText(sal_uInt16 _nTextRes)
1059 FixedText* pFixedText = new FixedText( this );
1060 pFixedText->SetText( ModuleRes(_nTextRes) );
1061 pFixedText->EnableClipSiblings();
1062 return pFixedText;
1064 // -----------------------------------------------------------------------------
1065 OPropNumericEditCtrl* OFieldDescControl::CreateNumericControl(sal_uInt16 _nHelpStr,short _nProperty,const rtl::OString& _sHelpId)
1067 OPropNumericEditCtrl* pControl = new OPropNumericEditCtrl( this, _nHelpStr, _nProperty, WB_BORDER );
1068 pControl->SetDecimalDigits(0);
1069 pControl->SetMin(0);
1070 pControl->SetMax(0x7FFFFFFF); // Should be changed outside, if needed
1071 pControl->SetStrictFormat(sal_True);
1073 InitializeControl(pControl,_sHelpId,false);
1075 return pControl;
1077 //------------------------------------------------------------------------------
1078 void OFieldDescControl::DeactivateAggregate( EControlType eType )
1080 DBG_CHKTHIS(OFieldDescControl,NULL);
1081 pLastFocusWindow = NULL;
1082 //////////////////////////////////////////////////////////////////////
1083 // Destroy Controls
1084 switch( eType )
1086 case tpDefault:
1087 lcl_HideAndDeleteControl(m_nPos,&pDefault,&pDefaultText);
1088 break;
1090 case tpAutoIncrementValue:
1091 lcl_HideAndDeleteControl(m_nPos,&m_pAutoIncrementValue,&m_pAutoIncrementValueText);
1092 break;
1094 case tpColumnName:
1095 lcl_HideAndDeleteControl(m_nPos,&m_pColumnName,&m_pColumnNameText);
1096 break;
1098 case tpType:
1099 lcl_HideAndDeleteControl(m_nPos,&m_pType,&m_pTypeText);
1100 break;
1102 case tpAutoIncrement:
1103 lcl_HideAndDeleteControl(m_nPos,&pAutoIncrement,&pAutoIncrementText);
1104 break;
1106 case tpRequired:
1107 lcl_HideAndDeleteControl(m_nPos,&pRequired,&pRequiredText);
1108 break;
1110 case tpTextLen:
1111 lcl_HideAndDeleteControl(m_nPos,&pTextLen,&pTextLenText);
1112 break;
1114 case tpNumType:
1115 lcl_HideAndDeleteControl(m_nPos,&pNumType,&pNumTypeText);
1116 break;
1118 case tpLength:
1119 lcl_HideAndDeleteControl(m_nPos,&pLength,&pLengthText);
1120 break;
1122 case tpScale:
1123 lcl_HideAndDeleteControl(m_nPos,&pScale,&pScaleText);
1124 break;
1126 case tpFormat:
1127 // TODO: we have to check if we have to increment m_nPos again
1128 lcl_HideAndDeleteControl(m_nPos,&pFormat,&pFormatText);
1129 if ( pFormatSample )
1131 pFormatSample->Hide();
1132 delete pFormatSample;
1133 pFormatSample = NULL;
1135 break;
1136 case tpBoolDefault:
1137 lcl_HideAndDeleteControl(m_nPos,&pBoolDefault,&pBoolDefaultText);
1138 break;
1142 //------------------------------------------------------------------------------
1143 void OFieldDescControl::SetPosSize( Control** ppControl, long nRow, sal_uInt16 nCol )
1145 DBG_CHKTHIS(OFieldDescControl,NULL);
1147 //////////////////////////////////////////////////////////////////////
1148 // Calculate size
1149 const sal_Int32 nControlHeight = GetMaxControlHeight();
1150 Size aSize(0,nControlHeight);
1151 if ( isRightAligned() && nCol )
1152 aSize.Width() = LogicToPixel(Size(m_nWidth, 0),MAP_APPFONT).Width();
1153 else
1155 switch( nCol )
1157 case 0:
1158 default:
1159 aSize.Width() = CONTROL_WIDTH_1;
1160 break;
1161 case 1:
1162 aSize.Width() = CONTROL_WIDTH_2;
1163 break;
1164 case 3:
1165 aSize.Width() = CONTROL_WIDTH_3;
1166 break;
1167 case 4:
1168 aSize.Width() = CONTROL_WIDTH_4;
1169 break;
1174 //////////////////////////////////////////////////////////////////////
1175 // Calculate Position
1176 Point aPosition;
1177 switch( nCol )
1179 case 0:
1180 aPosition.X() = 0;
1181 aPosition.Y() = 1;
1182 break;
1183 case 1:
1184 case 3:
1185 case 4:
1186 if ( isRightAligned() )
1188 Size aOwnSize = GetSizePixel();
1189 aPosition.X() = aOwnSize.Width() - aSize.Width();
1191 else
1192 aPosition.X() = CONTROL_WIDTH_1 + CONTROL_SPACING_X;
1193 break;
1194 default:
1195 aPosition.X() = 0;
1198 (*ppControl)->SetSizePixel( aSize );
1199 aSize = (*ppControl)->GetSizePixel( );
1201 const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
1202 aPosition.Y() += ((nRow+1)*nControl_Spacing_y) +
1203 (nRow*nControlHeight);
1205 //////////////////////////////////////////////////////////////////////
1206 // Display Control
1207 (*ppControl)->SetPosSizePixel( aPosition, aSize );
1208 aSize = (*ppControl)->GetSizePixel();
1210 (*ppControl)->Show();
1212 //------------------------------------------------------------------------------
1213 void OFieldDescControl::DisplayData(OFieldDescription* pFieldDescr )
1215 DBG_CHKTHIS(OFieldDescControl,NULL);
1216 pActFieldDescr = pFieldDescr;
1217 if(!pFieldDescr)
1219 DeactivateAggregate( tpDefault );
1220 DeactivateAggregate( tpRequired );
1221 DeactivateAggregate( tpTextLen );
1222 DeactivateAggregate( tpNumType );
1223 DeactivateAggregate( tpScale );
1224 DeactivateAggregate( tpLength );
1225 DeactivateAggregate( tpFormat );
1226 DeactivateAggregate( tpAutoIncrement );
1227 DeactivateAggregate( tpBoolDefault );
1228 DeactivateAggregate( tpColumnName );
1229 DeactivateAggregate( tpType );
1230 DeactivateAggregate( tpAutoIncrementValue );
1231 m_pPreviousType = TOTypeInfoSP();
1232 //////////////////////////////////////////////////////////////////////
1233 // Reset the saved focus' pointer
1234 pLastFocusWindow = NULL;
1235 if ( m_bAdded )
1237 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
1238 m_bAdded = sal_False;
1240 return;
1243 if ( !m_bAdded )
1245 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::AddWindow));
1246 m_bAdded = sal_True;
1249 TOTypeInfoSP pFieldType;
1250 if( pFieldDescr )
1251 pFieldType = pFieldDescr->getTypeInfo();
1253 ActivateAggregate( tpColumnName );
1254 ActivateAggregate( tpType );
1256 OSL_ENSURE(pFieldType.get(),"We need a type information here!");
1257 //////////////////////////////////////////////////////////////////////
1258 // If the type has changed, subsitute Controls
1259 if( m_pPreviousType != pFieldType )
1261 //////////////////////////////////////////////////////////////////////
1262 // Reset the saved focus' pointer
1263 pLastFocusWindow = NULL;
1265 //////////////////////////////////////////////////////////////////////
1266 // Controls, which must NOT be displayed again
1267 DeactivateAggregate( tpNumType );
1269 //////////////////////////////////////////////////////////////////////
1270 // determine which controls we should show and which not
1272 // 1. the required control
1273 if ( pFieldType->bNullable )
1274 ActivateAggregate( tpRequired );
1275 else
1276 DeactivateAggregate( tpRequired );
1278 // 2. the autoincrement
1279 if ( pFieldType->bAutoIncrement )
1281 DeactivateAggregate( tpRequired );
1282 DeactivateAggregate( tpDefault );
1283 ActivateAggregate( tpAutoIncrement );
1284 ActivateAggregate( tpAutoIncrementValue );
1286 else
1288 DeactivateAggregate( tpAutoIncrement );
1289 DeactivateAggregate( tpAutoIncrementValue );
1290 if(pFieldType->bNullable)
1291 ActivateAggregate( tpRequired );
1292 else
1293 DeactivateAggregate( tpRequired );
1294 ActivateAggregate( tpDefault );
1296 // 3. the scale and precision
1297 if (pFieldType->nPrecision)
1299 ActivateAggregate( tpLength );
1300 pLength->SetMax(::std::max<sal_Int32>(pFieldType->nPrecision,pFieldDescr->GetPrecision()));
1301 pLength->SetSpecialReadOnly(pFieldType->aCreateParams.isEmpty());
1303 else
1304 DeactivateAggregate( tpLength );
1306 if (pFieldType->nMaximumScale)
1308 ActivateAggregate( tpScale );
1309 pScale->SetMax(::std::max<sal_Int32>(pFieldType->nMaximumScale,pFieldDescr->GetScale()));
1310 pScale->SetMin(pFieldType->nMinimumScale);
1311 static const ::rtl::OUString s_sPRECISION(RTL_CONSTASCII_USTRINGPARAM("PRECISION"));
1312 pScale->SetSpecialReadOnly(pFieldType->aCreateParams.isEmpty() || pFieldType->aCreateParams == s_sPRECISION);
1314 else
1315 DeactivateAggregate( tpScale );
1317 // and now look for type specific things
1318 switch( pFieldType->nType )
1320 case DataType::CHAR:
1321 case DataType::VARCHAR:
1322 case DataType::LONGVARCHAR:
1323 DeactivateAggregate( tpLength );
1324 DeactivateAggregate( tpBoolDefault );
1326 ActivateAggregate( tpDefault );
1327 ActivateAggregate( tpFormat );
1328 if (pFieldType->nPrecision)
1330 ActivateAggregate( tpTextLen );
1331 pTextLen->SetMax(::std::max<sal_Int32>(pFieldType->nPrecision,pFieldDescr->GetPrecision()));
1332 pTextLen->SetSpecialReadOnly(pFieldType->aCreateParams.isEmpty());
1334 else
1335 DeactivateAggregate( tpTextLen );
1336 break;
1337 case DataType::DATE:
1338 case DataType::TIME:
1339 case DataType::TIMESTAMP:
1340 DeactivateAggregate( tpLength ); // we don't need a length for date types
1341 DeactivateAggregate( tpTextLen );
1342 DeactivateAggregate( tpBoolDefault );
1344 ActivateAggregate( tpDefault );
1345 ActivateAggregate( tpFormat );
1346 break;
1347 case DataType::BIT:
1348 if ( !pFieldType->aCreateParams.isEmpty() )
1350 DeactivateAggregate( tpFormat );
1351 DeactivateAggregate( tpTextLen );
1352 DeactivateAggregate( tpBoolDefault );
1353 break;
1355 // run through
1356 case DataType::BOOLEAN:
1357 DeactivateAggregate( tpTextLen );
1358 DeactivateAggregate( tpFormat );
1359 DeactivateAggregate( tpDefault );
1361 ActivateAggregate( tpBoolDefault );
1362 break;
1363 case DataType::DECIMAL:
1364 case DataType::NUMERIC:
1365 case DataType::BIGINT:
1366 case DataType::FLOAT:
1367 case DataType::DOUBLE:
1368 case DataType::TINYINT:
1369 case DataType::SMALLINT:
1370 case DataType::INTEGER:
1371 case DataType::REAL:
1372 DeactivateAggregate( tpTextLen );
1373 DeactivateAggregate( tpBoolDefault );
1375 ActivateAggregate( tpFormat );
1376 break;
1377 case DataType::BINARY:
1378 case DataType::VARBINARY:
1379 DeactivateAggregate( tpDefault );
1380 DeactivateAggregate( tpRequired );
1381 DeactivateAggregate( tpTextLen );
1382 DeactivateAggregate( tpBoolDefault );
1384 ActivateAggregate( tpFormat );
1385 break;
1386 case DataType::LONGVARBINARY:
1387 case DataType::SQLNULL:
1388 case DataType::OBJECT:
1389 case DataType::DISTINCT:
1390 case DataType::STRUCT:
1391 case DataType::ARRAY:
1392 case DataType::BLOB:
1393 case DataType::CLOB:
1394 case DataType::REF:
1395 case DataType::OTHER:
1396 DeactivateAggregate( tpFormat );
1397 DeactivateAggregate( tpTextLen );
1398 DeactivateAggregate( tpBoolDefault );
1400 break;
1401 default:
1402 OSL_FAIL("Unknown type");
1404 m_pPreviousType = pFieldType;
1406 if(pFieldDescr)
1408 if(pFieldDescr->IsPrimaryKey())
1410 DeactivateAggregate( tpRequired );
1412 else if ( !pAutoIncrement && pFieldType.get() )
1414 if ( pFieldType->bNullable )
1415 ActivateAggregate( tpRequired );
1416 else
1417 DeactivateAggregate( tpRequired );
1420 //////////////////////////////////////////////////////////////////////
1421 // Initialize Controls
1422 if( pAutoIncrement )
1424 if ( pFieldDescr->IsAutoIncrement() )
1426 pAutoIncrement->SelectEntryPos( 0 ); // yes
1427 ActivateAggregate( tpAutoIncrementValue );
1428 if ( m_pAutoIncrementValue )
1429 m_pAutoIncrementValue->SetText(pFieldDescr->GetAutoIncrementValue());
1430 DeactivateAggregate( tpRequired );
1431 DeactivateAggregate( tpDefault );
1433 else
1435 // disable autoincrement value because it should only be visible when autoincrement is to true
1436 DeactivateAggregate( tpAutoIncrementValue );
1437 pAutoIncrement->SelectEntryPos( 1 ); // no
1438 ActivateAggregate( tpDefault );
1439 // Affects pRequired
1440 if(!pFieldDescr->IsPrimaryKey())
1441 ActivateAggregate( tpRequired );
1445 if( pDefault )
1447 pDefault->SetText( getControlDefault(pFieldDescr) );
1448 pDefault->ClearModifyFlag();
1451 if( pBoolDefault )
1453 // If pRequired = sal_True then the sal_Bool field must NOT contain <<none>>
1454 ::rtl::OUString sValue;
1455 pFieldDescr->GetControlDefault() >>= sValue;
1456 String sDef = BoolStringUI(sValue);
1458 // Make sure that <<none>> is only present if the field can be NULL
1459 if ( ( pFieldType.get() && !pFieldType->bNullable ) || !pFieldDescr->IsNullable() )
1461 pFieldDescr->SetIsNullable(ColumnValue::NO_NULLS); // The type says so
1463 pBoolDefault->RemoveEntry(String(ModuleRes(STR_VALUE_NONE)));
1464 if ( !sDef.Equals(aYes) && !sDef.Equals(aNo) )
1465 pBoolDefault->SelectEntryPos(1); // No as a default
1466 else
1467 pBoolDefault->SelectEntry(sDef);
1469 pFieldDescr->SetControlDefault(makeAny(::rtl::OUString(BoolStringPersistent(pBoolDefault->GetSelectEntry()))));
1471 else if(pBoolDefault->GetEntryCount() < 3)
1473 pBoolDefault->InsertEntry(String(ModuleRes(STR_VALUE_NONE)));
1474 pBoolDefault->SelectEntry(sDef);
1476 else
1477 pBoolDefault->SelectEntry(sDef);
1480 if( pRequired )
1482 if( pFieldDescr->IsNullable() )
1483 pRequired->SelectEntryPos( 1 ); // no
1484 else
1485 pRequired->SelectEntryPos( 0 ); // yes
1488 if( pTextLen )
1490 pTextLen->SetText( String::CreateFromInt32(pFieldDescr->GetPrecision()) );
1491 pTextLen->ClearModifyFlag();
1494 if( pNumType )
1496 OSL_FAIL("OFieldDescControl::DisplayData: invalid num type!");
1499 if( pLength )
1500 pLength->SetText( String::CreateFromInt32(pFieldDescr->GetPrecision()) );
1502 if( pScale )
1503 pScale->SetText( String::CreateFromInt32(pFieldDescr->GetScale()) );
1505 if( pFormat )
1506 UpdateFormatSample(pFieldDescr);
1508 if(m_pColumnName)
1509 m_pColumnName->SetText(pFieldDescr->GetName());
1511 if(m_pType)
1513 sal_uInt16 nPos = pFieldType.get() ? m_pType->GetEntryPos(String(pFieldDescr->getTypeInfo()->aUIName)) : LISTBOX_ENTRY_NOTFOUND;
1514 if(nPos == LISTBOX_ENTRY_NOTFOUND)
1516 const OTypeInfoMap* pMap = getTypeInfo();
1517 OTypeInfoMap::const_iterator aIter = pMap->find(pFieldType.get() ? pFieldDescr->getTypeInfo()->nType : pFieldDescr->GetType());
1518 if(aIter == pMap->end() && !pMap->empty())
1520 aIter = pMap->begin();
1521 if(pFieldDescr->GetPrecision() > aIter->second->nPrecision)
1522 pFieldDescr->SetPrecision(aIter->second->nPrecision);
1523 if(pFieldDescr->GetScale() > aIter->second->nMaximumScale)
1524 pFieldDescr->SetScale(0);
1525 if(!aIter->second->bNullable && pFieldDescr->IsNullable())
1526 pFieldDescr->SetIsNullable(ColumnValue::NO_NULLS);
1527 if(!aIter->second->bAutoIncrement && pFieldDescr->IsAutoIncrement())
1528 pFieldDescr->SetAutoIncrement(sal_False);
1530 if ( aIter != pMap->end() )
1532 pFieldDescr->SetType(aIter->second);
1535 m_pType->SelectEntry(pFieldDescr->getTypeInfo()->aUIName);
1539 //////////////////////////////////////////////////////////////////////
1540 // Enable/disable Controls
1541 sal_Bool bRead(IsReadOnly());
1544 ArrangeAggregates();
1545 CheckScrollBars();
1546 ScrollAllAggregates();
1548 SetReadOnly( bRead );
1551 //------------------------------------------------------------------------------
1552 IMPL_LINK(OFieldDescControl, OnControlFocusGot, Control*, pControl )
1554 String strHelpText;
1555 OPropNumericEditCtrl* pNumeric = dynamic_cast< OPropNumericEditCtrl* >( pControl );
1556 if ( pNumeric )
1558 pNumeric->SaveValue();
1559 strHelpText = pNumeric->GetHelp();
1562 OPropColumnEditCtrl* pColumn = dynamic_cast< OPropColumnEditCtrl* >( pControl );
1563 if ( pColumn )
1565 pColumn->SaveValue();
1566 strHelpText = pColumn->GetHelp();
1569 OPropEditCtrl* pEdit = dynamic_cast< OPropEditCtrl* >( pControl );
1570 if ( pEdit )
1572 pEdit->SaveValue();
1573 strHelpText = pEdit->GetHelp();
1576 OPropListBoxCtrl* pListBox = dynamic_cast< OPropListBoxCtrl* >( pControl );
1577 if ( pListBox )
1579 pListBox->SaveValue();
1580 strHelpText = pListBox->GetHelp();
1583 if (pControl == pFormat)
1584 strHelpText =String(ModuleRes(STR_HELP_FORMAT_BUTTON));
1586 if (strHelpText.Len() && (pHelp != NULL))
1587 pHelp->SetHelpText(strHelpText);
1589 m_pActFocusWindow = pControl;
1591 return 0L;
1594 //------------------------------------------------------------------------------
1595 IMPL_LINK(OFieldDescControl, OnControlFocusLost, Control*, pControl )
1597 if ((pControl == pLength) || (pControl == pTextLen) || (pControl == pScale))
1599 OPropNumericEditCtrl* pConverted = (OPropNumericEditCtrl*)pControl;
1600 if (pConverted->IsModified())
1601 CellModified(-1, pConverted->GetPos());
1603 if(pControl == m_pColumnName)
1605 OPropColumnEditCtrl* pConverted = (OPropColumnEditCtrl*)pControl;
1606 if (pConverted->IsModified())
1607 CellModified(-1, pConverted->GetPos());
1609 else if ((pControl == pDefault) || (pControl == pFormatSample) || (pControl == m_pAutoIncrementValue) )
1611 OPropEditCtrl* pConverted = (OPropEditCtrl*)pControl;
1612 if (pConverted->IsModified())
1613 CellModified(-1, pConverted->GetPos());
1615 else if ((pControl == pRequired) || (pControl == pNumType) || (pControl == pAutoIncrement) || (pControl == pBoolDefault) || (pControl == m_pType))
1617 OPropListBoxCtrl* pConverted = (OPropListBoxCtrl*)pControl;
1618 if (pConverted->IsModified())
1619 CellModified(-1, pConverted->GetPos());
1622 if (pControl == pDefault)
1623 UpdateFormatSample(pActFieldDescr);
1625 implFocusLost(pControl);
1627 return 0L;
1629 //------------------------------------------------------------------------------
1630 void OFieldDescControl::SaveData( OFieldDescription* pFieldDescr )
1632 DBG_CHKTHIS(OFieldDescControl,NULL);
1633 if( !pFieldDescr )
1634 return;
1636 //////////////////////////////////////////////////////////////////////
1637 // Read out Controls
1638 ::rtl::OUString sDefault;
1639 if (pDefault)
1641 sDefault = pDefault->GetText();
1643 else if (pBoolDefault)
1645 sDefault = BoolStringPersistent(pBoolDefault->GetSelectEntry());
1648 if ( !sDefault.isEmpty() )
1649 pFieldDescr->SetControlDefault(makeAny(sDefault));
1650 else
1651 pFieldDescr->SetControlDefault(Any());
1653 if((pRequired && pRequired->GetSelectEntryPos() == 0) || pFieldDescr->IsPrimaryKey() || (pBoolDefault && pBoolDefault->GetEntryCount() == 2)) // yes
1654 pFieldDescr->SetIsNullable( ColumnValue::NO_NULLS );
1655 else
1656 pFieldDescr->SetIsNullable( ColumnValue::NULLABLE );
1658 if ( pAutoIncrement )
1659 pFieldDescr->SetAutoIncrement( pAutoIncrement->GetSelectEntryPos() == 0 );
1661 if( pTextLen )
1662 pFieldDescr->SetPrecision( static_cast<sal_Int32>(pTextLen->GetValue()) );
1663 else if( pLength )
1664 pFieldDescr->SetPrecision( static_cast<sal_Int32>(pLength->GetValue()) );
1665 if( pScale )
1666 pFieldDescr->SetScale( static_cast<sal_Int32>(pScale->GetValue()) );
1668 if(m_pColumnName)
1669 pFieldDescr->SetName(m_pColumnName->GetText());
1671 if ( m_pAutoIncrementValue && isAutoIncrementValueEnabled() )
1672 pFieldDescr->SetAutoIncrementValue(m_pAutoIncrementValue->GetText());
1675 //------------------------------------------------------------------------------
1676 void OFieldDescControl::UpdateFormatSample(OFieldDescription* pFieldDescr)
1678 if ( pFieldDescr && pFormatSample )
1679 pFormatSample->SetText(getControlDefault(pFieldDescr,sal_False));
1682 //------------------------------------------------------------------------------
1683 void OFieldDescControl::GetFocus()
1685 DBG_CHKTHIS(OFieldDescControl,NULL);
1686 //////////////////////////////////////////////////////////////////////
1687 // Set the Focus to the Control that has been active last
1688 TabPage::GetFocus();
1689 if( pLastFocusWindow )
1691 pLastFocusWindow->GrabFocus();
1692 pLastFocusWindow = NULL;
1696 //------------------------------------------------------------------------------
1697 void OFieldDescControl::implFocusLost(Window* _pWhich)
1699 DBG_CHKTHIS(OFieldDescControl,NULL);
1700 OSL_ENSURE(!_pWhich || IsChild(_pWhich), "OFieldDescControl::implFocusLost : invalid window !");
1702 //////////////////////////////////////////////////////////////////////
1703 // Remember the active Control
1704 if (!pLastFocusWindow)
1705 pLastFocusWindow = _pWhich;
1707 //////////////////////////////////////////////////////////////////////
1708 // Reset HelpText
1709 if (pHelp && !pHelp->HasChildPathFocus())
1710 pHelp->SetHelpText( String() );
1713 //------------------------------------------------------------------------------
1714 void OFieldDescControl::LoseFocus()
1716 DBG_CHKTHIS(OFieldDescControl,NULL);
1718 implFocusLost(NULL);
1720 TabPage::LoseFocus();
1722 // -----------------------------------------------------------------------------
1723 sal_Bool OFieldDescControl::isCopyAllowed()
1725 sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
1726 (m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample ||
1727 m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength ||
1728 m_pActFocusWindow == pScale || m_pActFocusWindow == m_pColumnName ||
1729 m_pActFocusWindow == m_pAutoIncrementValue) &&
1730 static_cast<Edit*>(m_pActFocusWindow)->GetSelected().Len() != 0;
1732 return bAllowed;
1734 // -----------------------------------------------------------------------------
1735 sal_Bool OFieldDescControl::isCutAllowed()
1737 sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
1738 (m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample ||
1739 m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength ||
1740 m_pActFocusWindow == pScale || m_pActFocusWindow == m_pColumnName ||
1741 m_pActFocusWindow == m_pAutoIncrementValue) &&
1742 static_cast<Edit*>(m_pActFocusWindow)->GetSelected().Len() != 0;
1743 return bAllowed;
1745 // -----------------------------------------------------------------------------
1746 sal_Bool OFieldDescControl::isPasteAllowed()
1748 sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
1749 (m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample ||
1750 m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength ||
1751 m_pActFocusWindow == pScale || m_pActFocusWindow == m_pColumnName ||
1752 m_pActFocusWindow == m_pAutoIncrementValue);
1753 if ( bAllowed )
1755 TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
1756 bAllowed = aTransferData.HasFormat(SOT_FORMAT_STRING);
1758 return bAllowed;
1760 // -----------------------------------------------------------------------------
1761 void OFieldDescControl::cut()
1763 if(isCutAllowed())
1764 static_cast<Edit*>(m_pActFocusWindow)->Cut();
1766 // -----------------------------------------------------------------------------
1767 void OFieldDescControl::copy()
1769 if(isCopyAllowed()) // this only checks if the focus window is valid
1770 static_cast<Edit*>(m_pActFocusWindow)->Copy();
1772 // -----------------------------------------------------------------------------
1773 void OFieldDescControl::paste()
1775 if(m_pActFocusWindow) // this only checks if the focus window is valid
1776 static_cast<Edit*>(m_pActFocusWindow)->Paste();
1778 // -----------------------------------------------------------------------------
1779 sal_Bool OFieldDescControl::isTextFormat(const OFieldDescription* _pFieldDescr,sal_uInt32& _nFormatKey) const
1781 _nFormatKey = _pFieldDescr->GetFormatKey();
1782 sal_Bool bTextFormat = sal_True;
1786 if (!_nFormatKey)
1788 Reference< ::com::sun::star::util::XNumberFormatTypes> xNumberTypes(GetFormatter()->getNumberFormatsSupplier()->getNumberFormats(),UNO_QUERY);
1789 OSL_ENSURE(xNumberTypes.is(),"XNumberFormatTypes is null!");
1791 _nFormatKey = ::dbtools::getDefaultNumberFormat( _pFieldDescr->GetType(),
1792 _pFieldDescr->GetScale(),
1793 _pFieldDescr->IsCurrency(),
1794 xNumberTypes,
1795 GetLocale());
1797 sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(GetFormatter(),_nFormatKey);
1798 bTextFormat = (nNumberFormat == ::com::sun::star::util::NumberFormat::TEXT);
1800 catch(const Exception&)
1805 return bTextFormat;
1807 // -----------------------------------------------------------------------------
1808 String OFieldDescControl::getControlDefault( const OFieldDescription* _pFieldDescr ,sal_Bool _bCheck) const
1810 ::rtl::OUString sDefault;
1811 sal_Bool bCheck = !_bCheck || _pFieldDescr->GetControlDefault().hasValue();
1812 if ( bCheck )
1814 sal_uInt32 nFormatKey;
1815 sal_Bool bTextFormat = sal_False;
1816 double nValue = 0.0;
1820 bTextFormat = isTextFormat(_pFieldDescr,nFormatKey);
1821 if ( _pFieldDescr->GetControlDefault() >>= sDefault )
1823 if ( !bTextFormat )
1825 if ( !sDefault.isEmpty() )
1829 nValue = GetFormatter()->convertStringToNumber(nFormatKey,sDefault);
1831 catch(const Exception&)
1833 return ::rtl::OUString(); // return empty string for format example
1838 else
1839 _pFieldDescr->GetControlDefault() >>= nValue;
1842 Reference< ::com::sun::star::util::XNumberFormatter> xNumberFormatter = GetFormatter();
1843 Reference<XPropertySet> xFormSet = xNumberFormatter->getNumberFormatsSupplier()->getNumberFormats()->getByKey(nFormatKey);
1844 OSL_ENSURE(xFormSet.is(),"XPropertySet is null!");
1845 ::rtl::OUString sFormat;
1846 xFormSet->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FormatString"))) >>= sFormat;
1848 if ( !bTextFormat )
1850 Locale aLocale;
1851 ::comphelper::getNumberFormatProperty(xNumberFormatter,nFormatKey,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Locale"))) >>= aLocale;
1853 sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(xNumberFormatter,nFormatKey);
1854 if( (nNumberFormat & ::com::sun::star::util::NumberFormat::DATE) == ::com::sun::star::util::NumberFormat::DATE
1855 || (nNumberFormat & ::com::sun::star::util::NumberFormat::DATETIME) == ::com::sun::star::util::NumberFormat::DATETIME )
1857 nValue = DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter->getNumberFormatsSupplier()),nValue);
1862 Reference< ::com::sun::star::util::XNumberFormatPreviewer> xPreViewer(xNumberFormatter,UNO_QUERY);
1863 OSL_ENSURE(xPreViewer.is(),"XNumberFormatPreviewer is null!");
1864 sDefault = xPreViewer->convertNumberToPreviewString(sFormat,nValue,aLocale,sal_True);
1866 else if ( !(_bCheck && sDefault.isEmpty()) )
1867 sDefault = xNumberFormatter->formatString(nFormatKey, sDefault.isEmpty() ? sFormat : sDefault);
1869 catch(const Exception&)
1875 return sDefault;
1877 // -----------------------------------------------------------------------------
1879 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */