1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
|
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2008 by Sun Microsystems, Inc.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: Condition.cxx,v $
* $Revision: 1.6 $
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include "precompiled_reportdesign.hxx"
#include "Condition.hxx"
#include "UITools.hxx"
#include "CondFormat.hxx"
#include "CondFormat.hrc"
#include "RptResId.hrc"
#include "ReportController.hxx"
#include "ModuleHelper.hxx"
#include "ColorChanger.hxx"
#include "RptResId.hrc"
#include "helpids.hrc"
#include "reportformula.hxx"
#include <com/sun/star/util/URL.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/ui/XUIConfigurationManager.hpp>
#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
#include <com/sun/star/ui/XImageManager.hpp>
#include <com/sun/star/awt/FontDescriptor.hpp>
#include <com/sun/star/ui/ImageType.hpp>
#define ITEMID_COLOR
#define ITEMID_BRUSH
#include <svx/tbcontrl.hxx>
#include <svx/svxids.hrc>
#include <svx/xtable.hxx>
#include <svx/tbxcolorupdate.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <svtools/imgdef.hxx>
#include <svtools/pathoptions.hxx>
#include <vcl/svapp.hxx>
#include <vcl/bmpacc.hxx>
#include <tools/diagnose_ex.h>
#include <rtl/ustrbuf.hxx>
namespace rptui
{
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::beans;
ConditionField::ConditionField( Condition* _pParent, const ResId& _rResId ) : Edit(_pParent,_rResId)
,m_pParent(_pParent)
,m_aFormula(this)
{
m_pSubEdit = new Edit(this,0);
SetSubEdit(m_pSubEdit);
m_pSubEdit->EnableRTL( FALSE );
m_pSubEdit->SetPosPixel( Point() );
m_aFormula.SetText(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("...")));
m_aFormula.SetClickHdl( LINK( this, ConditionField, OnFormula ) );
m_aFormula.Show();
m_pSubEdit->Show();
Resize();
}
// -----------------------------------------------------------------------------
ConditionField::~ConditionField()
{
SetSubEdit(NULL);
delete m_pSubEdit;
}
// -----------------------------------------------------------------------------
void ConditionField::Resize()
{
Edit::Resize();
const Size aSize = GetOutputSizePixel();
const Size aButtonSize( LogicToPixel( Size( 12, 0 ), MAP_APPFONT ).Width(),aSize.Height());
const Point aButtonPos(aSize.Width() - aButtonSize.Width(), 0);
m_aFormula.SetPosSizePixel(aButtonPos,aButtonSize);
m_pSubEdit->SetPosSizePixel(Point(0,0),Size(aButtonPos.X() ,aSize.Height()));
}
// -----------------------------------------------------------------------------
IMPL_LINK( ConditionField, OnFormula, Button*, /*_pClickedButton*/ )
{
::rtl::OUString sFormula(m_pSubEdit->GetText());
const sal_Int32 nLen = sFormula.getLength();
if ( nLen )
{
ReportFormula aFormula( sFormula );
sFormula = aFormula.getCompleteFormula();
} // if ( nLen )
uno::Reference< awt::XWindow> xInspectorWindow = VCLUnoHelper::GetInterface(this);
uno::Reference< beans::XPropertySet> xProp(m_pParent->getController().getRowSet(),uno::UNO_QUERY);
if ( rptui::openDialogFormula_nothrow( sFormula, m_pParent->getController().getContext(),xInspectorWindow,xProp ) )
{
ReportFormula aFormula( sFormula );
m_pSubEdit->SetText(aFormula.getUndecoratedContent());
}
return 0L;
}
//========================================================================
// class SvxColorWindow_Impl --------------------------------------------------
//========================================================================
#ifndef WB_NO_DIRECTSELECT
#define WB_NO_DIRECTSELECT ((WinBits)0x04000000)
#endif
#define PALETTE_X 10
#define PALETTE_Y 10
#define PALETTE_SIZE (PALETTE_X * PALETTE_Y)
class OColorPopup : public FloatingWindow
{
DECL_LINK( SelectHdl, void * );
Condition* m_pCondition;
USHORT m_nSlotId;
public:
OColorPopup(Window* _pParent,Condition* _pCondition);
ValueSet m_aColorSet;
virtual void KeyInput( const KeyEvent& rKEvt );
virtual void Resize();
void StartSelection();
void SetSlotId(USHORT _nSlotId);
};
// -----------------------------------------------------------------------------
OColorPopup::OColorPopup(Window* _pParent,Condition* _pCondition)
:FloatingWindow(_pParent, WinBits( WB_BORDER | WB_STDFLOATWIN | WB_3DLOOK|WB_DIALOGCONTROL ))
,m_pCondition(_pCondition)
,m_nSlotId(0)
,m_aColorSet( this, WinBits( WB_ITEMBORDER | WB_NAMEFIELD | WB_3DLOOK | WB_NO_DIRECTSELECT) )
{
m_aColorSet.SetHelpId( HID_RPT_POPUP_COLOR_CTRL );
SetHelpId( HID_RPT_POPUP_COLOR );
const Size aSize12( 13, 13 );
::std::auto_ptr<XColorTable> pColorTable(new XColorTable( SvtPathOptions().GetPalettePath() ));
short i = 0;
long nCount = pColorTable->Count();
XColorEntry* pEntry = NULL;
Color aColWhite( COL_WHITE );
String aStrWhite( ModuleRes(STR_COLOR_WHITE) );
if ( nCount > PALETTE_SIZE )
// Show scrollbar if more than PALLETTE_SIZE colors are available
m_aColorSet.SetStyle( m_aColorSet.GetStyle() | WB_VSCROLL );
for ( i = 0; i < nCount; i++ )
{
pEntry = pColorTable->GetColor(i);
m_aColorSet.InsertItem( i+1, pEntry->GetColor(), pEntry->GetName() );
}
while ( i < PALETTE_SIZE )
{
// fill empty elements if less then PALLETTE_SIZE colors are available
m_aColorSet.InsertItem( i+1, aColWhite, aStrWhite );
i++;
}
m_aColorSet.SetSelectHdl( LINK( this, OColorPopup, SelectHdl ) );
m_aColorSet.SetColCount( PALETTE_X );
m_aColorSet.SetLineCount( PALETTE_Y );
Size aSize = m_aColorSet.CalcWindowSizePixel( aSize12 );
aSize.Width() += 4;
aSize.Height() += 4;
SetOutputSizePixel( aSize );
m_aColorSet.Show();
}
// -----------------------------------------------------------------------------
void OColorPopup::KeyInput( const KeyEvent& rKEvt )
{
m_aColorSet.KeyInput(rKEvt);
}
// -----------------------------------------------------------------------------
void OColorPopup::Resize()
{
Size aSize = GetOutputSizePixel();
aSize.Width() -= 4;
aSize.Height() -= 4;
m_aColorSet.SetPosSizePixel( Point(2,2), aSize );
}
// -----------------------------------------------------------------------------
void OColorPopup::StartSelection()
{
m_aColorSet.StartSelection();
}
// -----------------------------------------------------------------------------
void OColorPopup::SetSlotId(USHORT _nSlotId)
{
m_nSlotId = _nSlotId;
if ( SID_ATTR_CHAR_COLOR_BACKGROUND == _nSlotId || SID_BACKGROUND_COLOR == _nSlotId )
{
m_aColorSet.SetStyle( m_aColorSet.GetStyle() | WB_NONEFIELD );
m_aColorSet.SetText( String(ModuleRes( STR_TRANSPARENT )) );
} // if ( SID_ATTR_CHAR_COLOR_BACKGROUND == theSlotId || SID_BACKGROUND_COLOR == theSlotId )
}
// -----------------------------------------------------------------------------
IMPL_LINK( OColorPopup, SelectHdl, void *, EMPTYARG )
{
USHORT nItemId = m_aColorSet.GetSelectItemId();
Color aColor( nItemId == 0 ? Color( COL_TRANSPARENT ) : m_aColorSet.GetItemColor( nItemId ) );
/* #i33380# DR 2004-09-03 Moved the following line above the Dispatch() calls.
This instance may be deleted in the meantime (i.e. when a dialog is opened
while in Dispatch()), accessing members will crash in this case. */
m_aColorSet.SetNoSelection();
if ( IsInPopupMode() )
EndPopupMode();
m_pCondition->ApplyCommand( m_nSlotId, aColor );
return 0;
}
// =============================================================================
// = Condition
// =============================================================================
// -----------------------------------------------------------------------------
Condition::Condition( Window* _pParent, IConditionalFormatAction& _rAction, ::rptui::OReportController& _rController )
:Control(_pParent, ModuleRes(WIN_CONDITION))
,m_rController( _rController )
,m_rAction( _rAction )
,m_aHeader(this, ModuleRes(FL_CONDITION_HEADER))
,m_aConditionType(this, ModuleRes(LB_COND_TYPE))
,m_aOperationList( this, ModuleRes(LB_OP))
,m_aCondLHS(this, ModuleRes(ED_CONDITION_LHS))
,m_aOperandGlue(this, ModuleRes(FT_AND))
,m_aCondRHS(this, ModuleRes(ED_CONDITION_RHS))
,m_aActions(this, ModuleRes(TB_FORMAT))
,m_aPreview(this, ModuleRes(CRTL_FORMAT_PREVIEW))
,m_aMoveUp( this, ModuleRes( BTN_MOVE_UP ) )
,m_aMoveDown( this, ModuleRes( BTN_MOVE_DOWN ) )
,m_aAddCondition( this, ModuleRes( BTN_ADD_CONDITION ) )
,m_aRemoveCondition( this, ModuleRes( BTN_REMOVE_CONDITION ) )
,m_pColorFloat(NULL)
,m_pBtnUpdaterFontColor(NULL)
,m_pBtnUpdaterBackgroundColor(NULL)
,m_nCondIndex( 0 )
,m_nLastKnownWindowWidth( -1 )
,m_bInDestruction( false )
{
m_aMoveUp.SetModeImage( ModuleRes( IMG_MOVE_UP_HC ), BMP_COLOR_HIGHCONTRAST );
m_aMoveDown.SetModeImage( ModuleRes( IMG_MOVE_DOWN_HC ), BMP_COLOR_HIGHCONTRAST );
FreeResource();
m_aActions.SetStyle(m_aActions.GetStyle()|WB_LINESPACING);
m_aCondLHS.GrabFocus();
m_aConditionType.SetSelectHdl( LINK( this, Condition, OnTypeSelected ) );
m_aOperationList.SetDropDownLineCount( 10 );
m_aOperationList.SetSelectHdl( LINK( this, Condition, OnOperationSelected ) );
m_aActions.SetSelectHdl(LINK(this, Condition, OnFormatAction));
m_aActions.SetDropdownClickHdl( LINK( this, Condition, DropdownClick ) );
setToolBox(&m_aActions);
m_aMoveUp.SetClickHdl( LINK( this, Condition, OnConditionAction ) );
m_aMoveDown.SetClickHdl( LINK( this, Condition, OnConditionAction ) );
m_aAddCondition.SetClickHdl( LINK( this, Condition, OnConditionAction ) );
m_aRemoveCondition.SetClickHdl( LINK( this, Condition, OnConditionAction ) );
m_aMoveUp.SetStyle( m_aMoveUp.GetStyle() | WB_NOPOINTERFOCUS );
m_aMoveDown.SetStyle( m_aMoveDown.GetStyle() | WB_NOPOINTERFOCUS );
m_aAddCondition.SetStyle( m_aMoveUp.GetStyle() | WB_NOPOINTERFOCUS | WB_CENTER | WB_VCENTER );
m_aRemoveCondition.SetStyle( m_aMoveDown.GetStyle() | WB_NOPOINTERFOCUS | WB_CENTER | WB_VCENTER );
Font aFont( m_aAddCondition.GetFont() );
aFont.SetWeight( WEIGHT_BOLD );
m_aAddCondition.SetFont( aFont );
m_aRemoveCondition.SetFont( aFont );
m_aOperandGlue.SetStyle( m_aOperandGlue.GetStyle() | WB_VCENTER );
m_aConditionType.SelectEntryPos( 0 );
m_aOperationList.SelectEntryPos( 0 );
// the toolbar got its site automatically, ensure that the preview is positioned
// right of it
Size aRelatedControls( LogicToPixel( Size( RELATED_CONTROLS, 0 ), MAP_APPFONT ) );
Point aToolbarPos( m_aActions.GetPosPixel() );
Size aToolbarSize( m_aActions.GetSizePixel() );
m_aPreview.SetPosSizePixel( aToolbarPos.X() + aToolbarSize.Width() + 2 * aRelatedControls.Width(),
0, 0, 0, WINDOW_POSSIZE_X );
// ensure the toolbar is vertically centered, relative to the preview
Size aPreviewSize( m_aPreview.GetSizePixel() );
m_aActions.SetPosSizePixel( 0, aToolbarPos.Y() + ( aPreviewSize.Height() - aToolbarSize.Height() ) / 2, 0, 0, WINDOW_POSSIZE_Y );
m_pBtnUpdaterBackgroundColor = new ::svx::ToolboxButtonColorUpdater(
SID_BACKGROUND_COLOR, SID_BACKGROUND_COLOR, &m_aActions );
m_pBtnUpdaterFontColor = new ::svx::ToolboxButtonColorUpdater(
SID_ATTR_CHAR_COLOR2, SID_ATTR_CHAR_COLOR2, &m_aActions, TBX_UPDATER_MODE_CHAR_COLOR_NEW );
Show();
impl_layoutAll();
ConditionalExpressionFactory::getKnownConditionalExpressions( m_aConditionalExpressions );
}
// -----------------------------------------------------------------------------
Condition::~Condition()
{
m_bInDestruction = true;
delete m_pColorFloat;
delete m_pBtnUpdaterFontColor;
delete m_pBtnUpdaterBackgroundColor;
}
// -----------------------------------------------------------------------------
IMPL_LINK( Condition, DropdownClick, ToolBox*, /*pToolBar*/ )
{
USHORT nId( m_aActions.GetCurItemId() );
if ( !m_pColorFloat )
m_pColorFloat = new OColorPopup(&m_aActions,this);
USHORT nTextId = 0;
switch(nId)
{
case SID_ATTR_CHAR_COLOR2:
nTextId = STR_CHARCOLOR;
break;
case SID_BACKGROUND_COLOR:
nTextId = STR_CHARBACKGROUND;
break;
default:
break;
} // switch(nId)
if ( nTextId )
m_pColorFloat->SetText(String(ModuleRes(nTextId)));
m_pColorFloat->SetSlotId(nId);
m_pColorFloat->SetPosPixel(m_aActions.GetItemPopupPosition(nId,m_pColorFloat->GetSizePixel()));
m_pColorFloat->StartPopupMode(&m_aActions);
m_pColorFloat->StartSelection();
return 1;
}
//------------------------------------------------------------------
IMPL_LINK( Condition, OnFormatAction, ToolBox*, /*NOTINTERESTEDIN*/ )
{
Color aCol(COL_AUTO);
ApplyCommand(m_aActions.GetCurItemId(),aCol);
return 0L;
}
//------------------------------------------------------------------
IMPL_LINK( Condition, OnConditionAction, Button*, _pClickedButton )
{
if ( _pClickedButton == &m_aMoveUp )
m_rAction.moveConditionUp( getConditionIndex() );
else if ( _pClickedButton == &m_aMoveDown )
m_rAction.moveConditionDown( getConditionIndex() );
else if ( _pClickedButton == &m_aAddCondition )
m_rAction.addCondition( getConditionIndex() );
else if ( _pClickedButton == &m_aRemoveCondition )
m_rAction.deleteCondition( getConditionIndex() );
return 0L;
}
//------------------------------------------------------------------------------
void Condition::ApplyCommand( USHORT _nCommandId, const ::Color& _rColor)
{
if ( _nCommandId == SID_ATTR_CHAR_COLOR2 )
m_pBtnUpdaterFontColor->Update( _rColor );
else if ( _nCommandId == SID_BACKGROUND_COLOR )
m_pBtnUpdaterBackgroundColor->Update( _rColor );
m_rAction.applyCommand( m_nCondIndex, _nCommandId, _rColor );
}
//------------------------------------------------------------------------------
ImageList Condition::getImageList(sal_Int16 _eBitmapSet,sal_Bool _bHiContast) const
{
sal_Int16 nN = IMG_CONDFORMAT_DLG_SC;
sal_Int16 nH = IMG_CONDFORMAT_DLG_SCH;
if ( _eBitmapSet == SFX_SYMBOLS_SIZE_LARGE )
{
nN = IMG_CONDFORMAT_DLG_LC;
nH = IMG_CONDFORMAT_DLG_LCH;
}
return ImageList(ModuleRes( _bHiContast ? nH : nN ));
}
//------------------------------------------------------------------
void Condition::resizeControls(const Size& _rDiff)
{
// we use large images so we must change them
if ( _rDiff.Width() || _rDiff.Height() )
{
Point aPos = LogicToPixel( Point( 2*RELATED_CONTROLS , 0), MAP_APPFONT );
Invalidate();
}
}
// -----------------------------------------------------------------------------
void Condition::Paint( const Rectangle& rRect )
{
Control::Paint(rRect);
// draw border
const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
ColorChanger aColors( this, rStyleSettings.GetShadowColor(), rStyleSettings.GetDialogColor() );
DrawRect( impl_getToolBarBorderRect() );
}
// -----------------------------------------------------------------------------
void Condition::StateChanged( StateChangedType nType )
{
Control::StateChanged( nType );
if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
{
// Check if we need to get new images for normal/high contrast mode
checkImageList();
}
else if ( nType == STATE_CHANGE_TEXT )
{
// The physical toolbar changed its outlook and shows another logical toolbar!
// We have to set the correct high contrast mode on the new tbx manager.
// pMgr->SetHiContrast( IsHiContrastMode() );
checkImageList();
}
}
// -----------------------------------------------------------------------------
void Condition::DataChanged( const DataChangedEvent& rDCEvt )
{
Control::DataChanged( rDCEvt );
if ((( rDCEvt.GetType() == DATACHANGED_SETTINGS ) ||
( rDCEvt.GetType() == DATACHANGED_DISPLAY )) &&
( rDCEvt.GetFlags() & SETTINGS_STYLE ))
{
// Check if we need to get new images for normal/high contrast mode
checkImageList();
}
}
// -----------------------------------------------------------------------------
void Condition::GetFocus()
{
Control::GetFocus();
if ( !m_bInDestruction )
m_aCondLHS.GrabFocus();
}
// -----------------------------------------------------------------------------
void Condition::Resize()
{
Control::Resize();
impl_layoutAll();
}
// -----------------------------------------------------------------------------
Rectangle Condition::impl_getToolBarBorderRect() const
{
const Point aToolbarPos( m_aActions.GetPosPixel() );
const Size aToolbarSize( m_aActions.GetSizePixel() );
const Size aRelatedControls = LogicToPixel( Size( RELATED_CONTROLS, RELATED_CONTROLS ), MAP_APPFONT );
Rectangle aBorderRect( aToolbarPos, aToolbarSize );
aBorderRect.Left() -= aRelatedControls.Width();
aBorderRect.Top() -= aRelatedControls.Height();
aBorderRect.Right() += aRelatedControls.Width();
aBorderRect.Bottom() += aRelatedControls.Height();
return aBorderRect;
}
// -----------------------------------------------------------------------------
void Condition::impl_layoutAll()
{
// if our width changed, resize/-position some controls
const Size aSize( GetOutputSizePixel() );
if ( aSize.Width() == m_nLastKnownWindowWidth )
return;
m_nLastKnownWindowWidth = aSize.Width();
const Size aRelatedControls( LogicToPixel( Size( RELATED_CONTROLS, RELATED_CONTROLS ), MAP_APPFONT ) );
const Size aUnrelatedControls( LogicToPixel( Size( UNRELATED_CONTROLS, 0 ), MAP_APPFONT ) );
const Point aRow1( LogicToPixel( Point( 0, ROW_1_POS ), MAP_APPFONT ) );
const Point aRow3( LogicToPixel( Point( 0, ROW_3_POS ), MAP_APPFONT ) );
// resize the header line
m_aHeader.SetPosSizePixel( 0, 0, aSize.Width() - 2 * aRelatedControls.Width(), 0, WINDOW_POSSIZE_WIDTH );
// position the up/down buttons
const Size aButtonSize( LogicToPixel( Size( IMAGE_BUTTON_WIDTH, IMAGE_BUTTON_HEIGHT ), MAP_APPFONT ) );
Point aButtonPos( aSize.Width() - aUnrelatedControls.Width() - aButtonSize.Width(), aRow1.Y() );
m_aMoveUp.SetPosSizePixel( aButtonPos.X(), aButtonPos.Y(), aButtonSize.Width(), aButtonSize.Height() );
aButtonPos.Move( 0, aButtonSize.Height() + aRelatedControls.Height() );
m_aMoveDown.SetPosSizePixel( aButtonPos.X(), aButtonPos.Y(), aButtonSize.Width(), aButtonSize.Height() );
// resize the preview
const long nNewPreviewRight = aButtonPos.X() - aRelatedControls.Width();
const Point aPreviewPos( m_aPreview.GetPosPixel() );
OSL_ENSURE( aPreviewPos.X() < nNewPreviewRight, "Condition::impl_layoutAll: being *that* small should not be allowed!" );
m_aPreview.SetPosSizePixel( 0, 0, nNewPreviewRight - aPreviewPos.X(), 0, WINDOW_POSSIZE_WIDTH );
// position the add/remove buttons
aButtonPos = Point( nNewPreviewRight - aButtonSize.Width(), aRow3.Y() );
m_aRemoveCondition.SetPosSizePixel( aButtonPos.X(), aButtonPos.Y(), aButtonSize.Width(), aButtonSize.Height() );
aButtonPos.Move( -( aButtonSize.Width() + aRelatedControls.Width() ), 0 );
m_aAddCondition.SetPosSizePixel( aButtonPos.X(), aButtonPos.Y(), aButtonSize.Width(), aButtonSize.Height() );
// layout the operands input controls
impl_layoutOperands();
}
// -----------------------------------------------------------------------------
IMPL_LINK( Condition, OnTypeSelected, ListBox*, /*_pNotInterestedIn*/ )
{
impl_layoutOperands();
return 0L;
}
// -----------------------------------------------------------------------------
IMPL_LINK( Condition, OnOperationSelected, ListBox*, /*_pNotInterestedIn*/ )
{
impl_layoutOperands();
return 0L;
}
// -----------------------------------------------------------------------------
void Condition::impl_layoutOperands()
{
const ConditionType eType( impl_getCurrentConditionType() );
const ComparisonOperation eOperation( impl_getCurrentComparisonOperation() );
const bool bIsExpression = ( eType == eExpression );
const bool bHaveRHS =
( ( eType == eFieldValueComparison )
&& ( ( eOperation == eBetween )
|| ( eOperation == eNotBetween )
)
);
const Size aRelatedControls( LogicToPixel( Size( RELATED_CONTROLS, 0 ), MAP_APPFONT ) );
const Rectangle aPreviewRect( m_aPreview.GetPosPixel(), m_aPreview.GetSizePixel() );
// the "condition type" list box
const Rectangle aCondTypeRect( m_aConditionType.GetPosPixel(), m_aConditionType.GetSizePixel() );
const Point aOpListPos( aCondTypeRect.Right() + aRelatedControls.Width(), aCondTypeRect.Top() );
const Size aOpListSize( LogicToPixel( Size( COND_OP_WIDTH, 60 ), MAP_APPFONT ) );
m_aOperationList.SetPosSizePixel( aOpListPos.X(), aOpListPos.Y(),aOpListSize.Width(), aOpListSize.Height() );
m_aOperationList.Show( !bIsExpression );
// the LHS input field
Point aLHSPos( aOpListPos.X() + aOpListSize.Width() + aRelatedControls.Width(), aOpListPos.Y() );
if ( bIsExpression )
aLHSPos.X() = aOpListPos.X();
Size aLHSSize( LogicToPixel( Size( EDIT_WIDTH, EDIT_HEIGHT ), MAP_APPFONT ) );
if ( !bHaveRHS )
aLHSSize.Width() = aPreviewRect.Right() - aLHSPos.X();
m_aCondLHS.SetPosSizePixel( aLHSPos.X(), aLHSPos.Y(), aLHSSize.Width(), aLHSSize.Height() );
if ( bHaveRHS )
{
// the "and" text being the glue between LHS and RHS
const Point aOpGluePos( aLHSPos.X() + aLHSSize.Width() + aRelatedControls.Width(), aLHSPos.Y() );
const Size aOpGlueSize( m_aOperandGlue.GetTextWidth( m_aOperandGlue.GetText() ) + aRelatedControls.Width(), aLHSSize.Height() );
m_aOperandGlue.SetPosSizePixel( aOpGluePos.X(), aOpGluePos.Y(), aOpGlueSize.Width(), aOpGlueSize.Height() );
// the RHS input field
const Point aRHSPos( aOpGluePos.X() + aOpGlueSize.Width() + aRelatedControls.Width(), aOpGluePos.Y() );
const Size aRHSSize( aPreviewRect.Right() - aRHSPos.X(), aLHSSize.Height() );
m_aCondRHS.SetPosSizePixel( aRHSPos.X(), aRHSPos.Y(), aRHSSize.Width(), aRHSSize.Height() );
}
m_aOperandGlue.Show( bHaveRHS );
m_aCondRHS.Show( bHaveRHS );
}
// -----------------------------------------------------------------------------
void Condition::impl_setCondition( const ::rtl::OUString& _rConditionFormula )
{
// determine the condition's type and comparison operation
ConditionType eType( eFieldValueComparison );
ComparisonOperation eOperation( eBetween );
// LHS and RHS, matched below
::rtl::OUString sLHS, sRHS;
if ( _rConditionFormula.getLength() )
{
// the unprefixed expression which forms the condition
ReportFormula aFormula( _rConditionFormula );
OSL_ENSURE( aFormula.getType() == ReportFormula::Expression, "Condition::setCondition: illegal formula!" );
::rtl::OUString sExpression;
if ( aFormula.getType() == ReportFormula::Expression )
sExpression = aFormula.getExpression();
// as fallback, if the below matching does not succeed, assume
// the whole expression is the LHS
eType = eExpression;
sLHS = sExpression;
// the data field (or expression) to which our control is bound
const ReportFormula aFieldContentFormula( m_rAction.getDataField() );
const ::rtl::OUString sUnprefixedFieldContent( aFieldContentFormula.getBracketedFieldOrExpression() );
// check whether one of the Field Value Expression Factories recognizes the expression
for ( ConditionalExpressions::const_iterator exp = m_aConditionalExpressions.begin();
exp != m_aConditionalExpressions.end();
++exp
)
{
if ( exp->second->matchExpression( sExpression, sUnprefixedFieldContent, sLHS, sRHS ) )
{
eType = eFieldValueComparison;
eOperation = exp->first;
break;
}
}
}
// update UI
m_aConditionType.SelectEntryPos( (USHORT)eType );
m_aOperationList.SelectEntryPos( (USHORT)eOperation );
m_aCondLHS.SetText( sLHS );
m_aCondRHS.SetText( sRHS );
// re-layout
impl_layoutOperands();
}
// -----------------------------------------------------------------------------
void Condition::setCondition( const uno::Reference< report::XFormatCondition >& _rxCondition )
{
OSL_PRECOND( _rxCondition.is(), "Condition::setCondition: empty condition object!" );
if ( !_rxCondition.is() )
return;
::rtl::OUString sConditionFormula;
try
{
if ( _rxCondition.is() )
sConditionFormula = _rxCondition->getFormula();
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
impl_setCondition( sConditionFormula );
updateToolbar( _rxCondition.get() );
}
// -----------------------------------------------------------------------------
void Condition::updateToolbar(const uno::Reference< report::XReportControlFormat >& _xReportControlFormat)
{
OSL_ENSURE(_xReportControlFormat.is(),"XReportControlFormat is NULL!");
if ( _xReportControlFormat.is() )
{
USHORT nItemCount = m_aActions.GetItemCount();
for (USHORT j = 0; j< nItemCount; ++j)
{
USHORT nItemId = m_aActions.GetItemId(j);
m_aActions.CheckItem( nItemId, m_rController.isFormatCommandEnabled( nItemId, _xReportControlFormat ) );
}
try
{
Font aBaseFont( Application::GetDefaultDevice()->GetSettings().GetStyleSettings().GetAppFont() );
SvxFont aFont( VCLUnoHelper::CreateFont( _xReportControlFormat->getFontDescriptor(), aBaseFont ) );
aFont.SetHeight( OutputDevice::LogicToLogic( Size( 0, (sal_Int32)aFont.GetHeight() ), MAP_POINT, MAP_TWIP ).Height());
aFont.SetEmphasisMark( static_cast< FontEmphasisMark >( _xReportControlFormat->getControlTextEmphasis() ) );
aFont.SetRelief( static_cast< FontRelief >( _xReportControlFormat->getCharRelief() ) );
aFont.SetColor( _xReportControlFormat->getCharColor() );
m_aPreview.SetFont( aFont );
m_aPreview.SetBackColor( _xReportControlFormat->getControlBackground() );
m_aPreview.SetTextLineColor( Color( _xReportControlFormat->getCharUnderlineColor() ) );
}
catch( const Exception& )
{
DBG_UNHANDLED_EXCEPTION();
}
}
}
// -----------------------------------------------------------------------------
void Condition::fillFormatCondition(const uno::Reference< report::XFormatCondition >& _xCondition)
{
const ConditionType eType( impl_getCurrentConditionType() );
const ComparisonOperation eOperation( impl_getCurrentComparisonOperation() );
const ::rtl::OUString sLHS( m_aCondLHS.GetText() );
const ::rtl::OUString sRHS( m_aCondRHS.GetText() );
::rtl::OUString sUndecoratedFormula( sLHS );
if ( eType == eFieldValueComparison )
{
ReportFormula aFieldContentFormula( m_rAction.getDataField() );
::rtl::OUString sUnprefixedFieldContent( aFieldContentFormula.getBracketedFieldOrExpression() );
PConditionalExpression pFactory( m_aConditionalExpressions[ eOperation ] );
sUndecoratedFormula = pFactory->assembleExpression( sUnprefixedFieldContent, sLHS, sRHS );
}
ReportFormula aFormula( ReportFormula::Expression, sUndecoratedFormula );
_xCondition->setFormula( aFormula.getCompleteFormula() );
}
// -----------------------------------------------------------------------------
void Condition::setConditionIndex( size_t _nCondIndex, size_t _nCondCount )
{
m_nCondIndex = _nCondIndex;
String sHeader( ModuleRes( STR_NUMBERED_CONDITION ) );
sHeader.SearchAndReplaceAscii( "$number$", String::CreateFromInt32( _nCondIndex + 1 ) );
m_aHeader.SetText( sHeader );
m_aMoveUp.Enable( _nCondIndex > 0 );
OSL_PRECOND( _nCondCount > 0, "Condition::setConditionIndex: having no conditions at all is nonsense!" );
m_aMoveDown.Enable( _nCondIndex < _nCondCount - 1 );
}
// -----------------------------------------------------------------------------
bool Condition::isEmpty() const
{
return m_aCondLHS.GetText().Len() == 0;
}
// =============================================================================
} // rptui
// =============================================================================
|