#include <config.h>
#include <unistd.h>
-#include <signal.h>
+#include <csignal>
#include <sys/wait.h>
#include FORMS_H_LOCATION
-#include <stdlib.h>
-#include <ctype.h>
-#include <math.h>
+#include <cstdlib>
+#include <cctype>
+#include <cmath>
+#include <fstream>
+#include <queue>
+#include <list>
+#include <algorithm>
+using std::ofstream;
+using std::ifstream;
+using std::queue;
+using std::list;
+using std::find;
+using std::flush;
-#include "form1.h"
#include "figinset.h"
#include "lyx.h"
#include "lyx_main.h"
#include "buffer.h"
#include "filedlg.h"
-#include "filetools.h"
+#include "support/filetools.h"
#include "LyXView.h" // just because of form_main
-#include "error.h"
+#include "debug.h"
#include "lyxdraw.h"
#include "LaTeXFeatures.h"
#include "lyxrc.h"
#include "gettext.h"
#include "lyx_gui_misc.h" // CancelCloseBoxCB
-#include "FileInfo.h"
+#include "support/FileInfo.h"
+#include "support/lyxlib.h"
-// $Id: figinset.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $
-
-#if !defined(lint) && !defined(WITH_WARNINGS)
-static char vcid[] = "$Id: figinset.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $";
-#endif /* lint */
-
-extern BufferView *current_view;
+extern BufferView * current_view;
+#if 0
static volatile bool alarmed;
-
-extern FL_OBJECT *figinset_canvas;
-inline
-void waitalarm(int)
+#endif
+extern FL_OBJECT * figinset_canvas;
+#if 0
+//inline
+extern "C" void waitalarm(int)
{
alarmed = true;
}
+#endif
-extern char **environ; // is this only redundtant on linux systems? Lgb.
-extern void UpdateInset(Inset* inset, bool mark_dirty = true);
+extern char ** environ; // is this only redundtant on linux systems? Lgb.
+extern void UpdateInset(Inset * inset, bool mark_dirty = true);
// better for asyncron updating:
-void PutInsetIntoInsetUpdateList(Inset* inset);
+void PutInsetIntoInsetUpdateList(Inset * inset);
extern void ProhibitInput();
extern void AllowInput();
-#define DEG2PI 57.295779513
-#define figallocchunk 32
+static float const DEG2PI = 57.295779513;
+static int const figallocchunk = 32;
static int figinsref = 0; /* number of figures */
static int figarrsize = 0; /* current max number of figures */
static int bmpinsref = 0; /* number of bitmaps */
static int bmparrsize = 0; /* current max number of bitmaps */
-struct queue {
- float rx, ry; /* resolution x and y */
- int ofsx, ofsy; /* x and y translation */
- figdata *data; /* we are doing it for this data */
- queue *next; /* next item in queue */
+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
};
-struct pidwait {
- int pid; /* pid to wait for */
- pidwait *next; /* next */
-};
+static int const MAXGS = 3; /* maximum 3 gs's at a time */
+
+static Figref ** figures; /* all the figures */
+static figdata ** bitmaps; /* all the bitmaps */
-#define MAXGS 3 /* maximum 3 gs's at a time */
+static queue<queue_element> gsqueue; // queue for ghostscripting
-static Figref **figures; /* all the figures */
-static figdata **bitmaps; /* all the bitmaps */
-static queue *gsqueue = NULL; /* queue for ghostscripting */
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_gray; // is grayscale?
static int gs_allcolors; // number of all colors
-static pidwait *pw = NULL; // pid wait list
-
+static list<int> pidwaitlist; // pid wait list
-extern FD_form_main *fd_form_main;
extern Colormap color_map;
void addpidwait(int pid)
{
// adds pid to pid wait list
- register pidwait *p = new pidwait;
-
- p->pid = pid;
- p->next = pw;
- pw = p;
+ pidwaitlist.push_back(pid);
if (lyxerr.debugging()) {
- lyxerr.print(LString("Pids to wait for: ") + int(p->pid));
- while (p->next) {
- p = p->next;
- lyxerr.print(LString() + int(p->pid));
+ lyxerr << "Pids to wait for: \n";
+ for (list<int>::const_iterator cit = pidwaitlist.begin();
+ cit != pidwaitlist.end(); ++cit) {
+ lyxerr << (*cit) << '\n';
}
+ lyxerr << flush;
}
}
-int GhostscriptMsg(FL_OBJECT *, Window, int, int,
- XEvent *ev, void *)
+extern "C" int GhostscriptMsg(FL_OBJECT *, Window, int, int,
+ XEvent * ev, void *)
{
- int i;
char tmp[128];
- XClientMessageEvent *e = (XClientMessageEvent*) ev;
+ XClientMessageEvent * e = reinterpret_cast<XClientMessageEvent*>(ev);
if(lyxerr.debugging()) {
- fprintf(stderr,
- "ClientMessage, win:[xx] gs:[%ld] pm:[%ld]\n",
- e->data.l[0], e->data.l[1]);
+ lyxerr << "ClientMessage, win:[xx] gs:[" << e->data.l[0]
+ << "] pm:[" << e->data.l[1] << "]" << endl;
}
// just kill gs, that way it will work for sure
- for (i = 0; i < bmpinsref; ++i)
+ // This loop looks like S**T so it probably is...
+ for (int i = 0; i < bmpinsref; ++i)
if ((long)bitmaps[i]->bitmap == (long)e->data.l[1]) {
// found the one
- figdata *p = bitmaps[i];
+ figdata * p = bitmaps[i];
p->gsdone = true;
// first update p->bitmap, if necessary
- if (p->bitmap != None && p->flags > (1|8) && gs_color && p->wid) {
+ if (p->bitmap != None
+ && p->flags > (1|8) && gs_color && p->wid) {
// query current colormap and re-render
// the pixmap with proper colors
- XColor *cmap;
+ //XColor * cmap;
XWindowAttributes wa;
- register XImage *im;
+ register XImage * im;
int i, y, wid1, spc1 = gs_spc-1,
- spc2 = gs_spc*gs_spc, wid = p->wid,
+ spc2 = gs_spc * gs_spc, wid = p->wid,
forkstat;
- Display *tmpdisp;
+ Display * tmpdisp;
GC gc = getGC(gc_copy);
- XGetWindowAttributes(fl_display, fl_get_canvas_id(
- figinset_canvas), &wa);
+ XGetWindowAttributes(fl_display,
+ fl_get_canvas_id(
+ figinset_canvas),
+ &wa);
XFlush(fl_display);
if (lyxerr.debugging()) {
- fprintf(stderr,
- "Starting image translation %ld %d %dx%d %d %d\n",
- p->bitmap, p->flags, p->wid, p->hgh, wa.depth,
- XYPixmap);
+ lyxerr << "Starting image translation "
+ << p->bitmap << " "
+ << p->flags << " "
+ << p->wid << "x" << p->hgh
+ << " " << wa.depth
+ << " " << XYPixmap << endl;
}
// now fork rendering process
forkstat = fork();
if (forkstat == -1) {
- lyxerr.debug("Cannot fork, using slow "
- "method for pixmap translation.");
+ lyxerr.debug()
+ << "Cannot fork, using slow "
+ "method for pixmap translation." << endl;
tmpdisp = fl_display;
- } else if (forkstat > 0) {
+ } else if (forkstat > 0) { // parent
// register child
if (lyxerr.debugging()) {
- lyxerr.print(
- LString("Spawned child ")
- + int(forkstat));
+ lyxerr << "Spawned child "
+ << forkstat << endl;
}
addpidwait(forkstat);
- break; // in parent process
- } else {
- tmpdisp = XOpenDisplay(XDisplayName(NULL));
+ break;
+ } else { // child
+ tmpdisp = XOpenDisplay(XDisplayName(0));
XFlush(tmpdisp);
}
im = XGetImage(tmpdisp, p->bitmap, 0, 0,
p->wid, p->hgh, (1<<wa.depth)-1, XYPixmap);
XFlush(tmpdisp);
if (lyxerr.debugging()) {
- lyxerr.print("Got the image");
+ lyxerr << "Got the image" << endl;
}
if (!im) {
if (lyxerr.debugging()) {
- lyxerr.print("Error getting the image");
+ lyxerr << "Error getting the image" << endl;
}
goto noim;
}
+ {
// query current colormap
- cmap = (XColor *) malloc(gs_allcolors*sizeof(XColor));
- for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
- XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
- XFlush(tmpdisp);
- wid1 = p->wid - 1;
+ XColor * cmap = new XColor[gs_allcolors];
+ for (i = 0; i < gs_allcolors; ++i) cmap[i].pixel = i;
+ XQueryColors(tmpdisp, color_map, cmap, gs_allcolors);
+ XFlush(tmpdisp);
+ wid1 = p->wid - 1;
// now we process all the image
- for (y = 0; y < p->hgh; ++y) {
- register int x;
- for (x = 0; x < wid; ++x) {
- register XColor* pc;
- 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);
+ 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);
+ }
+ }
+ // This must be correct.
+ 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;
}
- }
- if (lyxerr.debugging()) {
- lyxerr.print("Putting image back");
- }
- XPutImage(tmpdisp, p->bitmap, gc, im, 0, 0,
- 0, 0, p->wid, p->hgh);
- XDestroyImage(im);
- if (lyxerr.debugging()) {
- lyxerr.print("Done translation");
}
noim:
if (lyxerr.debugging()) {
- lyxerr.print(LString("Killing gs ")
- + int(p->gspid));
+ lyxerr << "Killing gs "
+ << p->gspid << endl;
}
- kill(p->gspid, SIGHUP);
+ lyx::kill(p->gspid, SIGHUP);
sprintf(tmp, "%s/~lyxgs%d.ps",
system_tempdir.c_str(),
}
} else {
if (lyxerr.debugging()) {
- lyxerr.print(LString("Killing gs ")
- +int(p->gspid));
+ lyxerr << "Killing gs "
+ << p->gspid << endl;
}
- kill(p->gspid, SIGHUP);
+ lyx::kill(p->gspid, SIGHUP);
sprintf(tmp, "%s/~lyxgs%d.ps",
system_tempdir.c_str(),
static void AllocColors(int num)
// allocate color cube numxnumxnum, if possible
{
- XColor xcol;
- int i;
-
if (lyxerr.debugging()) {
- printf("Allocating color cube %dx%dx%d\n", num, num, num);
+ lyxerr << "Allocating color cube " << num
+ << 'x' << num << 'x' << num << endl;
}
if (num <= 1) {
- lyxerr.print("Error allocating color colormap.");
+ lyxerr << "Error allocating color colormap." << endl;
gs_color = false;
return;
}
if (num > 5) num = 5;
- for (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);
+ 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.flags = DoRed | DoGreen | DoBlue;
if (!XAllocColor(fl_display, color_map, &xcol)) {
if (i) XFreeColors(fl_display, color_map,
gs_pixels, i, 0);
if(lyxerr.debugging()) {
- lyxerr.print(LString("Cannot allocate color cube " )
- + int(num));
+ lyxerr << "Cannot allocate color cube "
+ << num << endl;;
}
- AllocColors(num-1);
+ AllocColors(num - 1);
return;
}
gs_pixels[i] = xcol.pixel;
gs_color = true;
gs_gray = false;
gs_spc = num;
- gs_num_pixels = num*num*num;
+ gs_num_pixels = num * num * num;
}
-static void AllocGrays(int num)
// allocate grayscale ramp
+static
+void AllocGrays(int num)
{
- XColor xcol;
- int i;
-
if (lyxerr.debugging()) {
- lyxerr.print(LString("Allocating grayscale ramp ")
- + int(num));
+ lyxerr << "Allocating grayscale colormap "
+ << num << endl;
}
if (num < 4) {
- lyxerr.print("Error allocating grayscale colormap.");
+ lyxerr << "Error allocating grayscale colormap." << endl;
gs_color = false;
return;
}
if (num > 128) num = 128;
- for (i = 0; i < num; ++i) {
- xcol.red = xcol.green = xcol.blue = 65535*i/(num-1);
+ XColor xcol;
+ for (int i = 0; i < num; ++i) {
+ xcol.red = xcol.green = xcol.blue = 65535 * i / (num - 1);
xcol.flags = DoRed | DoGreen | DoBlue;
if (!XAllocColor(fl_display, color_map, &xcol)) {
if (i) XFreeColors(fl_display, color_map,
gs_pixels, i, 0);
if (lyxerr.debugging()) {
- lyxerr.print(LString("Cannot allocate grayscale ")
- + int(num));
+ lyxerr << "Cannot allocate grayscale "
+ << num << endl;
}
- AllocGrays(num/2);
+ AllocGrays(num / 2);
return;
}
gs_pixels[i] = xcol.pixel;
void InitFigures()
{
- unsigned int i, j, k;
- Visual *vi;
-
bmparrsize = figarrsize = figallocchunk;
- figures = (Figref**) malloc(sizeof(Figref*)*figallocchunk);
- bitmaps = (figdata**) malloc(sizeof(figdata*)*figallocchunk);
-
- for (i = 0; i < 256; ++i) {
+ typedef Figref * Figref_p;
+ figures = new Figref_p[figallocchunk];
+ //figures = static_cast<Figref**>
+ // (malloc(sizeof(Figref*) * figallocchunk));
+ typedef figdata * figdata_p;
+ bitmaps = new figdata_p[figallocchunk];
+ //bitmaps = static_cast<figdata**>
+ //(malloc(sizeof(figdata*) * figallocchunk));
+
+ unsigned int k;
+ for (unsigned int i = 0; i < 256; ++i) {
k = 0;
- for (j = 0; j < 8; ++j)
+ for (unsigned int j = 0; j < 8; ++j)
if (i & (1 << (7-j))) k |= 1 << j;
- bittable[i] = (char) ~k;
+ bittable[i] = char(~k);
}
fl_add_canvas_handler(figinset_canvas, ClientMessage,
- GhostscriptMsg, fd_form_main);
+ GhostscriptMsg, current_view->owner()->getMainForm());
// now we have to init color_map
if (!color_map) color_map = DefaultColormap(fl_display,
// first get visual
gs_color = false;
- vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
+ Visual * vi = DefaultVisual(fl_display, DefaultScreen(fl_display));
if (lyxerr.debugging()) {
printf("Visual ID: %ld, class: %d, bprgb: %d, mapsz: %d\n",
vi->visualid, vi->c_class,
vi->bits_per_rgb, vi->map_entries);
}
color_visual = ( (vi->c_class == StaticColor) ||
- (vi->c_class == PseudoColor) ||
- (vi->c_class == TrueColor) ||
- (vi->c_class == DirectColor) );
+ (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) {
} else {
// allocate normal color
int i = 5;
- while (i*i*i*2 > vi->map_entries) --i;
+ while (i * i * i * 2 > vi->map_entries) --i;
AllocColors(i);
}
gs_allcolors = vi->map_entries;
void DoneFigures()
{
- free(figures);
- free(bitmaps);
+ //free(figures);
+ //free(bitmaps);
+ delete[] figures;
+ delete[] bitmaps;
figarrsize = 0;
bmparrsize = 0;
- lyxerr.debug("Unregistering figures...");
+ lyxerr.debug() << "Unregistering figures..." << endl;
fl_remove_canvas_handler(figinset_canvas, ClientMessage,
GhostscriptMsg);
if (gs_color) {
- lyxerr.debug("Freeing up the colors...");
+ lyxerr.debug() << "Freeing up the colors..." << endl;
XFreeColors(fl_display, color_map, gs_pixels,
gs_num_pixels, 0);
/******????????????????? what's planes in this case ??????***/
}
-int FindBmpIndex(figdata *tmpdata)
+int FindBmpIndex(figdata * tmpdata)
{
int i = 0;
while (i < bmpinsref) {
static void chpixmap(Pixmap, int, int)
{
- Display* tempdisp = XOpenDisplay(XDisplayName(NULL));
+#if 0
+ Display * tempdisp = XOpenDisplay(XDisplayName(0));
// here read the pixmap and change all colors to those we
// have allocated
XCloseDisplay(tempdisp);
+#endif
}
-static void freefigdata(figdata *tmpdata)
+static void freefigdata(figdata * tmpdata)
{
- int i;
-
tmpdata->ref--;
if (tmpdata->ref) return;
chpixmap(tmpdata->bitmap, tmpdata->wid, tmpdata->hgh);
// kill ghostscript and unlink it's files
tmpdata->gspid = -1;
- kill(pid, SIGKILL);
+ lyx::kill(pid, SIGKILL);
sprintf(buf, "%s/~lyxgs%d.ps", system_tempdir.c_str(), pid);
unlink(buf);
}
if (tmpdata->bitmap) XFreePixmap(fl_display, tmpdata->bitmap);
delete tmpdata;
- i = FindBmpIndex(tmpdata);
+ int i = FindBmpIndex(tmpdata);
--bmpinsref;
while (i < bmpinsref) {
- bitmaps[i] = bitmaps[i+1];
+ bitmaps[i] = bitmaps[i + 1];
++i;
}
}
}
while (gsrunning < MAXGS) {
- queue *p;
- int pid;
char tbuf[384], tbuf2[80];
- Atom *prop;
+ Atom * prop;
int nprop, i;
- if (!gsqueue) {
+ if (gsqueue.empty()) {
if (!gsrunning && gs_xcolor) {
// de-allocate rest of colors
// *****
}
return;
}
- p = gsqueue;
-
+ queue_element * p = &gsqueue.front();
if (!p->data) {
- delete p;
+ gsqueue.pop();
continue;
}
- pid = fork();
+ int pid = fork();
if (pid == -1) {
if (lyxerr.debugging()) {
- lyxerr.print("GS start error! Cannot fork.");
+ lyxerr << "GS start error! Cannot fork."
+ << endl;
}
p->data->broken = true;
p->data->reading = false;
return;
}
if (pid == 0) { // child
- char **env, rbuf[80], gbuf[40];
+ char ** env, rbuf[80], gbuf[40];
int ne = 0;
- Display* tempdisp = XOpenDisplay(XDisplayName(NULL));
+ Display * tempdisp = XOpenDisplay(XDisplayName(0));
// create translation file
sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
int(getpid()));
- FilePtr f(tbuf, FilePtr::write);
- fprintf(f, "gsave clippath pathbbox grestore\n"
- "4 dict begin\n"
- "/ury exch def /urx exch def /lly exch def "
+ ofstream ofs(tbuf);
+ ofs << "gsave clippath pathbbox grestore\n"
+ << "4 dict begin\n"
+ << "/ury exch def /urx exch def /lly exch def "
"/llx exch def\n"
- "%g %g translate\n"
- "%g rotate\n"
- "%g %g translate\n"
- "%g %g scale\n"
- "%d %d translate\nend\n",
- p->data->wid / 2.0, p->data->hgh / 2.0,
- p->data->angle,
- - (p->data->raw_wid / 2.0), -(p->data->raw_hgh / 2.0),
- p->rx / 72.0, p->ry / 72.0,
- -p->ofsx, -p->ofsy
- );
-
- // DON'T EVER remove this!!
- f.close(); // was this all? (Lgb)
-
+ << 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.
+
// gs process - set ghostview environment first
sprintf(tbuf2, "GHOSTVIEW=%ld %ld", fl_get_canvas_id(
figinset_canvas), p->data->bitmap);
// now set up ghostview property on a window
sprintf(tbuf, "0 0 0 0 %d %d 72 72 0 0 0 0",
p->data->wid, p->data->hgh);
-//#warning BUG seems that the only bug here might be the hardcoded dpi.. Bummer!
+ // #warning BUG seems that the only bug here
+ // might be the hardcoded dpi.. Bummer!
if (lyxerr.debugging()) {
- lyxerr.print(LString("Will set GHOSTVIEW"
- " property to [") +
- tbuf + "]");
+ lyxerr << "Will set GHOSTVIEW property to ["
+ << tbuf << "]" << endl;
}
// wait until property is deleted if executing multiple
// ghostscripts
for (;;) {
- // grab server to prevent other child interfering
- // with setting GHOSTVIEW property
+ // grab server to prevent other child
+ // interfering with setting GHOSTVIEW property
if (lyxerr.debugging()) {
- lyxerr.print("Grabbing the server");
+ lyxerr << "Grabbing the server"
+ << endl;
}
XGrabServer(tempdisp);
- prop = XListProperties(tempdisp, fl_get_canvas_id(
+ prop = XListProperties(tempdisp,
+ fl_get_canvas_id(
figinset_canvas), &nprop);
if (!prop) break;
bool err = true;
for (i = 0; i < nprop; ++i) {
- char *p = XGetAtomName(tempdisp, prop[i]);
+ char * p = XGetAtomName(tempdisp,
+ prop[i]);
if (strcmp(p, "GHOSTVIEW") == 0) {
err = false;
break;
}
XFree(p);
}
- XFree((char *)prop); /* jc: */
+ XFree(reinterpret_cast<char *>(prop)); // jc:
if (err) break;
// release the server
XUngrabServer(tempdisp);
XFlush(tempdisp);
- // ok, property found, we must wait until ghostscript
- // deletes it
+ // ok, property found, we must wait until
+ // ghostscript deletes it
if (lyxerr.debugging()) {
- lyxerr.print("Releasing the server");
- lyxerr.print(LString('[') +
- int(getpid()) +
- "] GHOSTVIEW property"
- " found. Waiting.");
+ lyxerr << "Releasing the server\n["
+ << getpid()
+ << "] GHOSTVIEW property"
+ " found. Waiting." << endl;
}
+#if 0
#ifdef WITH_WARNINGS
#warning What is this doing? (wouldn't a sleep(1); work too?')
#endif
alarmed = false;
signal(SIGALRM, waitalarm);
while (!alarmed) pause();
+#else
+ sleep(1);
+#endif
}
XChangeProperty(tempdisp,
XInternAtom(tempdisp, "GHOSTVIEW", false),
XInternAtom(tempdisp, "STRING", false),
8, PropModeAppend,
- (unsigned char *) tbuf,
+ reinterpret_cast<unsigned char*>(tbuf),
strlen(tbuf));
switch (p->data->flags & 3) {
XChangeProperty(tempdisp,
fl_get_canvas_id(figinset_canvas),
- XInternAtom(tempdisp, "GHOSTVIEW_COLORS", false),
+ XInternAtom(tempdisp,
+ "GHOSTVIEW_COLORS", false),
XInternAtom(tempdisp, "STRING", false),
8, PropModeReplace,
- (unsigned char *) tbuf,
+ reinterpret_cast<unsigned char*>(tbuf),
strlen(tbuf));
XUngrabServer(tempdisp);
XFlush(tempdisp);
if (lyxerr.debugging()) {
- lyxerr.print("Releasing the server");
+ lyxerr << "Releasing the server" << endl;
}
XCloseDisplay(tempdisp);
// set up environment
while (environ[ne]) ++ne;
- env = (char **) malloc(sizeof(char*)*(ne+2));
+ typedef char * char_p;
+ env = new char_p[ne + 2];
+ //env = static_cast<char **>
+ // (malloc(sizeof(char*) * (ne + 2)));
env[0] = tbuf2;
- memcpy(&env[1], environ, sizeof(char*)*(ne+1));
+ memcpy(&env[1], environ, sizeof(char*) * (ne + 1));
environ = env;
// now make gs command
sprintf(tbuf, "%s/~lyxgs%d.ps", system_tempdir.c_str(),
int(getpid()));
if (lyxerr.debugging()) {
- printf("starting gs %s %s, pid: %d\n", tbuf,
- p->data->fname.c_str(), int(getpid()));
+ lyxerr << "starting gs " << tbuf << " "
+ << p->data->fname
+ << ", pid: " << getpid() << endl;
}
int err = execlp(lyxrc->ps_command.c_str(),
"-dSAFER",
rbuf, gbuf, tbuf,
p->data->fname.c_str(),
- "showpage.ps", "quit.ps", "-", NULL);
+ "showpage.ps", "quit.ps", "-", 0);
// if we are still there, an error occurred.
- lyxerr.print(LString("Error executing ghostscript. ")
- +"Code: "+err);
- lyxerr.debug("Cmd: "
- + lyxrc->ps_command
- +" -sDEVICE=x11 "
- + tbuf + LString(' ')
- + p->data->fname);
+ lyxerr << "Error executing ghostscript. "
+ << "Code: " << err << endl;
+ lyxerr.debug() << "Cmd: "
+ << lyxrc->ps_command
+ << " -sDEVICE=x11 "
+ << tbuf << ' '
+ << p->data->fname << endl;
_exit(0); // no gs?
}
// normal process (parent)
if (lyxerr.debugging()) {
- lyxerr.print(LString("GS [") + int(pid) + "] started");
+ lyxerr << "GS [" << pid << "] started" << endl;
}
- gsqueue = gsqueue->next;
- gsrunning++;
+
p->data->gspid = pid;
- delete p;
+ ++gsrunning;
+ gsqueue.pop();
}
}
-static void addwait(int psx, int psy, int pswid, int pshgh, figdata *data)
+static void addwait(int psx, int psy, int pswid, int pshgh, figdata * data)
{
// recompute the stuff and put in the queue
- queue *p, *p2;
- p = new queue;
- p->ofsx = psx;
- p->ofsy = psy;
- p->rx = ((float)data->raw_wid*72)/pswid;
- p->ry = ((float)data->raw_hgh*72)/pshgh;
+ 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;
- p->next = NULL;
+ p.data = data;
- // now put into queue
- p2 = gsqueue;
- if (!gsqueue) gsqueue = p;
- else {
- while (p2->next) p2 = p2->next;
- p2->next = p;
- }
+ gsqueue.push(p);
// if possible, run the queue
runqueue();
}
-static figdata *getfigdata(int wid, int hgh, LString const & fname,
- int psx, int psy, int pswid, int pshgh,
- int raw_wid, int raw_hgh, float angle, char flags)
+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)
{
/* first search for an exact match with fname and width/height */
- int i = 0;
- figdata *p;
- XWindowAttributes wa;
- if (fname.empty()) return NULL;
+ if (fname.empty()) return 0;
+ int i = 0;
while (i < bmpinsref) {
if (bitmaps[i]->wid == wid && bitmaps[i]->hgh == hgh &&
- bitmaps[i]->flags == flags && bitmaps[i]->fname==fname &&
+ bitmaps[i]->flags == flags && bitmaps[i]->fname == fname &&
bitmaps[i]->angle == angle) {
bitmaps[i]->ref++;
return bitmaps[i];
}
++i;
}
- /* not found -> create new record or return NULL if no record */
+ /* not found -> create new record or return 0 if no record */
++bmpinsref;
if (bmpinsref > bmparrsize) {
// allocate more space
bmparrsize += figallocchunk;
- figdata **tmp = (figdata**) malloc(sizeof(figdata*)*bmparrsize);
- memcpy(tmp, bitmaps, sizeof(figdata*)*(bmparrsize-figallocchunk));
- free(bitmaps);
+ typedef figdata * figdata_p;
+ figdata ** tmp = new figdata_p[bmparrsize];
+ //figdata ** tmp = static_cast<figdata**>
+ // (malloc(sizeof(figdata*) * bmparrsize));
+ memcpy(tmp, bitmaps,
+ sizeof(figdata*) * (bmparrsize - figallocchunk));
+ delete[] bitmaps;
+ //free(bitmaps);
bitmaps = tmp;
}
- p = new figdata;
+ figdata * p = new figdata;
bitmaps[bmpinsref-1] = p;
p->wid = wid;
p->hgh = hgh;
p->angle = angle;
p->fname = fname;
p->flags = flags;
+ XWindowAttributes wa;
XGetWindowAttributes(fl_display, fl_get_canvas_id(
figinset_canvas), &wa);
if (lyxerr.debugging()) {
- printf("Create pixmap disp:%d scr:%d w:%d h:%d depth:%d\n",
- PTR_AS_INT(fl_display), DefaultScreen(fl_display),
- wid, hgh, wa.depth);
+ lyxerr << "Create pixmap disp:" << fl_display
+ << " scr:" << DefaultScreen(fl_display)
+ << " w:" << wid
+ << " h:" << hgh
+ << " depth:" << wa.depth << endl;
}
p->ref = 1;
}
-static void getbitmap(figdata *p)
+static void getbitmap(figdata * p)
{
p->gspid = -1;
}
-static void makeupdatelist(figdata *p)
+static void makeupdatelist(figdata * p)
{
- int i;
-
- for (i = 0; i < figinsref; ++i) if (figures[i]->data == p) {
- if (lyxerr.debugging()) {
- printf("Updating inset %d\n",
- PTR_AS_INT(figures[i]->inset));
+ for (int i = 0; i < figinsref; ++i)
+ if (figures[i]->data == p) {
+ if (lyxerr.debugging()) {
+ lyxerr << "Updating inset "
+ << figures[i]->inset
+ << endl;
+ }
+ //UpdateInset(figures[i]->inset);
+ // add inset figures[i]->inset into to_update list
+ PutInsetIntoInsetUpdateList(figures[i]->inset);
}
- //UpdateInset(figures[i]->inset);
- // add inset figures[i]->inset into to_update list
- PutInsetIntoInsetUpdateList(figures[i]->inset);
- }
}
-void sigchldchecker(pid_t pid, int *status)
+void sigchldchecker(pid_t pid, int * status)
{
- int i;
- figdata *p;
-
+ lyxerr.debug() << "Got pid = " << pid << endl;
bool pid_handled = false;
-
- lyxerr.debug(LString("Got pid = ") + long (pid));
- pid_handled = false;
- for (i = bmpinsref - 1; i >= 0; --i) {
+ for (int i = bmpinsref - 1; i >= 0; --i) {
if (bitmaps[i]->reading && pid == bitmaps[i]->gspid) {
- lyxerr.debug("Found pid in bitmaps");
+ lyxerr.debug() << "Found pid in bitmaps" << endl;
// now read the file and remove it from disk
- p = bitmaps[i];
+ figdata * p = bitmaps[i];
p->reading = false;
if (bitmaps[i]->gsdone) *status = 0;
if (*status == 0) {
- lyxerr.debug(LString("GS [") + int(pid) +
- "] exit OK.");
+ lyxerr.debug() << "GS [" << pid
+ << "] exit OK." << endl;
} else {
- fprintf(stderr, "GS [%ld] error %d E:%d %d S:%d %d\n", long(pid),
- *status, WIFEXITED(*status), WEXITSTATUS(*status),
- WIFSIGNALED(*status), WTERMSIG(*status));
+ lyxerr << "GS [" << pid << "] error "
+ << *status << " E:"
+ << WIFEXITED(*status)
+ << " " << WEXITSTATUS(*status)
+ << " S:" << WIFSIGNALED(*status)
+ << " " << WTERMSIG(*status) << endl;
}
if (*status == 0) {
bitmap_waiting = true;
p->broken = true;
}
makeupdatelist(bitmaps[i]);
- gsrunning--;
+ --gsrunning;
runqueue();
pid_handled = true;
}
}
if (!pid_handled) {
- lyxerr.debug("Checking pid in pidwait");
- pidwait *p = pw, *prev = NULL;
- while (p) {
- if (pid == p->pid) {
- lyxerr.debug("Found pid in pidwait");
- lyxerr.debug(LString("Caught child pid of recompute routine ") + int(pid));
- if (prev)
- prev->next = p->next;
- else
- pw = p->next;
- free(p);
- break;
- }
- prev = p;
- p = p->next;
+ lyxerr.debug() << "Checking pid in pidwait" << endl;
+ list<int>::iterator it = find(pidwaitlist.begin(),
+ pidwaitlist.end(), pid);
+ if (it != pidwaitlist.end()) {
+ lyxerr.debug() << "Found pid in pidwait\n"
+ << "Caught child pid of recompute "
+ "routine" << pid << endl;
+ pidwaitlist.erase(it);
}
}
-
if (pid == -1) {
- lyxerr.debug("waitpid error");
+ lyxerr.debug() << "waitpid error" << endl;
switch (errno) {
case ECHILD:
- lyxerr.print(
- "The process or process group specified by pid "
- "does not exist or is not a child of the cal-"
- "ling process or can never be in the states "
- "specified by options.");
+ 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;
break;
case EINTR:
- lyxerr.print(
- "waitpid() was interrupted due to the receipt "
- "of a signal sent by the calling process.");
+ lyxerr << "waitpid() was interrupted due to the "
+ "receipt of a signal sent by the calling "
+ "process." << endl;
break;
case EINVAL:
- lyxerr.print(
- "An invalid value was specified for options.");
+ lyxerr << "An invalid value was specified for "
+ "options." << endl;
break;
default:
- lyxerr.print("Unknown error from waitpid");
+ lyxerr << "Unknown error from waitpid" << endl;
break;
}
} else if (pid == 0) {
- lyxerr.print("waitpid nohang");
+ lyxerr << "waitpid nohang" << endl;;
} else {
- lyxerr.debug("normal exit from childhandler");
+ lyxerr.debug() << "normal exit from childhandler" << endl;
}
}
static void getbitmaps()
{
- int i;
bitmap_waiting = false;
- for (i = 0; i < bmpinsref; ++i)
+ for (int i = 0; i < bmpinsref; ++i)
if (bitmaps[i]->gspid > 0 && !bitmaps[i]->reading)
getbitmap(bitmaps[i]);
}
-static void RegisterFigure(InsetFig *fi)
+static void RegisterFigure(InsetFig * fi)
{
- Figref *tmpfig;
-
if (figinsref == 0) InitFigures();
- fi->form = NULL;
+ fi->form = 0;
++figinsref;
if (figinsref > figarrsize) {
// allocate more space
figarrsize += figallocchunk;
- Figref **tmp = (Figref**) malloc(sizeof(Figref*)*figarrsize);
- memcpy(tmp, figures, sizeof(Figref*)*(figarrsize-figallocchunk));
- free(figures);
+ typedef Figref * Figref_p;
+ Figref ** tmp = new Figref_p[figarrsize];
+ //Figref ** tmp = static_cast<Figref**>
+ // (malloc(sizeof(Figref*)*figarrsize));
+ memcpy(tmp, figures,
+ sizeof(Figref*)*(figarrsize-figallocchunk));
+ delete[] figures;
+ //free(figures);
figures = tmp;
}
- tmpfig = new Figref;
- tmpfig->data = NULL;
+ Figref * tmpfig = new Figref;
+ tmpfig->data = 0;
tmpfig->inset = fi;
figures[figinsref-1] = tmpfig;
fi->figure = tmpfig;
if (lyxerr.debugging()) {
- lyxerr.print(LString("Register Figure: buffer:[") +
- long(current_view->currentBuffer()) + "]");
+ lyxerr << "Register Figure: buffer:["
+ << current_view->buffer() << "]" << endl;
}
}
-int FindFigIndex(Figref *tmpfig)
+int FindFigIndex(Figref * tmpfig)
{
int i = 0;
while (i < figinsref) {
}
-static void UnregisterFigure(InsetFig *fi)
+static void UnregisterFigure(InsetFig * fi)
{
- Figref *tmpfig = fi->figure;
- int i;
+ Figref * tmpfig = fi->figure;
if (tmpfig->data) freefigdata(tmpfig->data);
if (tmpfig->inset->form) {
- if (tmpfig->inset->form->Figure->visible)
+ if (tmpfig->inset->form->Figure->visible) {
+ fl_set_focus_object(tmpfig->inset->form->Figure,
+ tmpfig->inset->form->OkBtn);
fl_hide_form(tmpfig->inset->form->Figure);
+ }
+#if FL_REVISION == 89
+#warning Reactivate this free_form calls
+#else
fl_free_form(tmpfig->inset->form->Figure);
- free(tmpfig->inset->form);
- tmpfig->inset->form = NULL;
+ free(tmpfig->inset->form); // Why free?
+ tmpfig->inset->form = 0;
+#endif
}
- i = FindFigIndex(tmpfig);
+ int i = FindFigIndex(tmpfig);
--figinsref;
while (i < figinsref) {
figures[i] = figures[i+1];
}
-static char* NextToken(FILE *myfile)
+static string NextToken(istream & is)
{
- char* token = NULL;
+ string token;
char c;
- int i = 0;
-
- if (!feof(myfile)) {
- token = new char[256];
+ if (!is.eof()) {
do {
- c = fgetc(myfile);
- token[i++]=c;
- } while (!feof(myfile) && !isspace(c));
-
- token[i-1]='\0'; /* just the end of a command */
+ is.get(c);
+ token += c;
+ } while (!is.eof() && !isspace(c));
+ token.erase(token.length() - 1); // remove the isspace
}
return token;
}
-InsetFig::InsetFig(int tmpx, int tmpy, Buffer *o)
+InsetFig::InsetFig(int tmpx, int tmpy, Buffer * o)
: owner(o)
{
wid = tmpx;
pflags = flags = 9;
psubfigure = subfigure = false;
xwid = xhgh = angle = 0;
+ pswid = pshgh = 0;
raw_wid = raw_hgh = 0;
changedfname = false;
RegisterFigure(this);
InsetFig::~InsetFig()
{
if (lyxerr.debugging()) {
- lyxerr.print("Figure destructor called");
+ lyxerr << "Figure destructor called" << endl;
}
UnregisterFigure(this);
}
-int InsetFig::Ascent(LyXFont const&) const
+int InsetFig::Ascent(LyXFont const &) const
{
return hgh + 3;
}
-int InsetFig::Descent(LyXFont const&) const
+int InsetFig::Descent(LyXFont const &) const
{
return 1;
}
-int InsetFig::Width(LyXFont const&) const
+int InsetFig::Width(LyXFont const &) const
{
return wid + 2;
}
-void InsetFig::Draw(LyXFont font, LyXScreen &scr, int baseline, float &x)
+void InsetFig::Draw(LyXFont font, LyXScreen & scr, int baseline, float & x)
{
if (bitmap_waiting) getbitmaps();
char * msg = 0;
// draw frame
XDrawRectangle(fl_display, pm, getGC(gc_copy),
- (int) x,
+ int(x),
baseline - hgh - 1, wid+1, hgh+1);
if (figure && figure->data) {
- if (figure->data->broken) msg = _("[render error]");
- else if (figure->data->reading) msg = _("[rendering ... ]");
+ if (figure->data->broken) msg = _("[render error]");
+ else if (figure->data->reading) msg = _("[rendering ... ]");
} else
- if (fname.empty()) msg = _("[no file]");
- else if ((flags & 3) == 0) msg = _("[not displayed]");
- else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
+ if (fname.empty()) msg = _("[no file]");
+ else if ((flags & 3) == 0) msg = _("[not displayed]");
+ else if (lyxrc->ps_command.empty()) msg = _("[no ghostscript]");
if (!msg) msg = _("[unknown error]");
font.setFamily (LyXFont::SANS_FAMILY);
font.setSize (LyXFont::SIZE_FOOTNOTE);
- LString justname = OnlyFilename (fname);
- font.drawString(justname,pm,
- baseline - font.maxAscent() - 4,
- (int) x + 8);
+ string justname = OnlyFilename (fname);
+ font.drawString(justname, pm,
+ baseline - font.maxAscent() - 4,
+ int(x) + 8);
font.setSize (LyXFont::SIZE_TINY);
- font.drawText (msg, strlen(msg),pm,
+ font.drawText (msg, strlen(msg), pm,
baseline - 4,
- (int) x + 8);
+ int(x) + 8);
}
x += Width(font); // ?
}
-void InsetFig::Write(FILE *file)
+void InsetFig::Write(ostream & os)
{
Regenerate();
- fprintf(file, "Figure size %d %d\n", wid, hgh);
+ os << "Figure size " << wid << " " << hgh << "\n";
if (!fname.empty()) {
- LString buf1 = OnlyPath(owner->getFileName());
- LString fname2 = MakeRelPath(fname, buf1);
- fprintf(file, "file %s\n", fname2.c_str());
+ string buf1 = OnlyPath(owner->fileName());
+ string fname2 = MakeRelPath(fname, buf1);
+ os << "file " << fname2 << "\n";
}
if (!subcaption.empty())
- fprintf(file, "subcaption %s\n", subcaption.c_str());
- if (wtype) fprintf(file, "width %d %g\n", wtype, xwid);
- if (htype) fprintf(file, "height %d %g\n", htype, xhgh);
- if (angle != 0) fprintf(file, "angle %g\n", angle);
- fprintf(file, "flags %d\n", flags);
- if (subfigure) fprintf(file, "subfigure\n");
+ os << "subcaption " << subcaption << "\n";
+ if (wtype) os << "width " << static_cast<int>(wtype) << " " << xwid << "\n";
+ if (htype) os << "height " << static_cast<int>(htype) << " " << xhgh << "\n";
+ if (angle != 0) os << "angle " << angle << "\n";
+ os << "flags " << flags << "\n";
+ if (subfigure) os << "subfigure\n";
}
-void InsetFig::Read(LyXLex &lex)
+void InsetFig::Read(LyXLex & lex)
{
- LString buf;
+ string buf;
bool finished = false;
while (lex.IsOK() && !finished) {
lex.next();
- LString const token = lex.GetString();
- lyxerr.debug("Token: " + token);
+ string const token = lex.GetString();
+ lyxerr.debug() << "Token: " << token << endl;
if (token.empty())
continue;
} else if (token == "file") {
if (lex.next()) {
buf = lex.GetString();
- LString buf1 = OnlyPath(owner->getFileName());
+ string buf1 = OnlyPath(owner->fileName());
fname = MakeAbsPath(buf, buf1);
changedfname = true;
}
case PER_PAGE: wtype = PER_PAGE; break;
case PER_COL: wtype = PER_COL; break;
default:
- lyxerr.debug("Unknown type!");
+ lyxerr.debug() << "Unknown type!" << endl;
break;
}
twtype = wtype;
case IN: htype = IN; break;
case PER_PAGE: htype = PER_PAGE; break;
default:
- lyxerr.debug("Unknown type!");
+ lyxerr.debug() << "Unknown type!" << endl;
break;
}
thtype = htype;
}
-int InsetFig::Latex(FILE *file, signed char /* fragile*/ )
+int InsetFig::Latex(ostream & os, signed char /* fragile*/ )
{
Regenerate();
- if (!cmd.empty()) fprintf(file, "%s ", cmd.c_str());
+ if (!cmd.empty()) os << cmd << " ";
return 0;
}
-int InsetFig::Latex(LString &file, signed char /* fragile*/ )
+int InsetFig::Latex(string & file, signed char /* fragile*/ )
{
Regenerate();
file += cmd + ' ';
}
-int InsetFig::Linuxdoc(LString &/*file*/)
+int InsetFig::Linuxdoc(string &/*file*/)
{
return 0;
}
-int InsetFig::DocBook(LString &file)
+int InsetFig::DocBook(string & file)
{
- LString figurename=fname;
+ string figurename = fname;
- if(figurename.suffixIs(".eps"))
- figurename=figurename.substring(0,fname.length()-5);
+ if(suffixIs(figurename, ".eps"))
+ figurename.erase(fname.length() - 5);
file += "@<graphic fileref=\"" + figurename + "\"></graphic>";
return 0;
}
-void InsetFig::Validate(LaTeXFeatures &features) const
+void InsetFig::Validate(LaTeXFeatures & features) const
{
features.graphics = true;
if (subfigure) features.subfigure = true;
void InsetFig::Edit(int, int)
{
- lyxerr.debug("Editing InsetFig.");
+ lyxerr.debug() << "Editing InsetFig." << endl;
Regenerate();
// We should have RO-versions of the form instead.
// The actual prevention of altering a readonly doc
// is done in CallbackFig()
- if(current_view->currentBuffer()->isReadonly())
- WarnReadonly();
+ if(current_view->buffer()->isReadonly())
+ WarnReadonly(current_view->buffer()->fileName());
if (!form) {
form = create_form_Figure();
- fl_set_form_atclose(form->Figure, CancelCloseBoxCB, NULL);
- 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);
+ fl_set_form_atclose(form->Figure, CancelCloseBoxCB, 0);
+ 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);
}
RestoreForm();
if (form->Figure->visible) {
}
-Inset *InsetFig::Clone()
+Inset * InsetFig::Clone() const
{
- InsetFig *tmp = new InsetFig(100, 100, owner);
+ InsetFig * tmp = new InsetFig(100, 100, owner);
if (lyxerr.debugging()) {
- fprintf(stderr, "Clone Figure: buffer:[%d], cbuffer:[xx]\n",
- PTR_AS_INT(current_view->currentBuffer()));
+ lyxerr << "Clone Figure: buffer:["
+ << current_view->buffer()
+ << "], cbuffer:[xx]" << endl;
}
tmp->wid = wid;
tmp->pshgh = pshgh;
tmp->fname = fname;
if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
- // do not display if there is "do not display" chosen (Matthias 260696)
+ // do not display if there is
+ // "do not display" chosen (Matthias 260696)
tmp->figure->data = getfigdata(wid, hgh, fname, psx, psy,
pswid, pshgh, raw_wid, raw_hgh,
angle, flags & (3|8));
- } else tmp->figure->data = NULL;
+ } else tmp->figure->data = 0;
tmp->subcaption = subcaption;
tmp->changedfname = false;
tmp->owner = owner;
void InsetFig::Regenerate()
{
- LString cmdbuf;
- LString gcmd;
- LString resizeW, resizeH;
- LString rotate, recmd;
+ string cmdbuf;
+ string resizeW, resizeH;
+ string rotate, recmd;
if (fname.empty()) {
cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
return;
}
- LString buf1 = OnlyPath(owner->getFileName());
- LString fname2 = MakeRelPath(fname, buf1);
+ string buf1 = OnlyPath(owner->fileName());
+ string fname2 = MakeRelPath(fname, buf1);
- gcmd = "\\includegraphics{" + fname2 + '}';
+ string gcmd = "\\includegraphics{" + fname2 + '}';
switch (wtype) {
case DEF:
if (subfigure) {
if (!subcaption.empty())
cmdbuf = "\\subfigure[" + subcaption +
- "]{" + cmdbuf + "}";
+ "]{" + cmdbuf + "}";
else
cmdbuf = "\\subfigure{" + cmdbuf + "}";
}
void InsetFig::TempRegenerate()
{
- LString gcmd;
- LString cmdbuf;
- LString resizeW, resizeH;
- LString rotate, recmd;
- LString tsubcap;
+ string cmdbuf;
+ string resizeW, resizeH;
+ string rotate, recmd;
- char const *tfname; // *textra;
- float tangle, txwid, txhgh;
-
- tfname = fl_get_input(form->EpsFile);
- tsubcap = fl_get_input(form->Subcaption);
- tangle = atof(fl_get_input(form->Angle));
- txwid = atof(fl_get_input(form->Width));
- txhgh = atof(fl_get_input(form->Height));
+ 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));
if (!tfname || !*tfname) {
//fl_set_object_label(form->cmd, "");
return;
}
- LString buf1 = OnlyPath(owner->getFileName());
- LString fname2 = MakeRelPath(tfname, buf1);
+ string buf1 = OnlyPath(owner->fileName());
+ string fname2 = MakeRelPath(tfname, buf1);
// \includegraphics*[<llx,lly>][<urx,ury>]{file}
- gcmd = "\\includegraphics{" + fname2 + '}';
+ string gcmd = "\\includegraphics{" + fname2 + '}';
switch (twtype) {
case DEF:
if (!rotate.empty()) cmdbuf += '}';
if (!recmd.empty()) cmdbuf += '}';
if (psubfigure && !tsubcap.empty()) {
- cmdbuf = LString("\\subfigure{") + tsubcap
- + LString("}{") + cmdbuf + "}";
+ cmdbuf = string("\\subfigure{") + tsubcap
+ + string("}{") + cmdbuf + "}";
}
-
-
- //fl_set_object_label(form->cmd, cmdbuf.c_str());
- //fl_redraw_object(form->cmd);
}
void InsetFig::Recompute()
{
bool changed = changedfname;
- int newx, newy, nraw_x, nraw_y, frame_wid, frame_hgh;
- float sin_a, cos_a;
+ int newx, newy, nraw_x, nraw_y;
if (changed) GetPSSizes();
- sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
- cos_a = cos (angle / DEG2PI);
- frame_wid = (int) ceil (fabs(cos_a * pswid) + fabs(sin_a * pshgh));
- frame_hgh= (int) ceil (fabs(cos_a * pshgh) + fabs(sin_a * pswid));
+ float sin_a = sin (angle / DEG2PI); /* rotation; H. Zeller 021296 */
+ float cos_a = cos (angle / DEG2PI);
+ int frame_wid = int(ceil(fabs(cos_a * pswid) + fabs(sin_a * pshgh)));
+ int frame_hgh= int(ceil(fabs(cos_a * pshgh) + fabs(sin_a * pswid)));
/* now recompute wid and hgh, and if that is changed, set changed */
/* this depends on chosen size of the picture and its bbox */
case DEF:
break;
case CM: /* cm */
- newx = (int) (28.346*xwid);
+ newx = int(28.346 * xwid);
break;
case IN: /* in */
- newx = (int) (72*xwid);
+ newx = int(72 * xwid);
break;
case PER_PAGE: /* % of page */
- newx = (int) (5.95*xwid);
+ newx = int(5.95 * xwid);
break;
case PER_COL: /* % of col */
- newx = (int) (2.975*xwid);
+ newx = int(2.975 * xwid);
break;
}
switch (htype) {
case DEF:
- //fprintf(stderr, "This should not happen!\n");
+ //lyxerr << "This should not happen!" << endl;
break;
- case CM: /* cm */
- newy = (int) (28.346*xhgh);
+ case CM: /* cm */
+ newy = int(28.346 * xhgh);
break;
case IN: /* in */
- newy = (int) (72*xhgh);
+ newy = int(72 * xhgh);
break;
- case PER_PAGE: /* % of page */
- newy = (int) (8.42*xhgh);
+ case PER_PAGE: /* % of page */
+ newy = int(8.42 * xhgh);
break;
- case PER_COL:
- // Doesn't occur; case exists to suppress
+ case PER_COL:
+ // Doesn't occur; case exists to suppress
// compiler warnings.
break;
}
- if (htype && !wtype && frame_hgh) newx = newy*frame_wid/frame_hgh;
+ if (htype && !wtype && frame_hgh)
+ newx = newy*frame_wid/frame_hgh;
} else {
newx = wid;
newy = hgh;
if (frame_wid == 0)
nraw_x = 5;
else
- nraw_x = (int) ((1.0 * pswid * newx)/frame_wid);
+ nraw_x = int((1.0 * pswid * newx)/frame_wid);
if (frame_hgh == 0)
nraw_y = 5;
else
- nraw_y = (int) ((1.0 * pshgh * newy)/frame_hgh);
+ nraw_y = int((1.0 * pshgh * newy)/frame_hgh);
// cannot be zero, actually, set it to some minimum, so its clickable
if (newx < 5) newx = 5;
subfigure = psubfigure;
if (changed) {
- figdata *pf = figure->data;
+ figdata * pf = figure->data;
// get new data
- if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
+ if (!fname.empty() && (flags & 3)
+ && !lyxrc->ps_command.empty()) {
// do not display if there is "do not display"
// chosen (Matthias 260696)
figure->data = getfigdata(wid, hgh, fname,
psx, psy, pswid, pshgh,
raw_wid, raw_hgh,
angle, flags & (3|8));
- } else figure->data = NULL;
+ } else figure->data = 0;
// free the old data
if (pf) freefigdata(pf);
void InsetFig::GetPSSizes()
{
/* get %%BoundingBox: from postscript file */
- int lastchar, c;
- char *p = NULL;
/* defaults to associated size
- * ..just in case the PS-file is not readable (Henner,24-Aug-97)
+ * ..just in case the PS-file is not readable (Henner, 24-Aug-97)
*/
psx = 0;
psy = 0;
pshgh = hgh;
if (fname.empty()) return;
-
- FilePtr f(fname, FilePtr::read);
+ string p;
+ ifstream ifs(fname.c_str());
- if (!f()) return; // file not found !!!!
+ if (!ifs) return; // file not found !!!!
/* defaults to A4 page */
psx = 0;
pswid = 595;
pshgh = 842;
- lastchar = fgetc(f);
+ char lastchar = 0; ifs.get(lastchar);
for (;;) {
- c = fgetc(f);
- if (c == EOF) {
- lyxerr.debug("End of (E)PS file reached and"
- " no BoundingBox!");
+ char c = 0; ifs.get(c);
+ if (ifs.eof()) {
+ lyxerr.debug() << "End of (E)PS file reached and"
+ " no BoundingBox!" << endl;
break;
}
if (c == '%' && lastchar == '%') {
- p = NextToken(f);
- if (!p) break;
- if (strcmp(p, "EndComments") == 0) break;
- if (strcmp(p, "BoundingBox:") == 0) {
+ p = NextToken(ifs);
+ if (p.empty()) break;
+ // we should not use this, with it we cannot
+ // discover bounding box and end of file.
+ //if (strcmp(p, "EndComments") == 0) break;
+ lyxerr.debug() << "Token: `" << p << "'" << endl;
+ if (p == "BoundingBox:") {
float fpsx, fpsy, fpswid, fpshgh;
- if (fscanf(f, "%f %f %f %f", &fpsx, &fpsy,
- &fpswid, &fpshgh) == 4) {
- psx = (int) fpsx;
- psy = (int) fpsy;
- pswid = (int) fpswid;
- pshgh = (int) fpshgh;
- }
-
+ if (ifs >> fpsx >> fpsy >> fpswid >> fpshgh) {
+ psx = int(fpsx);
+ psy = int(fpsy);
+ pswid = int(fpswid);
+ pshgh = int(fpshgh);
+ }
if (lyxerr.debugging()) {
- fprintf(stderr, "%%%%BoundingBox:"
- " %d %d %d %d\n",
- psx, psy, pswid, pshgh);
- break;
+ lyxerr << "%%%%BoundingBox:"
+ << psx << ' '
+ << psy << ' '
+ << pswid << ' '
+ << pshgh << endl;
}
+ break;
}
c = 0;
- delete[] p;
- p = NULL;
}
lastchar = c;
}
- if (p) delete[] p;
pswid -= psx;
pshgh -= psy;
void InsetFig::CallbackFig(long arg)
{
bool regen = false;
- char const *p;
+ char const * p;
if (lyxerr.debugging()) {
- printf("Figure callback, arg %ld\n", arg);
+ lyxerr << "Figure callback, arg " << arg << endl;
}
switch (arg) {
fl_activate_object(form->Width);
break;
default:
- lyxerr.debug("Unknown type!");
+ lyxerr.debug() << "Unknown type!" << endl;
break;
}
regen = true;
fl_activate_object(form->Height);
break;
default:
- lyxerr.debug("Unknown type!");
+ lyxerr.debug() << "Unknown type!" << endl;
break;
}
regen = true;
break;
case 7: /* apply */
case 8: /* ok (apply and close) */
- if(!current_view->currentBuffer()->isReadonly())
- {
+ if(!current_view->buffer()->isReadonly()) {
wtype = twtype;
htype = thtype;
xwid = atof(fl_get_input(form->Width));
angle = atof(fl_get_input(form->Angle));
p = fl_get_input(form->EpsFile);
if (p && *p) {
- LString buf1 = OnlyPath(owner->getFileName());
+ string buf1 = OnlyPath(owner->fileName());
fname = MakeAbsPath(p, buf1);
changedfname = true;
} else {
if (!fname.empty()) {
changedfname = true;
- fname.clean();
+ fname.clear();
}
}
subcaption = fl_get_input(form->Subcaption);
Recompute();
/* now update inset */
if (lyxerr.debugging()) {
- fprintf(stderr, "Update: [%dx%d]\n", wid, hgh);
+ lyxerr << "Update: ["
+ << wid << 'x' << hgh << ']' << endl;
}
UpdateInset(this);
if (arg == 8) {
+ fl_set_focus_object(form->Figure, form->OkBtn);
fl_hide_form(form->Figure);
+#if FL_REVISION == 89
+#warning Reactivate this free_form calls
+#else
fl_free_form(form->Figure);
- free(form);
- form = NULL;
+ free(form); // Why free?
+ form = 0;
+#endif
}
break;
} //if not readonly
break;
// fall through
case 9: /* cancel = restore and close */
+ fl_set_focus_object(form->Figure, form->OkBtn);
fl_hide_form(form->Figure);
+#if FL_REVISION == 89
+#warning Reactivate this free_form calls
+#warning Jug, is this still a problem?
+#else
fl_free_form(form->Figure);
- free(form);
- form = NULL;
+ free(form); // Why free?
+ form = 0;
+#endif
break;
}
if (regen) TempRegenerate();
}
+
inline void DisableFigurePanel(FD_Figure * const form)
{
fl_deactivate_object(form->EpsFile);
fl_set_object_lcol (form->ApplyBtn, FL_INACTIVE);
}
+
inline void EnableFigurePanel(FD_Figure * const form)
{
fl_activate_object(form->EpsFile);
fl_set_object_lcol (form->ApplyBtn, FL_BLACK);
}
+
void InsetFig::RestoreForm()
{
char buf[32];
- int pflags;
EnableFigurePanel(form);
fl_activate_object(form->Height);
}
- pflags = flags & 3;
+ int pflags = flags & 3;
fl_set_button(form->Wysiwyg0, (pflags == 0));
fl_set_button(form->Wysiwyg1, (pflags == 1));
fl_set_button(form->Wysiwyg2, (pflags == 2));
sprintf(buf, "%g", angle);
fl_set_input(form->Angle, buf);
if (!fname.empty()){
- LString buf1 = OnlyPath(owner->getFileName());
- LString fname2 = MakeRelPath(fname, buf1);
+ string buf1 = OnlyPath(owner->fileName());
+ string fname2 = MakeRelPath(fname, buf1);
fl_set_input(form->EpsFile, fname2.c_str());
}
else fl_set_input(form->EpsFile, "");
fl_set_input(form->Subcaption, subcaption.c_str());
- if(current_view->currentBuffer()->isReadonly())
+ if(current_view->buffer()->isReadonly())
DisableFigurePanel(form);
TempRegenerate();
}
-void InsetFig::Preview(char const *p)
+void InsetFig::Preview(char const * p)
{
- int pid;
-
- pid = fork();
+ int pid = fork();
if (pid == -1) {
- lyxerr.print("Cannot fork process!");
+ lyxerr << "Cannot fork process!" << endl;
return; // error
}
if (pid > 0) {
return; // parent process
}
- LString buf1 = OnlyPath(owner->getFileName());
- LString buf2 = MakeAbsPath(p, buf1);
+ string buf1 = OnlyPath(owner->fileName());
+ string buf2 = MakeAbsPath(p, buf1);
- lyxerr.print(LString("Error during rendering ") +
- int(execlp(lyxrc->view_pspic_command.c_str(),
- lyxrc->view_pspic_command.c_str(),
- buf2.c_str(),
- NULL)));
+ lyxerr << "Error during rendering "
+ << execlp(lyxrc->view_pspic_command.c_str(),
+ lyxrc->view_pspic_command.c_str(),
+ buf2.c_str(), 0)
+ << endl;
_exit(0);
}
void InsetFig::BrowseFile()
{
- LString buf, buf2, bufclip;
- static LString current_figure_path;
+ static string current_figure_path;
static int once = 0;
LyXFileDlg fileDlg;
if (lyxerr.debugging()) {
- fprintf(stderr, "Filename: %s\n", owner->getFileName().c_str());
+ lyxerr << "Filename: "
+ << owner->fileName() << endl;
}
- LString p = fl_get_input(form->EpsFile);
+ string p = fl_get_input(form->EpsFile);
- buf = MakeAbsPath(owner->getFileName());
- buf2 = OnlyPath(buf);
+ string buf = MakeAbsPath(owner->fileName());
+ string buf2 = OnlyPath(buf);
if (!p.empty()) {
buf = MakeAbsPath(p, buf2);
buf = OnlyPath(buf);
} else {
- buf = OnlyPath(owner->getFileName().c_str());
+ buf = OnlyPath(owner->fileName().c_str());
}
// Does user clipart directory exist?
- bufclip = AddName (user_lyxdir, "clipart");
+ string bufclip = AddName (user_lyxdir, "clipart");
FileInfo fileInfo(bufclip);
if (!(fileInfo.isOK() && fileInfo.isDir()))
- // No - bail out to system clipart directory
- bufclip = AddName (system_lyxdir, "clipart");
+ // No - bail out to system clipart directory
+ bufclip = AddName (system_lyxdir, "clipart");
fileDlg.SetButton(0, _("Clipart"), bufclip);
do {
ProhibitInput();
if (once) {
- p =fileDlg.Select(_("EPS Figure"), current_figure_path,
- "*ps", LString());
+ p = fileDlg.Select(_("EPS Figure"),
+ current_figure_path,
+ "*ps", string());
} else {
p = fileDlg.Select(_("EPS Figure"), buf,
- "*ps", LString());
+ "*ps", string());
}
AllowInput();
current_figure_path = OnlyPath(p);
once = 1;
- if (p.contains("#") || p.contains("~") || p.contains("$")
- || p.contains("%") || p.contains(" "))
- {
- WriteAlert(_("Filename can't contain any of these characters:"), // xgettext:no-c-format
- _("space, '#', '~', '$' or '%'."));
- error = true;
- }
+ if (contains(p, "#") || contains(p, "~") || contains(p, "$")
+ || contains(p, "%") || contains(p, " "))
+ {
+ WriteAlert(_("Filename can't contain any "
+ "of these characters:"),
+ // xgettext:no-c-format
+ _("space, '#', '~', '$' or '%'."));
+ error = true;
+ }
} while (error);
if (form) fl_set_input(form->EpsFile, buf.c_str());
}
-void GraphicsCB(FL_OBJECT *obj, long arg)
+void GraphicsCB(FL_OBJECT * obj, long arg)
{
/* obj->form contains the form */
if (lyxerr.debugging()) {
- lyxerr.print(LString("GraphicsCB callback: ") + long(arg));
+ lyxerr << "GraphicsCB callback: " << arg << endl;
}
/* find inset we were reacting to */
== obj->form) {
if (lyxerr.debugging()) {
- lyxerr.print(LString("Calling back figure ")
- +int(i));
+ lyxerr << "Calling back figure " << i << endl;
}
figures[i]->inset->CallbackFig(arg);
return;
if (figures[i]->inset->form
&& figures[i]->inset->form->Figure->visible) {
if (lyxerr.debugging()) {
- lyxerr.print(LString("Hiding figure ")
- +int(i));
+ lyxerr << "Hiding figure " << i << endl;
}
// hide and free the form
figures[i]->inset->CallbackFig(9);