xref: /trunk/main/sc/source/ui/miscdlgs/mvtabdlg.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #undef SC_DLLIMPLEMENTATION
32 
33 
34 
35 //------------------------------------------------------------------
36 
37 #include <vcl/msgbox.hxx>
38 
39 #include "mvtabdlg.hxx"
40 #include "document.hxx"
41 #include "docsh.hxx"
42 #include "miscdlgs.hrc"
43 #include "global.hxx"
44 #include "scresid.hxx"
45 #include "globstr.hrc"
46 
47 #include <layout/layout-pre.hxx>
48 
49 #if ENABLE_LAYOUT
50 #undef ScResId
51 #define ScResId(x) #x
52 #undef ModalDialog
53 #define ModalDialog( parent, id ) Dialog( parent, "move-copy-sheet.xml", id )
54 #endif /* ENABLE_LAYOUT */
55 
56 //==================================================================
57 
58 ScMoveTableDlg::ScMoveTableDlg( Window* pParent )
59 
60     :   ModalDialog ( pParent, ScResId( RID_SCDLG_MOVETAB ) ),
61         //
62         aFtDoc      ( this, ScResId( FT_DEST ) ),
63         aLbDoc      ( this, ScResId( LB_DEST ) ),
64         aFtTable    ( this, ScResId( FT_INSERT ) ),
65         aLbTable    ( this, ScResId( LB_INSERT ) ),
66         aBtnCopy    ( this, ScResId( BTN_COPY ) ),
67         aBtnOk      ( this, ScResId( BTN_OK ) ),
68         aBtnCancel  ( this, ScResId( BTN_CANCEL ) ),
69         aBtnHelp    ( this, ScResId( BTN_HELP ) ),
70         //
71         nDocument   ( 0 ),
72         nTable      ( 0 ),
73         bCopyTable  ( sal_False )
74 {
75 #if ENABLE_LAYOUT
76 #undef ScResId
77     SetHelpId (FID_TAB_MOVE);
78 #endif /* ENABLE_LAYOUT */
79     Init();
80     FreeResource();
81 }
82 
83 //------------------------------------------------------------------------
84 
85 __EXPORT ScMoveTableDlg::~ScMoveTableDlg()
86 {
87 }
88 
89 //------------------------------------------------------------------------
90 
91 sal_uInt16 ScMoveTableDlg::GetSelectedDocument () const { return nDocument;  }
92 
93 SCTAB ScMoveTableDlg::GetSelectedTable    () const { return nTable;     }
94 
95 sal_Bool   ScMoveTableDlg::GetCopyTable        () const { return bCopyTable; }
96 
97 void ScMoveTableDlg::SetCopyTable(sal_Bool bFlag)
98 {
99     aBtnCopy.Check(bFlag);
100 }
101 void ScMoveTableDlg::EnableCopyTable(sal_Bool bFlag)
102 {
103     if(bFlag)
104         aBtnCopy.Enable();
105     else
106         aBtnCopy.Disable();
107 }
108 
109 
110 //------------------------------------------------------------------------
111 
112 void __EXPORT ScMoveTableDlg::Init()
113 {
114     aBtnOk.SetClickHdl   ( LINK( this, ScMoveTableDlg, OkHdl ) );
115     aLbDoc.SetSelectHdl  ( LINK( this, ScMoveTableDlg, SelHdl ) );
116     aBtnCopy.Check( sal_False );
117     InitDocListBox();
118     SelHdl( &aLbDoc );
119 }
120 
121 //------------------------------------------------------------------------
122 
123 void ScMoveTableDlg::InitDocListBox()
124 {
125     SfxObjectShell* pSh     = SfxObjectShell::GetFirst();
126     ScDocShell*     pScSh   = NULL;
127     sal_uInt16          nSelPos = 0;
128     sal_uInt16          i       = 0;
129 
130     aLbDoc.Clear();
131     aLbDoc.SetUpdateMode( sal_False );
132 
133     while ( pSh )
134     {
135         pScSh = PTR_CAST( ScDocShell, pSh );
136 
137         if ( pScSh )
138         {
139             if ( pScSh == SfxObjectShell::Current() )
140                 nSelPos = i;
141 
142             aLbDoc.InsertEntry( pScSh->GetTitle(), i );
143             aLbDoc.SetEntryData( i, (void*)pScSh->GetDocument() );
144 
145             i++;
146         }
147         pSh = SfxObjectShell::GetNext( *pSh );
148     }
149 
150     aLbDoc.SetUpdateMode( sal_True );
151     aLbDoc.InsertEntry( String( ScResId( STR_NEWDOC ) ) );
152     aLbDoc.SelectEntryPos( nSelPos );
153 }
154 
155 
156 //------------------------------------------------------------------------
157 // Handler:
158 
159 IMPL_LINK( ScMoveTableDlg, OkHdl, void *, EMPTYARG )
160 {
161     sal_uInt16  nDocSel     = aLbDoc.GetSelectEntryPos();
162     sal_uInt16  nDocLast    = aLbDoc.GetEntryCount()-1;
163     sal_uInt16  nTabSel     = aLbTable.GetSelectEntryPos();
164     sal_uInt16  nTabLast    = aLbTable.GetEntryCount()-1;
165 
166     nDocument   = (nDocSel != nDocLast) ? nDocSel : SC_DOC_NEW;
167     nTable      = (nTabSel != nTabLast) ? static_cast<SCTAB>(nTabSel) : SC_TAB_APPEND;
168     bCopyTable  = aBtnCopy.IsChecked();
169     EndDialog( RET_OK );
170 
171     return 0;
172 }
173 
174 //------------------------------------------------------------------------
175 
176 IMPL_LINK( ScMoveTableDlg, SelHdl, ListBox *, pLb )
177 {
178     if ( pLb == &aLbDoc )
179     {
180         ScDocument* pDoc   = (ScDocument*)
181                              aLbDoc.GetEntryData( aLbDoc.GetSelectEntryPos() );
182         SCTAB      nLast  = 0;
183         String      aName;
184 
185         aLbTable.Clear();
186         aLbTable.SetUpdateMode( sal_False );
187         if ( pDoc )
188         {
189             nLast = pDoc->GetTableCount()-1;
190             for ( SCTAB i=0; i<=nLast; i++ )
191             {
192                 pDoc->GetName( i, aName );
193                 aLbTable.InsertEntry( aName, static_cast<sal_uInt16>(i) );
194             }
195         }
196         aLbTable.InsertEntry( ScGlobal::GetRscString(STR_MOVE_TO_END) );
197         aLbTable.SetUpdateMode( sal_True );
198         aLbTable.SelectEntryPos( 0 );
199     }
200 
201     return 0;
202 }
203 
204 
205 
206