xref: /trunk/main/sc/source/ui/docshell/docsh2.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 
32 #include <svx/svdpage.hxx>
33 
34 
35 #include <svx/xtable.hxx>
36 
37 #include "scitems.hxx"
38 #include <tools/gen.hxx>
39 #include <svtools/ctrltool.hxx>
40 #include <editeng/flstitem.hxx>
41 #include <svx/drawitem.hxx>
42 #include <sfx2/printer.hxx>
43 #include <svl/smplhint.hxx>
44 #include <svx/svditer.hxx>
45 #include <svx/svdobj.hxx>
46 #include <svx/svdoole2.hxx>
47 #include <vcl/svapp.hxx>
48 #include <svl/asiancfg.hxx>
49 #include <editeng/forbiddencharacterstable.hxx>
50 #include <editeng/unolingu.hxx>
51 #include <rtl/logfile.hxx>
52 
53 #include <comphelper/processfactory.hxx>
54 #include <basic/sbstar.hxx>
55 #include <basic/basmgr.hxx>
56 #include <sfx2/app.hxx>
57 
58 // INCLUDE ---------------------------------------------------------------
59 /*
60 #include <svdrwetc.hxx>
61 #include <svdrwobx.hxx>
62 #include <sostor.hxx>
63 */
64 #include "drwlayer.hxx"
65 #include "stlpool.hxx"
66 #include "docsh.hxx"
67 #include "docshimp.hxx"
68 #include "docfunc.hxx"
69 #include "sc.hrc"
70 
71 using namespace com::sun::star;
72 
73 //------------------------------------------------------------------
74 
75 sal_Bool __EXPORT ScDocShell::InitNew( const uno::Reference < embed::XStorage >& xStor )
76 {
77     RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::InitNew" );
78 
79     sal_Bool bRet = SfxObjectShell::InitNew( xStor );
80 
81     aDocument.MakeTable(0);
82     //  zusaetzliche Tabellen werden von der ersten View angelegt,
83     //  wenn bIsEmpty dann noch sal_True ist
84 
85     if( bRet )
86     {
87         Size aSize( (long) ( STD_COL_WIDTH           * HMM_PER_TWIPS * OLE_STD_CELLS_X ),
88                     (long) ( ScGlobal::nStdRowHeight * HMM_PER_TWIPS * OLE_STD_CELLS_Y ) );
89         // hier muss auch der Start angepasst werden
90         SetVisAreaOrSize( Rectangle( Point(), aSize ), sal_True );
91     }
92 
93     aDocument.SetDrawDefaults();        // drawing layer defaults that are set only in InitNew
94 
95     // InitOptions sets the document languages, must be called before CreateStandardStyles
96     InitOptions(false);
97 
98     aDocument.GetStyleSheetPool()->CreateStandardStyles();
99     aDocument.UpdStlShtPtrsFrmNms();
100 
101     //  SetDocumentModified ist in Load/InitNew nicht mehr erlaubt!
102 
103     InitItems();
104     CalcOutputFactor();
105 #if 0
106     uno::Any aGlobs;
107         uno::Sequence< uno::Any > aArgs(1);
108         aArgs[ 0 ] <<= GetModel();
109     aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ), aArgs );
110     GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs );
111         // Fake ThisComponent being setup by Activate ( which is a view
112         // related thing ),
113         //  a) if another document is opened then in theory  ThisComponent
114         //     will be reset as before,
115         //  b) when this document is  'really' Activated then ThisComponent
116         //     again will be set as before
117         // The only wrinkle seems if this document is loaded 'InVisible'
118         // but.. I don't see that this is possible from the vba API
119         // I could be wrong though
120         // There may be implications setting the current component
121         // too early :-/ so I will just manually set the Basic Variables
122         BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
123         if ( pAppMgr )
124             pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] );
125 #endif
126 
127     return bRet;
128 }
129 
130 //------------------------------------------------------------------
131 
132 sal_Bool ScDocShell::IsEmpty() const
133 {
134     return bIsEmpty;
135 }
136 
137 
138 void ScDocShell::SetEmpty(sal_Bool bSet)
139 {
140     bIsEmpty = bSet;
141 }
142 
143 //------------------------------------------------------------------
144 
145 void ScDocShell::InitItems()
146 {
147     // AllItemSet fuer Controller mit benoetigten Items fuellen:
148 
149     // if ( pImpl->pFontList )
150     //  delete pImpl->pFontList;
151 
152     //  Druck-Optionen werden beim Drucken und evtl. in GetPrinter gesetzt
153 
154     // pImpl->pFontList = new FontList( GetPrinter(), Application::GetDefaultDevice() );
155     //PutItem( SvxFontListItem( pImpl->pFontList, SID_ATTR_CHAR_FONTLIST ) );
156     UpdateFontList();
157 
158     ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
159     if (pDrawLayer)
160     {
161         PutItem( SvxColorTableItem  ( pDrawLayer->GetColorTable(), SID_COLOR_TABLE ) );
162         PutItem( SvxGradientListItem( pDrawLayer->GetGradientList(), SID_GRADIENT_LIST ) );
163         PutItem( SvxHatchListItem   ( pDrawLayer->GetHatchList(), SID_HATCH_LIST ) );
164         PutItem( SvxBitmapListItem  ( pDrawLayer->GetBitmapList(), SID_BITMAP_LIST ) );
165         PutItem( SvxDashListItem    ( pDrawLayer->GetDashList(), SID_DASH_LIST ) );
166         PutItem( SvxLineEndListItem ( pDrawLayer->GetLineEndList(), SID_LINEEND_LIST ) );
167 
168             //  andere Anpassungen nach dem Anlegen des DrawLayers
169 
170         pDrawLayer->SetNotifyUndoActionHdl( LINK( pDocFunc, ScDocFunc, NotifyDrawUndo ) );
171 
172         //if (SfxObjectShell::HasSbxObject())
173         pDrawLayer->UpdateBasic();          // DocShell-Basic in DrawPages setzen
174     }
175     else
176     {
177         //  always use global color table instead of local copy
178         PutItem( SvxColorTableItem( XColorTable::GetStdColorTable(), SID_COLOR_TABLE ) );
179     }
180 
181     if ( !aDocument.GetForbiddenCharacters().isValid() ||
182             !aDocument.IsValidAsianCompression() || !aDocument.IsValidAsianKerning() )
183     {
184         //  get settings from SvxAsianConfig
185         SvxAsianConfig aAsian( sal_False );
186 
187         if ( !aDocument.GetForbiddenCharacters().isValid() )
188         {
189             // set forbidden characters if necessary
190             uno::Sequence<lang::Locale> aLocales = aAsian.GetStartEndCharLocales();
191             if (aLocales.getLength())
192             {
193                 vos::ORef<SvxForbiddenCharactersTable> xForbiddenTable =
194                         new SvxForbiddenCharactersTable( aDocument.GetServiceManager() );
195 
196                 const lang::Locale* pLocales = aLocales.getConstArray();
197                 for (sal_Int32 i = 0; i < aLocales.getLength(); i++)
198                 {
199                     i18n::ForbiddenCharacters aForbidden;
200                     aAsian.GetStartEndChars( pLocales[i], aForbidden.beginLine, aForbidden.endLine );
201                     LanguageType eLang = SvxLocaleToLanguage(pLocales[i]);
202                     //pDoc->SetForbiddenCharacters( eLang, aForbidden );
203 
204                     xForbiddenTable->SetForbiddenCharacters( eLang, aForbidden );
205                 }
206 
207                 aDocument.SetForbiddenCharacters( xForbiddenTable );
208             }
209         }
210 
211         if ( !aDocument.IsValidAsianCompression() )
212         {
213             // set compression mode from configuration if not already set (e.g. XML import)
214             aDocument.SetAsianCompression( sal::static_int_cast<sal_uInt8>( aAsian.GetCharDistanceCompression() ) );
215         }
216 
217         if ( !aDocument.IsValidAsianKerning() )
218         {
219             // set asian punctuation kerning from configuration if not already set (e.g. XML import)
220             aDocument.SetAsianKerning( !aAsian.IsKerningWesternTextOnly() );    // reversed
221         }
222     }
223 }
224 
225 //------------------------------------------------------------------
226 
227 void ScDocShell::ResetDrawObjectShell()
228 {
229     ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
230     if (pDrawLayer)
231         pDrawLayer->SetObjectShell( NULL );
232 }
233 
234 //------------------------------------------------------------------
235 
236 void __EXPORT ScDocShell::Activate()
237 {
238 }
239 
240 
241 void __EXPORT ScDocShell::Deactivate()
242 {
243 }
244 
245 //------------------------------------------------------------------
246 
247 
248 ScDrawLayer* ScDocShell::MakeDrawLayer()
249 {
250     ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
251     if (!pDrawLayer)
252     {
253         RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::MakeDrawLayer" );
254 
255         aDocument.InitDrawLayer(this);
256         pDrawLayer = aDocument.GetDrawLayer();
257         InitItems();                                            // incl. Undo und Basic
258         Broadcast( SfxSimpleHint( SC_HINT_DRWLAYER_NEW ) );
259         if (nDocumentLock)
260             pDrawLayer->setLock(sal_True);
261     }
262     return pDrawLayer;
263 }
264