merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / docshell / docshel2.cxx
blob43ec814eab991f48ca90de024115a834b16c2942
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docshel2.cxx,v $
10 * $Revision: 1.34 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "DrawDocShell.hxx"
35 #include <vcl/msgbox.hxx>
36 #include <svx/svdpagv.hxx>
37 #include <svx/svxdlg.hxx>
38 #include <svx/dialogs.hrc>
40 #include "helpids.h"
41 #include "ViewShell.hxx"
42 #include "drawview.hxx"
43 #ifndef SD_FRAMW_VIEW_HXX
44 #include "FrameView.hxx"
45 #endif
46 #include "drawdoc.hxx"
47 #include "sdpage.hxx"
48 #include "View.hxx"
49 #include "ClientView.hxx"
50 #ifndef SD_WINDOW_SHELL_HXX
51 #include "Window.hxx"
52 #endif
53 #include "strings.hrc"
54 #include "res_bmp.hrc"
55 #include "sdresid.hxx"
56 #include "strmname.h"
57 #include "fupoor.hxx"
58 #include <vcl/svapp.hxx>
59 #include <vcl/virdev.hxx>
61 namespace sd {
63 /*************************************************************************
65 |* Zeichnen der DocShell (mittels der Hilfsklasse SdDrawViewShell)
67 \************************************************************************/
69 void DrawDocShell::Draw(OutputDevice* pOut, const JobSetup&, USHORT nAspect)
71 if (nAspect == ASPECT_THUMBNAIL)
73 /**********************************************************************
74 * THUMBNAIL: Hier koennte ev. einmal der Draft-Mode gesetzt werden
75 **********************************************************************/
78 ClientView* pView = new ClientView(this, pOut, NULL);
80 pView->SetHlplVisible(FALSE);
81 pView->SetGridVisible(FALSE);
82 pView->SetBordVisible(FALSE);
83 pView->SetPageVisible(FALSE);
84 pView->SetGlueVisible(FALSE);
86 SdPage* pSelectedPage = NULL;
88 List* pFrameViewList = mpDoc->GetFrameViewList();
89 if( pFrameViewList && pFrameViewList->Count() )
91 FrameView* pFrameView = (FrameView*)pFrameViewList->GetObject(0);
92 if( pFrameView && pFrameView->GetPageKind() == PK_STANDARD )
94 USHORT nSelectedPage = pFrameView->GetSelectedPage();
95 pSelectedPage = mpDoc->GetSdPage(nSelectedPage, PK_STANDARD);
99 if( NULL == pSelectedPage )
101 SdPage* pPage = NULL;
102 USHORT nSelectedPage = 0;
103 USHORT nPageCnt = (USHORT) mpDoc->GetSdPageCount(PK_STANDARD);
105 for (USHORT i = 0; i < nPageCnt; i++)
107 pPage = mpDoc->GetSdPage(i, PK_STANDARD);
109 if ( pPage->IsSelected() )
111 nSelectedPage = i;
112 pSelectedPage = pPage;
116 if( NULL == pSelectedPage )
117 pSelectedPage = mpDoc->GetSdPage(0, PK_STANDARD);
120 Rectangle aVisArea = GetVisArea(nAspect);
121 pOut->IntersectClipRegion(aVisArea);
122 pView->ShowSdrPage(pSelectedPage);
124 if (pOut->GetOutDevType() != OUTDEV_WINDOW)
126 MapMode aOldMapMode = pOut->GetMapMode();
128 if (pOut->GetOutDevType() == OUTDEV_PRINTER)
130 MapMode aMapMode = aOldMapMode;
131 Point aOrigin = aMapMode.GetOrigin();
132 aOrigin.X() += 1;
133 aOrigin.Y() += 1;
134 aMapMode.SetOrigin(aOrigin);
135 pOut->SetMapMode(aMapMode);
138 Region aRegion(aVisArea);
139 pView->CompleteRedraw(pOut, aRegion);
141 if (pOut->GetOutDevType() == OUTDEV_PRINTER)
143 pOut->SetMapMode(aOldMapMode);
147 delete pView;
149 // Fuer Testzwecke: Bitte nicht entfernen!
151 // GDIMetaFile* pMtf = pOut->GetConnectMetaFile();
153 // if( pMtf )
154 // {
155 // String aURLStr;
157 // if( ::utl::LocalFileHelper::ConvertPhysicalNameToURL( String( RTL_CONSTASCII_USTRINGPARAM( "d:\\gdi.mtf" ) ), aURLStr ) )
158 // {
159 // SvStream* pOStm = ::utl::UcbStreamHelper::CreateStream( aURLStr, STREAM_WRITE | STREAM_TRUNC );
161 // if( pOStm )
162 // {
163 // *pOStm << *pMtf;
164 // delete pOStm;
165 // }
166 // }
167 // }
170 /*************************************************************************
174 \************************************************************************/
176 Rectangle DrawDocShell::GetVisArea(USHORT nAspect) const
178 Rectangle aVisArea;
180 if( ( ASPECT_THUMBNAIL == nAspect ) || ( ASPECT_DOCPRINT == nAspect ) )
182 // Groesse der ersten Seite herausgeben
183 MapMode aSrcMapMode(MAP_PIXEL);
184 MapMode aDstMapMode(MAP_100TH_MM);
185 Size aSize = mpDoc->GetSdPage(0, PK_STANDARD)->GetSize();
186 aSrcMapMode.SetMapUnit(MAP_100TH_MM);
188 aSize = Application::GetDefaultDevice()->LogicToLogic(aSize, &aSrcMapMode, &aDstMapMode);
189 aVisArea.SetSize(aSize);
191 else
193 aVisArea = SfxObjectShell::GetVisArea(nAspect);
196 if (aVisArea.IsEmpty() && mpViewShell)
198 Window* pWin = mpViewShell->GetActiveWindow();
200 if (pWin)
202 aVisArea = pWin->PixelToLogic(Rectangle(Point(0,0), pWin->GetOutputSizePixel()));
206 return (aVisArea);
209 /*************************************************************************
211 |* ViewShell anmelden
213 \************************************************************************/
215 void DrawDocShell::Connect(ViewShell* pViewSh)
217 mpViewShell = pViewSh;
220 /*************************************************************************
222 |* ViewShell abmelden
224 \************************************************************************/
226 void DrawDocShell::Disconnect(ViewShell* pViewSh)
228 if (mpViewShell == pViewSh)
230 mpViewShell = NULL;
234 /*************************************************************************
238 \************************************************************************/
240 FrameView* DrawDocShell::GetFrameView()
242 FrameView* pFrameView = NULL;
244 if (mpViewShell)
246 pFrameView = mpViewShell->GetFrameView();
249 return(pFrameView);
252 /*************************************************************************
254 |* Groesse der ersten Seite zurueckgeben
256 \************************************************************************/
258 Size DrawDocShell::GetFirstPageSize()
260 return SfxObjectShell::GetFirstPageSize();
263 /*************************************************************************
265 |* Bitmap einer beliebigen Seite erzeugen
267 \************************************************************************/
269 Bitmap DrawDocShell::GetPagePreviewBitmap(SdPage* pPage, USHORT nMaxEdgePixel)
271 MapMode aMapMode( MAP_100TH_MM );
272 const Size aSize( pPage->GetSize() );
273 const Point aNullPt;
274 VirtualDevice aVDev( *Application::GetDefaultDevice() );
276 aVDev.SetMapMode( aMapMode );
278 const Size aPixSize( aVDev.LogicToPixel( aSize ) );
279 const ULONG nMaxEdgePix = Max( aPixSize.Width(), aPixSize.Height() );
280 Fraction aFrac( nMaxEdgePixel, nMaxEdgePix );
282 aMapMode.SetScaleX( aFrac );
283 aMapMode.SetScaleY( aFrac );
284 aVDev.SetMapMode( aMapMode );
285 aVDev.SetOutputSize( aSize );
287 // damit die dunklen Linien am rechten und unteren Seitenrans mitkommen
288 aFrac = Fraction( nMaxEdgePixel - 1, nMaxEdgePix );
289 aMapMode.SetScaleX( aFrac );
290 aMapMode.SetScaleY( aFrac );
291 aVDev.SetMapMode( aMapMode );
293 ClientView* pView = new ClientView( this, &aVDev, NULL );
294 FrameView* pFrameView = GetFrameView();
295 pView->ShowSdrPage( pPage );
297 if ( GetFrameView() )
299 // Initialisierungen der Zeichen-(Bildschirm-)Attribute
300 pView->SetGridCoarse( pFrameView->GetGridCoarse() );
301 pView->SetGridFine( pFrameView->GetGridFine() );
302 pView->SetSnapGridWidth(pFrameView->GetSnapGridWidthX(), pFrameView->GetSnapGridWidthY());
303 pView->SetGridVisible( pFrameView->IsGridVisible() );
304 pView->SetGridFront( pFrameView->IsGridFront() );
305 pView->SetSnapAngle( pFrameView->GetSnapAngle() );
306 pView->SetGridSnap( pFrameView->IsGridSnap() );
307 pView->SetBordSnap( pFrameView->IsBordSnap() );
308 pView->SetHlplSnap( pFrameView->IsHlplSnap() );
309 pView->SetOFrmSnap( pFrameView->IsOFrmSnap() );
310 pView->SetOPntSnap( pFrameView->IsOPntSnap() );
311 pView->SetOConSnap( pFrameView->IsOConSnap() );
312 pView->SetDragStripes( pFrameView->IsDragStripes() );
313 pView->SetFrameDragSingles( pFrameView->IsFrameDragSingles() );
314 pView->SetSnapMagneticPixel( pFrameView->GetSnapMagneticPixel() );
315 pView->SetMarkedHitMovesAlways( pFrameView->IsMarkedHitMovesAlways() );
316 pView->SetMoveOnlyDragging( pFrameView->IsMoveOnlyDragging() );
317 pView->SetSlantButShear( pFrameView->IsSlantButShear() );
318 pView->SetNoDragXorPolys( pFrameView->IsNoDragXorPolys() );
319 pView->SetCrookNoContortion( pFrameView->IsCrookNoContortion() );
320 pView->SetAngleSnapEnabled( pFrameView->IsAngleSnapEnabled() );
321 pView->SetBigOrtho( pFrameView->IsBigOrtho() );
322 pView->SetOrtho( pFrameView->IsOrtho() );
324 SdrPageView* pPageView = pView->GetSdrPageView();
326 if (pPageView)
328 if ( pPageView->GetVisibleLayers() != pFrameView->GetVisibleLayers() )
329 pPageView->SetVisibleLayers( pFrameView->GetVisibleLayers() );
331 if ( pPageView->GetPrintableLayers() != pFrameView->GetPrintableLayers() )
332 pPageView->SetPrintableLayers( pFrameView->GetPrintableLayers() );
334 if ( pPageView->GetLockedLayers() != pFrameView->GetLockedLayers() )
335 pPageView->SetLockedLayers( pFrameView->GetLockedLayers() );
337 // if ( pPageView->GetHelpLines() != pFrameView->GetHelpLines() )
338 pPageView->SetHelpLines( pFrameView->GetStandardHelpLines() );
341 if ( pView->GetActiveLayer() != pFrameView->GetActiveLayer() )
342 pView->SetActiveLayer( pFrameView->GetActiveLayer() );
345 pView->CompleteRedraw( &aVDev, Rectangle( aNullPt, aSize ) );
347 // #111097# IsRedrawReady() always gives sal_True while ( !pView->IsRedrawReady() ) {}
348 delete pView;
350 aVDev.SetMapMode( MapMode() );
352 Bitmap aPreview( aVDev.GetBitmap( aNullPt, aVDev.GetOutputSizePixel() ) );
354 DBG_ASSERT(!!aPreview, "Vorschau-Bitmap konnte nicht erzeugt werden");
356 return aPreview;
360 /*************************************************************************
362 |* Pruefen, ob die Seite vorhanden ist und dann den Anwender zwingen einen
363 |* noch nicht vorhandenen Namen einzugeben. Wird FALSE zurueckgegeben,
364 |* wurde die Aktion vom Anwender abgebrochen.
366 \************************************************************************/
368 BOOL DrawDocShell::CheckPageName (::Window* pWin, String& rName )
370 const String aStrForDlg( rName );
371 bool bIsNameValid = IsNewPageNameValid( rName, true );
373 if( ! bIsNameValid )
375 String aDesc( SdResId( STR_WARN_PAGE_EXISTS ) );
376 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
377 AbstractSvxNameDialog* aNameDlg = pFact ? pFact->CreateSvxNameDialog( pWin, aStrForDlg, aDesc, RID_SVXDLG_NAME ) : 0;
378 if( aNameDlg )
380 aNameDlg->SetEditHelpId( HID_SD_NAMEDIALOG_PAGE );
382 if( mpViewShell )
383 aNameDlg->SetCheckNameHdl( LINK( this, DrawDocShell, RenameSlideHdl ) );
385 FunctionReference xFunc( mpViewShell->GetCurrentFunction() );
386 if( xFunc.is() )
387 xFunc->cancel();
389 if( aNameDlg->Execute() == RET_OK )
391 aNameDlg->GetName( rName );
392 bIsNameValid = IsNewPageNameValid( rName );
394 delete aNameDlg;
398 return ( bIsNameValid ? TRUE : FALSE );
401 bool DrawDocShell::IsNewPageNameValid( String & rInOutPageName, bool bResetStringIfStandardName /* = false */ )
403 bool bCanUseNewName = false;
405 // check if name is something like 'Slide n'
406 String aStrPage( SdResId( STR_SD_PAGE ) );
407 aStrPage += ' ';
409 bool bIsStandardName = false;
411 // prevent also _future_ slide names of the form "'STR_SD_PAGE' + ' ' + '[0-9]+|[a-z]|[A-Z]|[CDILMVX]+|[cdilmvx]+'"
412 // (arabic, lower- and upper case single letter, lower- and upper case roman numbers)
413 if( 0 == rInOutPageName.Search( aStrPage ) )
415 if( rInOutPageName.GetToken( 1, sal_Unicode(' ') ).GetChar(0) >= '0' &&
416 rInOutPageName.GetToken( 1, sal_Unicode(' ') ).GetChar(0) <= '9' )
418 // check for arabic numbering
420 // gobble up all following numbers
421 String sRemainder = rInOutPageName.GetToken( 1, sal_Unicode(' ') );
422 while( sRemainder.Len() &&
423 sRemainder.GetChar(0) >= '0' &&
424 sRemainder.GetChar(0) <= '9' )
426 // trim by one
427 sRemainder.Erase(0, 1);
430 // EOL? Reserved name!
431 if( !sRemainder.Len() )
433 bIsStandardName = true;
436 else if( rInOutPageName.GetToken( 1, sal_Unicode(' ') ).GetChar(0) >= 'a' &&
437 rInOutPageName.GetToken( 1, sal_Unicode(' ') ).GetChar(0) <= 'z' &&
438 rInOutPageName.GetToken( 1, sal_Unicode(' ') ).Len() == 1 )
440 // lower case, single character: reserved
441 bIsStandardName = true;
443 else if( rInOutPageName.GetToken( 1, sal_Unicode(' ') ).GetChar(0) >= 'A' &&
444 rInOutPageName.GetToken( 1, sal_Unicode(' ') ).GetChar(0) <= 'Z' &&
445 rInOutPageName.GetToken( 1, sal_Unicode(' ') ).Len() == 1 )
447 // upper case, single character: reserved
448 bIsStandardName = true;
450 else
452 // check for upper/lower case roman numbering
453 String sReserved( String::CreateFromAscii( "cdilmvx" ) );
455 // gobble up all following characters contained in one reserved class
456 String sRemainder = rInOutPageName.GetToken( 1, sal_Unicode(' ') );
457 if( sReserved.Search( sRemainder.GetChar(0) ) == STRING_NOTFOUND )
458 sReserved.ToUpperAscii();
460 while( sReserved.Search( sRemainder.GetChar(0) ) != STRING_NOTFOUND )
462 // trim by one
463 sRemainder.Erase(0, 1);
466 // EOL? Reserved name!
467 if( !sRemainder.Len() )
469 bIsStandardName = true;
474 if( bIsStandardName )
476 if( bResetStringIfStandardName )
478 // this is for insertion of slides from other files with standard
479 // name. They get a new standard name, if the string is set to an
480 // empty one.
481 rInOutPageName = String();
482 bCanUseNewName = true;
484 else
485 bCanUseNewName = false;
487 else
489 if( rInOutPageName.Len() > 0 )
491 BOOL bOutDummy;
492 USHORT nExistingPageNum = mpDoc->GetPageByName( rInOutPageName, bOutDummy );
493 bCanUseNewName = ( nExistingPageNum == SDRPAGE_NOTFOUND );
495 else
496 bCanUseNewName = false;
499 return bCanUseNewName;
502 IMPL_LINK( DrawDocShell, RenameSlideHdl, AbstractSvxNameDialog*, pDialog )
504 if( ! pDialog )
505 return 0;
507 String aNewName;
508 pDialog->GetName( aNewName );
510 return IsNewPageNameValid( aNewName );
512 } // end of namespace sd