home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dream 52
/
Amiga_Dream_52.iso
/
Linux
/
Divers
/
lyx-0.13.2.tar.gz
/
lyx-0.13.2.tar
/
lyx-0.13.2
/
src
/
insetfig.C
< prev
next >
Wrap
C/C++ Source or Header
|
1998-04-23
|
27KB
|
1,183 lines
#include <config.h>
#include <unistd.h>
#include <math.h>
#include <ctype.h>
#include "insetfig.h"
#include "error.h"
#include "lyxrc.h"
#include "filetools.h"
#include "lyx_gui_misc.h"
#include "FileInfo.h"
#include "filedlg.h"
#include "lyx_main.h"
#include "procMgr.h"
extern LyXRC *lyxrc;
extern BufferView *current_view;
//extern void sigchldhandler(int sig);
extern void UpdateInset(Inset* inset, bool mark_dirty = true);
extern void ProhibitInput();
extern void AllowInput();
static char* NextToken(FILE *myfile);
const float DEG2PI = 57.295779513;
InsetFig::InsetFig(int tmpx, int tmpy, Buffer *o)
: owner(o)
{
wid = tmpx;
hgh = tmpy;
wtype = DEF;
htype = DEF;
twtype = DEF;
thtype = DEF;
pflags = flags = 9;
psubfigure = subfigure = false;
xwid = xhgh = angle = 0;
raw_wid = raw_hgh = 0;
changedfname = false;
figL.RegisterFigure(this);
}
InsetFig::~InsetFig()
{
if (lyxerr.debugging()) {
printf("Figure destructor called\n");
}
figL.UnregisterFigure(this);
}
int InsetFig::Ascent(LyXFont const&) const
{
return hgh + 3;
}
int InsetFig::Descent(LyXFont const&) const
{
return 1;
}
int InsetFig::Width(LyXFont const&) const
{
return wid + 2;
}
void InsetFig::Draw(LyXFont font, LyXScreen &scr, int baseline, float &x)
{
if (figL.bitmap_waiting) figL.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.
unsigned long pm = scr.getForeground();
if (figure && figure->data && figure->data->bitmap &&
!figure->data->reading && !figure->data->broken) {
// draw the bitmap
XCopyArea(fl_display, figure->data->bitmap, pm, getGC(gc_copy),
0, 0, wid, hgh, int(x+1), baseline-hgh);
XFlush(fl_display);
if (flags & 4) XDrawRectangle(fl_display, pm, getGC(gc_copy),
int(x), baseline - hgh - 1,
wid+1, hgh+1);
} else {
LString msg;
// draw frame
XDrawRectangle(fl_display, pm, getGC(gc_copy),
(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 ... ]");
} 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 (msg.empty()) 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));
font.setSize (LyXFont::SIZE_TINY);
font.drawString(msg,pm,
baseline - 4,
int(x + 8));
}
x += Width(font); // ?
}
void InsetFig::Write(FILE *file)
{
Regenerate();
fprintf(file, "Figure size %d %d\n", wid, hgh);
if (!fname.empty()) {
LString buf1 = OnlyPath(owner->getFileName());
LString fname2 = MakeRelPath(fname, buf1);
fprintf(file, "file %s\n", fname2.c_str());
}
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");
}
void InsetFig::Read(LyXLex &lex)
{
LString buf;
//int i;
bool finished = false;
while (lex.IsOK() && !finished) {
lex.next();
LString const token = lex.GetString();
lyxerr.debug("Token: " + token);
if (token.empty())
continue;
else if (token == "\\end_inset") {
finished = true;
} else if (token == "file") {
if (lex.next()) {
buf = lex.GetString();
LString buf1 = OnlyPath(owner->getFileName());
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:
lyxerr.debug("Unknown type!");
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:
lyxerr.debug("Unknown type!");
break;
}
thtype = htype;
}
}
Regenerate();
Recompute();
}
int InsetFig::Latex(FILE *file, signed char /* fragile*/ )
{
Regenerate();
if (!cmd.empty()) fprintf(file, "%s ", cmd.c_str());
return 0;
}
int InsetFig::Latex(LString &file, signed char /* fragile*/ )
{
Regenerate();
file += cmd + ' ';
return 0;
}
void InsetFig::Validate(LaTeXFeatures &features) const
{
features.graphics = true;
if (subfigure) features.subfigure = true;
}
unsigned char InsetFig::Editable() const
{
return 1;
}
bool InsetFig::Deletable() const
{
return false;
}
void InsetFig::Edit(int, int)
{
if (lyxerr.debugging()) {
printf("Editing InsetFig\n");
}
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 (!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);
}
RestoreForm();
if (form->Figure->visible) {
fl_raise_form(form->Figure);
} else {
fl_show_form(form->Figure, FL_PLACE_MOUSE | FL_PLACE_SIZE,
FL_FULLBORDER, _("Figure"));
}
}
Inset *InsetFig::Clone()
{
InsetFig *tmp = new InsetFig(100, 100, owner);
if (lyxerr.debugging()) {
printf("Clone Figure: buffer:[%d], cbuffer:[xx]\n",
PTR_AS_INT(current_view->currentBuffer()));
}
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;
if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
// do not display if there is "do not display" chosen (Matthias 260696)
tmp->figure->data =
figL.getfigdata(wid, hgh, fname, psx, psy,
pswid, pshgh, raw_wid, raw_hgh,
angle, flags & (3|8));
} else tmp->figure->data = NULL;
tmp->subcaption = subcaption;
tmp->changedfname = false;
tmp->owner = owner;
tmp->Regenerate();
return tmp;
}
Inset::Code InsetFig::LyxCode() const
{
return Inset::GRAPHICS_CODE;
}
void InsetFig::Regenerate()
{
LString cmdbuf;
LString gcmd;
LString resizeW, resizeH;
LString rotate, recmd;
if (fname.empty()) {
cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
cmd += _("empty figure path");
cmd += '}';
//if (form) fl_set_object_label(form->cmd, "");
return;
}
LString buf1 = OnlyPath(owner->getFileName());
LString fname2 = MakeRelPath(fname, buf1);
gcmd = "\\includegraphics{" + fname2 + '}';
switch (wtype) {
case DEF:
break;
case CM:{// \resizebox*{h-length}{v-length}{text}
char buf[10];
sprintf(buf, "%g", xwid); // should find better
resizeW = buf;
resizeW += "cm";
break;
}
case IN: {
char buf[10];
sprintf(buf, "%g", xwid);
resizeW = buf;
resizeW += "in";
break;
}
case PER_PAGE:{
char buf[10];
sprintf(buf, "%g", xwid/100);
resizeW = buf;
resizeW += "\\textwidth";
break;
}
case PER_COL:{
char buf[10];
sprintf(buf, "%g", xwid/100);
resizeW = buf;
resizeW += "\\columnwidth";
break;
}
}
switch (htype) {
case DEF:
break;
case CM: {
char buf[10];
sprintf(buf, "%g", xhgh);
resizeH = buf;
resizeH += "cm";
break;
}
case IN:{
char buf[10];
sprintf(buf, "%g", xhgh);
resizeH = buf;
resizeH += "in";
break;
}
case PER_PAGE: {
char buf[10];
sprintf(buf, "%g", xhgh/100);
resizeH = buf;
resizeH += "\\textheight";
break;
}
case PER_COL: {
// Doesn't occur; case exists to suppress compiler warnings.
break;
}
}
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) {
char buf[10];
sprintf(buf, "%g", angle);
// \rotatebox{angle}{text}
rotate = "\\rotatebox{";
rotate += buf;
rotate += "}{";
}
cmdbuf = recmd;
cmdbuf += rotate;
cmdbuf += gcmd;
if (!rotate.empty()) cmdbuf += '}';
if (!recmd.empty()) cmdbuf += '}';
if (subfigure) {
if (!subcaption.empty())
cmdbuf = "\\subfigure[" + subcaption +
"]{" + cmdbuf + "}";
else
cmdbuf = "\\subfigure{" + cmdbuf + "}";
}
cmd = cmdbuf;
}
void InsetFig::TempRegenerate()
{
LString gcmd;
LString cmdbuf;
LString resizeW, resizeH;
LString rotate, recmd;
LString tsubcap;
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));
if (!tfname || !*tfname) {
cmd = "\\fbox{\\rule[-0.5in]{0pt}{1in}";
cmd += _("empty figure path");
cmd += '}';
return;
}
LString buf1 = OnlyPath(owner->getFileName());
LString fname2 = MakeRelPath(tfname, buf1);
// \includegraphics*[<llx,lly>][<urx,ury>]{file}
gcmd = "\\includegraphics{" + fname2 + '}';
switch (twtype) {
case DEF:
break;
case CM: {// \resizebox*{h-length}{v-length}{text}
char buf[10];
sprintf(buf, "%g", txwid); // should find better
resizeW = buf;
resizeW += "cm";
break;
}
case IN: {
char buf[10];
sprintf(buf, "%g", txwid);
resizeW = buf;
resizeW += "in";
break;
}
case PER_PAGE: {
char buf[10];
sprintf(buf, "%g", txwid/100);
resizeW = buf;
resizeW += "\\textwidth";
break;
}
case PER_COL: {
char buf[10];
sprintf(buf, "%g", txwid/100);
resizeW = buf;
resizeW += "\\columnwidth";
break;
}
}
switch (thtype) {
case DEF:
break;
case CM: {
char buf[10];
sprintf(buf, "%g", txhgh);
resizeH = buf;
resizeH += "cm";
break;
}
case IN: {
char buf[10];
sprintf(buf, "%g", txhgh);
resizeH = buf;
resizeH += "in";
break;
}
case PER_PAGE: {
char buf[10];
sprintf(buf, "%g", txhgh/100);
resizeH = buf;
resizeH += "\\textheight";
break;
}
case PER_COL: {
// Doesn't occur; case exists to suppress compiler warnings.
break;
}
}
// \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) {
char buf[10];
sprintf(buf, "%g", tangle);
// \rotatebox{angle}{text}
rotate = "\\rotatebox{";
rotate += buf;
rotate += "}{";
}
cmdbuf = recmd;
cmdbuf += rotate;
cmdbuf += gcmd;
if (!rotate.empty()) cmdbuf += '}';
if (!recmd.empty()) cmdbuf += '}';
if (psubfigure && !tsubcap.empty()) {
cmdbuf = LString("\\subfigure{") + tsubcap
+ LString("}{") + cmdbuf + "}";
}
}
void InsetFig::Recompute()
{
bool changed = changedfname;
int newx, newy, nraw_x, nraw_y, frame_wid, frame_hgh;
float sin_a, cos_a;
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));
/* 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)
if (!fname.empty()) {
// 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 */
newx = (int) (28.346*xwid);
break;
case IN: /* in */
newx = (int) (72*xwid);
break;
case PER_PAGE: /* % of page */
newx = (int) (5.95*xwid);
break;
case PER_COL: /* % of col */
newx = (int) (2.975*xwid);
break;
}
if (wtype && frame_wid) newy = newx*frame_hgh/frame_wid;
switch (htype) {
case DEF:
//fprintf(stderr, "This should not happen!\n");
break;
case CM: /* cm */
newy = (int) (28.346*xhgh);
break;
case IN: /* in */
newy = (int) (72*xhgh);
break;
case PER_PAGE: /* % of page */
newy = (int) (8.42*xhgh);
break;
case PER_COL:
// Doesn't occur; case exists to suppress
// compiler warnings.
break;
}
if (htype && !wtype && frame_hgh) newx = newy*frame_wid/frame_hgh;
} else {
newx = wid;
newy = hgh;
}
nraw_x = int((1.0 * pswid * newx)/frame_wid);
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;
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) {
figdata *pf = figure->data;
// get new data
if (!fname.empty() && (flags & 3) && !lyxrc->ps_command.empty()) {
// do not display if there is "do not display"
// chosen (Matthias 260696)
figure->data = figL.getfigdata(wid, hgh, fname,
psx, psy, pswid, pshgh,
raw_wid, raw_hgh,
angle, flags & (3|8));
} else figure->data = NULL;
// free the old data
if (pf) figL.freefigdata(pf);
}
changedfname = false;
}
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)
*/
psx = 0;
psy = 0;
pswid = wid;
pshgh = hgh;
if (fname.empty()) return;
FilePtr f(fname, FilePtr::read);
if (!f()) return; // file not found !!!!
/* defaults to A4 page */
psx = 0;
psy = 0;
pswid = 595;
pshgh = 842;
lastchar = fgetc(f);
for (;;) {
c = fgetc(f);
if (c == EOF) {
lyxerr.debug("End of (E)PS file reached and"
" no BoundingBox!");
break;
}
if (c == '%' && lastchar == '%') {
p = NextToken(f);
if (!p) break;
if (strcmp(p, "EndComments") == 0) break;
if (strcmp(p, "BoundingBox:") == 0) {
fscanf(f, "%d %d %d %d", &psx, &psy,
&pswid, &pshgh);
if (lyxerr.debugging()) {
fprintf(stderr, "%%%%BoundingBox:"
" %d %d %d %d\n",
psx, psy, pswid, pshgh);
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;
if (lyxerr.debugging()) {
printf("Figure callback, arg %ld\n", arg);
}
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:
lyxerr.debug("Unknown type!");
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:
lyxerr.debug("Unknown type!");
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) */
if(!current_view->currentBuffer()->isReadonly())
{
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) {
LString buf1 = OnlyPath(owner->getFileName());
fname = MakeAbsPath(p, buf1);
changedfname = true;
} else {
if (!fname.empty()) {
changedfname = true;
fname.erase();
}
}
subcaption = fl_get_input(form->Subcaption);
Regenerate();
Recompute();
/* now update inset */
if (lyxerr.debugging()) {
printf("Update: [%dx%d]\n", wid, hgh);
}
UpdateInset(this);
if (arg == 8) {
fl_hide_form(form->Figure);
fl_free_form(form->Figure);
free(form);
form = NULL;
}
break;
} //if not readonly
// The user has already been informed about RO in ::Edit
if(arg == 7) // if 'Apply'
break;
// fall through
case 9: /* cancel = restore and close */
fl_hide_form(form->Figure);
fl_free_form(form->Figure);
free(form);
form = NULL;
break;
}
if (regen) TempRegenerate();
}
inline void DisableFigurePanel(FD_Figure * const form)
{
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);
}
inline void EnableFigurePanel(FD_Figure * const form)
{
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);
}
void InsetFig::RestoreForm()
{
char buf[32];
int pflags;
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);
}
pflags = flags & 3;
fl_set_button(form->Wysiwyg0, (pflags == 0));
fl_set_button(form->Wysiwyg1, (pflags == 1));
fl_set_button(form->Wysiwyg2, (pflags == 2));
fl_set_button(form->Wysiwyg3, (pflags == 3));
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;
sprintf(buf, "%g", xwid);
fl_set_input(form->Width, buf);
sprintf(buf, "%g", xhgh);
fl_set_input(form->Height, buf);
sprintf(buf, "%g", angle);
fl_set_input(form->Angle, buf);
if (!fname.empty()){
LString buf1 = OnlyPath(owner->getFileName());
LString 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())
DisableFigurePanel(form);
TempRegenerate();
}
void InsetFig::Preview(char const *p)
{
int pid;
pid = fork();
if (pid == -1) {
lyxerr.print("Cannot fork process!");
return; // error
}
if (pid > 0) {
procMgr.addpidwait(pid);
return; // parent process
}
LString buf1 = OnlyPath(owner->getFileName());
LString 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)));
_exit(0);
}
void InsetFig::BrowseFile()
{
LString buf, buf2, bufclip;
static LString current_figure_path;
static int once = 0;
LyXFileDlg fileDlg;
if (lyxerr.debugging()) {
printf("Filename: %s\n", owner->getFileName().c_str());
}
LString p = fl_get_input(form->EpsFile);
buf = MakeAbsPath(owner->getFileName());
buf2 = OnlyPath(buf);
if (!p.empty()) {
buf = MakeAbsPath(p, buf2);
buf = OnlyPath(buf);
} else {
buf = OnlyPath(owner->getFileName().c_str());
}
// Does user clipart directory exist?
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");
fileDlg.SetButton(0, _("Clipart"), bufclip);
fileDlg.SetButton(1, _("Document"), buf);
bool error = false;
do {
ProhibitInput();
if (once) {
p =fileDlg.Select(_("EPS Figure"), current_figure_path,
"*ps", LString());
} else {
p = fileDlg.Select(_("EPS Figure"), buf,
"*ps", LString());
}
AllowInput();
if (p.empty()) return;
buf = MakeRelPath(p, buf2);
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:"),
_("space, '#', '~', '$' or '%'."));
error = true;
}
} while (error);
if (form) fl_set_input(form->EpsFile, buf.c_str());
}
void GraphicsCB(FL_OBJECT *obj, long arg)
{
/* obj->form contains the form */
if (lyxerr.debugging()) {
printf("GraphicsCB callback: %ld\n", arg);
}
/* find inset we were reacting to */
for (int i = 0; i < figL.figinsref; ++i)
if (figL.figures[i]->inset->form && figL.figures[i]->inset->form->Figure
== obj->form) {
if (lyxerr.debugging()) {
printf("Calling back figure %d\n", i);
}
figL.figures[i]->inset->CallbackFig(arg);
return;
}
}
static char* NextToken(FILE *myfile)
{
char* token = NULL;
char c;
int i = 0;
if (!feof(myfile)) {
token = new char[256];
do {
c = fgetc(myfile);
token[i++]=c;
} while (!feof(myfile) && !isspace(c));
token[i-1]='\0'; /* just the end of a command */
}
return token;
}