Back to index

scribus-ng  1.3.4.dfsg+svn20071115
cmdobj.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 #include "cmdobj.h"
00008 #include "cmdutil.h"
00009 #include "selection.h"
00010 #include "util.h"
00011 #include "commonstrings.h"
00012 #include "scribuscore.h"
00013 
00014 
00015 PyObject *scribus_newrect(PyObject* /* self */, PyObject* args)
00016 {
00017        double x, y, w, h;
00018        char *Name = const_cast<char*>("");
00019        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
00020               return NULL;
00021        if(!checkHaveDocument())
00022               return NULL;
00023        if (ItemExists(QString::fromUtf8(Name)))
00024        {
00025               PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
00026               return NULL;
00027        }
00028        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Rectangle,
00029                                                         pageUnitXToDocX(x), pageUnitYToDocY(y),
00030                                                         ValueToPoint(w), ValueToPoint(h),
00031                                                         ScCore->primaryMainWindow()->doc->toolSettings.dWidth,
00032                                                         ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true);
00033        ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i));
00034        if (Name != "")
00035               ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name));
00036        return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().utf8());
00037 }
00038 
00039 
00040 PyObject *scribus_newellipse(PyObject* /* self */, PyObject* args)
00041 {
00042        double x, y, w, h;
00043        char *Name = const_cast<char*>("");
00044        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
00045               return NULL;
00046        if(!checkHaveDocument())
00047               return NULL;
00048        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Ellipse,
00049                                                                       pageUnitXToDocX(x),
00050                                                                       pageUnitYToDocY(y),
00051                                                                       ValueToPoint(w),
00052                                                                       ValueToPoint(h),
00053                                                                       ScCore->primaryMainWindow()->doc->toolSettings.dWidth,
00054                                                                       ScCore->primaryMainWindow()->doc->toolSettings.dBrush,
00055                                                                       ScCore->primaryMainWindow()->doc->toolSettings.dPen,
00056                                                                       true);
00057        if (ItemExists(QString::fromUtf8(Name)))
00058        {
00059               PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
00060               return NULL;
00061        }
00062        ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i));
00063        if (Name != "")
00064               ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name));
00065        return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().utf8());
00066 }
00067 
00068 
00069 PyObject *scribus_newimage(PyObject* /* self */, PyObject* args)
00070 {
00071        double x, y, w, h;
00072        char *Name = const_cast<char*>("");
00073        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
00074               return NULL;
00075        if(!checkHaveDocument())
00076               return NULL;
00077        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::ImageFrame, PageItem::Unspecified,
00078                                                                pageUnitXToDocX(x),
00079                                                                pageUnitYToDocY(y),
00080                                                                ValueToPoint(w),
00081                                                                ValueToPoint(h),
00082                                                                1, ScCore->primaryMainWindow()->doc->toolSettings.dBrushPict,
00083                                                                CommonStrings::None, true);
00084        if (ItemExists(QString::fromUtf8(Name)))
00085        {
00086               PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
00087               return NULL;
00088        }
00089        ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i));
00090        if (Name != "")
00091               ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name));
00092        return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().utf8());
00093 }
00094 
00095 
00096 PyObject *scribus_newtext(PyObject* /* self */, PyObject* args)
00097 {
00098        double x, y, w, h;
00099        char *Name = const_cast<char*>("");
00100        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
00101               return NULL;
00102        if(!checkHaveDocument())
00103               return NULL;
00104        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::TextFrame, PageItem::Unspecified,
00105                                                         pageUnitXToDocX(x),
00106                                                         pageUnitYToDocY(y),
00107                                                         ValueToPoint(w),
00108                                                         ValueToPoint(h),
00109                                                         ScCore->primaryMainWindow()->doc->toolSettings.dWidth, CommonStrings::None,
00110                                                         ScCore->primaryMainWindow()->doc->toolSettings.dPenText, true);
00111        if (ItemExists(QString::fromUtf8(Name)))
00112        {
00113               PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
00114               return NULL;
00115        }
00116        ScCore->primaryMainWindow()->doc->setRedrawBounding(ScCore->primaryMainWindow()->doc->Items->at(i));
00117        if (Name != "")
00118               ScCore->primaryMainWindow()->doc->Items->at(i)->setItemName(QString::fromUtf8(Name));
00119        return PyString_FromString(ScCore->primaryMainWindow()->doc->Items->at(i)->itemName().utf8());
00120 }
00121 
00122 PyObject *scribus_newline(PyObject* /* self */, PyObject* args)
00123 {
00124        double x, y, w, h;
00125        char *Name = const_cast<char*>("");
00126        if (!PyArg_ParseTuple(args, "dddd|es", &x, &y, &w, &h, "utf-8", &Name))
00127               return NULL;
00128        if(!checkHaveDocument())
00129               return NULL;
00130        x = pageUnitXToDocX(x);
00131        y = pageUnitYToDocY(y);
00132        w = pageUnitXToDocX(w);
00133        h = pageUnitYToDocY(h);
00134        if (ItemExists(QString::fromUtf8(Name)))
00135        {
00136               PyErr_SetString(NameExistsError,
00137                                           QObject::tr("An object with the requested name already exists.",
00138                                                                "python error"));
00139               return NULL;
00140        }
00141        int i = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Line, PageItem::Unspecified,
00142                                                     x, y, w, h,
00143                                                     ScCore->primaryMainWindow()->doc->toolSettings.dWidth,
00144                                                     ScCore->primaryMainWindow()->doc->toolSettings.dBrush,
00145                                                     ScCore->primaryMainWindow()->doc->toolSettings.dPen, true);
00146        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(i);
00147        it->setRotation(xy2Deg(w-x, h-y));
00148        it->setWidthHeight(sqrt(pow(x-w, 2.0) + pow(y-h, 2.0)), 1.0);
00149        it->Sizing = false;
00150        it->updateClip();
00151        ScCore->primaryMainWindow()->doc->setRedrawBounding(it);
00152 /* WTF? maybe I'll examine who's author later. Or maybe I'll remove it later ;)
00153        it->PoLine.resize(4);
00154        it->PoLine.setPoint(0, 0, 0);
00155        it->PoLine.setPoint(1, 0, 0);
00156        it->PoLine.setPoint(2, w-x, h-y);
00157        it->PoLine.setPoint(3, w-x, h-y);
00158        FPoint np2 = getMinClipF(&it->PoLine);
00159        if (np2.x() < 0)
00160        {
00161               it->PoLine.translate(-np2.x(), 0);
00162               ScCore->primaryMainWindow()->view->MoveItem(np2.x(), 0, it);
00163        }
00164        if (np2.y() < 0)
00165        {
00166               it->PoLine.translate(0, -np2.y());
00167               ScCore->primaryMainWindow()->view->MoveItem(0, np2.y(), it);
00168        }
00169        ScCore->primaryMainWindow()->view->SizeItem(it->PoLine.WidthHeight().x(),
00170                                            it->PoLine.WidthHeight().y(), i, false, false, false);
00171        ScCore->primaryMainWindow()->view->AdjustItemSize(it);*/
00172        if (Name != "")
00173               it->setItemName(QString::fromUtf8(Name));
00174        return PyString_FromString(it->itemName().utf8());
00175 }
00176 
00177 
00178 PyObject *scribus_polyline(PyObject* /* self */, PyObject* args)
00179 {
00180        char *Name = const_cast<char*>("");
00181        PyObject *il;
00182        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
00183        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
00184               return NULL;
00185        if(!checkHaveDocument())
00186               return NULL;
00187        int len = PyList_Size(il);
00188        if (len < 4)
00189        {
00190               PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least two points (four values).","python error"));
00191               return NULL;
00192        }
00193        if ((len % 2) != 0)
00194        {
00195               PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error"));
00196               return NULL;
00197        }
00198        if (ItemExists(QString::fromUtf8(Name)))
00199        {
00200               PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
00201               return NULL;
00202        }
00203        double x, y, w, h;
00204        int i = 0;
00205        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00206        i++;
00207        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00208        i++;
00209        int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1,       ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true);
00210        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
00211        it->PoLine.resize(2);
00212        it->PoLine.setPoint(0, 0, 0);
00213        it->PoLine.setPoint(1, 0, 0);
00214        int pp = 6;
00215        for (i = 2; i < len - 2; i += 2)
00216        {
00217               w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00218               h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
00219               it->PoLine.resize(pp);
00220               it->PoLine.setPoint(pp-4, w-x, h-y);
00221               it->PoLine.setPoint(pp-3, w-x, h-y);
00222               it->PoLine.setPoint(pp-2, w-x, h-y);
00223               it->PoLine.setPoint(pp-1, w-x, h-y);
00224               pp += 4;
00225        }
00226        pp -= 2;
00227        w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
00228        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
00229        it->PoLine.resize(pp);
00230        it->PoLine.setPoint(pp-2, w-x, h-y);
00231        it->PoLine.setPoint(pp-1, w-x, h-y);
00232        FPoint np2 = getMinClipF(&it->PoLine);
00233        if (np2.x() < 0)
00234        {
00235               it->PoLine.translate(-np2.x(), 0);
00236               ScCore->primaryMainWindow()->doc->MoveItem(np2.x(), 0, it);
00237        }
00238        if (np2.y() < 0)
00239        {
00240               it->PoLine.translate(0, -np2.y());
00241               ScCore->primaryMainWindow()->doc->MoveItem(0, np2.y(), it);
00242        }
00243        ScCore->primaryMainWindow()->doc->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false, false);
00244        ScCore->primaryMainWindow()->doc->AdjustItemSize(it);
00245        if (Name != "")
00246        {
00247               it->setItemName(QString::fromUtf8(Name));
00248        }
00249        return PyString_FromString(it->itemName().utf8());
00250 }
00251 
00252 
00253 PyObject *scribus_polygon(PyObject* /* self */, PyObject* args)
00254 {
00255        char *Name = const_cast<char*>("");
00256        PyObject *il;
00257        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
00258        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
00259               return NULL;
00260        if(!checkHaveDocument())
00261               return NULL;
00262        int len = PyList_Size(il);
00263        if (len < 6)
00264        {
00265               PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least three points (six values).","python error"));
00266               return NULL;
00267        }
00268        if ((len % 2) != 0)
00269        {
00270               PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain an even number of values.","python error"));
00271               return NULL;
00272        }
00273        if (ItemExists(QString::fromUtf8(Name)))
00274        {
00275               PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
00276               return NULL;
00277        }
00278        double x, y, w, h;
00279        int i = 0;
00280        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00281        i++;
00282        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00283        i++;
00284        int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::Polygon, PageItem::Unspecified, x, y, 1, 1, ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true);
00285        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
00286        it->PoLine.resize(2);
00287        it->PoLine.setPoint(0, 0, 0);
00288        it->PoLine.setPoint(1, 0, 0);
00289        int pp = 6;
00290        for (i = 2; i < len - 2; i += 2)
00291        {
00292               w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00293               h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
00294               it->PoLine.resize(pp);
00295               it->PoLine.setPoint(pp-4, w-x, h-y);
00296               it->PoLine.setPoint(pp-3, w-x, h-y);
00297               it->PoLine.setPoint(pp-2, w-x, h-y);
00298               it->PoLine.setPoint(pp-1, w-x, h-y);
00299               pp += 4;
00300        }
00301        w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-2))));
00302        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-1))));
00303        it->PoLine.resize(pp);
00304        it->PoLine.setPoint(pp-4, w-x, h-y);
00305        it->PoLine.setPoint(pp-3, w-x, h-y);
00306        it->PoLine.setPoint(pp-2, w-x, h-y);
00307        it->PoLine.setPoint(pp-1, w-x, h-y);
00308        pp += 2;
00309        it->PoLine.resize(pp);
00310        it->PoLine.setPoint(pp-2, 0, 0);
00311        it->PoLine.setPoint(pp-1, 0, 0);
00312        FPoint np2 = getMinClipF(&it->PoLine);
00313        if (np2.x() < 0)
00314        {
00315               it->PoLine.translate(-np2.x(), 0);
00316               ScCore->primaryMainWindow()->doc->MoveItem(np2.x(), 0, it);
00317        }
00318        if (np2.y() < 0)
00319        {
00320               it->PoLine.translate(0, -np2.y());
00321               ScCore->primaryMainWindow()->doc->MoveItem(0, np2.y(), it);
00322        }
00323        ScCore->primaryMainWindow()->doc->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false, false);
00324        ScCore->primaryMainWindow()->doc->AdjustItemSize(it);
00325        if (Name != "")
00326               it->setItemName(QString::fromUtf8(Name));
00327        return PyString_FromString(it->itemName().utf8());
00328 }
00329 
00330 PyObject *scribus_bezierline(PyObject* /* self */, PyObject* args)
00331 {
00332        char *Name = const_cast<char*>("");
00333        PyObject *il;
00334        // FIXME: PyList_Check failing will cause the function to return NULL w/o an exception. Separarate out the check.
00335        if ((!PyArg_ParseTuple(args, "O|es", &il, "utf-8", &Name)) || (!PyList_Check(il)))
00336               return NULL;
00337        if(!checkHaveDocument())
00338               return NULL;
00339        int len = PyList_Size(il);
00340        if (len < 8)
00341        {
00342               PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must contain at least four points (eight values).","python error"));
00343               return NULL;
00344        }
00345        if ((len % 6) != 0)
00346        {
00347               PyErr_SetString(PyExc_ValueError, QObject::tr("Point list must have a multiple of six values.","python error"));
00348               return NULL;
00349        }
00350        if (ItemExists(QString::fromUtf8(Name)))
00351        {
00352               PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
00353               return NULL;
00354        }
00355        double x, y, w, h, kx, ky, kx2, ky2;
00356        int i = 0;
00357        x = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00358        i++;
00359        y = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00360        i++;
00361        kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00362        i++;
00363        ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00364        i++;
00365        kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00366        i++;
00367        ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00368        i++;
00369        //int ic = ScCore->primaryMainWindow()->view->PaintPolyLine(x, y, 1, 1,      ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen);
00370        int ic = ScCore->primaryMainWindow()->doc->itemAdd(PageItem::PolyLine, PageItem::Unspecified, x, y, 1, 1,       ScCore->primaryMainWindow()->doc->toolSettings.dWidth, ScCore->primaryMainWindow()->doc->toolSettings.dBrush, ScCore->primaryMainWindow()->doc->toolSettings.dPen, true);
00371        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(ic);
00372        it->PoLine.resize(2);
00373        it->PoLine.setPoint(0, 0, 0);
00374        it->PoLine.setPoint(1, kx-x, ky-y);
00375        int pp = 6;
00376        for (i = 6; i < len - 6; i += 6)
00377        {
00378               w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i))));
00379               h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+1))));
00380               kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+2))));
00381               ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+3))));
00382               kx2 = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+4))));
00383               ky2 = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, i+5))));
00384               it->PoLine.resize(pp);
00385               it->PoLine.setPoint(pp-4, w-x, h-y);
00386               it->PoLine.setPoint(pp-3, kx-x, ky-y);
00387               it->PoLine.setPoint(pp-2, it->PoLine.point(pp-4));
00388               it->PoLine.setPoint(pp-1, kx2-x, ky2-y);
00389               pp += 4;
00390        }
00391        pp -= 2;
00392        w = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-6))));
00393        h = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-5))));
00394        kx = pageUnitXToDocX(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-4))));
00395        ky = pageUnitYToDocY(static_cast<double>(PyFloat_AsDouble(PyList_GetItem(il, len-3))));
00396        it->PoLine.resize(pp);
00397        it->PoLine.setPoint(pp-2, w-x, h-y);
00398        it->PoLine.setPoint(pp-1, kx-x, ky-y);
00399        FPoint np2 = getMinClipF(&it->PoLine);
00400        if (np2.x() < 0)
00401        {
00402               it->PoLine.translate(-np2.x(), 0);
00403               ScCore->primaryMainWindow()->doc->MoveItem(np2.x(), 0, it);
00404        }
00405        if (np2.y() < 0)
00406        {
00407               it->PoLine.translate(0, -np2.y());
00408               ScCore->primaryMainWindow()->doc->MoveItem(0, np2.y(), it);
00409        }
00410        ScCore->primaryMainWindow()->doc->SizeItem(it->PoLine.WidthHeight().x(), it->PoLine.WidthHeight().y(), ic, false, false, false);
00411        ScCore->primaryMainWindow()->doc->AdjustItemSize(it);
00412        if (Name != "")
00413               it->setItemName(QString::fromUtf8(Name));
00414        return PyString_FromString(it->itemName().utf8());
00415 }
00416 
00417 
00418 /* 03/31/2004 - xception handling
00419  */
00420 PyObject *scribus_pathtext(PyObject* /* self */, PyObject* args)
00421 {
00422        double x, y;
00423        char *Name = const_cast<char*>("");
00424        char *TextB = const_cast<char*>("");
00425        char *PolyB = const_cast<char*>("");
00426        if (!PyArg_ParseTuple(args, "ddeses|es", &x, &y, "utf-8", &TextB, "utf-8", &PolyB, "utf-8", &Name))
00427               return NULL;
00428        if(!checkHaveDocument())
00429               return NULL;
00430        if (ItemExists(QString::fromUtf8(Name)))
00431        {
00432               PyErr_SetString(NameExistsError, QObject::tr("An object with the requested name already exists.","python error"));
00433               return NULL;
00434        }
00435        //FIXME: Why use GetItem not GetUniqueItem? Maybe use GetUniqueItem and use the exceptions
00436        // its sets for us?
00437        int i = GetItem(QString::fromUtf8(TextB));
00438        int ii = GetItem(QString::fromUtf8(PolyB));
00439        if ((i == -1) || (ii == -1))
00440        {
00441               PyErr_SetString(NotFoundError, QObject::tr("Object not found.","python error"));
00442               return NULL;
00443        }
00444        ScCore->primaryMainWindow()->doc->m_Selection->clear();
00445        ScCore->primaryMainWindow()->doc->m_Selection->addItem(ScCore->primaryMainWindow()->doc->Items->at(i));
00446        ScCore->primaryMainWindow()->doc->m_Selection->addItem(ScCore->primaryMainWindow()->doc->Items->at(ii));
00447        PageItem *it = ScCore->primaryMainWindow()->doc->Items->at(i);
00448        ScCore->primaryMainWindow()->view->ToPathText();
00449        ScCore->primaryMainWindow()->doc->MoveItem(pageUnitXToDocX(x) - it->xPos(), pageUnitYToDocY(y) - it->yPos(), it);
00450        if (Name != "")
00451               it->setItemName(QString::fromUtf8(Name));
00452        return PyString_FromString(it->itemName().utf8());
00453 }
00454 
00455 
00456 /* 03/21/2004 - exception raised when Name doesn't exists. Doesn't crash then. (subik)
00457  */
00458 PyObject *scribus_deleteobj(PyObject* /* self */, PyObject* args)
00459 {
00460        char *Name = const_cast<char*>("");
00461        if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
00462               return NULL;
00463        if(!checkHaveDocument())
00464               return NULL;
00465        PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
00466        if (i == NULL)
00467               return NULL;
00468        ScCore->primaryMainWindow()->doc->m_Selection->clear();
00469        ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
00470        ScCore->primaryMainWindow()->doc->itemSelection_DeleteItem();
00471 //     Py_INCREF(Py_None);
00472 //     return Py_None;
00473        Py_RETURN_NONE;
00474 }
00475 
00476 
00477 /* 03/21/2004 - exception raises by non existent name (subik)
00478  */
00479 PyObject *scribus_textflow(PyObject* /* self */, PyObject* args)
00480 {
00481        char *name = const_cast<char*>("");
00482        int state = -1;
00483 
00484        if (!PyArg_ParseTuple(args, "es|i", "utf-8", &name, &state))
00485               return NULL;
00486        if(!checkHaveDocument())
00487               return NULL;
00488        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
00489        if (i == NULL)
00490               return NULL;
00491        if (state == -1)
00492        {
00493               if (i->textFlowAroundObject())
00494                      i->setTextFlowMode(PageItem::TextFlowDisabled);
00495               else
00496                      i->setTextFlowMode(PageItem::TextFlowUsesFrameShape);
00497        }
00498        else if( state == (int) PageItem::TextFlowDisabled )
00499               i->setTextFlowMode(PageItem::TextFlowDisabled);
00500        else if( state == (int) PageItem::TextFlowUsesFrameShape )
00501               i->setTextFlowMode(PageItem::TextFlowUsesFrameShape);
00502        else if( state == (int) PageItem::TextFlowUsesBoundingBox )
00503               i->setTextFlowMode(PageItem::TextFlowUsesBoundingBox);
00504        else if( state == (int) PageItem::TextFlowUsesContourLine )
00505               i->setTextFlowMode(PageItem::TextFlowUsesContourLine);
00506        ScCore->primaryMainWindow()->view->DrawNew();
00507        ScCore->primaryMainWindow()->slotDocCh(true);
00508 //     Py_INCREF(Py_None);
00509 //     return Py_None;
00510        Py_RETURN_NONE;
00511 }
00512 
00513 
00514 PyObject *scribus_objectexists(PyObject* /* self */, PyObject* args)
00515 {
00516        char* name = const_cast<char*>("");
00517        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name))
00518               return NULL;
00519        if(!checkHaveDocument())
00520               return NULL;
00521        if (ItemExists(QString::fromUtf8(name)))
00522               return PyBool_FromLong(static_cast<long>(true));
00523        return PyBool_FromLong(static_cast<long>(false));
00524 }
00525 
00526 /*
00527  * Craig Ringer, 2004-09-09
00528  * Apply the named style to the currently selected object.
00529  * pv, 2004-09-13, optionaly param objectName + "check the page" stuff
00530  */
00531 PyObject *scribus_setstyle(PyObject* /* self */, PyObject* args)
00532 {
00533        char *style = const_cast<char*>("");
00534        char *name = const_cast<char*>("");
00535        if (!PyArg_ParseTuple(args, "es|es", "utf-8", &style, "utf-8", &name))
00536               return NULL;
00537        if(!checkHaveDocument())
00538               return NULL;
00539        PageItem *item = GetUniqueItem(QString::fromUtf8(name));
00540        if (item == NULL)
00541               return NULL;
00542        if ((item->itemType() == PageItem::TextFrame) || (item->itemType() == PageItem::PathText))
00543        {
00544               // First, find the style number associated with the requested style
00545               // by scanning through the styles looking for the name. If
00546               // we can't find it, raise PyExc_Exception.
00547               // FIXME: Should use a more specific exception.
00548               bool found = false;
00549               uint styleid = 0;
00550               // We start at zero here because it's OK to match an internal name
00551               uint docParagraphStylesCount=ScCore->primaryMainWindow()->doc->paragraphStyles().count();
00552               for (uint i=0; i < docParagraphStylesCount; ++i)
00553               {
00554                      if (ScCore->primaryMainWindow()->doc->paragraphStyles()[i].name() == QString::fromUtf8(style)) {
00555                             found = true;
00556                             styleid = i;
00557                             break;
00558                      }
00559               }
00560               if (!found) {
00561                      // whoops, the user specified an invalid style, complain loudly.
00562                      PyErr_SetString(NotFoundError, QObject::tr("Style not found.","python error"));
00563                      return NULL;
00564               }
00565               // for current item only
00566               if (ScCore->primaryMainWindow()->doc->m_Selection->count() == 0 || name != "")
00567               {
00568                      // quick hack to always apply on the right frame - pv
00569                      ScCore->primaryMainWindow()->view->Deselect(true);
00570                      //CB I dont think we need to draw here. Its faster if we dont.
00571                      ScCore->primaryMainWindow()->view->SelectItem(item, false);
00572                      // Now apply the style.
00573                      int mode = ScCore->primaryMainWindow()->doc->appMode;
00574                      ScCore->primaryMainWindow()->doc->appMode = modeEdit;
00575                      ScCore->primaryMainWindow()->setNewParStyle(QString::fromUtf8(style));
00576                      ScCore->primaryMainWindow()->doc->appMode = mode;
00577               }
00578               else // for multiple selection
00579               {
00580                      int mode = ScCore->primaryMainWindow()->doc->appMode;
00581                      ScCore->primaryMainWindow()->doc->appMode = modeNormal;
00582                      ScCore->primaryMainWindow()->doc->itemSelection_ApplyParagraphStyle(ScCore->primaryMainWindow()->doc->paragraphStyles()[styleid]);
00583                      ScCore->primaryMainWindow()->doc->appMode = mode;
00584               }
00585        }
00586        else
00587        {
00588               PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set style on a non-text frame.","python error"));
00589               return NULL;
00590        }
00591 //     Py_INCREF(Py_None);
00592 //     return Py_None;
00593        Py_RETURN_NONE;
00594 }
00595 
00596 /*
00597  * Craig Ringer, 2004-09-09
00598  * Enumerate all known paragraph styles
00599  */
00600 PyObject *scribus_getstylenames(PyObject* /* self */)
00601 {
00602        PyObject *styleList;
00603        if(!checkHaveDocument())
00604               return NULL;
00605        styleList = PyList_New(0);
00606        for (uint i=0; i < ScCore->primaryMainWindow()->doc->paragraphStyles().count(); ++i)
00607        {
00608               if (PyList_Append(styleList, PyString_FromString(ScCore->primaryMainWindow()->doc->paragraphStyles()[i].name().utf8())))
00609               {
00610                      // An exception will have already been set by PyList_Append apparently.
00611                      return NULL;
00612               }
00613        }
00614        return styleList;
00615 }
00616 
00617 PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args)
00618 {
00619        char* name = const_cast<char*>("");
00620        if (!PyArg_ParseTuple(args, "|es", "utf-8", &name)) {
00621               return NULL;
00622        }
00623        if(!checkHaveDocument()) {
00624               return NULL;
00625        }
00626        // Is there a special name given? Yes -> add this to selection
00627        PageItem *i = GetUniqueItem(QString::fromUtf8(name));
00628        if (i != NULL) {
00629               ScCore->primaryMainWindow()->doc->m_Selection->clear();
00630               ScCore->primaryMainWindow()->doc->m_Selection->addItem(i);
00631        }
00632        else
00633               return NULL;
00634        // do the duplicate
00635        ScCore->primaryMainWindow()->slotEditCopy();
00636        ScCore->primaryMainWindow()->slotEditPaste();
00637 //     Py_INCREF(Py_None);
00638 //     return Py_None;
00639        Py_RETURN_NONE;
00640 }
00641 
00645 void cmdobjdocwarnings()
00646 {
00647     QStringList s;
00648     s << scribus_newrect__doc__ <<scribus_newellipse__doc__ << scribus_newimage__doc__ << scribus_newtext__doc__ << scribus_newline__doc__ <<scribus_polyline__doc__ << scribus_polygon__doc__ << scribus_bezierline__doc__ <<scribus_pathtext__doc__ <<scribus_deleteobj__doc__ <<scribus_textflow__doc__ <<scribus_objectexists__doc__ <<scribus_setstyle__doc__ <<scribus_getstylenames__doc__ <<scribus_duplicateobject__doc__;
00649 }