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