1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "FieldDescControl.hxx"
21 #include "FieldControls.hxx"
22 #include <tools/diagnose_ex.h>
23 #include "TableDesignHelpBar.hxx"
24 #include <vcl/scrbar.hxx>
25 #include <vcl/button.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/fixed.hxx>
28 #include <vcl/msgbox.hxx>
30 #include "FieldDescriptions.hxx"
31 #include "dlgattr.hxx"
32 #include <svx/numfmtsh.hxx>
33 #include <svx/svxids.hrc>
34 #include <svx/algitem.hxx>
35 #include <svl/itempool.hxx>
36 #include <svl/zforlist.hxx>
37 #include <svl/rngitem.hxx>
38 #include <svl/intitem.hxx>
39 #include <svl/numuno.hxx>
40 #include <svtools/transfer.hxx>
41 #include <com/sun/star/lang/XUnoTunnel.hpp>
42 #include <com/sun/star/util/NumberFormat.hpp>
43 #include <com/sun/star/util/XNumberFormatPreviewer.hpp>
44 #include <com/sun/star/util/XNumberFormatTypes.hpp>
45 #include <com/sun/star/beans/XPropertySet.hpp>
46 #include "QEnumTypes.hxx"
47 #include "dbaccess_helpid.hrc"
48 #include <connectivity/dbtools.hxx>
49 #include <connectivity/dbconversion.hxx>
50 #include <comphelper/numbers.hxx>
51 #include <comphelper/string.hxx>
52 #include "UITools.hxx"
53 #include <boost/scoped_ptr.hpp>
54 #include "dbu_control.hrc"
55 #include "dbu_tbl.hrc"
56 #include <osl/diagnose.h>
58 using namespace dbaui
;
59 using namespace dbtools
;
60 using namespace ::com::sun::star::uno
;
61 using namespace ::com::sun::star::beans
;
62 using namespace ::com::sun::star::lang
;
63 using namespace ::com::sun::star::sdbc
;
64 using namespace ::com::sun::star::util
;
66 // For the Controls on the OFieldDescGenPage
67 #define CONTROL_SPACING_X 18 // 6
68 #define CONTROL_SPACING_Y 4
69 #define CONTROL_WIDTH_1 160 // 100
70 #define CONTROL_WIDTH_2 100 // 60
71 #define CONTROL_WIDTH_3 250
72 #define CONTROL_WIDTH_4 (CONTROL_WIDTH_3 - 20 - 5)
74 #define HSCROLL_STEP 20
79 template< typename T1
, typename T2
> void lcl_HideAndDeleteControl(short& _nPos
,VclPtr
<T1
>& _pControl
, VclPtr
<T2
>& _pControlText
)
85 _pControlText
->Hide();
86 _pControl
.disposeAndClear();
87 _pControlText
.disposeAndClear();
93 // class OFieldDescControl
94 OFieldDescControl::OFieldDescControl( vcl::Window
* pParent
, OTableDesignHelpBar
* pHelpBar
)
95 :TabPage( pParent
, WB_3DLOOK
| WB_DIALOGCONTROL
)
97 ,pLastFocusWindow(NULL
)
98 ,m_pActFocusWindow(NULL
)
101 ,pAutoIncrementText(NULL
)
107 ,pBoolDefaultText(NULL
)
108 ,m_pColumnNameText(NULL
)
110 ,m_pAutoIncrementValueText(NULL
)
113 ,pAutoIncrement(NULL
)
122 ,m_pAutoIncrementValue(NULL
)
124 ,m_pVertScroll( NULL
)
125 ,m_pHorzScroll( NULL
)
128 ,aYes(ModuleRes(STR_VALUE_YES
))
129 ,aNo(ModuleRes(STR_VALUE_NO
))
134 ,m_bRightAligned(false)
135 ,pActFieldDescr(NULL
)
140 void OFieldDescControl::Contruct()
142 m_pVertScroll
= VclPtr
<ScrollBar
>::Create(this, WB_VSCROLL
| WB_REPEAT
| WB_DRAG
);
143 m_pHorzScroll
= VclPtr
<ScrollBar
>::Create(this, WB_HSCROLL
| WB_REPEAT
| WB_DRAG
);
144 m_pVertScroll
->SetScrollHdl(LINK(this, OFieldDescControl
, OnScroll
));
145 m_pHorzScroll
->SetScrollHdl(LINK(this, OFieldDescControl
, OnScroll
));
146 m_pVertScroll
->Show();
147 m_pHorzScroll
->Show();
149 m_pVertScroll
->EnableClipSiblings();
150 m_pHorzScroll
->EnableClipSiblings();
152 m_pVertScroll
->SetLineSize(1);
153 m_pVertScroll
->SetPageSize(1);
154 m_pHorzScroll
->SetLineSize(1);
155 m_pHorzScroll
->SetPageSize(1);
157 m_nOldVThumb
= m_nOldHThumb
= 0;
160 OFieldDescControl::~OFieldDescControl()
165 void OFieldDescControl::dispose()
168 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
171 DeactivateAggregate( tpDefault
);
172 DeactivateAggregate( tpRequired
);
173 DeactivateAggregate( tpTextLen
);
174 DeactivateAggregate( tpNumType
);
175 DeactivateAggregate( tpScale
);
176 DeactivateAggregate( tpLength
);
177 DeactivateAggregate( tpFormat
);
178 DeactivateAggregate( tpAutoIncrement
);
179 DeactivateAggregate( tpBoolDefault
);
180 DeactivateAggregate( tpColumnName
);
181 DeactivateAggregate( tpType
);
182 DeactivateAggregate( tpAutoIncrementValue
);
184 pLastFocusWindow
.clear();
185 m_pActFocusWindow
.clear();
186 pDefaultText
.clear();
187 pRequiredText
.clear();
188 pAutoIncrementText
.clear();
189 pTextLenText
.clear();
190 pNumTypeText
.clear();
194 pBoolDefaultText
.clear();
195 m_pColumnNameText
.clear();
197 m_pAutoIncrementValueText
.clear();
200 pAutoIncrement
.clear();
205 pFormatSample
.clear();
206 pBoolDefault
.clear();
207 m_pColumnName
.clear();
209 m_pAutoIncrementValue
.clear();
211 m_pVertScroll
.disposeAndClear();
212 m_pHorzScroll
.disposeAndClear();
216 OUString
OFieldDescControl::BoolStringPersistent(const OUString
& rUIString
) const
218 if (rUIString
== aNo
)
219 return OUString('0');
220 if (rUIString
== aYes
)
221 return OUString('1');
225 OUString
OFieldDescControl::BoolStringUI(const OUString
& rPersistentString
) const
227 // Older versions may store a language dependent string as a default
228 if (rPersistentString
== aYes
|| rPersistentString
== aNo
)
229 return rPersistentString
;
231 if (comphelper::string::equals(rPersistentString
, '0'))
233 if (comphelper::string::equals(rPersistentString
, '1'))
236 return ModuleRes(STR_VALUE_NONE
).toString();
239 void OFieldDescControl::Init()
241 Reference
< ::com::sun::star::util::XNumberFormatter
> xFormatter
= GetFormatter();
242 ::dbaui::setEvalDateFormatForFormatter(xFormatter
);
245 IMPL_LINK(OFieldDescControl
, OnScroll
, ScrollBar
*, /*pBar*/)
247 ScrollAllAggregates();
253 void getMaxXPosition(vcl::Window
* _pWindow
,long& _rnMaxXPosition
)
257 long nTemp
= _pWindow
->GetSizePixel().Width() + _pWindow
->GetPosPixel().X();
258 _rnMaxXPosition
= ::std::max(_rnMaxXPosition
, nTemp
);
263 void OFieldDescControl::CheckScrollBars()
265 // Calculate the ScrollBars' new position
266 Size szOverallSize
= GetSizePixel();
267 long nHScrollHeight
= m_pHorzScroll
->GetSizePixel().Height();
268 long nVScrollWidth
= m_pVertScroll
->GetSizePixel().Width();
270 long nNewHWidth
= szOverallSize
.Width() - nVScrollWidth
;
271 long nNewVHeight
= szOverallSize
.Height() - nHScrollHeight
;
273 bool bNeedHScrollBar(false), bNeedVScrollBar(false);
276 // Do I actually need ScrollBars?
278 long lMaxXPosition
= 0;
279 Control
* ppAggregates
[] = { pRequired
, pNumType
, pAutoIncrement
, pDefault
, pTextLen
, pLength
, pScale
, pFormat
, m_pColumnName
, m_pType
,m_pAutoIncrementValue
};
280 for (sal_uInt16 i
=0; i
<sizeof(ppAggregates
)/sizeof(ppAggregates
[0]); ++i
)
281 getMaxXPosition(ppAggregates
[i
],lMaxXPosition
);
283 lMaxXPosition
+= m_pHorzScroll
->GetThumbPos() * HSCROLL_STEP
;
285 long lMaxXAvailable
= szOverallSize
.Width();
286 bNeedHScrollBar
= lMaxXPosition
> lMaxXAvailable
;
290 // How many Controls do I have?
291 sal_uInt16 nActive
= CountActiveAggregates();
292 // Which one is the last one that fits?
293 sal_uInt16 nLastVisible
;
294 const sal_Int32 nControlHeight
= GetMaxControlHeight();
295 const sal_Int32 nControl_Spacing_y
= LogicToPixel(Size(0, CONTROL_SPACING_Y
),MAP_APPFONT
).Height();
297 nLastVisible
= static_cast<sal_uInt16
>((szOverallSize
.Height() - nControl_Spacing_y
- nHScrollHeight
) / (nControl_Spacing_y
+ nControlHeight
));
299 nLastVisible
= static_cast<sal_uInt16
>((szOverallSize
.Height() - nControl_Spacing_y
) / (nControl_Spacing_y
+ nControlHeight
));
300 bNeedVScrollBar
= nActive
>nLastVisible
;
304 // When originally calculating lMaxXAvailable we did not take into account that we have a VScrollBar, so we need to do that now
305 lMaxXAvailable
-= nVScrollWidth
;
306 if (!bNeedHScrollBar
&& (lMaxXPosition
> lMaxXAvailable
))
308 // The vertical one now necessitates a horizontal one
309 bNeedHScrollBar
= true;
310 // Adjust nLastVisible
311 nLastVisible
= static_cast<sal_uInt16
>((szOverallSize
.Height() - nControl_Spacing_y
- nHScrollHeight
) / (nControl_Spacing_y
+ nControlHeight
));
312 // bNeedVScrollBar does NOT change: it's already set to sal_True and nLastVisible will only decrease
316 // Now we can really position them and set their parameters
319 m_pVertScroll
->Show();
320 m_pVertScroll
->SetRangeMax(nActive
- nLastVisible
);
322 m_pVertScroll
->SetPosSizePixel( Point(nNewHWidth
, 0), Size(nVScrollWidth
, szOverallSize
.Height()) );
326 m_pVertScroll
->Hide();
327 m_pVertScroll
->SetRangeMax(0);
328 m_pVertScroll
->SetThumbPos(0);
333 m_pHorzScroll
->Show();
334 m_pHorzScroll
->SetRangeMax((lMaxXPosition
- lMaxXAvailable
+ HSCROLL_STEP
- 1 )/HSCROLL_STEP
);
336 m_pHorzScroll
->SetPosSizePixel( Point(0, nNewVHeight
), Size(bNeedVScrollBar
? nNewHWidth
: szOverallSize
.Width(), nHScrollHeight
) );
340 m_pHorzScroll
->Hide();
341 m_pHorzScroll
->SetRangeMax(0);
342 m_pHorzScroll
->SetThumbPos(0);
346 void OFieldDescControl::Resize()
349 ScrollAllAggregates();
352 inline void OFieldDescControl::ScrollAggregate(Control
* pText
, Control
* pInput
, Control
* pButton
, long nDeltaX
, long nDeltaY
)
356 pText
->SetPosPixel(pText
->GetPosPixel() + Point(nDeltaX
, nDeltaY
));
357 pInput
->SetPosPixel(pInput
->GetPosPixel() + Point(nDeltaX
, nDeltaY
));
359 pButton
->SetPosPixel(pButton
->GetPosPixel() + Point(nDeltaX
, nDeltaY
));
362 void OFieldDescControl::ScrollAllAggregates()
364 long nDeltaX
= 0, nDeltaY
= 0;
365 if (m_nOldHThumb
!= m_pHorzScroll
->GetThumbPos())
367 nDeltaX
= (m_nOldHThumb
- m_pHorzScroll
->GetThumbPos()) * HSCROLL_STEP
;
368 m_nOldHThumb
= m_pHorzScroll
->GetThumbPos();
371 if (m_nOldVThumb
!= m_pVertScroll
->GetThumbPos())
373 const sal_Int32 nControlHeight
= GetMaxControlHeight();
374 const sal_Int32 nControl_Spacing_y
= LogicToPixel(Size(0, CONTROL_SPACING_Y
),MAP_APPFONT
).Height();
375 nDeltaY
= (m_nOldVThumb
- m_pVertScroll
->GetThumbPos()) * (nControl_Spacing_y
+ nControlHeight
);
376 m_nOldVThumb
= m_pVertScroll
->GetThumbPos();
379 if (nDeltaX
|| nDeltaY
)
381 Control
* ppAggregates
[] = { pRequired
, pNumType
382 , pAutoIncrement
, pDefault
384 , pScale
, m_pColumnName
385 , m_pType
, m_pAutoIncrementValue
};
386 Control
* ppAggregatesText
[] = { pRequiredText
, pNumTypeText
387 , pAutoIncrementText
, pDefaultText
388 , pTextLenText
, pLengthText
389 , pScaleText
, m_pColumnNameText
390 , m_pTypeText
, m_pAutoIncrementValueText
};
391 OSL_ENSURE(sizeof(ppAggregates
)/sizeof(ppAggregates
[0]) == sizeof(ppAggregatesText
)/sizeof(ppAggregatesText
[0]),"Lists are not identical!");
393 for (sal_uInt16 i
=0; i
<sizeof(ppAggregates
)/sizeof(ppAggregates
[0]); ++i
)
394 ScrollAggregate(ppAggregatesText
[i
],ppAggregates
[i
],NULL
,nDeltaX
, nDeltaY
);
396 ScrollAggregate(pFormatText
,pFormatSample
,pFormat
,nDeltaX
, nDeltaY
);
400 sal_uInt16
OFieldDescControl::CountActiveAggregates() const
402 Control
* ppAggregates
[] = { pRequired
, pNumType
, pAutoIncrement
, pDefault
, pTextLen
, pLength
, pScale
, pFormat
, m_pColumnName
, m_pType
,m_pAutoIncrementValue
};
403 sal_uInt16 nVisibleAggregates
= 0;
404 for (sal_uInt16 i
=0; i
<sizeof(ppAggregates
)/sizeof(ppAggregates
[0]); ++i
)
406 ++nVisibleAggregates
;
407 return nVisibleAggregates
;
410 sal_Int32
OFieldDescControl::GetMaxControlHeight() const
413 Control
* ppAggregates
[] = { pRequired
, pNumType
, pAutoIncrement
, pDefault
, pTextLen
, pLength
, pScale
, pFormat
, m_pColumnName
, m_pType
,m_pAutoIncrementValue
};
414 for (sal_uInt16 i
=0; i
<sizeof(ppAggregates
)/sizeof(ppAggregates
[0]); ++i
)
416 if ( ppAggregates
[i
] )
418 const Size
aTemp(ppAggregates
[i
]->GetOptimalSize());
419 if ( aTemp
.Height() > aHeight
.Height() )
420 aHeight
.Height() = aTemp
.Height();
424 return aHeight
.Height();
427 void OFieldDescControl::SetReadOnly( bool bReadOnly
)
429 // Enable/disable Controls
430 Control
* ppAggregates
[] = { pRequired
, pNumType
431 , pAutoIncrement
, pDefault
433 , pScale
, m_pColumnName
434 , m_pType
, m_pAutoIncrementValue
436 Control
* ppAggregatesText
[] = { pRequiredText
, pNumTypeText
437 , pAutoIncrementText
, pDefaultText
438 , pTextLenText
, pLengthText
439 , pScaleText
, m_pColumnNameText
440 , m_pTypeText
, m_pAutoIncrementValueText
443 OSL_ENSURE(sizeof(ppAggregates
)/sizeof(ppAggregates
[0]) == sizeof(ppAggregatesText
)/sizeof(ppAggregatesText
[0]),"Lists are not identical!");
445 for (sal_uInt16 i
=0; i
<sizeof(ppAggregates
)/sizeof(ppAggregates
[0]); ++i
)
447 if ( ppAggregatesText
[i
] )
448 ppAggregatesText
[i
]->Enable( !bReadOnly
);
449 if ( ppAggregates
[i
] )
450 ppAggregates
[i
]->Enable( !bReadOnly
);
454 OUString
OFieldDescControl::GetControlText( sal_uInt16 nControlId
)
456 // Read out the Controls' texts
459 case FIELD_PROPERTY_BOOL_DEFAULT
:
461 return pBoolDefault
->GetSelectEntry();
463 case FIELD_PROPERTY_DEFAULT
:
465 return pDefault
->GetText();
467 case FIELD_PROPERTY_REQUIRED
:
469 return pRequired
->GetSelectEntry();
471 case FIELD_PROPERTY_TEXTLEN
:
473 return OUString::number(pTextLen
->GetValue());
475 case FIELD_PROPERTY_NUMTYPE
:
477 return pNumType
->GetSelectEntry();
479 case FIELD_PROPERTY_AUTOINC
:
481 return pAutoIncrement
->GetSelectEntry();
483 case FIELD_PROPERTY_LENGTH
:
485 return pLength
->GetText();
487 case FIELD_PROPERTY_SCALE
:
489 return pScale
->GetText();
491 case FIELD_PROPERTY_FORMAT
:
493 return pFormatSample
->GetText();
495 case FIELD_PROPERTY_COLUMNNAME
:
497 return m_pColumnName
->GetText();
499 case FIELD_PROPERTY_TYPE
:
501 return m_pType
->GetSelectEntry();
503 case FIELD_PROPERTY_AUTOINCREMENT
:
504 if(m_pAutoIncrementValue
)
505 return m_pAutoIncrementValue
->GetText();
511 void OFieldDescControl::SetControlText( sal_uInt16 nControlId
, const OUString
& rText
)
513 // Set the Controls' texts
516 case FIELD_PROPERTY_BOOL_DEFAULT
:
519 OUString sOld
= pBoolDefault
->GetSelectEntry();
520 pBoolDefault
->SelectEntry(rText
);
522 LINK(this, OFieldDescControl
, ChangeHdl
).Call(pBoolDefault
);
525 case FIELD_PROPERTY_DEFAULT
:
528 pDefault
->SetText(rText
);
529 UpdateFormatSample(pActFieldDescr
);
533 case FIELD_PROPERTY_REQUIRED
:
535 pRequired
->SelectEntry(rText
);
538 case FIELD_PROPERTY_TEXTLEN
:
540 pTextLen
->SetText(rText
);
543 case FIELD_PROPERTY_NUMTYPE
:
545 pNumType
->SelectEntry(rText
);
548 case FIELD_PROPERTY_AUTOINC
:
551 OUString sOld
= pAutoIncrement
->GetSelectEntry();
552 pAutoIncrement
->SelectEntry(rText
);
554 LINK(this, OFieldDescControl
, ChangeHdl
).Call(pAutoIncrement
);
558 case FIELD_PROPERTY_LENGTH
:
560 pLength
->SetText(rText
);
563 case FIELD_PROPERTY_SCALE
:
565 pScale
->SetText(rText
);
568 case FIELD_PROPERTY_FORMAT
:
570 UpdateFormatSample(pActFieldDescr
);
572 case FIELD_PROPERTY_COLUMNNAME
:
574 m_pColumnName
->SetText(rText
);
576 case FIELD_PROPERTY_TYPE
:
578 m_pType
->SelectEntry(rText
);
580 case FIELD_PROPERTY_AUTOINCREMENT
:
581 if(m_pAutoIncrementValue
)
582 m_pAutoIncrementValue
->SetText(rText
);
587 IMPL_LINK( OFieldDescControl
, FormatClickHdl
, Button
*, /*pButton*/ )
589 // Create temporary Column, which is used for data exchange with Dialog
590 if( !pActFieldDescr
)
593 sal_Int32
nOldFormatKey(pActFieldDescr
->GetFormatKey());
594 SvxCellHorJustify rOldJustify
= pActFieldDescr
->GetHorJustify();
595 Reference
< XNumberFormatsSupplier
> xSupplier
= GetFormatter()->getNumberFormatsSupplier();
596 SvNumberFormatsSupplierObj
* pSupplierImpl
= SvNumberFormatsSupplierObj::getImplementation( xSupplier
);
600 SvNumberFormatter
* pFormatter
= pSupplierImpl
->GetNumberFormatter();
601 if(::dbaui::callColumnFormatDialog(this,pFormatter
,pActFieldDescr
->GetType(),nOldFormatKey
,rOldJustify
,true))
603 bool bModified
= false;
604 if(nOldFormatKey
!= pActFieldDescr
->GetFormatKey())
606 pActFieldDescr
->SetFormatKey( nOldFormatKey
);
609 if(rOldJustify
!= pActFieldDescr
->GetHorJustify())
611 pActFieldDescr
->SetHorJustify( rOldJustify
);
618 UpdateFormatSample(pActFieldDescr
);
624 void OFieldDescControl::SetModified(bool /*bModified*/)
628 IMPL_LINK( OFieldDescControl
, ChangeHdl
, ListBox
*, pListBox
)
630 if ( !pActFieldDescr
)
633 if ( pListBox
->IsValueChangedFromSaved() )
636 // Special treatment for Boold fields
637 if(pListBox
== pRequired
&& pBoolDefault
)
639 // If pRequired = sal_True then the sal_Bool field must NOT contain <<none>>
640 OUString sDef
= BoolStringUI(::comphelper::getString(pActFieldDescr
->GetControlDefault()));
642 if(pRequired
->GetSelectEntryPos() == 0) // Yes
644 pBoolDefault
->RemoveEntry(OUString(ModuleRes(STR_VALUE_NONE
)));
645 if (sDef
!= aYes
&& sDef
!= aNo
)
646 pBoolDefault
->SelectEntryPos(1); // No as a default
648 pBoolDefault
->SelectEntry(sDef
);
650 else if(pBoolDefault
->GetEntryCount() < 3)
652 pBoolDefault
->InsertEntry(OUString(ModuleRes(STR_VALUE_NONE
)));
653 pBoolDefault
->SelectEntry(sDef
);
657 // A special treatment only for AutoIncrement
658 if (pListBox
== pAutoIncrement
)
660 if(pListBox
->GetSelectEntryPos() == 1)
662 DeactivateAggregate( tpAutoIncrementValue
);
663 if(pActFieldDescr
->IsPrimaryKey())
664 DeactivateAggregate( tpRequired
);
665 else if( pActFieldDescr
->getTypeInfo()->bNullable
)
667 ActivateAggregate( tpRequired
);
670 if( pActFieldDescr
->IsNullable() )
671 pRequired
->SelectEntryPos( 1 ); // no
673 pRequired
->SelectEntryPos( 0 ); // yes
676 ActivateAggregate( tpDefault
);
680 DeactivateAggregate( tpRequired
);
681 DeactivateAggregate( tpDefault
);
682 ActivateAggregate( tpAutoIncrementValue
);
688 if(pListBox
== m_pType
)
690 TOTypeInfoSP pTypeInfo
= getTypeInfo(m_pType
->GetSelectEntryPos());
691 pActFieldDescr
->FillFromTypeInfo(pTypeInfo
,true,false); // SetType(pTypeInfo);
693 DisplayData(pActFieldDescr
);
694 CellModified(-1, m_pType
->GetPos());
700 // Rearrange all Controls, such that they are in fixed order and really on top
701 // of the DescriptionPage
702 void OFieldDescControl::ArrangeAggregates()
704 // A Control's description
705 struct AGGREGATE_DESCRIPTION
707 VclPtr
<Control
> pctrlInputControl
; // The actual Control for input
708 VclPtr
<Control
> pctrlTextControl
; // The corresponding Label
709 sal_uInt16 nPosSizeArgument
; // The second argument for SetPosSize
711 AGGREGATE_DESCRIPTION adAggregates
[] = {
712 { m_pColumnName
, m_pColumnNameText
, 1},
713 { m_pType
, m_pTypeText
, 1},
714 { pAutoIncrement
, pAutoIncrementText
, 1 },
715 { m_pAutoIncrementValue
, m_pAutoIncrementValueText
, 3 },
716 { pNumType
, pNumTypeText
, 1 },
717 { pRequired
, pRequiredText
, 1 },
718 { pTextLen
, pTextLenText
, 1 },
719 { pLength
, pLengthText
, 1 },
720 { pScale
, pScaleText
, 1 },
721 { pDefault
, pDefaultText
, 3 },
722 { pFormatSample
, pFormatText
, 4 },
723 { pBoolDefault
, pBoolDefaultText
, 1 },
727 for (size_t i
=0; i
<sizeof(adAggregates
)/sizeof(adAggregates
[0]); i
++)
729 if (adAggregates
[i
].pctrlTextControl
)
731 nMaxWidth
= ::std::max
<long>(OutputDevice::GetTextWidth(adAggregates
[i
].pctrlTextControl
->GetText()),nMaxWidth
);
735 OSL_ENSURE(nMaxWidth
!= 0,"Invalid width!");
738 int nCurrentControlPos
= 0;
739 Control
* pZOrderPredecessor
= NULL
;
740 for (size_t i
=0; i
<sizeof(adAggregates
)/sizeof(adAggregates
[0]); i
++)
742 if (adAggregates
[i
].pctrlInputControl
)
744 SetPosSize(adAggregates
[i
].pctrlTextControl
, nCurrentControlPos
, 0);
745 SetPosSize(adAggregates
[i
].pctrlInputControl
, nCurrentControlPos
, adAggregates
[i
].nPosSizeArgument
);
747 // 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
748 adAggregates
[i
].pctrlTextControl
->SetZOrder(pZOrderPredecessor
, pZOrderPredecessor
? WINDOW_ZORDER_BEHIND
: WINDOW_ZORDER_FIRST
);
749 adAggregates
[i
].pctrlInputControl
->SetZOrder(adAggregates
[i
].pctrlTextControl
, WINDOW_ZORDER_BEHIND
);
750 pZOrderPredecessor
= adAggregates
[i
].pctrlInputControl
;
752 if (adAggregates
[i
].pctrlInputControl
== pFormatSample
)
754 pFormat
->SetZOrder(pZOrderPredecessor
, WINDOW_ZORDER_BEHIND
);
755 pZOrderPredecessor
= pFormat
;
758 ++nCurrentControlPos
;
762 // Special treatment for the Format Controls
765 Point
ptSamplePos(pFormatSample
->GetPosPixel());
766 Size
szSampleSize(pFormatSample
->GetSizePixel());
767 pFormat
->SetPosPixel(Point(ptSamplePos
.X() + szSampleSize
.Width() + 5, ptSamplePos
.Y()));
770 // Finally, put the ScrollBars at the top of the z-order
771 m_pVertScroll
->SetZOrder(NULL
, WINDOW_ZORDER_FIRST
);
772 m_pHorzScroll
->SetZOrder(NULL
, WINDOW_ZORDER_FIRST
);
775 void OFieldDescControl::ActivateAggregate( EControlType eType
)
784 pDefaultText
= CreateText(STR_DEFAULT_VALUE
);
785 pDefault
= VclPtr
<OPropEditCtrl
>::Create( this, STR_HELP_DEFAULT_VALUE
, FIELD_PROPERTY_DEFAULT
, WB_BORDER
);
786 InitializeControl(pDefault
,HID_TAB_ENT_DEFAULT
,false);
788 case tpAutoIncrementValue
:
789 if( m_pAutoIncrementValue
|| !isAutoIncrementValueEnabled() )
792 m_pAutoIncrementValueText
= CreateText(STR_AUTOINCREMENT_VALUE
);
793 m_pAutoIncrementValue
= VclPtr
<OPropEditCtrl
>::Create( this, STR_HELP_AUTOINCREMENT_VALUE
, FIELD_PROPERTY_AUTOINCREMENT
, WB_BORDER
);
794 m_pAutoIncrementValue
->SetText( getAutoIncrementValue() );
795 InitializeControl(m_pAutoIncrementValue
,HID_TAB_AUTOINCREMENTVALUE
,false);
802 Reference
< XDatabaseMetaData
> xMetaData
= getMetaData();
804 if(xMetaData
.is() && xMetaData
->supportsNonNullableColumns())
807 pRequiredText
= CreateText(STR_FIELD_REQUIRED
);
808 pRequired
= VclPtr
<OPropListBoxCtrl
>::Create( this, STR_HELP_FIELD_REQUIRED
, FIELD_PROPERTY_REQUIRED
, WB_DROPDOWN
);
810 pRequired
->InsertEntry( aYes
);
811 pRequired
->InsertEntry( aNo
);
812 pRequired
->SelectEntryPos(1);
814 InitializeControl(pRequired
,HID_TAB_ENT_REQUIRED
,true);
818 case tpAutoIncrement
:
823 pAutoIncrementText
= CreateText(STR_FIELD_AUTOINCREMENT
);
824 pAutoIncrement
= VclPtr
<OPropListBoxCtrl
>::Create( this, STR_HELP_AUTOINCREMENT
, FIELD_PROPERTY_AUTOINC
, WB_DROPDOWN
);
825 pAutoIncrement
->InsertEntry( aYes
);
826 pAutoIncrement
->InsertEntry( aNo
);
827 pAutoIncrement
->SelectEntryPos(0);
828 InitializeControl(pAutoIncrement
,HID_TAB_ENT_AUTOINCREMENT
,true);
835 pTextLenText
= CreateText(STR_TEXT_LENGTH
);
836 pTextLen
= CreateNumericControl(STR_HELP_TEXT_LENGTH
, FIELD_PROPERTY_TEXTLEN
,HID_TAB_ENT_TEXT_LEN
);
843 m_pTypeText
= CreateText(STR_TAB_FIELD_DATATYPE
);
844 m_pType
= VclPtr
<OPropListBoxCtrl
>::Create( this, STR_HELP_AUTOINCREMENT
, FIELD_PROPERTY_TYPE
, WB_DROPDOWN
);
845 m_pType
->SetDropDownLineCount(20);
847 const OTypeInfoMap
* pTypeInfo
= getTypeInfo();
848 OTypeInfoMap::const_iterator aIter
= pTypeInfo
->begin();
849 OTypeInfoMap::const_iterator aEnd
= pTypeInfo
->end();
850 for(;aIter
!= aEnd
;++aIter
)
851 m_pType
->InsertEntry( aIter
->second
->aUIName
);
853 m_pType
->SelectEntryPos(0);
854 InitializeControl(m_pType
,HID_TAB_ENT_TYPE
,true);
861 sal_Int32 nMax
= EDIT_NOLIMIT
;
865 Reference
< XDatabaseMetaData
> xMetaData
= getMetaData();
866 if ( xMetaData
.is() )
868 nMax
= xMetaData
->getMaxColumnNameLength();
869 aTmpString
= xMetaData
->getExtraNameCharacters();
872 catch (const Exception
&)
874 DBG_UNHANDLED_EXCEPTION();
876 m_pColumnNameText
= CreateText(STR_TAB_FIELD_NAME
);
877 m_pColumnName
= VclPtr
<OPropColumnEditCtrl
>::Create( this,
879 STR_HELP_DEFAULT_VALUE
,
880 FIELD_PROPERTY_COLUMNNAME
,
882 m_pColumnName
->SetMaxTextLen(nMax
? nMax
: EDIT_NOLIMIT
);
883 m_pColumnName
->setCheck( isSQL92CheckEnabled(getConnection()) );
886 InitializeControl(m_pColumnName
,HID_TAB_ENT_COLUMNNAME
,false);
892 pNumTypeText
= CreateText(STR_NUMERIC_TYPE
);
894 pNumType
= VclPtr
<OPropListBoxCtrl
>::Create( this, STR_HELP_NUMERIC_TYPE
, FIELD_PROPERTY_NUMTYPE
, WB_DROPDOWN
);
895 pNumType
->SetDropDownLineCount(5);
897 pNumType
->InsertEntry( OUString("Byte") );
898 pNumType
->InsertEntry( OUString("SmallInt") );
899 pNumType
->InsertEntry( OUString("Integer") );
900 pNumType
->InsertEntry( OUString("Single") );
901 pNumType
->InsertEntry( OUString("Double") );
902 pNumType
->SelectEntryPos(2);
903 InitializeControl(pNumType
,HID_TAB_ENT_NUMTYP
,true);
910 pLengthText
= CreateText(STR_LENGTH
);
911 pLength
= CreateNumericControl(STR_HELP_LENGTH
, FIELD_PROPERTY_LENGTH
,HID_TAB_ENT_LEN
);
918 pScaleText
= CreateText(STR_SCALE
);
919 pScale
= CreateNumericControl(STR_HELP_SCALE
, FIELD_PROPERTY_SCALE
,HID_TAB_ENT_SCALE
);
926 pFormatText
= CreateText(STR_FORMAT
);
928 pFormatSample
= VclPtr
<OPropEditCtrl
>::Create( this, STR_HELP_FORMAT_CODE
, -1, WB_BORDER
);
929 pFormatSample
->SetReadOnly(true);
930 pFormatSample
->Enable(false);
931 InitializeControl(pFormatSample
,HID_TAB_ENT_FORMAT_SAMPLE
,false);
933 pFormat
= VclPtr
<PushButton
>::Create( this, ModuleRes(PB_FORMAT
) );
934 const sal_Int32 nControlHeight
= GetMaxControlHeight();
935 pFormat
->SetSizePixel(Size(nControlHeight
, nControlHeight
));
936 pFormat
->SetClickHdl( LINK( this, OFieldDescControl
, FormatClickHdl
) );
937 InitializeControl(pFormat
,HID_TAB_ENT_FORMAT
,false);
940 UpdateFormatSample(pActFieldDescr
);
947 pBoolDefaultText
= CreateText(STR_DEFAULT_VALUE
);
948 pBoolDefault
= VclPtr
<OPropListBoxCtrl
>::Create( this, STR_HELP_BOOL_DEFAULT
, FIELD_PROPERTY_BOOL_DEFAULT
, WB_DROPDOWN
);
949 pBoolDefault
->SetDropDownLineCount(3);
950 pBoolDefault
->InsertEntry(OUString(ModuleRes(STR_VALUE_NONE
)));
951 pBoolDefault
->InsertEntry(aYes
);
952 pBoolDefault
->InsertEntry(aNo
);
954 InitializeControl(pBoolDefault
,HID_TAB_ENT_BOOL_DEFAULT
,false);
959 void OFieldDescControl::InitializeControl(Control
* _pControl
,const OString
& _sHelpId
,bool _bAddChangeHandler
)
961 _pControl
->SetHelpId(_sHelpId
);
962 if ( _bAddChangeHandler
)
963 static_cast<OPropListBoxCtrl
*>(_pControl
)->SetSelectHdl(LINK(this,OFieldDescControl
,ChangeHdl
));
965 _pControl
->SetGetFocusHdl(LINK(this, OFieldDescControl
, OnControlFocusGot
));
966 _pControl
->SetLoseFocusHdl(LINK(this, OFieldDescControl
, OnControlFocusLost
));
967 _pControl
->EnableClipSiblings();
970 VclPtr
<FixedText
> OFieldDescControl::CreateText(sal_uInt16 _nTextRes
)
972 VclPtrInstance
<FixedText
> pFixedText( this );
973 pFixedText
->SetText( ModuleRes(_nTextRes
) );
974 pFixedText
->EnableClipSiblings();
978 VclPtr
<OPropNumericEditCtrl
> OFieldDescControl::CreateNumericControl(sal_uInt16 _nHelpStr
,short _nProperty
,const OString
& _sHelpId
)
980 VclPtrInstance
<OPropNumericEditCtrl
> pControl( this, _nHelpStr
, _nProperty
, WB_BORDER
);
981 pControl
->SetDecimalDigits(0);
983 pControl
->SetMax(0x7FFFFFFF); // Should be changed outside, if needed
984 pControl
->SetStrictFormat(true);
986 InitializeControl(pControl
,_sHelpId
,false);
991 void OFieldDescControl::DeactivateAggregate( EControlType eType
)
993 pLastFocusWindow
= NULL
;
998 lcl_HideAndDeleteControl(m_nPos
,pDefault
,pDefaultText
);
1001 case tpAutoIncrementValue
:
1002 lcl_HideAndDeleteControl(m_nPos
,m_pAutoIncrementValue
,m_pAutoIncrementValueText
);
1006 lcl_HideAndDeleteControl(m_nPos
,m_pColumnName
,m_pColumnNameText
);
1010 lcl_HideAndDeleteControl(m_nPos
,m_pType
,m_pTypeText
);
1013 case tpAutoIncrement
:
1014 lcl_HideAndDeleteControl(m_nPos
,pAutoIncrement
,pAutoIncrementText
);
1018 lcl_HideAndDeleteControl(m_nPos
,pRequired
,pRequiredText
);
1022 lcl_HideAndDeleteControl(m_nPos
,pTextLen
,pTextLenText
);
1026 lcl_HideAndDeleteControl(m_nPos
,pNumType
,pNumTypeText
);
1030 lcl_HideAndDeleteControl(m_nPos
,pLength
,pLengthText
);
1034 lcl_HideAndDeleteControl(m_nPos
,pScale
,pScaleText
);
1038 // TODO: we have to check if we have to increment m_nPos again
1039 lcl_HideAndDeleteControl(m_nPos
,pFormat
,pFormatText
);
1040 if ( pFormatSample
)
1042 pFormatSample
->Hide();
1043 pFormatSample
.disposeAndClear();
1047 lcl_HideAndDeleteControl(m_nPos
,pBoolDefault
,pBoolDefaultText
);
1052 void OFieldDescControl::SetPosSize( VclPtr
<Control
>& rControl
, long nRow
, sal_uInt16 nCol
)
1056 const sal_Int32 nControlHeight
= GetMaxControlHeight();
1057 Size
aSize(0,nControlHeight
);
1058 if ( isRightAligned() && nCol
)
1059 aSize
.Width() = LogicToPixel(Size(m_nWidth
, 0),MAP_APPFONT
).Width();
1066 aSize
.Width() = CONTROL_WIDTH_1
;
1069 aSize
.Width() = CONTROL_WIDTH_2
;
1072 aSize
.Width() = CONTROL_WIDTH_3
;
1075 aSize
.Width() = CONTROL_WIDTH_4
;
1080 // Calculate Position
1091 if ( isRightAligned() )
1093 Size aOwnSize
= GetSizePixel();
1094 aPosition
.X() = aOwnSize
.Width() - aSize
.Width();
1097 aPosition
.X() = CONTROL_WIDTH_1
+ CONTROL_SPACING_X
;
1103 rControl
->SetSizePixel( aSize
);
1104 aSize
= rControl
->GetSizePixel( );
1106 const sal_Int32 nControl_Spacing_y
= LogicToPixel(Size(0, CONTROL_SPACING_Y
),MAP_APPFONT
).Height();
1107 aPosition
.Y() += ((nRow
+1)*nControl_Spacing_y
) +
1108 (nRow
*nControlHeight
);
1111 rControl
->SetPosSizePixel( aPosition
, aSize
);
1112 aSize
= rControl
->GetSizePixel();
1117 void OFieldDescControl::DisplayData(OFieldDescription
* pFieldDescr
)
1119 pActFieldDescr
= pFieldDescr
;
1122 DeactivateAggregate( tpDefault
);
1123 DeactivateAggregate( tpRequired
);
1124 DeactivateAggregate( tpTextLen
);
1125 DeactivateAggregate( tpNumType
);
1126 DeactivateAggregate( tpScale
);
1127 DeactivateAggregate( tpLength
);
1128 DeactivateAggregate( tpFormat
);
1129 DeactivateAggregate( tpAutoIncrement
);
1130 DeactivateAggregate( tpBoolDefault
);
1131 DeactivateAggregate( tpColumnName
);
1132 DeactivateAggregate( tpType
);
1133 DeactivateAggregate( tpAutoIncrementValue
);
1134 m_pPreviousType
= TOTypeInfoSP();
1135 // Reset the saved focus' pointer
1136 pLastFocusWindow
= NULL
;
1139 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
1147 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::AddWindow
));
1151 TOTypeInfoSP pFieldType
;
1153 pFieldType
= pFieldDescr
->getTypeInfo();
1155 ActivateAggregate( tpColumnName
);
1156 ActivateAggregate( tpType
);
1158 OSL_ENSURE(pFieldType
.get(),"We need a type information here!");
1159 // If the type has changed, substitute Controls
1160 if( m_pPreviousType
!= pFieldType
)
1162 // Reset the saved focus' pointer
1163 pLastFocusWindow
= NULL
;
1165 // Controls, which must NOT be displayed again
1166 DeactivateAggregate( tpNumType
);
1168 // determine which controls we should show and which not
1170 // 1. the required control
1171 if ( pFieldType
->bNullable
)
1172 ActivateAggregate( tpRequired
);
1174 DeactivateAggregate( tpRequired
);
1176 // 2. the autoincrement
1177 if ( pFieldType
->bAutoIncrement
)
1179 DeactivateAggregate( tpRequired
);
1180 DeactivateAggregate( tpDefault
);
1181 ActivateAggregate( tpAutoIncrement
);
1182 ActivateAggregate( tpAutoIncrementValue
);
1186 DeactivateAggregate( tpAutoIncrement
);
1187 DeactivateAggregate( tpAutoIncrementValue
);
1188 if(pFieldType
->bNullable
)
1189 ActivateAggregate( tpRequired
);
1191 DeactivateAggregate( tpRequired
);
1192 ActivateAggregate( tpDefault
);
1194 // 3. the scale and precision
1195 if (pFieldType
->nPrecision
)
1197 ActivateAggregate( tpLength
);
1198 pLength
->SetMax(::std::max
<sal_Int32
>(pFieldType
->nPrecision
,pFieldDescr
->GetPrecision()));
1199 pLength
->SetSpecialReadOnly(pFieldType
->aCreateParams
.isEmpty());
1202 DeactivateAggregate( tpLength
);
1204 if (pFieldType
->nMaximumScale
)
1206 ActivateAggregate( tpScale
);
1207 pScale
->SetMax(::std::max
<sal_Int32
>(pFieldType
->nMaximumScale
,pFieldDescr
->GetScale()));
1208 pScale
->SetMin(pFieldType
->nMinimumScale
);
1209 static const char s_sPRECISION
[] = "PRECISION";
1210 pScale
->SetSpecialReadOnly(pFieldType
->aCreateParams
.isEmpty() || pFieldType
->aCreateParams
== s_sPRECISION
);
1213 DeactivateAggregate( tpScale
);
1215 // and now look for type specific things
1216 switch( pFieldType
->nType
)
1218 case DataType::CHAR
:
1219 case DataType::VARCHAR
:
1220 case DataType::LONGVARCHAR
:
1221 DeactivateAggregate( tpLength
);
1222 DeactivateAggregate( tpBoolDefault
);
1224 ActivateAggregate( tpDefault
);
1225 ActivateAggregate( tpFormat
);
1226 if (pFieldType
->nPrecision
)
1228 ActivateAggregate( tpTextLen
);
1229 pTextLen
->SetMax(::std::max
<sal_Int32
>(pFieldType
->nPrecision
,pFieldDescr
->GetPrecision()));
1230 pTextLen
->SetSpecialReadOnly(pFieldType
->aCreateParams
.isEmpty());
1233 DeactivateAggregate( tpTextLen
);
1235 case DataType::DATE
:
1236 case DataType::TIME
:
1237 case DataType::TIMESTAMP
:
1238 DeactivateAggregate( tpLength
); // we don't need a length for date types
1239 DeactivateAggregate( tpTextLen
);
1240 DeactivateAggregate( tpBoolDefault
);
1242 ActivateAggregate( tpDefault
);
1243 ActivateAggregate( tpFormat
);
1246 if ( !pFieldType
->aCreateParams
.isEmpty() )
1248 DeactivateAggregate( tpFormat
);
1249 DeactivateAggregate( tpTextLen
);
1250 DeactivateAggregate( tpBoolDefault
);
1254 case DataType::BOOLEAN
:
1255 DeactivateAggregate( tpTextLen
);
1256 DeactivateAggregate( tpFormat
);
1257 DeactivateAggregate( tpDefault
);
1259 ActivateAggregate( tpBoolDefault
);
1261 case DataType::DECIMAL
:
1262 case DataType::NUMERIC
:
1263 case DataType::BIGINT
:
1264 case DataType::FLOAT
:
1265 case DataType::DOUBLE
:
1266 case DataType::TINYINT
:
1267 case DataType::SMALLINT
:
1268 case DataType::INTEGER
:
1269 case DataType::REAL
:
1270 DeactivateAggregate( tpTextLen
);
1271 DeactivateAggregate( tpBoolDefault
);
1273 ActivateAggregate( tpFormat
);
1275 case DataType::BINARY
:
1276 case DataType::VARBINARY
:
1277 DeactivateAggregate( tpDefault
);
1278 DeactivateAggregate( tpRequired
);
1279 DeactivateAggregate( tpTextLen
);
1280 DeactivateAggregate( tpBoolDefault
);
1282 ActivateAggregate( tpFormat
);
1284 case DataType::LONGVARBINARY
:
1285 case DataType::SQLNULL
:
1286 case DataType::OBJECT
:
1287 case DataType::DISTINCT
:
1288 case DataType::STRUCT
:
1289 case DataType::ARRAY
:
1290 case DataType::BLOB
:
1291 case DataType::CLOB
:
1293 case DataType::OTHER
:
1294 DeactivateAggregate( tpFormat
);
1295 DeactivateAggregate( tpTextLen
);
1296 DeactivateAggregate( tpBoolDefault
);
1300 OSL_FAIL("Unknown type");
1302 m_pPreviousType
= pFieldType
;
1306 if(pFieldDescr
->IsPrimaryKey())
1308 DeactivateAggregate( tpRequired
);
1310 else if ( !pAutoIncrement
&& pFieldType
.get() )
1312 if ( pFieldType
->bNullable
)
1313 ActivateAggregate( tpRequired
);
1315 DeactivateAggregate( tpRequired
);
1318 // Initialize Controls
1319 if( pAutoIncrement
)
1321 if ( pFieldDescr
->IsAutoIncrement() )
1323 pAutoIncrement
->SelectEntryPos( 0 ); // yes
1324 ActivateAggregate( tpAutoIncrementValue
);
1325 if ( m_pAutoIncrementValue
)
1326 m_pAutoIncrementValue
->SetText(pFieldDescr
->GetAutoIncrementValue());
1327 DeactivateAggregate( tpRequired
);
1328 DeactivateAggregate( tpDefault
);
1332 // disable autoincrement value because it should only be visible when autoincrement is to true
1333 DeactivateAggregate( tpAutoIncrementValue
);
1334 pAutoIncrement
->SelectEntryPos( 1 ); // no
1335 ActivateAggregate( tpDefault
);
1336 // Affects pRequired
1337 if(!pFieldDescr
->IsPrimaryKey())
1338 ActivateAggregate( tpRequired
);
1344 pDefault
->SetText( getControlDefault(pFieldDescr
) );
1345 pDefault
->ClearModifyFlag();
1350 // If pRequired = sal_True then the sal_Bool field must NOT contain <<none>>
1352 pFieldDescr
->GetControlDefault() >>= sValue
;
1353 OUString sDef
= BoolStringUI(sValue
);
1355 // Make sure that <<none>> is only present if the field can be NULL
1356 if ( ( pFieldType
.get() && !pFieldType
->bNullable
) || !pFieldDescr
->IsNullable() )
1358 pFieldDescr
->SetIsNullable(ColumnValue::NO_NULLS
); // The type says so
1360 pBoolDefault
->RemoveEntry(OUString(ModuleRes(STR_VALUE_NONE
)));
1361 if ( sDef
!= aYes
&& sDef
!= aNo
)
1362 pBoolDefault
->SelectEntryPos(1); // No as a default
1364 pBoolDefault
->SelectEntry(sDef
);
1366 pFieldDescr
->SetControlDefault(makeAny(OUString(BoolStringPersistent(pBoolDefault
->GetSelectEntry()))));
1368 else if(pBoolDefault
->GetEntryCount() < 3)
1370 pBoolDefault
->InsertEntry(OUString(ModuleRes(STR_VALUE_NONE
)));
1371 pBoolDefault
->SelectEntry(sDef
);
1374 pBoolDefault
->SelectEntry(sDef
);
1379 if( pFieldDescr
->IsNullable() )
1380 pRequired
->SelectEntryPos( 1 ); // no
1382 pRequired
->SelectEntryPos( 0 ); // yes
1387 pTextLen
->SetText( OUString::number(pFieldDescr
->GetPrecision()) );
1388 pTextLen
->ClearModifyFlag();
1393 OSL_FAIL("OFieldDescControl::DisplayData: invalid num type!");
1397 pLength
->SetText( OUString::number(pFieldDescr
->GetPrecision()) );
1400 pScale
->SetText( OUString::number(pFieldDescr
->GetScale()) );
1403 UpdateFormatSample(pFieldDescr
);
1406 m_pColumnName
->SetText(pFieldDescr
->GetName());
1410 sal_Int32 nPos
= pFieldType
.get() ? m_pType
->GetEntryPos(OUString(pFieldDescr
->getTypeInfo()->aUIName
)) : LISTBOX_ENTRY_NOTFOUND
;
1411 if(nPos
== LISTBOX_ENTRY_NOTFOUND
)
1413 const OTypeInfoMap
* pMap
= getTypeInfo();
1414 OTypeInfoMap::const_iterator aIter
= pMap
->find(pFieldType
.get() ? pFieldDescr
->getTypeInfo()->nType
: pFieldDescr
->GetType());
1415 if(aIter
== pMap
->end() && !pMap
->empty())
1417 aIter
= pMap
->begin();
1418 if(pFieldDescr
->GetPrecision() > aIter
->second
->nPrecision
)
1419 pFieldDescr
->SetPrecision(aIter
->second
->nPrecision
);
1420 if(pFieldDescr
->GetScale() > aIter
->second
->nMaximumScale
)
1421 pFieldDescr
->SetScale(0);
1422 if(!aIter
->second
->bNullable
&& pFieldDescr
->IsNullable())
1423 pFieldDescr
->SetIsNullable(ColumnValue::NO_NULLS
);
1424 if(!aIter
->second
->bAutoIncrement
&& pFieldDescr
->IsAutoIncrement())
1425 pFieldDescr
->SetAutoIncrement(false);
1427 if ( aIter
!= pMap
->end() )
1429 pFieldDescr
->SetType(aIter
->second
);
1432 m_pType
->SelectEntry(pFieldDescr
->getTypeInfo()->aUIName
);
1435 // Enable/disable Controls
1436 bool bRead(IsReadOnly());
1438 ArrangeAggregates();
1440 ScrollAllAggregates();
1442 SetReadOnly( bRead
);
1445 IMPL_LINK(OFieldDescControl
, OnControlFocusGot
, Control
*, pControl
)
1447 OUString strHelpText
;
1448 OPropNumericEditCtrl
* pNumeric
= dynamic_cast< OPropNumericEditCtrl
* >( pControl
);
1451 pNumeric
->SaveValue();
1452 strHelpText
= pNumeric
->GetHelp();
1455 OPropColumnEditCtrl
* pColumn
= dynamic_cast< OPropColumnEditCtrl
* >( pControl
);
1458 pColumn
->SaveValue();
1459 strHelpText
= pColumn
->GetHelp();
1462 OPropEditCtrl
* pEdit
= dynamic_cast< OPropEditCtrl
* >( pControl
);
1466 strHelpText
= pEdit
->GetHelp();
1469 OPropListBoxCtrl
* pListBox
= dynamic_cast< OPropListBoxCtrl
* >( pControl
);
1472 pListBox
->SaveValue();
1473 strHelpText
= pListBox
->GetHelp();
1476 if (pControl
== pFormat
)
1477 strHelpText
= ModuleRes(STR_HELP_FORMAT_BUTTON
);
1479 if (!strHelpText
.isEmpty() && (pHelp
!= nullptr))
1480 pHelp
->SetHelpText(strHelpText
);
1482 m_pActFocusWindow
= pControl
;
1487 IMPL_LINK(OFieldDescControl
, OnControlFocusLost
, Control
*, pControl
)
1489 if ((pControl
== pLength
) || (pControl
== pTextLen
) || (pControl
== pScale
))
1491 OPropNumericEditCtrl
* pConverted
= static_cast<OPropNumericEditCtrl
*>(pControl
);
1492 if (pConverted
->IsModified())
1493 CellModified(-1, pConverted
->GetPos());
1495 if(pControl
== m_pColumnName
)
1497 OPropColumnEditCtrl
* pConverted
= static_cast<OPropColumnEditCtrl
*>(pControl
);
1498 if (pConverted
->IsModified())
1499 CellModified(-1, pConverted
->GetPos());
1501 else if ((pControl
== pDefault
) || (pControl
== pFormatSample
) || (pControl
== m_pAutoIncrementValue
) )
1503 OPropEditCtrl
* pConverted
= static_cast<OPropEditCtrl
*>(pControl
);
1504 if (pConverted
->IsModified())
1505 CellModified(-1, pConverted
->GetPos());
1507 else if ((pControl
== pRequired
) || (pControl
== pNumType
) || (pControl
== pAutoIncrement
) || (pControl
== pBoolDefault
) || (pControl
== m_pType
))
1509 OPropListBoxCtrl
* pConverted
= static_cast<OPropListBoxCtrl
*>(pControl
);
1510 if (pConverted
->IsModified())
1511 CellModified(-1, pConverted
->GetPos());
1514 if (pControl
== pDefault
)
1515 UpdateFormatSample(pActFieldDescr
);
1517 implFocusLost(pControl
);
1522 void OFieldDescControl::SaveData( OFieldDescription
* pFieldDescr
)
1527 // Read out Controls
1531 sDefault
= pDefault
->GetText();
1533 else if (pBoolDefault
)
1535 sDefault
= BoolStringPersistent(pBoolDefault
->GetSelectEntry());
1538 if ( !sDefault
.isEmpty() )
1539 pFieldDescr
->SetControlDefault(makeAny(sDefault
));
1541 pFieldDescr
->SetControlDefault(Any());
1543 if((pRequired
&& pRequired
->GetSelectEntryPos() == 0) || pFieldDescr
->IsPrimaryKey() || (pBoolDefault
&& pBoolDefault
->GetEntryCount() == 2)) // yes
1544 pFieldDescr
->SetIsNullable( ColumnValue::NO_NULLS
);
1546 pFieldDescr
->SetIsNullable( ColumnValue::NULLABLE
);
1548 if ( pAutoIncrement
)
1549 pFieldDescr
->SetAutoIncrement( pAutoIncrement
->GetSelectEntryPos() == 0 );
1552 pFieldDescr
->SetPrecision( static_cast<sal_Int32
>(pTextLen
->GetValue()) );
1554 pFieldDescr
->SetPrecision( static_cast<sal_Int32
>(pLength
->GetValue()) );
1556 pFieldDescr
->SetScale( static_cast<sal_Int32
>(pScale
->GetValue()) );
1559 pFieldDescr
->SetName(m_pColumnName
->GetText());
1561 if ( m_pAutoIncrementValue
&& isAutoIncrementValueEnabled() )
1562 pFieldDescr
->SetAutoIncrementValue(m_pAutoIncrementValue
->GetText());
1565 void OFieldDescControl::UpdateFormatSample(OFieldDescription
* pFieldDescr
)
1567 if ( pFieldDescr
&& pFormatSample
)
1568 pFormatSample
->SetText(getControlDefault(pFieldDescr
,false));
1571 void OFieldDescControl::GetFocus()
1573 // Set the Focus to the Control that has been active last
1574 TabPage::GetFocus();
1575 if( pLastFocusWindow
)
1577 pLastFocusWindow
->GrabFocus();
1578 pLastFocusWindow
= NULL
;
1582 void OFieldDescControl::implFocusLost(vcl::Window
* _pWhich
)
1584 OSL_ENSURE(!_pWhich
|| IsChild(_pWhich
), "OFieldDescControl::implFocusLost : invalid window !");
1586 // Remember the active Control
1587 if (!pLastFocusWindow
)
1588 pLastFocusWindow
= _pWhich
;
1591 if (pHelp
&& !pHelp
->HasChildPathFocus())
1592 pHelp
->SetHelpText( OUString() );
1595 void OFieldDescControl::LoseFocus()
1597 implFocusLost(NULL
);
1599 TabPage::LoseFocus();
1602 bool OFieldDescControl::isCopyAllowed()
1604 bool bAllowed
= (m_pActFocusWindow
!= nullptr) &&
1605 (m_pActFocusWindow
== pDefault
|| m_pActFocusWindow
== pFormatSample
||
1606 m_pActFocusWindow
== pTextLen
|| m_pActFocusWindow
== pLength
||
1607 m_pActFocusWindow
== pScale
|| m_pActFocusWindow
== m_pColumnName
||
1608 m_pActFocusWindow
== m_pAutoIncrementValue
) &&
1609 !static_cast<Edit
*>(m_pActFocusWindow
.get())->GetSelected().isEmpty();
1614 bool OFieldDescControl::isCutAllowed()
1616 bool bAllowed
= (m_pActFocusWindow
!= nullptr) &&
1617 (m_pActFocusWindow
== pDefault
|| m_pActFocusWindow
== pFormatSample
||
1618 m_pActFocusWindow
== pTextLen
|| m_pActFocusWindow
== pLength
||
1619 m_pActFocusWindow
== pScale
|| m_pActFocusWindow
== m_pColumnName
||
1620 m_pActFocusWindow
== m_pAutoIncrementValue
) &&
1621 !static_cast<Edit
*>(m_pActFocusWindow
.get())->GetSelected().isEmpty();
1625 bool OFieldDescControl::isPasteAllowed()
1627 bool bAllowed
= (m_pActFocusWindow
!= nullptr) &&
1628 (m_pActFocusWindow
== pDefault
|| m_pActFocusWindow
== pFormatSample
||
1629 m_pActFocusWindow
== pTextLen
|| m_pActFocusWindow
== pLength
||
1630 m_pActFocusWindow
== pScale
|| m_pActFocusWindow
== m_pColumnName
||
1631 m_pActFocusWindow
== m_pAutoIncrementValue
);
1634 TransferableDataHelper
aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
1635 bAllowed
= aTransferData
.HasFormat(SotClipboardFormatId::STRING
);
1640 void OFieldDescControl::cut()
1643 static_cast<Edit
*>(m_pActFocusWindow
.get())->Cut();
1646 void OFieldDescControl::copy()
1648 if(isCopyAllowed()) // this only checks if the focus window is valid
1649 static_cast<Edit
*>(m_pActFocusWindow
.get())->Copy();
1652 void OFieldDescControl::paste()
1654 if(m_pActFocusWindow
) // this only checks if the focus window is valid
1655 static_cast<Edit
*>(m_pActFocusWindow
.get())->Paste();
1658 bool OFieldDescControl::isTextFormat(const OFieldDescription
* _pFieldDescr
, sal_uInt32
& _nFormatKey
) const
1660 _nFormatKey
= _pFieldDescr
->GetFormatKey();
1661 bool bTextFormat
= true;
1667 Reference
< ::com::sun::star::util::XNumberFormatTypes
> xNumberTypes(GetFormatter()->getNumberFormatsSupplier()->getNumberFormats(),UNO_QUERY
);
1668 OSL_ENSURE(xNumberTypes
.is(),"XNumberFormatTypes is null!");
1670 _nFormatKey
= ::dbtools::getDefaultNumberFormat( _pFieldDescr
->GetType(),
1671 _pFieldDescr
->GetScale(),
1672 _pFieldDescr
->IsCurrency(),
1676 sal_Int32 nNumberFormat
= ::comphelper::getNumberFormatType(GetFormatter(),_nFormatKey
);
1677 bTextFormat
= (nNumberFormat
== ::com::sun::star::util::NumberFormat::TEXT
);
1679 catch(const Exception
&)
1687 OUString
OFieldDescControl::getControlDefault( const OFieldDescription
* _pFieldDescr
, bool _bCheck
) const
1690 bool bCheck
= !_bCheck
|| _pFieldDescr
->GetControlDefault().hasValue();
1693 sal_uInt32 nFormatKey
;
1697 double nValue
= 0.0;
1698 bool bTextFormat
= isTextFormat(_pFieldDescr
,nFormatKey
);
1699 if ( _pFieldDescr
->GetControlDefault() >>= sDefault
)
1703 if ( !sDefault
.isEmpty() )
1707 nValue
= GetFormatter()->convertStringToNumber(nFormatKey
,sDefault
);
1709 catch(const Exception
&)
1711 return OUString(); // return empty string for format example
1717 _pFieldDescr
->GetControlDefault() >>= nValue
;
1719 Reference
< ::com::sun::star::util::XNumberFormatter
> xNumberFormatter
= GetFormatter();
1720 Reference
<XPropertySet
> xFormSet
= xNumberFormatter
->getNumberFormatsSupplier()->getNumberFormats()->getByKey(nFormatKey
);
1721 OSL_ENSURE(xFormSet
.is(),"XPropertySet is null!");
1723 xFormSet
->getPropertyValue("FormatString") >>= sFormat
;
1728 ::comphelper::getNumberFormatProperty(xNumberFormatter
,nFormatKey
,OUString("Locale")) >>= aLocale
;
1730 sal_Int32 nNumberFormat
= ::comphelper::getNumberFormatType(xNumberFormatter
,nFormatKey
);
1731 if( (nNumberFormat
& ::com::sun::star::util::NumberFormat::DATE
) == ::com::sun::star::util::NumberFormat::DATE
1732 || (nNumberFormat
& ::com::sun::star::util::NumberFormat::DATETIME
) == ::com::sun::star::util::NumberFormat::DATETIME
)
1734 nValue
= DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter
->getNumberFormatsSupplier()),nValue
);
1737 Reference
< ::com::sun::star::util::XNumberFormatPreviewer
> xPreviewer(xNumberFormatter
,UNO_QUERY
);
1738 OSL_ENSURE(xPreviewer
.is(),"XNumberFormatPreviewer is null!");
1739 sDefault
= xPreviewer
->convertNumberToPreviewString(sFormat
,nValue
,aLocale
,sal_True
);
1741 else if ( !(_bCheck
&& sDefault
.isEmpty()) )
1742 sDefault
= xNumberFormatter
->formatString(nFormatKey
, sDefault
.isEmpty() ? sFormat
: sDefault
);
1744 catch(const Exception
&)
1753 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */