LCOV - code coverage report
Current view: top level - dbaccess/source/ui/control - FieldDescControl.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 910 0.1 %
Date: 2014-04-11 Functions: 2 57 3.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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>
      57             : 
      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;
      65             : 
      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)
      73             : 
      74             : #define HSCROLL_STEP        20
      75             : 
      76             : namespace
      77             : {
      78             : 
      79           0 :     template< typename T1, typename T2> void lcl_HideAndDeleteControl(short& _nPos,T1** _pControl,T2** _pControlText)
      80             :     {
      81           0 :         if ( *_pControl )
      82             :         {
      83           0 :             --_nPos;
      84           0 :             (*_pControl)->Hide();
      85           0 :             (*_pControlText)->Hide();
      86           0 :             delete *_pControl;
      87           0 :             delete *_pControlText;
      88           0 :             (*_pControl) = NULL;
      89           0 :             (*_pControlText) = NULL;
      90             :         }
      91           0 :     }
      92             : 
      93             : }
      94             : 
      95             : // class OFieldDescControl
      96             : 
      97             : 
      98           0 : OFieldDescControl::OFieldDescControl( Window* pParent, const ResId& rResId, OTableDesignHelpBar* pHelpBar)
      99             :     :TabPage( pParent, rResId )
     100             :     ,pHelp( pHelpBar )
     101             :     ,pLastFocusWindow(NULL)
     102             :     ,m_pActFocusWindow(NULL)
     103             :     ,pDefaultText(NULL)
     104             :     ,pRequiredText(NULL)
     105             :     ,pAutoIncrementText(NULL)
     106             :     ,pTextLenText(NULL)
     107             :     ,pNumTypeText(NULL)
     108             :     ,pLengthText(NULL)
     109             :     ,pScaleText(NULL)
     110             :     ,pFormatText(NULL)
     111             :     ,pBoolDefaultText(NULL)
     112             :     ,m_pColumnNameText(NULL)
     113             :     ,m_pTypeText(NULL)
     114             :     ,m_pAutoIncrementValueText(NULL)
     115             :     ,pRequired(NULL)
     116             :     ,pNumType(NULL)
     117             :     ,pAutoIncrement(NULL)
     118             :     ,pDefault(NULL)
     119             :     ,pTextLen(NULL)
     120             :     ,pLength(NULL)
     121             :     ,pScale(NULL)
     122             :     ,pFormatSample(NULL)
     123             :     ,pBoolDefault(NULL)
     124             :     ,m_pColumnName(NULL)
     125             :     ,m_pType(NULL)
     126             :     ,m_pAutoIncrementValue(NULL)
     127             :     ,pFormat(NULL)
     128             :     ,m_pVertScroll( NULL )
     129             :     ,m_pHorzScroll( NULL )
     130             :     ,m_pPreviousType()
     131             :     ,m_nPos(-1)
     132             :     ,aYes(ModuleRes(STR_VALUE_YES))
     133             :     ,aNo(ModuleRes(STR_VALUE_NO))
     134             :     ,m_nOldVThumb( 0 )
     135             :     ,m_nOldHThumb( 0 )
     136             :     ,m_nWidth(50)
     137             :     ,m_bAdded(sal_False)
     138             :     ,m_bRightAligned(false)
     139           0 :     ,pActFieldDescr(NULL)
     140             : {
     141             : 
     142           0 :     Contruct();
     143           0 : }
     144             : 
     145           0 : OFieldDescControl::OFieldDescControl( Window* pParent, OTableDesignHelpBar* pHelpBar )
     146             :     :TabPage( pParent, WB_3DLOOK | WB_DIALOGCONTROL )
     147             :     ,pHelp( pHelpBar )
     148             :     ,pLastFocusWindow(NULL)
     149             :     ,m_pActFocusWindow(NULL)
     150             :     ,pDefaultText(NULL)
     151             :     ,pRequiredText(NULL)
     152             :     ,pAutoIncrementText(NULL)
     153             :     ,pTextLenText(NULL)
     154             :     ,pNumTypeText(NULL)
     155             :     ,pLengthText(NULL)
     156             :     ,pScaleText(NULL)
     157             :     ,pFormatText(NULL)
     158             :     ,pBoolDefaultText(NULL)
     159             :     ,m_pColumnNameText(NULL)
     160             :     ,m_pTypeText(NULL)
     161             :     ,m_pAutoIncrementValueText(NULL)
     162             :     ,pRequired(NULL)
     163             :     ,pNumType(NULL)
     164             :     ,pAutoIncrement(NULL)
     165             :     ,pDefault(NULL)
     166             :     ,pTextLen(NULL)
     167             :     ,pLength(NULL)
     168             :     ,pScale(NULL)
     169             :     ,pFormatSample(NULL)
     170             :     ,pBoolDefault(NULL)
     171             :     ,m_pColumnName(NULL)
     172             :     ,m_pType(NULL)
     173             :     ,m_pAutoIncrementValue(NULL)
     174             :     ,pFormat(NULL)
     175             :     ,m_pVertScroll( NULL )
     176             :     ,m_pHorzScroll( NULL )
     177             :     ,m_pPreviousType()
     178             :     ,m_nPos(-1)
     179             :     ,aYes(ModuleRes(STR_VALUE_YES))
     180             :     ,aNo(ModuleRes(STR_VALUE_NO))
     181             :     ,m_nOldVThumb( 0 )
     182             :     ,m_nOldHThumb( 0 )
     183             :     ,m_nWidth(50)
     184             :     ,m_bAdded(sal_False)
     185             :     ,m_bRightAligned(false)
     186           0 :     ,pActFieldDescr(NULL)
     187             : {
     188           0 :     Contruct();
     189           0 : }
     190             : 
     191           0 : void OFieldDescControl::Contruct()
     192             : {
     193           0 :     m_pVertScroll = new ScrollBar(this, WB_VSCROLL | WB_REPEAT | WB_DRAG);
     194           0 :     m_pHorzScroll = new ScrollBar(this, WB_HSCROLL | WB_REPEAT | WB_DRAG);
     195           0 :     m_pVertScroll->SetScrollHdl(LINK(this, OFieldDescControl, OnScroll));
     196           0 :     m_pHorzScroll->SetScrollHdl(LINK(this, OFieldDescControl, OnScroll));
     197           0 :     m_pVertScroll->Show();
     198           0 :     m_pHorzScroll->Show();
     199             : 
     200           0 :     m_pVertScroll->EnableClipSiblings();
     201           0 :     m_pHorzScroll->EnableClipSiblings();
     202             : 
     203           0 :     m_pVertScroll->SetLineSize(1);
     204           0 :     m_pVertScroll->SetPageSize(1);
     205           0 :     m_pHorzScroll->SetLineSize(1);
     206           0 :     m_pHorzScroll->SetPageSize(1);
     207             : 
     208           0 :     m_nOldVThumb = m_nOldHThumb = 0;
     209           0 : }
     210             : 
     211           0 : OFieldDescControl::~OFieldDescControl()
     212             : {
     213             : 
     214             :     {
     215           0 :         boost::scoped_ptr<Window> aTemp(m_pVertScroll);
     216           0 :         m_pVertScroll    = NULL;
     217             :     }
     218             :     {
     219           0 :         boost::scoped_ptr<Window> aTemp(m_pHorzScroll);
     220           0 :         m_pHorzScroll    = NULL;
     221             :     }
     222           0 :     if ( m_bAdded )
     223           0 :         ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
     224           0 :     pLastFocusWindow = NULL;
     225             : 
     226             :     // Destroy children
     227           0 :     DeactivateAggregate( tpDefault );
     228           0 :     DeactivateAggregate( tpRequired );
     229           0 :     DeactivateAggregate( tpTextLen );
     230           0 :     DeactivateAggregate( tpNumType );
     231           0 :     DeactivateAggregate( tpScale );
     232           0 :     DeactivateAggregate( tpLength );
     233           0 :     DeactivateAggregate( tpFormat );
     234           0 :     DeactivateAggregate( tpAutoIncrement );
     235           0 :     DeactivateAggregate( tpBoolDefault );
     236           0 :     DeactivateAggregate( tpColumnName );
     237           0 :     DeactivateAggregate( tpType );
     238           0 :     DeactivateAggregate( tpAutoIncrementValue );
     239           0 : }
     240             : 
     241           0 : OUString OFieldDescControl::BoolStringPersistent(const OUString& rUIString) const
     242             : {
     243           0 :     if (rUIString == aNo)
     244           0 :         return OUString('0');
     245           0 :     if (rUIString == aYes)
     246           0 :         return OUString('1');
     247           0 :     return OUString();
     248             : }
     249             : 
     250           0 : OUString OFieldDescControl::BoolStringUI(const OUString& rPersistentString) const
     251             : {
     252             :     // Older versions may store a language dependend string as a default
     253           0 :     if (rPersistentString == aYes || rPersistentString == aNo)
     254           0 :         return rPersistentString;
     255             : 
     256           0 :     if (comphelper::string::equals(rPersistentString, '0'))
     257           0 :         return aNo;
     258           0 :     if (comphelper::string::equals(rPersistentString, '1'))
     259           0 :         return aYes;
     260             : 
     261           0 :     return ModuleRes(STR_VALUE_NONE).toString();
     262             : }
     263             : 
     264           0 : void OFieldDescControl::Init()
     265             : {
     266           0 :     Reference< ::com::sun::star::util::XNumberFormatter > xFormatter = GetFormatter();
     267           0 :     ::dbaui::setEvalDateFormatForFormatter(xFormatter);
     268           0 : }
     269             : 
     270           0 : IMPL_LINK(OFieldDescControl, OnScroll, ScrollBar*, /*pBar*/)
     271             : {
     272           0 :     ScrollAllAggregates();
     273           0 :     return 0;
     274             : }
     275             : 
     276             : namespace
     277             : {
     278           0 :     void getMaxXPosition(Window* _pWindow,long& _rnMaxXPosition)
     279             :     {
     280           0 :         if (_pWindow)
     281             :         {
     282           0 :             long nTemp = _pWindow->GetSizePixel().Width() + _pWindow->GetPosPixel().X();
     283           0 :             _rnMaxXPosition = ::std::max(_rnMaxXPosition, nTemp);
     284             :         }
     285           0 :     }
     286             : }
     287             : 
     288           0 : void OFieldDescControl::CheckScrollBars()
     289             : {
     290             :     // Calculate the ScrollBars' new position
     291           0 :     Size szOverallSize = GetSizePixel();
     292           0 :     long nHScrollHeight = m_pHorzScroll->GetSizePixel().Height();
     293           0 :     long nVScrollWidth = m_pVertScroll->GetSizePixel().Width();
     294             : 
     295           0 :     long nNewHWidth = szOverallSize.Width() - nVScrollWidth;
     296           0 :     long nNewVHeight = szOverallSize.Height() - nHScrollHeight;
     297             : 
     298           0 :     sal_Bool bNeedHScrollBar(sal_False), bNeedVScrollBar(sal_False);
     299             : 
     300             :     // Adjust the areas
     301             :     // Do I actually need ScrollBars?
     302             :     // horizontal :
     303           0 :     long lMaxXPosition = 0;
     304           0 :     Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
     305           0 :     for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
     306           0 :         getMaxXPosition(ppAggregates[i],lMaxXPosition);
     307             : 
     308           0 :     lMaxXPosition += m_pHorzScroll->GetThumbPos() * HSCROLL_STEP;
     309             : 
     310           0 :     long lMaxXAvailable = szOverallSize.Width();
     311           0 :     bNeedHScrollBar = lMaxXPosition > lMaxXAvailable;
     312             :         // Might change
     313             : 
     314             :     // Vertical
     315             :     // How many Controls do I have?
     316           0 :     sal_uInt16 nActive = CountActiveAggregates();
     317             :     // Which one is the last one that fits?
     318             :     sal_uInt16 nLastVisible;
     319           0 :     const sal_Int32 nControlHeight = GetMaxControlHeight();
     320           0 :     const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
     321           0 :     if (bNeedHScrollBar)
     322           0 :         nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y - nHScrollHeight) / (nControl_Spacing_y + nControlHeight));
     323             :     else
     324           0 :         nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y) / (nControl_Spacing_y + nControlHeight));
     325           0 :     bNeedVScrollBar = nActive>nLastVisible;
     326             : 
     327           0 :     if (bNeedVScrollBar)
     328             :     {
     329             :         // When originally calculating lMaxXAvailable we did not take into account that we have a VScrollBar, so we need to do that now
     330           0 :         lMaxXAvailable -= nVScrollWidth;
     331           0 :         if (!bNeedHScrollBar && (lMaxXPosition > lMaxXAvailable))
     332             :         {
     333             :             // The vertical one now necessitates a horizontal one
     334           0 :             bNeedHScrollBar = sal_True;
     335             :             // Adjust nLastVisible
     336           0 :             nLastVisible = static_cast<sal_uInt16>((szOverallSize.Height() - nControl_Spacing_y - nHScrollHeight) / (nControl_Spacing_y + nControlHeight));
     337             :                 // bNeedVScrollBar does NOT change: it's already set to sal_True and nLastVisible will only decrease
     338             :         }
     339             :     }
     340             : 
     341             :     // Now we can really position them and set their parameters
     342           0 :     if (bNeedVScrollBar)
     343             :     {
     344           0 :         m_pVertScroll->Show();
     345           0 :         m_pVertScroll->SetRangeMax(nActive - nLastVisible);
     346             : 
     347           0 :         m_pVertScroll->SetPosSizePixel( Point(nNewHWidth, 0), Size(nVScrollWidth, szOverallSize.Height()) );
     348             :     }
     349             :     else
     350             :     {
     351           0 :         m_pVertScroll->Hide();
     352           0 :         m_pVertScroll->SetRangeMax(0);
     353           0 :         m_pVertScroll->SetThumbPos(0);
     354             :     }
     355             : 
     356           0 :     if (bNeedHScrollBar)
     357             :     {
     358           0 :         m_pHorzScroll->Show();
     359           0 :         m_pHorzScroll->SetRangeMax((lMaxXPosition - lMaxXAvailable + HSCROLL_STEP - 1 )/HSCROLL_STEP);
     360             : 
     361           0 :         m_pHorzScroll->SetPosSizePixel( Point(0, nNewVHeight), Size(bNeedVScrollBar ? nNewHWidth : szOverallSize.Width(), nHScrollHeight) );
     362             :     }
     363             :     else
     364             :     {
     365           0 :         m_pHorzScroll->Hide();
     366           0 :         m_pHorzScroll->SetRangeMax(0);
     367           0 :         m_pHorzScroll->SetThumbPos(0);
     368             :     }
     369           0 : }
     370             : 
     371           0 : void OFieldDescControl::Resize()
     372             : {
     373           0 :     CheckScrollBars();
     374           0 :     ScrollAllAggregates();
     375           0 : }
     376             : 
     377           0 : inline void OFieldDescControl::ScrollAggregate(Control* pText, Control* pInput, Control* pButton, long nDeltaX, long nDeltaY)
     378             : {
     379           0 :     if  (!pText)
     380           0 :         return;
     381           0 :     pText->SetPosPixel(pText->GetPosPixel() + Point(nDeltaX, nDeltaY));
     382           0 :     pInput->SetPosPixel(pInput->GetPosPixel() + Point(nDeltaX, nDeltaY));
     383           0 :     if (pButton)
     384           0 :         pButton->SetPosPixel(pButton->GetPosPixel() + Point(nDeltaX, nDeltaY));
     385             : }
     386             : 
     387           0 : void OFieldDescControl::ScrollAllAggregates()
     388             : {
     389           0 :     long nDeltaX = 0, nDeltaY = 0;
     390           0 :     if (m_nOldHThumb != m_pHorzScroll->GetThumbPos())
     391             :     {
     392           0 :         nDeltaX = (m_nOldHThumb - m_pHorzScroll->GetThumbPos()) * HSCROLL_STEP;
     393           0 :         m_nOldHThumb = m_pHorzScroll->GetThumbPos();
     394             :     }
     395             : 
     396           0 :     if (m_nOldVThumb != m_pVertScroll->GetThumbPos())
     397             :     {
     398           0 :         const sal_Int32 nControlHeight = GetMaxControlHeight();
     399           0 :         const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
     400           0 :         nDeltaY = (m_nOldVThumb - m_pVertScroll->GetThumbPos()) * (nControl_Spacing_y + nControlHeight);
     401           0 :         m_nOldVThumb = m_pVertScroll->GetThumbPos();
     402             :     }
     403             : 
     404           0 :     if (nDeltaX || nDeltaY)
     405             :     {
     406             :         Control* ppAggregates[]     = {   pRequired, pNumType
     407             :                                         , pAutoIncrement, pDefault
     408             :                                         , pTextLen, pLength
     409             :                                         , pScale, m_pColumnName
     410           0 :                                         , m_pType, m_pAutoIncrementValue};
     411             :         Control* ppAggregatesText[] = {   pRequiredText, pNumTypeText
     412             :                                         , pAutoIncrementText, pDefaultText
     413             :                                         , pTextLenText, pLengthText
     414             :                                         , pScaleText, m_pColumnNameText
     415           0 :                                         , m_pTypeText, m_pAutoIncrementValueText};
     416             :         OSL_ENSURE(sizeof(ppAggregates)/sizeof(ppAggregates[0]) == sizeof(ppAggregatesText)/sizeof(ppAggregatesText[0]),"Lists are not identical!");
     417             : 
     418           0 :         for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
     419           0 :             ScrollAggregate(ppAggregatesText[i],ppAggregates[i],NULL,nDeltaX, nDeltaY);
     420             : 
     421           0 :         ScrollAggregate(pFormatText,pFormatSample,pFormat,nDeltaX, nDeltaY);
     422             :     }
     423           0 : }
     424             : 
     425           0 : sal_uInt16 OFieldDescControl::CountActiveAggregates() const
     426             : {
     427           0 :     Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
     428           0 :     sal_uInt16 nVisibleAggregates = 0;
     429           0 :     for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
     430           0 :         if (ppAggregates[i])
     431           0 :             ++nVisibleAggregates;
     432           0 :     return nVisibleAggregates;
     433             : }
     434             : 
     435           0 : sal_Int32 OFieldDescControl::GetMaxControlHeight() const
     436             : {
     437           0 :     Size aHeight;
     438           0 :     Control* ppAggregates[] = { pRequired, pNumType, pAutoIncrement, pDefault, pTextLen, pLength, pScale, pFormat, m_pColumnName, m_pType,m_pAutoIncrementValue};
     439           0 :     for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
     440             :     {
     441           0 :         if ( ppAggregates[i] )
     442             :         {
     443           0 :             const Size aTemp(ppAggregates[i]->GetOptimalSize());
     444           0 :             if ( aTemp.Height() > aHeight.Height() )
     445           0 :                 aHeight.Height() = aTemp.Height();
     446             :         }
     447             :     }
     448             : 
     449           0 :     return aHeight.Height();
     450             : }
     451             : 
     452           0 : void OFieldDescControl::SetReadOnly( sal_Bool bReadOnly )
     453             : {
     454             :     // Enable/disable Controls
     455             :     Control* ppAggregates[]     = {   pRequired, pNumType
     456             :                                         , pAutoIncrement, pDefault
     457             :                                         , pTextLen, pLength
     458             :                                         , pScale, m_pColumnName
     459             :                                         , m_pType, m_pAutoIncrementValue
     460           0 :                                         , pFormat};
     461             :     Control* ppAggregatesText[] = {   pRequiredText, pNumTypeText
     462             :                                         , pAutoIncrementText, pDefaultText
     463             :                                         , pTextLenText, pLengthText
     464             :                                         , pScaleText, m_pColumnNameText
     465             :                                         , m_pTypeText, m_pAutoIncrementValueText
     466           0 :                                         , pFormatText};
     467             : 
     468             :     OSL_ENSURE(sizeof(ppAggregates)/sizeof(ppAggregates[0]) == sizeof(ppAggregatesText)/sizeof(ppAggregatesText[0]),"Lists are not identical!");
     469             : 
     470           0 :     for (sal_uInt16 i=0; i<sizeof(ppAggregates)/sizeof(ppAggregates[0]); ++i)
     471             :     {
     472           0 :         if ( ppAggregatesText[i] )
     473           0 :             ppAggregatesText[i]->Enable( !bReadOnly );
     474           0 :         if ( ppAggregates[i] )
     475           0 :             ppAggregates[i]->Enable( !bReadOnly );
     476             :     }
     477           0 : }
     478             : 
     479           0 : OUString OFieldDescControl::GetControlText( sal_uInt16 nControlId )
     480             : {
     481             :     // Read out the Controls' texts
     482           0 :     switch( nControlId )
     483             :     {
     484             :         case FIELD_PROPERTY_BOOL_DEFAULT:
     485           0 :             if (pBoolDefault)
     486           0 :                 return pBoolDefault->GetSelectEntry();
     487           0 :             break;
     488             :         case FIELD_PROPERTY_DEFAULT:
     489           0 :             if (pDefault)
     490           0 :                 return pDefault->GetText();
     491           0 :             break;
     492             :         case FIELD_PROPERTY_REQUIRED:
     493           0 :             if (pRequired)
     494           0 :                 return pRequired->GetSelectEntry();
     495           0 :             break;
     496             :         case FIELD_PROPERTY_TEXTLEN:
     497           0 :             if (pTextLen)
     498           0 :                 return OUString::number(pTextLen->GetValue());
     499           0 :             break;
     500             :         case FIELD_PROPERTY_NUMTYPE:
     501           0 :             if (pNumType)
     502           0 :                 return pNumType->GetSelectEntry();
     503           0 :             break;
     504             :         case FIELD_PROPERTY_AUTOINC:
     505           0 :             if (pAutoIncrement)
     506           0 :                 return pAutoIncrement->GetSelectEntry();
     507           0 :             break;
     508             :         case FIELD_PROPERTY_LENGTH:
     509           0 :             if (pLength)
     510           0 :                 return pLength->GetText();
     511           0 :             break;
     512             :         case FIELD_PROPERTY_SCALE:
     513           0 :             if (pScale)
     514           0 :                 return pScale->GetText();
     515           0 :             break;
     516             :         case FIELD_PROPERTY_FORMAT:
     517           0 :             if (pFormatSample)
     518           0 :                 return pFormatSample->GetText();
     519           0 :             break;
     520             :         case FIELD_PROPERTY_COLUMNNAME:
     521           0 :             if(m_pColumnName)
     522           0 :                 return m_pColumnName->GetText();
     523           0 :             break;
     524             :         case FIELD_PROPERTY_TYPE:
     525           0 :             if(m_pType)
     526           0 :                 return m_pType->GetSelectEntry();
     527           0 :             break;
     528             :         case FIELD_PROPERTY_AUTOINCREMENT:
     529           0 :             if(m_pAutoIncrementValue)
     530           0 :                 return m_pAutoIncrementValue->GetText();
     531             :     }
     532             : 
     533           0 :     return OUString();
     534             : }
     535             : 
     536           0 : void OFieldDescControl::SetControlText( sal_uInt16 nControlId, const OUString& rText )
     537             : {
     538             :     // Set the Controls' texts
     539           0 :     switch( nControlId )
     540             :     {
     541             :         case FIELD_PROPERTY_BOOL_DEFAULT:
     542           0 :             if (pBoolDefault)
     543             :             {
     544           0 :                 OUString sOld = pBoolDefault->GetSelectEntry();
     545           0 :                 pBoolDefault->SelectEntry(rText);
     546           0 :                 if (sOld != rText)
     547           0 :                     LINK(this, OFieldDescControl, ChangeHdl).Call(pBoolDefault);
     548             :             }
     549           0 :             break;
     550             :         case FIELD_PROPERTY_DEFAULT:
     551           0 :             if (pDefault)
     552             :             {
     553           0 :                 pDefault->SetText(rText);
     554           0 :                 UpdateFormatSample(pActFieldDescr);
     555             :             }
     556           0 :             break;
     557             : 
     558             :         case FIELD_PROPERTY_REQUIRED:
     559           0 :             if (pRequired)
     560           0 :                 pRequired->SelectEntry(rText);
     561           0 :             break;
     562             : 
     563             :         case FIELD_PROPERTY_TEXTLEN:
     564           0 :             if (pTextLen)
     565           0 :                 pTextLen->SetText(rText);
     566           0 :             break;
     567             : 
     568             :         case FIELD_PROPERTY_NUMTYPE:
     569           0 :             if (pNumType)
     570           0 :                 pNumType->SelectEntry(rText);
     571           0 :             break;
     572             : 
     573             :         case FIELD_PROPERTY_AUTOINC:
     574           0 :             if (pAutoIncrement)
     575             :             {
     576           0 :                 OUString sOld = pAutoIncrement->GetSelectEntry();
     577           0 :                 pAutoIncrement->SelectEntry(rText);
     578           0 :                 if (sOld != rText)
     579           0 :                     LINK(this, OFieldDescControl, ChangeHdl).Call(pAutoIncrement);
     580             :             }
     581           0 :             break;
     582             : 
     583             :         case FIELD_PROPERTY_LENGTH:
     584           0 :             if (pLength)
     585           0 :                 pLength->SetText(rText);
     586           0 :             break;
     587             : 
     588             :         case FIELD_PROPERTY_SCALE:
     589           0 :             if (pScale)
     590           0 :                 pScale->SetText(rText);
     591           0 :             break;
     592             : 
     593             :         case FIELD_PROPERTY_FORMAT:
     594           0 :             if (pActFieldDescr)
     595           0 :                 UpdateFormatSample(pActFieldDescr);
     596           0 :             break;
     597             :         case FIELD_PROPERTY_COLUMNNAME:
     598           0 :             if(m_pColumnName)
     599           0 :                 m_pColumnName->SetText(rText);
     600           0 :             break;
     601             :         case FIELD_PROPERTY_TYPE:
     602           0 :             if(m_pType)
     603           0 :                 m_pType->SelectEntry(rText);
     604           0 :             break;
     605             :         case FIELD_PROPERTY_AUTOINCREMENT:
     606           0 :             if(m_pAutoIncrementValue)
     607           0 :                 m_pAutoIncrementValue->SetText(rText);
     608           0 :             break;
     609             :     }
     610           0 : }
     611             : 
     612           0 : IMPL_LINK( OFieldDescControl, FormatClickHdl, Button *, /*pButton*/ )
     613             : {
     614             :     // Create temporary Column, which is used for data exchange with Dialog
     615           0 :     if( !pActFieldDescr )
     616           0 :         return 0;
     617             : 
     618           0 :     sal_Int32 nOldFormatKey(pActFieldDescr->GetFormatKey());
     619           0 :     SvxCellHorJustify rOldJustify = pActFieldDescr->GetHorJustify();
     620           0 :     Reference< XNumberFormatsSupplier >  xSupplier = GetFormatter()->getNumberFormatsSupplier();
     621           0 :     SvNumberFormatsSupplierObj* pSupplierImpl = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
     622           0 :     if (!pSupplierImpl)
     623           0 :         return 0;
     624             : 
     625           0 :     SvNumberFormatter* pFormatter = pSupplierImpl->GetNumberFormatter();
     626           0 :     if(::dbaui::callColumnFormatDialog(this,pFormatter,pActFieldDescr->GetType(),nOldFormatKey,rOldJustify,sal_True))
     627             :     {
     628           0 :         sal_Bool bModified = sal_False;
     629           0 :         if(nOldFormatKey != pActFieldDescr->GetFormatKey())
     630             :         {
     631           0 :             pActFieldDescr->SetFormatKey( nOldFormatKey );
     632           0 :             bModified = sal_True;
     633             :         }
     634           0 :         if(rOldJustify != pActFieldDescr->GetHorJustify())
     635             :         {
     636           0 :             pActFieldDescr->SetHorJustify( rOldJustify );
     637           0 :             bModified = sal_True;
     638             :         }
     639             : 
     640           0 :         if(bModified)
     641             :         {
     642           0 :             SetModified(sal_True);
     643           0 :             UpdateFormatSample(pActFieldDescr);
     644             :         }
     645             :     }
     646           0 :     return 0;
     647             : }
     648             : 
     649           0 : void OFieldDescControl::SetModified(sal_Bool /*bModified*/)
     650             : {
     651           0 : }
     652             : 
     653           0 : IMPL_LINK( OFieldDescControl, ChangeHdl, ListBox *, pListBox )
     654             : {
     655           0 :     if ( !pActFieldDescr )
     656           0 :         return 0;
     657             : 
     658           0 :     if ( pListBox->GetSavedValue() != pListBox->GetSelectEntryPos() )
     659           0 :         SetModified(sal_True);
     660             : 
     661             :     // Special treatment for Boold fields
     662           0 :     if(pListBox == pRequired && pBoolDefault )
     663             :     {
     664             :         // If pRequired = sal_True then the sal_Bool field must NOT contain <<none>>
     665           0 :         OUString sDef = BoolStringUI(::comphelper::getString(pActFieldDescr->GetControlDefault()));
     666             : 
     667           0 :         if(pRequired->GetSelectEntryPos() == 0) // Yes
     668             :         {
     669           0 :             pBoolDefault->RemoveEntry(OUString(ModuleRes(STR_VALUE_NONE)));
     670           0 :             if (sDef != aYes && sDef != aNo)
     671           0 :                 pBoolDefault->SelectEntryPos(1);  // No as a default
     672             :             else
     673           0 :                 pBoolDefault->SelectEntry(sDef);
     674             :         }
     675           0 :         else if(pBoolDefault->GetEntryCount() < 3)
     676             :         {
     677           0 :             pBoolDefault->InsertEntry(OUString(ModuleRes(STR_VALUE_NONE)));
     678           0 :             pBoolDefault->SelectEntry(sDef);
     679           0 :         }
     680             :     }
     681             : 
     682             :     // A special treatment only for AutoIncrement
     683           0 :     if (pListBox == pAutoIncrement)
     684             :     {
     685           0 :         if(pListBox->GetSelectEntryPos() == 1)
     686             :         { // no
     687           0 :             DeactivateAggregate( tpAutoIncrementValue );
     688           0 :             if(pActFieldDescr->IsPrimaryKey())
     689           0 :                 DeactivateAggregate( tpRequired );
     690           0 :             else if( pActFieldDescr->getTypeInfo()->bNullable )
     691             :             {
     692           0 :                 ActivateAggregate( tpRequired );
     693           0 :                 if(pRequired)
     694             :                 {
     695           0 :                     if( pActFieldDescr->IsNullable() )
     696           0 :                         pRequired->SelectEntryPos( 1 ); // no
     697             :                     else
     698           0 :                         pRequired->SelectEntryPos( 0 ); // yes
     699             :                 }
     700             :             }
     701           0 :             ActivateAggregate( tpDefault );
     702             :         }
     703             :         else
     704             :         {
     705           0 :             DeactivateAggregate( tpRequired );
     706           0 :             DeactivateAggregate( tpDefault );
     707           0 :             ActivateAggregate( tpAutoIncrementValue );
     708             :         }
     709             :         // Move all up
     710           0 :         ArrangeAggregates();
     711             :     }
     712             : 
     713           0 :     if(pListBox == m_pType)
     714             :     {
     715           0 :         TOTypeInfoSP pTypeInfo = getTypeInfo(m_pType->GetSelectEntryPos());
     716           0 :         pActFieldDescr->FillFromTypeInfo(pTypeInfo,sal_True,sal_False); // SetType(pTypeInfo);
     717             : 
     718           0 :         DisplayData(pActFieldDescr);
     719           0 :         CellModified(-1, m_pType->GetPos());
     720             :     }
     721             : 
     722           0 :     return 0;
     723             : }
     724             : 
     725             : // Rearrange all Controls, such that they are in fixed order and really on top
     726             : // of the DescriptionPage
     727           0 : void OFieldDescControl::ArrangeAggregates()
     728             : {
     729             :     // A Control's description
     730             :     struct AGGREGATE_DESCRIPTION
     731             :     {
     732             :         Control*    pctrlInputControl;  // The actual Control for input
     733             :         Control*    pctrlTextControl;   // The corresponding Label
     734             :         sal_uInt16      nPosSizeArgument;   // The second argument for SetPosSize
     735             :     };
     736             :     AGGREGATE_DESCRIPTION adAggregates[] = {
     737             :         { m_pColumnName, m_pColumnNameText, 1},
     738             :         { m_pType, m_pTypeText, 1},
     739             :         { pAutoIncrement, pAutoIncrementText, 1 },
     740             :         { m_pAutoIncrementValue, m_pAutoIncrementValueText, 3 },
     741             :         { pNumType, pNumTypeText, 1 },
     742             :         { pRequired, pRequiredText, 1 },
     743             :         { pTextLen, pTextLenText, 1 },
     744             :         { pLength, pLengthText, 1 },
     745             :         { pScale, pScaleText, 1 },
     746             :         { pDefault, pDefaultText, 3 },
     747             :         { pFormatSample, pFormatText, 4 },
     748             :         { pBoolDefault, pBoolDefaultText, 1 },
     749           0 :     };
     750             : 
     751           0 :     long nMaxWidth = 0;
     752           0 :     for (size_t i=0; i<sizeof(adAggregates)/sizeof(adAggregates[0]); i++)
     753             :     {
     754           0 :         if (adAggregates[i].pctrlTextControl)
     755             :         {
     756           0 :             nMaxWidth = ::std::max<long>(OutputDevice::GetTextWidth(adAggregates[i].pctrlTextControl->GetText()),nMaxWidth);
     757             :         }
     758             :     }
     759             : 
     760             :     OSL_ENSURE(nMaxWidth != 0,"Invalid width!");
     761             : 
     762             :     // And go ...
     763           0 :     int nCurrentControlPos = 0;
     764           0 :     Control* pZOrderPredecessor = NULL;
     765           0 :     for (size_t i=0; i<sizeof(adAggregates)/sizeof(adAggregates[0]); i++)
     766             :     {
     767           0 :         if (adAggregates[i].pctrlInputControl)
     768             :         {
     769           0 :             SetPosSize(&adAggregates[i].pctrlTextControl, nCurrentControlPos, 0);
     770           0 :             SetPosSize(&adAggregates[i].pctrlInputControl, nCurrentControlPos, adAggregates[i].nPosSizeArgument);
     771             : 
     772             :             // 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
     773           0 :             adAggregates[i].pctrlTextControl->SetZOrder(pZOrderPredecessor, pZOrderPredecessor ? WINDOW_ZORDER_BEHIND : WINDOW_ZORDER_FIRST);
     774           0 :             adAggregates[i].pctrlInputControl->SetZOrder(adAggregates[i].pctrlTextControl, WINDOW_ZORDER_BEHIND );
     775           0 :             pZOrderPredecessor = adAggregates[i].pctrlInputControl;
     776             : 
     777           0 :             if (adAggregates[i].pctrlInputControl == pFormatSample)
     778             :             {
     779           0 :                 pFormat->SetZOrder(pZOrderPredecessor, WINDOW_ZORDER_BEHIND);
     780           0 :                 pZOrderPredecessor = pFormat;
     781             :             }
     782             : 
     783           0 :             ++nCurrentControlPos;
     784             :         }
     785             :     }
     786             : 
     787             :     // Special treatment for the Format Controls
     788           0 :     if (pFormat)
     789             :     {
     790           0 :         Point ptSamplePos(pFormatSample->GetPosPixel());
     791           0 :         Size szSampleSize(pFormatSample->GetSizePixel());
     792           0 :         pFormat->SetPosPixel(Point(ptSamplePos.X() + szSampleSize.Width() + 5, ptSamplePos.Y()));
     793             :     }
     794             : 
     795             :     // Finally, put the ScrollBars at the top of the z-order
     796           0 :     m_pVertScroll->SetZOrder(NULL, WINDOW_ZORDER_FIRST);
     797           0 :     m_pHorzScroll->SetZOrder(NULL, WINDOW_ZORDER_FIRST);
     798           0 : }
     799             : 
     800           0 : void OFieldDescControl::ActivateAggregate( EControlType eType )
     801             : {
     802             :     // Create Controls
     803           0 :     switch( eType )
     804             :     {
     805             :     case tpDefault:
     806           0 :         if( pDefault )
     807           0 :             return;
     808           0 :         m_nPos++;
     809           0 :         pDefaultText = CreateText(STR_DEFAULT_VALUE);
     810           0 :         pDefault = new OPropEditCtrl( this, STR_HELP_DEFAULT_VALUE, FIELD_PROPERTY_DEFAULT, WB_BORDER );
     811           0 :         InitializeControl(pDefault,HID_TAB_ENT_DEFAULT,false);
     812           0 :         break;
     813             :     case tpAutoIncrementValue:
     814           0 :         if( m_pAutoIncrementValue || !isAutoIncrementValueEnabled() )
     815           0 :             return;
     816           0 :         m_nPos++;
     817           0 :         m_pAutoIncrementValueText = CreateText(STR_AUTOINCREMENT_VALUE);
     818           0 :         m_pAutoIncrementValue = new OPropEditCtrl( this, STR_HELP_AUTOINCREMENT_VALUE, FIELD_PROPERTY_AUTOINCREMENT, WB_BORDER );
     819           0 :         m_pAutoIncrementValue->SetText( getAutoIncrementValue() );
     820           0 :         InitializeControl(m_pAutoIncrementValue,HID_TAB_AUTOINCREMENTVALUE,false);
     821           0 :         break;
     822             : 
     823             :     case tpRequired:
     824             :     {
     825           0 :         if( pRequired )
     826           0 :             return;
     827           0 :         Reference< XDatabaseMetaData> xMetaData = getMetaData();
     828             : 
     829           0 :         if(xMetaData.is() && xMetaData->supportsNonNullableColumns())
     830             :         {
     831           0 :             m_nPos++;
     832           0 :             pRequiredText = CreateText(STR_FIELD_REQUIRED);
     833           0 :             pRequired = new OPropListBoxCtrl( this, STR_HELP_FIELD_REQUIRED, FIELD_PROPERTY_REQUIRED, WB_DROPDOWN);
     834             : 
     835           0 :             pRequired->InsertEntry( aYes );
     836           0 :             pRequired->InsertEntry( aNo );
     837           0 :             pRequired->SelectEntryPos(1);
     838             : 
     839           0 :             InitializeControl(pRequired,HID_TAB_ENT_REQUIRED,true);
     840           0 :         }
     841             :     }
     842           0 :     break;
     843             :     case tpAutoIncrement:
     844             :     {
     845           0 :         if( pAutoIncrement )
     846           0 :             return;
     847           0 :         m_nPos++;
     848           0 :         pAutoIncrementText = CreateText(STR_FIELD_AUTOINCREMENT);
     849           0 :         pAutoIncrement = new OPropListBoxCtrl( this, STR_HELP_AUTOINCREMENT, FIELD_PROPERTY_AUTOINC, WB_DROPDOWN );
     850           0 :         pAutoIncrement->InsertEntry( aYes );
     851           0 :         pAutoIncrement->InsertEntry( aNo );
     852           0 :         pAutoIncrement->SelectEntryPos(0);
     853           0 :         InitializeControl(pAutoIncrement,HID_TAB_ENT_AUTOINCREMENT,true);
     854             :     }
     855           0 :     break;
     856             :     case tpTextLen:
     857           0 :         if( pTextLen )
     858           0 :             return;
     859           0 :         m_nPos++;
     860           0 :         pTextLenText = CreateText(STR_TEXT_LENGTH);
     861           0 :         pTextLen = CreateNumericControl(STR_HELP_TEXT_LENGTH, FIELD_PROPERTY_TEXTLEN,HID_TAB_ENT_TEXT_LEN);
     862           0 :         break;
     863             : 
     864             :     case tpType:
     865           0 :         if( m_pType)
     866           0 :             return;
     867           0 :         m_nPos++;
     868           0 :         m_pTypeText = CreateText(STR_TAB_FIELD_DATATYPE);
     869           0 :         m_pType = new OPropListBoxCtrl( this, STR_HELP_AUTOINCREMENT, FIELD_PROPERTY_TYPE, WB_DROPDOWN );
     870           0 :         m_pType->SetDropDownLineCount(20);
     871             :         {
     872           0 :             const OTypeInfoMap* pTypeInfo = getTypeInfo();
     873           0 :             OTypeInfoMap::const_iterator aIter = pTypeInfo->begin();
     874           0 :             OTypeInfoMap::const_iterator aEnd = pTypeInfo->end();
     875           0 :             for(;aIter != aEnd;++aIter)
     876           0 :                 m_pType->InsertEntry( aIter->second->aUIName );
     877             :         }
     878           0 :         m_pType->SelectEntryPos(0);
     879           0 :         InitializeControl(m_pType,HID_TAB_ENT_TYPE,true);
     880           0 :         break;
     881             :     case tpColumnName:
     882           0 :         if( m_pColumnName )
     883           0 :             return;
     884           0 :         m_nPos++;
     885             :         {
     886           0 :             sal_Int32 nMax = EDIT_NOLIMIT;
     887           0 :             OUString aTmpString;
     888             :             try
     889             :             {
     890           0 :                 Reference< XDatabaseMetaData> xMetaData = getMetaData();
     891           0 :                 if ( xMetaData.is() )
     892             :                 {
     893           0 :                     nMax =  xMetaData->getMaxColumnNameLength();
     894           0 :                     aTmpString = xMetaData->getExtraNameCharacters();
     895           0 :                 }
     896             :             }
     897           0 :             catch (const Exception&)
     898             :             {
     899             :                 DBG_UNHANDLED_EXCEPTION();
     900             :             }
     901           0 :             m_pColumnNameText = CreateText(STR_TAB_FIELD_NAME);
     902             :             m_pColumnName = new OPropColumnEditCtrl( this,
     903             :                                                     aTmpString,
     904             :                                                     STR_HELP_DEFAULT_VALUE,
     905             :                                                     FIELD_PROPERTY_COLUMNNAME,
     906           0 :                                                     WB_BORDER );
     907           0 :             m_pColumnName->SetMaxTextLen(nMax ? nMax : EDIT_NOLIMIT);
     908           0 :             m_pColumnName->setCheck( isSQL92CheckEnabled(getConnection()) );
     909             :         }
     910             : 
     911           0 :         InitializeControl(m_pColumnName,HID_TAB_ENT_COLUMNNAME,false);
     912           0 :         break;
     913             :     case tpNumType:
     914           0 :         if( pNumType )
     915           0 :             return;
     916           0 :         m_nPos++;
     917           0 :         pNumTypeText = CreateText(STR_NUMERIC_TYPE);
     918             : 
     919           0 :         pNumType = new OPropListBoxCtrl( this, STR_HELP_NUMERIC_TYPE, FIELD_PROPERTY_NUMTYPE, WB_DROPDOWN );
     920           0 :         pNumType->SetDropDownLineCount(5);
     921             : 
     922           0 :         pNumType->InsertEntry( OUString("Byte") );
     923           0 :         pNumType->InsertEntry( OUString("SmallInt") );
     924           0 :         pNumType->InsertEntry( OUString("Integer") );
     925           0 :         pNumType->InsertEntry( OUString("Single") );
     926           0 :         pNumType->InsertEntry( OUString("Double") );
     927           0 :         pNumType->SelectEntryPos(2);
     928           0 :         InitializeControl(pNumType,HID_TAB_ENT_NUMTYP,true);
     929           0 :         break;
     930             : 
     931             :     case tpLength:
     932           0 :         if( pLength )
     933           0 :             return;
     934           0 :         m_nPos++;
     935           0 :         pLengthText = CreateText(STR_LENGTH);
     936           0 :         pLength = CreateNumericControl(STR_HELP_LENGTH, FIELD_PROPERTY_LENGTH,HID_TAB_ENT_LEN);
     937           0 :         break;
     938             : 
     939             :     case tpScale:
     940           0 :         if( pScale )
     941           0 :             return;
     942           0 :         m_nPos++;
     943           0 :         pScaleText = CreateText(STR_SCALE);
     944           0 :         pScale = CreateNumericControl(STR_HELP_SCALE, FIELD_PROPERTY_SCALE,HID_TAB_ENT_SCALE);
     945           0 :         break;
     946             : 
     947             :     case tpFormat:
     948           0 :         if (!pFormat)
     949             :         {
     950           0 :             m_nPos++;
     951           0 :             pFormatText = CreateText(STR_FORMAT);
     952             : 
     953           0 :             pFormatSample = new OPropEditCtrl( this, STR_HELP_FORMAT_CODE, -1, WB_BORDER );
     954           0 :             pFormatSample->SetReadOnly(true);
     955           0 :             pFormatSample->Enable(false);
     956           0 :             InitializeControl(pFormatSample,HID_TAB_ENT_FORMAT_SAMPLE,false);
     957             : 
     958           0 :             pFormat = new PushButton( this, ModuleRes(PB_FORMAT) );
     959           0 :             const sal_Int32 nControlHeight = GetMaxControlHeight();
     960           0 :             pFormat->SetSizePixel(Size(nControlHeight, nControlHeight));
     961           0 :             pFormat->SetClickHdl( LINK( this, OFieldDescControl, FormatClickHdl ) );
     962           0 :             InitializeControl(pFormat,HID_TAB_ENT_FORMAT,false);
     963             :         }
     964             : 
     965           0 :         UpdateFormatSample(pActFieldDescr);
     966           0 :         break;
     967             :     case tpBoolDefault:
     968           0 :         if (pBoolDefault)
     969           0 :             return;
     970             : 
     971           0 :         m_nPos++;
     972           0 :         pBoolDefaultText = CreateText(STR_DEFAULT_VALUE);
     973           0 :         pBoolDefault = new OPropListBoxCtrl( this, STR_HELP_BOOL_DEFAULT, FIELD_PROPERTY_BOOL_DEFAULT, WB_DROPDOWN );
     974           0 :         pBoolDefault->SetDropDownLineCount(3);
     975           0 :         pBoolDefault->InsertEntry(OUString(ModuleRes(STR_VALUE_NONE)));
     976           0 :         pBoolDefault->InsertEntry(aYes);
     977           0 :         pBoolDefault->InsertEntry(aNo);
     978             : 
     979           0 :         InitializeControl(pBoolDefault,HID_TAB_ENT_BOOL_DEFAULT,false);
     980           0 :         break;
     981             :     }
     982             : }
     983             : 
     984           0 : void OFieldDescControl::InitializeControl(Control* _pControl,const OString& _sHelpId,bool _bAddChangeHandler)
     985             : {
     986           0 :     _pControl->SetHelpId(_sHelpId);
     987           0 :     if ( _bAddChangeHandler )
     988           0 :         ((OPropListBoxCtrl*)_pControl)->SetSelectHdl(LINK(this,OFieldDescControl,ChangeHdl));
     989             : 
     990           0 :     _pControl->SetGetFocusHdl(LINK(this, OFieldDescControl, OnControlFocusGot));
     991           0 :     _pControl->SetLoseFocusHdl(LINK(this, OFieldDescControl, OnControlFocusLost));
     992           0 :     _pControl->EnableClipSiblings();
     993           0 : }
     994             : 
     995           0 : FixedText* OFieldDescControl::CreateText(sal_uInt16 _nTextRes)
     996             : {
     997           0 :     FixedText* pFixedText = new FixedText( this );
     998           0 :     pFixedText->SetText( ModuleRes(_nTextRes) );
     999           0 :     pFixedText->EnableClipSiblings();
    1000           0 :     return pFixedText;
    1001             : }
    1002             : 
    1003           0 : OPropNumericEditCtrl* OFieldDescControl::CreateNumericControl(sal_uInt16 _nHelpStr,short _nProperty,const OString& _sHelpId)
    1004             : {
    1005           0 :     OPropNumericEditCtrl* pControl = new OPropNumericEditCtrl( this, _nHelpStr, _nProperty, WB_BORDER );
    1006           0 :     pControl->SetDecimalDigits(0);
    1007           0 :     pControl->SetMin(0);
    1008           0 :     pControl->SetMax(0x7FFFFFFF);   // Should be changed outside, if needed
    1009           0 :     pControl->SetStrictFormat(true);
    1010             : 
    1011           0 :     InitializeControl(pControl,_sHelpId,false);
    1012             : 
    1013           0 :     return pControl;
    1014             : }
    1015             : 
    1016           0 : void OFieldDescControl::DeactivateAggregate( EControlType eType )
    1017             : {
    1018           0 :     pLastFocusWindow = NULL;
    1019             :     // Destroy Controls
    1020           0 :     switch( eType )
    1021             :     {
    1022             :     case tpDefault:
    1023           0 :         lcl_HideAndDeleteControl(m_nPos,&pDefault,&pDefaultText);
    1024           0 :         break;
    1025             : 
    1026             :     case tpAutoIncrementValue:
    1027           0 :         lcl_HideAndDeleteControl(m_nPos,&m_pAutoIncrementValue,&m_pAutoIncrementValueText);
    1028           0 :         break;
    1029             : 
    1030             :     case tpColumnName:
    1031           0 :         lcl_HideAndDeleteControl(m_nPos,&m_pColumnName,&m_pColumnNameText);
    1032           0 :         break;
    1033             : 
    1034             :     case tpType:
    1035           0 :         lcl_HideAndDeleteControl(m_nPos,&m_pType,&m_pTypeText);
    1036           0 :         break;
    1037             : 
    1038             :     case tpAutoIncrement:
    1039           0 :         lcl_HideAndDeleteControl(m_nPos,&pAutoIncrement,&pAutoIncrementText);
    1040           0 :         break;
    1041             : 
    1042             :     case tpRequired:
    1043           0 :         lcl_HideAndDeleteControl(m_nPos,&pRequired,&pRequiredText);
    1044           0 :         break;
    1045             : 
    1046             :     case tpTextLen:
    1047           0 :         lcl_HideAndDeleteControl(m_nPos,&pTextLen,&pTextLenText);
    1048           0 :         break;
    1049             : 
    1050             :     case tpNumType:
    1051           0 :         lcl_HideAndDeleteControl(m_nPos,&pNumType,&pNumTypeText);
    1052           0 :         break;
    1053             : 
    1054             :     case tpLength:
    1055           0 :         lcl_HideAndDeleteControl(m_nPos,&pLength,&pLengthText);
    1056           0 :         break;
    1057             : 
    1058             :     case tpScale:
    1059           0 :         lcl_HideAndDeleteControl(m_nPos,&pScale,&pScaleText);
    1060           0 :         break;
    1061             : 
    1062             :     case tpFormat:
    1063             :         // TODO: we have to check if we have to increment m_nPos again
    1064           0 :         lcl_HideAndDeleteControl(m_nPos,&pFormat,&pFormatText);
    1065           0 :         if ( pFormatSample )
    1066             :         {
    1067           0 :             pFormatSample->Hide();
    1068           0 :             delete pFormatSample;
    1069           0 :             pFormatSample = NULL;
    1070             :         }
    1071           0 :         break;
    1072             :     case tpBoolDefault:
    1073           0 :         lcl_HideAndDeleteControl(m_nPos,&pBoolDefault,&pBoolDefaultText);
    1074           0 :         break;
    1075             :     }
    1076           0 : }
    1077             : 
    1078           0 : void OFieldDescControl::SetPosSize( Control** ppControl, long nRow, sal_uInt16 nCol )
    1079             : {
    1080             : 
    1081             :     // Calculate size
    1082           0 :     const sal_Int32 nControlHeight = GetMaxControlHeight();
    1083           0 :     Size aSize(0,nControlHeight);
    1084           0 :     if ( isRightAligned() && nCol )
    1085           0 :         aSize.Width() = LogicToPixel(Size(m_nWidth, 0),MAP_APPFONT).Width();
    1086             :     else
    1087             :     {
    1088           0 :         switch( nCol )
    1089             :         {
    1090             :         case 0:
    1091             :         default:
    1092           0 :             aSize.Width()  = CONTROL_WIDTH_1;
    1093           0 :             break;
    1094             :         case 1:
    1095           0 :             aSize.Width()  = CONTROL_WIDTH_2;
    1096           0 :             break;
    1097             :         case 3:
    1098           0 :             aSize.Width()  = CONTROL_WIDTH_3;
    1099           0 :             break;
    1100             :         case 4:
    1101           0 :             aSize.Width()  = CONTROL_WIDTH_4;
    1102           0 :             break;
    1103             :         }
    1104             :     }
    1105             : 
    1106             :     // Calculate Position
    1107           0 :     Point aPosition;
    1108           0 :     switch( nCol )
    1109             :     {
    1110             :     case 0:
    1111           0 :         aPosition.X() = 0;
    1112           0 :         aPosition.Y() = 1;
    1113           0 :         break;
    1114             :     case 1:
    1115             :     case 3:
    1116             :     case 4:
    1117           0 :         if ( isRightAligned() )
    1118             :         {
    1119           0 :             Size aOwnSize = GetSizePixel();
    1120           0 :             aPosition.X() = aOwnSize.Width() - aSize.Width();
    1121             :         }
    1122             :         else
    1123           0 :             aPosition.X() = CONTROL_WIDTH_1 + CONTROL_SPACING_X;
    1124           0 :         break;
    1125             :     default:
    1126           0 :         aPosition.X() = 0;
    1127             :     }
    1128             : 
    1129           0 :     (*ppControl)->SetSizePixel( aSize );
    1130           0 :     aSize = (*ppControl)->GetSizePixel( );
    1131             : 
    1132           0 :     const sal_Int32 nControl_Spacing_y = LogicToPixel(Size(0, CONTROL_SPACING_Y),MAP_APPFONT).Height();
    1133           0 :     aPosition.Y() += ((nRow+1)*nControl_Spacing_y) +
    1134           0 :                     (nRow*nControlHeight);
    1135             : 
    1136             :     // Display Control
    1137           0 :     (*ppControl)->SetPosSizePixel( aPosition, aSize );
    1138           0 :     aSize = (*ppControl)->GetSizePixel();
    1139             : 
    1140           0 :     (*ppControl)->Show();
    1141           0 : }
    1142             : 
    1143           0 : void OFieldDescControl::DisplayData(OFieldDescription* pFieldDescr )
    1144             : {
    1145           0 :     pActFieldDescr = pFieldDescr;
    1146           0 :     if(!pFieldDescr)
    1147             :     {
    1148           0 :         DeactivateAggregate( tpDefault );
    1149           0 :         DeactivateAggregate( tpRequired );
    1150           0 :         DeactivateAggregate( tpTextLen );
    1151           0 :         DeactivateAggregate( tpNumType );
    1152           0 :         DeactivateAggregate( tpScale );
    1153           0 :         DeactivateAggregate( tpLength );
    1154           0 :         DeactivateAggregate( tpFormat );
    1155           0 :         DeactivateAggregate( tpAutoIncrement );
    1156           0 :         DeactivateAggregate( tpBoolDefault );
    1157           0 :         DeactivateAggregate( tpColumnName );
    1158           0 :         DeactivateAggregate( tpType );
    1159           0 :         DeactivateAggregate( tpAutoIncrementValue );
    1160           0 :         m_pPreviousType = TOTypeInfoSP();
    1161             :         // Reset the saved focus' pointer
    1162           0 :         pLastFocusWindow = NULL;
    1163           0 :         if ( m_bAdded )
    1164             :         {
    1165           0 :             ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::RemoveWindow));
    1166           0 :             m_bAdded = sal_False;
    1167             :         }
    1168           0 :         return;
    1169             :     }
    1170             : 
    1171           0 :     if ( !m_bAdded )
    1172             :     {
    1173           0 :         ::dbaui::notifySystemWindow(this,this,::comphelper::mem_fun(&TaskPaneList::AddWindow));
    1174           0 :         m_bAdded = sal_True;
    1175             :     }
    1176             : 
    1177           0 :     TOTypeInfoSP pFieldType;
    1178           0 :     if( pFieldDescr )
    1179           0 :         pFieldType = pFieldDescr->getTypeInfo();
    1180             : 
    1181           0 :     ActivateAggregate( tpColumnName );
    1182           0 :     ActivateAggregate( tpType );
    1183             : 
    1184             :     OSL_ENSURE(pFieldType.get(),"We need a type information here!");
    1185             :     // If the type has changed, subsitute Controls
    1186           0 :     if( m_pPreviousType != pFieldType )
    1187             :     {
    1188             :         // Reset the saved focus' pointer
    1189           0 :         pLastFocusWindow = NULL;
    1190             : 
    1191             :         // Controls, which must NOT be displayed again
    1192           0 :         DeactivateAggregate( tpNumType );
    1193             : 
    1194             :         // determine which controls we should show and which not
    1195             : 
    1196             :         // 1. the required control
    1197           0 :         if ( pFieldType->bNullable )
    1198           0 :             ActivateAggregate( tpRequired );
    1199             :         else
    1200           0 :             DeactivateAggregate( tpRequired );
    1201             : 
    1202             :         // 2. the autoincrement
    1203           0 :         if ( pFieldType->bAutoIncrement )
    1204             :         {
    1205           0 :             DeactivateAggregate( tpRequired );
    1206           0 :             DeactivateAggregate( tpDefault );
    1207           0 :             ActivateAggregate( tpAutoIncrement );
    1208           0 :             ActivateAggregate( tpAutoIncrementValue );
    1209             :         }
    1210             :         else
    1211             :         {
    1212           0 :             DeactivateAggregate( tpAutoIncrement );
    1213           0 :             DeactivateAggregate( tpAutoIncrementValue );
    1214           0 :             if(pFieldType->bNullable)
    1215           0 :                 ActivateAggregate( tpRequired );
    1216             :             else
    1217           0 :                 DeactivateAggregate( tpRequired );
    1218           0 :             ActivateAggregate( tpDefault );
    1219             :         }
    1220             :         // 3. the scale and precision
    1221           0 :         if (pFieldType->nPrecision)
    1222             :         {
    1223           0 :             ActivateAggregate( tpLength );
    1224           0 :             pLength->SetMax(::std::max<sal_Int32>(pFieldType->nPrecision,pFieldDescr->GetPrecision()));
    1225           0 :             pLength->SetSpecialReadOnly(pFieldType->aCreateParams.isEmpty());
    1226             :         }
    1227             :         else
    1228           0 :             DeactivateAggregate( tpLength );
    1229             : 
    1230           0 :         if (pFieldType->nMaximumScale)
    1231             :         {
    1232           0 :             ActivateAggregate( tpScale );
    1233           0 :             pScale->SetMax(::std::max<sal_Int32>(pFieldType->nMaximumScale,pFieldDescr->GetScale()));
    1234           0 :             pScale->SetMin(pFieldType->nMinimumScale);
    1235           0 :             static const OUString s_sPRECISION("PRECISION");
    1236           0 :             pScale->SetSpecialReadOnly(pFieldType->aCreateParams.isEmpty() || pFieldType->aCreateParams == s_sPRECISION);
    1237             :         }
    1238             :         else
    1239           0 :             DeactivateAggregate( tpScale );
    1240             : 
    1241             :         // and now look for type specific things
    1242           0 :         switch( pFieldType->nType )
    1243             :         {
    1244             :             case DataType::CHAR:
    1245             :             case DataType::VARCHAR:
    1246             :             case DataType::LONGVARCHAR:
    1247           0 :                 DeactivateAggregate( tpLength );
    1248           0 :                 DeactivateAggregate( tpBoolDefault );
    1249             : 
    1250           0 :                 ActivateAggregate( tpDefault );
    1251           0 :                 ActivateAggregate( tpFormat );
    1252           0 :                 if (pFieldType->nPrecision)
    1253             :                 {
    1254           0 :                     ActivateAggregate( tpTextLen );
    1255           0 :                     pTextLen->SetMax(::std::max<sal_Int32>(pFieldType->nPrecision,pFieldDescr->GetPrecision()));
    1256           0 :                     pTextLen->SetSpecialReadOnly(pFieldType->aCreateParams.isEmpty());
    1257             :                 }
    1258             :                 else
    1259           0 :                     DeactivateAggregate( tpTextLen );
    1260           0 :                 break;
    1261             :             case DataType::DATE:
    1262             :             case DataType::TIME:
    1263             :             case DataType::TIMESTAMP:
    1264           0 :                 DeactivateAggregate( tpLength ); // we don't need a length for date types
    1265           0 :                 DeactivateAggregate( tpTextLen );
    1266           0 :                 DeactivateAggregate( tpBoolDefault );
    1267             : 
    1268           0 :                 ActivateAggregate( tpDefault );
    1269           0 :                 ActivateAggregate( tpFormat );
    1270           0 :                 break;
    1271             :             case DataType::BIT:
    1272           0 :                 if ( !pFieldType->aCreateParams.isEmpty() )
    1273             :                 {
    1274           0 :                     DeactivateAggregate( tpFormat );
    1275           0 :                     DeactivateAggregate( tpTextLen );
    1276           0 :                     DeactivateAggregate( tpBoolDefault );
    1277           0 :                     break;
    1278             :                 }
    1279             :                 // run through
    1280             :             case DataType::BOOLEAN:
    1281           0 :                 DeactivateAggregate( tpTextLen );
    1282           0 :                 DeactivateAggregate( tpFormat );
    1283           0 :                 DeactivateAggregate( tpDefault );
    1284             : 
    1285           0 :                 ActivateAggregate( tpBoolDefault );
    1286           0 :                 break;
    1287             :             case DataType::DECIMAL:
    1288             :             case DataType::NUMERIC:
    1289             :             case DataType::BIGINT:
    1290             :             case DataType::FLOAT:
    1291             :             case DataType::DOUBLE:
    1292             :             case DataType::TINYINT:
    1293             :             case DataType::SMALLINT:
    1294             :             case DataType::INTEGER:
    1295             :             case DataType::REAL:
    1296           0 :                 DeactivateAggregate( tpTextLen );
    1297           0 :                 DeactivateAggregate( tpBoolDefault );
    1298             : 
    1299           0 :                 ActivateAggregate( tpFormat );
    1300           0 :                 break;
    1301             :             case DataType::BINARY:
    1302             :             case DataType::VARBINARY:
    1303           0 :                 DeactivateAggregate( tpDefault );
    1304           0 :                 DeactivateAggregate( tpRequired );
    1305           0 :                 DeactivateAggregate( tpTextLen );
    1306           0 :                 DeactivateAggregate( tpBoolDefault );
    1307             : 
    1308           0 :                 ActivateAggregate( tpFormat );
    1309           0 :                 break;
    1310             :             case DataType::LONGVARBINARY:
    1311             :             case DataType::SQLNULL:
    1312             :             case DataType::OBJECT:
    1313             :             case DataType::DISTINCT:
    1314             :             case DataType::STRUCT:
    1315             :             case DataType::ARRAY:
    1316             :             case DataType::BLOB:
    1317             :             case DataType::CLOB:
    1318             :             case DataType::REF:
    1319             :             case DataType::OTHER:
    1320           0 :                 DeactivateAggregate( tpFormat );
    1321           0 :                 DeactivateAggregate( tpTextLen );
    1322           0 :                 DeactivateAggregate( tpBoolDefault );
    1323             : 
    1324           0 :                 break;
    1325             :             default:
    1326             :                 OSL_FAIL("Unknown type");
    1327             :         }
    1328           0 :         m_pPreviousType = pFieldType;
    1329             :     }
    1330           0 :     if(pFieldDescr)
    1331             :     {
    1332           0 :         if(pFieldDescr->IsPrimaryKey())
    1333             :         {
    1334           0 :             DeactivateAggregate( tpRequired );
    1335             :         }
    1336           0 :         else if ( !pAutoIncrement && pFieldType.get() )
    1337             :         {
    1338           0 :             if ( pFieldType->bNullable )
    1339           0 :                 ActivateAggregate( tpRequired );
    1340             :             else
    1341           0 :                 DeactivateAggregate( tpRequired );
    1342             :         }
    1343             :     }
    1344             :     // Initialize Controls
    1345           0 :     if( pAutoIncrement )
    1346             :     {
    1347           0 :         if ( pFieldDescr->IsAutoIncrement() )
    1348             :         {
    1349           0 :             pAutoIncrement->SelectEntryPos( 0 ); // yes
    1350           0 :             ActivateAggregate( tpAutoIncrementValue );
    1351           0 :             if ( m_pAutoIncrementValue )
    1352           0 :                 m_pAutoIncrementValue->SetText(pFieldDescr->GetAutoIncrementValue());
    1353           0 :             DeactivateAggregate( tpRequired );
    1354           0 :             DeactivateAggregate( tpDefault );
    1355             :         }
    1356             :         else
    1357             :         {
    1358             :             // disable autoincrement value because it should only be visible when autoincrement is to true
    1359           0 :             DeactivateAggregate( tpAutoIncrementValue );
    1360           0 :             pAutoIncrement->SelectEntryPos( 1 );        // no
    1361           0 :             ActivateAggregate( tpDefault );
    1362             :             // Affects pRequired
    1363           0 :             if(!pFieldDescr->IsPrimaryKey())
    1364           0 :                 ActivateAggregate( tpRequired );
    1365             :         }
    1366             :     }
    1367             : 
    1368           0 :     if( pDefault )
    1369             :     {
    1370           0 :         pDefault->SetText( getControlDefault(pFieldDescr) );
    1371           0 :         pDefault->ClearModifyFlag();
    1372             :     }
    1373             : 
    1374           0 :     if( pBoolDefault )
    1375             :     {
    1376             :         // If pRequired = sal_True then the sal_Bool field must NOT contain <<none>>
    1377           0 :         OUString sValue;
    1378           0 :         pFieldDescr->GetControlDefault() >>= sValue;
    1379           0 :         OUString sDef = BoolStringUI(sValue);
    1380             : 
    1381             :         // Make sure that <<none>> is only present if the field can be NULL
    1382           0 :         if ( ( pFieldType.get() && !pFieldType->bNullable ) || !pFieldDescr->IsNullable() )
    1383             :         {
    1384           0 :             pFieldDescr->SetIsNullable(ColumnValue::NO_NULLS); // The type says so
    1385             : 
    1386           0 :             pBoolDefault->RemoveEntry(OUString(ModuleRes(STR_VALUE_NONE)));
    1387           0 :             if ( sDef != aYes && sDef != aNo )
    1388           0 :                 pBoolDefault->SelectEntryPos(1);  // No as a default
    1389             :             else
    1390           0 :                 pBoolDefault->SelectEntry(sDef);
    1391             : 
    1392           0 :             pFieldDescr->SetControlDefault(makeAny(OUString(BoolStringPersistent(pBoolDefault->GetSelectEntry()))));
    1393             :         }
    1394           0 :         else if(pBoolDefault->GetEntryCount() < 3)
    1395             :         {
    1396           0 :             pBoolDefault->InsertEntry(OUString(ModuleRes(STR_VALUE_NONE)));
    1397           0 :             pBoolDefault->SelectEntry(sDef);
    1398             :         }
    1399             :         else
    1400           0 :             pBoolDefault->SelectEntry(sDef);
    1401             :     }
    1402             : 
    1403           0 :     if( pRequired )
    1404             :     {
    1405           0 :         if( pFieldDescr->IsNullable() )
    1406           0 :             pRequired->SelectEntryPos( 1 ); // no
    1407             :         else
    1408           0 :             pRequired->SelectEntryPos( 0 ); // yes
    1409             :     }
    1410             : 
    1411           0 :     if( pTextLen )
    1412             :     {
    1413           0 :         pTextLen->SetText( OUString::number(pFieldDescr->GetPrecision()) );
    1414           0 :         pTextLen->ClearModifyFlag();
    1415             :     }
    1416             : 
    1417           0 :     if( pNumType )
    1418             :     {
    1419             :         OSL_FAIL("OFieldDescControl::DisplayData: invalid num type!");
    1420             :     }
    1421             : 
    1422           0 :     if( pLength )
    1423           0 :         pLength->SetText( OUString::number(pFieldDescr->GetPrecision()) );
    1424             : 
    1425           0 :     if( pScale )
    1426           0 :         pScale->SetText( OUString::number(pFieldDescr->GetScale()) );
    1427             : 
    1428           0 :     if( pFormat )
    1429           0 :         UpdateFormatSample(pFieldDescr);
    1430             : 
    1431           0 :     if(m_pColumnName)
    1432           0 :         m_pColumnName->SetText(pFieldDescr->GetName());
    1433             : 
    1434           0 :     if(m_pType)
    1435             :     {
    1436           0 :         sal_Int32 nPos = pFieldType.get() ? m_pType->GetEntryPos(OUString(pFieldDescr->getTypeInfo()->aUIName)) : LISTBOX_ENTRY_NOTFOUND;
    1437           0 :         if(nPos == LISTBOX_ENTRY_NOTFOUND)
    1438             :         {
    1439           0 :             const OTypeInfoMap* pMap = getTypeInfo();
    1440           0 :             OTypeInfoMap::const_iterator aIter = pMap->find(pFieldType.get() ? pFieldDescr->getTypeInfo()->nType : pFieldDescr->GetType());
    1441           0 :             if(aIter == pMap->end() && !pMap->empty())
    1442             :             {
    1443           0 :                 aIter = pMap->begin();
    1444           0 :                 if(pFieldDescr->GetPrecision() > aIter->second->nPrecision)
    1445           0 :                     pFieldDescr->SetPrecision(aIter->second->nPrecision);
    1446           0 :                 if(pFieldDescr->GetScale() > aIter->second->nMaximumScale)
    1447           0 :                     pFieldDescr->SetScale(0);
    1448           0 :                 if(!aIter->second->bNullable && pFieldDescr->IsNullable())
    1449           0 :                     pFieldDescr->SetIsNullable(ColumnValue::NO_NULLS);
    1450           0 :                 if(!aIter->second->bAutoIncrement && pFieldDescr->IsAutoIncrement())
    1451           0 :                     pFieldDescr->SetAutoIncrement(sal_False);
    1452             :             }
    1453           0 :             if ( aIter != pMap->end() )
    1454             :             {
    1455           0 :                 pFieldDescr->SetType(aIter->second);
    1456             :             }
    1457             :         }
    1458           0 :         m_pType->SelectEntry(pFieldDescr->getTypeInfo()->aUIName);
    1459             :     }
    1460             : 
    1461             :     // Enable/disable Controls
    1462           0 :     sal_Bool bRead(IsReadOnly());
    1463             : 
    1464           0 :     ArrangeAggregates();
    1465           0 :     CheckScrollBars();
    1466           0 :     ScrollAllAggregates();
    1467             : 
    1468           0 :     SetReadOnly( bRead );
    1469             : }
    1470             : 
    1471           0 : IMPL_LINK(OFieldDescControl, OnControlFocusGot, Control*, pControl )
    1472             : {
    1473           0 :     OUString strHelpText;
    1474           0 :     OPropNumericEditCtrl* pNumeric = dynamic_cast< OPropNumericEditCtrl* >( pControl );
    1475           0 :     if ( pNumeric )
    1476             :     {
    1477           0 :         pNumeric->SaveValue();
    1478           0 :         strHelpText = pNumeric->GetHelp();
    1479             :     }
    1480             : 
    1481           0 :     OPropColumnEditCtrl* pColumn = dynamic_cast< OPropColumnEditCtrl* >( pControl );
    1482           0 :     if ( pColumn )
    1483             :     {
    1484           0 :         pColumn->SaveValue();
    1485           0 :         strHelpText = pColumn->GetHelp();
    1486             :     }
    1487             : 
    1488           0 :     OPropEditCtrl* pEdit = dynamic_cast< OPropEditCtrl* >( pControl );
    1489           0 :     if ( pEdit )
    1490             :     {
    1491           0 :         pEdit->SaveValue();
    1492           0 :         strHelpText = pEdit->GetHelp();
    1493             :     }
    1494             : 
    1495           0 :     OPropListBoxCtrl* pListBox = dynamic_cast< OPropListBoxCtrl* >( pControl );
    1496           0 :     if ( pListBox )
    1497             :     {
    1498           0 :         pListBox->SaveValue();
    1499           0 :         strHelpText = pListBox->GetHelp();
    1500             :     }
    1501             : 
    1502           0 :     if (pControl == pFormat)
    1503           0 :         strHelpText = ModuleRes(STR_HELP_FORMAT_BUTTON);
    1504             : 
    1505           0 :     if (!strHelpText.isEmpty() && (pHelp != NULL))
    1506           0 :         pHelp->SetHelpText(strHelpText);
    1507             : 
    1508           0 :     m_pActFocusWindow = pControl;
    1509             : 
    1510           0 :     return 0L;
    1511             : }
    1512             : 
    1513           0 : IMPL_LINK(OFieldDescControl, OnControlFocusLost, Control*, pControl )
    1514             : {
    1515           0 :     if ((pControl == pLength) || (pControl == pTextLen) || (pControl == pScale))
    1516             :     {
    1517           0 :         OPropNumericEditCtrl* pConverted = (OPropNumericEditCtrl*)pControl;
    1518           0 :         if (pConverted->IsModified())
    1519           0 :             CellModified(-1, pConverted->GetPos());
    1520             :     }
    1521           0 :     if(pControl == m_pColumnName)
    1522             :     {
    1523           0 :         OPropColumnEditCtrl* pConverted = (OPropColumnEditCtrl*)pControl;
    1524           0 :         if (pConverted->IsModified())
    1525           0 :             CellModified(-1, pConverted->GetPos());
    1526             :     }
    1527           0 :     else if ((pControl == pDefault) || (pControl == pFormatSample) || (pControl == m_pAutoIncrementValue) )
    1528             :     {
    1529           0 :         OPropEditCtrl* pConverted = (OPropEditCtrl*)pControl;
    1530           0 :         if (pConverted->IsModified())
    1531           0 :             CellModified(-1, pConverted->GetPos());
    1532             :     }
    1533           0 :     else if ((pControl == pRequired) || (pControl == pNumType) || (pControl == pAutoIncrement) || (pControl == pBoolDefault) || (pControl == m_pType))
    1534             :     {
    1535           0 :         OPropListBoxCtrl* pConverted = (OPropListBoxCtrl*)pControl;
    1536           0 :         if (pConverted->IsModified())
    1537           0 :             CellModified(-1, pConverted->GetPos());
    1538             :     }
    1539             : 
    1540           0 :     if (pControl == pDefault)
    1541           0 :         UpdateFormatSample(pActFieldDescr);
    1542             : 
    1543           0 :     implFocusLost(pControl);
    1544             : 
    1545           0 :     return 0L;
    1546             : }
    1547             : 
    1548           0 : void OFieldDescControl::SaveData( OFieldDescription* pFieldDescr )
    1549             : {
    1550           0 :     if( !pFieldDescr )
    1551           0 :         return;
    1552             : 
    1553             :     // Read out Controls
    1554           0 :     OUString sDefault;
    1555           0 :     if (pDefault)
    1556             :     {
    1557           0 :         sDefault = pDefault->GetText();
    1558             :     }
    1559           0 :     else if (pBoolDefault)
    1560             :     {
    1561           0 :         sDefault = BoolStringPersistent(pBoolDefault->GetSelectEntry());
    1562             :     }
    1563             : 
    1564           0 :     if ( !sDefault.isEmpty() )
    1565           0 :         pFieldDescr->SetControlDefault(makeAny(sDefault));
    1566             :     else
    1567           0 :         pFieldDescr->SetControlDefault(Any());
    1568             : 
    1569           0 :     if((pRequired && pRequired->GetSelectEntryPos() == 0) || pFieldDescr->IsPrimaryKey() || (pBoolDefault && pBoolDefault->GetEntryCount() == 2))  // yes
    1570           0 :         pFieldDescr->SetIsNullable( ColumnValue::NO_NULLS );
    1571             :     else
    1572           0 :         pFieldDescr->SetIsNullable( ColumnValue::NULLABLE );
    1573             : 
    1574           0 :     if ( pAutoIncrement )
    1575           0 :         pFieldDescr->SetAutoIncrement( pAutoIncrement->GetSelectEntryPos() == 0 );
    1576             : 
    1577           0 :     if( pTextLen )
    1578           0 :         pFieldDescr->SetPrecision( static_cast<sal_Int32>(pTextLen->GetValue()) );
    1579           0 :     else if( pLength )
    1580           0 :         pFieldDescr->SetPrecision( static_cast<sal_Int32>(pLength->GetValue()) );
    1581           0 :     if( pScale )
    1582           0 :         pFieldDescr->SetScale( static_cast<sal_Int32>(pScale->GetValue()) );
    1583             : 
    1584           0 :     if(m_pColumnName)
    1585           0 :         pFieldDescr->SetName(m_pColumnName->GetText());
    1586             : 
    1587           0 :     if ( m_pAutoIncrementValue && isAutoIncrementValueEnabled() )
    1588           0 :         pFieldDescr->SetAutoIncrementValue(m_pAutoIncrementValue->GetText());
    1589             : }
    1590             : 
    1591           0 : void OFieldDescControl::UpdateFormatSample(OFieldDescription* pFieldDescr)
    1592             : {
    1593           0 :     if ( pFieldDescr && pFormatSample )
    1594           0 :         pFormatSample->SetText(getControlDefault(pFieldDescr,sal_False));
    1595           0 : }
    1596             : 
    1597           0 : void OFieldDescControl::GetFocus()
    1598             : {
    1599             :     // Set the Focus to the Control that has been active last
    1600           0 :     TabPage::GetFocus();
    1601           0 :     if( pLastFocusWindow )
    1602             :     {
    1603           0 :         pLastFocusWindow->GrabFocus();
    1604           0 :         pLastFocusWindow = NULL;
    1605             :     }
    1606           0 : }
    1607             : 
    1608           0 : void OFieldDescControl::implFocusLost(Window* _pWhich)
    1609             : {
    1610             :     OSL_ENSURE(!_pWhich || IsChild(_pWhich), "OFieldDescControl::implFocusLost : invalid window !");
    1611             : 
    1612             :     // Remember the active Control
    1613           0 :     if (!pLastFocusWindow)
    1614           0 :         pLastFocusWindow = _pWhich;
    1615             : 
    1616             :     // Reset HelpText
    1617           0 :     if (pHelp && !pHelp->HasChildPathFocus())
    1618           0 :         pHelp->SetHelpText( OUString() );
    1619           0 : }
    1620             : 
    1621           0 : void OFieldDescControl::LoseFocus()
    1622             : {
    1623             : 
    1624           0 :     implFocusLost(NULL);
    1625             : 
    1626           0 :     TabPage::LoseFocus();
    1627           0 : }
    1628             : 
    1629           0 : sal_Bool OFieldDescControl::isCopyAllowed()
    1630             : {
    1631           0 :     sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
    1632           0 :                         (m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample    ||
    1633           0 :                         m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength           ||
    1634           0 :                         m_pActFocusWindow == pScale  || m_pActFocusWindow == m_pColumnName      ||
    1635           0 :                         m_pActFocusWindow == m_pAutoIncrementValue) &&
    1636           0 :                         !static_cast<Edit*>(m_pActFocusWindow)->GetSelected().isEmpty();
    1637             : 
    1638           0 :     return bAllowed;
    1639             : }
    1640             : 
    1641           0 : sal_Bool OFieldDescControl::isCutAllowed()
    1642             : {
    1643           0 :     sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
    1644           0 :                         (m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample    ||
    1645           0 :                         m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength           ||
    1646           0 :                         m_pActFocusWindow == pScale  || m_pActFocusWindow == m_pColumnName      ||
    1647           0 :                         m_pActFocusWindow == m_pAutoIncrementValue) &&
    1648           0 :                         !static_cast<Edit*>(m_pActFocusWindow)->GetSelected().isEmpty();
    1649           0 :     return bAllowed;
    1650             : }
    1651             : 
    1652           0 : sal_Bool OFieldDescControl::isPasteAllowed()
    1653             : {
    1654           0 :     sal_Bool bAllowed = (m_pActFocusWindow != NULL) &&
    1655           0 :                         (m_pActFocusWindow == pDefault || m_pActFocusWindow == pFormatSample    ||
    1656           0 :                         m_pActFocusWindow == pTextLen || m_pActFocusWindow == pLength           ||
    1657           0 :                         m_pActFocusWindow == pScale  || m_pActFocusWindow == m_pColumnName      ||
    1658           0 :                         m_pActFocusWindow == m_pAutoIncrementValue);
    1659           0 :     if ( bAllowed )
    1660             :     {
    1661           0 :         TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
    1662           0 :         bAllowed = aTransferData.HasFormat(SOT_FORMAT_STRING);
    1663             :     }
    1664           0 :     return bAllowed;
    1665             : }
    1666             : 
    1667           0 : void OFieldDescControl::cut()
    1668             : {
    1669           0 :     if(isCutAllowed())
    1670           0 :         static_cast<Edit*>(m_pActFocusWindow)->Cut();
    1671           0 : }
    1672             : 
    1673           0 : void OFieldDescControl::copy()
    1674             : {
    1675           0 :     if(isCopyAllowed()) // this only checks if the focus window is valid
    1676           0 :         static_cast<Edit*>(m_pActFocusWindow)->Copy();
    1677           0 : }
    1678             : 
    1679           0 : void OFieldDescControl::paste()
    1680             : {
    1681           0 :     if(m_pActFocusWindow) // this only checks if the focus window is valid
    1682           0 :         static_cast<Edit*>(m_pActFocusWindow)->Paste();
    1683           0 : }
    1684             : 
    1685           0 : sal_Bool OFieldDescControl::isTextFormat(const OFieldDescription* _pFieldDescr,sal_uInt32& _nFormatKey) const
    1686             : {
    1687           0 :     _nFormatKey = _pFieldDescr->GetFormatKey();
    1688           0 :     sal_Bool bTextFormat = sal_True;
    1689             : 
    1690             :     try
    1691             :     {
    1692           0 :         if (!_nFormatKey)
    1693             :         {
    1694           0 :             Reference< ::com::sun::star::util::XNumberFormatTypes> xNumberTypes(GetFormatter()->getNumberFormatsSupplier()->getNumberFormats(),UNO_QUERY);
    1695             :             OSL_ENSURE(xNumberTypes.is(),"XNumberFormatTypes is null!");
    1696             : 
    1697             :             _nFormatKey = ::dbtools::getDefaultNumberFormat( _pFieldDescr->GetType(),
    1698             :                 _pFieldDescr->GetScale(),
    1699           0 :                 _pFieldDescr->IsCurrency(),
    1700             :                 xNumberTypes,
    1701           0 :                 GetLocale());
    1702             :         }
    1703           0 :         sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(GetFormatter(),_nFormatKey);
    1704           0 :         bTextFormat = (nNumberFormat == ::com::sun::star::util::NumberFormat::TEXT);
    1705             :     }
    1706           0 :     catch(const Exception&)
    1707             :     {
    1708             : 
    1709             :     }
    1710             : 
    1711           0 :     return bTextFormat;
    1712             : }
    1713             : 
    1714           0 : OUString OFieldDescControl::getControlDefault( const OFieldDescription* _pFieldDescr ,sal_Bool _bCheck) const
    1715             : {
    1716           0 :     OUString sDefault;
    1717           0 :     sal_Bool bCheck = !_bCheck || _pFieldDescr->GetControlDefault().hasValue();
    1718           0 :     if ( bCheck )
    1719             :     {
    1720             :         sal_uInt32 nFormatKey;
    1721           0 :         sal_Bool bTextFormat = sal_False;
    1722             : 
    1723             :         try
    1724             :         {
    1725           0 :             double nValue = 0.0;
    1726           0 :             bTextFormat = isTextFormat(_pFieldDescr,nFormatKey);
    1727           0 :             if ( _pFieldDescr->GetControlDefault() >>= sDefault )
    1728             :             {
    1729           0 :                 if ( !bTextFormat )
    1730             :                 {
    1731           0 :                     if ( !sDefault.isEmpty() )
    1732             :                     {
    1733             :                         try
    1734             :                         {
    1735           0 :                             nValue = GetFormatter()->convertStringToNumber(nFormatKey,sDefault);
    1736             :                         }
    1737           0 :                         catch(const Exception&)
    1738             :                         {
    1739           0 :                             return OUString(); // return empty string for format example
    1740             :                         }
    1741             :                     }
    1742             :                 }
    1743             :             }
    1744             :             else
    1745           0 :                 _pFieldDescr->GetControlDefault() >>= nValue;
    1746             : 
    1747           0 :             Reference< ::com::sun::star::util::XNumberFormatter> xNumberFormatter = GetFormatter();
    1748           0 :             Reference<XPropertySet> xFormSet = xNumberFormatter->getNumberFormatsSupplier()->getNumberFormats()->getByKey(nFormatKey);
    1749             :             OSL_ENSURE(xFormSet.is(),"XPropertySet is null!");
    1750           0 :             OUString sFormat;
    1751           0 :             xFormSet->getPropertyValue("FormatString") >>= sFormat;
    1752             : 
    1753           0 :             if ( !bTextFormat )
    1754             :             {
    1755           0 :                 Locale aLocale;
    1756           0 :                 ::comphelper::getNumberFormatProperty(xNumberFormatter,nFormatKey,OUString("Locale")) >>= aLocale;
    1757             : 
    1758           0 :                 sal_Int32 nNumberFormat = ::comphelper::getNumberFormatType(xNumberFormatter,nFormatKey);
    1759           0 :                 if(     (nNumberFormat & ::com::sun::star::util::NumberFormat::DATE)    == ::com::sun::star::util::NumberFormat::DATE
    1760           0 :                     || (nNumberFormat & ::com::sun::star::util::NumberFormat::DATETIME) == ::com::sun::star::util::NumberFormat::DATETIME )
    1761             :                 {
    1762           0 :                     nValue = DBTypeConversion::toNullDate(DBTypeConversion::getNULLDate(xNumberFormatter->getNumberFormatsSupplier()),nValue);
    1763             :                 }
    1764             : 
    1765           0 :                 Reference< ::com::sun::star::util::XNumberFormatPreviewer> xPreviewer(xNumberFormatter,UNO_QUERY);
    1766             :                 OSL_ENSURE(xPreviewer.is(),"XNumberFormatPreviewer is null!");
    1767           0 :                 sDefault = xPreviewer->convertNumberToPreviewString(sFormat,nValue,aLocale,sal_True);
    1768             :             }
    1769           0 :             else if ( !(_bCheck && sDefault.isEmpty()) )
    1770           0 :                 sDefault = xNumberFormatter->formatString(nFormatKey, sDefault.isEmpty() ? sFormat : sDefault);
    1771             :         }
    1772           0 :         catch(const Exception&)
    1773             :         {
    1774             : 
    1775             :         }
    1776             :     }
    1777             : 
    1778           0 :     return sDefault;
    1779          27 : }
    1780             : 
    1781             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10