#include <list>
#include <algorithm>
#include <vector>
+#include <utility>
#include <unistd.h>
#include <csignal>
#include <cmath>
#include "figinset.h"
-#include "lyx.h"
#include "lyx_main.h"
#include "buffer.h"
-#include "filedlg.h"
+#include "frontends/FileDialog.h"
#include "support/filetools.h"
#include "LyXView.h" // just because of form_main
#include "debug.h"
#include "converter.h"
#include "frontends/Dialogs.h" // redrawGUI
-#ifdef SIGC_CXX_NAMESPACES
-using SigC::slot;
-#endif
-
using std::ostream;
using std::istream;
using std::ofstream;
using std::endl;
using std::ostringstream;
using std::copy;
+using std::pair;
+using std::make_pair;
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;
| GCLineWidth | GCLineStyle , &val);
}
-static
GC local_gc_copy;
-static
void addpidwait(int pid)
{
// adds pid to pid wait list
}
-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"
+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()) {
}
break;
}
- return 0;
+ return FL_PREEMPT;
}
-static
void AllocColors(int num)
// allocate color cube numxnumxnum, if possible
{
// allocate grayscale ramp
-static
void AllocGrays(int num)
{
if (lyxerr.debugging()) {
gs_color = true;
}
-
-static
void InitFigures()
{
// if bitmaps and figures are not empty we will leak mem
// 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();
}
-static
void DoneFigures()
{
// if bitmaps and figures are not empty we will leak mem
figures.clear();
lyxerr.debug() << "Unregistering figures..." << endl;
-
- fl_remove_canvas_handler(figinset_canvas, ClientMessage,
- GhostscriptMsg);
}
-static
void freefigdata(figdata * tmpdata)
{
tmpdata->ref--;
}
-static
void runqueue()
{
// This _have_ to be set before the fork!
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);
}
-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)
}
-static
void getbitmap(figdata * p)
{
p->gspid = -1;
}
-static
void makeupdatelist(figdata * p)
{
for (figures_type::iterator it = figures.begin();
}
}
+} // namespace anon
+
// this func is only "called" in spellchecker.C
void sigchldchecker(pid_t pid, int * status)
}
-static
+namespace {
+
void getbitmaps()
{
bitmap_waiting = false;
}
-static
void RegisterFigure(InsetFig * fi)
{
if (figures.empty()) InitFigures();
}
-static
void UnregisterFigure(InsetFig * fi)
{
if (!lyxrc.use_gui)
if (figures.empty()) DoneFigures();
}
+} // namespace anon
+
InsetFig::InsetFig(int tmpx, int tmpy, Buffer const & o)
: owner(&o)
raw_wid = raw_hgh = 0;
changedfname = false;
RegisterFigure(this);
- r_ = Dialogs::redrawGUI.connect(slot(this, &InsetFig::redraw));
+ r_ = Dialogs::redrawGUI.connect(SigC::slot(this, &InsetFig::redraw));
}
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;
}
-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
{
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 !!!!
{
static string current_figure_path;
static int once = 0;
- LyXFileDlg fileDlg;
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")), string(bufclip)),
+ make_pair(string(_("Documents")), 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;
+
+ FileDialog::Result result = fileDlg.Select(path, _("*ps| PostScript documents"));
- if (p.empty()) return;
+ string const p = result.second;
+
+ if (p.empty())
+ return;
buf = MakeRelPath(p, buf2);
current_figure_path = OnlyPath(p);