1999-09-27 18:44:28 +00:00
|
|
|
/*
|
|
|
|
* figinset.C - part of LyX project
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Rework of path-handling (Matthias 04.07.1996 )
|
|
|
|
* ------------------------------------------------
|
|
|
|
* figinsets keep an absolute path to the eps-file.
|
|
|
|
* For the user alway a relative path appears
|
|
|
|
* (in lyx-file, latex-file and edit-popup).
|
|
|
|
* To calculate this relative path the path to the
|
|
|
|
* document where the figinset is in is needed.
|
|
|
|
* This is done by a reference to the buffer, called
|
|
|
|
* figinset::cbuffer. To be up to date the cbuffer
|
|
|
|
* is sometimes set to the current buffer
|
|
|
|
* bufferlist.current(), when it can be assumed that
|
|
|
|
* this operation happens in the current buffer.
|
|
|
|
* This is true for InsetFig::Edit(...),
|
|
|
|
* InsetFig::InsetFig(...), InsetFig::Read(...),
|
|
|
|
* InsetFig::Write and InsetFig::Latex(...).
|
|
|
|
* Therefore the bufferlist has to make sure that
|
|
|
|
* during these operations bufferlist.current()
|
|
|
|
* returns the buffer where the figinsets are in.
|
|
|
|
* This made few changes in buffer.C necessary.
|
|
|
|
*
|
|
|
|
* The above is not totally valid anymore. (Lgb)
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
#include <fstream>
|
|
|
|
#include <queue>
|
|
|
|
#include <list>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2001-03-07 14:25:31 +00:00
|
|
|
#include <utility>
|
2000-04-24 20:58:23 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include <unistd.h>
|
1999-10-02 16:21:10 +00:00
|
|
|
#include <csignal>
|
1999-09-27 18:44:28 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
1999-10-02 16:21:10 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
#include <cctype>
|
|
|
|
#include <cmath>
|
2000-03-12 10:35:05 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "figinset.h"
|
|
|
|
#include "lyx.h"
|
|
|
|
#include "lyx_main.h"
|
|
|
|
#include "buffer.h"
|
2001-03-07 14:25:31 +00:00
|
|
|
#include "frontends/FileDialog.h"
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/filetools.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "LyXView.h" // just because of form_main
|
1999-10-07 18:44:17 +00:00
|
|
|
#include "debug.h"
|
1999-09-27 18:44:28 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "lyxrc.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include "lyx_gui_misc.h" // CancelCloseBoxCB
|
1999-10-02 16:21:10 +00:00
|
|
|
#include "support/FileInfo.h"
|
2000-01-17 21:01:30 +00:00
|
|
|
#include "support/lyxlib.h"
|
2000-02-10 17:53:36 +00:00
|
|
|
#include "Painter.h"
|
2000-04-04 00:19:15 +00:00
|
|
|
#include "font.h"
|
2000-04-12 14:20:08 +00:00
|
|
|
#include "bufferview_funcs.h"
|
2000-04-16 22:27:30 +00:00
|
|
|
#include "ColorHandler.h"
|
2000-10-02 16:44:47 +00:00
|
|
|
#include "converter.h"
|
2000-11-28 06:46:06 +00:00
|
|
|
#include "frontends/Dialogs.h" // redrawGUI
|
|
|
|
|
2000-04-04 00:19:15 +00:00
|
|
|
using std::ostream;
|
|
|
|
using std::istream;
|
|
|
|
using std::ofstream;
|
|
|
|
using std::ifstream;
|
|
|
|
using std::queue;
|
|
|
|
using std::list;
|
|
|
|
using std::vector;
|
|
|
|
using std::find;
|
|
|
|
using std::flush;
|
|
|
|
using std::endl;
|
2000-04-24 20:58:23 +00:00
|
|
|
using std::ostringstream;
|
2000-10-11 21:06:43 +00:00
|
|
|
using std::copy;
|
2001-03-07 14:25:31 +00:00
|
|
|
using std::pair;
|
|
|
|
using std::make_pair;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-26 06:57:35 +00:00
|
|
|
extern BufferView * current_view;
|
|
|
|
extern FL_OBJECT * figinset_canvas;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-11-26 06:57:35 +00:00
|
|
|
extern char ** environ; // is this only redundtant on linux systems? Lgb.
|
2000-02-23 16:39:03 +00:00
|
|
|
|
2001-03-20 10:14:03 +00:00
|
|
|
// 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 *);
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
float const DEG2PI = 57.295779513;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-01-21 17:41:57 +00:00
|
|
|
struct queue_element {
|
|
|
|
float rx, ry; // resolution x and y
|
|
|
|
int ofsx, ofsy; // x and y translation
|
|
|
|
figdata * data; // we are doing it for this data
|
1999-09-27 18:44:28 +00:00
|
|
|
};
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
int const MAXGS = 3; /* maximum 3 gs's at a time */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
typedef vector<Figref *> figures_type;
|
|
|
|
typedef vector<figdata *> bitmaps_type;
|
2001-03-20 01:22:46 +00:00
|
|
|
figures_type figures; // all figures
|
|
|
|
bitmaps_type bitmaps; // all bitmaps
|
2000-01-21 17:41:57 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
queue<queue_element> gsqueue; // queue for ghostscripting
|
2000-01-21 17:41:57 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
int gsrunning = 0; /* currently so many gs's are running */
|
|
|
|
bool bitmap_waiting = false; /* bitmaps are waiting finished */
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
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
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
list<int> pidwaitlist; // pid wait list
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
GC createGC()
|
|
|
|
{
|
|
|
|
XGCValues val;
|
2000-10-11 21:06:43 +00:00
|
|
|
val.foreground = BlackPixel(fl_get_display(),
|
|
|
|
DefaultScreen(fl_get_display()));
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
val.function=GXcopy;
|
|
|
|
val.graphics_exposures = false;
|
|
|
|
val.line_style = LineSolid;
|
|
|
|
val.line_width = 0;
|
2000-10-11 21:06:43 +00:00
|
|
|
return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
|
2000-02-10 17:53:36 +00:00
|
|
|
GCForeground | GCFunction | GCGraphicsExposures
|
|
|
|
| GCLineWidth | GCLineStyle , &val);
|
|
|
|
}
|
|
|
|
|
|
|
|
GC local_gc_copy;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
void addpidwait(int pid)
|
|
|
|
{
|
|
|
|
// adds pid to pid wait list
|
2000-01-21 18:33:54 +00:00
|
|
|
pidwaitlist.push_back(pid);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (lyxerr.debugging()) {
|
2000-01-21 18:33:54 +00:00
|
|
|
lyxerr << "Pids to wait for: \n";
|
2000-10-11 21:06:43 +00:00
|
|
|
copy(pidwaitlist.begin(), pidwaitlist.end(),
|
2000-10-12 15:17:42 +00:00
|
|
|
std::ostream_iterator<int>(lyxerr, "\n"));
|
2000-01-21 18:33:54 +00:00
|
|
|
lyxerr << flush;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
string make_tmp(int pid)
|
|
|
|
{
|
|
|
|
return system_tempdir + "/~lyxgs" + tostr(pid) + ".ps";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void kill_gs(int pid, int sig)
|
|
|
|
{
|
|
|
|
if (lyxerr.debugging())
|
|
|
|
lyxerr << "Killing gs " << pid << endl;
|
|
|
|
lyx::kill(pid, sig);
|
2000-09-26 13:54:57 +00:00
|
|
|
lyx::unlink(make_tmp(pid));
|
2000-04-24 20:58:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
extern "C"
|
2000-12-05 14:15:44 +00:00
|
|
|
int GhostscriptMsg(XEvent * ev, void *)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-12-05 14:15:44 +00:00
|
|
|
// bin all events not of interest
|
|
|
|
if (ev->type != ClientMessage)
|
|
|
|
return FL_PREEMPT;
|
|
|
|
|
1999-11-26 06:57:35 +00:00
|
|
|
XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
|
|
|
|
<< "] pm:[" << e->data.l[1] << "]" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// just kill gs, that way it will work for sure
|
1999-12-16 06:43:25 +00:00
|
|
|
// This loop looks like S**T so it probably is...
|
2000-03-12 10:35:05 +00:00
|
|
|
for (bitmaps_type::iterator it = bitmaps.begin();
|
|
|
|
it != bitmaps.end(); ++it)
|
|
|
|
if (static_cast<long>((*it)->bitmap) ==
|
|
|
|
static_cast<long>(e->data.l[1])) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// found the one
|
2000-03-12 10:35:05 +00:00
|
|
|
figdata * p = (*it);
|
1999-09-27 18:44:28 +00:00
|
|
|
p->gsdone = true;
|
|
|
|
|
|
|
|
// first update p->bitmap, if necessary
|
1999-12-16 06:43:25 +00:00
|
|
|
if (p->bitmap != None
|
|
|
|
&& p->flags > (1|8) && gs_color && p->wid) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// query current colormap and re-render
|
|
|
|
// the pixmap with proper colors
|
|
|
|
XWindowAttributes wa;
|
1999-11-26 06:57:35 +00:00
|
|
|
register XImage * im;
|
2000-02-10 17:53:36 +00:00
|
|
|
int i;
|
|
|
|
int y;
|
2000-03-12 10:35:05 +00:00
|
|
|
int spc1 = gs_spc - 1;
|
2000-02-10 17:53:36 +00:00
|
|
|
int spc2 = gs_spc * gs_spc;
|
|
|
|
int wid = p->wid;
|
|
|
|
int forkstat;
|
1999-11-26 06:57:35 +00:00
|
|
|
Display * tmpdisp;
|
2000-02-10 17:53:36 +00:00
|
|
|
GC gc = local_gc_copy;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
XGetWindowAttributes(fl_get_display(),
|
1999-12-16 06:43:25 +00:00
|
|
|
fl_get_canvas_id(
|
|
|
|
figinset_canvas),
|
|
|
|
&wa);
|
2000-10-11 21:06:43 +00:00
|
|
|
XFlush(fl_get_display());
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lyxerr.debugging()) {
|
1999-11-26 06:57:35 +00:00
|
|
|
lyxerr << "Starting image translation "
|
|
|
|
<< p->bitmap << " "
|
|
|
|
<< p->flags << " "
|
|
|
|
<< p->wid << "x" << p->hgh
|
|
|
|
<< " " << wa.depth
|
|
|
|
<< " " << XYPixmap << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
// now fork rendering process
|
|
|
|
forkstat = fork();
|
|
|
|
if (forkstat == -1) {
|
1999-11-26 06:57:35 +00:00
|
|
|
lyxerr.debug()
|
|
|
|
<< "Cannot fork, using slow "
|
1999-10-07 18:44:17 +00:00
|
|
|
"method for pixmap translation." << endl;
|
2000-10-11 21:06:43 +00:00
|
|
|
tmpdisp = fl_get_display();
|
2000-01-21 18:33:54 +00:00
|
|
|
} else if (forkstat > 0) { // parent
|
1999-09-27 18:44:28 +00:00
|
|
|
// register child
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Spawned child "
|
|
|
|
<< forkstat << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
addpidwait(forkstat);
|
2000-01-21 18:33:54 +00:00
|
|
|
break;
|
|
|
|
} else { // child
|
2000-10-24 11:21:52 +00:00
|
|
|
tmpdisp = XOpenDisplay(DisplayString(fl_get_display()));
|
1999-09-27 18:44:28 +00:00
|
|
|
XFlush(tmpdisp);
|
|
|
|
}
|
|
|
|
im = XGetImage(tmpdisp, p->bitmap, 0, 0,
|
|
|
|
p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
|
|
|
|
XFlush(tmpdisp);
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Got the image" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
if (!im) {
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Error getting the image" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
goto noim;
|
|
|
|
}
|
1999-11-26 06:57:35 +00:00
|
|
|
{
|
1999-09-27 18:44:28 +00:00
|
|
|
// query current colormap
|
1999-12-16 06:43:25 +00:00
|
|
|
XColor * cmap = new XColor[gs_allcolors];
|
|
|
|
for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
|
2000-02-29 02:19:17 +00:00
|
|
|
XQueryColors(tmpdisp,
|
|
|
|
fl_state[fl_get_vclass()]
|
|
|
|
.colormap, cmap,
|
|
|
|
gs_allcolors);
|
1999-12-16 06:43:25 +00:00
|
|
|
XFlush(tmpdisp);
|
1999-09-27 18:44:28 +00:00
|
|
|
// now we process all the image
|
1999-12-16 06:43:25 +00:00
|
|
|
for (y = 0; y < p->hgh; ++y) {
|
|
|
|
for (int x = 0; x < wid; ++x) {
|
|
|
|
XColor * pc = cmap +
|
|
|
|
XGetPixel(im, x, y);
|
|
|
|
XFlush(tmpdisp);
|
|
|
|
XPutPixel(im, x, y,
|
|
|
|
gs_pixels[((pc->red+6553)*
|
|
|
|
spc1/65535)*spc2+((pc->green+6553)*
|
|
|
|
spc1/65535)*gs_spc+((pc->blue+6553)*
|
|
|
|
spc1/65535)]);
|
|
|
|
XFlush(tmpdisp);
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-26 06:57:35 +00:00
|
|
|
// This must be correct.
|
1999-12-16 06:43:25 +00:00
|
|
|
delete [] cmap;
|
|
|
|
if (lyxerr.debugging()) {
|
|
|
|
lyxerr << "Putting image back"
|
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
XPutImage(tmpdisp, p->bitmap,
|
|
|
|
gc, im, 0, 0,
|
|
|
|
0, 0, p->wid, p->hgh);
|
|
|
|
XDestroyImage(im);
|
|
|
|
if (lyxerr.debugging()) {
|
|
|
|
lyxerr << "Done translation"
|
|
|
|
<< endl;
|
|
|
|
}
|
1999-11-26 06:57:35 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
noim:
|
2000-04-24 20:58:23 +00:00
|
|
|
kill_gs(p->gspid, SIGHUP);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (forkstat == 0) {
|
|
|
|
XCloseDisplay(tmpdisp);
|
|
|
|
_exit(0);
|
|
|
|
}
|
|
|
|
} else {
|
2000-04-24 20:58:23 +00:00
|
|
|
kill_gs(p->gspid, SIGHUP);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2000-12-05 14:15:44 +00:00
|
|
|
return FL_PREEMPT;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
void AllocColors(int num)
|
1999-09-27 18:44:28 +00:00
|
|
|
// allocate color cube numxnumxnum, if possible
|
|
|
|
{
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Allocating color cube " << num
|
|
|
|
<< 'x' << num << 'x' << num << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (num <= 1) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Error allocating color colormap." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
gs_color = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (num > 5) num = 5;
|
1999-12-16 06:43:25 +00:00
|
|
|
XColor xcol;
|
|
|
|
for (int i = 0; i < num * num * num; ++i) {
|
2000-09-27 18:13:30 +00:00
|
|
|
xcol.red = short(65535 * (i / (num * num)) / (num - 1));
|
|
|
|
xcol.green = short(65535 * ((i / num) % num) / (num - 1));
|
|
|
|
xcol.blue = short(65535 * (i % num) / (num - 1));
|
1999-09-27 18:44:28 +00:00
|
|
|
xcol.flags = DoRed | DoGreen | DoBlue;
|
2000-10-11 21:06:43 +00:00
|
|
|
if (!XAllocColor(fl_get_display(),
|
2000-02-10 17:53:36 +00:00
|
|
|
fl_state[fl_get_vclass()].colormap, &xcol)) {
|
2000-10-11 21:06:43 +00:00
|
|
|
if (i) XFreeColors(fl_get_display(),
|
2000-02-10 17:53:36 +00:00
|
|
|
fl_state[fl_get_vclass()].colormap,
|
1999-09-27 18:44:28 +00:00
|
|
|
gs_pixels, i, 0);
|
2000-11-04 10:00:12 +00:00
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Cannot allocate color cube "
|
|
|
|
<< num << endl;;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-12-16 06:43:25 +00:00
|
|
|
AllocColors(num - 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
gs_pixels[i] = xcol.pixel;
|
|
|
|
}
|
|
|
|
gs_color = true;
|
|
|
|
gs_spc = num;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// allocate grayscale ramp
|
1999-12-16 06:43:25 +00:00
|
|
|
void AllocGrays(int num)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
if (lyxerr.debugging()) {
|
1999-12-16 06:43:25 +00:00
|
|
|
lyxerr << "Allocating grayscale colormap "
|
1999-10-07 18:44:17 +00:00
|
|
|
<< num << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (num < 4) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Error allocating grayscale colormap." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
gs_color = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (num > 128) num = 128;
|
1999-12-16 06:43:25 +00:00
|
|
|
XColor xcol;
|
|
|
|
for (int i = 0; i < num; ++i) {
|
2000-09-29 18:44:07 +00:00
|
|
|
xcol.red = xcol.green = xcol.blue = short(65535 * i / (num - 1));
|
1999-09-27 18:44:28 +00:00
|
|
|
xcol.flags = DoRed | DoGreen | DoBlue;
|
2000-10-11 21:06:43 +00:00
|
|
|
if (!XAllocColor(fl_get_display(),
|
2000-02-10 17:53:36 +00:00
|
|
|
fl_state[fl_get_vclass()].colormap, &xcol)) {
|
2000-10-11 21:06:43 +00:00
|
|
|
if (i) XFreeColors(fl_get_display(),
|
2000-02-10 17:53:36 +00:00
|
|
|
fl_state[fl_get_vclass()].colormap,
|
1999-09-27 18:44:28 +00:00
|
|
|
gs_pixels, i, 0);
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Cannot allocate grayscale "
|
|
|
|
<< num << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-12-16 06:43:25 +00:00
|
|
|
AllocGrays(num / 2);
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
gs_pixels[i] = xcol.pixel;
|
|
|
|
}
|
|
|
|
gs_color = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitFigures()
|
|
|
|
{
|
2000-03-12 10:35:05 +00:00
|
|
|
// if bitmaps and figures are not empty we will leak mem
|
|
|
|
figures.clear();
|
|
|
|
bitmaps.clear();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// allocate color cube on pseudo-color display
|
|
|
|
// first get visual
|
|
|
|
gs_color = false;
|
2000-03-20 16:37:50 +00:00
|
|
|
if (lyxrc.use_gui) {
|
2000-12-05 14:15:44 +00:00
|
|
|
/* 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);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-20 16:37:50 +00:00
|
|
|
local_gc_copy = createGC();
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
Visual * vi = DefaultVisual(fl_get_display(),
|
|
|
|
DefaultScreen(fl_get_display()));
|
2000-03-20 16:37:50 +00:00
|
|
|
if (lyxerr.debugging()) {
|
|
|
|
printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
|
2000-04-24 20:58:23 +00:00
|
|
|
vi->visualid, vi->c_class,
|
|
|
|
vi->bits_per_rgb, vi->map_entries);
|
2000-03-20 16:37:50 +00:00
|
|
|
}
|
|
|
|
color_visual = ( (vi->c_class == StaticColor) ||
|
|
|
|
(vi->c_class == PseudoColor) ||
|
|
|
|
(vi->c_class == TrueColor) ||
|
|
|
|
(vi->c_class == DirectColor) );
|
|
|
|
if ((vi->c_class & 1) == 0) return;
|
|
|
|
// now allocate colors
|
|
|
|
if (vi->c_class == GrayScale) {
|
|
|
|
// allocate grayscale
|
|
|
|
AllocGrays(vi->map_entries/2);
|
|
|
|
} else {
|
|
|
|
// allocate normal color
|
|
|
|
int i = 5;
|
|
|
|
while (i * i * i * 2 > vi->map_entries) --i;
|
|
|
|
AllocColors(i);
|
|
|
|
}
|
|
|
|
gs_allcolors = vi->map_entries;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DoneFigures()
|
|
|
|
{
|
2000-03-12 10:35:05 +00:00
|
|
|
// if bitmaps and figures are not empty we will leak mem
|
|
|
|
bitmaps.clear();
|
|
|
|
figures.clear();
|
|
|
|
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Unregistering figures..." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
void freefigdata(figdata * tmpdata)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
tmpdata->ref--;
|
|
|
|
if (tmpdata->ref) return;
|
|
|
|
|
|
|
|
if (tmpdata->gspid > 0) {
|
|
|
|
int pid = tmpdata->gspid;
|
|
|
|
// kill ghostscript and unlink it's files
|
|
|
|
tmpdata->gspid = -1;
|
2000-04-24 20:58:23 +00:00
|
|
|
kill_gs(pid, SIGKILL);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-10-11 21:06:43 +00:00
|
|
|
if (tmpdata->bitmap) XFreePixmap(fl_get_display(), tmpdata->bitmap);
|
2000-03-12 10:35:05 +00:00
|
|
|
bitmaps.erase(find(bitmaps.begin(), bitmaps.end(), tmpdata));
|
1999-09-27 18:44:28 +00:00
|
|
|
delete tmpdata;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
void runqueue()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-04-16 22:27:30 +00:00
|
|
|
// This _have_ to be set before the fork!
|
|
|
|
unsigned long background_pixel =
|
|
|
|
lyxColorHandler->colorPixel(LColor::background);
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// run queued requests for ghostscript, if any
|
|
|
|
if (!gsrunning && gs_color && !gs_xcolor) {
|
|
|
|
// here alloc all colors, so that gs will use only
|
|
|
|
// those we allocated for it
|
|
|
|
// *****
|
|
|
|
gs_xcolor = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (gsrunning < MAXGS) {
|
2000-04-24 20:58:23 +00:00
|
|
|
//char tbuf[384]; //, tbuf2[80];
|
1999-11-24 22:14:46 +00:00
|
|
|
Atom * prop;
|
1999-09-27 18:44:28 +00:00
|
|
|
int nprop, i;
|
|
|
|
|
2000-01-21 17:41:57 +00:00
|
|
|
if (gsqueue.empty()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!gsrunning && gs_xcolor) {
|
|
|
|
// de-allocate rest of colors
|
|
|
|
// *****
|
|
|
|
gs_xcolor = false;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2000-01-21 17:41:57 +00:00
|
|
|
queue_element * p = &gsqueue.front();
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!p->data) {
|
2000-01-21 17:41:57 +00:00
|
|
|
gsqueue.pop();
|
1999-09-27 18:44:28 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
int pid = ::fork();
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (pid == -1) {
|
|
|
|
if (lyxerr.debugging()) {
|
1999-11-24 22:14:46 +00:00
|
|
|
lyxerr << "GS start error! Cannot fork."
|
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
p->data->broken = true;
|
|
|
|
p->data->reading = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (pid == 0) { // child
|
2000-04-24 20:58:23 +00:00
|
|
|
char ** env;
|
1999-09-27 18:44:28 +00:00
|
|
|
int ne = 0;
|
2000-10-24 11:21:52 +00:00
|
|
|
Display * tempdisp = XOpenDisplay(DisplayString(fl_get_display()));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// create translation file
|
2000-04-24 20:58:23 +00:00
|
|
|
ofstream ofs;
|
|
|
|
ofs.open(make_tmp(getpid()).c_str());
|
1999-11-24 22:14:46 +00:00
|
|
|
ofs << "gsave clippath pathbbox grestore\n"
|
|
|
|
<< "4 dict begin\n"
|
|
|
|
<< "/ury exch def /urx exch def /lly exch def "
|
1999-09-27 18:44:28 +00:00
|
|
|
"/llx exch def\n"
|
1999-11-24 22:14:46 +00:00
|
|
|
<< p->data->wid / 2.0 << " "
|
|
|
|
<< p->data->hgh / 2.0 << " translate\n"
|
|
|
|
<< p->data->angle << " rotate\n"
|
|
|
|
<< -(p->data->raw_wid / 2.0) << " "
|
|
|
|
<< -(p->data->raw_hgh / 2.0) << " translate\n"
|
|
|
|
<< p->rx / 72.0 << " " << p->ry / 72.0
|
|
|
|
<< " scale\n"
|
|
|
|
<< -p->ofsx << " " << -p->ofsy << " translate\n"
|
|
|
|
<< "end" << endl;
|
|
|
|
ofs.close(); // Don't remove this.
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// gs process - set ghostview environment first
|
2000-04-24 20:58:23 +00:00
|
|
|
ostringstream t2;
|
|
|
|
t2 << "GHOSTVIEW=" << fl_get_canvas_id(figinset_canvas)
|
|
|
|
<< ' ' << p->data->bitmap;
|
1999-09-27 18:44:28 +00:00
|
|
|
// now set up ghostview property on a window
|
1999-12-16 06:43:25 +00:00
|
|
|
// #warning BUG seems that the only bug here
|
|
|
|
// might be the hardcoded dpi.. Bummer!
|
2000-04-24 20:58:23 +00:00
|
|
|
ostringstream t1;
|
|
|
|
t1 << "0 0 0 0 " << p->data->wid << ' '
|
|
|
|
<< p->data->hgh << " 72 72 0 0 0 0";
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Will set GHOSTVIEW property to ["
|
2000-04-24 20:58:23 +00:00
|
|
|
<< t1.str() << "]" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
// wait until property is deleted if executing multiple
|
|
|
|
// ghostscripts
|
2000-04-16 22:27:30 +00:00
|
|
|
XGrabServer(tempdisp);
|
1999-09-27 18:44:28 +00:00
|
|
|
for (;;) {
|
1999-12-16 06:43:25 +00:00
|
|
|
// grab server to prevent other child
|
|
|
|
// interfering with setting GHOSTVIEW property
|
2000-04-16 22:27:30 +00:00
|
|
|
// The grabbing goes on for too long, is it
|
|
|
|
// really needed? (Lgb)
|
|
|
|
// I moved most of the grabs... (Lgb)
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lyxerr.debugging()) {
|
1999-12-16 06:43:25 +00:00
|
|
|
lyxerr << "Grabbing the server"
|
|
|
|
<< endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-12-16 06:43:25 +00:00
|
|
|
prop = XListProperties(tempdisp,
|
|
|
|
fl_get_canvas_id(
|
1999-09-27 18:44:28 +00:00
|
|
|
figinset_canvas), &nprop);
|
|
|
|
if (!prop) break;
|
|
|
|
|
|
|
|
bool err = true;
|
|
|
|
for (i = 0; i < nprop; ++i) {
|
1999-12-16 06:43:25 +00:00
|
|
|
char * p = XGetAtomName(tempdisp,
|
|
|
|
prop[i]);
|
2001-02-16 09:25:43 +00:00
|
|
|
if (compare(p, "GHOSTVIEW") == 0) {
|
1999-09-27 18:44:28 +00:00
|
|
|
err = false;
|
2000-08-08 09:18:39 +00:00
|
|
|
// We free it when we leave so we don't leak.
|
|
|
|
XFree(p);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
XFree(p);
|
|
|
|
}
|
1999-12-16 06:43:25 +00:00
|
|
|
XFree(reinterpret_cast<char *>(prop)); // jc:
|
1999-09-27 18:44:28 +00:00
|
|
|
if (err) break;
|
1999-12-16 06:43:25 +00:00
|
|
|
// ok, property found, we must wait until
|
|
|
|
// ghostscript deletes it
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lyxerr.debugging()) {
|
1999-12-16 06:43:25 +00:00
|
|
|
lyxerr << "Releasing the server\n["
|
1999-10-07 18:44:17 +00:00
|
|
|
<< getpid()
|
|
|
|
<< "] GHOSTVIEW property"
|
|
|
|
" found. Waiting." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-04-16 22:27:30 +00:00
|
|
|
XUngrabServer(tempdisp);
|
|
|
|
XFlush(tempdisp);
|
|
|
|
::sleep(1);
|
|
|
|
XGrabServer(tempdisp);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
XChangeProperty(tempdisp,
|
|
|
|
fl_get_canvas_id(figinset_canvas),
|
|
|
|
XInternAtom(tempdisp, "GHOSTVIEW", false),
|
|
|
|
XInternAtom(tempdisp, "STRING", false),
|
|
|
|
8, PropModeAppend,
|
2000-04-24 20:58:23 +00:00
|
|
|
reinterpret_cast<unsigned char*>(const_cast<char*>(t1.str().c_str())),
|
2000-09-29 18:44:07 +00:00
|
|
|
int(t1.str().size()));
|
2000-04-16 22:27:30 +00:00
|
|
|
XUngrabServer(tempdisp);
|
|
|
|
XFlush(tempdisp);
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
|
|
ostringstream t3;
|
2000-09-18 17:39:21 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
switch (p->data->flags & 3) {
|
2000-04-24 20:58:23 +00:00
|
|
|
case 0: t3 << 'H'; break; // Hidden
|
|
|
|
case 1: t3 << 'M'; break; // Mono
|
|
|
|
case 2: t3 << 'G'; break; // Gray
|
1999-09-27 18:44:28 +00:00
|
|
|
case 3:
|
|
|
|
if (color_visual)
|
2000-04-24 20:58:23 +00:00
|
|
|
t3 << 'C'; // Color
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
2000-04-24 20:58:23 +00:00
|
|
|
t3 << 'G'; // Gray
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
|
|
t3 << ' ' << BlackPixelOfScreen(DefaultScreenOfDisplay(tempdisp))
|
|
|
|
<< ' ' << background_pixel;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
XGrabServer(tempdisp);
|
1999-09-27 18:44:28 +00:00
|
|
|
XChangeProperty(tempdisp,
|
|
|
|
fl_get_canvas_id(figinset_canvas),
|
1999-12-16 06:43:25 +00:00
|
|
|
XInternAtom(tempdisp,
|
|
|
|
"GHOSTVIEW_COLORS", false),
|
1999-09-27 18:44:28 +00:00
|
|
|
XInternAtom(tempdisp, "STRING", false),
|
|
|
|
8, PropModeReplace,
|
2000-04-24 20:58:23 +00:00
|
|
|
reinterpret_cast<unsigned char*>(const_cast<char*>(t3.str().c_str())),
|
2000-09-29 18:44:07 +00:00
|
|
|
int(t3.str().size()));
|
1999-09-27 18:44:28 +00:00
|
|
|
XUngrabServer(tempdisp);
|
|
|
|
XFlush(tempdisp);
|
2000-04-16 22:27:30 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Releasing the server" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
XCloseDisplay(tempdisp);
|
|
|
|
|
|
|
|
// set up environment
|
2000-04-24 20:58:23 +00:00
|
|
|
while (environ[ne])
|
|
|
|
++ne;
|
2000-01-20 01:41:55 +00:00
|
|
|
typedef char * char_p;
|
|
|
|
env = new char_p[ne + 2];
|
2000-04-24 20:58:23 +00:00
|
|
|
string tmp = t2.str().c_str();
|
|
|
|
env[0] = new char[tmp.size() + 1];
|
|
|
|
std::copy(tmp.begin(), tmp.end(), env[0]);
|
|
|
|
env[0][tmp.size()] = '\0';
|
2000-04-16 22:27:30 +00:00
|
|
|
::memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
|
1999-09-27 18:44:28 +00:00
|
|
|
environ = env;
|
|
|
|
|
|
|
|
// now make gs command
|
|
|
|
// close(0);
|
|
|
|
// close(1); do NOT close. If GS writes out
|
|
|
|
// errors it would hang. (Matthias 290596)
|
2000-04-24 20:58:23 +00:00
|
|
|
|
|
|
|
string rbuf = "-r" + tostr(p->rx) + "x" + tostr(p->ry);
|
|
|
|
string gbuf = "-g" + tostr(p->data->wid) + "x" + tostr(p->data->hgh);
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
// now chdir into dir with .eps file, to be on the safe
|
|
|
|
// side
|
2000-09-26 13:54:57 +00:00
|
|
|
lyx::chdir(OnlyPath(p->data->fname));
|
1999-09-27 18:44:28 +00:00
|
|
|
// make temp file name
|
2000-04-24 20:58:23 +00:00
|
|
|
string tmpf = make_tmp(getpid());
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lyxerr.debugging()) {
|
2000-04-24 20:58:23 +00:00
|
|
|
lyxerr << "starting gs " << tmpf << " "
|
1999-12-16 06:43:25 +00:00
|
|
|
<< p->data->fname
|
|
|
|
<< ", pid: " << getpid() << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-04-16 22:27:30 +00:00
|
|
|
int err = ::execlp(lyxrc.ps_command.c_str(),
|
2000-03-12 10:35:05 +00:00
|
|
|
lyxrc.ps_command.c_str(),
|
1999-09-27 18:44:28 +00:00
|
|
|
"-sDEVICE=x11",
|
|
|
|
"-dNOPAUSE", "-dQUIET",
|
|
|
|
"-dSAFER",
|
2000-04-24 20:58:23 +00:00
|
|
|
rbuf.c_str(), gbuf.c_str(), tmpf.c_str(),
|
1999-09-27 18:44:28 +00:00
|
|
|
p->data->fname.c_str(),
|
1999-10-02 16:21:10 +00:00
|
|
|
"showpage.ps", "quit.ps", "-", 0);
|
1999-09-27 18:44:28 +00:00
|
|
|
// if we are still there, an error occurred.
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Error executing ghostscript. "
|
|
|
|
<< "Code: " << err << endl;
|
|
|
|
lyxerr.debug() << "Cmd: "
|
2000-03-12 10:35:05 +00:00
|
|
|
<< lyxrc.ps_command
|
1999-10-07 18:44:17 +00:00
|
|
|
<< " -sDEVICE=x11 "
|
2000-09-26 13:54:57 +00:00
|
|
|
<< tmpf << ' '
|
1999-10-07 18:44:17 +00:00
|
|
|
<< p->data->fname << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
_exit(0); // no gs?
|
|
|
|
}
|
|
|
|
// normal process (parent)
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "GS [" << pid << "] started" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-01-21 17:41:57 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
p->data->gspid = pid;
|
2000-01-21 17:41:57 +00:00
|
|
|
++gsrunning;
|
|
|
|
gsqueue.pop();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
// recompute the stuff and put in the queue
|
2000-01-21 17:41:57 +00:00
|
|
|
queue_element p;
|
|
|
|
p.ofsx = psx;
|
|
|
|
p.ofsy = psy;
|
|
|
|
p.rx = (float(data->raw_wid) * 72.0) / pswid;
|
|
|
|
p.ry = (float(data->raw_hgh) * 72.0) / pshgh;
|
|
|
|
|
|
|
|
p.data = data;
|
|
|
|
|
|
|
|
gsqueue.push(p);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// if possible, run the queue
|
|
|
|
runqueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
figdata * getfigdata(int wid, int hgh, string const & fname,
|
2000-04-24 20:58:23 +00:00
|
|
|
int psx, int psy, int pswid, int pshgh,
|
|
|
|
int raw_wid, int raw_hgh, float angle, char flags)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
/* first search for an exact match with fname and width/height */
|
|
|
|
|
2000-04-28 14:42:59 +00:00
|
|
|
if (fname.empty() || !IsFileReadable(fname))
|
|
|
|
return 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
for (bitmaps_type::iterator it = bitmaps.begin();
|
|
|
|
it != bitmaps.end(); ++it) {
|
|
|
|
if ((*it)->wid == wid && (*it)->hgh == hgh &&
|
|
|
|
(*it)->flags == flags && (*it)->fname == fname &&
|
|
|
|
(*it)->angle == angle) {
|
|
|
|
(*it)->ref++;
|
|
|
|
return (*it);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
1999-12-01 00:57:31 +00:00
|
|
|
figdata * p = new figdata;
|
1999-09-27 18:44:28 +00:00
|
|
|
p->wid = wid;
|
|
|
|
p->hgh = hgh;
|
|
|
|
p->raw_wid = raw_wid;
|
|
|
|
p->raw_hgh = raw_hgh;
|
|
|
|
p->angle = angle;
|
|
|
|
p->fname = fname;
|
|
|
|
p->flags = flags;
|
2000-03-12 10:35:05 +00:00
|
|
|
bitmaps.push_back(p);
|
1999-12-01 00:57:31 +00:00
|
|
|
XWindowAttributes wa;
|
2000-10-11 21:06:43 +00:00
|
|
|
XGetWindowAttributes(fl_get_display(), fl_get_canvas_id(
|
1999-09-27 18:44:28 +00:00
|
|
|
figinset_canvas), &wa);
|
|
|
|
|
|
|
|
if (lyxerr.debugging()) {
|
2000-10-11 21:06:43 +00:00
|
|
|
lyxerr << "Create pixmap disp:" << fl_get_display()
|
|
|
|
<< " scr:" << DefaultScreen(fl_get_display())
|
1999-10-07 18:44:17 +00:00
|
|
|
<< " w:" << wid
|
|
|
|
<< " h:" << hgh
|
|
|
|
<< " depth:" << wa.depth << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
p->ref = 1;
|
|
|
|
p->reading = false;
|
|
|
|
p->broken = false;
|
|
|
|
p->gspid = -1;
|
|
|
|
if (flags) {
|
2000-10-11 21:06:43 +00:00
|
|
|
p->bitmap = XCreatePixmap(fl_get_display(), fl_get_canvas_id(
|
1999-09-27 18:44:28 +00:00
|
|
|
figinset_canvas), wid, hgh, wa.depth);
|
|
|
|
p->gsdone = false;
|
|
|
|
// initialize reading of .eps file with correct sizes and stuff
|
|
|
|
addwait(psx, psy, pswid, pshgh, p);
|
|
|
|
p->reading = true;
|
|
|
|
} else {
|
|
|
|
p->bitmap = None;
|
|
|
|
p->gsdone = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-23 16:39:03 +00:00
|
|
|
void getbitmap(figdata * p)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
p->gspid = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-23 16:39:03 +00:00
|
|
|
void makeupdatelist(figdata * p)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-11-04 10:00:12 +00:00
|
|
|
for (figures_type::iterator it = figures.begin();
|
2000-03-12 10:35:05 +00:00
|
|
|
it != figures.end(); ++it)
|
|
|
|
if ((*it)->data == p) {
|
1999-12-01 00:57:31 +00:00
|
|
|
if (lyxerr.debugging()) {
|
|
|
|
lyxerr << "Updating inset "
|
2000-03-12 10:35:05 +00:00
|
|
|
<< (*it)->inset
|
1999-12-01 00:57:31 +00:00
|
|
|
<< endl;
|
|
|
|
}
|
|
|
|
// add inset figures[i]->inset into to_update list
|
2000-03-12 10:35:05 +00:00
|
|
|
current_view->pushIntoUpdateList((*it)->inset);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
// this func is only "called" in spellchecker.C
|
1999-12-01 00:57:31 +00:00
|
|
|
void sigchldchecker(pid_t pid, int * status)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Got pid = " << pid << endl;
|
1999-12-01 00:57:31 +00:00
|
|
|
bool pid_handled = false;
|
2000-03-12 10:35:05 +00:00
|
|
|
for (bitmaps_type::iterator it = bitmaps.begin();
|
|
|
|
it != bitmaps.end(); ++it) {
|
|
|
|
if ((*it)->reading && pid == (*it)->gspid) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Found pid in bitmaps" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
// now read the file and remove it from disk
|
2000-03-12 10:35:05 +00:00
|
|
|
figdata * p = (*it);
|
1999-09-27 18:44:28 +00:00
|
|
|
p->reading = false;
|
2000-03-12 10:35:05 +00:00
|
|
|
if ((*it)->gsdone) *status = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (*status == 0) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "GS [" << pid
|
|
|
|
<< "] exit OK." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "GS [" << pid << "] error "
|
|
|
|
<< *status << " E:"
|
|
|
|
<< WIFEXITED(*status)
|
|
|
|
<< " " << WEXITSTATUS(*status)
|
|
|
|
<< " S:" << WIFSIGNALED(*status)
|
|
|
|
<< " " << WTERMSIG(*status) << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
if (*status == 0) {
|
|
|
|
bitmap_waiting = true;
|
|
|
|
p->broken = false;
|
|
|
|
} else {
|
|
|
|
// remove temporary files
|
2000-09-26 13:54:57 +00:00
|
|
|
lyx::unlink(make_tmp(p->gspid));
|
1999-09-27 18:44:28 +00:00
|
|
|
p->gspid = -1;
|
|
|
|
p->broken = true;
|
|
|
|
}
|
2000-03-12 10:35:05 +00:00
|
|
|
makeupdatelist((*it));
|
2000-01-24 18:34:46 +00:00
|
|
|
--gsrunning;
|
1999-09-27 18:44:28 +00:00
|
|
|
runqueue();
|
|
|
|
pid_handled = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!pid_handled) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Checking pid in pidwait" << endl;
|
2000-01-21 18:33:54 +00:00
|
|
|
list<int>::iterator it = find(pidwaitlist.begin(),
|
|
|
|
pidwaitlist.end(), pid);
|
|
|
|
if (it != pidwaitlist.end()) {
|
|
|
|
lyxerr.debug() << "Found pid in pidwait\n"
|
|
|
|
<< "Caught child pid of recompute "
|
|
|
|
"routine" << pid << endl;
|
|
|
|
pidwaitlist.erase(it);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pid == -1) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "waitpid error" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
switch (errno) {
|
|
|
|
case ECHILD:
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "The process or process group specified by "
|
|
|
|
"pid does not exist or is not a child of "
|
|
|
|
"the calling process or can never be in the "
|
|
|
|
"states specified by options." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case EINTR:
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "waitpid() was interrupted due to the "
|
|
|
|
"receipt of a signal sent by the calling "
|
|
|
|
"process." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case EINVAL:
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "An invalid value was specified for "
|
|
|
|
"options." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Unknown error from waitpid" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (pid == 0) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "waitpid nohang" << endl;;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "normal exit from childhandler" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
void getbitmaps()
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
bitmap_waiting = false;
|
2000-03-12 10:35:05 +00:00
|
|
|
for (bitmaps_type::iterator it = bitmaps.begin();
|
|
|
|
it != bitmaps.end(); ++it)
|
|
|
|
if ((*it)->gspid > 0 && !(*it)->reading)
|
|
|
|
getbitmap((*it));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
void RegisterFigure(InsetFig * fi)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-12 10:35:05 +00:00
|
|
|
if (figures.empty()) InitFigures();
|
1999-10-02 16:21:10 +00:00
|
|
|
fi->form = 0;
|
1999-12-01 00:57:31 +00:00
|
|
|
Figref * tmpfig = new Figref;
|
1999-10-02 16:21:10 +00:00
|
|
|
tmpfig->data = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
tmpfig->inset = fi;
|
2000-03-12 10:35:05 +00:00
|
|
|
figures.push_back(tmpfig);
|
1999-09-27 18:44:28 +00:00
|
|
|
fi->figure = tmpfig;
|
|
|
|
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Register Figure: buffer:["
|
1999-11-09 22:53:41 +00:00
|
|
|
<< current_view->buffer() << "]" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-29 02:19:17 +00:00
|
|
|
void UnregisterFigure(InsetFig * fi)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-10-02 04:21:44 +00:00
|
|
|
if (!lyxrc.use_gui)
|
|
|
|
return;
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
Figref * tmpfig = fi->figure;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (tmpfig->data) freefigdata(tmpfig->data);
|
|
|
|
if (tmpfig->inset->form) {
|
1999-10-20 14:35:05 +00:00
|
|
|
if (tmpfig->inset->form->Figure->visible) {
|
|
|
|
fl_set_focus_object(tmpfig->inset->form->Figure,
|
|
|
|
tmpfig->inset->form->OkBtn);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_hide_form(tmpfig->inset->form->Figure);
|
1999-10-20 14:35:05 +00:00
|
|
|
}
|
1999-10-22 02:37:56 +00:00
|
|
|
#if FL_REVISION == 89
|
2000-04-26 13:57:28 +00:00
|
|
|
// CHECK Reactivate this free_form calls
|
1999-10-22 15:20:26 +00:00
|
|
|
#else
|
1999-10-22 02:37:56 +00:00
|
|
|
fl_free_form(tmpfig->inset->form->Figure);
|
2000-01-20 01:41:55 +00:00
|
|
|
free(tmpfig->inset->form); // Why free?
|
1999-10-22 02:37:56 +00:00
|
|
|
tmpfig->inset->form = 0;
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-03-12 10:35:05 +00:00
|
|
|
figures.erase(find(figures.begin(), figures.end(), tmpfig));
|
1999-09-27 18:44:28 +00:00
|
|
|
delete tmpfig;
|
|
|
|
|
2000-03-12 10:35:05 +00:00
|
|
|
if (figures.empty()) DoneFigures();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-10-10 11:50:43 +00:00
|
|
|
InsetFig::InsetFig(int tmpx, int tmpy, Buffer const & o)
|
|
|
|
: owner(&o)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
wid = tmpx;
|
|
|
|
hgh = tmpy;
|
|
|
|
wtype = DEF;
|
|
|
|
htype = DEF;
|
|
|
|
twtype = DEF;
|
|
|
|
thtype = DEF;
|
|
|
|
pflags = flags = 9;
|
|
|
|
psubfigure = subfigure = false;
|
|
|
|
xwid = xhgh = angle = 0;
|
2000-01-05 14:50:52 +00:00
|
|
|
pswid = pshgh = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
raw_wid = raw_hgh = 0;
|
|
|
|
changedfname = false;
|
|
|
|
RegisterFigure(this);
|
2001-03-15 18:21:56 +00:00
|
|
|
r_ = Dialogs::redrawGUI.connect(SigC::slot(this, &InsetFig::redraw));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetFig::~InsetFig()
|
|
|
|
{
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Figure destructor called" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
UnregisterFigure(this);
|
2000-11-28 06:46:06 +00:00
|
|
|
r_.disconnect();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFig::redraw()
|
|
|
|
{
|
|
|
|
if (form && form->Figure->visible)
|
|
|
|
fl_redraw_form(form->Figure);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetFig::ascent(BufferView *, LyXFont const &) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
return hgh + 3;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetFig::descent(BufferView *, LyXFont const &) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-07-05 14:57:48 +00:00
|
|
|
int InsetFig::width(BufferView *, LyXFont const &) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
return wid + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-21 15:07:57 +00:00
|
|
|
void InsetFig::draw(BufferView * bv, LyXFont const & f,
|
2000-06-23 15:02:46 +00:00
|
|
|
int baseline, float & x, bool) const
|
2000-02-10 17:53:36 +00:00
|
|
|
{
|
|
|
|
LyXFont font(f);
|
2000-06-21 15:07:57 +00:00
|
|
|
Painter & pain = bv->painter();
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
if (bitmap_waiting) getbitmaps();
|
|
|
|
|
|
|
|
// I wish that I didn't have to use this
|
|
|
|
// but the figinset code is so complicated so
|
|
|
|
// I don't want to fiddle with it now.
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
if (figure && figure->data && figure->data->bitmap &&
|
|
|
|
!figure->data->reading && !figure->data->broken) {
|
|
|
|
// draw the bitmap
|
2000-02-11 16:56:34 +00:00
|
|
|
pain.pixmap(int(x + 1), baseline - hgh,
|
|
|
|
wid, hgh, figure->data->bitmap);
|
|
|
|
|
|
|
|
if (flags & 4)
|
|
|
|
pain.rectangle(int(x), baseline - hgh - 1,
|
|
|
|
wid + 1, hgh + 1);
|
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
} else {
|
2000-10-11 21:06:43 +00:00
|
|
|
char const * msg = 0;
|
2000-08-31 15:11:15 +00:00
|
|
|
string lfname = fname;
|
2000-09-19 13:50:47 +00:00
|
|
|
if (!fname.empty() && GetExtension(fname).empty())
|
2000-08-31 15:11:15 +00:00
|
|
|
lfname += ".eps";
|
2000-02-10 17:53:36 +00:00
|
|
|
// draw frame
|
2000-05-20 21:37:05 +00:00
|
|
|
pain.rectangle(int(x), baseline - hgh - 1, wid + 1, hgh + 1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-02-10 17:53:36 +00:00
|
|
|
if (figure && figure->data) {
|
|
|
|
if (figure->data->broken) msg = _("[render error]");
|
|
|
|
else if (figure->data->reading) msg = _("[rendering ... ]");
|
2000-04-28 14:42:59 +00:00
|
|
|
}
|
|
|
|
else if (fname.empty())
|
|
|
|
msg = _("[no file]");
|
2000-08-31 15:11:15 +00:00
|
|
|
else if (!IsFileReadable(lfname))
|
2000-04-28 14:42:59 +00:00
|
|
|
msg = _("[bad file name]");
|
|
|
|
else if ((flags & 3) == 0)
|
|
|
|
msg = _("[not displayed]");
|
|
|
|
else if (lyxrc.ps_command.empty())
|
|
|
|
msg = _("[no ghostscript]");
|
2000-02-10 17:53:36 +00:00
|
|
|
|
|
|
|
if (!msg) msg = _("[unknown error]");
|
|
|
|
|
|
|
|
font.setFamily(LyXFont::SANS_FAMILY);
|
|
|
|
font.setSize(LyXFont::SIZE_FOOTNOTE);
|
|
|
|
string justname = OnlyFilename (fname);
|
2000-04-04 00:19:15 +00:00
|
|
|
pain.text(int(x + 8), baseline - lyxfont::maxAscent(font) - 4,
|
2000-02-10 17:53:36 +00:00
|
|
|
justname, font);
|
|
|
|
|
|
|
|
font.setSize(LyXFont::SIZE_TINY);
|
|
|
|
pain.text(int(x + 8), baseline - 4, msg, strlen(msg), font);
|
|
|
|
}
|
2000-07-05 14:57:48 +00:00
|
|
|
x += width(bv, font); // ?
|
2000-02-10 17:53:36 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetFig::Write(Buffer const *, ostream & os) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
Regenerate();
|
1999-12-07 00:44:53 +00:00
|
|
|
os << "Figure size " << wid << " " << hgh << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!fname.empty()) {
|
1999-12-16 06:43:25 +00:00
|
|
|
string buf1 = OnlyPath(owner->fileName());
|
|
|
|
string fname2 = MakeRelPath(fname, buf1);
|
|
|
|
os << "file " << fname2 << "\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
if (!subcaption.empty())
|
1999-12-07 00:44:53 +00:00
|
|
|
os << "subcaption " << subcaption << "\n";
|
1999-12-19 22:35:36 +00:00
|
|
|
if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
|
|
|
|
if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
|
1999-12-07 00:44:53 +00:00
|
|
|
if (angle != 0) os << "angle " << angle << "\n";
|
|
|
|
os << "flags " << flags << "\n";
|
|
|
|
if (subfigure) os << "subfigure\n";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
void InsetFig::Read(Buffer const *, LyXLex & lex)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string buf;
|
1999-09-27 18:44:28 +00:00
|
|
|
bool finished = false;
|
|
|
|
|
|
|
|
while (lex.IsOK() && !finished) {
|
|
|
|
lex.next();
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
string const token = lex.GetString();
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Token: " << token << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (token.empty())
|
|
|
|
continue;
|
|
|
|
else if (token == "\\end_inset") {
|
|
|
|
finished = true;
|
|
|
|
} else if (token == "file") {
|
|
|
|
if (lex.next()) {
|
|
|
|
buf = lex.GetString();
|
1999-12-10 00:07:59 +00:00
|
|
|
string buf1 = OnlyPath(owner->fileName());
|
1999-09-27 18:44:28 +00:00
|
|
|
fname = MakeAbsPath(buf, buf1);
|
|
|
|
changedfname = true;
|
|
|
|
}
|
|
|
|
} else if (token == "extra") {
|
|
|
|
if (lex.next());
|
|
|
|
// kept for backwards compability. Delete in 0.13.x
|
|
|
|
} else if (token == "subcaption") {
|
|
|
|
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();
|
|
|
|
} else if (token == "size") {
|
|
|
|
if (lex.next())
|
|
|
|
wid = lex.GetInteger();
|
|
|
|
if (lex.next())
|
|
|
|
hgh = lex.GetInteger();
|
|
|
|
} else if (token == "flags") {
|
|
|
|
if (lex.next())
|
|
|
|
flags = pflags = lex.GetInteger();
|
|
|
|
} else if (token == "subfigure") {
|
|
|
|
subfigure = psubfigure = true;
|
|
|
|
} else if (token == "width") {
|
|
|
|
int typ = 0;
|
|
|
|
if (lex.next())
|
|
|
|
typ = lex.GetInteger();
|
|
|
|
if (lex.next())
|
|
|
|
xwid = lex.GetFloat();
|
|
|
|
switch (typ) {
|
|
|
|
case DEF: wtype = DEF; break;
|
|
|
|
case CM: wtype = CM; break;
|
|
|
|
case IN: wtype = IN; break;
|
|
|
|
case PER_PAGE: wtype = PER_PAGE; break;
|
|
|
|
case PER_COL: wtype = PER_COL; break;
|
|
|
|
default:
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Unknown type!" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
twtype = wtype;
|
|
|
|
} else if (token == "height") {
|
|
|
|
int typ = 0;
|
|
|
|
if (lex.next())
|
|
|
|
typ = lex.GetInteger();
|
|
|
|
if (lex.next())
|
|
|
|
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:
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Unknown type!" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
thtype = htype;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Regenerate();
|
|
|
|
Recompute();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetFig::Latex(Buffer const *, ostream & os,
|
2000-04-19 01:42:55 +00:00
|
|
|
bool /* fragile*/, bool /* fs*/) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
Regenerate();
|
1999-12-07 00:44:53 +00:00
|
|
|
if (!cmd.empty()) os << cmd << " ";
|
1999-09-27 18:44:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-26 15:25:14 +00:00
|
|
|
int InsetFig::Ascii(Buffer const *, ostream &, int) const
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetFig::Linuxdoc(Buffer const *, ostream &) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-06-12 11:27:15 +00:00
|
|
|
int InsetFig::DocBook(Buffer const *, ostream & os) const
|
2000-03-06 02:42:40 +00:00
|
|
|
{
|
2000-06-12 11:27:15 +00:00
|
|
|
string buf1 = OnlyPath(owner->fileName());
|
|
|
|
string figurename = MakeRelPath(fname, buf1);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
2000-11-04 10:00:12 +00:00
|
|
|
if (suffixIs(figurename, ".eps"))
|
2000-09-29 11:12:11 +00:00
|
|
|
figurename.erase(figurename.length() - 4);
|
2000-03-06 02:42:40 +00:00
|
|
|
|
|
|
|
os << "@<graphic fileref=\"" << figurename << "\"></graphic>";
|
|
|
|
return 0;
|
2000-06-12 11:27:15 +00:00
|
|
|
}
|
2000-03-06 02:42:40 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
void InsetFig::Validate(LaTeXFeatures & features) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
features.graphics = true;
|
|
|
|
if (subfigure) features.subfigure = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-03-08 13:52:57 +00:00
|
|
|
Inset::EDITABLE InsetFig::Editable() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-03-08 13:52:57 +00:00
|
|
|
return IS_EDITABLE;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetFig::Deletable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
string const InsetFig::EditMessage() const
|
2000-04-04 00:19:15 +00:00
|
|
|
{
|
|
|
|
return _("Opened figure");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-25 12:06:15 +00:00
|
|
|
void InsetFig::Edit(BufferView * bv, int, int, unsigned int)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Editing InsetFig." << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
Regenerate();
|
|
|
|
|
|
|
|
// We should have RO-versions of the form instead.
|
|
|
|
// The actual prevention of altering a readonly doc
|
|
|
|
// is done in CallbackFig()
|
2000-11-04 10:00:12 +00:00
|
|
|
if (bv->buffer()->isReadonly())
|
2000-02-22 00:36:17 +00:00
|
|
|
WarnReadonly(bv->buffer()->fileName());
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!form) {
|
|
|
|
form = create_form_Figure();
|
1999-10-02 16:21:10 +00:00
|
|
|
fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
|
1999-11-15 10:58:38 +00:00
|
|
|
fl_set_object_return(form->Angle, FL_RETURN_ALWAYS);
|
|
|
|
fl_set_object_return(form->Width, FL_RETURN_ALWAYS);
|
|
|
|
fl_set_object_return(form->Height, FL_RETURN_ALWAYS);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
RestoreForm();
|
|
|
|
if (form->Figure->visible) {
|
|
|
|
fl_raise_form(form->Figure);
|
|
|
|
} else {
|
2000-11-08 09:39:46 +00:00
|
|
|
fl_show_form(form->Figure,
|
|
|
|
FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
|
|
|
|
_("Figure"));
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-10-10 11:50:43 +00:00
|
|
|
Inset * InsetFig::Clone(Buffer const & buffer) const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-10-10 11:50:43 +00:00
|
|
|
InsetFig * tmp = new InsetFig(100, 100, buffer);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Clone Figure: buffer:["
|
2000-10-10 11:50:43 +00:00
|
|
|
<< &buffer
|
1999-10-07 18:44:17 +00:00
|
|
|
<< "], cbuffer:[xx]" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tmp->wid = wid;
|
|
|
|
tmp->hgh = hgh;
|
|
|
|
tmp->raw_wid = raw_wid;
|
|
|
|
tmp->raw_hgh = raw_hgh;
|
|
|
|
tmp->angle = angle;
|
|
|
|
tmp->xwid = xwid;
|
|
|
|
tmp->xhgh = xhgh;
|
|
|
|
tmp->flags = flags;
|
|
|
|
tmp->pflags = pflags;
|
|
|
|
tmp->subfigure = subfigure;
|
|
|
|
tmp->psubfigure = psubfigure;
|
|
|
|
tmp->wtype = wtype;
|
|
|
|
tmp->htype = htype;
|
|
|
|
tmp->psx = psx;
|
|
|
|
tmp->psy = psy;
|
|
|
|
tmp->pswid = pswid;
|
|
|
|
tmp->pshgh = pshgh;
|
|
|
|
tmp->fname = fname;
|
2000-04-28 14:42:59 +00:00
|
|
|
if (!fname.empty() && IsFileReadable(fname)
|
|
|
|
&& (flags & 3) && !lyxrc.ps_command.empty()
|
2000-03-20 16:37:50 +00:00
|
|
|
&& lyxrc.use_gui) {
|
1999-12-16 06:43:25 +00:00
|
|
|
// do not display if there is
|
|
|
|
// "do not display" chosen (Matthias 260696)
|
1999-09-27 18:44:28 +00:00
|
|
|
tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
|
|
|
|
pswid, pshgh, raw_wid, raw_hgh,
|
|
|
|
angle, flags & (3|8));
|
1999-10-02 16:21:10 +00:00
|
|
|
} else tmp->figure->data = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
tmp->subcaption = subcaption;
|
|
|
|
tmp->changedfname = false;
|
|
|
|
tmp->owner = owner;
|
|
|
|
tmp->Regenerate();
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Inset::Code InsetFig::LyxCode() const
|
|
|
|
{
|
|
|
|
return Inset::GRAPHICS_CODE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
string const stringify(InsetFig::HWTYPE hw, float f, string suffix)
|
2000-04-24 20:58:23 +00:00
|
|
|
{
|
|
|
|
string res;
|
|
|
|
switch (hw) {
|
|
|
|
case InsetFig::DEF:
|
|
|
|
break;
|
|
|
|
case InsetFig::CM:// \resizebox*{h-length}{v-length}{text}
|
|
|
|
res = tostr(f) + "cm";
|
|
|
|
break;
|
|
|
|
case InsetFig::IN:
|
|
|
|
res = tostr(f) + "in";
|
|
|
|
break;
|
|
|
|
case InsetFig::PER_PAGE:
|
|
|
|
res = tostr(f/100) + "\\text" + suffix;
|
|
|
|
break;
|
|
|
|
case InsetFig::PER_COL:
|
|
|
|
// Doesn't occur for htype...
|
|
|
|
res = tostr(f/100) + "\\column" + suffix;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2001-03-20 01:22:46 +00:00
|
|
|
} // namespace anon
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
|
2000-02-18 22:22:42 +00:00
|
|
|
void InsetFig::Regenerate() const
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string cmdbuf;
|
|
|
|
string resizeW, resizeH;
|
|
|
|
string rotate, recmd;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (fname.empty()) {
|
|
|
|
cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
|
|
|
|
cmd += _("empty figure path");
|
|
|
|
cmd += '}';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
string buf1 = OnlyPath(owner->fileName());
|
1999-10-02 16:21:10 +00:00
|
|
|
string fname2 = MakeRelPath(fname, buf1);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
string gcmd = "\\includegraphics{" + fname2 + '}';
|
2000-04-24 20:58:23 +00:00
|
|
|
resizeW = stringify(wtype, xwid, "width");
|
|
|
|
resizeH = stringify(htype, xhgh, "height");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!resizeW.empty() || !resizeH.empty()) {
|
|
|
|
recmd = "\\resizebox*{";
|
|
|
|
if (!resizeW.empty())
|
|
|
|
recmd += resizeW;
|
|
|
|
else
|
|
|
|
recmd += '!';
|
|
|
|
recmd += "}{";
|
|
|
|
if (!resizeH.empty())
|
|
|
|
recmd += resizeH;
|
|
|
|
else
|
|
|
|
recmd += '!';
|
|
|
|
recmd += "}{";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (angle != 0) {
|
|
|
|
// \rotatebox{angle}{text}
|
2000-04-24 20:58:23 +00:00
|
|
|
rotate = "\\rotatebox{" + tostr(angle) + "}{";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmdbuf = recmd;
|
|
|
|
cmdbuf += rotate;
|
|
|
|
cmdbuf += gcmd;
|
|
|
|
if (!rotate.empty()) cmdbuf += '}';
|
|
|
|
if (!recmd.empty()) cmdbuf += '}';
|
|
|
|
if (subfigure) {
|
|
|
|
if (!subcaption.empty())
|
|
|
|
cmdbuf = "\\subfigure[" + subcaption +
|
1999-12-16 06:43:25 +00:00
|
|
|
"]{" + cmdbuf + "}";
|
1999-09-27 18:44:28 +00:00
|
|
|
else
|
|
|
|
cmdbuf = "\\subfigure{" + cmdbuf + "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd = cmdbuf;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFig::TempRegenerate()
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
string cmdbuf;
|
|
|
|
string resizeW, resizeH;
|
|
|
|
string rotate, recmd;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
char const * tfname = fl_get_input(form->EpsFile);
|
|
|
|
string tsubcap = fl_get_input(form->Subcaption);
|
|
|
|
float tangle = atof(fl_get_input(form->Angle));
|
|
|
|
float txwid = atof(fl_get_input(form->Width));
|
|
|
|
float txhgh = atof(fl_get_input(form->Height));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (!tfname || !*tfname) {
|
2000-04-24 20:58:23 +00:00
|
|
|
cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
|
|
|
|
cmd += _("empty figure path");
|
1999-09-27 18:44:28 +00:00
|
|
|
cmd += '}';
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
string buf1 = OnlyPath(owner->fileName());
|
1999-10-02 16:21:10 +00:00
|
|
|
string fname2 = MakeRelPath(tfname, buf1);
|
1999-09-27 18:44:28 +00:00
|
|
|
// \includegraphics*[<llx,lly>][<urx,ury>]{file}
|
1999-12-01 00:57:31 +00:00
|
|
|
string gcmd = "\\includegraphics{" + fname2 + '}';
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
resizeW = stringify(twtype, txwid, "width");
|
|
|
|
resizeH = stringify(thtype, txhgh, "height");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// \resizebox*{h-length}{v-length}{text}
|
|
|
|
if (!resizeW.empty() || !resizeH.empty()) {
|
|
|
|
recmd = "\\resizebox*{";
|
|
|
|
if (!resizeW.empty())
|
|
|
|
recmd += resizeW;
|
|
|
|
else
|
|
|
|
recmd += '!';
|
|
|
|
recmd += "}{";
|
|
|
|
if (!resizeH.empty())
|
|
|
|
recmd += resizeH;
|
|
|
|
else
|
|
|
|
recmd += '!';
|
|
|
|
recmd += "}{";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tangle != 0) {
|
|
|
|
// \rotatebox{angle}{text}
|
2000-04-24 20:58:23 +00:00
|
|
|
rotate = "\\rotatebox{" + tostr(tangle) + "}{";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
2000-04-24 20:58:23 +00:00
|
|
|
cmdbuf = recmd + rotate + gcmd;
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!rotate.empty()) cmdbuf += '}';
|
|
|
|
if (!recmd.empty()) cmdbuf += '}';
|
|
|
|
if (psubfigure && !tsubcap.empty()) {
|
1999-10-02 16:21:10 +00:00
|
|
|
cmdbuf = string("\\subfigure{") + tsubcap
|
1999-12-16 06:43:25 +00:00
|
|
|
+ string("}{") + cmdbuf + "}";
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFig::Recompute()
|
|
|
|
{
|
2000-10-02 04:21:44 +00:00
|
|
|
if (!lyxrc.use_gui)
|
|
|
|
return;
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
bool changed = changedfname;
|
1999-12-01 00:57:31 +00:00
|
|
|
int newx, newy, nraw_x, nraw_y;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (changed) GetPSSizes();
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
|
|
|
|
float cos_a = cos (angle / DEG2PI);
|
1999-12-13 00:05:34 +00:00
|
|
|
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)));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2000-08-31 15:11:15 +00:00
|
|
|
string lfname = fname;
|
|
|
|
if (GetExtension(fname).empty())
|
|
|
|
lfname += ".eps";
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
/* now recompute wid and hgh, and if that is changed, set changed */
|
|
|
|
/* this depends on chosen size of the picture and its bbox */
|
|
|
|
// This will be redone in 0.13 ... (hen)
|
2000-08-31 15:11:15 +00:00
|
|
|
if (!lfname.empty() && IsFileReadable(lfname)) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// say, total width is 595 pts, as A4 in TeX, thats in 1/72" */
|
|
|
|
|
|
|
|
newx = frame_wid;
|
|
|
|
newy = frame_hgh;
|
|
|
|
switch (wtype) {
|
|
|
|
case DEF:
|
|
|
|
break;
|
|
|
|
case CM: /* cm */
|
1999-12-13 00:05:34 +00:00
|
|
|
newx = int(28.346 * xwid);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case IN: /* in */
|
1999-12-13 00:05:34 +00:00
|
|
|
newx = int(72 * xwid);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case PER_PAGE: /* % of page */
|
1999-12-13 00:05:34 +00:00
|
|
|
newx = int(5.95 * xwid);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case PER_COL: /* % of col */
|
1999-12-13 00:05:34 +00:00
|
|
|
newx = int(2.975 * xwid);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
|
|
|
|
|
|
|
|
switch (htype) {
|
|
|
|
case DEF:
|
1999-10-07 18:44:17 +00:00
|
|
|
//lyxerr << "This should not happen!" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
1999-10-07 18:44:17 +00:00
|
|
|
case CM: /* cm */
|
1999-12-13 00:05:34 +00:00
|
|
|
newy = int(28.346 * xhgh);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
case IN: /* in */
|
1999-12-13 00:05:34 +00:00
|
|
|
newy = int(72 * xhgh);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
1999-10-07 18:44:17 +00:00
|
|
|
case PER_PAGE: /* % of page */
|
1999-12-13 00:05:34 +00:00
|
|
|
newy = int(8.42 * xhgh);
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
1999-10-07 18:44:17 +00:00
|
|
|
case PER_COL:
|
|
|
|
// Doesn't occur; case exists to suppress
|
1999-09-27 18:44:28 +00:00
|
|
|
// compiler warnings.
|
|
|
|
break;
|
|
|
|
}
|
1999-12-16 06:43:25 +00:00
|
|
|
if (htype && !wtype && frame_hgh)
|
|
|
|
newx = newy*frame_wid/frame_hgh;
|
1999-09-27 18:44:28 +00:00
|
|
|
} else {
|
|
|
|
newx = wid;
|
|
|
|
newy = hgh;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame_wid == 0)
|
|
|
|
nraw_x = 5;
|
|
|
|
else
|
1999-12-13 00:05:34 +00:00
|
|
|
nraw_x = int((1.0 * pswid * newx)/frame_wid);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (frame_hgh == 0)
|
|
|
|
nraw_y = 5;
|
|
|
|
else
|
1999-12-13 00:05:34 +00:00
|
|
|
nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// cannot be zero, actually, set it to some minimum, so its clickable
|
|
|
|
if (newx < 5) newx = 5;
|
|
|
|
if (newy < 5) newy = 5;
|
|
|
|
|
|
|
|
if (newx != wid || newy != hgh ||
|
|
|
|
nraw_x != raw_wid || nraw_y != raw_hgh ||
|
|
|
|
flags != pflags || subfigure != psubfigure)
|
|
|
|
changed = true;
|
|
|
|
|
|
|
|
raw_wid = nraw_x;
|
|
|
|
raw_hgh = nraw_y;
|
|
|
|
wid = newx;
|
|
|
|
hgh = newy;
|
|
|
|
flags = pflags;
|
|
|
|
subfigure = psubfigure;
|
|
|
|
|
|
|
|
if (changed) {
|
1999-12-01 00:57:31 +00:00
|
|
|
figdata * pf = figure->data;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// get new data
|
2000-08-31 15:11:15 +00:00
|
|
|
if (!lfname.empty() && IsFileReadable(lfname) && (flags & 3)
|
2000-03-12 10:35:05 +00:00
|
|
|
&& !lyxrc.ps_command.empty()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
// do not display if there is "do not display"
|
|
|
|
// chosen (Matthias 260696)
|
2000-08-31 15:11:15 +00:00
|
|
|
figure->data = getfigdata(wid, hgh, lfname,
|
1999-09-27 18:44:28 +00:00
|
|
|
psx, psy, pswid, pshgh,
|
|
|
|
raw_wid, raw_hgh,
|
|
|
|
angle, flags & (3|8));
|
1999-10-02 16:21:10 +00:00
|
|
|
} else figure->data = 0;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
// free the old data
|
|
|
|
if (pf) freefigdata(pf);
|
|
|
|
}
|
|
|
|
|
|
|
|
changedfname = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFig::GetPSSizes()
|
|
|
|
{
|
|
|
|
/* get %%BoundingBox: from postscript file */
|
|
|
|
|
|
|
|
/* defaults to associated size
|
1999-11-15 10:58:38 +00:00
|
|
|
* ..just in case the PS-file is not readable (Henner, 24-Aug-97)
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
|
|
|
psx = 0;
|
|
|
|
psy = 0;
|
|
|
|
pswid = wid;
|
|
|
|
pshgh = hgh;
|
|
|
|
|
|
|
|
if (fname.empty()) return;
|
2000-01-06 02:44:26 +00:00
|
|
|
string p;
|
|
|
|
ifstream ifs(fname.c_str());
|
1999-11-24 22:14:46 +00:00
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
if (!ifs) return; // file not found !!!!
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
/* defaults to A4 page */
|
|
|
|
psx = 0;
|
|
|
|
psy = 0;
|
|
|
|
pswid = 595;
|
|
|
|
pshgh = 842;
|
|
|
|
|
2000-01-06 02:44:26 +00:00
|
|
|
char lastchar = 0; ifs.get(lastchar);
|
1999-09-27 18:44:28 +00:00
|
|
|
for (;;) {
|
2000-01-06 02:44:26 +00:00
|
|
|
char c = 0; ifs.get(c);
|
|
|
|
if (ifs.eof()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "End of (E)PS file reached and"
|
|
|
|
" no BoundingBox!" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (c == '%' && lastchar == '%') {
|
2000-04-16 22:27:30 +00:00
|
|
|
ifs >> p;
|
2000-01-06 02:44:26 +00:00
|
|
|
if (p.empty()) break;
|
|
|
|
lyxerr.debug() << "Token: `" << p << "'" << endl;
|
|
|
|
if (p == "BoundingBox:") {
|
1999-09-27 18:44:28 +00:00
|
|
|
float fpsx, fpsy, fpswid, fpshgh;
|
2000-01-06 02:44:26 +00:00
|
|
|
if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
|
1999-12-13 00:05:34 +00:00
|
|
|
psx = int(fpsx);
|
|
|
|
psy = int(fpsy);
|
|
|
|
pswid = int(fpswid);
|
|
|
|
pshgh = int(fpshgh);
|
2000-01-06 02:44:26 +00:00
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "%%%%BoundingBox:"
|
|
|
|
<< psx << ' '
|
|
|
|
<< psy << ' '
|
|
|
|
<< pswid << ' '
|
|
|
|
<< pshgh << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-11-24 22:14:46 +00:00
|
|
|
break;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
c = 0;
|
|
|
|
}
|
|
|
|
lastchar = c;
|
|
|
|
}
|
|
|
|
pswid -= psx;
|
|
|
|
pshgh -= psy;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFig::CallbackFig(long arg)
|
|
|
|
{
|
|
|
|
bool regen = false;
|
1999-12-01 00:57:31 +00:00
|
|
|
char const * p;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
if (lyxerr.debugging()) {
|
1999-12-16 06:43:25 +00:00
|
|
|
lyxerr << "Figure callback, arg " << arg << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (arg) {
|
|
|
|
case 10:
|
|
|
|
case 11:
|
|
|
|
case 12: /* width type */
|
|
|
|
case 13:
|
|
|
|
case 14:
|
|
|
|
switch (arg - 10) {
|
|
|
|
case DEF:
|
|
|
|
twtype = DEF;
|
|
|
|
// put disable here
|
|
|
|
fl_deactivate_object(form->Width);
|
|
|
|
break;
|
|
|
|
case CM:
|
|
|
|
twtype = CM;
|
|
|
|
// put enable here
|
|
|
|
fl_activate_object(form->Width);
|
|
|
|
break;
|
|
|
|
case IN:
|
|
|
|
twtype = IN;
|
|
|
|
// put enable here
|
|
|
|
fl_activate_object(form->Width);
|
|
|
|
break;
|
|
|
|
case PER_PAGE:
|
|
|
|
twtype = PER_PAGE;
|
|
|
|
// put enable here
|
|
|
|
fl_activate_object(form->Width);
|
|
|
|
break;
|
|
|
|
case PER_COL:
|
|
|
|
twtype = PER_COL;
|
|
|
|
// put enable here
|
|
|
|
fl_activate_object(form->Width);
|
|
|
|
break;
|
|
|
|
default:
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Unknown type!" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
regen = true;
|
|
|
|
break;
|
|
|
|
case 20:
|
|
|
|
case 21:
|
|
|
|
case 22: /* height type */
|
|
|
|
case 23:
|
|
|
|
switch (arg - 20) {
|
|
|
|
case DEF:
|
|
|
|
thtype = DEF;
|
|
|
|
// put disable here
|
|
|
|
fl_deactivate_object(form->Height);
|
|
|
|
break;
|
|
|
|
case CM:
|
|
|
|
thtype = CM;
|
|
|
|
// put enable here
|
|
|
|
fl_activate_object(form->Height);
|
|
|
|
break;
|
|
|
|
case IN:
|
|
|
|
thtype = IN;
|
|
|
|
// put enable here
|
|
|
|
fl_activate_object(form->Height);
|
|
|
|
break;
|
|
|
|
case PER_PAGE:
|
|
|
|
thtype = PER_PAGE;
|
|
|
|
// put enable here
|
|
|
|
fl_activate_object(form->Height);
|
|
|
|
break;
|
|
|
|
default:
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr.debug() << "Unknown type!" << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
regen = true;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pflags = pflags & ~3; /* wysiwyg0 */
|
|
|
|
break;
|
|
|
|
case 33:
|
|
|
|
pflags = (pflags & ~3) | 1; /* wysiwyg1 */
|
|
|
|
break;
|
|
|
|
case 43:
|
|
|
|
pflags = (pflags & ~3) | 2; /* wysiwyg2 */
|
|
|
|
break;
|
|
|
|
case 63:
|
|
|
|
pflags = (pflags & ~3) | 3; /* wysiwyg3 */
|
|
|
|
break;
|
|
|
|
case 53:
|
|
|
|
pflags ^= 4; /* frame */
|
|
|
|
break;
|
|
|
|
case 54:
|
|
|
|
pflags ^= 8; /* do translations */
|
|
|
|
break;
|
|
|
|
case 70:
|
|
|
|
psubfigure = !psubfigure; /* This is a subfigure */
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
regen = true; /* regenerate command */
|
|
|
|
break;
|
|
|
|
case 0: /* browse file */
|
|
|
|
BrowseFile();
|
|
|
|
regen = true;
|
|
|
|
break;
|
|
|
|
case 1: /* preview */
|
|
|
|
p = fl_get_input(form->EpsFile);
|
|
|
|
Preview(p);
|
|
|
|
break;
|
|
|
|
case 7: /* apply */
|
|
|
|
case 8: /* ok (apply and close) */
|
2000-11-04 10:00:12 +00:00
|
|
|
if (!current_view->buffer()->isReadonly()) {
|
1999-09-27 18:44:28 +00:00
|
|
|
wtype = twtype;
|
|
|
|
htype = thtype;
|
|
|
|
xwid = atof(fl_get_input(form->Width));
|
|
|
|
xhgh = atof(fl_get_input(form->Height));
|
|
|
|
angle = atof(fl_get_input(form->Angle));
|
|
|
|
p = fl_get_input(form->EpsFile);
|
|
|
|
if (p && *p) {
|
1999-12-10 00:07:59 +00:00
|
|
|
string buf1 = OnlyPath(owner->fileName());
|
1999-09-27 18:44:28 +00:00
|
|
|
fname = MakeAbsPath(p, buf1);
|
|
|
|
changedfname = true;
|
|
|
|
} else {
|
|
|
|
if (!fname.empty()) {
|
|
|
|
changedfname = true;
|
2000-05-04 10:57:00 +00:00
|
|
|
fname.erase();
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
subcaption = fl_get_input(form->Subcaption);
|
|
|
|
|
|
|
|
Regenerate();
|
|
|
|
Recompute();
|
|
|
|
/* now update inset */
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Update: ["
|
|
|
|
<< wid << 'x' << hgh << ']' << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-02-23 16:39:03 +00:00
|
|
|
current_view->updateInset(this, true);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (arg == 8) {
|
1999-10-20 14:35:05 +00:00
|
|
|
fl_set_focus_object(form->Figure, form->OkBtn);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_hide_form(form->Figure);
|
1999-10-22 02:37:56 +00:00
|
|
|
#if FL_REVISION == 89
|
2000-04-26 13:57:28 +00:00
|
|
|
// CHECK Reactivate this free_form calls
|
1999-10-22 15:20:26 +00:00
|
|
|
#else
|
1999-10-22 02:37:56 +00:00
|
|
|
fl_free_form(form->Figure);
|
2000-01-20 01:41:55 +00:00
|
|
|
free(form); // Why free?
|
1999-10-22 02:37:56 +00:00
|
|
|
form = 0;
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
} //if not readonly
|
|
|
|
// The user has already been informed about RO in ::Edit
|
2000-11-04 10:00:12 +00:00
|
|
|
if (arg == 7) // if 'Apply'
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
// fall through
|
|
|
|
case 9: /* cancel = restore and close */
|
1999-10-20 14:35:05 +00:00
|
|
|
fl_set_focus_object(form->Figure, form->OkBtn);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_hide_form(form->Figure);
|
1999-10-22 02:37:56 +00:00
|
|
|
#if FL_REVISION == 89
|
2000-04-26 13:57:28 +00:00
|
|
|
// CHECK Reactivate this free_form calls
|
|
|
|
// Jug, is this still a problem?
|
1999-10-22 15:20:26 +00:00
|
|
|
#else
|
1999-10-22 02:37:56 +00:00
|
|
|
fl_free_form(form->Figure);
|
2000-01-20 01:41:55 +00:00
|
|
|
free(form); // Why free?
|
1999-10-22 02:37:56 +00:00
|
|
|
form = 0;
|
|
|
|
#endif
|
1999-09-27 18:44:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (regen) TempRegenerate();
|
|
|
|
}
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
void DisableFigurePanel(FD_Figure * const form)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
fl_deactivate_object(form->EpsFile);
|
|
|
|
fl_deactivate_object(form->Browse);
|
|
|
|
fl_deactivate_object(form->Width);
|
|
|
|
fl_deactivate_object(form->Height);
|
|
|
|
fl_deactivate_object(form->Frame);
|
|
|
|
fl_deactivate_object(form->Translations);
|
|
|
|
fl_deactivate_object(form->Angle);
|
|
|
|
fl_deactivate_object(form->HeightGrp);
|
|
|
|
fl_deactivate_object(form->page2);
|
|
|
|
fl_deactivate_object(form->Default2);
|
|
|
|
fl_deactivate_object(form->cm2);
|
|
|
|
fl_deactivate_object(form->in2);
|
|
|
|
fl_deactivate_object(form->HeightLabel);
|
|
|
|
fl_deactivate_object(form->WidthLabel);
|
|
|
|
fl_deactivate_object(form->DisplayGrp);
|
|
|
|
fl_deactivate_object(form->Wysiwyg3);
|
|
|
|
fl_deactivate_object(form->Wysiwyg0);
|
|
|
|
fl_deactivate_object(form->Wysiwyg2);
|
|
|
|
fl_deactivate_object(form->Wysiwyg1);
|
|
|
|
fl_deactivate_object(form->WidthGrp);
|
|
|
|
fl_deactivate_object(form->Default1);
|
|
|
|
fl_deactivate_object(form->cm1);
|
|
|
|
fl_deactivate_object(form->in1);
|
|
|
|
fl_deactivate_object(form->page1);
|
|
|
|
fl_deactivate_object(form->column1);
|
|
|
|
fl_deactivate_object(form->Subcaption);
|
|
|
|
fl_deactivate_object(form->Subfigure);
|
|
|
|
fl_deactivate_object (form->OkBtn);
|
|
|
|
fl_deactivate_object (form->ApplyBtn);
|
|
|
|
fl_set_object_lcol (form->OkBtn, FL_INACTIVE);
|
|
|
|
fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
|
|
|
|
}
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
|
2000-03-07 01:14:37 +00:00
|
|
|
inline
|
|
|
|
void EnableFigurePanel(FD_Figure * const form)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
fl_activate_object(form->EpsFile);
|
|
|
|
fl_activate_object(form->Browse);
|
|
|
|
fl_activate_object(form->Width);
|
|
|
|
fl_activate_object(form->Height);
|
|
|
|
fl_activate_object(form->Frame);
|
|
|
|
fl_activate_object(form->Translations);
|
|
|
|
fl_activate_object(form->Angle);
|
|
|
|
fl_activate_object(form->HeightGrp);
|
|
|
|
fl_activate_object(form->page2);
|
|
|
|
fl_activate_object(form->Default2);
|
|
|
|
fl_activate_object(form->cm2);
|
|
|
|
fl_activate_object(form->in2);
|
|
|
|
fl_activate_object(form->HeightLabel);
|
|
|
|
fl_activate_object(form->WidthLabel);
|
|
|
|
fl_activate_object(form->DisplayGrp);
|
|
|
|
fl_activate_object(form->Wysiwyg3);
|
|
|
|
fl_activate_object(form->Wysiwyg0);
|
|
|
|
fl_activate_object(form->Wysiwyg2);
|
|
|
|
fl_activate_object(form->Wysiwyg1);
|
|
|
|
fl_activate_object(form->WidthGrp);
|
|
|
|
fl_activate_object(form->Default1);
|
|
|
|
fl_activate_object(form->cm1);
|
|
|
|
fl_activate_object(form->in1);
|
|
|
|
fl_activate_object(form->page1);
|
|
|
|
fl_activate_object(form->column1);
|
|
|
|
fl_activate_object(form->Subcaption);
|
|
|
|
fl_activate_object(form->Subfigure);
|
|
|
|
fl_activate_object (form->OkBtn);
|
|
|
|
fl_activate_object (form->ApplyBtn);
|
|
|
|
fl_set_object_lcol (form->OkBtn, FL_BLACK);
|
|
|
|
fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
|
|
|
|
}
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
void InsetFig::RestoreForm()
|
|
|
|
{
|
|
|
|
EnableFigurePanel(form);
|
|
|
|
|
|
|
|
twtype = wtype;
|
|
|
|
fl_set_button(form->Default1, (wtype == 0));
|
|
|
|
fl_set_button(form->cm1, (wtype == 1));
|
|
|
|
fl_set_button(form->in1, (wtype == 2));
|
|
|
|
fl_set_button(form->page1, (wtype == 3));
|
|
|
|
fl_set_button(form->column1, (wtype == 4));
|
|
|
|
if (wtype == 0) {
|
|
|
|
fl_deactivate_object(form->Width);
|
|
|
|
} else {
|
|
|
|
fl_activate_object(form->Width);
|
|
|
|
}
|
|
|
|
|
|
|
|
// enable and disable should be put here.
|
|
|
|
thtype = htype;
|
|
|
|
fl_set_button(form->Default2, (htype == 0));
|
|
|
|
fl_set_button(form->cm2, (htype == 1));
|
|
|
|
fl_set_button(form->in2, (htype == 2));
|
|
|
|
fl_set_button(form->page2, (htype == 3));
|
|
|
|
// enable and disable should be put here.
|
|
|
|
if (htype == 0) {
|
|
|
|
fl_deactivate_object(form->Height);
|
|
|
|
} else {
|
|
|
|
fl_activate_object(form->Height);
|
|
|
|
}
|
|
|
|
|
2000-05-05 08:44:11 +00:00
|
|
|
int piflags = flags & 3;
|
|
|
|
fl_set_button(form->Wysiwyg0, (piflags == 0));
|
|
|
|
fl_set_button(form->Wysiwyg1, (piflags == 1));
|
|
|
|
fl_set_button(form->Wysiwyg2, (piflags == 2));
|
|
|
|
fl_set_button(form->Wysiwyg3, (piflags == 3));
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_button(form->Frame, ((flags & 4) != 0));
|
|
|
|
fl_set_button(form->Translations, ((flags & 8) != 0));
|
|
|
|
fl_set_button(form->Subfigure, (subfigure != 0));
|
|
|
|
pflags = flags;
|
|
|
|
psubfigure = subfigure;
|
2000-04-24 20:58:23 +00:00
|
|
|
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());
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!fname.empty()){
|
1999-12-10 00:07:59 +00:00
|
|
|
string buf1 = OnlyPath(owner->fileName());
|
1999-10-02 16:21:10 +00:00
|
|
|
string fname2 = MakeRelPath(fname, buf1);
|
1999-09-27 18:44:28 +00:00
|
|
|
fl_set_input(form->EpsFile, fname2.c_str());
|
|
|
|
}
|
|
|
|
else fl_set_input(form->EpsFile, "");
|
|
|
|
fl_set_input(form->Subcaption, subcaption.c_str());
|
2000-11-04 10:00:12 +00:00
|
|
|
if (current_view->buffer()->isReadonly())
|
1999-09-27 18:44:28 +00:00
|
|
|
DisableFigurePanel(form);
|
|
|
|
|
|
|
|
TempRegenerate();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +00:00
|
|
|
void InsetFig::Preview(string const & p)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
2000-08-31 15:11:15 +00:00
|
|
|
string tfname = p;
|
|
|
|
if (GetExtension(tfname).empty())
|
|
|
|
tfname += ".eps";
|
1999-12-10 00:07:59 +00:00
|
|
|
string buf1 = OnlyPath(owner->fileName());
|
2000-08-31 15:11:15 +00:00
|
|
|
string buf2 = MakeAbsPath(tfname, buf1);
|
2000-11-06 11:20:22 +00:00
|
|
|
if (!formats.View(owner, buf2, "eps"))
|
2000-10-02 16:44:47 +00:00
|
|
|
lyxerr << "Can't view " << buf2 << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InsetFig::BrowseFile()
|
|
|
|
{
|
1999-10-02 16:21:10 +00:00
|
|
|
static string current_figure_path;
|
1999-09-27 18:44:28 +00:00
|
|
|
static int once = 0;
|
|
|
|
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "Filename: "
|
1999-12-10 00:07:59 +00:00
|
|
|
<< owner->fileName() << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
1999-10-02 16:21:10 +00:00
|
|
|
string p = fl_get_input(form->EpsFile);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
string buf = MakeAbsPath(owner->fileName());
|
1999-12-01 00:57:31 +00:00
|
|
|
string buf2 = OnlyPath(buf);
|
1999-09-27 18:44:28 +00:00
|
|
|
if (!p.empty()) {
|
|
|
|
buf = MakeAbsPath(p, buf2);
|
|
|
|
buf = OnlyPath(buf);
|
|
|
|
} else {
|
2000-09-26 13:54:57 +00:00
|
|
|
buf = OnlyPath(owner->fileName());
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Does user clipart directory exist?
|
1999-12-01 00:57:31 +00:00
|
|
|
string bufclip = AddName (user_lyxdir, "clipart");
|
1999-09-27 18:44:28 +00:00
|
|
|
FileInfo fileInfo(bufclip);
|
|
|
|
if (!(fileInfo.isOK() && fileInfo.isDir()))
|
1999-12-16 06:43:25 +00:00
|
|
|
// No - bail out to system clipart directory
|
|
|
|
bufclip = AddName (system_lyxdir, "clipart");
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
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)));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
bool error = false;
|
|
|
|
do {
|
2001-03-07 14:25:31 +00:00
|
|
|
string const path = (once) ? current_figure_path : buf;
|
|
|
|
|
|
|
|
FileDialog::Result result = fileDlg.Select(path, _("*ps| PostScript documents"));
|
1999-09-27 18:44:28 +00:00
|
|
|
|
2001-03-07 14:25:31 +00:00
|
|
|
string const p = result.second;
|
|
|
|
|
|
|
|
if (p.empty())
|
|
|
|
return;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
|
|
buf = MakeRelPath(p, buf2);
|
|
|
|
current_figure_path = OnlyPath(p);
|
|
|
|
once = 1;
|
|
|
|
|
1999-10-02 16:21:10 +00:00
|
|
|
if (contains(p, "#") || contains(p, "~") || contains(p, "$")
|
2000-04-24 20:58:23 +00:00
|
|
|
|| contains(p, "%") || contains(p, " ")) {
|
|
|
|
WriteAlert(_("Filename can't contain any "
|
|
|
|
"of these characters:"),
|
|
|
|
// xgettext:no-c-format
|
|
|
|
_("space, '#', '~', '$' or '%'."));
|
|
|
|
error = true;
|
|
|
|
}
|
1999-09-27 18:44:28 +00:00
|
|
|
} while (error);
|
|
|
|
|
|
|
|
if (form) fl_set_input(form->EpsFile, buf.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-12-01 00:57:31 +00:00
|
|
|
void GraphicsCB(FL_OBJECT * obj, long arg)
|
1999-09-27 18:44:28 +00:00
|
|
|
{
|
|
|
|
/* obj->form contains the form */
|
|
|
|
|
|
|
|
if (lyxerr.debugging()) {
|
1999-10-07 18:44:17 +00:00
|
|
|
lyxerr << "GraphicsCB callback: " << arg << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find inset we were reacting to */
|
2000-03-12 10:35:05 +00:00
|
|
|
for (figures_type::iterator it = figures.begin();
|
|
|
|
it != figures.end(); ++it)
|
|
|
|
if ((*it)->inset->form && (*it)->inset->form->Figure
|
1999-09-27 18:44:28 +00:00
|
|
|
== obj->form) {
|
|
|
|
if (lyxerr.debugging()) {
|
2000-03-12 10:35:05 +00:00
|
|
|
lyxerr << "Calling back figure "
|
|
|
|
<< (*it) << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
2000-03-12 10:35:05 +00:00
|
|
|
(*it)->inset->CallbackFig(arg);
|
1999-09-27 18:44:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void HideFiguresPopups()
|
|
|
|
{
|
2000-03-12 10:35:05 +00:00
|
|
|
for (figures_type::iterator it = figures.begin();
|
|
|
|
it != figures.end(); ++it)
|
|
|
|
if ((*it)->inset->form
|
|
|
|
&& (*it)->inset->form->Figure->visible) {
|
1999-09-27 18:44:28 +00:00
|
|
|
if (lyxerr.debugging()) {
|
2000-03-12 10:35:05 +00:00
|
|
|
lyxerr << "Hiding figure " << (*it) << endl;
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
// hide and free the form
|
2000-03-12 10:35:05 +00:00
|
|
|
(*it)->inset->CallbackFig(9);
|
1999-09-27 18:44:28 +00:00
|
|
|
}
|
|
|
|
}
|