sync master with lastest vba changes
[ooovba.git] / sc / source / ui / miscdlgs / mvtabdlg.cxx
blob67db04ab253997d09da7f22f23ba0ed9d0143542
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mvtabdlg.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 //------------------------------------------------------------------
40 #include <vcl/msgbox.hxx>
42 #include "mvtabdlg.hxx"
43 #include "document.hxx"
44 #include "docsh.hxx"
45 #include "miscdlgs.hrc"
46 #include "global.hxx"
47 #include "scresid.hxx"
48 #include "globstr.hrc"
50 #include <layout/layout-pre.hxx>
52 #if ENABLE_LAYOUT
53 #undef ScResId
54 #define ScResId(x) #x
55 #undef ModalDialog
56 #define ModalDialog( parent, id ) Dialog( parent, "move-copy-sheet.xml", id )
57 #endif /* ENABLE_LAYOUT */
59 //==================================================================
61 ScMoveTableDlg::ScMoveTableDlg( Window* pParent )
63 : ModalDialog ( pParent, ScResId( RID_SCDLG_MOVETAB ) ),
65 aFtDoc ( this, ScResId( FT_DEST ) ),
66 aLbDoc ( this, ScResId( LB_DEST ) ),
67 aFtTable ( this, ScResId( FT_INSERT ) ),
68 aLbTable ( this, ScResId( LB_INSERT ) ),
69 aBtnCopy ( this, ScResId( BTN_COPY ) ),
70 aBtnOk ( this, ScResId( BTN_OK ) ),
71 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
72 aBtnHelp ( this, ScResId( BTN_HELP ) ),
74 nDocument ( 0 ),
75 nTable ( 0 ),
76 bCopyTable ( FALSE )
78 #if ENABLE_LAYOUT
79 #undef ScResId
80 SetHelpId (FID_TAB_MOVE);
81 #endif /* ENABLE_LAYOUT */
82 Init();
83 FreeResource();
86 //------------------------------------------------------------------------
88 __EXPORT ScMoveTableDlg::~ScMoveTableDlg()
92 //------------------------------------------------------------------------
94 USHORT ScMoveTableDlg::GetSelectedDocument () const { return nDocument; }
96 SCTAB ScMoveTableDlg::GetSelectedTable () const { return nTable; }
98 BOOL ScMoveTableDlg::GetCopyTable () const { return bCopyTable; }
100 void ScMoveTableDlg::SetCopyTable(BOOL bFlag)
102 aBtnCopy.Check(bFlag);
104 void ScMoveTableDlg::EnableCopyTable(BOOL bFlag)
106 if(bFlag)
107 aBtnCopy.Enable();
108 else
109 aBtnCopy.Disable();
113 //------------------------------------------------------------------------
115 void __EXPORT ScMoveTableDlg::Init()
117 aBtnOk.SetClickHdl ( LINK( this, ScMoveTableDlg, OkHdl ) );
118 aLbDoc.SetSelectHdl ( LINK( this, ScMoveTableDlg, SelHdl ) );
119 aBtnCopy.Check( FALSE );
120 InitDocListBox();
121 SelHdl( &aLbDoc );
124 //------------------------------------------------------------------------
126 void ScMoveTableDlg::InitDocListBox()
128 SfxObjectShell* pSh = SfxObjectShell::GetFirst();
129 ScDocShell* pScSh = NULL;
130 USHORT nSelPos = 0;
131 USHORT i = 0;
133 aLbDoc.Clear();
134 aLbDoc.SetUpdateMode( FALSE );
136 while ( pSh )
138 pScSh = PTR_CAST( ScDocShell, pSh );
140 if ( pScSh )
142 if ( pScSh == SfxObjectShell::Current() )
143 nSelPos = i;
145 aLbDoc.InsertEntry( pScSh->GetTitle(), i );
146 aLbDoc.SetEntryData( i, (void*)pScSh->GetDocument() );
148 i++;
150 pSh = SfxObjectShell::GetNext( *pSh );
153 aLbDoc.SetUpdateMode( TRUE );
154 aLbDoc.InsertEntry( String( ScResId( STR_NEWDOC ) ) );
155 aLbDoc.SelectEntryPos( nSelPos );
159 //------------------------------------------------------------------------
160 // Handler:
162 IMPL_LINK( ScMoveTableDlg, OkHdl, void *, EMPTYARG )
164 USHORT nDocSel = aLbDoc.GetSelectEntryPos();
165 USHORT nDocLast = aLbDoc.GetEntryCount()-1;
166 USHORT nTabSel = aLbTable.GetSelectEntryPos();
167 USHORT nTabLast = aLbTable.GetEntryCount()-1;
169 nDocument = (nDocSel != nDocLast) ? nDocSel : SC_DOC_NEW;
170 nTable = (nTabSel != nTabLast) ? static_cast<SCTAB>(nTabSel) : SC_TAB_APPEND;
171 bCopyTable = aBtnCopy.IsChecked();
172 EndDialog( RET_OK );
174 return 0;
177 //------------------------------------------------------------------------
179 IMPL_LINK( ScMoveTableDlg, SelHdl, ListBox *, pLb )
181 if ( pLb == &aLbDoc )
183 ScDocument* pDoc = (ScDocument*)
184 aLbDoc.GetEntryData( aLbDoc.GetSelectEntryPos() );
185 SCTAB nLast = 0;
186 String aName;
188 aLbTable.Clear();
189 aLbTable.SetUpdateMode( FALSE );
190 if ( pDoc )
192 nLast = pDoc->GetTableCount()-1;
193 for ( SCTAB i=0; i<=nLast; i++ )
195 pDoc->GetName( i, aName );
196 aLbTable.InsertEntry( aName, static_cast<sal_uInt16>(i) );
199 aLbTable.InsertEntry( ScGlobal::GetRscString(STR_MOVE_TO_END) );
200 aLbTable.SetUpdateMode( TRUE );
201 aLbTable.SelectEntryPos( 0 );
204 return 0;