#include <config.h>
-#include <fstream>
-#include <queue>
-#include <list>
-#include <algorithm>
-#include <vector>
-
-#include <unistd.h>
-#include <csignal>
-#include <sys/wait.h>
-
-#include FORMS_H_LOCATION
-#include <cstdlib>
-#include <cctype>
-#include <cmath>
-
#include "figinset.h"
-#include "lyx.h"
+
#include "lyx_main.h"
#include "buffer.h"
-#include "filedlg.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 "Painter.h"
#include "font.h"
#include "bufferview_funcs.h"
#include "ColorHandler.h"
+#include "converter.h"
+#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 <fstream>
+#include <queue>
+#include <list>
+#include <algorithm>
+#include <vector>
+#include <utility>
+
+#include <unistd.h>
+#include <csignal>
+#include <sys/wait.h>
+#include <cstdlib>
+#include <cctype>
+#include <cmath>
+#include <cerrno>
using std::ostream;
using std::istream;
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;
+using std::sin;
+using std::cos;
+using std::fabs;
+#endif
+
+
extern BufferView * current_view;
extern FL_OBJECT * figinset_canvas;
extern char ** environ; // is this only redundtant on linux systems? Lgb.
-static float const DEG2PI = 57.295779513;
+// xforms doesn't define this (but it should be in <forms.h>).
+extern "C"
+FL_APPEVENT_CB fl_set_preemptive_callback(Window, FL_APPEVENT_CB, void *);
+
+namespace {
+
+float const DEG2PI = 57.295779513;
struct queue_element {
float rx, ry; // resolution x and y
figdata * data; // we are doing it for this data
};
-static int const MAXGS = 3; /* maximum 3 gs's at a time */
+int const MAXGS = 3; /* maximum 3 gs's at a time */
typedef vector<Figref *> figures_type;
typedef vector<figdata *> bitmaps_type;
-static figures_type figures; // all figures
-static bitmaps_type bitmaps; // all bitmaps
+figures_type figures; // all figures
+bitmaps_type bitmaps; // all bitmaps
-static queue<queue_element> gsqueue; // queue for ghostscripting
+queue<queue_element> gsqueue; // queue for ghostscripting
-static int gsrunning = 0; /* currently so many gs's are running */
-static bool bitmap_waiting = false; /* bitmaps are waiting finished */
+int gsrunning = 0; /* currently so many gs's are running */
+bool bitmap_waiting = false; /* bitmaps are waiting finished */
-static bool gs_color; // do we allocate colors for gs?
-static bool color_visual; // is the visual color?
-static bool gs_xcolor = false; // allocated extended colors
-static unsigned long gs_pixels[128]; // allocated pixels
-static int gs_spc; // shades per color
-static int gs_allcolors; // number of all colors
+bool gs_color; // do we allocate colors for gs?
+bool color_visual; // is the visual color?
+bool gs_xcolor = false; // allocated extended colors
+unsigned long gs_pixels[128]; // allocated pixels
+int gs_spc; // shades per color
+int gs_allcolors; // number of all colors
-static list<int> pidwaitlist; // pid wait list
+list<int> pidwaitlist; // pid wait list
-static
GC createGC()
{
XGCValues val;
- val.foreground = BlackPixel(fl_display,
- DefaultScreen(fl_display));
+ val.foreground = BlackPixel(fl_get_display(),
+ DefaultScreen(fl_get_display()));
val.function=GXcopy;
val.graphics_exposures = false;
val.line_style = LineSolid;
val.line_width = 0;
- return XCreateGC(fl_display, RootWindow(fl_display, 0),
+ return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
GCForeground | GCFunction | GCGraphicsExposures
| GCLineWidth | GCLineStyle , &val);
}
-static
GC local_gc_copy;
-static
void addpidwait(int pid)
{
// adds pid to pid wait list
if (lyxerr.debugging()) {
lyxerr << "Pids to wait for: \n";
- for (list<int>::const_iterator cit = pidwaitlist.begin();
- cit != pidwaitlist.end(); ++cit) {
- lyxerr << (*cit) << '\n';
- }
+ copy(pidwaitlist.begin(), pidwaitlist.end(),
+ ostream_iterator<int>(lyxerr, "\n"));
lyxerr << flush;
}
}
-static
string make_tmp(int pid)
{
return system_tempdir + "/~lyxgs" + tostr(pid) + ".ps";
}
-static
void kill_gs(int pid, int sig)
{
if (lyxerr.debugging())
}
-extern "C" // static
-int GhostscriptMsg(FL_OBJECT *, Window, int, int,
- XEvent * ev, void *)
+extern "C" {
+
+static
+int GhostscriptMsg(XEvent * ev, void *)
{
+ // bin all events not of interest
+ if (ev->type != ClientMessage)
+ return FL_PREEMPT;
+
XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
- if(lyxerr.debugging()) {
+ if (lyxerr.debugging()) {
lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
<< "] pm:[" << e->data.l[1] << "]" << endl;
}
Display * tmpdisp;
GC gc = local_gc_copy;
- XGetWindowAttributes(fl_display,
+ XGetWindowAttributes(fl_get_display(),
fl_get_canvas_id(
figinset_canvas),
&wa);
- XFlush(fl_display);
+ XFlush(fl_get_display());
if (lyxerr.debugging()) {
lyxerr << "Starting image translation "
<< p->bitmap << " "
// now fork rendering process
forkstat = fork();
if (forkstat == -1) {
- lyxerr.debug()
+ lyxerr[Debug::INFO]
<< "Cannot fork, using slow "
"method for pixmap translation." << endl;
- tmpdisp = fl_display;
+ tmpdisp = fl_get_display();
} else if (forkstat > 0) { // parent
// register child
if (lyxerr.debugging()) {
addpidwait(forkstat);
break;
} else { // child
- tmpdisp = XOpenDisplay(XDisplayName(0));
+ tmpdisp = XOpenDisplay(DisplayString(fl_get_display()));
XFlush(tmpdisp);
}
im = XGetImage(tmpdisp, p->bitmap, 0, 0,
}
break;
}
- return 0;
+ return FL_PREEMPT;
+}
+
}
-static
void AllocColors(int num)
// allocate color cube numxnumxnum, if possible
{
xcol.green = short(65535 * ((i / num) % num) / (num - 1));
xcol.blue = short(65535 * (i % num) / (num - 1));
xcol.flags = DoRed | DoGreen | DoBlue;
- if (!XAllocColor(fl_display,
+ if (!XAllocColor(fl_get_display(),
fl_state[fl_get_vclass()].colormap, &xcol)) {
- if (i) XFreeColors(fl_display,
+ if (i) XFreeColors(fl_get_display(),
fl_state[fl_get_vclass()].colormap,
gs_pixels, i, 0);
- if(lyxerr.debugging()) {
+ if (lyxerr.debugging()) {
lyxerr << "Cannot allocate color cube "
<< num << endl;;
}
// allocate grayscale ramp
-static
void AllocGrays(int num)
{
if (lyxerr.debugging()) {
if (num > 128) num = 128;
XColor xcol;
for (int i = 0; i < num; ++i) {
- xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
+ xcol.red = xcol.green = xcol.blue = short(65535 * i / (num - 1));
xcol.flags = DoRed | DoGreen | DoBlue;
- if (!XAllocColor(fl_display,
+ if (!XAllocColor(fl_get_display(),
fl_state[fl_get_vclass()].colormap, &xcol)) {
- if (i) XFreeColors(fl_display,
+ if (i) XFreeColors(fl_get_display(),
fl_state[fl_get_vclass()].colormap,
gs_pixels, i, 0);
if (lyxerr.debugging()) {
}
-static
void InitFigures()
{
// if bitmaps and figures are not empty we will leak mem
figures.clear();
bitmaps.clear();
- unsigned int k;
- for (unsigned int i = 0; i < 256; ++i) {
- k = 0;
- for (unsigned int j = 0; j < 8; ++j)
- if (i & (1 << (7-j))) k |= 1 << j;
- }
-
// allocate color cube on pseudo-color display
// first get visual
gs_color = false;
if (lyxrc.use_gui) {
- fl_add_canvas_handler(figinset_canvas, ClientMessage,
- GhostscriptMsg,
- current_view->owner()->getForm());
+ /* we want to capture every event, in order to work around an
+ * xforms bug.
+ */
+ fl_set_preemptive_callback(fl_get_canvas_id(figinset_canvas), GhostscriptMsg, 0);
local_gc_copy = createGC();
- Visual * vi = DefaultVisual(fl_display,
- DefaultScreen(fl_display));
+ Visual * vi = DefaultVisual(fl_get_display(),
+ DefaultScreen(fl_get_display()));
if (lyxerr.debugging()) {
printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
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) {
}
-static
void DoneFigures()
{
// if bitmaps and figures are not empty we will leak mem
bitmaps.clear();
figures.clear();
- lyxerr.debug() << "Unregistering figures..." << endl;
-
- fl_remove_canvas_handler(figinset_canvas, ClientMessage,
- GhostscriptMsg);
+ lyxerr[Debug::INFO] << "Unregistering figures..." << endl;
}
-static
void freefigdata(figdata * tmpdata)
{
tmpdata->ref--;
kill_gs(pid, SIGKILL);
}
- if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
+ if (tmpdata->bitmap) XFreePixmap(fl_get_display(), tmpdata->bitmap);
bitmaps.erase(find(bitmaps.begin(), bitmaps.end(), tmpdata));
delete tmpdata;
}
-static
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) {
if (pid == 0) { // child
char ** env;
int ne = 0;
- Display * tempdisp = XOpenDisplay(XDisplayName(0));
+ Display * tempdisp = XOpenDisplay(DisplayString(fl_get_display()));
// 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 "
t2 << "GHOSTVIEW=" << fl_get_canvas_id(figinset_canvas)
<< ' ' << p->data->bitmap;
// now set up ghostview property on a window
+ // #ifdef WITH_WARNINGS
// #warning BUG seems that the only bug here
// might be the hardcoded dpi.. Bummer!
+ // #endif
ostringstream t1;
t1 << "0 0 0 0 " << p->data->wid << ' '
<< p->data->hgh << " 72 72 0 0 0 0";
for (i = 0; i < nprop; ++i) {
char * p = XGetAtomName(tempdisp,
prop[i]);
- if (strcmp(p, "GHOSTVIEW") == 0) {
+ if (compare(p, "GHOSTVIEW") == 0) {
err = false;
// We free it when we leave so we don't leak.
XFree(p);
XInternAtom(tempdisp, "STRING", false),
8, PropModeAppend,
reinterpret_cast<unsigned char*>(const_cast<char*>(t1.str().c_str())),
- t1.str().size());
+ int(t1.str().size()));
XUngrabServer(tempdisp);
XFlush(tempdisp);
XInternAtom(tempdisp, "STRING", false),
8, PropModeReplace,
reinterpret_cast<unsigned char*>(const_cast<char*>(t3.str().c_str())),
- t3.str().size());
+ int(t3.str().size()));
XUngrabServer(tempdisp);
XFlush(tempdisp);
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));
+ memcpy(&env[1], environ,
+ sizeof(char*) * (ne + 1));
environ = env;
// now make gs command
// if we are still there, an error occurred.
lyxerr << "Error executing ghostscript. "
<< "Code: " << err << endl;
- lyxerr.debug() << "Cmd: "
+ lyxerr[Debug::INFO] << "Cmd: "
<< lyxrc.ps_command
<< " -sDEVICE=x11 "
<< tmpf << ' '
}
-static
void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
{
// recompute the stuff and put in the queue
}
-static
figdata * getfigdata(int wid, int hgh, string const & fname,
int psx, int psy, int pswid, int pshgh,
int raw_wid, int raw_hgh, float angle, char flags)
p->flags = flags;
bitmaps.push_back(p);
XWindowAttributes wa;
- XGetWindowAttributes(fl_display, fl_get_canvas_id(
+ XGetWindowAttributes(fl_get_display(), fl_get_canvas_id(
figinset_canvas), &wa);
if (lyxerr.debugging()) {
- lyxerr << "Create pixmap disp:" << fl_display
- << " scr:" << DefaultScreen(fl_display)
+ lyxerr << "Create pixmap disp:" << fl_get_display()
+ << " scr:" << DefaultScreen(fl_get_display())
<< " w:" << wid
<< " h:" << hgh
<< " depth:" << wa.depth << endl;
p->broken = false;
p->gspid = -1;
if (flags) {
- p->bitmap = XCreatePixmap(fl_display, fl_get_canvas_id(
+ p->bitmap = XCreatePixmap(fl_get_display(), fl_get_canvas_id(
figinset_canvas), wid, hgh, wa.depth);
p->gsdone = false;
// initialize reading of .eps file with correct sizes and stuff
}
-static
void getbitmap(figdata * p)
{
p->gspid = -1;
}
-static
void makeupdatelist(figdata * p)
{
- for(figures_type::iterator it = figures.begin();
+ for (figures_type::iterator it = figures.begin();
it != figures.end(); ++it)
if ((*it)->data == p) {
if (lyxerr.debugging()) {
}
}
+} // namespace anon
+
// this func is only "called" in spellchecker.C
void sigchldchecker(pid_t pid, int * status)
{
- lyxerr.debug() << "Got pid = " << pid << endl;
+ lyxerr[Debug::INFO] << "Got pid = " << pid << endl;
bool pid_handled = false;
for (bitmaps_type::iterator it = bitmaps.begin();
it != bitmaps.end(); ++it) {
if ((*it)->reading && pid == (*it)->gspid) {
- lyxerr.debug() << "Found pid in bitmaps" << endl;
+ lyxerr[Debug::INFO] << "Found pid in bitmaps" << endl;
// now read the file and remove it from disk
figdata * p = (*it);
p->reading = false;
if ((*it)->gsdone) *status = 0;
if (*status == 0) {
- lyxerr.debug() << "GS [" << pid
+ lyxerr[Debug::INFO] << "GS [" << pid
<< "] exit OK." << endl;
} else {
lyxerr << "GS [" << pid << "] error "
}
}
if (!pid_handled) {
- lyxerr.debug() << "Checking pid in pidwait" << endl;
+ lyxerr[Debug::INFO] << "Checking pid in pidwait" << endl;
list<int>::iterator it = find(pidwaitlist.begin(),
pidwaitlist.end(), pid);
if (it != pidwaitlist.end()) {
- lyxerr.debug() << "Found pid in pidwait\n"
+ lyxerr[Debug::INFO] << "Found pid in pidwait\n"
<< "Caught child pid of recompute "
"routine" << pid << endl;
pidwaitlist.erase(it);
}
}
if (pid == -1) {
- lyxerr.debug() << "waitpid error" << endl;
+ lyxerr[Debug::INFO] << "waitpid error" << endl;
switch (errno) {
case ECHILD:
lyxerr << "The process or process group specified by "
} else if (pid == 0) {
lyxerr << "waitpid nohang" << endl;;
} else {
- lyxerr.debug() << "normal exit from childhandler" << endl;
+ lyxerr[Debug::INFO] << "normal exit from childhandler" << endl;
}
}
-static
+namespace {
+
void getbitmaps()
{
bitmap_waiting = false;
}
-static
void RegisterFigure(InsetFig * fi)
{
if (figures.empty()) InitFigures();
figures.push_back(tmpfig);
fi->figure = tmpfig;
- if (lyxerr.debugging()) {
+ if (lyxerr.debugging() && current_view) {
lyxerr << "Register Figure: buffer:["
<< current_view->buffer() << "]" << endl;
}
}
-static
void UnregisterFigure(InsetFig * fi)
{
+ if (!lyxrc.use_gui)
+ return;
+
Figref * tmpfig = fi->figure;
if (tmpfig->data) freefigdata(tmpfig->data);
if (figures.empty()) DoneFigures();
}
+} // namespace anon
-InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
- : owner(o)
+
+InsetFig::InsetFig(int tmpx, int tmpy, Buffer const & o)
+ : owner(&o)
{
wid = tmpx;
hgh = tmpy;
raw_wid = raw_hgh = 0;
changedfname = false;
RegisterFigure(this);
+ r_ = Dialogs::redrawGUI.connect(SigC::slot(this, &InsetFig::redraw));
}
lyxerr << "Figure destructor called" << endl;
}
UnregisterFigure(this);
+ r_.disconnect();
+}
+
+
+void InsetFig::redraw()
+{
+ if (form && form->Figure->visible)
+ fl_redraw_form(form->Figure);
}
wid + 1, hgh + 1);
} else {
- char * msg = 0;
+ //char const * msg = 0;
+ string msg;
string lfname = fname;
if (!fname.empty() && GetExtension(fname).empty())
lfname += ".eps";
else if (lyxrc.ps_command.empty())
msg = _("[no ghostscript]");
- if (!msg) msg = _("[unknown error]");
+ if (msg.empty()) msg = _("[unknown error]");
font.setFamily(LyXFont::SANS_FAMILY);
font.setSize(LyXFont::SIZE_FOOTNOTE);
- string justname = OnlyFilename (fname);
+ string const justname = OnlyFilename (fname);
pain.text(int(x + 8), baseline - lyxfont::maxAscent(font) - 4,
justname, font);
font.setSize(LyXFont::SIZE_TINY);
- pain.text(int(x + 8), baseline - 4, msg, strlen(msg), font);
+ pain.text(int(x + 8), baseline - 4, msg, font);
}
x += width(bv, font); // ?
}
-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());
}
-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();
- lyxerr.debug() << "Token: " << token << endl;
+ string const token = lex.getString();
+ lyxerr[Debug::INFO] << "Token: " << token << endl;
if (token.empty())
continue;
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;
}
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;
case PER_PAGE: wtype = PER_PAGE; break;
case PER_COL: wtype = PER_COL; break;
default:
- lyxerr.debug() << "Unknown type!" << endl;
+ lyxerr[Debug::INFO] << "Unknown type!" << endl;
break;
}
twtype = wtype;
} 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;
case IN: htype = IN; break;
case PER_PAGE: htype = PER_PAGE; break;
default:
- lyxerr.debug() << "Unknown type!" << endl;
+ lyxerr[Debug::INFO] << "Unknown type!" << endl;
break;
}
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"))
+ if (suffixIs(figurename, ".eps"))
figurename.erase(figurename.length() - 4);
- os << "@<graphic fileref=\"" << figurename << "\"></graphic>";
+ os << "<graphic fileref=\"" << figurename << "\"></graphic>";
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() << "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());
+ lyxerr[Debug::INFO] << "Editing InsetFig." << endl;
+ regenerate();
if (!form) {
form = create_form_Figure();
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 {
- fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
- FL_FULLBORDER, _("Figure"));
+ fl_show_form(form->Figure,
+ FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
+ _("Figure"));
}
}
-Inset * InsetFig::Clone() const
+void InsetFig::edit(BufferView * bv, bool)
{
- InsetFig * tmp = new InsetFig(100, 100, owner);
+ edit(bv, 0, 0, 0);
+}
+
+
+Inset * InsetFig::clone(Buffer const & buffer, bool) const
+{
+ InsetFig * tmp = new InsetFig(100, 100, buffer);
if (lyxerr.debugging()) {
lyxerr << "Clone Figure: buffer:["
- << current_view->buffer()
+ << &buffer
<< "], cbuffer:[xx]" << endl;
}
tmp->pswid = pswid;
tmp->pshgh = pshgh;
tmp->fname = fname;
- if (!fname.empty() && IsFileReadable(fname)
+ string lfname = fname;
+ if (!fname.empty() && GetExtension(fname).empty())
+ lfname += ".eps";
+ if (!fname.empty() && IsFileReadable(lfname)
&& (flags & 3) && !lyxrc.ps_command.empty()
&& lyxrc.use_gui) {
// do not display if there is
// "do not display" chosen (Matthias 260696)
- tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
+ tmp->figure->data = getfigdata(wid, hgh, lfname, psx, psy,
pswid, pshgh, raw_wid, raw_hgh,
angle, flags & (3|8));
} else tmp->figure->data = 0;
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;
}
-static
-string stringify(InsetFig::HWTYPE hw, float f, string suffix)
+namespace {
+
+string const stringify(InsetFig::HWTYPE hw, float f, string suffix)
{
string res;
switch (hw) {
return res;
}
+} // 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}";
}
-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);
}
-void InsetFig::Recompute()
+void InsetFig::recompute()
{
+ if (!lyxrc.use_gui)
+ return;
+
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);
+ float sin_a = sin(angle / DEG2PI); /* rotation; H. Zeller 021296 */
+ float cos_a = cos(angle / DEG2PI);
int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
}
-void InsetFig::GetPSSizes()
+void InsetFig::getPSSizes()
{
/* get %%BoundingBox: from postscript file */
if (fname.empty()) return;
string p;
- ifstream ifs(fname.c_str());
+ string lfname = fname;
+ if (GetExtension(fname).empty())
+ lfname += ".eps";
+ ifstream ifs(lfname.c_str());
if (!ifs) return; // file not found !!!!
for (;;) {
char c = 0; ifs.get(c);
if (ifs.eof()) {
- lyxerr.debug() << "End of (E)PS file reached and"
+ lyxerr[Debug::INFO] << "End of (E)PS file reached and"
" no BoundingBox!" << endl;
break;
}
if (c == '%' && lastchar == '%') {
ifs >> p;
if (p.empty()) break;
- lyxerr.debug() << "Token: `" << p << "'" << endl;
+ lyxerr[Debug::INFO] << "Token: `" << p << "'" << endl;
if (p == "BoundingBox:") {
float fpsx, fpsy, fpswid, fpshgh;
if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
}
-void InsetFig::CallbackFig(long arg)
+void InsetFig::callbackFig(long arg)
{
bool regen = false;
char const * p;
fl_activate_object(form->Width);
break;
default:
- lyxerr.debug() << "Unknown type!" << endl;
+ lyxerr[Debug::INFO] << "Unknown type!" << endl;
break;
}
regen = true;
fl_activate_object(form->Height);
break;
default:
- lyxerr.debug() << "Unknown type!" << endl;
+ lyxerr[Debug::INFO] << "Unknown type!" << endl;
break;
}
regen = true;
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) */
- if(!current_view->buffer()->isReadonly()) {
+ if (!current_view->buffer()->isReadonly()) {
wtype = twtype;
htype = thtype;
xwid = atof(fl_get_input(form->Width));
}
subcaption = fl_get_input(form->Subcaption);
- Regenerate();
- Recompute();
+ regenerate();
+ recompute();
/* now update inset */
if (lyxerr.debugging()) {
lyxerr << "Update: ["
break;
} //if not readonly
// The user has already been informed about RO in ::Edit
- if(arg == 7) // if 'Apply'
+ if (arg == 7) // if 'Apply'
break;
// fall through
case 9: /* cancel = restore and close */
break;
}
- if (regen) TempRegenerate();
+ if (regen) tempRegenerate();
}
}
-void InsetFig::RestoreForm()
+void InsetFig::restoreForm()
{
EnableFigurePanel(form);
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());
}
else fl_set_input(form->EpsFile, "");
fl_set_input(form->Subcaption, subcaption.c_str());
- if(current_view->buffer()->isReadonly())
+ if (current_view->buffer()->isReadonly())
DisableFigurePanel(form);
- TempRegenerate();
+ tempRegenerate();
}
-void InsetFig::Preview(string const & p)
+void InsetFig::preview(string const & p)
{
- int pid = fork();
-
- if (pid == -1) {
- lyxerr << "Cannot fork process!" << endl;
- return; // error
- }
- if (pid > 0) {
- addpidwait(pid);
- return; // parent process
- }
-
string tfname = p;
if (GetExtension(tfname).empty())
tfname += ".eps";
string buf1 = OnlyPath(owner->fileName());
- string buf2 = MakeAbsPath(tfname, buf1);
-
- lyxerr << "Error during rendering "
- << execlp(lyxrc.view_pspic_command.c_str(),
- lyxrc.view_pspic_command.c_str(),
- buf2.c_str(), 0)
- << endl;
- _exit(0);
+ string buf2 = os::external_path(MakeAbsPath(tfname, buf1));
+ 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 = 0;
- LyXFileDlg fileDlg;
+ static int once;
if (lyxerr.debugging()) {
lyxerr << "Filename: "
bufclip = AddName (system_lyxdir, "clipart");
- fileDlg.SetButton(0, _("Clipart"), bufclip);
- fileDlg.SetButton(1, _("Document"), buf);
+ FileDialog fileDlg(current_view->owner(), _("Select an EPS figure"),
+ LFUN_SELECT_FILE_SYNC,
+ make_pair(string(_("Clip art|#C#c")), string(bufclip)),
+ make_pair(string(_("Documents|#o#O")), string(buf)));
bool error = false;
do {
- ProhibitInput(current_view);
- if (once) {
- p = fileDlg.Select(_("EPS Figure"),
- current_figure_path,
- "*ps", string());
- } else {
- p = fileDlg.Select(_("EPS Figure"), buf,
- "*ps", string());
- }
- AllowInput(current_view);
+ string const path = (once) ? current_figure_path : buf;
- if (p.empty()) return;
+ FileDialog::Result result = fileDlg.Select(path, _("*ps| PostScript documents"));
+
+ string const p = result.second;
+
+ if (p.empty())
+ return;
buf = MakeRelPath(p, buf2);
current_figure_path = OnlyPath(p);
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 '%'."));
lyxerr << "Calling back figure "
<< (*it) << endl;
}
- (*it)->inset->CallbackFig(arg);
+ (*it)->inset->callbackFig(arg);
return;
}
}
lyxerr << "Hiding figure " << (*it) << endl;
}
// hide and free the form
- (*it)->inset->CallbackFig(9);
+ (*it)->inset->callbackFig(9);
}
}