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

Generated by: LCOV version 1.10