2001-03-28 14:51:25 +00:00
|
|
|
/* This file is part of
|
|
|
|
* ======================================================
|
|
|
|
*
|
|
|
|
* LyX, The Document Processor
|
|
|
|
*
|
|
|
|
* Copyright 1995 Matthias Ettrich,
|
2001-05-30 13:53:44 +00:00
|
|
|
* Copyright 1995-2001 The LyX Team.
|
2001-03-28 14:51:25 +00:00
|
|
|
*
|
|
|
|
* ====================================================== */
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <utility>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include FORMS_H_LOCATION
|
|
|
|
|
|
|
|
#include "figure_form.h"
|
|
|
|
#include "insets/figinset.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "lyxtext.h"
|
|
|
|
#include "LyXView.h"
|
2001-07-06 15:57:54 +00:00
|
|
|
#include "undo_funcs.h"
|
2001-04-17 15:15:59 +00:00
|
|
|
#include "gettext.h"
|
2001-03-28 14:51:25 +00:00
|
|
|
|
|
|
|
extern FD_form_figure * fd_form_figure;
|
|
|
|
extern BufferView * current_view;
|
|
|
|
|
|
|
|
void Figure()
|
|
|
|
{
|
|
|
|
if (fd_form_figure->form_figure->visible) {
|
|
|
|
fl_raise_form(fd_form_figure->form_figure);
|
|
|
|
} else {
|
|
|
|
fl_show_form(fd_form_figure->form_figure,
|
|
|
|
FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
|
|
|
|
_("Insert Figure"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* callbacks for form form_figure */
|
2001-09-09 22:02:19 +00:00
|
|
|
extern "C" {
|
|
|
|
|
2001-03-28 14:51:25 +00:00
|
|
|
void FigureApplyCB(FL_OBJECT *, long)
|
|
|
|
{
|
|
|
|
if (!current_view->available())
|
|
|
|
return;
|
|
|
|
|
|
|
|
Buffer * buffer = current_view->buffer();
|
|
|
|
if (buffer->isReadonly()) // paranoia
|
|
|
|
return;
|
2001-04-17 15:15:59 +00:00
|
|
|
|
2001-04-24 17:33:01 +00:00
|
|
|
current_view->owner()->message(_("Inserting figure..."));
|
2001-03-28 14:51:25 +00:00
|
|
|
if (fl_get_button(fd_form_figure->radio_inline)) {
|
|
|
|
InsetFig * new_inset = new InsetFig(100, 20, *buffer);
|
|
|
|
current_view->insertInset(new_inset);
|
2001-04-24 17:33:01 +00:00
|
|
|
current_view->owner()->message(_("Figure inserted"));
|
2001-06-28 10:25:20 +00:00
|
|
|
new_inset->edit(current_view, 0, 0, 0);
|
2001-03-28 14:51:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_view->hideCursor();
|
|
|
|
current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR);
|
|
|
|
current_view->beforeChange(current_view->text);
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
setCursorParUndo(current_view);
|
|
|
|
freezeUndo();
|
2001-03-28 14:51:25 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
current_view->text->breakParagraph(current_view);
|
2001-03-28 14:51:25 +00:00
|
|
|
current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
|
|
|
|
|
|
|
if (current_view->text->cursor.par()->size()) {
|
2001-06-25 00:06:33 +00:00
|
|
|
current_view->text->cursorLeft(current_view);
|
2001-03-28 14:51:25 +00:00
|
|
|
|
2001-06-25 00:06:33 +00:00
|
|
|
current_view->text->breakParagraph(current_view);
|
2001-03-28 14:51:25 +00:00
|
|
|
current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The standard layout should always be numer 0;
|
2001-06-25 00:06:33 +00:00
|
|
|
current_view->text->setLayout(current_view, 0);
|
2001-03-28 14:51:25 +00:00
|
|
|
|
2001-12-02 23:47:06 +00:00
|
|
|
LyXLength len(0.3 * buffer->params.spacing.getValue(), LyXLength::CM);
|
|
|
|
current_view->text->setParagraph(current_view, 0, 0, 0, 0,
|
|
|
|
VSpace(len), VSpace(len), Spacing(),
|
|
|
|
LYX_ALIGN_CENTER, string(), 0);
|
2001-03-28 14:51:25 +00:00
|
|
|
|
|
|
|
current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
|
|
|
|
|
|
|
|
Inset * new_inset = new InsetFig(100, 100, *buffer);
|
|
|
|
current_view->insertInset(new_inset);
|
2001-06-28 10:25:20 +00:00
|
|
|
new_inset->edit(current_view, 0, 0, 0);
|
2001-03-28 14:51:25 +00:00
|
|
|
current_view->update(current_view->text, BufferView::SELECT|BufferView::FITCUR);
|
2001-04-24 17:33:01 +00:00
|
|
|
current_view->owner()->message(_("Figure inserted"));
|
2001-07-06 15:57:54 +00:00
|
|
|
unFreezeUndo();
|
2001-03-28 14:51:25 +00:00
|
|
|
current_view->setState();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FigureCancelCB(FL_OBJECT *, long)
|
|
|
|
{
|
|
|
|
fl_hide_form(fd_form_figure->form_figure);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FigureOKCB(FL_OBJECT * ob, long data)
|
|
|
|
{
|
|
|
|
FigureApplyCB(ob, data);
|
|
|
|
FigureCancelCB(ob, data);
|
|
|
|
}
|
2001-09-09 22:02:19 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|