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