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