Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / control / FieldDescControl.cxx
blobbc1820e8a697f9e3ace48b30bf0d638efaa3cf1c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
29 #include <vector>
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
76 namespace
79 template< typename T1, typename T2> void lcl_HideAndDeleteControl(short& _nPos,VclPtr<T1>& _pControl, VclPtr<T2>& _pControlText)
81 if ( _pControl )
83 --_nPos;
84 _pControl->Hide();
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 )
96 ,pHelp( pHelpBar )
97 ,pLastFocusWindow(NULL)
98 ,m_pActFocusWindow(NULL)
99 ,pDefaultText(NULL)
100 ,pRequiredText(NULL)
101 ,pAutoIncrementText(NULL)
102 ,pTextLenText(NULL)
103 ,pNumTypeText(NULL)
104 ,pLengthText(NULL)
105 ,pScaleText(NULL)
106 ,pFormatText(NULL)
107 ,pBoolDefaultText(NULL)
108 ,m_pColumnNameText(NULL)
109 ,m_pTypeText(NULL)
110 ,m_pAutoIncrementValueText(NULL)
111 ,pRequired(NULL)
112 ,pNumType(NULL)
113 ,pAutoIncrement(NULL)
114 ,pDefault(NULL)
115 ,pTextLen(NULL)
116 ,pLength(NULL)
117 ,pScale(NULL)
118 ,pFormatSample(NULL)
119 ,pBoolDefault(NULL)
120 ,m_pColumnName(NULL)
121 ,m_pType(NULL)
122 ,m_pAutoIncrementValue(NULL)
123 ,pFormat(NULL)
124 ,m_pVertScroll( NULL )
125 ,m_pHorzScroll( NULL )
126 ,m_pPreviousType()
127 ,m_nPos(-1)
128 ,aYes(ModuleRes(STR_VALUE_YES))
129 ,aNo(ModuleRes(STR_VALUE_NO))
130 ,m_nOldVThumb( 0 )
131 ,m_nOldHThumb( 0 )
132 ,m_nWidth(50)
133 ,m_bAdded(false)
134 ,m_bRightAligned(false)
135 ,pActFieldDescr(NULL)
137 Contruct();
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()
162 disposeOnce();
165 void OFieldDescControl::dispose()
167 if ( m_bAdded )
168 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
170 // Destroy children
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 );
183 pHelp.clear();
184 pLastFocusWindow.clear();
185 m_pActFocusWindow.clear();
186 pDefaultText.clear();
187 pRequiredText.clear();
188 pAutoIncrementText.clear();
189 pTextLenText.clear();
190 pNumTypeText.clear();
191 pLengthText.clear();
192 pScaleText.clear();
193 pFormatText.clear();
194 pBoolDefaultText.clear();
195 m_pColumnNameText.clear();
196 m_pTypeText.clear();
197 m_pAutoIncrementValueText.clear();
198 pRequired.clear();
199 pNumType.clear();
200 pAutoIncrement.clear();
201 pDefault.clear();
202 pTextLen.clear();
203 pLength.clear();
204 pScale.clear();
205 pFormatSample.clear();
206 pBoolDefault.clear();
207 m_pColumnName.clear();
208 m_pType.clear();
209 m_pAutoIncrementValue.clear();
210 pFormat.clear();
211 m_pVertScroll.disposeAndClear();
212 m_pHorzScroll.disposeAndClear();
213 TabPage::dispose();
216 OUString OFieldDescControl::BoolStringPersistent(const OUString& rUIString) const
218 if (rUIString == aNo)
219 return OUString('0');
220 if (rUIString == aYes)
221 return OUString('1');
222 return OUString();
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'))
232 return aNo;
233 if (comphelper::string::equals(rPersistentString, '1'))
234 return aYes;
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();
248 return 0;
251 namespace
253 void getMaxXPosition(vcl::Window* _pWindow,long& _rnMaxXPosition)
255 if (_pWindow)
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);
275 // Adjust the areas
276 // Do I actually need ScrollBars?
277 // horizontal :
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;
287 // Might change
289 // Vertical
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();
296 if (bNeedHScrollBar)
297 nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y - nHScrollHeight) / (nControl_Spacing_y + nControlHeight));
298 else
299 nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y) / (nControl_Spacing_y + nControlHeight));
300 bNeedVScrollBar = nActive>nLastVisible;
302 if (bNeedVScrollBar)
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
317 if (bNeedVScrollBar)
319 m_pVertScroll->Show();
320 m_pVertScroll->SetRangeMax(nActive - nLastVisible);
322 m_pVertScroll->SetPosSizePixel( Point(nNewHWidth, 0), Size(nVScrollWidth, szOverallSize.Height()) );
324 else
326 m_pVertScroll->Hide();
327 m_pVertScroll->SetRangeMax(0);
328 m_pVertScroll->SetThumbPos(0);
331 if (bNeedHScrollBar)
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) );
338 else
340 m_pHorzScroll->Hide();
341 m_pHorzScroll->SetRangeMax(0);
342 m_pHorzScroll->SetThumbPos(0);
346 void OFieldDescControl::Resize()
348 CheckScrollBars();
349 ScrollAllAggregates();
352 inline void OFieldDescControl::ScrollAggregate(Control* pText, Control* pInput, Control* pButton, long nDeltaX, long nDeltaY)
354 if (!pText)
355 return;
356 pText->SetPosPixel(pText->GetPosPixel() + Point(nDeltaX, nDeltaY));
357 pInput->SetPosPixel(pInput->GetPosPixel() + Point(nDeltaX, nDeltaY));
358 if (pButton)
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
383 , pTextLen, pLength
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)
405 if (ppAggregates[i])
406 ++nVisibleAggregates;
407 return nVisibleAggregates;
410 sal_Int32 OFieldDescControl::GetMaxControlHeight() const
412 Size aHeight;
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
432 , pTextLen, pLength
433 , pScale, m_pColumnName
434 , m_pType, m_pAutoIncrementValue
435 , pFormat};
436 Control* ppAggregatesText[] = { pRequiredText, pNumTypeText
437 , pAutoIncrementText, pDefaultText
438 , pTextLenText, pLengthText
439 , pScaleText, m_pColumnNameText
440 , m_pTypeText, m_pAutoIncrementValueText
441 , pFormatText};
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
457 switch( nControlId )
459 case FIELD_PROPERTY_BOOL_DEFAULT:
460 if (pBoolDefault)
461 return pBoolDefault->GetSelectEntry();
462 break;
463 case FIELD_PROPERTY_DEFAULT:
464 if (pDefault)
465 return pDefault->GetText();
466 break;
467 case FIELD_PROPERTY_REQUIRED:
468 if (pRequired)
469 return pRequired->GetSelectEntry();
470 break;
471 case FIELD_PROPERTY_TEXTLEN:
472 if (pTextLen)
473 return OUString::number(pTextLen->GetValue());
474 break;
475 case FIELD_PROPERTY_NUMTYPE:
476 if (pNumType)
477 return pNumType->GetSelectEntry();
478 break;
479 case FIELD_PROPERTY_AUTOINC:
480 if (pAutoIncrement)
481 return pAutoIncrement->GetSelectEntry();
482 break;
483 case FIELD_PROPERTY_LENGTH:
484 if (pLength)
485 return pLength->GetText();
486 break;
487 case FIELD_PROPERTY_SCALE:
488 if (pScale)
489 return pScale->GetText();
490 break;
491 case FIELD_PROPERTY_FORMAT:
492 if (pFormatSample)
493 return pFormatSample->GetText();
494 break;
495 case FIELD_PROPERTY_COLUMNNAME:
496 if(m_pColumnName)
497 return m_pColumnName->GetText();
498 break;
499 case FIELD_PROPERTY_TYPE:
500 if(m_pType)
501 return m_pType->GetSelectEntry();
502 break;
503 case FIELD_PROPERTY_AUTOINCREMENT:
504 if(m_pAutoIncrementValue)
505 return m_pAutoIncrementValue->GetText();
508 return OUString();
511 void OFieldDescControl::SetControlText( sal_uInt16 nControlId, const OUString& rText )
513 // Set the Controls' texts
514 switch( nControlId )
516 case FIELD_PROPERTY_BOOL_DEFAULT:
517 if (pBoolDefault)
519 OUString sOld = pBoolDefault->GetSelectEntry();
520 pBoolDefault->SelectEntry(rText);
521 if (sOld != rText)
522 LINK(this, OFieldDescControl, ChangeHdl).Call(pBoolDefault);
524 break;
525 case FIELD_PROPERTY_DEFAULT:
526 if (pDefault)
528 pDefault->SetText(rText);
529 UpdateFormatSample(pActFieldDescr);
531 break;
533 case FIELD_PROPERTY_REQUIRED:
534 if (pRequired)
535 pRequired->SelectEntry(rText);
536 break;
538 case FIELD_PROPERTY_TEXTLEN:
539 if (pTextLen)
540 pTextLen->SetText(rText);
541 break;
543 case FIELD_PROPERTY_NUMTYPE:
544 if (pNumType)
545 pNumType->SelectEntry(rText);
546 break;
548 case FIELD_PROPERTY_AUTOINC:
549 if (pAutoIncrement)
551 OUString sOld = pAutoIncrement->GetSelectEntry();
552 pAutoIncrement->SelectEntry(rText);
553 if (sOld != rText)
554 LINK(this, OFieldDescControl, ChangeHdl).Call(pAutoIncrement);
556 break;
558 case FIELD_PROPERTY_LENGTH:
559 if (pLength)
560 pLength->SetText(rText);
561 break;
563 case FIELD_PROPERTY_SCALE:
564 if (pScale)
565 pScale->SetText(rText);
566 break;
568 case FIELD_PROPERTY_FORMAT:
569 if (pActFieldDescr)
570 UpdateFormatSample(pActFieldDescr);
571 break;
572 case FIELD_PROPERTY_COLUMNNAME:
573 if(m_pColumnName)
574 m_pColumnName->SetText(rText);
575 break;
576 case FIELD_PROPERTY_TYPE:
577 if(m_pType)
578 m_pType->SelectEntry(rText);
579 break;
580 case FIELD_PROPERTY_AUTOINCREMENT:
581 if(m_pAutoIncrementValue)
582 m_pAutoIncrementValue->SetText(rText);
583 break;
587 IMPL_LINK( OFieldDescControl, FormatClickHdl, Button *, /*pButton*/ )
589 // Create temporary Column, which is used for data exchange with Dialog
590 if( !pActFieldDescr )
591 return 0;
593 sal_Int32 nOldFormatKey(pActFieldDescr->GetFormatKey());
594 SvxCellHorJustify rOldJustify = pActFieldDescr->GetHorJustify();
595 Reference< XNumberFormatsSupplier > xSupplier = GetFormatter()->getNumberFormatsSupplier();
596 SvNumberFormatsSupplierObj* pSupplierImpl = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
597 if (!pSupplierImpl)
598 return 0;
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 );
607 bModified = true;
609 if(rOldJustify != pActFieldDescr->GetHorJustify())
611 pActFieldDescr->SetHorJustify( rOldJustify );
612 bModified = true;
615 if(bModified)
617 SetModified(true);
618 UpdateFormatSample(pActFieldDescr);
621 return 0;
624 void OFieldDescControl::SetModified(bool /*bModified*/)
628 IMPL_LINK( OFieldDescControl, ChangeHdl, ListBox *, pListBox )
630 if ( !pActFieldDescr )
631 return 0;
633 if ( pListBox->IsValueChangedFromSaved() )
634 SetModified(true);
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
647 else
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)
661 { // no
662 DeactivateAggregate( tpAutoIncrementValue );
663 if(pActFieldDescr->IsPrimaryKey())
664 DeactivateAggregate( tpRequired );
665 else if( pActFieldDescr->getTypeInfo()->bNullable )
667 ActivateAggregate( tpRequired );
668 if(pRequired)
670 if( pActFieldDescr->IsNullable() )
671 pRequired->SelectEntryPos( 1 ); // no
672 else
673 pRequired->SelectEntryPos( 0 ); // yes
676 ActivateAggregate( tpDefault );
678 else
680 DeactivateAggregate( tpRequired );
681 DeactivateAggregate( tpDefault );
682 ActivateAggregate( tpAutoIncrementValue );
684 // Move all up
685 ArrangeAggregates();
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());
697 return 0;
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 },
726 long nMaxWidth = 0;
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!");
737 // And go ...
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
763 if (pFormat)
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 )
777 // Create Controls
778 switch( eType )
780 case tpDefault:
781 if( pDefault )
782 return;
783 m_nPos++;
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);
787 break;
788 case tpAutoIncrementValue:
789 if( m_pAutoIncrementValue || !isAutoIncrementValueEnabled() )
790 return;
791 m_nPos++;
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);
796 break;
798 case tpRequired:
800 if( pRequired )
801 return;
802 Reference< XDatabaseMetaData> xMetaData = getMetaData();
804 if(xMetaData.is() && xMetaData->supportsNonNullableColumns())
806 m_nPos++;
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);
817 break;
818 case tpAutoIncrement:
820 if( pAutoIncrement )
821 return;
822 m_nPos++;
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);
830 break;
831 case tpTextLen:
832 if( pTextLen )
833 return;
834 m_nPos++;
835 pTextLenText = CreateText(STR_TEXT_LENGTH);
836 pTextLen = CreateNumericControl(STR_HELP_TEXT_LENGTH, FIELD_PROPERTY_TEXTLEN,HID_TAB_ENT_TEXT_LEN);
837 break;
839 case tpType:
840 if( m_pType)
841 return;
842 m_nPos++;
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);
855 break;
856 case tpColumnName:
857 if( m_pColumnName )
858 return;
859 m_nPos++;
861 sal_Int32 nMax = EDIT_NOLIMIT;
862 OUString aTmpString;
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,
878 aTmpString,
879 STR_HELP_DEFAULT_VALUE,
880 FIELD_PROPERTY_COLUMNNAME,
881 WB_BORDER );
882 m_pColumnName->SetMaxTextLen(nMax ? nMax : EDIT_NOLIMIT);
883 m_pColumnName->setCheck( isSQL92CheckEnabled(getConnection()) );
886 InitializeControl(m_pColumnName,HID_TAB_ENT_COLUMNNAME,false);
887 break;
888 case tpNumType:
889 if( pNumType )
890 return;
891 m_nPos++;
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);
904 break;
906 case tpLength:
907 if( pLength )
908 return;
909 m_nPos++;
910 pLengthText = CreateText(STR_LENGTH);
911 pLength = CreateNumericControl(STR_HELP_LENGTH, FIELD_PROPERTY_LENGTH,HID_TAB_ENT_LEN);
912 break;
914 case tpScale:
915 if( pScale )
916 return;
917 m_nPos++;
918 pScaleText = CreateText(STR_SCALE);
919 pScale = CreateNumericControl(STR_HELP_SCALE, FIELD_PROPERTY_SCALE,HID_TAB_ENT_SCALE);
920 break;
922 case tpFormat:
923 if (!pFormat)
925 m_nPos++;
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);
941 break;
942 case tpBoolDefault:
943 if (pBoolDefault)
944 return;
946 m_nPos++;
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);
955 break;
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();
975 return pFixedText;
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);
982 pControl->SetMin(0);
983 pControl->SetMax(0x7FFFFFFF); // Should be changed outside, if needed
984 pControl->SetStrictFormat(true);
986 InitializeControl(pControl,_sHelpId,false);
988 return pControl;
991 void OFieldDescControl::DeactivateAggregate( EControlType eType )
993 pLastFocusWindow = NULL;
994 // Destroy Controls
995 switch( eType )
997 case tpDefault:
998 lcl_HideAndDeleteControl(m_nPos,pDefault,pDefaultText);
999 break;
1001 case tpAutoIncrementValue:
1002 lcl_HideAndDeleteControl(m_nPos,m_pAutoIncrementValue,m_pAutoIncrementValueText);
1003 break;
1005 case tpColumnName:
1006 lcl_HideAndDeleteControl(m_nPos,m_pColumnName,m_pColumnNameText);
1007 break;
1009 case tpType:
1010 lcl_HideAndDeleteControl(m_nPos,m_pType,m_pTypeText);
1011 break;
1013 case tpAutoIncrement:
1014 lcl_HideAndDeleteControl(m_nPos,pAutoIncrement,pAutoIncrementText);
1015 break;
1017 case tpRequired:
1018 lcl_HideAndDeleteControl(m_nPos,pRequired,pRequiredText);
1019 break;
1021 case tpTextLen:
1022 lcl_HideAndDeleteControl(m_nPos,pTextLen,pTextLenText);
1023 break;
1025 case tpNumType:
1026 lcl_HideAndDeleteControl(m_nPos,pNumType,pNumTypeText);
1027 break;
1029 case tpLength:
1030 lcl_HideAndDeleteControl(m_nPos,pLength,pLengthText);
1031 break;
1033 case tpScale:
1034 lcl_HideAndDeleteControl(m_nPos,pScale,pScaleText);
1035 break;
1037 case tpFormat:
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();
1045 break;
1046 case tpBoolDefault:
1047 lcl_HideAndDeleteControl(m_nPos,pBoolDefault,pBoolDefaultText);
1048 break;
1052 void OFieldDescControl::SetPosSize( VclPtr<Control>& rControl, long nRow, sal_uInt16 nCol )
1055 // Calculate size
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();
1060 else
1062 switch( nCol )
1064 case 0:
1065 default:
1066 aSize.Width() = CONTROL_WIDTH_1;
1067 break;
1068 case 1:
1069 aSize.Width() = CONTROL_WIDTH_2;
1070 break;
1071 case 3:
1072 aSize.Width() = CONTROL_WIDTH_3;
1073 break;
1074 case 4:
1075 aSize.Width() = CONTROL_WIDTH_4;
1076 break;
1080 // Calculate Position
1081 Point aPosition;
1082 switch( nCol )
1084 case 0:
1085 aPosition.X() = 0;
1086 aPosition.Y() = 1;
1087 break;
1088 case 1:
1089 case 3:
1090 case 4:
1091 if ( isRightAligned() )
1093 Size aOwnSize = GetSizePixel();
1094 aPosition.X() = aOwnSize.Width() - aSize.Width();
1096 else
1097 aPosition.X() = CONTROL_WIDTH_1 + CONTROL_SPACING_X;
1098 break;
1099 default:
1100 aPosition.X() = 0;
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);
1110 // Display Control
1111 rControl->SetPosSizePixel( aPosition, aSize );
1112 aSize = rControl->GetSizePixel();
1114 rControl->Show();
1117 void OFieldDescControl::DisplayData(OFieldDescription* pFieldDescr )
1119 pActFieldDescr = pFieldDescr;
1120 if(!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;
1137 if ( m_bAdded )
1139 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
1140 m_bAdded = false;
1142 return;
1145 if ( !m_bAdded )
1147 ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::AddWindow));
1148 m_bAdded = true;
1151 TOTypeInfoSP pFieldType;
1152 if( pFieldDescr )
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 );
1173 else
1174 DeactivateAggregate( tpRequired );
1176 // 2. the autoincrement
1177 if ( pFieldType->bAutoIncrement )
1179 DeactivateAggregate( tpRequired );
1180 DeactivateAggregate( tpDefault );
1181 ActivateAggregate( tpAutoIncrement );
1182 ActivateAggregate( tpAutoIncrementValue );
1184 else
1186 DeactivateAggregate( tpAutoIncrement );
1187 DeactivateAggregate( tpAutoIncrementValue );
1188 if(pFieldType->bNullable)
1189 ActivateAggregate( tpRequired );
1190 else
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());
1201 else
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);
1212 else
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());
1232 else
1233 DeactivateAggregate( tpTextLen );
1234 break;
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 );
1244 break;
1245 case DataType::BIT:
1246 if ( !pFieldType->aCreateParams.isEmpty() )
1248 DeactivateAggregate( tpFormat );
1249 DeactivateAggregate( tpTextLen );
1250 DeactivateAggregate( tpBoolDefault );
1251 break;
1253 // run through
1254 case DataType::BOOLEAN:
1255 DeactivateAggregate( tpTextLen );
1256 DeactivateAggregate( tpFormat );
1257 DeactivateAggregate( tpDefault );
1259 ActivateAggregate( tpBoolDefault );
1260 break;
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 );
1274 break;
1275 case DataType::BINARY:
1276 case DataType::VARBINARY:
1277 DeactivateAggregate( tpDefault );
1278 DeactivateAggregate( tpRequired );
1279 DeactivateAggregate( tpTextLen );
1280 DeactivateAggregate( tpBoolDefault );
1282 ActivateAggregate( tpFormat );
1283 break;
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:
1292 case DataType::REF:
1293 case DataType::OTHER:
1294 DeactivateAggregate( tpFormat );
1295 DeactivateAggregate( tpTextLen );
1296 DeactivateAggregate( tpBoolDefault );
1298 break;
1299 default:
1300 OSL_FAIL("Unknown type");
1302 m_pPreviousType = pFieldType;
1304 if(pFieldDescr)
1306 if(pFieldDescr->IsPrimaryKey())
1308 DeactivateAggregate( tpRequired );
1310 else if ( !pAutoIncrement && pFieldType.get() )
1312 if ( pFieldType->bNullable )
1313 ActivateAggregate( tpRequired );
1314 else
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 );
1330 else
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 );
1342 if( pDefault )
1344 pDefault->SetText( getControlDefault(pFieldDescr) );
1345 pDefault->ClearModifyFlag();
1348 if( pBoolDefault )
1350 // If pRequired = sal_True then the sal_Bool field must NOT contain <<none>>
1351 OUString sValue;
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
1363 else
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);
1373 else
1374 pBoolDefault->SelectEntry(sDef);
1377 if( pRequired )
1379 if( pFieldDescr->IsNullable() )
1380 pRequired->SelectEntryPos( 1 ); // no
1381 else
1382 pRequired->SelectEntryPos( 0 ); // yes
1385 if( pTextLen )
1387 pTextLen->SetText( OUString::number(pFieldDescr->GetPrecision()) );
1388 pTextLen->ClearModifyFlag();
1391 if( pNumType )
1393 OSL_FAIL("OFieldDescControl::DisplayData: invalid num type!");
1396 if( pLength )
1397 pLength->SetText( OUString::number(pFieldDescr->GetPrecision()) );
1399 if( pScale )
1400 pScale->SetText( OUString::number(pFieldDescr->GetScale()) );
1402 if( pFormat )
1403 UpdateFormatSample(pFieldDescr);
1405 if(m_pColumnName)
1406 m_pColumnName->SetText(pFieldDescr->GetName());
1408 if(m_pType)
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();
1439 CheckScrollBars();
1440 ScrollAllAggregates();
1442 SetReadOnly( bRead );
1445 IMPL_LINK(OFieldDescControl, OnControlFocusGot, Control*, pControl )
1447 OUString strHelpText;
1448 OPropNumericEditCtrl* pNumeric = dynamic_cast< OPropNumericEditCtrl* >( pControl );
1449 if ( pNumeric )
1451 pNumeric->SaveValue();
1452 strHelpText = pNumeric->GetHelp();
1455 OPropColumnEditCtrl* pColumn = dynamic_cast< OPropColumnEditCtrl* >( pControl );
1456 if ( pColumn )
1458 pColumn->SaveValue();
1459 strHelpText = pColumn->GetHelp();
1462 OPropEditCtrl* pEdit = dynamic_cast< OPropEditCtrl* >( pControl );
1463 if ( pEdit )
1465 pEdit->SaveValue();
1466 strHelpText = pEdit->GetHelp();
1469 OPropListBoxCtrl* pListBox = dynamic_cast< OPropListBoxCtrl* >( pControl );
1470 if ( pListBox )
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;
1484 return 0L;
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);
1519 return 0L;
1522 void OFieldDescControl::SaveData( OFieldDescription* pFieldDescr )
1524 if( !pFieldDescr )
1525 return;
1527 // Read out Controls
1528 OUString sDefault;
1529 if (pDefault)
1531 sDefault = pDefault->GetText();
1533 else if (pBoolDefault)
1535 sDefault = BoolStringPersistent(pBoolDefault->GetSelectEntry());
1538 if ( !sDefault.isEmpty() )
1539 pFieldDescr->SetControlDefault(makeAny(sDefault));
1540 else
1541 pFieldDescr->SetControlDefault(Any());
1543 if((pRequired && pRequired->GetSelectEntryPos() == 0) || pFieldDescr->IsPrimaryKey() || (pBoolDefault && pBoolDefault->GetEntryCount() == 2)) // yes
1544 pFieldDescr->SetIsNullable( ColumnValue::NO_NULLS );
1545 else
1546 pFieldDescr->SetIsNullable( ColumnValue::NULLABLE );
1548 if ( pAutoIncrement )
1549 pFieldDescr->SetAutoIncrement( pAutoIncrement->GetSelectEntryPos() == 0 );
1551 if( pTextLen )
1552 pFieldDescr->SetPrecision( static_cast<sal_Int32>(pTextLen->GetValue()) );
1553 else if( pLength )
1554 pFieldDescr->SetPrecision( static_cast<sal_Int32>(pLength->GetValue()) );
1555 if( pScale )
1556 pFieldDescr->SetScale( static_cast<sal_Int32>(pScale->GetValue()) );
1558 if(m_pColumnName)
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;
1590 // Reset HelpText
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();
1611 return bAllowed;
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();
1622 return bAllowed;
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);
1632 if ( bAllowed )
1634 TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
1635 bAllowed = aTransferData.HasFormat(SotClipboardFormatId::STRING);
1637 return bAllowed;
1640 void OFieldDescControl::cut()
1642 if(isCutAllowed())
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;
1665 if (!_nFormatKey)
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(),
1673 xNumberTypes,
1674 GetLocale());
1676 sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(GetFormatter(),_nFormatKey);
1677 bTextFormat = (nNumberFormat == ::com::sun::star::util::NumberFormat::TEXT);
1679 catch(const Exception&)
1684 return bTextFormat;
1687 OUString OFieldDescControl::getControlDefault( const OFieldDescription* _pFieldDescr, bool _bCheck) const
1689 OUString sDefault;
1690 bool bCheck = !_bCheck || _pFieldDescr->GetControlDefault().hasValue();
1691 if ( bCheck )
1693 sal_uInt32 nFormatKey;
1697 double nValue = 0.0;
1698 bool bTextFormat = isTextFormat(_pFieldDescr,nFormatKey);
1699 if ( _pFieldDescr->GetControlDefault() >>= sDefault )
1701 if ( !bTextFormat )
1703 if ( !sDefault.isEmpty() )
1707 nValue = GetFormatter()->convertStringToNumber(nFormatKey,sDefault);
1709 catch(const Exception&)
1711 return OUString(); // return empty string for format example
1716 else
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!");
1722 OUString sFormat;
1723 xFormSet->getPropertyValue("FormatString") >>= sFormat;
1725 if ( !bTextFormat )
1727 Locale aLocale;
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&)
1750 return sDefault;
1753 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */