xref: /aoo41x/main/sc/source/ui/attrdlg/condfrmt.cxx (revision b3f79822)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 #include <sfx2/dispatch.hxx>
29 #include <svl/stritem.hxx>
30 
31 #include "tabvwsh.hxx"
32 #include "reffact.hxx"
33 #include "conditio.hxx"
34 #include "stlpool.hxx"
35 #include "uiitems.hxx"
36 #include "document.hxx"
37 #include "scresid.hxx"
38 
39 #include "condfrmt.hrc"
40 #include "globstr.hrc"
41 
42 #define _CONDFRMT_CXX
43 #include "condfrmt.hxx"
44 #undef _CONDFRMT_CXX
45 
46 
47 //============================================================================
48 //	class ScConditionalFormat
49 
50 //----------------------------------------------------------------------------
51 // Konstruktor
52 
ScConditionalFormatDlg(SfxBindings * pB,SfxChildWindow * pCW,Window * pParent,ScDocument * pCurDoc,const ScConditionalFormat * pCurrentFormat)53 ScConditionalFormatDlg::ScConditionalFormatDlg(
54 			SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
55 			ScDocument* pCurDoc,
56 			const ScConditionalFormat* pCurrentFormat )
57 	:	ScAnyRefDlg			( pB, pCW, pParent, RID_SCDLG_CONDFORMAT ),
58 
59 		aCbxCond1			( this, ScResId( CBX_COND1 ) ),
60 		aLbCond11			( this, ScResId( LB_COND1_1 ) ),
61 		aLbCond12			( this, ScResId( LB_COND1_2 ) ),
62         aEdtCond11          ( this, this, ScResId( EDT_COND1_1 ) ),
63 		aRbCond11			( this, ScResId( RB_COND1_1 ), &aEdtCond11,this ),
64 		aFtCond1And			( this, ScResId( FT_COND1_AND ) ),
65         aEdtCond12          ( this, this, ScResId( EDT_COND1_2 ) ),
66 		aRbCond12			( this, ScResId( RB_COND1_2 ), &aEdtCond12,this ),
67 		aFtCond1Template	( this, ScResId( FT_COND1_TEMPLATE ) ),
68 		aLbCond1Template	( this, ScResId( LB_COND1_TEMPLATE ) ),
69         aBtnNew1            ( this, ScResId( BTN_COND1_NEW ) ),
70 
71 		aCbxCond2			( this, ScResId( CBX_COND2 ) ),
72 		aLbCond21			( this, ScResId( LB_COND2_1 ) ),
73 		aLbCond22			( this, ScResId( LB_COND2_2 ) ),
74         aEdtCond21          ( this, this, ScResId( EDT_COND2_1 ) ),
75 		aRbCond21			( this, ScResId( RB_COND2_1 ), &aEdtCond21,this ),
76 		aFtCond2And			( this, ScResId( FT_COND2_AND ) ),
77         aEdtCond22          ( this, this, ScResId( EDT_COND2_2 ) ),
78 		aRbCond22			( this, ScResId( RB_COND2_2 ), &aEdtCond22,this ),
79 		aFtCond2Template	( this, ScResId( FT_COND2_TEMPLATE ) ),
80 		aLbCond2Template	( this, ScResId( LB_COND2_TEMPLATE ) ),
81         aBtnNew2            ( this, ScResId( BTN_COND2_NEW ) ),
82 
83 		aCbxCond3			( this, ScResId( CBX_COND3 ) ),
84 		aLbCond31			( this, ScResId( LB_COND3_1 ) ),
85 		aLbCond32			( this, ScResId( LB_COND3_2 ) ),
86         aEdtCond31          ( this, this, ScResId( EDT_COND3_1 ) ),
87 		aRbCond31			( this, ScResId( RB_COND3_1 ), &aEdtCond31,this ),
88 		aFtCond3And			( this, ScResId( FT_COND3_AND ) ),
89         aEdtCond32          ( this, this, ScResId( EDT_COND3_2 ) ),
90 		aRbCond32			( this, ScResId( RB_COND3_2 ), &aEdtCond32,this ),
91 		aFtCond3Template	( this, ScResId( FT_COND3_TEMPLATE ) ),
92 		aLbCond3Template	( this, ScResId( LB_COND3_TEMPLATE ) ),
93         aBtnNew3            ( this, ScResId( BTN_COND3_NEW ) ),
94 
95 		aBtnOk				( this, ScResId( BTN_OK ) ),
96 		aBtnCancel			( this, ScResId( BTN_CANCEL ) ),
97 		aBtnHelp			( this, ScResId( BTN_HELP ) ),
98         aFlSep2             ( this, ScResId( FL_SEP2 ) ),
99         aFlSep1             ( this, ScResId( FL_SEP1 ) ),
100 		pEdActive			( NULL ),
101 		bDlgLostFocus       ( sal_False ),
102 
103 		pDoc				( pCurDoc )
104 {
105 	Point aPos;
106 	String aName;
107 	SfxStyleSheetBase* pStyle;
108 
109 	FreeResource();
110 
111 	// Handler setzen
112 	aCbxCond1.SetClickHdl ( LINK( this, ScConditionalFormatDlg, ClickCond1Hdl ) );
113 	aLbCond11.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond11Hdl ) );
114 	aLbCond12.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond12Hdl ) );
115 
116 	aCbxCond2.SetClickHdl ( LINK( this, ScConditionalFormatDlg, ClickCond2Hdl ) );
117 	aLbCond21.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond21Hdl ) );
118 	aLbCond22.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond22Hdl ) );
119 
120 	aCbxCond3.SetClickHdl ( LINK( this, ScConditionalFormatDlg, ClickCond3Hdl ) );
121 	aLbCond31.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond31Hdl ) );
122 	aLbCond32.SetSelectHdl( LINK( this, ScConditionalFormatDlg, ChangeCond32Hdl ) );
123 
124 	aBtnOk.SetClickHdl    ( LINK( this, ScConditionalFormatDlg, BtnHdl ) );
125 //?	aBtnCancel.SetClickHdl( LINK( this, ScConditionalFormatDlg, BtnHdl ) );
126 
127     Link aLink = LINK( this, ScConditionalFormatDlg, NewBtnHdl );
128     aBtnNew1.SetClickHdl( aLink );
129     aBtnNew2.SetClickHdl( aLink );
130     aBtnNew3.SetClickHdl( aLink );
131 
132     aLink = LINK( this, ScConditionalFormatDlg, GetFocusHdl );
133     aEdtCond11.SetGetFocusHdl( aLink );
134     aEdtCond12.SetGetFocusHdl( aLink );
135     aEdtCond21.SetGetFocusHdl( aLink );
136     aEdtCond22.SetGetFocusHdl( aLink );
137     aEdtCond31.SetGetFocusHdl( aLink );
138     aEdtCond32.SetGetFocusHdl( aLink );
139     aRbCond11.SetGetFocusHdl( aLink );
140     aRbCond12.SetGetFocusHdl( aLink );
141     aRbCond21.SetGetFocusHdl( aLink );
142     aRbCond22.SetGetFocusHdl( aLink );
143     aRbCond31.SetGetFocusHdl( aLink );
144     aRbCond32.SetGetFocusHdl( aLink );
145 
146     aLink = LINK( this, ScConditionalFormatDlg, LoseFocusHdl );
147     aEdtCond11.SetLoseFocusHdl( aLink );
148     aEdtCond12.SetLoseFocusHdl( aLink );
149     aEdtCond21.SetLoseFocusHdl( aLink );
150     aEdtCond22.SetLoseFocusHdl( aLink );
151     aEdtCond31.SetLoseFocusHdl( aLink );
152     aEdtCond32.SetLoseFocusHdl( aLink );
153     aRbCond11.SetLoseFocusHdl( aLink );
154     aRbCond12.SetLoseFocusHdl( aLink );
155     aRbCond21.SetLoseFocusHdl( aLink );
156     aRbCond22.SetLoseFocusHdl( aLink );
157     aRbCond31.SetLoseFocusHdl( aLink );
158     aRbCond32.SetLoseFocusHdl( aLink );
159 
160 	// Condition 1
161 	aCond1Pos1 = aLbCond12.GetPosPixel();		// Position Edit ohne Listbox
162 	aCond1Pos2 = aEdtCond11.GetPosPixel();		// Position Edit mit Listbox
163 	aRBtn1Pos1 = aRbCond11.GetPosPixel();
164 	aRBtn1Pos2 = aRbCond12.GetPosPixel();
165 	aPos = aEdtCond12.GetPosPixel();
166 	aPos.X() += aEdtCond12.GetSizePixel().Width();	// rechter Rand
167 	aCond1Size3 = aEdtCond11.GetSizePixel();
168 	aCond1Size2 = Size( aPos.X() - aCond1Pos2.X(), aCond1Size3.Height() );
169 	aCond1Size1 = Size( aPos.X() - aCond1Pos1.X(), aCond1Size3.Height() );
170 
171 	aCbxCond1.Check();
172 	aLbCond11.SelectEntryPos( 0 );
173 	aLbCond12.SelectEntryPos( 0 );
174 
175 	// Condition 2
176 	aCond2Pos1  = aLbCond22.GetPosPixel();		// Position Edit ohne Listbox
177 	aCond2Pos2  = aEdtCond21.GetPosPixel();		// Position Edit mit Listbox
178 	aRBtn2Pos1 = aRbCond21.GetPosPixel();
179 	aRBtn2Pos2 = aRbCond22.GetPosPixel();
180 	aPos = aEdtCond22.GetPosPixel();
181 	aPos.X() += aEdtCond22.GetSizePixel().Width();	// rechter Rand
182 	aCond2Size3 = aEdtCond21.GetSizePixel();
183 	aCond2Size2 = Size( aPos.X() - aCond2Pos2.X(), aCond2Size3.Height() );
184 	aCond2Size1 = Size( aPos.X() - aCond2Pos1.X(), aCond2Size3.Height() );
185 
186 	aCbxCond2.Check( sal_False );
187 	aLbCond21.SelectEntryPos( 0 );
188 	aLbCond22.SelectEntryPos( 0 );
189 
190 	// Condition 3
191 	aCond3Pos1  = aLbCond32.GetPosPixel();		// Position Edit ohne Listbox
192 	aCond3Pos2  = aEdtCond31.GetPosPixel();		// Position Edit mit Listbox
193 	aRBtn3Pos1 = aRbCond31.GetPosPixel();
194 	aRBtn3Pos2 = aRbCond32.GetPosPixel();
195 	aPos = aEdtCond32.GetPosPixel();
196 	aPos.X() += aEdtCond32.GetSizePixel().Width();	// rechter Rand
197 	aCond3Size3 = aEdtCond31.GetSizePixel();
198 	aCond3Size2 = Size( aPos.X() - aCond3Pos2.X(), aCond3Size3.Height() );
199 	aCond3Size1 = Size( aPos.X() - aCond3Pos1.X(), aCond3Size3.Height() );
200 
201 	aCbxCond3.Check( sal_False );
202 	aLbCond31.SelectEntryPos( 0 );
203 	aLbCond32.SelectEntryPos( 0 );
204 
205 	// Vorlagen aus pDoc holen
206 	SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
207 	for ( pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
208 	{
209 		aName = pStyle->GetName();
210 		aLbCond1Template.InsertEntry( aName );
211 		aLbCond2Template.InsertEntry( aName );
212 		aLbCond3Template.InsertEntry( aName );
213 	}
214 
215 	// Vorlagen eintragen
216 //!	pStyle = pDoc->GetSelectionStyle( /* ??? const ScMarkData& rMark ??? */ );
217 	pStyle = NULL;	//!
218 	if (pStyle)
219 		aName = pStyle->GetName();
220 	else
221 		aName = ScGlobal::GetRscString(STR_STYLENAME_STANDARD);
222 	aLbCond1Template.SelectEntry( aName );
223 	aLbCond2Template.SelectEntry( aName );
224 	aLbCond3Template.SelectEntry( aName );
225 
226 	ScAddress aCurPos;
227 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
228 	if (pViewShell)
229 	{
230 		ScViewData* pData = pViewShell->GetViewData();
231 		aCurPos = ScAddress( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
232 	}
233 
234 	// Inhalt aus ConditionalFormat holen
235 	if ( pCurrentFormat )
236 	{
237 		const ScCondFormatEntry* pEntry;
238 		if ( pCurrentFormat->Count() > 0 )
239 		{
240 			pEntry= pCurrentFormat->GetEntry( 0 );
241 			aEdtCond11.SetText( pEntry->GetExpression( aCurPos, 0 ) );
242 			aLbCond1Template.SelectEntry( pEntry->GetStyle() );
243 
244 			ScConditionMode	eMode = pEntry->GetOperation();
245 			if ( eMode == SC_COND_DIRECT )			// via Formel
246 			{
247 				aLbCond11.SelectEntryPos( 1 );
248 				ChangeCond11Hdl( NULL );
249 			}
250 			else if ( eMode == SC_COND_NONE )		// ???
251 				;
252 			else									// via Werte
253 			{
254                 aLbCond12.SelectEntryPos( sal::static_int_cast<sal_uInt16>( eMode ) );
255 				if ( ( eMode == SC_COND_BETWEEN ) || ( eMode == SC_COND_NOTBETWEEN ) )
256 					aEdtCond12.SetText( pEntry->GetExpression( aCurPos, 1 ) );
257 			}
258 		}
259 
260 
261 		if ( pCurrentFormat->Count() > 1 )
262 		{
263 			aCbxCond2.Check( sal_True );
264 			pEntry= pCurrentFormat->GetEntry( 1 );
265 			aEdtCond21.SetText( pEntry->GetExpression( aCurPos, 0 ) );
266 			aLbCond2Template.SelectEntry( pEntry->GetStyle() );
267 
268 			ScConditionMode	eMode = pEntry->GetOperation();
269 			if ( eMode == SC_COND_DIRECT )			// via Formel
270 			{
271 				aLbCond21.SelectEntryPos( 1 );
272 				ChangeCond21Hdl( NULL );
273 			}
274 			else if ( eMode == SC_COND_NONE )		// ???
275 				;
276 			else									// via Werte
277 			{
278                 aLbCond22.SelectEntryPos( sal::static_int_cast<sal_uInt16>( eMode ) );
279 				if ( ( eMode == SC_COND_BETWEEN ) || ( eMode == SC_COND_NOTBETWEEN ) )
280 					aEdtCond22.SetText( pEntry->GetExpression( aCurPos, 1 ) );
281 			}
282 		}
283 
284 		if ( pCurrentFormat->Count() > 2 )
285 		{
286 			aCbxCond3.Check( sal_True );
287 			pEntry= pCurrentFormat->GetEntry( 2 );
288 			aEdtCond31.SetText( pEntry->GetExpression( aCurPos, 0 ) );
289 			aLbCond3Template.SelectEntry( pEntry->GetStyle() );
290 
291 			ScConditionMode	eMode = pEntry->GetOperation();
292 			if ( eMode == SC_COND_DIRECT )			// via Formel
293 			{
294 				aLbCond31.SelectEntryPos( 1 );
295 				ChangeCond31Hdl( NULL );
296 			}
297 			else if ( eMode == SC_COND_NONE )		// ???
298 				;
299 			else									// via Werte
300 			{
301                 aLbCond32.SelectEntryPos( sal::static_int_cast<sal_uInt16>( eMode ) );
302 				if ( ( eMode == SC_COND_BETWEEN ) || ( eMode == SC_COND_NOTBETWEEN ) )
303 					aEdtCond32.SetText( pEntry->GetExpression( aCurPos, 1 ) );
304 			}
305 		}
306 	}
307 
308 	ClickCond1Hdl( NULL );
309 	ClickCond2Hdl( NULL );
310 	ClickCond3Hdl( NULL );
311 
312 	ChangeCond12Hdl( NULL );
313 	ChangeCond22Hdl( NULL );
314 	ChangeCond32Hdl( NULL );
315 
316 	aEdtCond11.GrabFocus();
317 	pEdActive = &aEdtCond11;
318 	//@BugID 54702 Enablen/Disablen nur noch in Basisklasse
319 	//SFX_APPWINDOW->Enable();		// Ref-Feld hat Focus
320 //	SFX_APPWINDOW->Disable();
321 
322 	aLbCond11.SetAccessibleRelationLabeledBy( &aCbxCond1 );
323 	aLbCond12.SetAccessibleRelationLabeledBy( &aCbxCond1 );
324 	aEdtCond11.SetAccessibleRelationLabeledBy( &aCbxCond1 );
325 	aRbCond11.SetAccessibleRelationLabeledBy( &aCbxCond1 );
326 
327 	aLbCond21.SetAccessibleRelationLabeledBy( &aCbxCond2 );
328 	aLbCond22.SetAccessibleRelationLabeledBy( &aCbxCond2 );
329 	aEdtCond21.SetAccessibleRelationLabeledBy( &aCbxCond2 );
330 	aRbCond21.SetAccessibleRelationLabeledBy( &aCbxCond2 );
331 
332 	aLbCond31.SetAccessibleRelationLabeledBy( &aCbxCond3 );
333 	aLbCond32.SetAccessibleRelationLabeledBy( &aCbxCond3 );
334 	aEdtCond31.SetAccessibleRelationLabeledBy( &aCbxCond3 );
335 	aRbCond31.SetAccessibleRelationLabeledBy( &aCbxCond3 );
336 	aLbCond11.SetAccessibleName( ScResId(LABEL_FORMARTTING_CONDITIONS) );
337 	aLbCond12.SetAccessibleName( ScResId(LABEL_CONDITIONS) );
338 	aEdtCond11.SetAccessibleName( ScResId(LABEL_CONDITION_VALUE) );
339 
340 	aLbCond21.SetAccessibleName( ScResId(LABEL_FORMARTTING_CONDITIONS) );
341 	aLbCond22.SetAccessibleName( ScResId(LABEL_CONDITIONS) );
342 	aEdtCond21.SetAccessibleName( ScResId(LABEL_CONDITION_VALUE) );
343 
344 	aLbCond31.SetAccessibleName( ScResId(LABEL_FORMARTTING_CONDITIONS) );
345 	aLbCond32.SetAccessibleName( ScResId(LABEL_CONDITIONS) );
346 	aEdtCond31.SetAccessibleName( ScResId(LABEL_CONDITION_VALUE) );
347 }
348 
349 
350 //----------------------------------------------------------------------------
351 // Destruktor
352 
~ScConditionalFormatDlg()353 __EXPORT ScConditionalFormatDlg::~ScConditionalFormatDlg()
354 {
355 }
356 
357 
358 //----------------------------------------------------------------------------
359 
SetReference(const ScRange & rRef,ScDocument * pDocP)360 void ScConditionalFormatDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
361 {
362 	if ( pEdActive )
363 	{
364 		if ( rRef.aStart != rRef.aEnd )
365 			RefInputStart(pEdActive);
366 
367 		String aStr;
368 		rRef.Format( aStr, SCR_ABS_3D, pDocP, pDocP->GetAddressConvention () );
369 		String aVal( pEdActive->GetText() );
370 		Selection aSel( pEdActive->GetSelection() );
371         aSel.Justify();
372 		aVal.Erase( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() );
373 		aVal.Insert( aStr, (xub_StrLen)aSel.Min() );
374 		Selection aNewSel( aSel.Min(), aSel.Min()+aStr.Len() );
375 		pEdActive->SetRefString( aVal );
376 		pEdActive->SetSelection( aNewSel );
377 //		pEdActive->SetModifyFlag();
378 	}
379 }
380 
381 //----------------------------------------------------------------------------
382 
AddRefEntry()383 void ScConditionalFormatDlg::AddRefEntry()
384 {
385 	if ( pEdActive )
386 	{
387 		String aVal = pEdActive->GetText();
388 		aVal += ';';
389 		pEdActive->SetText(aVal);
390 
391 		xub_StrLen nLen = aVal.Len();
392 		pEdActive->SetSelection( Selection( nLen, nLen ) );
393 //		pEdActive->SetModifyFlag();
394 	}
395 }
396 
397 //----------------------------------------------------------------------------
398 
IsRefInputMode() const399 sal_Bool ScConditionalFormatDlg::IsRefInputMode() const
400 {
401 	return (pEdActive != NULL);
402 }
403 
404 
405 //----------------------------------------------------------------------------
406 
SetActive()407 void ScConditionalFormatDlg::SetActive()
408 {
409 	if ( bDlgLostFocus )
410 	{
411 		bDlgLostFocus = sal_False;
412         if( pEdActive )
413             pEdActive->GrabFocus();
414 	}
415 	else
416 		GrabFocus();
417 
418 	RefInputDone();
419 }
420 
421 
422 //----------------------------------------------------------------------------
423 // Holt die ausgewaehlte bedingte Formatierung ab
424 
GetConditionalFormat(ScConditionalFormat & rCndFmt)425 void ScConditionalFormatDlg::GetConditionalFormat( ScConditionalFormat& rCndFmt )
426 {
427 	ScConditionMode eOper;
428 	String sExpr1;
429 	String sExpr2;
430 	String sStyle;
431 	ScAddress aCurPos;
432 
433 	ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
434 	if (pViewShell)
435 	{
436 		ScViewData* pData = pViewShell->GetViewData();
437 		aCurPos = ScAddress( pData->GetCurX(), pData->GetCurY(), pData->GetTabNo() );
438 	}
439 
440 	if ( aCbxCond1.IsChecked() )
441 	{
442 		if ( aLbCond11.GetSelectEntryPos() == 1 )	// via Formel
443 			eOper = SC_COND_DIRECT;
444 		else
445 			eOper = (ScConditionMode)aLbCond12.GetSelectEntryPos();
446 		sExpr1 = aEdtCond11.GetText();
447 		sExpr2 = aEdtCond12.GetText();
448 		sStyle = aLbCond1Template.GetSelectEntry();
449 		ScCondFormatEntry aNewEntry( eOper, sExpr1, sExpr2, pDoc, aCurPos, sStyle );
450 		rCndFmt.AddEntry( aNewEntry );
451 	}
452 
453 	if ( aCbxCond2.IsChecked() )
454 	{
455 		if ( aLbCond21.GetSelectEntryPos() == 1 )	// via Formel???
456 			eOper = SC_COND_DIRECT;
457 		else
458 			eOper = (ScConditionMode)aLbCond22.GetSelectEntryPos();
459 		sExpr1 = aEdtCond21.GetText();
460 		sExpr2 = aEdtCond22.GetText();
461 		sStyle = aLbCond2Template.GetSelectEntry();
462 		ScCondFormatEntry aNewEntry( eOper, sExpr1, sExpr2, pDoc, aCurPos, sStyle );
463 		rCndFmt.AddEntry( aNewEntry );
464 	}
465 
466 	if ( aCbxCond3.IsChecked() )
467 	{
468 		if ( aLbCond31.GetSelectEntryPos() == 1 )	// via Formel???
469 			eOper = SC_COND_DIRECT;
470 		else
471 			eOper = (ScConditionMode)aLbCond32.GetSelectEntryPos();
472 		sExpr1 = aEdtCond31.GetText();
473 		sExpr2 = aEdtCond32.GetText();
474 		sStyle = aLbCond3Template.GetSelectEntry();
475 		ScCondFormatEntry aNewEntry( eOper, sExpr1, sExpr2, pDoc, aCurPos, sStyle );
476 		rCndFmt.AddEntry( aNewEntry );
477 	}
478 }
479 
480 
481 //----------------------------------------------------------------------------
482 // Zerstoert den Dialog
483 
Close()484 sal_Bool ScConditionalFormatDlg::Close()
485 {
486 	return DoClose( ScCondFormatDlgWrapper::GetChildWindowId() );
487 }
488 
489 
490 //----------------------------------------------------------------------------
491 // Handler:
492 
493 //----------------------------------------------------------------------------
494 // Enabled/Disabled Condition1-Controls
495 
IMPL_LINK(ScConditionalFormatDlg,ClickCond1Hdl,void *,EMPTYARG)496 IMPL_LINK( ScConditionalFormatDlg, ClickCond1Hdl, void *, EMPTYARG )
497 {
498 	sal_Bool bChecked = aCbxCond1.IsChecked();
499 
500 	aLbCond11.Enable( bChecked );
501 	aLbCond12.Enable( bChecked );
502 	aEdtCond11.Enable( bChecked );
503 	aRbCond11.Enable( bChecked );
504 	aFtCond1And.Enable( bChecked );
505 	aEdtCond12.Enable( bChecked );
506 	aRbCond12.Enable( bChecked );
507 	aFtCond1Template.Enable( bChecked );
508 	aLbCond1Template.Enable( bChecked );
509     aBtnNew1.Enable( bChecked );
510 
511 	return( 0L );
512 }
513 
514 
515 //----------------------------------------------------------------------------
516 // Zellwert/Formel
517 
IMPL_LINK(ScConditionalFormatDlg,ChangeCond11Hdl,void *,EMPTYARG)518 IMPL_LINK( ScConditionalFormatDlg, ChangeCond11Hdl, void *, EMPTYARG )
519 {
520 	sal_uInt16 nPos = aLbCond11.GetSelectEntryPos();
521 
522 	if( nPos == 0 ) // Zellwert
523 	{
524 		aLbCond12.Show();
525 		aEdtCond11.SetPosPixel( aCond1Pos2 );
526 	}
527 	else // Formel
528 	{
529 		aLbCond12.Hide();
530 		aFtCond1And.Hide();
531 		aEdtCond12.Hide();
532 		aRbCond12.Hide();
533 		aRbCond11.SetPosPixel( aRBtn1Pos2 );
534 		aEdtCond11.SetPosSizePixel( aCond1Pos1, aCond1Size1 );
535 	}
536 
537 	ChangeCond12Hdl( NULL );
538 
539 	return( 0L );
540 }
541 
542 
543 //----------------------------------------------------------------------------
544 // zwischen, gleich, groesser, ...
545 
IMPL_LINK(ScConditionalFormatDlg,ChangeCond12Hdl,void *,EMPTYARG)546 IMPL_LINK( ScConditionalFormatDlg, ChangeCond12Hdl, void *, EMPTYARG )
547 {
548 	if( aLbCond12.IsVisible() )
549 	{
550 		sal_uInt16 nPos = aLbCond12.GetSelectEntryPos();
551 
552 		if( nPos == 6  || nPos == 7 ) // zwischen, n. zwischen
553 		{
554 			aEdtCond11.SetSizePixel( aCond1Size3 );
555 			aRbCond11.SetPosPixel( aRBtn1Pos1 );
556 			aFtCond1And.Show();
557 			aEdtCond12.Show();
558 			aRbCond12.Show();
559 		}
560 		else // gleich, n. gleich ...
561 		{
562 			aEdtCond12.Hide();
563 			aRbCond12.Hide();
564 			aFtCond1And.Hide();
565 			aRbCond11.SetPosPixel( aRBtn1Pos2 );
566 			aEdtCond11.SetSizePixel( aCond1Size2 );
567 		}
568 	}
569 
570 	return( 0L );
571 }
572 
573 
574 //----------------------------------------------------------------------------
575 // Enabled/Disabled Condition2-Controls
576 
IMPL_LINK(ScConditionalFormatDlg,ClickCond2Hdl,void *,EMPTYARG)577 IMPL_LINK( ScConditionalFormatDlg, ClickCond2Hdl, void *, EMPTYARG )
578 {
579 	sal_Bool bChecked = aCbxCond2.IsChecked();
580 
581 	aLbCond21.Enable( bChecked );
582 	aLbCond22.Enable( bChecked );
583 	aEdtCond21.Enable( bChecked );
584 	aRbCond21.Enable( bChecked );
585 	aFtCond2And.Enable( bChecked );
586 	aEdtCond22.Enable( bChecked );
587 	aRbCond22.Enable( bChecked );
588 	aFtCond2Template.Enable( bChecked );
589 	aLbCond2Template.Enable( bChecked );
590     aBtnNew2.Enable( bChecked );
591 
592 	return( 0L );
593 }
594 
595 
596 //----------------------------------------------------------------------------
597 // Zellwert/Formel
598 
IMPL_LINK(ScConditionalFormatDlg,ChangeCond21Hdl,void *,EMPTYARG)599 IMPL_LINK( ScConditionalFormatDlg, ChangeCond21Hdl, void *, EMPTYARG )
600 {
601 	sal_uInt16 nPos = aLbCond21.GetSelectEntryPos();
602 
603 	if( nPos == 0 ) // Zellwert
604 	{
605 		aLbCond22.Show();
606 		aEdtCond21.SetPosPixel( aCond2Pos2 );
607 	}
608 	else // Formel
609 	{
610 		aLbCond22.Hide();
611 		aFtCond2And.Hide();
612 		aEdtCond22.Hide();
613 		aRbCond22.Hide();
614 		aRbCond21.SetPosPixel( aRBtn2Pos2 );
615 		aEdtCond21.SetPosSizePixel( aCond2Pos1, aCond2Size1 );
616 	}
617 
618 	ChangeCond22Hdl( NULL );
619 
620 	return( 0L );
621 }
622 
623 
624 //----------------------------------------------------------------------------
625 // zwischen, gleich, groesser, ...
626 
IMPL_LINK(ScConditionalFormatDlg,ChangeCond22Hdl,void *,EMPTYARG)627 IMPL_LINK( ScConditionalFormatDlg, ChangeCond22Hdl, void *, EMPTYARG )
628 {
629 	if( aLbCond22.IsVisible() )
630 	{
631 		sal_uInt16 nPos = aLbCond22.GetSelectEntryPos();
632 
633 		if( nPos == 6  || nPos == 7 ) // zwischen, n. zwischen
634 		{
635 			aEdtCond21.SetSizePixel( aCond2Size3 );
636 			aRbCond21.SetPosPixel( aRBtn2Pos1 );
637 			aFtCond2And.Show();
638 			aEdtCond22.Show();
639 			aRbCond22.Show();
640 		}
641 		else // gleich, n. gleich ...
642 		{
643 			aEdtCond22.Hide();
644 			aRbCond22.Hide();
645 			aFtCond2And.Hide();
646 			aRbCond21.SetPosPixel( aRBtn2Pos2 );
647 			aEdtCond21.SetSizePixel( aCond2Size2 );
648 		}
649 	}
650 
651 	return( 0L );
652 }
653 
654 
655 //----------------------------------------------------------------------------
656 // Enabled/Disabled Condition3-Controls
657 
IMPL_LINK(ScConditionalFormatDlg,ClickCond3Hdl,void *,EMPTYARG)658 IMPL_LINK( ScConditionalFormatDlg, ClickCond3Hdl, void *, EMPTYARG )
659 {
660 	sal_Bool bChecked = aCbxCond3.IsChecked();
661 
662 	aLbCond31.Enable( bChecked );
663 	aLbCond32.Enable( bChecked );
664 	aEdtCond31.Enable( bChecked );
665 	aRbCond31.Enable( bChecked );
666 	aFtCond3And.Enable( bChecked );
667 	aEdtCond32.Enable( bChecked );
668 	aRbCond32.Enable( bChecked );
669 	aFtCond3Template.Enable( bChecked );
670 	aLbCond3Template.Enable( bChecked );
671     aBtnNew3.Enable( bChecked );
672 
673 	return( 0L );
674 }
675 
676 
677 //----------------------------------------------------------------------------
678 // Zellwert/Formel
679 
IMPL_LINK(ScConditionalFormatDlg,ChangeCond31Hdl,void *,EMPTYARG)680 IMPL_LINK( ScConditionalFormatDlg, ChangeCond31Hdl, void *, EMPTYARG )
681 {
682 	sal_uInt16 nPos = aLbCond31.GetSelectEntryPos();
683 
684 	if( nPos == 0 ) // Zellwert
685 	{
686 		aLbCond32.Show();
687 		aEdtCond31.SetPosPixel( aCond3Pos2 );
688 	}
689 	else // Formel
690 	{
691 		aLbCond32.Hide();
692 		aFtCond3And.Hide();
693 		aEdtCond32.Hide();
694 		aRbCond32.Hide();
695 		aRbCond31.SetPosPixel( aRBtn3Pos2 );
696 		aEdtCond31.SetPosSizePixel( aCond3Pos1, aCond3Size1 );
697 	}
698 
699 	ChangeCond32Hdl( NULL );
700 
701 	return( 0L );
702 }
703 
704 
705 //----------------------------------------------------------------------------
706 // zwischen, gleich, groesser, ...
707 
IMPL_LINK(ScConditionalFormatDlg,ChangeCond32Hdl,void *,EMPTYARG)708 IMPL_LINK( ScConditionalFormatDlg, ChangeCond32Hdl, void *, EMPTYARG )
709 {
710 	if( aLbCond32.IsVisible() )
711 	{
712 		sal_uInt16 nPos = aLbCond32.GetSelectEntryPos();
713 
714 		if( nPos == 6  || nPos == 7 ) // zwischen, n. zwischen
715 		{
716 			aEdtCond31.SetSizePixel( aCond3Size3 );
717 			aRbCond31.SetPosPixel( aRBtn3Pos1 );
718 			aFtCond3And.Show();
719 			aEdtCond32.Show();
720 			aRbCond32.Show();
721 		}
722 		else // gleich, n. gleich ...
723 		{
724 			aEdtCond32.Hide();
725 			aRbCond32.Hide();
726 			aFtCond3And.Hide();
727 			aRbCond31.SetPosPixel( aRBtn3Pos2 );
728 			aEdtCond31.SetSizePixel( aCond3Size2 );
729 		}
730 	}
731 
732 	return( 0L );
733 }
734 
735 
736 //----------------------------------------------------------------------------
737 
IMPL_LINK(ScConditionalFormatDlg,GetFocusHdl,Control *,pCtrl)738 IMPL_LINK( ScConditionalFormatDlg, GetFocusHdl, Control*, pCtrl )
739 {
740     if( (pCtrl == (Control*)&aEdtCond11) || (pCtrl == (Control*)&aRbCond11) )
741         pEdActive = &aEdtCond11;
742     else if( (pCtrl == (Control*)&aEdtCond12) || (pCtrl == (Control*)&aRbCond12) )
743         pEdActive = &aEdtCond12;
744     else if( (pCtrl == (Control*)&aEdtCond21) || (pCtrl == (Control*)&aRbCond21) )
745         pEdActive = &aEdtCond21;
746     else if( (pCtrl == (Control*)&aEdtCond22) || (pCtrl == (Control*)&aRbCond22) )
747         pEdActive = &aEdtCond22;
748     else if( (pCtrl == (Control*)&aEdtCond31) || (pCtrl == (Control*)&aRbCond31) )
749         pEdActive = &aEdtCond31;
750     else if( (pCtrl == (Control*)&aEdtCond32) || (pCtrl == (Control*)&aRbCond32) )
751         pEdActive = &aEdtCond32;
752     else
753         pEdActive = NULL;
754 
755     if( pEdActive )
756         pEdActive->SetSelection( Selection( 0, SELECTION_MAX ) );
757 
758     return 0;
759 }
760 
761 
762 //----------------------------------------------------------------------------
763 
IMPL_LINK(ScConditionalFormatDlg,LoseFocusHdl,Control *,EMPTYARG)764 IMPL_LINK( ScConditionalFormatDlg, LoseFocusHdl, Control*, EMPTYARG )
765 {
766     bDlgLostFocus = !IsActive();
767     return 0;
768 }
769 
770 
771 //----------------------------------------------------------------------------
772 //	[OK], [Cancel]
773 
IMPL_LINK(ScConditionalFormatDlg,BtnHdl,PushButton *,pBtn)774 IMPL_LINK( ScConditionalFormatDlg, BtnHdl, PushButton*, pBtn )
775 {
776 	if ( pBtn == &aBtnOk )
777 	{
778 		ScConditionalFormat aCondFrmt( 0, pDoc );
779 		GetConditionalFormat( aCondFrmt );
780 		ScCondFrmtItem aOutItem( FID_CONDITIONAL_FORMAT, aCondFrmt );
781 
782 		SetDispatcherLock( sal_False );
783 		SwitchToDocument();
784 		GetBindings().GetDispatcher()->Execute( FID_CONDITIONAL_FORMAT,
785 								  SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
786 								  &aOutItem, 0L, 0L );
787 		Close();
788 	}
789 	else if ( pBtn == &aBtnCancel )
790 		Close();
791 
792 	return( 0L );
793 }
794 
795 
796 //----------------------------------------------------------------------------
797 
IMPL_LINK(ScConditionalFormatDlg,NewBtnHdl,PushButton *,pBtn)798 IMPL_LINK( ScConditionalFormatDlg, NewBtnHdl, PushButton*, pBtn )
799 {
800     SfxUInt16Item aFamilyItem( SID_STYLE_FAMILY, SFX_STYLE_FAMILY_PARA );
801     SfxStringItem aRefItem( SID_STYLE_REFERENCE, ScGlobal::GetRscString(STR_STYLENAME_STANDARD) );
802 
803     // unlock the dispatcher so SID_STYLE_NEW can be executed
804     // (SetDispatcherLock would affect all Calc documents)
805     SfxDispatcher* pDisp = GetBindings().GetDispatcher();
806     sal_Bool bLocked = pDisp->IsLocked();
807     if (bLocked)
808         pDisp->Lock(sal_False);
809 
810     // Execute the "new style" slot, complete with undo and all necessary updates.
811     // The return value (SfxUInt16Item) is ignored, look for new styles instead.
812     pDisp->Execute( SID_STYLE_NEW, SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD | SFX_CALLMODE_MODAL,
813                     &aFamilyItem,
814                     &aRefItem,
815                     0L );
816 
817     if (bLocked)
818         pDisp->Lock(sal_True);
819 
820     // Find the new style and add it into the style list boxes
821     String aNewStyle;
822     SfxStyleSheetIterator aStyleIter( pDoc->GetStyleSheetPool(), SFX_STYLE_FAMILY_PARA );
823     for ( SfxStyleSheetBase* pStyle = aStyleIter.First(); pStyle; pStyle = aStyleIter.Next() )
824     {
825         String aName = pStyle->GetName();
826         if ( aLbCond1Template.GetEntryPos(aName) == LISTBOX_ENTRY_NOTFOUND )    // all lists contain the same entries
827         {
828             aLbCond1Template.InsertEntry( aName );
829             aLbCond2Template.InsertEntry( aName );
830             aLbCond3Template.InsertEntry( aName );
831             // if there are several new styles (from API or a different view),
832             // assume the last one is the result of the dialog
833             aNewStyle = aName;
834         }
835     }
836 
837     // select the new style in the list box for which the button was pressed
838     if ( aNewStyle.Len() )
839     {
840         ListBox* pListBox = &aLbCond1Template;
841         if ( pBtn == &aBtnNew2 )
842             pListBox = &aLbCond2Template;
843         else if ( pBtn == &aBtnNew3 )
844             pListBox = &aLbCond3Template;
845 
846         pListBox->SelectEntry( aNewStyle );
847     }
848 
849     return 0;
850 }
851 
852