xref: /trunk/main/sc/source/ui/miscdlgs/mvtabdlg.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 <vcl/msgbox.hxx>
33 
34 #include "mvtabdlg.hxx"
35 #include "document.hxx"
36 #include "docsh.hxx"
37 #include "miscdlgs.hrc"
38 #include "global.hxx"
39 #include "scresid.hxx"
40 #include "globstr.hrc"
41 
42 #include <layout/layout-pre.hxx>
43 
44 #if ENABLE_LAYOUT
45 #undef ScResId
46 #define ScResId(x) #x
47 #undef ModalDialog
48 #define ModalDialog( parent, id ) Dialog( parent, "move-copy-sheet.xml", id )
49 #endif /* ENABLE_LAYOUT */
50 
51 //==================================================================
52 
ScMoveTableDlg(Window * pParent)53 ScMoveTableDlg::ScMoveTableDlg( Window* pParent )
54 
55 	:	ModalDialog ( pParent, ScResId( RID_SCDLG_MOVETAB ) ),
56 		//
57 		aFtDoc      ( this, ScResId( FT_DEST ) ),
58 		aLbDoc      ( this, ScResId( LB_DEST ) ),
59 		aFtTable    ( this, ScResId( FT_INSERT ) ),
60 		aLbTable    ( this, ScResId( LB_INSERT ) ),
61 		aBtnCopy    ( this, ScResId( BTN_COPY ) ),
62 		aBtnOk      ( this, ScResId( BTN_OK ) ),
63 		aBtnCancel  ( this, ScResId( BTN_CANCEL ) ),
64 		aBtnHelp    ( this, ScResId( BTN_HELP ) ),
65 		//
66 		nDocument   ( 0 ),
67 		nTable      ( 0 ),
68 		bCopyTable  ( sal_False )
69 {
70 #if ENABLE_LAYOUT
71 #undef ScResId
72     SetHelpId (FID_TAB_MOVE);
73 #endif /* ENABLE_LAYOUT */
74 	Init();
75 	FreeResource();
76 }
77 
78 //------------------------------------------------------------------------
79 
~ScMoveTableDlg()80 __EXPORT ScMoveTableDlg::~ScMoveTableDlg()
81 {
82 }
83 
84 //------------------------------------------------------------------------
85 
GetSelectedDocument() const86 sal_uInt16 ScMoveTableDlg::GetSelectedDocument () const { return nDocument;  }
87 
GetSelectedTable() const88 SCTAB ScMoveTableDlg::GetSelectedTable    () const { return nTable;     }
89 
GetCopyTable() const90 sal_Bool   ScMoveTableDlg::GetCopyTable        () const { return bCopyTable; }
91 
SetCopyTable(sal_Bool bFlag)92 void ScMoveTableDlg::SetCopyTable(sal_Bool bFlag)
93 {
94 	aBtnCopy.Check(bFlag);
95 }
EnableCopyTable(sal_Bool bFlag)96 void ScMoveTableDlg::EnableCopyTable(sal_Bool bFlag)
97 {
98 	if(bFlag)
99 		aBtnCopy.Enable();
100 	else
101 		aBtnCopy.Disable();
102 }
103 
104 
105 //------------------------------------------------------------------------
106 
Init()107 void __EXPORT ScMoveTableDlg::Init()
108 {
109 	aBtnOk.SetClickHdl   ( LINK( this, ScMoveTableDlg, OkHdl ) );
110 	aLbDoc.SetSelectHdl  ( LINK( this, ScMoveTableDlg, SelHdl ) );
111 	aBtnCopy.Check( sal_False );
112 	InitDocListBox();
113 	SelHdl( &aLbDoc );
114 }
115 
116 //------------------------------------------------------------------------
117 
InitDocListBox()118 void ScMoveTableDlg::InitDocListBox()
119 {
120 	SfxObjectShell* pSh		= SfxObjectShell::GetFirst();
121 	ScDocShell*		pScSh	= NULL;
122 	sal_uInt16    		nSelPos	= 0;
123 	sal_uInt16    		i    	= 0;
124 
125 	aLbDoc.Clear();
126 	aLbDoc.SetUpdateMode( sal_False );
127 
128 	while ( pSh )
129 	{
130 		pScSh = PTR_CAST( ScDocShell, pSh );
131 
132 		if ( pScSh )
133 		{
134 			if ( pScSh == SfxObjectShell::Current() )
135 				nSelPos = i;
136 
137 			aLbDoc.InsertEntry( pScSh->GetTitle(), i );
138 			aLbDoc.SetEntryData( i, (void*)pScSh->GetDocument() );
139 
140 			i++;
141 		}
142 		pSh = SfxObjectShell::GetNext( *pSh );
143 	}
144 
145 	aLbDoc.SetUpdateMode( sal_True );
146 	aLbDoc.InsertEntry( String( ScResId( STR_NEWDOC ) ) );
147 	aLbDoc.SelectEntryPos( nSelPos );
148 }
149 
150 
151 //------------------------------------------------------------------------
152 // Handler:
153 
IMPL_LINK(ScMoveTableDlg,OkHdl,void *,EMPTYARG)154 IMPL_LINK( ScMoveTableDlg, OkHdl, void *, EMPTYARG )
155 {
156 	sal_uInt16  nDocSel     = aLbDoc.GetSelectEntryPos();
157 	sal_uInt16  nDocLast    = aLbDoc.GetEntryCount()-1;
158 	sal_uInt16  nTabSel     = aLbTable.GetSelectEntryPos();
159 	sal_uInt16  nTabLast    = aLbTable.GetEntryCount()-1;
160 
161 	nDocument   = (nDocSel != nDocLast) ? nDocSel : SC_DOC_NEW;
162 	nTable      = (nTabSel != nTabLast) ? static_cast<SCTAB>(nTabSel) : SC_TAB_APPEND;
163 	bCopyTable  = aBtnCopy.IsChecked();
164 	EndDialog( RET_OK );
165 
166 	return 0;
167 }
168 
169 //------------------------------------------------------------------------
170 
IMPL_LINK(ScMoveTableDlg,SelHdl,ListBox *,pLb)171 IMPL_LINK( ScMoveTableDlg, SelHdl, ListBox *, pLb )
172 {
173 	if ( pLb == &aLbDoc )
174 	{
175 		ScDocument* pDoc   = (ScDocument*)
176 							 aLbDoc.GetEntryData( aLbDoc.GetSelectEntryPos() );
177 		SCTAB      nLast  = 0;
178 		String      aName;
179 
180 		aLbTable.Clear();
181 		aLbTable.SetUpdateMode( sal_False );
182 		if ( pDoc )
183 		{
184 			nLast = pDoc->GetTableCount()-1;
185 			for ( SCTAB i=0; i<=nLast; i++ )
186 			{
187 				pDoc->GetName( i, aName );
188 				aLbTable.InsertEntry( aName, static_cast<sal_uInt16>(i) );
189 			}
190 		}
191 		aLbTable.InsertEntry( ScGlobal::GetRscString(STR_MOVE_TO_END) );
192 		aLbTable.SetUpdateMode( sal_True );
193 		aLbTable.SelectEntryPos( 0 );
194 	}
195 
196 	return 0;
197 }
198 
199 
200 
201