X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Ffiginset.C;h=9bf32f5e6b47ba5a17f68a63a033ffbcb43e9815;hb=4a5b7a5952ad2381fcdf4830511293e184c7c5a1;hp=fa11c2a78dbe4e039ec13adeb7692c3cd72e6ef4;hpb=76ef051b1cb1fb51c3ffd8ccc9105be4471e74d4;p=lyx.git diff --git a/src/insets/figinset.C b/src/insets/figinset.C index fa11c2a78d..9bf32f5e6b 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -28,44 +28,47 @@ #include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include FORMS_H_LOCATION -#include -#include -#include - #include "figinset.h" + #include "lyx_main.h" #include "buffer.h" -#include "frontends/FileDialog.h" -#include "support/filetools.h" #include "LyXView.h" // just because of form_main #include "debug.h" #include "LaTeXFeatures.h" #include "lyxrc.h" #include "gettext.h" #include "lyx_gui_misc.h" // CancelCloseBoxCB -#include "support/FileInfo.h" -#include "support/lyxlib.h" -#include "support/os.h" #include "Painter.h" #include "font.h" #include "bufferview_funcs.h" #include "ColorHandler.h" #include "converter.h" -#include "frontends/Dialogs.h" // redrawGUI #include "BufferView.h" +#include "frontends/FileDialog.h" +#include "frontends/Alert.h" +#include "frontends/Dialogs.h" // redrawGUI + +#include "support/FileInfo.h" +#include "support/lyxlib.h" +#include "support/os.h" +#include "support/filetools.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + using std::ostream; using std::istream; using std::ofstream; @@ -76,10 +79,11 @@ using std::vector; using std::find; using std::flush; using std::endl; -using std::ostringstream; using std::copy; using std::pair; using std::make_pair; +using std::ios; +using std::ostream_iterator; #ifndef CXX_GLOBAL_CSTD using std::memcpy; @@ -156,7 +160,7 @@ void addpidwait(int pid) if (lyxerr.debugging()) { lyxerr << "Pids to wait for: \n"; copy(pidwaitlist.begin(), pidwaitlist.end(), - std::ostream_iterator(lyxerr, "\n")); + ostream_iterator(lyxerr, "\n")); lyxerr << flush; } } @@ -177,7 +181,9 @@ void kill_gs(int pid, int sig) } -extern "C" +extern "C" { + +static int GhostscriptMsg(XEvent * ev, void *) { // bin all events not of interest @@ -313,6 +319,8 @@ int GhostscriptMsg(XEvent * ev, void *) return FL_PREEMPT; } +} + void AllocColors(int num) // allocate color cube numxnumxnum, if possible @@ -388,6 +396,7 @@ void AllocGrays(int num) gs_color = true; } + void InitFigures() { // if bitmaps and figures are not empty we will leak mem @@ -412,10 +421,10 @@ void InitFigures() vi->visualid, vi->c_class, vi->bits_per_rgb, vi->map_entries); } - color_visual = ( (vi->c_class == StaticColor) || + color_visual = ((vi->c_class == StaticColor) || (vi->c_class == PseudoColor) || (vi->c_class == TrueColor) || - (vi->c_class == DirectColor) ); + (vi->c_class == DirectColor)); if ((vi->c_class & 1) == 0) return; // now allocate colors if (vi->c_class == GrayScale) { @@ -464,7 +473,7 @@ void runqueue() { // This _have_ to be set before the fork! unsigned long background_pixel = - lyxColorHandler->colorPixel(LColor::background); + lyxColorHandler->colorPixel(LColor::graphicsbg); // run queued requests for ghostscript, if any if (!gsrunning && gs_color && !gs_xcolor) { @@ -511,7 +520,7 @@ void runqueue() // create translation file ofstream ofs; - ofs.open(make_tmp(getpid()).c_str()); + ofs.open(make_tmp(getpid()).c_str(), ios::binary); ofs << "gsave clippath pathbbox grestore\n" << "4 dict begin\n" << "/ury exch def /urx exch def /lly exch def " @@ -640,7 +649,7 @@ void runqueue() env = new char_p[ne + 2]; string tmp = t2.str().c_str(); env[0] = new char[tmp.size() + 1]; - std::copy(tmp.begin(), tmp.end(), env[0]); + copy(tmp.begin(), tmp.end(), env[0]); env[0][tmp.size()] = '\0'; memcpy(&env[1], environ, sizeof(char*) * (ne + 1)); @@ -898,7 +907,7 @@ void RegisterFigure(InsetFig * fi) figures.push_back(tmpfig); fi->figure = tmpfig; - if (lyxerr.debugging()) { + if (lyxerr.debugging() && current_view) { lyxerr << "Register Figure: buffer:[" << current_view->buffer() << "]" << endl; } @@ -1050,9 +1059,9 @@ void InsetFig::draw(BufferView * bv, LyXFont const & f, } -void InsetFig::Write(Buffer const *, ostream & os) const +void InsetFig::write(Buffer const *, ostream & os) const { - Regenerate(); + regenerate(); os << "Figure size " << wid << " " << hgh << "\n"; if (!fname.empty()) { string buf1 = OnlyPath(owner->fileName()); @@ -1069,15 +1078,15 @@ void InsetFig::Write(Buffer const *, ostream & os) const } -void InsetFig::Read(Buffer const *, LyXLex & lex) +void InsetFig::read(Buffer const *, LyXLex & lex) { string buf; bool finished = false; - while (lex.IsOK() && !finished) { + while (lex.isOK() && !finished) { lex.next(); - string const token = lex.GetString(); + string const token = lex.getString(); lyxerr[Debug::INFO] << "Token: " << token << endl; if (token.empty()) @@ -1086,8 +1095,8 @@ void InsetFig::Read(Buffer const *, LyXLex & lex) finished = true; } else if (token == "file") { if (lex.next()) { - buf = lex.GetString(); - string buf1 = OnlyPath(owner->fileName()); + buf = lex.getString(); + string const buf1(OnlyPath(owner->fileName())); fname = MakeAbsPath(buf, buf1); changedfname = true; } @@ -1095,30 +1104,30 @@ void InsetFig::Read(Buffer const *, LyXLex & lex) if (lex.next()); // kept for backwards compability. Delete in 0.13.x } else if (token == "subcaption") { - if (lex.EatLine()) - subcaption = lex.GetString(); + if (lex.eatLine()) + subcaption = lex.getString(); } else if (token == "label") { if (lex.next()); // kept for backwards compability. Delete in 0.13.x } else if (token == "angle") { if (lex.next()) - angle = lex.GetFloat(); + angle = lex.getFloat(); } else if (token == "size") { if (lex.next()) - wid = lex.GetInteger(); + wid = lex.getInteger(); if (lex.next()) - hgh = lex.GetInteger(); + hgh = lex.getInteger(); } else if (token == "flags") { if (lex.next()) - flags = pflags = lex.GetInteger(); + flags = pflags = lex.getInteger(); } else if (token == "subfigure") { subfigure = psubfigure = true; } else if (token == "width") { int typ = 0; if (lex.next()) - typ = lex.GetInteger(); + typ = lex.getInteger(); if (lex.next()) - xwid = lex.GetFloat(); + xwid = lex.getFloat(); switch (typ) { case DEF: wtype = DEF; break; case CM: wtype = CM; break; @@ -1133,9 +1142,9 @@ void InsetFig::Read(Buffer const *, LyXLex & lex) } else if (token == "height") { int typ = 0; if (lex.next()) - typ = lex.GetInteger(); + typ = lex.getInteger(); if (lex.next()) - xhgh = lex.GetFloat(); + xhgh = lex.getFloat(); switch (typ) { case DEF: htype = DEF; break; case CM: htype = CM; break; @@ -1148,80 +1157,75 @@ void InsetFig::Read(Buffer const *, LyXLex & lex) thtype = htype; } } - Regenerate(); - Recompute(); + regenerate(); + recompute(); } -int InsetFig::Latex(Buffer const *, ostream & os, +int InsetFig::latex(Buffer const *, ostream & os, bool /* fragile*/, bool /* fs*/) const { - Regenerate(); + regenerate(); if (!cmd.empty()) os << cmd << " "; return 0; } -int InsetFig::Ascii(Buffer const *, ostream &, int) const +int InsetFig::ascii(Buffer const *, ostream &, int) const { return 0; } -int InsetFig::Linuxdoc(Buffer const *, ostream &) const +int InsetFig::linuxdoc(Buffer const *, ostream &) const { return 0; } -int InsetFig::DocBook(Buffer const *, ostream & os) const +int InsetFig::docbook(Buffer const *, ostream & os) const { - string buf1 = OnlyPath(owner->fileName()); + string const buf1 = OnlyPath(owner->fileName()); string figurename = MakeRelPath(fname, buf1); if (suffixIs(figurename, ".eps")) figurename.erase(figurename.length() - 4); - os << "@"; + os << ""; return 0; } -void InsetFig::Validate(LaTeXFeatures & features) const +void InsetFig::validate(LaTeXFeatures & features) const { - features.graphics = true; - if (subfigure) features.subfigure = true; + features.require("graphics"); + if (subfigure) + features.require("subfigure"); } -Inset::EDITABLE InsetFig::Editable() const +Inset::EDITABLE InsetFig::editable() const { return IS_EDITABLE; } -bool InsetFig::Deletable() const +bool InsetFig::deletable() const { return false; } -string const InsetFig::EditMessage() const +string const InsetFig::editMessage() const { return _("Opened figure"); } -void InsetFig::Edit(BufferView * bv, int, int, unsigned int) +void InsetFig::edit(BufferView *, int, int, unsigned int) { lyxerr[Debug::INFO] << "Editing InsetFig." << endl; - Regenerate(); - - // We should have RO-versions of the form instead. - // The actual prevention of altering a readonly doc - // is done in CallbackFig() - if (bv->buffer()->isReadonly()) - WarnReadonly(bv->buffer()->fileName()); + regenerate(); if (!form) { form = create_form_Figure(); @@ -1230,7 +1234,7 @@ void InsetFig::Edit(BufferView * bv, int, int, unsigned int) fl_set_object_return(form->Width, FL_RETURN_ALWAYS); fl_set_object_return(form->Height, FL_RETURN_ALWAYS); } - RestoreForm(); + restoreForm(); if (form->Figure->visible) { fl_raise_form(form->Figure); } else { @@ -1241,7 +1245,13 @@ void InsetFig::Edit(BufferView * bv, int, int, unsigned int) } -Inset * InsetFig::Clone(Buffer const & buffer) const +void InsetFig::edit(BufferView * bv, bool) +{ + edit(bv, 0, 0, 0); +} + + +Inset * InsetFig::clone(Buffer const & buffer, bool) const { InsetFig * tmp = new InsetFig(100, 100, buffer); @@ -1284,12 +1294,12 @@ Inset * InsetFig::Clone(Buffer const & buffer) const tmp->subcaption = subcaption; tmp->changedfname = false; tmp->owner = owner; - tmp->Regenerate(); + tmp->regenerate(); return tmp; } -Inset::Code InsetFig::LyxCode() const +Inset::Code InsetFig::lyxCode() const { return Inset::GRAPHICS_CODE; } @@ -1323,11 +1333,13 @@ string const stringify(InsetFig::HWTYPE hw, float f, string suffix) } // namespace anon -void InsetFig::Regenerate() const +void InsetFig::regenerate() const { string cmdbuf; - string resizeW, resizeH; - string rotate, recmd; + string resizeW; + string resizeH; + string rotate; + string recmd; if (fname.empty()) { cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}"; @@ -1380,11 +1392,13 @@ void InsetFig::Regenerate() const } -void InsetFig::TempRegenerate() +void InsetFig::tempRegenerate() { string cmdbuf; - string resizeW, resizeH; - string rotate, recmd; + string resizeW; + string resizeH; + string rotate; + string recmd; char const * tfname = fl_get_input(form->EpsFile); string tsubcap = fl_get_input(form->Subcaption); @@ -1437,7 +1451,7 @@ void InsetFig::TempRegenerate() } -void InsetFig::Recompute() +void InsetFig::recompute() { if (!lyxrc.use_gui) return; @@ -1445,7 +1459,7 @@ void InsetFig::Recompute() bool changed = changedfname; int newx, newy, nraw_x, nraw_y; - if (changed) GetPSSizes(); + if (changed) getPSSizes(); float sin_a = sin(angle / DEG2PI); /* rotation; H. Zeller 021296 */ float cos_a = cos(angle / DEG2PI); @@ -1556,7 +1570,7 @@ void InsetFig::Recompute() } -void InsetFig::GetPSSizes() +void InsetFig::getPSSizes() { /* get %%BoundingBox: from postscript file */ @@ -1622,7 +1636,7 @@ void InsetFig::GetPSSizes() } -void InsetFig::CallbackFig(long arg) +void InsetFig::callbackFig(long arg) { bool regen = false; char const * p; @@ -1725,12 +1739,12 @@ void InsetFig::CallbackFig(long arg) regen = true; /* regenerate command */ break; case 0: /* browse file */ - BrowseFile(); + browseFile(); regen = true; break; case 1: /* preview */ p = fl_get_input(form->EpsFile); - Preview(p); + preview(p); break; case 7: /* apply */ case 8: /* ok (apply and close) */ @@ -1753,8 +1767,8 @@ void InsetFig::CallbackFig(long arg) } subcaption = fl_get_input(form->Subcaption); - Regenerate(); - Recompute(); + regenerate(); + recompute(); /* now update inset */ if (lyxerr.debugging()) { lyxerr << "Update: [" @@ -1792,7 +1806,7 @@ void InsetFig::CallbackFig(long arg) break; } - if (regen) TempRegenerate(); + if (regen) tempRegenerate(); } @@ -1870,7 +1884,7 @@ void EnableFigurePanel(FD_Figure * const form) } -void InsetFig::RestoreForm() +void InsetFig::restoreForm() { EnableFigurePanel(form); @@ -1912,7 +1926,7 @@ void InsetFig::RestoreForm() fl_set_input(form->Width, tostr(xwid).c_str()); fl_set_input(form->Height, tostr(xhgh).c_str()); fl_set_input(form->Angle, tostr(angle).c_str()); - if (!fname.empty()){ + if (!fname.empty()) { string buf1 = OnlyPath(owner->fileName()); string fname2 = MakeRelPath(fname, buf1); fl_set_input(form->EpsFile, fname2.c_str()); @@ -1922,23 +1936,23 @@ void InsetFig::RestoreForm() if (current_view->buffer()->isReadonly()) DisableFigurePanel(form); - TempRegenerate(); + tempRegenerate(); } -void InsetFig::Preview(string const & p) +void InsetFig::preview(string const & p) { string tfname = p; if (GetExtension(tfname).empty()) tfname += ".eps"; string buf1 = OnlyPath(owner->fileName()); string buf2 = os::external_path(MakeAbsPath(tfname, buf1)); - if (!formats.View(owner, buf2, "eps")) + if (!formats.view(owner, buf2, "eps")) lyxerr << "Can't view " << buf2 << endl; } -void InsetFig::BrowseFile() +void InsetFig::browseFile() { static string current_figure_path; static int once; @@ -1968,8 +1982,8 @@ void InsetFig::BrowseFile() FileDialog fileDlg(current_view->owner(), _("Select an EPS figure"), LFUN_SELECT_FILE_SYNC, - make_pair(string(_("Clip art")), string(bufclip)), - make_pair(string(_("Documents")), string(buf))); + make_pair(string(_("Clip art|#C#c")), string(bufclip)), + make_pair(string(_("Documents|#o#O")), string(buf))); bool error = false; do { @@ -1988,7 +2002,7 @@ void InsetFig::BrowseFile() if (contains(p, "#") || contains(p, "~") || contains(p, "$") || contains(p, "%") || contains(p, " ")) { - WriteAlert(_("Filename can't contain any " + Alert::alert(_("Filename can't contain any " "of these characters:"), // xgettext:no-c-format _("space, '#', '~', '$' or '%'.")); @@ -2017,7 +2031,7 @@ void GraphicsCB(FL_OBJECT * obj, long arg) lyxerr << "Calling back figure " << (*it) << endl; } - (*it)->inset->CallbackFig(arg); + (*it)->inset->callbackFig(arg); return; } } @@ -2033,6 +2047,6 @@ void HideFiguresPopups() lyxerr << "Hiding figure " << (*it) << endl; } // hide and free the form - (*it)->inset->CallbackFig(9); + (*it)->inset->callbackFig(9); } }