xref: /aoo42x/main/sc/source/ui/docshell/docsh2.cxx (revision c7be74b1)
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 
InitNew(const uno::Reference<embed::XStorage> & xStor)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 	// InitOptions sets the document languages, must be called before CreateStandardStyles
90     InitOptions(false);
91 
92 	aDocument.GetStyleSheetPool()->CreateStandardStyles();
93 	aDocument.UpdStlShtPtrsFrmNms();
94 
95 	//	SetDocumentModified ist in Load/InitNew nicht mehr erlaubt!
96 
97 	InitItems();
98 	CalcOutputFactor();
99 #if 0
100 	uno::Any aGlobs;
101         uno::Sequence< uno::Any > aArgs(1);
102         aArgs[ 0 ] <<= GetModel();
103 	aGlobs <<= ::comphelper::getProcessServiceFactory()->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ooo.vba.excel.Globals" ) ), aArgs );
104 	GetBasicManager()->SetGlobalUNOConstant( "VBAGlobals", aGlobs );
105         // Fake ThisComponent being setup by Activate ( which is a view
106         // related thing ),
107         //  a) if another document is opened then in theory  ThisComponent
108         //     will be reset as before,
109         //  b) when this document is  'really' Activated then ThisComponent
110         //     again will be set as before
111         // The only wrinkle seems if this document is loaded 'InVisible'
112         // but.. I don't see that this is possible from the vba API
113         // I could be wrong though
114         // There may be implications setting the current component
115         // too early :-/ so I will just manually set the Basic Variables
116         BasicManager* pAppMgr = SFX_APP()->GetBasicManager();
117         if ( pAppMgr )
118             pAppMgr->SetGlobalUNOConstant( "ThisExcelDoc", aArgs[ 0 ] );
119 #endif
120 
121 	return bRet;
122 }
123 
124 //------------------------------------------------------------------
125 
IsEmpty() const126 sal_Bool ScDocShell::IsEmpty() const
127 {
128 	return bIsEmpty;
129 }
130 
131 
SetEmpty(sal_Bool bSet)132 void ScDocShell::SetEmpty(sal_Bool bSet)
133 {
134 	bIsEmpty = bSet;
135 }
136 
137 //------------------------------------------------------------------
138 
InitItems()139 void ScDocShell::InitItems()
140 {
141 	// AllItemSet fuer Controller mit benoetigten Items fuellen:
142 
143     // if ( pImpl->pFontList )
144     //  delete pImpl->pFontList;
145 
146 	//	Druck-Optionen werden beim Drucken und evtl. in GetPrinter gesetzt
147 
148     // pImpl->pFontList = new FontList( GetPrinter(), Application::GetDefaultDevice() );
149     //PutItem( SvxFontListItem( pImpl->pFontList, SID_ATTR_CHAR_FONTLIST ) );
150 	UpdateFontList();
151 
152 	ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
153 	if (pDrawLayer)
154 	{
155         PutItem( SvxColorTableItem  ( pDrawLayer->GetColorTableFromSdrModel(), SID_COLOR_TABLE ) );
156         PutItem( SvxGradientListItem( pDrawLayer->GetGradientListFromSdrModel(), SID_GRADIENT_LIST ) );
157         PutItem( SvxHatchListItem   ( pDrawLayer->GetHatchListFromSdrModel(), SID_HATCH_LIST ) );
158         PutItem( SvxBitmapListItem  ( pDrawLayer->GetBitmapListFromSdrModel(), SID_BITMAP_LIST ) );
159         PutItem( SvxDashListItem    ( pDrawLayer->GetDashListFromSdrModel(), SID_DASH_LIST ) );
160         PutItem( SvxLineEndListItem ( pDrawLayer->GetLineEndListFromSdrModel(), SID_LINEEND_LIST ) );
161 
162 			//	andere Anpassungen nach dem Anlegen des DrawLayers
163 
164 		pDrawLayer->SetNotifyUndoActionHdl( LINK( pDocFunc, ScDocFunc, NotifyDrawUndo ) );
165 
166 		//if (SfxObjectShell::HasSbxObject())
167 		pDrawLayer->UpdateBasic();			// DocShell-Basic in DrawPages setzen
168 	}
169 	else
170 	{
171 		//	always use global color table instead of local copy
172         PutItem( SvxColorTableItem( XColorList::GetStdColorList(), SID_COLOR_TABLE ) );
173 	}
174 
175 	if ( !aDocument.GetForbiddenCharacters().isValid() ||
176 			!aDocument.IsValidAsianCompression() || !aDocument.IsValidAsianKerning() )
177 	{
178 		//	get settings from SvxAsianConfig
179 		SvxAsianConfig aAsian( sal_False );
180 
181 		if ( !aDocument.GetForbiddenCharacters().isValid() )
182 		{
183 			// set forbidden characters if necessary
184 			uno::Sequence<lang::Locale> aLocales = aAsian.GetStartEndCharLocales();
185 			if (aLocales.getLength())
186 			{
187 				vos::ORef<SvxForbiddenCharactersTable> xForbiddenTable =
188 						new SvxForbiddenCharactersTable( aDocument.GetServiceManager() );
189 
190 				const lang::Locale* pLocales = aLocales.getConstArray();
191 				for (sal_Int32 i = 0; i < aLocales.getLength(); i++)
192 				{
193 					i18n::ForbiddenCharacters aForbidden;
194 					aAsian.GetStartEndChars( pLocales[i], aForbidden.beginLine, aForbidden.endLine );
195 					LanguageType eLang = SvxLocaleToLanguage(pLocales[i]);
196 					//pDoc->SetForbiddenCharacters( eLang, aForbidden );
197 
198 					xForbiddenTable->SetForbiddenCharacters( eLang, aForbidden );
199 				}
200 
201 				aDocument.SetForbiddenCharacters( xForbiddenTable );
202 			}
203 		}
204 
205 		if ( !aDocument.IsValidAsianCompression() )
206 		{
207 			// set compression mode from configuration if not already set (e.g. XML import)
208             aDocument.SetAsianCompression( sal::static_int_cast<sal_uInt8>( aAsian.GetCharDistanceCompression() ) );
209 		}
210 
211 		if ( !aDocument.IsValidAsianKerning() )
212 		{
213 			// set asian punctuation kerning from configuration if not already set (e.g. XML import)
214 			aDocument.SetAsianKerning( !aAsian.IsKerningWesternTextOnly() );	// reversed
215 		}
216 	}
217 }
218 
219 //------------------------------------------------------------------
220 
ResetDrawObjectShell()221 void ScDocShell::ResetDrawObjectShell()
222 {
223 	ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
224 	if (pDrawLayer)
225 		pDrawLayer->SetObjectShell( NULL );
226 }
227 
228 //------------------------------------------------------------------
229 
Activate()230 void __EXPORT ScDocShell::Activate()
231 {
232 }
233 
234 
Deactivate()235 void __EXPORT ScDocShell::Deactivate()
236 {
237 }
238 
239 //------------------------------------------------------------------
240 
241 
MakeDrawLayer()242 ScDrawLayer* ScDocShell::MakeDrawLayer()
243 {
244 	ScDrawLayer* pDrawLayer = aDocument.GetDrawLayer();
245 	if (!pDrawLayer)
246 	{
247 		RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "sc", "nn93723", "ScDocShell::MakeDrawLayer" );
248 
249 		aDocument.InitDrawLayer(this);
250 		pDrawLayer = aDocument.GetDrawLayer();
251 		InitItems();											// incl. Undo und Basic
252 		Broadcast( SfxSimpleHint( SC_HINT_DRWLAYER_NEW ) );
253 		if (nDocumentLock)
254 			pDrawLayer->setLock(sal_True);
255 	}
256 	return pDrawLayer;
257 }
258