#include <list>
#include <algorithm>
#include <vector>
+#include <utility>
#include <unistd.h>
#include <csignal>
#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 "font.h"
#include "bufferview_funcs.h"
#include "ColorHandler.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::flush;
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;
static int gsrunning = 0; /* currently so many gs's are running */
static bool bitmap_waiting = false; /* bitmaps are waiting finished */
-static char bittable[256]; /* bit reversion table */
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_num_pixels; // number of pixels allocated
static int gs_spc; // shades per color
-static bool gs_gray; // is grayscale?
static int gs_allcolors; // number of all colors
static list<int> pidwaitlist; // pid wait list
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);
}
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(),
+ std::ostream_iterator<int>(lyxerr, "\n"));
lyxerr << flush;
}
}
}
-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;
}
register XImage * im;
int i;
int y;
- int wid1;
int spc1 = gs_spc - 1;
int spc2 = gs_spc * gs_spc;
int wid = p->wid;
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 << " "
lyxerr.debug()
<< "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,
.colormap, cmap,
gs_allcolors);
XFlush(tmpdisp);
- wid1 = p->wid - 1;
// now we process all the image
for (y = 0; y < p->hgh; ++y) {
for (int x = 0; x < wid; ++x) {
}
break;
}
- return 0;
+ return FL_PREEMPT;
+}
}
if (num > 5) num = 5;
XColor xcol;
for (int i = 0; i < num * num * num; ++i) {
- xcol.red = 65535 * (i / (num * num)) / (num - 1);
- xcol.green = 65535 * ((i / num) % num) / (num - 1);
- xcol.blue = 65535 * (i % num) / (num - 1);
+ 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));
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;;
}
gs_pixels[i] = xcol.pixel;
}
gs_color = true;
- gs_gray = false;
gs_spc = num;
- gs_num_pixels = num * num * num;
}
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()) {
gs_pixels[i] = xcol.pixel;
}
gs_color = true;
- gs_gray = false;
- gs_num_pixels = num;
}
+// xforms doesn't define this
+extern "C" FL_APPEVENT_CB fl_set_preemptive_callback(Window, FL_APPEVENT_CB, void *);
+
static
void InitFigures()
{
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;
- bittable[i] = char(~k);
- }
-
// 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,
figures.clear();
lyxerr.debug() << "Unregistering figures..." << endl;
-
- fl_remove_canvas_handler(figinset_canvas, ClientMessage,
- GhostscriptMsg);
}
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;
}
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;
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);
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 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()) {
static
void UnregisterFigure(InsetFig * fi)
{
+ if (!lyxrc.use_gui)
+ return;
+
Figref * tmpfig = fi->figure;
if (tmpfig->data) freefigdata(tmpfig->data);
}
-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(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 lfname = fname;
if (!fname.empty() && GetExtension(fname).empty())
lfname += ".eps";
string buf1 = OnlyPath(owner->fileName());
string figurename = MakeRelPath(fname, buf1);
- if(suffixIs(figurename, ".eps"))
- figurename.erase(fname.length() - 4);
+ if (suffixIs(figurename, ".eps"))
+ figurename.erase(figurename.length() - 4);
os << "@<graphic fileref=\"" << figurename << "\"></graphic>";
return 0;
// 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())
+ if (bv->buffer()->isReadonly())
WarnReadonly(bv->buffer()->fileName());
if (!form) {
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
+Inset * InsetFig::Clone(Buffer const & buffer) const
{
- InsetFig * tmp = new InsetFig(100, 100, owner);
+ InsetFig * tmp = new InsetFig(100, 100, buffer);
if (lyxerr.debugging()) {
lyxerr << "Clone Figure: buffer:["
- << current_view->buffer()
+ << &buffer
<< "], cbuffer:[xx]" << endl;
}
void InsetFig::Recompute()
{
+ if (!lyxrc.use_gui)
+ return;
+
bool changed = changedfname;
int newx, newy, nraw_x, nraw_y;
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));
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 */
}
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();
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);
+ if (!formats.View(owner, buf2, "eps"))
+ lyxerr << "Can't view " << buf2 << endl;
}
-
void InsetFig::BrowseFile()
{
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;
- 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);