xref: /trunk/main/sc/source/ui/miscdlgs/inscodlg.cxx (revision a479921a)
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_scui.hxx"
26 
27 
28 
29 
30 //------------------------------------------------------------------
31 
32 #include "inscodlg.hxx"
33 #include "scresid.hxx"
34 #include "miscdlgs.hrc"
35 
36 
37 //==================================================================
38 
39 sal_Bool   ScInsertContentsDlg::bPreviousAllCheck = sal_False;
40 sal_uInt16 ScInsertContentsDlg::nPreviousChecks   = (IDF_VALUE | IDF_DATETIME | IDF_STRING);
41 sal_uInt16 ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
42 sal_uInt16 ScInsertContentsDlg::nPreviousChecks2 = 0;
43 sal_uInt16 ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;	// enum InsCellCmd
44 
45 //-----------------------------------------------------------------------
46 
ScInsertContentsDlg(Window * pParent,sal_uInt16 nCheckDefaults,const String * pStrTitle)47 ScInsertContentsDlg::ScInsertContentsDlg( Window*		pParent,
48 										  sal_uInt16		nCheckDefaults,
49 										  const String* pStrTitle )
50 
51  :  ModalDialog     ( pParent, ScResId( RID_SCDLG_INSCONT ) ),
52 	//
53     aFlFrame        ( this, ScResId( FL_FRAME ) ),
54 	aBtnInsAll      ( this, ScResId( BTN_INSALL ) ),
55 	aBtnInsStrings  ( this, ScResId( BTN_INSSTRINGS ) ),
56 	aBtnInsNumbers  ( this, ScResId( BTN_INSNUMBERS ) ),
57 	aBtnInsDateTime ( this, ScResId( BTN_INSDATETIME ) ),
58 	aBtnInsFormulas ( this, ScResId( BTN_INSFORMULAS ) ),
59 	aBtnInsNotes    ( this, ScResId( BTN_INSNOTES ) ),
60 	aBtnInsAttrs    ( this, ScResId( BTN_INSATTRS ) ),
61 	aBtnInsObjects  ( this, ScResId( BTN_INSOBJECTS ) ),
62     aFlSep1         ( this, ScResId( FL_SEP1 ) ),
63     aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
64 	aBtnSkipEmptyCells( this, ScResId(BTN_SKIP_EMPTY ) ),
65 	aBtnTranspose	( this, ScResId( BTN_TRANSPOSE ) ),
66 	aBtnLink        ( this, ScResId( BTN_LINK ) ),
67     aFlOperation    ( this, ScResId( FL_OPERATION ) ),
68 	aRbNoOp         ( this, ScResId( BTN_OP_NOOP ) ),
69 	aRbAdd          ( this, ScResId( BTN_OP_ADD	) ),
70 	aRbSub          ( this, ScResId( BTN_OP_SUB  ) ),
71 	aRbMul          ( this, ScResId( BTN_OP_MUL  ) ),
72 	aRbDiv          ( this, ScResId( BTN_OP_DIV  ) ),
73     aFlSep2         ( this, ScResId( FL_SEP2 ) ),
74     aFlMove         ( this, ScResId( FL_MOVE ) ),
75 	aRbMoveNone     ( this, ScResId( BTN_MV_NONE ) ),
76 	aRbMoveDown     ( this, ScResId( BTN_MV_DOWN ) ),
77 	aRbMoveRight    ( this, ScResId( BTN_MV_RIGHT ) ),
78 	aBtnOk          ( this, ScResId( BTN_OK ) ),
79 	aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
80 	aBtnHelp        ( this, ScResId( BTN_HELP ) ),
81 	bOtherDoc		( sal_False ),
82 	bFillMode		( sal_False ),
83 	bChangeTrack	( sal_False ),
84 	bMoveDownDisabled( sal_False ),
85 	bMoveRightDisabled( sal_False )
86 {
87 	if ( pStrTitle )
88 		SetText( *pStrTitle );
89 
90 	if ( nCheckDefaults != 0 )
91 	{
92 		ScInsertContentsDlg::nPreviousChecks = nCheckDefaults;
93 		ScInsertContentsDlg::bPreviousAllCheck = sal_False;
94 		ScInsertContentsDlg::nPreviousChecks2 = 0;
95 	}
96 
97 	aBtnInsAll.Check     ( ScInsertContentsDlg::bPreviousAllCheck );
98 	aBtnInsStrings.Check ( IS_SET( IDF_STRING,
99 								   ScInsertContentsDlg::nPreviousChecks ) );
100 	aBtnInsNumbers.Check ( IS_SET( IDF_VALUE,
101 								   ScInsertContentsDlg::nPreviousChecks ) );
102 	aBtnInsDateTime.Check( IS_SET( IDF_DATETIME,
103 								   ScInsertContentsDlg::nPreviousChecks ) );
104 	aBtnInsFormulas.Check( IS_SET( IDF_FORMULA,
105 								   ScInsertContentsDlg::nPreviousChecks ) );
106 	aBtnInsNotes.Check   ( IS_SET( IDF_NOTE,
107 								   ScInsertContentsDlg::nPreviousChecks ) );
108 	aBtnInsAttrs.Check   ( IS_SET( IDF_ATTRIB,
109 								   ScInsertContentsDlg::nPreviousChecks ) );
110 	aBtnInsObjects.Check ( IS_SET( IDF_OBJECTS,
111 								   ScInsertContentsDlg::nPreviousChecks ) );
112 
113 	switch( ScInsertContentsDlg::nPreviousFormulaChecks )
114 	{
115 		case PASTE_NOFUNC: aRbNoOp.Check(sal_True); break;
116 		case PASTE_ADD:    aRbAdd.Check(sal_True); break;
117 		case PASTE_SUB:    aRbSub.Check(sal_True); break;
118 		case PASTE_MUL:    aRbMul.Check(sal_True); break;
119 		case PASTE_DIV:    aRbDiv.Check(sal_True); break;
120 	}
121 
122 	switch( ScInsertContentsDlg::nPreviousMoveMode )
123 	{
124 		case INS_NONE:  	 aRbMoveNone.Check(sal_True); break;
125 		case INS_CELLSDOWN:	 aRbMoveDown.Check(sal_True); break;
126 		case INS_CELLSRIGHT: aRbMoveRight.Check(sal_True); break;
127 	}
128 
129 	aBtnSkipEmptyCells.Check( ( ScInsertContentsDlg::nPreviousChecks2 & INS_CONT_NOEMPTY ) != 0);
130 	aBtnTranspose.Check( ( ScInsertContentsDlg::nPreviousChecks2 	& INS_CONT_TRANS ) != 0);
131 	aBtnLink.Check( ( ScInsertContentsDlg::nPreviousChecks2 			& INS_CONT_LINK  ) != 0);
132 
133 	DisableChecks( aBtnInsAll.IsChecked() );
134 
135     aFlSep1.SetStyle( aFlSep1.GetStyle() | WB_VERT );
136     aFlSep2.SetStyle( aFlSep2.GetStyle() | WB_VERT );
137 
138 	aBtnInsAll.SetClickHdl( LINK( this, ScInsertContentsDlg, InsAllHdl ) );
139 	aBtnLink.SetClickHdl( LINK( this, ScInsertContentsDlg, LinkBtnHdl ) );
140 
141 	//-------------
142 	FreeResource();
143 }
144 
145 //------------------------------------------------------------------------
146 
GetInsContentsCmdBits() const147 sal_uInt16 ScInsertContentsDlg::GetInsContentsCmdBits() const
148 {
149 	ScInsertContentsDlg::nPreviousChecks = 0;
150 
151 	if ( aBtnInsStrings.IsChecked() )
152 		ScInsertContentsDlg::nPreviousChecks = IDF_STRING;
153 	if ( aBtnInsNumbers.IsChecked() )
154 		ScInsertContentsDlg::nPreviousChecks |= IDF_VALUE;
155 	if ( aBtnInsDateTime.IsChecked())
156 		ScInsertContentsDlg::nPreviousChecks |= IDF_DATETIME;
157 	if ( aBtnInsFormulas.IsChecked())
158 		ScInsertContentsDlg::nPreviousChecks |= IDF_FORMULA;
159 	if ( aBtnInsNotes.IsChecked()   )
160 		ScInsertContentsDlg::nPreviousChecks |= IDF_NOTE;
161 	if ( aBtnInsAttrs.IsChecked()   )
162 		ScInsertContentsDlg::nPreviousChecks |= IDF_ATTRIB;
163 	if ( aBtnInsObjects.IsChecked() )
164 		ScInsertContentsDlg::nPreviousChecks |= IDF_OBJECTS;
165 
166 	ScInsertContentsDlg::bPreviousAllCheck = aBtnInsAll.IsChecked();
167 
168 	return ( (ScInsertContentsDlg::bPreviousAllCheck)
169 				? IDF_ALL
170 				: ScInsertContentsDlg::nPreviousChecks );
171 }
172 
173 //------------------------------------------------------------------------
174 
GetMoveMode()175 InsCellCmd ScInsertContentsDlg::GetMoveMode()
176 {
177 	if ( aRbMoveDown.IsChecked() )
178 		return INS_CELLSDOWN;
179 	if ( aRbMoveRight.IsChecked() )
180 		return INS_CELLSRIGHT;
181 
182 	return INS_NONE;
183 }
184 
185 //------------------------------------------------------------------------
186 
DisableChecks(sal_Bool bInsAllChecked)187 void ScInsertContentsDlg::DisableChecks( sal_Bool bInsAllChecked )
188 {
189 	if ( bInsAllChecked )
190 	{
191 		aBtnInsStrings.Disable();
192 		aBtnInsNumbers.Disable();
193 		aBtnInsDateTime.Disable();
194 		aBtnInsFormulas.Disable();
195 		aBtnInsNotes.Disable();
196 		aBtnInsAttrs.Disable();
197 		aBtnInsObjects.Disable();
198 	}
199 	else
200 	{
201 		aBtnInsStrings.Enable();
202 		aBtnInsNumbers.Enable();
203 		aBtnInsDateTime.Enable();
204 		aBtnInsFormulas.Enable();
205 		aBtnInsNotes.Enable();
206 		aBtnInsAttrs.Enable();
207 
208 		//	"Objects" is disabled for "Fill Tables"
209 		if ( bFillMode )
210 			aBtnInsObjects.Disable();
211 		else
212 			aBtnInsObjects.Enable();
213 	}
214 }
215 
216 // Link in anderes Dokument -> alles andere disabled
217 
TestModes()218 void ScInsertContentsDlg::TestModes()
219 {
220 	if ( bOtherDoc && aBtnLink.IsChecked() )
221 	{
222 		aBtnSkipEmptyCells.Disable();
223 		aBtnTranspose.Disable();
224 		aRbNoOp.Disable();
225 		aRbAdd.Disable();
226 		aRbSub.Disable();
227 		aRbMul.Disable();
228 		aRbDiv.Disable();
229         aFlOperation.Disable();
230 
231 		aRbMoveNone.Disable();
232 		aRbMoveDown.Disable();
233 		aRbMoveRight.Disable();
234         aFlMove.Disable();
235 
236         aFlFrame.Disable();
237 		aBtnInsAll.Disable();
238 		DisableChecks(sal_True);
239 	}
240 	else
241 	{
242 		aBtnSkipEmptyCells.Enable();
243 		aBtnTranspose.Enable(!bFillMode);
244 		aRbNoOp.Enable();
245 		aRbAdd.Enable();
246 		aRbSub.Enable();
247 		aRbMul.Enable();
248 		aRbDiv.Enable();
249         aFlOperation.Enable();
250 
251 		aRbMoveNone.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));
252 		aRbMoveDown.Enable(!bFillMode && !bChangeTrack && !bMoveDownDisabled);
253 		aRbMoveRight.Enable(!bFillMode && !bChangeTrack && !bMoveRightDisabled);
254         aFlMove.Enable(!bFillMode && !bChangeTrack && !(bMoveDownDisabled && bMoveRightDisabled));
255 
256         aFlFrame.Enable();
257 		aBtnInsAll.Enable();
258 		DisableChecks( aBtnInsAll.IsChecked() );
259 	}
260 }
261 
SetOtherDoc(sal_Bool bSet)262 void ScInsertContentsDlg::SetOtherDoc( sal_Bool bSet )
263 {
264 	if ( bSet != bOtherDoc )
265 	{
266 		bOtherDoc = bSet;
267 		TestModes();
268 		if ( bSet )
269 			aRbMoveNone.Check(sal_True);
270 	}
271 }
272 
SetFillMode(sal_Bool bSet)273 void ScInsertContentsDlg::SetFillMode( sal_Bool bSet )
274 {
275 	if ( bSet != bFillMode )
276 	{
277 		bFillMode = bSet;
278 		TestModes();
279 		if ( bSet )
280 			aRbMoveNone.Check(sal_True);
281 	}
282 }
283 
SetChangeTrack(sal_Bool bSet)284 void ScInsertContentsDlg::SetChangeTrack( sal_Bool bSet )
285 {
286 	if ( bSet != bChangeTrack )
287 	{
288 		bChangeTrack = bSet;
289 		TestModes();
290 		if ( bSet )
291 			aRbMoveNone.Check(sal_True);
292 	}
293 }
294 
SetCellShiftDisabled(int nDisable)295 void ScInsertContentsDlg::SetCellShiftDisabled( int nDisable )
296 {
297 	sal_Bool bDown = ((nDisable & SC_CELL_SHIFT_DISABLE_DOWN) != 0);
298 	sal_Bool bRight = ((nDisable & SC_CELL_SHIFT_DISABLE_RIGHT) != 0);
299 	if ( bDown != bMoveDownDisabled || bRight != bMoveRightDisabled )
300 	{
301 		bMoveDownDisabled = bDown;
302 		bMoveRightDisabled = bRight;
303 		TestModes();
304 		if ( bMoveDownDisabled && aRbMoveDown.IsChecked() )
305 			aRbMoveNone.Check(sal_True);
306 		if ( bMoveRightDisabled && aRbMoveRight.IsChecked() )
307 			aRbMoveNone.Check(sal_True);
308 	}
309 }
310 
311 
312 //------------------------------------------------------------------------
313 
IMPL_LINK(ScInsertContentsDlg,InsAllHdl,void *,EMPTYARG)314 IMPL_LINK( ScInsertContentsDlg, InsAllHdl, void*, EMPTYARG )
315 {
316 	DisableChecks( aBtnInsAll.IsChecked() );
317 
318 	return 0;
319 }
320 
IMPL_LINK(ScInsertContentsDlg,LinkBtnHdl,void *,EMPTYARG)321 IMPL_LINK( ScInsertContentsDlg, LinkBtnHdl, void*, EMPTYARG )
322 {
323 	TestModes();
324 
325 	return 0;
326 }
327 
~ScInsertContentsDlg()328 __EXPORT ScInsertContentsDlg::~ScInsertContentsDlg()
329 {
330 	ScInsertContentsDlg::nPreviousChecks2 = 0;
331 	if(aBtnSkipEmptyCells.IsChecked())
332 		ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_NOEMPTY;
333 	if(	aBtnTranspose.IsChecked())
334 		ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_TRANS;
335 	if( aBtnLink.IsChecked() )
336 		ScInsertContentsDlg::nPreviousChecks2 |= INS_CONT_LINK;
337 
338 	if (!bFillMode)		// im FillMode ist None gecheckt und alle 3 disabled
339 	{
340 		if ( aRbMoveNone.IsChecked() )
341 			ScInsertContentsDlg::nPreviousMoveMode = INS_NONE;
342 		else if ( aRbMoveDown.IsChecked() )
343 			ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSDOWN;
344 		else if ( aRbMoveRight.IsChecked() )
345 			ScInsertContentsDlg::nPreviousMoveMode = INS_CELLSRIGHT;
346 	}
347 }
348 
GetFormulaCmdBits() const349 sal_uInt16	ScInsertContentsDlg::GetFormulaCmdBits() const
350 {
351 	ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_NOFUNC;
352 	if(aRbAdd.IsChecked())
353 		ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_ADD;
354 	else if(aRbSub.IsChecked())
355 		ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_SUB;
356 	else if(aRbMul.IsChecked())
357 		ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_MUL;
358 	else if(aRbDiv.IsChecked())
359 		ScInsertContentsDlg::nPreviousFormulaChecks = PASTE_DIV;
360 	// Bits fuer Checkboxen ausblenden
361 	return ScInsertContentsDlg::nPreviousFormulaChecks;
362 }
363 
364 
365 
366