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