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