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 "dbu_control.hrc"
54 #include "dbu_tbl.hrc"
55 #include <osl/diagnose.h>
57 using namespace dbaui
;
58 using namespace dbtools
;
59 using namespace ::com::sun::star::uno
;
60 using namespace ::com::sun::star::beans
;
61 using namespace ::com::sun::star::lang
;
62 using namespace ::com::sun::star::sdbc
;
63 using namespace ::com::sun::star::util
;
65 // For the Controls on the OFieldDescGenPage
66 #define CONTROL_SPACING_X 18 // 6
67 #define CONTROL_SPACING_Y 4
68 #define CONTROL_WIDTH_1 160 // 100
69 #define CONTROL_WIDTH_2 100 // 60
70 #define CONTROL_WIDTH_3 250
71 #define CONTROL_WIDTH_4 (CONTROL_WIDTH_3 - 20 - 5)
73 #define HSCROLL_STEP 20
78 template< typename T1
, typename T2
> void lcl_HideAndDeleteControl(short& _nPos
,VclPtr
<T1
>& _pControl
, VclPtr
<T2
>& _pControlText
)
84 _pControlText
->Hide();
85 _pControl
.disposeAndClear();
86 _pControlText
.disposeAndClear();
92 // class OFieldDescControl
93 OFieldDescControl::OFieldDescControl( vcl::Window
* pParent
, OTableDesignHelpBar
* pHelpBar
)
94 :TabPage( pParent
, WB_3DLOOK
| WB_DIALOGCONTROL
)
96 ,pLastFocusWindow(nullptr)
97 ,m_pActFocusWindow(nullptr)
98 ,pDefaultText(nullptr)
99 ,pRequiredText(nullptr)
100 ,pAutoIncrementText(nullptr)
101 ,pTextLenText(nullptr)
102 ,pNumTypeText(nullptr)
103 ,pLengthText(nullptr)
105 ,pFormatText(nullptr)
106 ,pBoolDefaultText(nullptr)
107 ,m_pColumnNameText(nullptr)
108 ,m_pTypeText(nullptr)
109 ,m_pAutoIncrementValueText(nullptr)
112 ,pAutoIncrement(nullptr)
117 ,pFormatSample(nullptr)
118 ,pBoolDefault(nullptr)
119 ,m_pColumnName(nullptr)
121 ,m_pAutoIncrementValue(nullptr)
123 ,m_pVertScroll( nullptr )
124 ,m_pHorzScroll( nullptr )
127 ,aYes(ModuleRes(STR_VALUE_YES
))
128 ,aNo(ModuleRes(STR_VALUE_NO
))
133 ,m_bRightAligned(false)
134 ,pActFieldDescr(nullptr)
139 void OFieldDescControl::Contruct()
141 m_pVertScroll
= VclPtr
<ScrollBar
>::Create(this, WB_VSCROLL
| WB_REPEAT
| WB_DRAG
);
142 m_pHorzScroll
= VclPtr
<ScrollBar
>::Create(this, WB_HSCROLL
| WB_REPEAT
| WB_DRAG
);
143 m_pVertScroll
->SetScrollHdl(LINK(this, OFieldDescControl
, OnScroll
));
144 m_pHorzScroll
->SetScrollHdl(LINK(this, OFieldDescControl
, OnScroll
));
145 m_pVertScroll
->Show();
146 m_pHorzScroll
->Show();
148 m_pVertScroll
->EnableClipSiblings();
149 m_pHorzScroll
->EnableClipSiblings();
151 m_pVertScroll
->SetLineSize(1);
152 m_pVertScroll
->SetPageSize(1);
153 m_pHorzScroll
->SetLineSize(1);
154 m_pHorzScroll
->SetPageSize(1);
156 m_nOldVThumb
= m_nOldHThumb
= 0;
159 OFieldDescControl::~OFieldDescControl()
164 void OFieldDescControl::dispose()
167 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
170 DeactivateAggregate( tpDefault
);
171 DeactivateAggregate( tpRequired
);
172 DeactivateAggregate( tpTextLen
);
173 DeactivateAggregate( tpNumType
);
174 DeactivateAggregate( tpScale
);
175 DeactivateAggregate( tpLength
);
176 DeactivateAggregate( tpFormat
);
177 DeactivateAggregate( tpAutoIncrement
);
178 DeactivateAggregate( tpBoolDefault
);
179 DeactivateAggregate( tpColumnName
);
180 DeactivateAggregate( tpType
);
181 DeactivateAggregate( tpAutoIncrementValue
);
183 pLastFocusWindow
.clear();
184 m_pActFocusWindow
.clear();
185 pDefaultText
.clear();
186 pRequiredText
.clear();
187 pAutoIncrementText
.clear();
188 pTextLenText
.clear();
189 pNumTypeText
.clear();
193 pBoolDefaultText
.clear();
194 m_pColumnNameText
.clear();
196 m_pAutoIncrementValueText
.clear();
199 pAutoIncrement
.clear();
204 pFormatSample
.clear();
205 pBoolDefault
.clear();
206 m_pColumnName
.clear();
208 m_pAutoIncrementValue
.clear();
210 m_pVertScroll
.disposeAndClear();
211 m_pHorzScroll
.disposeAndClear();
215 OUString
OFieldDescControl::BoolStringPersistent(const OUString
& rUIString
) const
217 if (rUIString
== aNo
)
218 return OUString('0');
219 if (rUIString
== aYes
)
220 return OUString('1');
224 OUString
OFieldDescControl::BoolStringUI(const OUString
& rPersistentString
) const
226 // Older versions may store a language dependent string as a default
227 if (rPersistentString
== aYes
|| rPersistentString
== aNo
)
228 return rPersistentString
;
230 if (rPersistentString
== "0")
232 if (rPersistentString
== "1")
235 return ModuleRes(STR_VALUE_NONE
).toString();
238 void OFieldDescControl::Init()
240 Reference
< css::util::XNumberFormatter
> xFormatter
= GetFormatter();
241 ::dbaui::setEvalDateFormatForFormatter(xFormatter
);
244 IMPL_LINK_TYPED(OFieldDescControl
, OnScroll
, ScrollBar
*, /*pBar*/, void)
246 ScrollAllAggregates();
251 void getMaxXPosition(vcl::Window
* _pWindow
,long& _rnMaxXPosition
)
255 long nTemp
= _pWindow
->GetSizePixel().Width() + _pWindow
->GetPosPixel().X();
256 _rnMaxXPosition
= ::std::max(_rnMaxXPosition
, nTemp
);
261 void OFieldDescControl::CheckScrollBars()
263 // Calculate the ScrollBars' new position
264 Size szOverallSize
= GetSizePixel();
265 long nHScrollHeight
= m_pHorzScroll
->GetSizePixel().Height();
266 long nVScrollWidth
= m_pVertScroll
->GetSizePixel().Width();
268 long nNewHWidth
= szOverallSize
.Width() - nVScrollWidth
;
269 long nNewVHeight
= szOverallSize
.Height() - nHScrollHeight
;
271 bool bNeedHScrollBar(false), bNeedVScrollBar(false);
274 // Do I actually need ScrollBars?
276 long lMaxXPosition
= 0;
277 Control
* ppAggregates
[] = { pRequired
, pNumType
, pAutoIncrement
, pDefault
, pTextLen
, pLength
, pScale
, pFormat
, m_pColumnName
, m_pType
,m_pAutoIncrementValue
};
278 for (Control
* ppAggregate
: ppAggregates
)
279 getMaxXPosition(ppAggregate
,lMaxXPosition
);
281 lMaxXPosition
+= m_pHorzScroll
->GetThumbPos() * HSCROLL_STEP
;
283 long lMaxXAvailable
= szOverallSize
.Width();
284 bNeedHScrollBar
= lMaxXPosition
> lMaxXAvailable
;
288 // How many Controls do I have?
289 sal_uInt16 nActive
= CountActiveAggregates();
290 // Which one is the last one that fits?
291 sal_uInt16 nLastVisible
;
292 const sal_Int32 nControlHeight
= GetMaxControlHeight();
293 const sal_Int32 nControl_Spacing_y
= LogicToPixel(Size(0, CONTROL_SPACING_Y
),MAP_APPFONT
).Height();
295 nLastVisible
= static_cast<sal_uInt16
>((szOverallSize
.Height() - nControl_Spacing_y
- nHScrollHeight
) / (nControl_Spacing_y
+ nControlHeight
));
297 nLastVisible
= static_cast<sal_uInt16
>((szOverallSize
.Height() - nControl_Spacing_y
) / (nControl_Spacing_y
+ nControlHeight
));
298 bNeedVScrollBar
= nActive
>nLastVisible
;
302 // When originally calculating lMaxXAvailable we did not take into account that we have a VScrollBar, so we need to do that now
303 lMaxXAvailable
-= nVScrollWidth
;
304 if (!bNeedHScrollBar
&& (lMaxXPosition
> lMaxXAvailable
))
306 // The vertical one now necessitates a horizontal one
307 bNeedHScrollBar
= true;
308 // Adjust nLastVisible
309 nLastVisible
= static_cast<sal_uInt16
>((szOverallSize
.Height() - nControl_Spacing_y
- nHScrollHeight
) / (nControl_Spacing_y
+ nControlHeight
));
310 // bNeedVScrollBar does NOT change: it's already set to sal_True and nLastVisible will only decrease
314 // Now we can really position them and set their parameters
317 m_pVertScroll
->Show();
318 m_pVertScroll
->SetRangeMax(nActive
- nLastVisible
);
320 m_pVertScroll
->SetPosSizePixel( Point(nNewHWidth
, 0), Size(nVScrollWidth
, szOverallSize
.Height()) );
324 m_pVertScroll
->Hide();
325 m_pVertScroll
->SetRangeMax(0);
326 m_pVertScroll
->SetThumbPos(0);
331 m_pHorzScroll
->Show();
332 m_pHorzScroll
->SetRangeMax((lMaxXPosition
- lMaxXAvailable
+ HSCROLL_STEP
- 1 )/HSCROLL_STEP
);
334 m_pHorzScroll
->SetPosSizePixel( Point(0, nNewVHeight
), Size(bNeedVScrollBar
? nNewHWidth
: szOverallSize
.Width(), nHScrollHeight
) );
338 m_pHorzScroll
->Hide();
339 m_pHorzScroll
->SetRangeMax(0);
340 m_pHorzScroll
->SetThumbPos(0);
344 void OFieldDescControl::Resize()
347 ScrollAllAggregates();
350 inline void OFieldDescControl::ScrollAggregate(Control
* pText
, Control
* pInput
, Control
* pButton
, long nDeltaX
, long nDeltaY
)
354 pText
->SetPosPixel(pText
->GetPosPixel() + Point(nDeltaX
, nDeltaY
));
355 pInput
->SetPosPixel(pInput
->GetPosPixel() + Point(nDeltaX
, nDeltaY
));
357 pButton
->SetPosPixel(pButton
->GetPosPixel() + Point(nDeltaX
, nDeltaY
));
360 void OFieldDescControl::ScrollAllAggregates()
362 long nDeltaX
= 0, nDeltaY
= 0;
363 if (m_nOldHThumb
!= m_pHorzScroll
->GetThumbPos())
365 nDeltaX
= (m_nOldHThumb
- m_pHorzScroll
->GetThumbPos()) * HSCROLL_STEP
;
366 m_nOldHThumb
= m_pHorzScroll
->GetThumbPos();
369 if (m_nOldVThumb
!= m_pVertScroll
->GetThumbPos())
371 const sal_Int32 nControlHeight
= GetMaxControlHeight();
372 const sal_Int32 nControl_Spacing_y
= LogicToPixel(Size(0, CONTROL_SPACING_Y
),MAP_APPFONT
).Height();
373 nDeltaY
= (m_nOldVThumb
- m_pVertScroll
->GetThumbPos()) * (nControl_Spacing_y
+ nControlHeight
);
374 m_nOldVThumb
= m_pVertScroll
->GetThumbPos();
377 if (nDeltaX
|| nDeltaY
)
379 Control
* ppAggregates
[] = { pRequired
, pNumType
380 , pAutoIncrement
, pDefault
382 , pScale
, m_pColumnName
383 , m_pType
, m_pAutoIncrementValue
};
384 Control
* ppAggregatesText
[] = { pRequiredText
, pNumTypeText
385 , pAutoIncrementText
, pDefaultText
386 , pTextLenText
, pLengthText
387 , pScaleText
, m_pColumnNameText
388 , m_pTypeText
, m_pAutoIncrementValueText
};
389 OSL_ENSURE(SAL_N_ELEMENTS(ppAggregates
) == SAL_N_ELEMENTS(ppAggregatesText
),"Lists are not identical!");
391 for (sal_uInt16 i
=0; i
<SAL_N_ELEMENTS(ppAggregates
); ++i
)
392 ScrollAggregate(ppAggregatesText
[i
],ppAggregates
[i
],nullptr,nDeltaX
, nDeltaY
);
394 ScrollAggregate(pFormatText
,pFormatSample
,pFormat
,nDeltaX
, nDeltaY
);
398 sal_uInt16
OFieldDescControl::CountActiveAggregates() const
400 Control
* ppAggregates
[] = { pRequired
, pNumType
, pAutoIncrement
, pDefault
, pTextLen
, pLength
, pScale
, pFormat
, m_pColumnName
, m_pType
,m_pAutoIncrementValue
};
401 sal_uInt16 nVisibleAggregates
= 0;
402 for (Control
* pAggregate
: ppAggregates
)
404 ++nVisibleAggregates
;
405 return nVisibleAggregates
;
408 sal_Int32
OFieldDescControl::GetMaxControlHeight() const
411 Control
* ppAggregates
[] = { pRequired
, pNumType
, pAutoIncrement
, pDefault
, pTextLen
, pLength
, pScale
, pFormat
, m_pColumnName
, m_pType
,m_pAutoIncrementValue
};
412 for (Control
* pAggregate
: ppAggregates
)
416 const Size
aTemp(pAggregate
->GetOptimalSize());
417 if ( aTemp
.Height() > aHeight
.Height() )
418 aHeight
.Height() = aTemp
.Height();
422 return aHeight
.Height();
425 void OFieldDescControl::SetReadOnly( bool bReadOnly
)
427 // Enable/disable Controls
428 Control
* ppAggregates
[] = { pRequired
, pNumType
429 , pAutoIncrement
, pDefault
431 , pScale
, m_pColumnName
432 , m_pType
, m_pAutoIncrementValue
434 Control
* ppAggregatesText
[] = { pRequiredText
, pNumTypeText
435 , pAutoIncrementText
, pDefaultText
436 , pTextLenText
, pLengthText
437 , pScaleText
, m_pColumnNameText
438 , m_pTypeText
, m_pAutoIncrementValueText
441 OSL_ENSURE(SAL_N_ELEMENTS(ppAggregates
) == SAL_N_ELEMENTS(ppAggregatesText
),"Lists are not identical!");
443 for (sal_uInt16 i
=0; i
<SAL_N_ELEMENTS(ppAggregates
); ++i
)
445 if ( ppAggregatesText
[i
] )
446 ppAggregatesText
[i
]->Enable( !bReadOnly
);
447 if ( ppAggregates
[i
] )
448 ppAggregates
[i
]->Enable( !bReadOnly
);
452 void OFieldDescControl::SetControlText( sal_uInt16 nControlId
, const OUString
& rText
)
454 // Set the Controls' texts
457 case FIELD_PROPERTY_BOOL_DEFAULT
:
460 OUString sOld
= pBoolDefault
->GetSelectEntry();
461 pBoolDefault
->SelectEntry(rText
);
463 LINK(this, OFieldDescControl
, ChangeHdl
).Call(*pBoolDefault
);
466 case FIELD_PROPERTY_DEFAULT
:
469 pDefault
->SetText(rText
);
470 UpdateFormatSample(pActFieldDescr
);
474 case FIELD_PROPERTY_REQUIRED
:
476 pRequired
->SelectEntry(rText
);
479 case FIELD_PROPERTY_TEXTLEN
:
481 pTextLen
->SetText(rText
);
484 case FIELD_PROPERTY_NUMTYPE
:
486 pNumType
->SelectEntry(rText
);
489 case FIELD_PROPERTY_AUTOINC
:
492 OUString sOld
= pAutoIncrement
->GetSelectEntry();
493 pAutoIncrement
->SelectEntry(rText
);
495 LINK(this, OFieldDescControl
, ChangeHdl
).Call(*pAutoIncrement
);
499 case FIELD_PROPERTY_LENGTH
:
501 pLength
->SetText(rText
);
504 case FIELD_PROPERTY_SCALE
:
506 pScale
->SetText(rText
);
509 case FIELD_PROPERTY_FORMAT
:
511 UpdateFormatSample(pActFieldDescr
);
513 case FIELD_PROPERTY_COLUMNNAME
:
515 m_pColumnName
->SetText(rText
);
517 case FIELD_PROPERTY_TYPE
:
519 m_pType
->SelectEntry(rText
);
521 case FIELD_PROPERTY_AUTOINCREMENT
:
522 if(m_pAutoIncrementValue
)
523 m_pAutoIncrementValue
->SetText(rText
);
528 IMPL_LINK_NOARG_TYPED( OFieldDescControl
, FormatClickHdl
, Button
*, void )
530 // Create temporary Column, which is used for data exchange with Dialog
531 if( !pActFieldDescr
)
534 sal_Int32
nOldFormatKey(pActFieldDescr
->GetFormatKey());
535 SvxCellHorJustify rOldJustify
= pActFieldDescr
->GetHorJustify();
536 Reference
< XNumberFormatsSupplier
> xSupplier
= GetFormatter()->getNumberFormatsSupplier();
537 SvNumberFormatsSupplierObj
* pSupplierImpl
= SvNumberFormatsSupplierObj::getImplementation( xSupplier
);
541 SvNumberFormatter
* pFormatter
= pSupplierImpl
->GetNumberFormatter();
542 if(::dbaui::callColumnFormatDialog(this,pFormatter
,pActFieldDescr
->GetType(),nOldFormatKey
,rOldJustify
,true))
544 bool bModified
= false;
545 if(nOldFormatKey
!= pActFieldDescr
->GetFormatKey())
547 pActFieldDescr
->SetFormatKey( nOldFormatKey
);
550 if(rOldJustify
!= pActFieldDescr
->GetHorJustify())
552 pActFieldDescr
->SetHorJustify( rOldJustify
);
559 UpdateFormatSample(pActFieldDescr
);
564 void OFieldDescControl::SetModified(bool /*bModified*/)
568 IMPL_LINK_TYPED( OFieldDescControl
, ChangeHdl
, ListBox
&, rListBox
, void )
570 if ( !pActFieldDescr
)
573 if ( rListBox
.IsValueChangedFromSaved() )
576 // Special treatment for Bool fields
577 if(&rListBox
== pRequired
&& pBoolDefault
)
579 // If pRequired = sal_True then the sal_Bool field must NOT contain <<none>>
580 OUString sDef
= BoolStringUI(::comphelper::getString(pActFieldDescr
->GetControlDefault()));
582 if(pRequired
->GetSelectEntryPos() == 0) // Yes
584 pBoolDefault
->RemoveEntry(OUString(ModuleRes(STR_VALUE_NONE
)));
585 if (sDef
!= aYes
&& sDef
!= aNo
)
586 pBoolDefault
->SelectEntryPos(1); // No as a default
588 pBoolDefault
->SelectEntry(sDef
);
590 else if(pBoolDefault
->GetEntryCount() < 3)
592 pBoolDefault
->InsertEntry(OUString(ModuleRes(STR_VALUE_NONE
)));
593 pBoolDefault
->SelectEntry(sDef
);
597 // A special treatment only for AutoIncrement
598 if (&rListBox
== pAutoIncrement
)
600 if(rListBox
.GetSelectEntryPos() == 1)
602 DeactivateAggregate( tpAutoIncrementValue
);
603 if(pActFieldDescr
->IsPrimaryKey())
604 DeactivateAggregate( tpRequired
);
605 else if( pActFieldDescr
->getTypeInfo()->bNullable
)
607 ActivateAggregate( tpRequired
);
610 if( pActFieldDescr
->IsNullable() )
611 pRequired
->SelectEntryPos( 1 ); // no
613 pRequired
->SelectEntryPos( 0 ); // yes
616 ActivateAggregate( tpDefault
);
620 DeactivateAggregate( tpRequired
);
621 DeactivateAggregate( tpDefault
);
622 ActivateAggregate( tpAutoIncrementValue
);
628 if(&rListBox
== m_pType
)
630 TOTypeInfoSP pTypeInfo
= getTypeInfo(m_pType
->GetSelectEntryPos());
631 pActFieldDescr
->FillFromTypeInfo(pTypeInfo
,true,false); // SetType(pTypeInfo);
633 DisplayData(pActFieldDescr
);
634 CellModified(-1, m_pType
->GetPos());
638 // Rearrange all Controls, such that they are in fixed order and really on top
639 // of the DescriptionPage
640 void OFieldDescControl::ArrangeAggregates()
642 // A Control's description
643 struct AGGREGATE_DESCRIPTION
645 VclPtr
<Control
> pctrlInputControl
; // The actual Control for input
646 VclPtr
<Control
> pctrlTextControl
; // The corresponding Label
647 sal_uInt16 nPosSizeArgument
; // The second argument for SetPosSize
649 AGGREGATE_DESCRIPTION adAggregates
[] = {
650 { m_pColumnName
, m_pColumnNameText
, 1},
651 { m_pType
, m_pTypeText
, 1},
652 { pAutoIncrement
, pAutoIncrementText
, 1 },
653 { m_pAutoIncrementValue
, m_pAutoIncrementValueText
, 3 },
654 { pNumType
, pNumTypeText
, 1 },
655 { pRequired
, pRequiredText
, 1 },
656 { pTextLen
, pTextLenText
, 1 },
657 { pLength
, pLengthText
, 1 },
658 { pScale
, pScaleText
, 1 },
659 { pDefault
, pDefaultText
, 3 },
660 { pFormatSample
, pFormatText
, 4 },
661 { pBoolDefault
, pBoolDefaultText
, 1 },
665 for (const AGGREGATE_DESCRIPTION
& adAggregate
: adAggregates
)
667 if (adAggregate
.pctrlTextControl
)
669 nMaxWidth
= ::std::max
<long>(OutputDevice::GetTextWidth(adAggregate
.pctrlTextControl
->GetText()),nMaxWidth
);
673 OSL_ENSURE(nMaxWidth
!= 0,"Invalid width!");
676 int nCurrentControlPos
= 0;
677 Control
* pZOrderPredecessor
= nullptr;
678 for (AGGREGATE_DESCRIPTION
& adAggregate
: adAggregates
)
680 if (adAggregate
.pctrlInputControl
)
682 SetPosSize(adAggregate
.pctrlTextControl
, nCurrentControlPos
, 0);
683 SetPosSize(adAggregate
.pctrlInputControl
, nCurrentControlPos
, adAggregate
.nPosSizeArgument
);
685 // 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
686 adAggregate
.pctrlTextControl
->SetZOrder(pZOrderPredecessor
, pZOrderPredecessor
? ZOrderFlags::Behind
: ZOrderFlags::First
);
687 adAggregate
.pctrlInputControl
->SetZOrder(adAggregate
.pctrlTextControl
, ZOrderFlags::Behind
);
688 pZOrderPredecessor
= adAggregate
.pctrlInputControl
;
690 if (adAggregate
.pctrlInputControl
== pFormatSample
)
692 pFormat
->SetZOrder(pZOrderPredecessor
, ZOrderFlags::Behind
);
693 pZOrderPredecessor
= pFormat
;
696 ++nCurrentControlPos
;
700 // Special treatment for the Format Controls
703 Point
ptSamplePos(pFormatSample
->GetPosPixel());
704 Size
szSampleSize(pFormatSample
->GetSizePixel());
705 pFormat
->SetPosPixel(Point(ptSamplePos
.X() + szSampleSize
.Width() + 5, ptSamplePos
.Y()));
708 // Finally, put the ScrollBars at the top of the z-order
709 m_pVertScroll
->SetZOrder(nullptr, ZOrderFlags::First
);
710 m_pHorzScroll
->SetZOrder(nullptr, ZOrderFlags::First
);
713 void OFieldDescControl::ActivateAggregate( EControlType eType
)
722 pDefaultText
= CreateText(STR_DEFAULT_VALUE
);
723 pDefault
= VclPtr
<OPropEditCtrl
>::Create( this, STR_HELP_DEFAULT_VALUE
, FIELD_PROPERTY_DEFAULT
, WB_BORDER
);
724 InitializeControl(pDefault
,HID_TAB_ENT_DEFAULT
,false);
726 case tpAutoIncrementValue
:
727 if( m_pAutoIncrementValue
|| !isAutoIncrementValueEnabled() )
730 m_pAutoIncrementValueText
= CreateText(STR_AUTOINCREMENT_VALUE
);
731 m_pAutoIncrementValue
= VclPtr
<OPropEditCtrl
>::Create( this, STR_HELP_AUTOINCREMENT_VALUE
, FIELD_PROPERTY_AUTOINCREMENT
, WB_BORDER
);
732 m_pAutoIncrementValue
->SetText( getAutoIncrementValue() );
733 InitializeControl(m_pAutoIncrementValue
,HID_TAB_AUTOINCREMENTVALUE
,false);
740 Reference
< XDatabaseMetaData
> xMetaData
= getMetaData();
742 if(xMetaData
.is() && xMetaData
->supportsNonNullableColumns())
745 pRequiredText
= CreateText(STR_FIELD_REQUIRED
);
746 pRequired
= VclPtr
<OPropListBoxCtrl
>::Create( this, STR_HELP_FIELD_REQUIRED
, FIELD_PROPERTY_REQUIRED
, WB_DROPDOWN
);
748 pRequired
->InsertEntry( aYes
);
749 pRequired
->InsertEntry( aNo
);
750 pRequired
->SelectEntryPos(1);
752 InitializeControl(pRequired
,HID_TAB_ENT_REQUIRED
,true);
756 case tpAutoIncrement
:
761 pAutoIncrementText
= CreateText(STR_FIELD_AUTOINCREMENT
);
762 pAutoIncrement
= VclPtr
<OPropListBoxCtrl
>::Create( this, STR_HELP_AUTOINCREMENT
, FIELD_PROPERTY_AUTOINC
, WB_DROPDOWN
);
763 pAutoIncrement
->InsertEntry( aYes
);
764 pAutoIncrement
->InsertEntry( aNo
);
765 pAutoIncrement
->SelectEntryPos(0);
766 InitializeControl(pAutoIncrement
,HID_TAB_ENT_AUTOINCREMENT
,true);
773 pTextLenText
= CreateText(STR_TEXT_LENGTH
);
774 pTextLen
= CreateNumericControl(STR_HELP_TEXT_LENGTH
, FIELD_PROPERTY_TEXTLEN
,HID_TAB_ENT_TEXT_LEN
);
781 m_pTypeText
= CreateText(STR_TAB_FIELD_DATATYPE
);
782 m_pType
= VclPtr
<OPropListBoxCtrl
>::Create( this, STR_HELP_AUTOINCREMENT
, FIELD_PROPERTY_TYPE
, WB_DROPDOWN
);
783 m_pType
->SetDropDownLineCount(20);
785 const OTypeInfoMap
* pTypeInfo
= getTypeInfo();
786 OTypeInfoMap::const_iterator aIter
= pTypeInfo
->begin();
787 OTypeInfoMap::const_iterator aEnd
= pTypeInfo
->end();
788 for(;aIter
!= aEnd
;++aIter
)
789 m_pType
->InsertEntry( aIter
->second
->aUIName
);
791 m_pType
->SelectEntryPos(0);
792 InitializeControl(m_pType
,HID_TAB_ENT_TYPE
,true);
799 sal_Int32 nMax
= EDIT_NOLIMIT
;
803 Reference
< XDatabaseMetaData
> xMetaData
= getMetaData();
804 if ( xMetaData
.is() )
806 nMax
= xMetaData
->getMaxColumnNameLength();
807 aTmpString
= xMetaData
->getExtraNameCharacters();
810 catch (const Exception
&)
812 DBG_UNHANDLED_EXCEPTION();
814 m_pColumnNameText
= CreateText(STR_TAB_FIELD_NAME
);
815 m_pColumnName
= VclPtr
<OPropColumnEditCtrl
>::Create( this,
817 STR_HELP_DEFAULT_VALUE
,
818 FIELD_PROPERTY_COLUMNNAME
,
820 m_pColumnName
->SetMaxTextLen(nMax
? nMax
: EDIT_NOLIMIT
);
821 m_pColumnName
->setCheck( isSQL92CheckEnabled(getConnection()) );
824 InitializeControl(m_pColumnName
,HID_TAB_ENT_COLUMNNAME
,false);
830 pNumTypeText
= CreateText(STR_NUMERIC_TYPE
);
832 pNumType
= VclPtr
<OPropListBoxCtrl
>::Create( this, STR_HELP_NUMERIC_TYPE
, FIELD_PROPERTY_NUMTYPE
, WB_DROPDOWN
);
833 pNumType
->SetDropDownLineCount(5);
835 pNumType
->InsertEntry( OUString("Byte") );
836 pNumType
->InsertEntry( OUString("SmallInt") );
837 pNumType
->InsertEntry( OUString("Integer") );
838 pNumType
->InsertEntry( OUString("Single") );
839 pNumType
->InsertEntry( OUString("Double") );
840 pNumType
->SelectEntryPos(2);
841 InitializeControl(pNumType
,HID_TAB_ENT_NUMTYP
,true);
848 pLengthText
= CreateText(STR_LENGTH
);
849 pLength
= CreateNumericControl(STR_HELP_LENGTH
, FIELD_PROPERTY_LENGTH
,HID_TAB_ENT_LEN
);
856 pScaleText
= CreateText(STR_SCALE
);
857 pScale
= CreateNumericControl(STR_HELP_SCALE
, FIELD_PROPERTY_SCALE
,HID_TAB_ENT_SCALE
);
864 pFormatText
= CreateText(STR_FORMAT
);
866 pFormatSample
= VclPtr
<OPropEditCtrl
>::Create( this, STR_HELP_FORMAT_CODE
, -1, WB_BORDER
);
867 pFormatSample
->SetReadOnly();
868 pFormatSample
->Enable(false);
869 InitializeControl(pFormatSample
,HID_TAB_ENT_FORMAT_SAMPLE
,false);
871 pFormat
= VclPtr
<PushButton
>::Create( this, ModuleRes(PB_FORMAT
) );
872 const sal_Int32 nControlHeight
= GetMaxControlHeight();
873 pFormat
->SetSizePixel(Size(nControlHeight
, nControlHeight
));
874 pFormat
->SetClickHdl( LINK( this, OFieldDescControl
, FormatClickHdl
) );
875 InitializeControl(pFormat
,HID_TAB_ENT_FORMAT
,false);
878 UpdateFormatSample(pActFieldDescr
);
885 pBoolDefaultText
= CreateText(STR_DEFAULT_VALUE
);
886 pBoolDefault
= VclPtr
<OPropListBoxCtrl
>::Create( this, STR_HELP_BOOL_DEFAULT
, FIELD_PROPERTY_BOOL_DEFAULT
, WB_DROPDOWN
);
887 pBoolDefault
->SetDropDownLineCount(3);
888 pBoolDefault
->InsertEntry(OUString(ModuleRes(STR_VALUE_NONE
)));
889 pBoolDefault
->InsertEntry(aYes
);
890 pBoolDefault
->InsertEntry(aNo
);
892 InitializeControl(pBoolDefault
,HID_TAB_ENT_BOOL_DEFAULT
,false);
897 void OFieldDescControl::InitializeControl(Control
* _pControl
,const OString
& _sHelpId
,bool _bAddChangeHandler
)
899 _pControl
->SetHelpId(_sHelpId
);
900 if ( _bAddChangeHandler
)
901 static_cast<OPropListBoxCtrl
*>(_pControl
)->SetSelectHdl(LINK(this,OFieldDescControl
,ChangeHdl
));
903 _pControl
->SetGetFocusHdl(LINK(this, OFieldDescControl
, OnControlFocusGot
));
904 _pControl
->SetLoseFocusHdl(LINK(this, OFieldDescControl
, OnControlFocusLost
));
905 _pControl
->EnableClipSiblings();
908 VclPtr
<FixedText
> OFieldDescControl::CreateText(sal_uInt16 _nTextRes
)
910 VclPtrInstance
<FixedText
> pFixedText( this );
911 pFixedText
->SetText( ModuleRes(_nTextRes
) );
912 pFixedText
->EnableClipSiblings();
916 VclPtr
<OPropNumericEditCtrl
> OFieldDescControl::CreateNumericControl(sal_uInt16 _nHelpStr
,short _nProperty
,const OString
& _sHelpId
)
918 VclPtrInstance
<OPropNumericEditCtrl
> pControl( this, _nHelpStr
, _nProperty
, WB_BORDER
);
919 pControl
->SetDecimalDigits(0);
921 pControl
->SetMax(0x7FFFFFFF); // Should be changed outside, if needed
922 pControl
->SetStrictFormat(true);
924 InitializeControl(pControl
,_sHelpId
,false);
929 void OFieldDescControl::DeactivateAggregate( EControlType eType
)
931 pLastFocusWindow
= nullptr;
936 lcl_HideAndDeleteControl(m_nPos
,pDefault
,pDefaultText
);
939 case tpAutoIncrementValue
:
940 lcl_HideAndDeleteControl(m_nPos
,m_pAutoIncrementValue
,m_pAutoIncrementValueText
);
944 lcl_HideAndDeleteControl(m_nPos
,m_pColumnName
,m_pColumnNameText
);
948 lcl_HideAndDeleteControl(m_nPos
,m_pType
,m_pTypeText
);
951 case tpAutoIncrement
:
952 lcl_HideAndDeleteControl(m_nPos
,pAutoIncrement
,pAutoIncrementText
);
956 lcl_HideAndDeleteControl(m_nPos
,pRequired
,pRequiredText
);
960 lcl_HideAndDeleteControl(m_nPos
,pTextLen
,pTextLenText
);
964 lcl_HideAndDeleteControl(m_nPos
,pNumType
,pNumTypeText
);
968 lcl_HideAndDeleteControl(m_nPos
,pLength
,pLengthText
);
972 lcl_HideAndDeleteControl(m_nPos
,pScale
,pScaleText
);
976 // TODO: we have to check if we have to increment m_nPos again
977 lcl_HideAndDeleteControl(m_nPos
,pFormat
,pFormatText
);
980 pFormatSample
->Hide();
981 pFormatSample
.disposeAndClear();
985 lcl_HideAndDeleteControl(m_nPos
,pBoolDefault
,pBoolDefaultText
);
990 void OFieldDescControl::SetPosSize( VclPtr
<Control
>& rControl
, long nRow
, sal_uInt16 nCol
)
994 const sal_Int32 nControlHeight
= GetMaxControlHeight();
995 Size
aSize(0,nControlHeight
);
996 if ( isRightAligned() && nCol
)
997 aSize
.Width() = LogicToPixel(Size(m_nWidth
, 0),MAP_APPFONT
).Width();
1004 aSize
.Width() = CONTROL_WIDTH_1
;
1007 aSize
.Width() = CONTROL_WIDTH_2
;
1010 aSize
.Width() = CONTROL_WIDTH_3
;
1013 aSize
.Width() = CONTROL_WIDTH_4
;
1018 // Calculate Position
1029 if ( isRightAligned() )
1031 Size aOwnSize
= GetSizePixel();
1032 aPosition
.X() = aOwnSize
.Width() - aSize
.Width();
1035 aPosition
.X() = CONTROL_WIDTH_1
+ CONTROL_SPACING_X
;
1041 rControl
->SetSizePixel( aSize
);
1042 aSize
= rControl
->GetSizePixel( );
1044 const sal_Int32 nControl_Spacing_y
= LogicToPixel(Size(0, CONTROL_SPACING_Y
),MAP_APPFONT
).Height();
1045 aPosition
.Y() += ((nRow
+1)*nControl_Spacing_y
) +
1046 (nRow
*nControlHeight
);
1049 rControl
->SetPosSizePixel( aPosition
, aSize
);
1050 aSize
= rControl
->GetSizePixel();
1055 void OFieldDescControl::DisplayData(OFieldDescription
* pFieldDescr
)
1057 pActFieldDescr
= pFieldDescr
;
1060 DeactivateAggregate( tpDefault
);
1061 DeactivateAggregate( tpRequired
);
1062 DeactivateAggregate( tpTextLen
);
1063 DeactivateAggregate( tpNumType
);
1064 DeactivateAggregate( tpScale
);
1065 DeactivateAggregate( tpLength
);
1066 DeactivateAggregate( tpFormat
);
1067 DeactivateAggregate( tpAutoIncrement
);
1068 DeactivateAggregate( tpBoolDefault
);
1069 DeactivateAggregate( tpColumnName
);
1070 DeactivateAggregate( tpType
);
1071 DeactivateAggregate( tpAutoIncrementValue
);
1072 m_pPreviousType
= TOTypeInfoSP();
1073 // Reset the saved focus' pointer
1074 pLastFocusWindow
= nullptr;
1077 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow
));
1085 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::AddWindow
));
1089 TOTypeInfoSP pFieldType
;
1091 pFieldType
= pFieldDescr
->getTypeInfo();
1093 ActivateAggregate( tpColumnName
);
1094 ActivateAggregate( tpType
);
1096 OSL_ENSURE(pFieldType
.get(),"We need a type information here!");
1097 // If the type has changed, substitute Controls
1098 if( m_pPreviousType
!= pFieldType
)
1100 // Reset the saved focus' pointer
1101 pLastFocusWindow
= nullptr;
1103 // Controls, which must NOT be displayed again
1104 DeactivateAggregate( tpNumType
);
1106 // determine which controls we should show and which not
1108 // 1. the required control
1109 if ( pFieldType
->bNullable
)
1110 ActivateAggregate( tpRequired
);
1112 DeactivateAggregate( tpRequired
);
1114 // 2. the autoincrement
1115 if ( pFieldType
->bAutoIncrement
)
1117 DeactivateAggregate( tpRequired
);
1118 DeactivateAggregate( tpDefault
);
1119 ActivateAggregate( tpAutoIncrement
);
1120 ActivateAggregate( tpAutoIncrementValue
);
1124 DeactivateAggregate( tpAutoIncrement
);
1125 DeactivateAggregate( tpAutoIncrementValue
);
1126 if(pFieldType
->bNullable
)
1127 ActivateAggregate( tpRequired
);
1129 DeactivateAggregate( tpRequired
);
1130 ActivateAggregate( tpDefault
);
1132 // 3. the scale and precision
1133 if (pFieldType
->nPrecision
)
1135 ActivateAggregate( tpLength
);
1136 pLength
->SetMax(::std::max
<sal_Int32
>(pFieldType
->nPrecision
,pFieldDescr
->GetPrecision()));
1137 pLength
->SetSpecialReadOnly(pFieldType
->aCreateParams
.isEmpty());
1140 DeactivateAggregate( tpLength
);
1142 if (pFieldType
->nMaximumScale
)
1144 ActivateAggregate( tpScale
);
1145 pScale
->SetMax(::std::max
<sal_Int32
>(pFieldType
->nMaximumScale
,pFieldDescr
->GetScale()));
1146 pScale
->SetMin(pFieldType
->nMinimumScale
);
1147 static const char s_sPRECISION
[] = "PRECISION";
1148 pScale
->SetSpecialReadOnly(pFieldType
->aCreateParams
.isEmpty() || pFieldType
->aCreateParams
== s_sPRECISION
);
1151 DeactivateAggregate( tpScale
);
1153 // and now look for type specific things
1154 switch( pFieldType
->nType
)
1156 case DataType::CHAR
:
1157 case DataType::VARCHAR
:
1158 case DataType::LONGVARCHAR
:
1159 DeactivateAggregate( tpLength
);
1160 DeactivateAggregate( tpBoolDefault
);
1162 ActivateAggregate( tpDefault
);
1163 ActivateAggregate( tpFormat
);
1164 if (pFieldType
->nPrecision
)
1166 ActivateAggregate( tpTextLen
);
1167 pTextLen
->SetMax(::std::max
<sal_Int32
>(pFieldType
->nPrecision
,pFieldDescr
->GetPrecision()));
1168 pTextLen
->SetSpecialReadOnly(pFieldType
->aCreateParams
.isEmpty());
1171 DeactivateAggregate( tpTextLen
);
1173 case DataType::DATE
:
1174 case DataType::TIME
:
1175 case DataType::TIMESTAMP
:
1176 DeactivateAggregate( tpLength
); // we don't need a length for date types
1177 DeactivateAggregate( tpTextLen
);
1178 DeactivateAggregate( tpBoolDefault
);
1180 ActivateAggregate( tpDefault
);
1181 ActivateAggregate( tpFormat
);
1184 if ( !pFieldType
->aCreateParams
.isEmpty() )
1186 DeactivateAggregate( tpFormat
);
1187 DeactivateAggregate( tpTextLen
);
1188 DeactivateAggregate( tpBoolDefault
);
1192 case DataType::BOOLEAN
:
1193 DeactivateAggregate( tpTextLen
);
1194 DeactivateAggregate( tpFormat
);
1195 DeactivateAggregate( tpDefault
);
1197 ActivateAggregate( tpBoolDefault
);
1199 case DataType::DECIMAL
:
1200 case DataType::NUMERIC
:
1201 case DataType::BIGINT
:
1202 case DataType::FLOAT
:
1203 case DataType::DOUBLE
:
1204 case DataType::TINYINT
:
1205 case DataType::SMALLINT
:
1206 case DataType::INTEGER
:
1207 case DataType::REAL
:
1208 DeactivateAggregate( tpTextLen
);
1209 DeactivateAggregate( tpBoolDefault
);
1211 ActivateAggregate( tpFormat
);
1213 case DataType::BINARY
:
1214 case DataType::VARBINARY
:
1215 DeactivateAggregate( tpDefault
);
1216 DeactivateAggregate( tpRequired
);
1217 DeactivateAggregate( tpTextLen
);
1218 DeactivateAggregate( tpBoolDefault
);
1220 ActivateAggregate( tpFormat
);
1222 case DataType::LONGVARBINARY
:
1223 case DataType::SQLNULL
:
1224 case DataType::OBJECT
:
1225 case DataType::DISTINCT
:
1226 case DataType::STRUCT
:
1227 case DataType::ARRAY
:
1228 case DataType::BLOB
:
1229 case DataType::CLOB
:
1231 case DataType::OTHER
:
1232 DeactivateAggregate( tpFormat
);
1233 DeactivateAggregate( tpTextLen
);
1234 DeactivateAggregate( tpBoolDefault
);
1238 OSL_FAIL("Unknown type");
1240 m_pPreviousType
= pFieldType
;
1244 if(pFieldDescr
->IsPrimaryKey())
1246 DeactivateAggregate( tpRequired
);
1248 else if ( !pAutoIncrement
&& pFieldType
.get() )
1250 if ( pFieldType
->bNullable
)
1251 ActivateAggregate( tpRequired
);
1253 DeactivateAggregate( tpRequired
);
1256 // Initialize Controls
1257 if( pAutoIncrement
)
1259 if ( pFieldDescr
->IsAutoIncrement() )
1261 pAutoIncrement
->SelectEntryPos( 0 ); // yes
1262 ActivateAggregate( tpAutoIncrementValue
);
1263 if ( m_pAutoIncrementValue
)
1264 m_pAutoIncrementValue
->SetText(pFieldDescr
->GetAutoIncrementValue());
1265 DeactivateAggregate( tpRequired
);
1266 DeactivateAggregate( tpDefault
);
1270 // disable autoincrement value because it should only be visible when autoincrement is to true
1271 DeactivateAggregate( tpAutoIncrementValue
);
1272 pAutoIncrement
->SelectEntryPos( 1 ); // no
1273 ActivateAggregate( tpDefault
);
1274 // Affects pRequired
1275 if(!pFieldDescr
->IsPrimaryKey())
1276 ActivateAggregate( tpRequired
);
1282 pDefault
->SetText( getControlDefault(pFieldDescr
) );
1283 pDefault
->ClearModifyFlag();
1288 // If pRequired = sal_True then the sal_Bool field must NOT contain <<none>>
1290 pFieldDescr
->GetControlDefault() >>= sValue
;
1291 OUString sDef
= BoolStringUI(sValue
);
1293 // Make sure that <<none>> is only present if the field can be NULL
1294 if ( ( pFieldType
.get() && !pFieldType
->bNullable
) || !pFieldDescr
->IsNullable() )
1296 pFieldDescr
->SetIsNullable(ColumnValue::NO_NULLS
); // The type says so
1298 pBoolDefault
->RemoveEntry(OUString(ModuleRes(STR_VALUE_NONE
)));
1299 if ( sDef
!= aYes
&& sDef
!= aNo
)
1300 pBoolDefault
->SelectEntryPos(1); // No as a default
1302 pBoolDefault
->SelectEntry(sDef
);
1304 pFieldDescr
->SetControlDefault(makeAny(OUString(BoolStringPersistent(pBoolDefault
->GetSelectEntry()))));
1306 else if(pBoolDefault
->GetEntryCount() < 3)
1308 pBoolDefault
->InsertEntry(OUString(ModuleRes(STR_VALUE_NONE
)));
1309 pBoolDefault
->SelectEntry(sDef
);
1312 pBoolDefault
->SelectEntry(sDef
);
1317 if( pFieldDescr
->IsNullable() )
1318 pRequired
->SelectEntryPos( 1 ); // no
1320 pRequired
->SelectEntryPos( 0 ); // yes
1325 pTextLen
->SetText( OUString::number(pFieldDescr
->GetPrecision()) );
1326 pTextLen
->ClearModifyFlag();
1331 OSL_FAIL("OFieldDescControl::DisplayData: invalid num type!");
1335 pLength
->SetText( OUString::number(pFieldDescr
->GetPrecision()) );
1338 pScale
->SetText( OUString::number(pFieldDescr
->GetScale()) );
1341 UpdateFormatSample(pFieldDescr
);
1344 m_pColumnName
->SetText(pFieldDescr
->GetName());
1348 sal_Int32 nPos
= pFieldType
.get() ? m_pType
->GetEntryPos(OUString(pFieldDescr
->getTypeInfo()->aUIName
)) : LISTBOX_ENTRY_NOTFOUND
;
1349 if(nPos
== LISTBOX_ENTRY_NOTFOUND
)
1351 const OTypeInfoMap
* pMap
= getTypeInfo();
1352 OTypeInfoMap::const_iterator aIter
= pMap
->find(pFieldType
.get() ? pFieldDescr
->getTypeInfo()->nType
: pFieldDescr
->GetType());
1353 if(aIter
== pMap
->end() && !pMap
->empty())
1355 aIter
= pMap
->begin();
1356 if(pFieldDescr
->GetPrecision() > aIter
->second
->nPrecision
)
1357 pFieldDescr
->SetPrecision(aIter
->second
->nPrecision
);
1358 if(pFieldDescr
->GetScale() > aIter
->second
->nMaximumScale
)
1359 pFieldDescr
->SetScale(0);
1360 if(!aIter
->second
->bNullable
&& pFieldDescr
->IsNullable())
1361 pFieldDescr
->SetIsNullable(ColumnValue::NO_NULLS
);
1362 if(!aIter
->second
->bAutoIncrement
&& pFieldDescr
->IsAutoIncrement())
1363 pFieldDescr
->SetAutoIncrement(false);
1365 if ( aIter
!= pMap
->end() )
1367 pFieldDescr
->SetType(aIter
->second
);
1370 m_pType
->SelectEntry(pFieldDescr
->getTypeInfo()->aUIName
);
1373 // Enable/disable Controls
1374 bool bRead(IsReadOnly());
1376 ArrangeAggregates();
1378 ScrollAllAggregates();
1380 SetReadOnly( bRead
);
1383 IMPL_LINK_TYPED(OFieldDescControl
, OnControlFocusGot
, Control
&, rControl
, void )
1385 OUString strHelpText
;
1386 OPropNumericEditCtrl
* pNumeric
= dynamic_cast< OPropNumericEditCtrl
* >( &rControl
);
1389 pNumeric
->SaveValue();
1390 strHelpText
= pNumeric
->GetHelp();
1393 OPropColumnEditCtrl
* pColumn
= dynamic_cast< OPropColumnEditCtrl
* >( &rControl
);
1396 pColumn
->SaveValue();
1397 strHelpText
= pColumn
->GetHelp();
1400 OPropEditCtrl
* pEdit
= dynamic_cast< OPropEditCtrl
* >( &rControl
);
1404 strHelpText
= pEdit
->GetHelp();
1407 OPropListBoxCtrl
* pListBox
= dynamic_cast< OPropListBoxCtrl
* >( &rControl
);
1410 pListBox
->SaveValue();
1411 strHelpText
= pListBox
->GetHelp();
1414 if (&rControl
== pFormat
)
1415 strHelpText
= ModuleRes(STR_HELP_FORMAT_BUTTON
);
1417 if (!strHelpText
.isEmpty() && (pHelp
!= nullptr))
1418 pHelp
->SetHelpText(strHelpText
);
1420 m_pActFocusWindow
= &rControl
;
1423 IMPL_LINK_TYPED(OFieldDescControl
, OnControlFocusLost
, Control
&, rControl
, void )
1425 if ((&rControl
== pLength
) || (&rControl
== pTextLen
) || (&rControl
== pScale
))
1427 OPropNumericEditCtrl
* pConverted
= static_cast<OPropNumericEditCtrl
*>(&rControl
);
1428 if (pConverted
->IsModified())
1429 CellModified(-1, pConverted
->GetPos());
1431 if(&rControl
== m_pColumnName
)
1433 OPropColumnEditCtrl
* pConverted
= static_cast<OPropColumnEditCtrl
*>(&rControl
);
1434 if (pConverted
->IsModified())
1435 CellModified(-1, pConverted
->GetPos());
1437 else if ((&rControl
== pDefault
) || (&rControl
== pFormatSample
) || (&rControl
== m_pAutoIncrementValue
) )
1439 OPropEditCtrl
* pConverted
= static_cast<OPropEditCtrl
*>(&rControl
);
1440 if (pConverted
->IsModified())
1441 CellModified(-1, pConverted
->GetPos());
1443 else if ((&rControl
== pRequired
) || (&rControl
== pNumType
) || (&rControl
== pAutoIncrement
) || (&rControl
== pBoolDefault
) || (&rControl
== m_pType
))
1445 OPropListBoxCtrl
* pConverted
= static_cast<OPropListBoxCtrl
*>(&rControl
);
1446 if (pConverted
->IsModified())
1447 CellModified(-1, pConverted
->GetPos());
1450 if (&rControl
== pDefault
)
1451 UpdateFormatSample(pActFieldDescr
);
1453 implFocusLost(&rControl
);
1456 void OFieldDescControl::SaveData( OFieldDescription
* pFieldDescr
)
1461 // Read out Controls
1465 sDefault
= pDefault
->GetText();
1467 else if (pBoolDefault
)
1469 sDefault
= BoolStringPersistent(pBoolDefault
->GetSelectEntry());
1472 if ( !sDefault
.isEmpty() )
1473 pFieldDescr
->SetControlDefault(makeAny(sDefault
));
1475 pFieldDescr
->SetControlDefault(Any());
1477 if((pRequired
&& pRequired
->GetSelectEntryPos() == 0) || pFieldDescr
->IsPrimaryKey() || (pBoolDefault
&& pBoolDefault
->GetEntryCount() == 2)) // yes
1478 pFieldDescr
->SetIsNullable( ColumnValue::NO_NULLS
);
1480 pFieldDescr
->SetIsNullable( ColumnValue::NULLABLE
);
1482 if ( pAutoIncrement
)
1483 pFieldDescr
->SetAutoIncrement( pAutoIncrement
->GetSelectEntryPos() == 0 );
1486 pFieldDescr
->SetPrecision( static_cast<sal_Int32
>(pTextLen
->GetValue()) );
1488 pFieldDescr
->SetPrecision( static_cast<sal_Int32
>(pLength
->GetValue()) );
1490 pFieldDescr
->SetScale( static_cast<sal_Int32
>(pScale
->GetValue()) );
1493 pFieldDescr
->SetName(m_pColumnName
->GetText());
1495 if ( m_pAutoIncrementValue
&& isAutoIncrementValueEnabled() )
1496 pFieldDescr
->SetAutoIncrementValue(m_pAutoIncrementValue
->GetText());
1499 void OFieldDescControl::UpdateFormatSample(OFieldDescription
* pFieldDescr
)
1501 if ( pFieldDescr
&& pFormatSample
)
1502 pFormatSample
->SetText(getControlDefault(pFieldDescr
,false));
1505 void OFieldDescControl::GetFocus()
1507 // Set the Focus to the Control that has been active last
1508 TabPage::GetFocus();
1509 if( pLastFocusWindow
)
1511 pLastFocusWindow
->GrabFocus();
1512 pLastFocusWindow
= nullptr;
1516 void OFieldDescControl::implFocusLost(vcl::Window
* _pWhich
)
1518 OSL_ENSURE(!_pWhich
|| IsChild(_pWhich
), "OFieldDescControl::implFocusLost : invalid window !");
1520 // Remember the active Control
1521 if (!pLastFocusWindow
)
1522 pLastFocusWindow
= _pWhich
;
1525 if (pHelp
&& !pHelp
->HasChildPathFocus())
1526 pHelp
->SetHelpText( OUString() );
1529 void OFieldDescControl::LoseFocus()
1531 implFocusLost(nullptr);
1533 TabPage::LoseFocus();
1536 bool OFieldDescControl::isCopyAllowed()
1538 bool bAllowed
= (m_pActFocusWindow
!= nullptr) &&
1539 (m_pActFocusWindow
== pDefault
|| m_pActFocusWindow
== pFormatSample
||
1540 m_pActFocusWindow
== pTextLen
|| m_pActFocusWindow
== pLength
||
1541 m_pActFocusWindow
== pScale
|| m_pActFocusWindow
== m_pColumnName
||
1542 m_pActFocusWindow
== m_pAutoIncrementValue
) &&
1543 !static_cast<Edit
*>(m_pActFocusWindow
.get())->GetSelected().isEmpty();
1548 bool OFieldDescControl::isCutAllowed()
1550 bool bAllowed
= (m_pActFocusWindow
!= nullptr) &&
1551 (m_pActFocusWindow
== pDefault
|| m_pActFocusWindow
== pFormatSample
||
1552 m_pActFocusWindow
== pTextLen
|| m_pActFocusWindow
== pLength
||
1553 m_pActFocusWindow
== pScale
|| m_pActFocusWindow
== m_pColumnName
||
1554 m_pActFocusWindow
== m_pAutoIncrementValue
) &&
1555 !static_cast<Edit
*>(m_pActFocusWindow
.get())->GetSelected().isEmpty();
1559 bool OFieldDescControl::isPasteAllowed()
1561 bool bAllowed
= (m_pActFocusWindow
!= nullptr) &&
1562 (m_pActFocusWindow
== pDefault
|| m_pActFocusWindow
== pFormatSample
||
1563 m_pActFocusWindow
== pTextLen
|| m_pActFocusWindow
== pLength
||
1564 m_pActFocusWindow
== pScale
|| m_pActFocusWindow
== m_pColumnName
||
1565 m_pActFocusWindow
== m_pAutoIncrementValue
);
1568 TransferableDataHelper
aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
1569 bAllowed
= aTransferData
.HasFormat(SotClipboardFormatId::STRING
);
1574 void OFieldDescControl::cut()
1577 static_cast<Edit
*>(m_pActFocusWindow
.get())->Cut();
1580 void OFieldDescControl::copy()
1582 if(isCopyAllowed()) // this only checks if the focus window is valid
1583 static_cast<Edit
*>(m_pActFocusWindow
.get())->Copy();
1586 void OFieldDescControl::paste()
1588 if(m_pActFocusWindow
) // this only checks if the focus window is valid
1589 static_cast<Edit
*>(m_pActFocusWindow
.get())->Paste();
1592 bool OFieldDescControl::isTextFormat(const OFieldDescription
* _pFieldDescr
, sal_uInt32
& _nFormatKey
) const
1594 _nFormatKey
= _pFieldDescr
->GetFormatKey();
1595 bool bTextFormat
= true;
1601 Reference
< css::util::XNumberFormatTypes
> xNumberTypes(GetFormatter()->getNumberFormatsSupplier()->getNumberFormats(),UNO_QUERY
);
1602 OSL_ENSURE(xNumberTypes
.is(),"XNumberFormatTypes is null!");
1604 _nFormatKey
= ::dbtools::getDefaultNumberFormat( _pFieldDescr
->GetType(),
1605 _pFieldDescr
->GetScale(),
1606 _pFieldDescr
->IsCurrency(),
1610 sal_Int32 nNumberFormat
= ::comphelper::getNumberFormatType(GetFormatter(),_nFormatKey
);
1611 bTextFormat
= (nNumberFormat
== css::util::NumberFormat::TEXT
);
1613 catch(const Exception
&)
1621 OUString
OFieldDescControl::getControlDefault( const OFieldDescription
* _pFieldDescr
, bool _bCheck
) const
1624 bool bCheck
= !_bCheck
|| _pFieldDescr
->GetControlDefault().hasValue();
1627 sal_uInt32 nFormatKey
;
1631 double nValue
= 0.0;
1632 bool bTextFormat
= isTextFormat(_pFieldDescr
,nFormatKey
);
1633 if ( _pFieldDescr
->GetControlDefault() >>= sDefault
)
1637 if ( !sDefault
.isEmpty() )
1641 nValue
= GetFormatter()->convertStringToNumber(nFormatKey
,sDefault
);
1643 catch(const Exception
&)
1645 return OUString(); // return empty string for format example
1651 _pFieldDescr
->GetControlDefault() >>= nValue
;
1653 Reference
< css::util::XNumberFormatter
> xNumberFormatter
= GetFormatter();
1654 Reference
<XPropertySet
> xFormSet
= xNumberFormatter
->getNumberFormatsSupplier()->getNumberFormats()->getByKey(nFormatKey
);
1655 OSL_ENSURE(xFormSet
.is(),"XPropertySet is null!");
1657 xFormSet
->getPropertyValue("FormatString") >>= sFormat
;
1662 ::comphelper::getNumberFormatProperty(xNumberFormatter
,nFormatKey
,"Locale") >>= aLocale
;
1664 sal_Int32 nNumberFormat
= ::comphelper::getNumberFormatType(xNumberFormatter
,nFormatKey
);
1665 if( (nNumberFormat
& css::util::NumberFormat::DATE
) == css::util::NumberFormat::DATE
1666 || (nNumberFormat
& css::util::NumberFormat::DATETIME
) == css::util::NumberFormat::DATETIME
)
1668 nValue
= DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter
->getNumberFormatsSupplier()),nValue
);
1671 Reference
< css::util::XNumberFormatPreviewer
> xPreviewer(xNumberFormatter
,UNO_QUERY
);
1672 OSL_ENSURE(xPreviewer
.is(),"XNumberFormatPreviewer is null!");
1673 sDefault
= xPreviewer
->convertNumberToPreviewString(sFormat
,nValue
,aLocale
,true);
1675 else if ( !(_bCheck
&& sDefault
.isEmpty()) )
1676 sDefault
= xNumberFormatter
->formatString(nFormatKey
, sDefault
.isEmpty() ? sFormat
: sDefault
);
1678 catch(const Exception
&)
1687 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */