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>
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"
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
95 template< typename T1
, typename T2
> void lcl_HideAndDeleteControl(short& _nPos
,T1
** _pControl
,T2
** _pControlText
)
100 (*_pControl
)->Hide();
101 (*_pControlText
)->Hide();
103 delete *_pControlText
;
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
)
121 ,pLastFocusWindow(NULL
)
122 ,m_pActFocusWindow(NULL
)
125 ,pAutoIncrementText(NULL
)
131 ,pBoolDefaultText(NULL
)
132 ,m_pColumnNameText(NULL
)
134 ,m_pAutoIncrementValueText(NULL
)
137 ,pAutoIncrement(NULL
)
146 ,m_pAutoIncrementValue(NULL
)
148 ,m_pVertScroll( NULL
)
149 ,m_pHorzScroll( NULL
)
153 ,aYes(ModuleRes(STR_VALUE_YES
))
154 ,aNo(ModuleRes(STR_VALUE_NO
))
159 ,m_bRightAligned(false)
160 ,pActFieldDescr(NULL
)
162 DBG_CTOR(OFieldDescControl
,NULL
);
166 //------------------------------------------------------------------------------
167 OFieldDescControl::OFieldDescControl( Window
* pParent
, OTableDesignHelpBar
* pHelpBar
)
168 :TabPage( pParent
, WB_3DLOOK
| WB_DIALOGCONTROL
)
170 ,pLastFocusWindow(NULL
)
171 ,m_pActFocusWindow(NULL
)
174 ,pAutoIncrementText(NULL
)
180 ,pBoolDefaultText(NULL
)
181 ,m_pColumnNameText(NULL
)
183 ,m_pAutoIncrementValueText(NULL
)
186 ,pAutoIncrement(NULL
)
195 ,m_pAutoIncrementValue(NULL
)
197 ,m_pVertScroll( NULL
)
198 ,m_pHorzScroll( NULL
)
202 ,aYes(ModuleRes(STR_VALUE_YES
))
203 ,aNo(ModuleRes(STR_VALUE_NO
))
208 ,m_bRightAligned(false)
209 ,pActFieldDescr(NULL
)
211 DBG_CTOR(OFieldDescControl
,NULL
);
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
;
253 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
254 pLastFocusWindow
= NULL
;
256 //////////////////////////////////////////////////////////////////////
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
)
280 if (rUIString
== aYes
)
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
)
298 if (rPersistentString
== aOne
)
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();
317 // -----------------------------------------------------------------------------
320 void getMaxXPosition(Window
* _pWindow
,long& _rnMaxXPosition
)
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
);
343 // Do I actually need ScrollBars?
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
);
351 lMaxXPosition
+= m_pHorzScroll
->GetThumbPos() * HSCROLL_STEP
;
353 long lMaxXAvailable
= szOverallSize
.Width();
354 bNeedHScrollBar
= lMaxXPosition
> lMaxXAvailable
;
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();
365 nLastVisible
= static_cast<sal_uInt16
>((szOverallSize
.Height() - nControl_Spacing_y
- nHScrollHeight
) / (nControl_Spacing_y
+ nControlHeight
));
367 nLastVisible
= static_cast<sal_uInt16
>((szOverallSize
.Height() - nControl_Spacing_y
) / (nControl_Spacing_y
+ nControlHeight
));
368 bNeedVScrollBar
= nActive
>nLastVisible
;
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
387 m_pVertScroll
->Show();
388 m_pVertScroll
->SetRangeMax(nActive
- nLastVisible
);
390 m_pVertScroll
->SetPosSizePixel( Point(nNewHWidth
, 0), Size(nVScrollWidth
, szOverallSize
.Height()) );
394 m_pVertScroll
->Hide();
395 m_pVertScroll
->SetRangeMax(0);
396 m_pVertScroll
->SetThumbPos(0);
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
) );
408 m_pHorzScroll
->Hide();
409 m_pHorzScroll
->SetRangeMax(0);
410 m_pHorzScroll
->SetThumbPos(0);
414 //------------------------------------------------------------------------------
415 void OFieldDescControl::Resize()
418 ScrollAllAggregates();
421 //------------------------------------------------------------------------------
422 inline void OFieldDescControl::ScrollAggregate(Control
* pText
, Control
* pInput
, Control
* pButton
, long nDeltaX
, long nDeltaY
)
426 pText
->SetPosPixel(pText
->GetPosPixel() + Point(nDeltaX
, nDeltaY
));
427 pInput
->SetPosPixel(pInput
->GetPosPixel() + Point(nDeltaX
, nDeltaY
));
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
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
)
478 ++nVisibleAggregates
;
479 return nVisibleAggregates
;
481 //------------------------------------------------------------------------------
482 sal_Int32
OFieldDescControl::GetMaxControlHeight() const
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
507 , pScale
, m_pColumnName
508 , m_pType
, m_pAutoIncrementValue
510 Control
* ppAggregatesText
[] = { pRequiredText
, pNumTypeText
511 , pAutoIncrementText
, pDefaultText
512 , pTextLenText
, pLengthText
513 , pScaleText
, m_pColumnNameText
514 , m_pTypeText
, m_pAutoIncrementValueText
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
536 case FIELD_PROPERTY_BOOL_DEFAULT
:
538 return pBoolDefault
->GetSelectEntry();
540 case FIELD_PROPERTY_DEFAULT
:
542 return pDefault
->GetText();
544 case FIELD_PROPERTY_REQUIRED
:
546 return pRequired
->GetSelectEntry();
548 case FIELD_PROPERTY_TEXTLEN
:
550 return rtl::OUString::valueOf(static_cast<sal_Int64
>(pTextLen
->GetValue()));
551 case FIELD_PROPERTY_NUMTYPE
:
553 return pNumType
->GetSelectEntry();
555 case FIELD_PROPERTY_AUTOINC
:
557 return pAutoIncrement
->GetSelectEntry();
559 case FIELD_PROPERTY_LENGTH
:
561 return pLength
->GetText();
563 case FIELD_PROPERTY_SCALE
:
565 return pScale
->GetText();
567 case FIELD_PROPERTY_FORMAT
:
569 return pFormatSample
->GetText();
571 case FIELD_PRPOERTY_COLUMNNAME
:
573 return m_pColumnName
->GetText();
574 case FIELD_PRPOERTY_TYPE
:
576 return m_pType
->GetSelectEntry();
578 case FIELD_PRPOERTY_AUTOINCREMENT
:
579 if(m_pAutoIncrementValue
)
580 return m_pAutoIncrementValue
->GetText();
586 //------------------------------------------------------------------------------
587 void OFieldDescControl::SetControlText( sal_uInt16 nControlId
, const String
& rText
)
589 DBG_CHKTHIS(OFieldDescControl
,NULL
);
590 //////////////////////////////////////////////////////////////////////
591 // Set the Controls' texts
594 case FIELD_PROPERTY_BOOL_DEFAULT
:
597 String sOld
= pBoolDefault
->GetSelectEntry();
598 pBoolDefault
->SelectEntry(rText
);
599 if (!sOld
.Equals(rText
))
600 LINK(this, OFieldDescControl
, ChangeHdl
).Call(pBoolDefault
);
603 case FIELD_PROPERTY_DEFAULT
:
606 pDefault
->SetText(rText
);
607 UpdateFormatSample(pActFieldDescr
);
611 case FIELD_PROPERTY_REQUIRED
:
613 pRequired
->SelectEntry(rText
);
617 case FIELD_PROPERTY_TEXTLEN
:
619 pTextLen
->SetText(rText
);
622 case FIELD_PROPERTY_NUMTYPE
:
624 pNumType
->SelectEntry(rText
);
627 case FIELD_PROPERTY_AUTOINC
:
630 String sOld
= pAutoIncrement
->GetSelectEntry();
631 pAutoIncrement
->SelectEntry(rText
);
632 if (!sOld
.Equals(rText
))
633 LINK(this, OFieldDescControl
, ChangeHdl
).Call(pAutoIncrement
);
637 case FIELD_PROPERTY_LENGTH
:
639 pLength
->SetText(rText
);
642 case FIELD_PROPERTY_SCALE
:
644 pScale
->SetText(rText
);
647 case FIELD_PROPERTY_FORMAT
:
649 UpdateFormatSample(pActFieldDescr
);
651 case FIELD_PRPOERTY_COLUMNNAME
:
653 m_pColumnName
->SetText(rText
);
655 case FIELD_PRPOERTY_TYPE
:
657 m_pType
->SelectEntry(rText
);
659 case FIELD_PRPOERTY_AUTOINCREMENT
:
660 if(m_pAutoIncrementValue
)
661 m_pAutoIncrementValue
->SetText(rText
);
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
)
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();
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
;
698 SetModified(sal_True
);
699 UpdateFormatSample(pActFieldDescr
);
705 // -----------------------------------------------------------------------
706 void OFieldDescControl::SetModified(sal_Bool
/*bModified*/)
709 //------------------------------------------------------------------------
710 IMPL_LINK( OFieldDescControl
, ChangeHdl
, ListBox
*, pListBox
)
712 DBG_CHKTHIS(OFieldDescControl
,NULL
);
713 if ( !pActFieldDescr
)
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
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)
745 DeactivateAggregate( tpAutoIncrementValue
);
746 if(pActFieldDescr
->IsPrimaryKey())
747 DeactivateAggregate( tpRequired
);
748 else if( pActFieldDescr
->getTypeInfo()->bNullable
)
750 ActivateAggregate( tpRequired
);
753 if( pActFieldDescr
->IsNullable() )
754 pRequired
->SelectEntryPos( 1 ); // no
756 pRequired
->SelectEntryPos( 0 ); // yes
759 ActivateAggregate( tpDefault
);
763 DeactivateAggregate( tpRequired
);
764 DeactivateAggregate( tpDefault
);
765 ActivateAggregate( tpAutoIncrementValue
);
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());
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 },
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!");
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
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 //////////////////////////////////////////////////////////////////////
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);
875 case tpAutoIncrementValue
:
876 if( m_pAutoIncrementValue
|| !isAutoIncrementValueEnabled() )
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);
889 Reference
< XDatabaseMetaData
> xMetaData
= getMetaData();
891 if(xMetaData
.is() && xMetaData
->supportsNonNullableColumns())
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);
905 case tpAutoIncrement
:
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);
922 pTextLenText
= CreateText(STR_TEXT_LENGTH
);
923 pTextLen
= CreateNumericControl(STR_HELP_TEXT_LENGTH
, FIELD_PROPERTY_TEXTLEN
,HID_TAB_ENT_TEXT_LEN
);
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);
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();
961 DBG_UNHANDLED_EXCEPTION();
963 m_pColumnNameText
= CreateText(STR_TAB_FIELD_NAME
);
964 m_pColumnName
= new OPropColumnEditCtrl( this,
966 STR_HELP_DEFAULT_VALUE
,
967 FIELD_PRPOERTY_COLUMNNAME
,
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);
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);
997 pLengthText
= CreateText(STR_LENGTH
);
998 pLength
= CreateNumericControl(STR_HELP_LENGTH
, FIELD_PROPERTY_LENGTH
,HID_TAB_ENT_LEN
);
1005 pScaleText
= CreateText(STR_SCALE
);
1006 pScale
= CreateNumericControl(STR_HELP_SCALE
, FIELD_PROPERTY_SCALE
,HID_TAB_ENT_SCALE
);
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
);
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);
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();
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);
1077 //------------------------------------------------------------------------------
1078 void OFieldDescControl::DeactivateAggregate( EControlType eType
)
1080 DBG_CHKTHIS(OFieldDescControl
,NULL
);
1081 pLastFocusWindow
= NULL
;
1082 //////////////////////////////////////////////////////////////////////
1087 lcl_HideAndDeleteControl(m_nPos
,&pDefault
,&pDefaultText
);
1090 case tpAutoIncrementValue
:
1091 lcl_HideAndDeleteControl(m_nPos
,&m_pAutoIncrementValue
,&m_pAutoIncrementValueText
);
1095 lcl_HideAndDeleteControl(m_nPos
,&m_pColumnName
,&m_pColumnNameText
);
1099 lcl_HideAndDeleteControl(m_nPos
,&m_pType
,&m_pTypeText
);
1102 case tpAutoIncrement
:
1103 lcl_HideAndDeleteControl(m_nPos
,&pAutoIncrement
,&pAutoIncrementText
);
1107 lcl_HideAndDeleteControl(m_nPos
,&pRequired
,&pRequiredText
);
1111 lcl_HideAndDeleteControl(m_nPos
,&pTextLen
,&pTextLenText
);
1115 lcl_HideAndDeleteControl(m_nPos
,&pNumType
,&pNumTypeText
);
1119 lcl_HideAndDeleteControl(m_nPos
,&pLength
,&pLengthText
);
1123 lcl_HideAndDeleteControl(m_nPos
,&pScale
,&pScaleText
);
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
;
1137 lcl_HideAndDeleteControl(m_nPos
,&pBoolDefault
,&pBoolDefaultText
);
1142 //------------------------------------------------------------------------------
1143 void OFieldDescControl::SetPosSize( Control
** ppControl
, long nRow
, sal_uInt16 nCol
)
1145 DBG_CHKTHIS(OFieldDescControl
,NULL
);
1147 //////////////////////////////////////////////////////////////////////
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();
1159 aSize
.Width() = CONTROL_WIDTH_1
;
1162 aSize
.Width() = CONTROL_WIDTH_2
;
1165 aSize
.Width() = CONTROL_WIDTH_3
;
1168 aSize
.Width() = CONTROL_WIDTH_4
;
1174 //////////////////////////////////////////////////////////////////////
1175 // Calculate Position
1186 if ( isRightAligned() )
1188 Size aOwnSize
= GetSizePixel();
1189 aPosition
.X() = aOwnSize
.Width() - aSize
.Width();
1192 aPosition
.X() = CONTROL_WIDTH_1
+ CONTROL_SPACING_X
;
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 //////////////////////////////////////////////////////////////////////
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
;
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
;
1237 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
1238 m_bAdded
= sal_False
;
1245 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::AddWindow
));
1246 m_bAdded
= sal_True
;
1249 TOTypeInfoSP pFieldType
;
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
);
1276 DeactivateAggregate( tpRequired
);
1278 // 2. the autoincrement
1279 if ( pFieldType
->bAutoIncrement
)
1281 DeactivateAggregate( tpRequired
);
1282 DeactivateAggregate( tpDefault
);
1283 ActivateAggregate( tpAutoIncrement
);
1284 ActivateAggregate( tpAutoIncrementValue
);
1288 DeactivateAggregate( tpAutoIncrement
);
1289 DeactivateAggregate( tpAutoIncrementValue
);
1290 if(pFieldType
->bNullable
)
1291 ActivateAggregate( tpRequired
);
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());
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
);
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());
1335 DeactivateAggregate( tpTextLen
);
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
);
1348 if ( !pFieldType
->aCreateParams
.isEmpty() )
1350 DeactivateAggregate( tpFormat
);
1351 DeactivateAggregate( tpTextLen
);
1352 DeactivateAggregate( tpBoolDefault
);
1356 case DataType::BOOLEAN
:
1357 DeactivateAggregate( tpTextLen
);
1358 DeactivateAggregate( tpFormat
);
1359 DeactivateAggregate( tpDefault
);
1361 ActivateAggregate( tpBoolDefault
);
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
);
1377 case DataType::BINARY
:
1378 case DataType::VARBINARY
:
1379 DeactivateAggregate( tpDefault
);
1380 DeactivateAggregate( tpRequired
);
1381 DeactivateAggregate( tpTextLen
);
1382 DeactivateAggregate( tpBoolDefault
);
1384 ActivateAggregate( tpFormat
);
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
:
1395 case DataType::OTHER
:
1396 DeactivateAggregate( tpFormat
);
1397 DeactivateAggregate( tpTextLen
);
1398 DeactivateAggregate( tpBoolDefault
);
1402 OSL_FAIL("Unknown type");
1404 m_pPreviousType
= pFieldType
;
1408 if(pFieldDescr
->IsPrimaryKey())
1410 DeactivateAggregate( tpRequired
);
1412 else if ( !pAutoIncrement
&& pFieldType
.get() )
1414 if ( pFieldType
->bNullable
)
1415 ActivateAggregate( tpRequired
);
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
);
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
);
1447 pDefault
->SetText( getControlDefault(pFieldDescr
) );
1448 pDefault
->ClearModifyFlag();
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
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
);
1477 pBoolDefault
->SelectEntry(sDef
);
1482 if( pFieldDescr
->IsNullable() )
1483 pRequired
->SelectEntryPos( 1 ); // no
1485 pRequired
->SelectEntryPos( 0 ); // yes
1490 pTextLen
->SetText( String::CreateFromInt32(pFieldDescr
->GetPrecision()) );
1491 pTextLen
->ClearModifyFlag();
1496 OSL_FAIL("OFieldDescControl::DisplayData: invalid num type!");
1500 pLength
->SetText( String::CreateFromInt32(pFieldDescr
->GetPrecision()) );
1503 pScale
->SetText( String::CreateFromInt32(pFieldDescr
->GetScale()) );
1506 UpdateFormatSample(pFieldDescr
);
1509 m_pColumnName
->SetText(pFieldDescr
->GetName());
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();
1546 ScrollAllAggregates();
1548 SetReadOnly( bRead
);
1551 //------------------------------------------------------------------------------
1552 IMPL_LINK(OFieldDescControl
, OnControlFocusGot
, Control
*, pControl
)
1555 OPropNumericEditCtrl
* pNumeric
= dynamic_cast< OPropNumericEditCtrl
* >( pControl
);
1558 pNumeric
->SaveValue();
1559 strHelpText
= pNumeric
->GetHelp();
1562 OPropColumnEditCtrl
* pColumn
= dynamic_cast< OPropColumnEditCtrl
* >( pControl
);
1565 pColumn
->SaveValue();
1566 strHelpText
= pColumn
->GetHelp();
1569 OPropEditCtrl
* pEdit
= dynamic_cast< OPropEditCtrl
* >( pControl
);
1573 strHelpText
= pEdit
->GetHelp();
1576 OPropListBoxCtrl
* pListBox
= dynamic_cast< OPropListBoxCtrl
* >( pControl
);
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
;
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
);
1629 //------------------------------------------------------------------------------
1630 void OFieldDescControl::SaveData( OFieldDescription
* pFieldDescr
)
1632 DBG_CHKTHIS(OFieldDescControl
,NULL
);
1636 //////////////////////////////////////////////////////////////////////
1637 // Read out Controls
1638 ::rtl::OUString sDefault
;
1641 sDefault
= pDefault
->GetText();
1643 else if (pBoolDefault
)
1645 sDefault
= BoolStringPersistent(pBoolDefault
->GetSelectEntry());
1648 if ( !sDefault
.isEmpty() )
1649 pFieldDescr
->SetControlDefault(makeAny(sDefault
));
1651 pFieldDescr
->SetControlDefault(Any());
1653 if((pRequired
&& pRequired
->GetSelectEntryPos() == 0) || pFieldDescr
->IsPrimaryKey() || (pBoolDefault
&& pBoolDefault
->GetEntryCount() == 2)) // yes
1654 pFieldDescr
->SetIsNullable( ColumnValue::NO_NULLS
);
1656 pFieldDescr
->SetIsNullable( ColumnValue::NULLABLE
);
1658 if ( pAutoIncrement
)
1659 pFieldDescr
->SetAutoIncrement( pAutoIncrement
->GetSelectEntryPos() == 0 );
1662 pFieldDescr
->SetPrecision( static_cast<sal_Int32
>(pTextLen
->GetValue()) );
1664 pFieldDescr
->SetPrecision( static_cast<sal_Int32
>(pLength
->GetValue()) );
1666 pFieldDescr
->SetScale( static_cast<sal_Int32
>(pScale
->GetValue()) );
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 //////////////////////////////////////////////////////////////////////
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;
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;
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
);
1755 TransferableDataHelper
aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
1756 bAllowed
= aTransferData
.HasFormat(SOT_FORMAT_STRING
);
1760 // -----------------------------------------------------------------------------
1761 void OFieldDescControl::cut()
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
;
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(),
1797 sal_Int32 nNumberFormat
= ::comphelper::getNumberFormatType(GetFormatter(),_nFormatKey
);
1798 bTextFormat
= (nNumberFormat
== ::com::sun::star::util::NumberFormat::TEXT
);
1800 catch(const Exception
&)
1807 // -----------------------------------------------------------------------------
1808 String
OFieldDescControl::getControlDefault( const OFieldDescription
* _pFieldDescr
,sal_Bool _bCheck
) const
1810 ::rtl::OUString sDefault
;
1811 sal_Bool bCheck
= !_bCheck
|| _pFieldDescr
->GetControlDefault().hasValue();
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
)
1825 if ( !sDefault
.isEmpty() )
1829 nValue
= GetFormatter()->convertStringToNumber(nFormatKey
,sDefault
);
1831 catch(const Exception
&)
1833 return ::rtl::OUString(); // return empty string for format example
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
;
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
&)
1877 // -----------------------------------------------------------------------------
1879 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */