filters

slide.cpp

00001 /* libppt - library to read PowerPoint presentation
00002    Copyright (C) 2005 Yolla Indria <yolla.indria@gmail.com>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008    
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA
00018 */
00019 
00020 #include "slide.h"
00021 #include "presentation.h"
00022 #include "ustring.h"
00023 #include "objects.h"
00024 
00025 #include <vector>
00026 #include <iostream>
00027 
00028 
00029 using namespace Libppt;
00030 
00031 class Slide::Private
00032 {
00033 public:
00034   Presentation* presentation;
00035   UString title;
00036   GroupObject* rootObject;
00037 
00038   double pageWidth; 
00039   double pageHeight;
00040 };
00041 
00042 Slide::Slide( Presentation* pr )
00043 {
00044   d = new Private;
00045   d->presentation = pr;
00046   d->rootObject = new GroupObject;
00047   d->pageWidth = 0.0; 
00048   d->pageHeight = 0.0;
00049 }
00050   
00051 Slide::~Slide()
00052 {
00053   delete d->rootObject;
00054   delete d;
00055 }
00056 
00057 void Slide::clear()
00058 {
00059   d->title = UString::null;
00060   setRootObject( 0 );
00061   d->rootObject = new GroupObject;
00062 }
00063 
00064 UString Slide::title() const
00065 {
00066   return d->title;
00067 }
00068 
00069 void Slide::setTitle( const UString& t )
00070 {
00071   UChar* s = new UChar[t.length()];
00072   int len = 0;
00073 
00074   // filter crazy characters
00075   for( int i=0; i<t.length(); i++ )
00076     if( t[i] != UChar(11) )
00077       s[len++] = t[i];
00078 
00079   d->title = UString( s, len );
00080   delete [] s;
00081 }
00082 
00083 GroupObject *Slide::rootObject()
00084 {
00085   return d->rootObject;
00086 }
00087 
00088 void Slide::setRootObject( GroupObject* root )
00089 {
00090   delete d->rootObject;
00091   d->rootObject = root;
00092 }
00093 
00094 TextObject* recursiveSearch( GroupObject* group, unsigned placeId )
00095 {
00096   if( group )
00097     for( unsigned i=0; i<group->objectCount(); i++ )
00098     {
00099       Object* object = group->object(i);
00100       if( object->isText() )
00101       {
00102         TextObject* textObject = static_cast<TextObject*>(object);
00103         if( textObject)
00104           if( textObject->id() == (int)placeId )
00105             return textObject;
00106       }
00107       if( object->isGroup() )
00108         return recursiveSearch( static_cast<GroupObject*>(object), placeId );
00109     }
00110 
00111   return 0;
00112 }
00113 
00114 
00115 TextObject* Slide::textObject( unsigned placeId )
00116 {
00117   return recursiveSearch( d->rootObject, placeId );
00118 }
00119 
00120 double Slide::pageWidth() const
00121 { 
00122   return d->pageWidth; 
00123 }
00124 
00125 void Slide::setPageWidth( double pageWidth ) 
00126 {  
00127   d->pageWidth = pageWidth; 
00128 }
00129 
00130 double Slide::pageHeight() const
00131 {
00132   return d->pageHeight; 
00133 }
00134 
00135 void Slide::setPageHeight( double pageHeight ) 
00136 {
00137   d->pageHeight = pageHeight; 
00138 }
KDE Home | KDE Accessibility Home | Description of Access Keys