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