Back to index

scribus-ng  1.3.4.dfsg+svn20071115
sctextstruct.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 
00008 #include <qvaluelist.h>
00009 #include <qobject.h>
00010 #include "sctextstruct.h"
00011 #include "scfonts.h"
00012 #include "pageitem.h"
00013 #include "scribusdoc.h"
00014 
00015 
00016 struct InlineFrameData
00017 {
00018        PageItem* item;
00019        int refs;
00020        
00021        void reserve()  
00022        { 
00023               ++refs; 
00024        }
00025        
00026        void release()
00027        {
00028               --refs;
00029               if (refs == 0 && item != NULL)
00030               {
00031                      item->doc()->FrameItems.remove(item);
00032                      item->doc()->updateFrameItems();
00033                      delete item;
00034                      item = NULL;
00035               }
00036        }
00037 };
00038 
00039 InlineFrame::InlineFrame(PageItem* item)
00040 {
00041        d = new InlineFrameData;
00042        d->item = item;
00043        d->refs = 1;
00044 }
00045 
00046 InlineFrame::InlineFrame(const InlineFrame& other)
00047 {
00048        d = other.d;
00049        d->reserve(); 
00050 }
00051 
00052 InlineFrame& InlineFrame::operator= (const InlineFrame& other)
00053 {
00054        if (this != &other)
00055        {
00056               d->release();
00057               d = other.d;
00058               d->reserve();
00059        }
00060        return *this;
00061 }
00062 
00063 InlineFrame::~InlineFrame()
00064 {
00065        d->release();
00066 }
00067 
00068 bool InlineFrame::hasItem()
00069 {
00070        return d->item != NULL;
00071 }
00072 
00073 bool InlineFrame::isShared()
00074 {
00075        return d->refs > 1;
00076 }
00077 
00078 PageItem* InlineFrame::getItem()
00079 {
00080        return d->item;
00081 }
00082 
00083 QPtrList<PageItem> InlineFrame::getGroupedItems()
00084 {
00085        QPtrList<PageItem> result;
00086        result.setAutoDelete(false);
00087        if (hasItem())
00088        {
00089               PageItem* dItem = d->item;
00090               ScribusDoc& doc(*dItem->doc());
00091               result.append(d->item);
00092               if (dItem->Groups.count() != 0)
00093               {
00094                      for (uint ga=0; ga < doc.FrameItems.count(); ++ga)
00095                      {
00096                             if (doc.FrameItems.at(ga)->Groups.count() != 0)
00097                             {
00098                                    if (doc.FrameItems.at(ga)->Groups.top() == dItem->Groups.top())
00099                                    {
00100                                           if (doc.FrameItems.at(ga)->ItemNr != dItem->ItemNr)
00101                                           {
00102                                                  if (result.find(doc.FrameItems.at(ga)) == -1)
00103                                                         result.append(doc.FrameItems.at(ga));
00104                                           }
00105                                    }
00106                             }
00107                      }
00108               }
00109        }
00110        return result;
00111 }
00112 
00113 
00114 ScText::~ScText() 
00115 {
00116        // delete the linked list if present
00117        GlyphLayout * more = glyph.more;
00118        while (more) {
00119               glyph.more = glyph.more->more;
00120               delete more;
00121               more = glyph.more;
00122        }
00123        if (parstyle)
00124               delete parstyle;
00125        parstyle = NULL;
00126 }