From f1c24d100985c6df2eb5ec390017b69c78fe49c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Tue, 18 Jun 2002 15:44:30 +0000 Subject: [PATCH] *duck* git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4417 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 2 +- src/BufferView.h | 4 +- src/BufferView2.C | 8 +- src/BufferView_pimpl.C | 46 +- src/BufferView_pimpl.h | 13 +- src/ChangeLog | 36 ++ src/LyXAction.C | 1 + src/buffer.C | 173 +++--- src/buffer.h | 4 +- src/commandtags.h | 1 + src/frontends/ChangeLog | 66 +- src/frontends/Dialogs.C | 284 ++++++++- src/frontends/Dialogs.h | 96 ++- src/frontends/LyXKeySym.C | 15 + src/frontends/LyXKeySym.h | 60 ++ src/frontends/LyXKeySymFactory.h | 22 + src/frontends/LyXScreenFactory.h | 23 + src/frontends/LyXView.C | 16 +- src/frontends/LyXView.h | 20 +- src/frontends/Makefile.am | 11 +- src/frontends/Toolbar.C | 13 +- src/frontends/Toolbar.h | 12 +- src/frontends/WorkArea.C | 23 + src/frontends/WorkArea.h | 100 ++- src/frontends/WorkAreaFactory.h | 22 + src/frontends/controllers/ChangeLog | 14 +- src/frontends/controllers/ControlAboutlyx.C | 14 +- src/frontends/controllers/ControlBibitem.C | 13 +- src/frontends/controllers/ControlBibtex.C | 15 +- src/frontends/controllers/ControlCharacter.C | 11 +- src/frontends/controllers/ControlCharacter.h | 2 +- src/frontends/controllers/ControlCitation.C | 20 +- src/frontends/controllers/ControlDialog.tmpl | 1 - src/frontends/controllers/ControlERT.C | 21 +- src/frontends/controllers/ControlError.C | 11 +- src/frontends/controllers/ControlExternal.C | 19 +- src/frontends/controllers/ControlFloat.C | 21 +- src/frontends/controllers/ControlForks.C | 7 +- src/frontends/controllers/ControlGraphics.C | 16 +- src/frontends/controllers/ControlInclude.C | 15 +- src/frontends/controllers/ControlIndex.C | 12 +- src/frontends/controllers/ControlInset.tmpl | 3 + src/frontends/controllers/ControlLog.C | 9 +- src/frontends/controllers/ControlMinipage.C | 19 +- src/frontends/controllers/ControlParagraph.C | 26 +- src/frontends/controllers/ControlParagraph.h | 1 - src/frontends/controllers/ControlPreamble.C | 18 +- src/frontends/controllers/ControlPreamble.h | 2 + src/frontends/controllers/ControlPrint.C | 12 +- src/frontends/controllers/ControlPrint.h | 2 + src/frontends/controllers/ControlRef.C | 18 +- src/frontends/controllers/ControlSearch.C | 27 +- src/frontends/controllers/ControlSendto.C | 13 +- src/frontends/controllers/ControlSendto.h | 2 + src/frontends/controllers/ControlShowFile.C | 13 +- .../controllers/ControlSpellchecker.C | 9 +- .../controllers/ControlTabularCreate.C | 6 +- src/frontends/controllers/ControlTexinfo.C | 8 +- src/frontends/controllers/ControlThesaurus.C | 16 +- src/frontends/controllers/ControlToc.C | 12 +- src/frontends/controllers/ControlUrl.C | 12 +- src/frontends/controllers/ControlVCLog.C | 10 +- src/frontends/controllers/GUI.h | 425 ++----------- src/frontends/guiapi.h | 66 ++ src/frontends/screen.C | 567 ++++++------------ src/frontends/screen.h | 201 ++++--- src/frontends/xforms/ChangeLog | 81 ++- src/frontends/xforms/Dialogs.C | 136 +---- src/frontends/xforms/FormAboutlyx.h | 1 + src/frontends/xforms/FormBaseDeprecated.h | 2 + src/frontends/xforms/FormDocument.C | 2 + src/frontends/xforms/FormMathsPanel.C | 2 + src/frontends/xforms/FormMathsPanel.h | 3 +- src/frontends/xforms/FormPreferences.C | 8 +- src/frontends/xforms/FormPreferences.h | 4 +- src/frontends/xforms/FormRef.C | 20 - src/frontends/xforms/FormShowFile.C | 1 + src/frontends/xforms/FormTabular.C | 6 +- src/frontends/xforms/FormTabular.h | 5 +- src/frontends/xforms/LyXKeySymFactory.C | 22 + src/frontends/xforms/LyXScreenFactory.C | 23 + src/frontends/xforms/Makefile.am | 8 + src/frontends/xforms/WorkAreaFactory.C | 22 + src/frontends/xforms/XLyXKeySym.C | 106 ++++ src/frontends/xforms/XLyXKeySym.h | 60 ++ src/frontends/xforms/XPainter.C | 2 +- src/frontends/xforms/XPainter.h | 6 +- src/frontends/xforms/XWorkArea.C | 62 +- src/frontends/xforms/XWorkArea.h | 75 +-- src/frontends/xforms/forms/.cvsignore | 3 - .../xforms/forms/form_maths_delim.fd | 14 +- src/frontends/xforms/guiapi.C | 534 +++++++++++++++++ src/frontends/xforms/xscreen.C | 260 ++++++++ src/frontends/xforms/xscreen.h | 75 +++ src/insets/ChangeLog | 5 + src/insets/inset.h | 2 +- src/insets/insetcaption.C | 4 +- src/insets/insetcaption.h | 2 +- src/insets/insetcollapsable.C | 10 +- src/insets/insetcollapsable.h | 2 +- src/insets/insetcommand.C | 2 +- src/insets/insetcommand.h | 2 +- src/insets/inseterror.h | 2 +- src/insets/insetert.C | 2 +- src/insets/insetert.h | 2 +- src/insets/insetexternal.C | 2 +- src/insets/insetexternal.h | 2 +- src/insets/insetfloat.C | 4 +- src/insets/insetfloat.h | 2 +- src/insets/insetfloatlist.h | 2 +- src/insets/insetfoot.C | 4 +- src/insets/insetfoot.h | 2 +- src/insets/insetgraphics.C | 2 +- src/insets/insetgraphics.h | 2 +- src/insets/insetinclude.C | 2 +- src/insets/insetinclude.h | 2 +- src/insets/insetindex.C | 2 +- src/insets/insetindex.h | 2 +- src/insets/insetlabel.C | 2 +- src/insets/insetlabel.h | 2 +- src/insets/insetlatexaccent.C | 2 +- src/insets/insetlatexaccent.h | 2 +- src/insets/insetnote.h | 2 +- src/insets/insetquotes.C | 2 +- src/insets/insetquotes.h | 2 +- src/insets/insetref.C | 2 +- src/insets/insetref.h | 2 +- src/insets/insetspecialchar.C | 2 +- src/insets/insetspecialchar.h | 2 +- src/insets/insettabular.C | 79 ++- src/insets/insettabular.h | 4 +- src/insets/insettext.C | 185 +++--- src/insets/insettext.h | 2 +- src/insets/insettoc.C | 2 +- src/insets/insettoc.h | 2 +- src/insets/inseturl.C | 2 +- src/insets/inseturl.h | 2 +- src/intl.h | 4 +- src/kbmap.C | 54 +- src/kbmap.h | 17 +- src/kbsequence.C | 50 +- src/kbsequence.h | 44 +- src/lyx_cb.C | 1 - src/lyxfind.C | 143 +++-- src/lyxfind.h | 36 +- src/lyxfunc.C | 35 +- src/lyxfunc.h | 7 +- src/lyxtext.h | 2 +- src/mathed/ChangeLog | 19 + src/mathed/Makefile.am | 8 +- src/mathed/formula.C | 247 +------- src/mathed/formula.h | 2 +- src/mathed/formulabase.C | 43 +- src/mathed/formulabase.h | 4 + src/mathed/formulamacro.C | 2 +- src/mathed/formulamacro.h | 2 +- src/mathed/math_autocorrect.C | 4 +- src/mathed/math_charinset.C | 6 + src/mathed/math_charinset.h | 4 +- src/mathed/math_cursor.C | 563 +++++++++-------- src/mathed/math_cursor.h | 40 +- src/mathed/math_data.C | 52 +- src/mathed/math_data.h | 61 +- src/mathed/math_extern.C | 287 ++++++++- src/mathed/math_extern.h | 5 + src/mathed/math_factory.C | 107 ++-- src/mathed/math_fontinset.C | 23 +- src/mathed/math_gridinset.C | 76 ++- src/mathed/math_gridinset.h | 18 + src/mathed/math_hullinset.C | 16 + src/mathed/math_hullinset.h | 4 + src/mathed/math_inset.h | 2 - src/mathed/math_nestinset.C | 14 +- src/mathed/math_nestinset.h | 2 + src/mathed/math_notinset.C | 10 +- src/mathed/math_numberinset.C | 65 ++ src/mathed/math_numberinset.h | 46 ++ src/mathed/math_parser.C | 96 +-- src/mathed/math_scriptinset.C | 37 +- src/mathed/math_stringinset.C | 4 - src/mathed/math_stringinset.h | 9 +- src/mathed/math_support.C | 88 +-- src/mathed/math_support.h | 2 - src/mathed/math_symbolinset.C | 12 +- src/tabular.C | 4 +- src/tabular.h | 2 +- 186 files changed, 4144 insertions(+), 2923 deletions(-) create mode 100644 src/frontends/LyXKeySym.C create mode 100644 src/frontends/LyXKeySym.h create mode 100644 src/frontends/LyXKeySymFactory.h create mode 100644 src/frontends/LyXScreenFactory.h create mode 100644 src/frontends/WorkArea.C create mode 100644 src/frontends/WorkAreaFactory.h create mode 100644 src/frontends/guiapi.h create mode 100644 src/frontends/xforms/LyXKeySymFactory.C create mode 100644 src/frontends/xforms/LyXScreenFactory.C create mode 100644 src/frontends/xforms/WorkAreaFactory.C create mode 100644 src/frontends/xforms/XLyXKeySym.C create mode 100644 src/frontends/xforms/XLyXKeySym.h create mode 100644 src/frontends/xforms/guiapi.C create mode 100644 src/frontends/xforms/xscreen.C create mode 100644 src/frontends/xforms/xscreen.h create mode 100644 src/mathed/math_numberinset.C create mode 100644 src/mathed/math_numberinset.h diff --git a/src/BufferView.C b/src/BufferView.C index 6e169eb689..78b4b09d25 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -41,7 +41,7 @@ Buffer * BufferView::buffer() const } -LScreen & BufferView::screen() const +LyXScreen & BufferView::screen() const { return pimpl_->screen(); } diff --git a/src/BufferView.h b/src/BufferView.h index f994f582cd..ef3072a889 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -25,7 +25,7 @@ class LyXView; class LyXText; class TeXErrors; class Buffer; -class LScreen; +class LyXScreen; class Language; class Painter; class UpdatableInset; @@ -54,7 +54,7 @@ public: /// Painter & painter() const; /// - LScreen & screen() const; + LyXScreen & screen() const; /// void buffer(Buffer * b); /// diff --git a/src/BufferView2.C b/src/BufferView2.C index 8022c299b6..7638b0435e 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -564,7 +564,7 @@ void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc) locking_inset)) text->setCursor(this, cursor, cursor.par(), cursor.pos() - 1); - LScreen::Cursor_Shape shape = LScreen::BAR_SHAPE; + LyXScreen::Cursor_Shape shape = LyXScreen::BAR_SHAPE; LyXText * txt = getLyXText(); if (locking_inset->isTextInset() && locking_inset->lyxCode() != Inset::ERT_CODE && @@ -573,8 +573,8 @@ void BufferView::showLockedInsetCursor(int x, int y, int asc, int desc) || txt->real_current_font.isVisibleRightToLeft() != buffer()->params.language->RightToLeft())) shape = (txt->real_current_font.isVisibleRightToLeft()) - ? LScreen::REVERSED_L_SHAPE - : LScreen::L_SHAPE; + ? LyXScreen::REVERSED_L_SHAPE + : LyXScreen::L_SHAPE; y += cursor.iy() + theLockingInset()->insetInInsetY(); screen().showManualCursor(text, x, y, asc, desc, shape); @@ -594,7 +594,7 @@ bool BufferView::fitLockedInsetCursor(int x, int y, int asc, int desc) { if (theLockingInset() && available()) { y += text->cursor.iy() + theLockingInset()->insetInInsetY(); - if (screen().fitManualCursor(text, this, x, y, asc, desc)) { + if (screen().fitManualCursor(this, text, x, y, asc, desc)) { updateScrollbar(); return true; } diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 83696e9b15..e3804be66d 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -15,6 +15,8 @@ #include "BufferView_pimpl.h" #include "frontends/WorkArea.h" #include "frontends/screen.h" +#include "frontends/LyXScreenFactory.h" +#include "frontends/WorkAreaFactory.h" #include "frontends/Dialogs.h" #include "frontends/Alert.h" #include "frontends/FileDialog.h" @@ -117,25 +119,6 @@ namespace { const unsigned int saved_positions_num = 20; -inline -void waitForX() -{ - XSync(fl_get_display(), 0); -} - - -void SetXtermCursor(Window win) -{ - static Cursor cursor; - static bool cursor_undefined = true; - if (cursor_undefined) { - cursor = XCreateFontCursor(fl_get_display(), XC_xterm); - XFlush(fl_get_display()); - cursor_undefined = false; - } - XDefineCursor(fl_get_display(), win, cursor); - XFlush(fl_get_display()); -} } // anon namespace @@ -145,8 +128,8 @@ BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o, : bv_(b), owner_(o), buffer_(0), cursor_timeout(400), using_xterm_cursor(false) { - workarea_.reset(new WorkArea(xpos, ypos, width, height)); - screen_.reset(new LScreen(workarea())); + workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height)); + screen_.reset(LyXScreenFactory::create(workarea())); // Setup the signals workarea().scrollDocView.connect(boost::bind(&BufferView::Pimpl::scrollDocView, this, _1)); @@ -182,7 +165,7 @@ WorkArea & BufferView::Pimpl::workarea() const } -LScreen & BufferView::Pimpl::screen() const +LyXScreen & BufferView::Pimpl::screen() const { return *screen_.get(); } @@ -408,7 +391,7 @@ int BufferView::Pimpl::resizeCurrentBuffer() void BufferView::Pimpl::updateScreen() { // Regenerate the screen. - screen().reset(); + screen().redraw(bv_->text, bv_); } @@ -435,7 +418,6 @@ void BufferView::Pimpl::scrollDocView(int value) screen().draw(bv_->text, bv_, value); if (!lyxrc.cursor_follows_scrollbar) { - waitForX(); return; } @@ -449,8 +431,6 @@ void BufferView::Pimpl::scrollDocView(int value) vbt->setCursorFromCoordinates(bv_, 0, first); else if (vbt->cursor.y() > last) vbt->setCursorFromCoordinates(bv_, 0, last); - - waitForX(); } @@ -470,7 +450,8 @@ int BufferView::Pimpl::scroll(long time) } -void BufferView::Pimpl::workAreaKeyPress(KeySym key, key_modifier::state state) +void BufferView::Pimpl::workAreaKeyPress(LyXKeySymPtr key, + key_modifier::state state) { bv_->owner()->getLyXFunc()->processKeySym(key, state); } @@ -2545,7 +2526,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) LyXText * lt = bv_->getLyXText(); if (!lt->selection.set()) { - if (owner_->getIntl()->getTrans().backspace()) { + if (owner_->getIntl()->getTransManager().backspace()) { lt->backspace(bv_); lt->selection.cursor = lt->cursor; update(lt, @@ -2930,7 +2911,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) owner_->getLyXFunc()->handleKeyFunc(action); } else { owner_->getLyXFunc()->handleKeyFunc(action); - owner_->getIntl()->getTrans() + owner_->getIntl()->getTransManager() .TranslateAndInsert(argument[0], bv_->getLyXText()); update(bv_->getLyXText(), BufferView::SELECT @@ -2939,6 +2920,10 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) } break; + case LFUN_MATH: + mathDispatch(bv_, argument); + break; + case LFUN_MATH_MACRO: mathDispatchMathMacro(bv_, argument); break; @@ -3174,7 +3159,8 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument) string::const_iterator cit = argument.begin(); string::const_iterator end = argument.end(); for (; cit != end; ++cit) { - owner_->getIntl()->getTrans().TranslateAndInsert(*cit, lt); + owner_->getIntl()->getTransManager(). + TranslateAndInsert(*cit, lt); } bv_->update(lt, diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index b0a45d1461..4ae67509b3 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -15,6 +15,7 @@ #include "frontends/Timeout.h" #include "frontends/key_state.h" #include "frontends/mouse_state.h" +#include "frontends/LyXKeySym.h" #include "box.h" #include "insets/insetspecialchar.h" #include "support/types.h" @@ -28,10 +29,7 @@ class LyXView; class WorkArea; -class LScreen; - -// FIXME: remove -#include +class LyXScreen; /// struct BufferView::Pimpl : public boost::signals::trackable { @@ -43,7 +41,7 @@ struct BufferView::Pimpl : public boost::signals::trackable { /// return the work area for this bview WorkArea & workarea() const; /// return the screen for this bview - LScreen & screen() const; + LyXScreen & screen() const; /// void buffer(Buffer *); /// @@ -79,7 +77,8 @@ struct BufferView::Pimpl : public boost::signals::trackable { /// wheel mouse scroll int scroll(long time); /// - void workAreaKeyPress(KeySym key, key_modifier::state state); + void workAreaKeyPress(LyXKeySymPtr key, + key_modifier::state state); /// void workAreaMotionNotify(int x, int y, mouse_button::state state); /// @@ -172,7 +171,7 @@ private: /// Buffer * buffer_; /// - boost::scoped_ptr screen_; + boost::scoped_ptr screen_; /// boost::scoped_ptr workarea_; /// diff --git a/src/ChangeLog b/src/ChangeLog index bc3b515175..772d27f183 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,39 @@ +2002-06-16 + + * BufferView_pimpl.C (Pimpl): Use WorkAreaFactory. + Got rid of FORMS_H_LOCATION include. Now we are + GUII. + +2002-06-15 LyX Development team + + * buffer.[Ch] (sgmlOpenTag): + (sgmlCloseTag): Added support for avoiding pernicious mixed + content. Return number of lines written. + + (makeLinuxDocFile): + (makeDocBookFile): Fixed calls to sgml*Tag. + Simple white space clean. + + (simpleDocBookOnePar): Simple white space clean. + + * tabular.[Ch] (docBook): Renamed to docbook and got another + argument to related with the pernicious mixed content. + + (docbookRow): Fixed calls for docbook inset method. + +2002-06-15 Lyx Development team + + * lyxfunc.[Ch]: Use LyXKeySym instead of KeySym, + so it's X11 independent. + + * kb*.[Ch]: ditto. + + * BufferView_pimpl.[Ch] (workAreaKeyPress): ditto. + +2002-06-15 Lyx Development team + + * intl.h: Renamed getTrans to getTransManager. + 2002-06-14 Angus Leeming * Makefile.am: nuke forgotten stl_string_fwd.h. diff --git a/src/LyXAction.C b/src/LyXAction.C index ae804fb502..ca434957ff 100644 --- a/src/LyXAction.C +++ b/src/LyXAction.C @@ -280,6 +280,7 @@ void LyXAction::init() { LFUN_MARK_OFF, "mark-off", "", ReadOnly }, { LFUN_MARK_ON, "mark-on", "", ReadOnly }, { LFUN_SETMARK, "mark-toggle", "", ReadOnly }, + { LFUN_MATH, "math", "", Noop }, { LFUN_MATH_DELIM, "math-delim", "", Noop }, { LFUN_MATH_DISPLAY, "math-display", "", Noop }, { LFUN_GREEK, "math-greek", N_("Math Greek"), Noop }, diff --git a/src/buffer.C b/src/buffer.C index 95912feaea..ef5cf08538 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1713,7 +1713,7 @@ bool Buffer::readFile(LyXLex & lex, Paragraph * par) } else if (file_format < 220) { Alert::alert(_("ERROR!"), _("Old LyX file format found. " - "User LyX 1.2.x to read this!")); + "Use LyX 1.2.x to read this!")); return false; } } @@ -2749,21 +2749,35 @@ bool Buffer::isSGML() const } -void Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type, +int Buffer::sgmlOpenTag(ostream & os, Paragraph::depth_type depth, bool mixcont, string const & latexname) const { - if (!latexname.empty() && latexname != "!-- --") - //os << "" << "<" << latexname << ">"; - os << "<" << latexname << ">"; + if (!latexname.empty() && latexname != "!-- --") { + if (!mixcont) + os << string(" ",depth); + os << "<" << latexname << ">"; + } + + if (!mixcont) + os << endl; + + return mixcont?0:1; } -void Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type, +int Buffer::sgmlCloseTag(ostream & os, Paragraph::depth_type depth, bool mixcont, string const & latexname) const { - if (!latexname.empty() && latexname != "!-- --") - //os << "" << "\n"; + if (!latexname.empty() && latexname != "!-- --") { + if (!mixcont) + os << endl << string(" ",depth); os << ""; + } + + if (!mixcont) + os << endl; + + return mixcont?0:1; } @@ -2803,12 +2817,12 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) ofs << ">\n\n"; if (params.options.empty()) - sgmlOpenTag(ofs, 0, top_element); + sgmlOpenTag(ofs, 0, false, top_element); else { string top = top_element; top += " "; top += params.options; - sgmlOpenTag(ofs, 0, top); + sgmlOpenTag(ofs, 0, false, top); } } @@ -2830,7 +2844,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) Inset::Code lyx_code = inset->lyxCode(); if (lyx_code == Inset::TOC_CODE) { string const temp = "toc"; - sgmlOpenTag(ofs, depth, temp); + sgmlOpenTag(ofs, depth, false, temp); par = par->next(); continue; @@ -2839,7 +2853,7 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) // environment tag closing for (; depth > par->params().depth(); --depth) { - sgmlCloseTag(ofs, depth, environment_stack[depth]); + sgmlCloseTag(ofs, depth, false, environment_stack[depth]); environment_stack[depth].erase(); } @@ -2848,14 +2862,14 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) case LATEX_PARAGRAPH: if (depth == par->params().depth() && !environment_stack[depth].empty()) { - sgmlCloseTag(ofs, depth, environment_stack[depth]); + sgmlCloseTag(ofs, depth, false, environment_stack[depth]); environment_stack[depth].erase(); if (depth) --depth; else ofs << "

"; } - sgmlOpenTag(ofs, depth, style.latexname()); + sgmlOpenTag(ofs, depth, false, style.latexname()); break; case LATEX_COMMAND: @@ -2865,21 +2879,19 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) " LatexType Command.\n")); if (!environment_stack[depth].empty()) { - sgmlCloseTag(ofs, depth, - environment_stack[depth]); + sgmlCloseTag(ofs, depth, false, environment_stack[depth]); ofs << "

"; } environment_stack[depth].erase(); - sgmlOpenTag(ofs, depth, style.latexname()); + sgmlOpenTag(ofs, depth, false, style.latexname()); break; case LATEX_ENVIRONMENT: case LATEX_ITEM_ENVIRONMENT: if (depth == par->params().depth() && environment_stack[depth] != style.latexname()) { - sgmlCloseTag(ofs, depth, - environment_stack[depth]); + sgmlCloseTag(ofs, depth, false, environment_stack[depth]); environment_stack[depth].erase(); } if (depth < par->params().depth()) { @@ -2888,9 +2900,9 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) } if (environment_stack[depth] != style.latexname()) { if (depth == 0) { - sgmlOpenTag(ofs, depth, "p"); + sgmlOpenTag(ofs, depth, false, "p"); } - sgmlOpenTag(ofs, depth, style.latexname()); + sgmlOpenTag(ofs, depth, false, style.latexname()); if (environment_stack.size() == depth + 1) environment_stack.push_back("!-- --"); @@ -2907,10 +2919,10 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) else item_name = "item"; - sgmlOpenTag(ofs, depth + 1, item_name); + sgmlOpenTag(ofs, depth + 1, false, item_name); break; default: - sgmlOpenTag(ofs, depth, style.latexname()); + sgmlOpenTag(ofs, depth, false, style.latexname()); break; } @@ -2929,18 +2941,18 @@ void Buffer::makeLinuxDocFile(string const & fname, bool nice, bool body_only) ofs << "]]>"; break; default: - sgmlCloseTag(ofs, depth, style.latexname()); + sgmlCloseTag(ofs, depth, false, style.latexname()); break; } } // Close open tags for (int i=depth; i >= 0; --i) - sgmlCloseTag(ofs, depth, environment_stack[i]); + sgmlCloseTag(ofs, depth, false, environment_stack[i]); if (!body_only) { ofs << "\n\n"; - sgmlCloseTag(ofs, 0, top_element); + sgmlCloseTag(ofs, 0, false, top_element); } ofs.close(); @@ -3266,7 +3278,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) top += " "; top += params.options; } - sgmlOpenTag(ofs, 0, top); + sgmlOpenTag(ofs, 0, false, top); ofs << "\n"; @@ -3296,14 +3308,11 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) for (; depth > par->params().depth(); --depth) { if (environment_inner[depth] != "!-- --") { item_name = "listitem"; - sgmlCloseTag(ofs, command_depth + depth, - item_name); + sgmlCloseTag(ofs, command_depth + depth, false, item_name); if (environment_inner[depth] == "varlistentry") - sgmlCloseTag(ofs, depth+command_depth, - environment_inner[depth]); + sgmlCloseTag(ofs, depth+command_depth, false, environment_inner[depth]); } - sgmlCloseTag(ofs, depth + command_depth, - environment_stack[depth]); + sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]); environment_stack[depth].erase(); environment_inner[depth].erase(); } @@ -3313,16 +3322,12 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) && !environment_stack[depth].empty()) { if (environment_inner[depth] != "!-- --") { item_name= "listitem"; - sgmlCloseTag(ofs, command_depth+depth, - item_name); + sgmlCloseTag(ofs, command_depth+depth, false, item_name); if (environment_inner[depth] == "varlistentry") - sgmlCloseTag(ofs, - depth + command_depth, - environment_inner[depth]); + sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]); } - sgmlCloseTag(ofs, depth + command_depth, - environment_stack[depth]); + sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]); environment_stack[depth].erase(); environment_inner[depth].erase(); @@ -3331,8 +3336,7 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) // Write opening SGML tags. switch (style.latextype) { case LATEX_PARAGRAPH: - sgmlOpenTag(ofs, depth + command_depth, - style.latexname()); + sgmlOpenTag(ofs, depth + command_depth, false, style.latexname()); break; case LATEX_COMMAND: @@ -3352,14 +3356,14 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) if (cmd_depth < command_base) { for (Paragraph::depth_type j = command_depth; j >= command_base; --j) { - sgmlCloseTag(ofs, j, command_stack[j]); + sgmlCloseTag(ofs, j, false, command_stack[j]); ofs << endl; } command_depth = command_base = cmd_depth; } else if (cmd_depth <= command_depth) { for (int j = command_depth; j >= int(cmd_depth); --j) { - sgmlCloseTag(ofs, j, command_stack[j]); + sgmlCloseTag(ofs, j, false, command_stack[j]); ofs << endl; } command_depth = cmd_depth; @@ -3388,12 +3392,10 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) } } - sgmlOpenTag(ofs, depth + command_depth, command_name); - if (c_params.empty()) - item_name = "title"; - else - item_name = c_params; - sgmlOpenTag(ofs, depth + 1 + command_depth, item_name); + sgmlOpenTag(ofs, depth + command_depth, false, command_name); + + item_name = c_params.empty()?"title":c_params; + sgmlOpenTag(ofs, depth + 1 + command_depth, false, item_name); break; case LATEX_ENVIRONMENT: @@ -3410,18 +3412,13 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) } environment_stack[depth] = style.latexname(); environment_inner[depth] = "!-- --"; - sgmlOpenTag(ofs, depth + command_depth, - environment_stack[depth]); + sgmlOpenTag(ofs, depth + command_depth, false, environment_stack[depth]); } else { if (environment_inner[depth] != "!-- --") { item_name= "listitem"; - sgmlCloseTag(ofs, - command_depth + depth, - item_name); + sgmlCloseTag(ofs, command_depth + depth, false, item_name); if (environment_inner[depth] == "varlistentry") - sgmlCloseTag(ofs, - depth + command_depth, - environment_inner[depth]); + sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]); } } @@ -3430,35 +3427,21 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) if (style.latexparam() == "CDATA") ofs << ""; else - sgmlCloseTag(ofs, depth + command_depth, - style.latexparam()); + sgmlCloseTag(ofs, depth + command_depth, false, style.latexparam()); } break; case LATEX_ITEM_ENVIRONMENT: if (desc_on == 1) break; end_tag= "para"; - sgmlCloseTag(ofs, depth + 1 + command_depth, end_tag); + sgmlCloseTag(ofs, depth + 1 + command_depth, false, end_tag); break; case LATEX_PARAGRAPH: - sgmlCloseTag(ofs, depth + command_depth, style.latexname()); + sgmlCloseTag(ofs, depth + command_depth, false, style.latexname()); break; default: - sgmlCloseTag(ofs, depth + command_depth, style.latexname()); + sgmlCloseTag(ofs, depth + command_depth, false, style.latexname()); break; } } @@ -3503,26 +3482,23 @@ void Buffer::makeDocBookFile(string const & fname, bool nice, bool only_body) if (!environment_stack[depth].empty()) { if (environment_inner[depth] != "!-- --") { item_name = "listitem"; - sgmlCloseTag(ofs, command_depth + depth, - item_name); + sgmlCloseTag(ofs, command_depth + depth, false, item_name); if (environment_inner[depth] == "varlistentry") - sgmlCloseTag(ofs, depth + command_depth, - environment_inner[depth]); + sgmlCloseTag(ofs, depth + command_depth, false, environment_inner[depth]); } - sgmlCloseTag(ofs, depth + command_depth, - environment_stack[depth]); + sgmlCloseTag(ofs, depth + command_depth, false, environment_stack[depth]); } } for (int j = command_depth; j >= 0 ; --j) if (!command_stack[j].empty()) { - sgmlCloseTag(ofs, j, command_stack[j]); + sgmlCloseTag(ofs, j, false, command_stack[j]); ofs << endl; } ofs << "\n\n"; - sgmlCloseTag(ofs, 0, top_element); + sgmlCloseTag(ofs, 0, false, top_element); ofs.close(); // How to check for successful close @@ -3538,8 +3514,7 @@ void Buffer::simpleDocBookOnePar(ostream & os, { bool emph_flag = false; - LyXLayout const & style = - textclasslist[params.textclass][par->layout()]; + LyXLayout const & style = textclasslist[params.textclass][par->layout()]; LyXFont font_old = style.labeltype == LABEL_MANUAL ? style.labelfont : style.font; @@ -3577,7 +3552,7 @@ void Buffer::simpleDocBookOnePar(ostream & os, if ( i || desc_on != 3) { if(style.latexparam() == "CDATA") os << "]]>"; - inset->docbook(this, os); + inset->docbook(this, os, false); if(style.latexparam() == "CDATA") os << " + + * add a nother layer of inderection for calling gui specific + methods. + * guiapi.h: new file + +2002-06-16 + + * WorkArea.C: New file for GUII. + + * WorkAreaFactory.h: New file for GUII. + + * WorkArea.h: GUII stuff. + +2002-06-15 Lyx Development team + + * LyXKeySymFactory.h: Added GUII factory for LyXKeySyms. + + * LyXKeySym.[Ch]: Made the LyXKeySym class GUII. + + * LyXKeySym.[Ch]: new LyXKeySym class for representing a + keypress. For now, X11 dependent. + + * Makefile.am: Added LyXKeySym. + +2002-06-14 Lyx Development team + + * LyXScreenFactory.h: New factory for creating the screen + object in the super GUII way. + + * screen.h: Made LyXScreen an abstract base class for the + screen object. + + * LyXView.h: Moved last_textclass_ member to Toolbar.C where it + belongs. + 2002-06-12 John Levon * Painter.h: * Painter.C: s/PainterBase/Painter, remove dead code - + 2002-06-12 Angus Leeming - * lyx_gui.h: remove trailing semi-colon after the brace closing + * lyx_gui.h: remove trailing semi-colon after the brace closing the namespace. 2002-06-12 John Levon @@ -13,15 +49,15 @@ * LyXView.h: cleanup * LyXView.C: move init() here from xforms/ - + 2002-06-12 John Levon * screen.h: * screen.C: change topCursorVisible() prototype - + 2002-06-12 Angus Leeming - * font_metrics.h: remove trailing semi-colon after the brace closing + * font_metrics.h: remove trailing semi-colon after the brace closing the namespace. 2002-06-12 John Levon @@ -29,34 +65,34 @@ * GUIRunTime.h: remove in favour of ... * Makefile.am: - * lyx_gui.h: ... namespace for GUI start up - - * LyXView.h: remove init(),show(),setPosition() - + * lyx_gui.h: ... namespace for GUI start up + + * LyXView.h: remove init(),show(),setPosition() + 2002-06-12 John Levon * Menubar.C: * Timeout.h: * Toolbar.C: * LyXView.h: - * LyXView.C: some cleanup, prefer scoped_ptr - + * LyXView.C: some cleanup, prefer scoped_ptr + 2002-06-12 John Levon * screen.C: * Painter.C: use workHeight() * WorkArea.h: remove confusing duplicate unused code - + 2002-06-12 John Levon * screen.h: * screen.C: rename, add reset() - + 2002-06-11 John Levon * font_metrics.h: move X-specific stuff out of namespace - + 2002-06-07 Angus Leeming Fixes needed to compile with Compaq cxx 6.5. @@ -68,7 +104,7 @@ 2002-05-31 John Levon * Alert.h: better variable name - + 2002-05-29 Lars Gullik Bjønnes * switch from SigC signals to boost::signals diff --git a/src/frontends/Dialogs.C b/src/frontends/Dialogs.C index 85d7611b11..01a67137ea 100644 --- a/src/frontends/Dialogs.C +++ b/src/frontends/Dialogs.C @@ -21,18 +21,296 @@ #endif #include "Dialogs.h" + #include "support/LAssert.h" +#include "guiapi.h" + // Signal enabling all visible dialogs to be redrawn if so desired. // E.g., when the GUI colours have been remapped. boost::signal0 Dialogs::redrawGUI; +extern LyXView * dialogs_lyxview; + // toggle tooltips on/off in all dialogs. boost::signal0 Dialogs::toggleTooltips; -void Dialogs::add(DialogBase * ptr) +void Dialogs::showAboutlyx() +{ + gui_ShowAboutlyx(*dialogs_lyxview, *this); +} + + +void Dialogs::showBibitem(InsetCommand * ic) +{ + gui_ShowBibitem(ic, *dialogs_lyxview, *this); +} + + +void Dialogs::showBibtex(InsetCommand * ic) +{ + gui_ShowBibtex(ic, *dialogs_lyxview, *this); +} + + +void Dialogs::showCharacter() +{ + gui_ShowCharacter(*dialogs_lyxview, *this); +} + + +void Dialogs::setUserFreeFont() +{ + gui_SetUserFreeFont(*dialogs_lyxview, *this); +} + + +void Dialogs::showCitation(InsetCommand * ic) +{ + gui_ShowCitation(ic, *dialogs_lyxview, *this); +} + + +void Dialogs::createCitation(string const & s) +{ + gui_CreateCitation(s, *dialogs_lyxview, *this); +} + + +void Dialogs::showDocument() +{ + gui_ShowDocument(*dialogs_lyxview, *this); +} + + +void Dialogs::showError(InsetError * ie) +{ + gui_ShowError(ie, *dialogs_lyxview, *this); +} + + +void Dialogs::showERT(InsetERT * ie) +{ + gui_ShowERT(ie, *dialogs_lyxview, *this); +} + + +void Dialogs::updateERT(InsetERT * ie) +{ + gui_UpdateERT(ie, *dialogs_lyxview, *this); +} + + +void Dialogs::showExternal(InsetExternal * ie) +{ + gui_ShowExternal(ie, *dialogs_lyxview, *this); +} + + +void Dialogs::showFile(string const & f) +{ + gui_ShowFile(f, *dialogs_lyxview, *this); +} + + +void Dialogs::showFloat(InsetFloat * ifl) +{ + gui_ShowFloat(ifl, *dialogs_lyxview, *this); +} + + +void Dialogs::showForks() +{ + gui_ShowForks(*dialogs_lyxview, *this); +} + + +void Dialogs::showGraphics(InsetGraphics * ig) +{ + gui_ShowGraphics(ig, *dialogs_lyxview, *this); +} + + +void Dialogs::showInclude(InsetInclude * ii) +{ + gui_ShowInclude(ii, *dialogs_lyxview, *this); +} + + +void Dialogs::showIndex(InsetCommand * ic) +{ + gui_ShowIndex(ic, *dialogs_lyxview, *this); +} + + +void Dialogs::createIndex(string const & s) +{ + gui_CreateIndex(s, *dialogs_lyxview, *this); +} + + +void Dialogs::showInfo(InsetInfo * /*ii*/) +{ +#if 0 + gui_ShowInfo(ii, *dialogs_lyxview, *this); +#endif +} + + +void Dialogs::showLogFile() +{ + gui_ShowLogFile(*dialogs_lyxview, *this); +} + + +void Dialogs::showMathPanel() +{ + gui_ShowMathPanel(*dialogs_lyxview, *this); +} + + +void Dialogs::showMinipage(InsetMinipage * im) +{ + gui_ShowMinipage(im, *dialogs_lyxview, *this); +} + + +void Dialogs::updateMinipage(InsetMinipage * im) +{ + gui_UpdateMinipage(im, *dialogs_lyxview, *this); +} + + +void Dialogs::showParagraph() +{ + gui_ShowParagraph(*dialogs_lyxview, *this); +} + +void Dialogs::updateParagraph() +{ +#if 0 + gui_UpdateParagraph(*dialogs_lyxview, *this); +#endif +} + + +void Dialogs::showPreamble() +{ + gui_ShowPreamble(*dialogs_lyxview, *this); +} + + +void Dialogs::showPreferences() +{ + gui_ShowPreferences(*dialogs_lyxview, *this); +} + + +void Dialogs::showPrint() +{ + gui_ShowPrint(*dialogs_lyxview, *this); +} + + +void Dialogs::showRef(InsetCommand * ic) { - lyx::Assert(ptr); - dialogs_.push_back(db_ptr(ptr)); + gui_ShowRef(ic, *dialogs_lyxview, *this); } + + +void Dialogs::createRef(string const & s) +{ + gui_CreateRef(s, *dialogs_lyxview, *this); +} + + +void Dialogs::showSearch() +{ + gui_ShowSearch(*dialogs_lyxview, *this); +} + + +void Dialogs::showSendto() +{ + gui_ShowSendto(*dialogs_lyxview, *this); +} + + +void Dialogs::showSpellchecker() +{ + gui_ShowSpellchecker(*dialogs_lyxview, *this); +} + + +void Dialogs::showSpellcheckerPreferences() +{ + gui_ShowSpellcheckerPreferences(*dialogs_lyxview, *this); +} + + +void Dialogs::showTabular(InsetTabular * it) +{ + gui_ShowTabular(it, *dialogs_lyxview, *this); +} + + +void Dialogs::updateTabular(InsetTabular * it) +{ + gui_UpdateTabular(it, *dialogs_lyxview, *this); +} + + +void Dialogs::showTabularCreate() +{ + gui_ShowTabularCreate(*dialogs_lyxview, *this); +} + + +void Dialogs::showThesaurus(string const & s) +{ + gui_ShowThesaurus(s, *dialogs_lyxview, *this); +} + + +void Dialogs::showTexinfo() +{ + gui_ShowTexinfo(*dialogs_lyxview, *this); +} + + +void Dialogs::showTOC(InsetCommand * ic) +{ + gui_ShowTOC(ic, *dialogs_lyxview, *this); +} + + +void Dialogs::createTOC(string const & s) +{ + gui_CreateTOC(s, *dialogs_lyxview, *this); +} + + +void Dialogs::showUrl(InsetCommand * ic) +{ + gui_ShowUrl(ic, *dialogs_lyxview, *this); +} + + +void Dialogs::createUrl(string const & s) +{ + gui_CreateUrl(s, *dialogs_lyxview, *this); +} + + +void Dialogs::showVCLogFile() +{ + gui_ShowVCLogFile(*dialogs_lyxview, *this); +} + + +//void Dialogs::add(DialogBase * ptr) +//{ +// lyx::Assert(ptr); +// dialogs_.push_back(db_ptr(ptr)); +//} diff --git a/src/frontends/Dialogs.h b/src/frontends/Dialogs.h index d9eb211d5f..fd32e5ea90 100644 --- a/src/frontends/Dialogs.h +++ b/src/frontends/Dialogs.h @@ -24,8 +24,6 @@ #include #include #include -#include - #include #ifdef __GNUG__ @@ -95,101 +93,101 @@ public: Put into some sort of alphabetical order */ //@{ /// - boost::function showAboutlyx; + void showAboutlyx(); /// show the key and label of a bibliography entry - boost::function showBibitem; + void showBibitem(InsetCommand * ic); /// show the bibtex dialog - boost::function showBibtex; + void showBibtex(InsetCommand * ic); /// - boost::function showCharacter; + void showCharacter(); /// connected to the character dialog also - boost::function setUserFreeFont; + void setUserFreeFont(); /// - boost::function showCitation; + void showCitation(InsetCommand *); /// - boost::function createCitation; + void createCitation(string const &); /// - boost::function showDocument; + void showDocument(); /// - boost::function showError; + void showError(InsetError *); /// show the external inset dialog - boost::function showExternal; + void showExternal(InsetExternal *); /// show the contents of a file. - boost::function showFile; + void showFile(string const &); /// show all forked child processes - boost::function showForks; + void showForks(); /// - boost::function showGraphics; + void showGraphics(InsetGraphics *); /// show the details of a LyX file include inset - boost::function showInclude; + void showInclude(InsetInclude *); /// - boost::function showIndex; + void showIndex(InsetCommand *); /// - boost::function createIndex; + void createIndex(string const &); /// - boost::function showInfo; + void showInfo(InsetInfo *); /// show the LaTeX log or build file - boost::function showLogFile; + void showLogFile(); /// display the top-level maths panel - boost::function showMathPanel; + void showMathPanel(); /// - boost::function showMinipage; + void showMinipage(InsetMinipage *); /// - boost::function updateMinipage; + void updateMinipage(InsetMinipage *); /// - boost::function showERT; + void showERT(InsetERT *); /// - boost::function updateERT; + void updateERT(InsetERT *); /// - boost::function showFloat; + void showFloat(InsetFloat *); /// - boost::function showParagraph; + void showParagraph(); /// - boost::signal0 updateParagraph; + void updateParagraph(); /// - boost::function showPreamble; + void showPreamble(); /// - boost::function showPreferences; + void showPreferences(); /// - boost::function showPrint; + void showPrint(); /// - boost::function showRef; + void showRef(InsetCommand *); /// - boost::function createRef; + void createRef(string const &); /// - boost::function showSearch; + void showSearch(); /// - boost::function showSendto; + void showSendto(); /// bring up the spellchecker - boost::function showSpellchecker; + void showSpellchecker(); /// bring up the spellchecker tab in preferences - boost::function showSpellcheckerPreferences; + void showSpellcheckerPreferences(); /// - boost::function showTabular; + void showTabular(InsetTabular *); /// - boost::function updateTabular; + void updateTabular(InsetTabular *); /// - boost::function showTabularCreate; + void showTabularCreate(); /// show the TexInfo - boost::function showTexinfo; + void showTexinfo(); /// show the thesaurus dialog - boost::function showThesaurus; + void showThesaurus(string const &); /// - boost::function showTOC; + void showTOC(InsetCommand *); /// - boost::function createTOC; + void createTOC(string const &); /// - boost::function showUrl; + void showUrl(InsetCommand *); /// - boost::function createUrl; + void createUrl(string const &); /// show the version control log - boost::function showVCLogFile; + void showVCLogFile(); //@} private: /// Add a dialog to the vector of dialogs. - void add(DialogBase *); + //void add(DialogBase *); /// the dialogs being managed - std::vector dialogs_; + //std::vector dialogs_; }; #endif diff --git a/src/frontends/LyXKeySym.C b/src/frontends/LyXKeySym.C new file mode 100644 index 0000000000..4e24684491 --- /dev/null +++ b/src/frontends/LyXKeySym.C @@ -0,0 +1,15 @@ +/** + * \file LyXKeySym.C + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author Asger and Juergen + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "LyXKeySym.h" diff --git a/src/frontends/LyXKeySym.h b/src/frontends/LyXKeySym.h new file mode 100644 index 0000000000..c003e5ab7a --- /dev/null +++ b/src/frontends/LyXKeySym.h @@ -0,0 +1,60 @@ +// -*- C++ -*- +/** + * \file LyXKeySym.h + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author Asger and Juergen + */ + +#ifndef LYXKEYSYM_H +#define LYXKEYSYM_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "LString.h" +#include + +/** + * This is a base class for representing a keypress. + * Each frontend has to implement this to provide + * the functionality that LyX needs in regards to + * key presses. + */ +class LyXKeySym { +public: + LyXKeySym() {} + + virtual ~LyXKeySym() {} + + /// Initialize with the name of a key. F. ex. "space" or "a" + virtual void init(string const & symbolname) = 0; + + /// Is this a valid key? + virtual bool isOK() const = 0; + + /// Is this a modifier key only? + virtual bool isModifier() const = 0; + + /// What is the symbolic name of this key? F.ex. "Return" or "c" + virtual string getSymbolName() const = 0; + + /** + * Return the value of the keysym into the local ISO encoding. + * This converts the LyXKeySym to a 8-bit encoded character. + * This relies on user to use the right encoding. + */ + virtual char getISOEncoded() const = 0; + + /** + * We need to be able to equality compare these for the + * sake of the keymap business. + */ + virtual bool operator==(LyXKeySym const & k) const = 0; +}; + +typedef boost::shared_ptr LyXKeySymPtr; + +#endif diff --git a/src/frontends/LyXKeySymFactory.h b/src/frontends/LyXKeySymFactory.h new file mode 100644 index 0000000000..5bff157105 --- /dev/null +++ b/src/frontends/LyXKeySymFactory.h @@ -0,0 +1,22 @@ +/** + * \file LyXKeySymFactory.h + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author Asger & Juergen + */ + +#ifndef LYXKEYSYMFACTORY_H +#define LYXKEYSYMFACTORY_H + +class LyXKeySym; + +namespace LyXKeySymFactory { + /** + * Make a LyXKeySym. Used because we want to + * generate a toolkit-specific instance. + */ + LyXKeySym * create(); +} + +#endif // LYXKEYSYM_FACTORY_H diff --git a/src/frontends/LyXScreenFactory.h b/src/frontends/LyXScreenFactory.h new file mode 100644 index 0000000000..880f2cd3b6 --- /dev/null +++ b/src/frontends/LyXScreenFactory.h @@ -0,0 +1,23 @@ +/** + * \file LyXScreenFactory.h + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#ifndef LYXSCREENFACTORY_H +#define LYXSCREENFACTORY_H + +class WorkArea; +class LyXScreen; + +namespace LyXScreenFactory { + /** + * Make a screen renderer. Used because we want to + * generate a toolkit-specific instance. + */ + LyXScreen * create(WorkArea & owner); +} + +#endif // LYXSCREEN_FACTORY_H diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index d8c4ee1539..7daffc511a 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -66,8 +66,6 @@ LyXView::~LyXView() void LyXView::init() { - // Set the textclass choice - invalidateLayoutChoice(); updateLayoutChoice(); updateMenubar(); @@ -182,12 +180,6 @@ void LyXView::resetAutosaveTimer() } -void LyXView::invalidateLayoutChoice() -{ - last_textclass_ = -1; -} - - void LyXView::updateLayoutChoice() { // don't show any layouts without a buffer @@ -197,12 +189,8 @@ void LyXView::updateLayoutChoice() } // update the layout display - if (last_textclass_ != int(buffer()->params.textclass)) { - toolbar_->updateLayoutList(true); - last_textclass_ = int(buffer()->params.textclass); - current_layout = textclasslist[last_textclass_].defaultLayoutName(); - } else { - toolbar_->updateLayoutList(false); + if (toolbar_->updateLayoutList(buffer()->params.textclass)) { + current_layout = textclasslist[buffer()->params.textclass].defaultLayoutName(); } string const & layout = diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index bf8388a3a4..fcf4187011 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -55,7 +55,11 @@ public: virtual ~LyXView(); - /// FIXME: what is the requirement for this be to separate from the ctor ? + /** + * This is called after the concrete view has been created. + * We have to have the toolbar and the other stuff created + * before we can populate it with this call. + */ void init(); /// start modal operation @@ -111,7 +115,7 @@ public: void messagePop(); /// show state (font etc.) in minibuffer void showState(); - + /// updates the title of the window void updateWindowTitle(); @@ -138,9 +142,6 @@ protected: /// called on timeout void autoSave(); - /// FIXME: GUII - toolbar property - void invalidateLayoutChoice(); - private: /** * setWindowTitle - set title of window @@ -153,15 +154,6 @@ private: boost::scoped_ptr lyxfunc_; /// dialogs for this view boost::scoped_ptr dialogs_; - - /** - * The last textclass layout list in the layout choice selector - * This should probably be moved to the toolbar, but for now it's - * here. (Asger) - * - * FIXME: GUII - */ - int last_textclass_; }; #endif // LYXVIEW_H diff --git a/src/frontends/Makefile.am b/src/frontends/Makefile.am index b586297be1..0dc1e8e019 100644 --- a/src/frontends/Makefile.am +++ b/src/frontends/Makefile.am @@ -23,6 +23,12 @@ libfrontends_la_SOURCES = \ FileDialog.h \ Liason.C \ Liason.h \ + LyXKeySym.C \ + LyXKeySym.h \ + LyXKeySymFactory.h \ + LyXScreenFactory.h \ + LyXView.C \ + LyXView.h \ Menubar.C \ Menubar.h \ Painter.C \ @@ -31,11 +37,12 @@ libfrontends_la_SOURCES = \ Timeout.h \ Toolbar.C \ Toolbar.h \ - LyXView.C \ - LyXView.h \ + WorkArea.C \ WorkArea.h \ + WorkAreaFactory.h \ font_loader.h \ font_metrics.h \ + guiapi.h \ key_state.h \ lyx_gui.h \ mouse_state.h \ diff --git a/src/frontends/Toolbar.C b/src/frontends/Toolbar.C index f564c534df..bfe845a638 100644 --- a/src/frontends/Toolbar.C +++ b/src/frontends/Toolbar.C @@ -23,6 +23,7 @@ extern LyXAction lyxaction; Toolbar::Toolbar(LyXView * o, int x, int y, ToolbarDefaults const &tbd) + : last_textclass_(-1) { pimpl_ = new Pimpl(o, x, y); @@ -75,9 +76,17 @@ void Toolbar::setLayout(string const & layout) } -void Toolbar::updateLayoutList(bool force) +bool Toolbar::updateLayoutList(int textclass) { - pimpl_->updateLayoutList(force); + // update the layout display + if (last_textclass_ != textclass) { + pimpl_->updateLayoutList(true); + last_textclass_ = textclass; + return true; + } else { + pimpl_->updateLayoutList(false); + return false; + } } diff --git a/src/frontends/Toolbar.h b/src/frontends/Toolbar.h index 3ef7dcb85a..3558f73121 100644 --- a/src/frontends/Toolbar.h +++ b/src/frontends/Toolbar.h @@ -55,8 +55,11 @@ public: /// update the layout combox void setLayout(string const & layout); - /// Populate the layout combox; re-do everything if force is true. - void updateLayoutList(bool force); + /** + * Populate the layout combox - returns whether we did a full + * update or not + */ + bool updateLayoutList(int textclass); /// Drop down the layout list void openLayoutList(); /// Erase the layout list @@ -69,5 +72,10 @@ private: friend struct Toolbar::Pimpl; /// Pimpl * pimpl_; + + /** + * The last textclass layout list in the layout choice selector + */ + int last_textclass_; }; #endif diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C new file mode 100644 index 0000000000..70ae7bebf0 --- /dev/null +++ b/src/frontends/WorkArea.C @@ -0,0 +1,23 @@ +/** + * \file WorkArea.C + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author Asger and Juergen + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "WorkArea.h" + + + + + + + + diff --git a/src/frontends/WorkArea.h b/src/frontends/WorkArea.h index a3751bf52e..091318b0d6 100644 --- a/src/frontends/WorkArea.h +++ b/src/frontends/WorkArea.h @@ -1,2 +1,98 @@ -// temporary -#include "frontends/xforms/XWorkArea.h" +// -*- C++ -*- +/** + * \file WorkArea.h + * Copyright 1995-2002 the LyX Team + * Read the file COPYING + * + * \author unknown + * \author John Levon + */ + +#ifndef WORKAREA_H +#define WORKAREA_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "frontends/Painter.h" +#include "frontends/mouse_state.h" +#include "frontends/key_state.h" +#include "frontends/LyXKeySym.h" + +#include +#include +#include +#include + +#include + +/// +class WorkArea { +public: + /// + WorkArea() {} + /// + virtual ~WorkArea() {} + /// + virtual Painter & getPainter() = 0; + /// + virtual int workWidth() const = 0; + /// + virtual int workHeight() const = 0; + /// + virtual unsigned int width() const = 0; + + /// + virtual int xpos() const = 0; + /// + virtual int ypos() const = 0; + /// + virtual void resize(int xpos, int ypos, int width, int height) = 0; + /// + virtual void redraw() const = 0; + /// + virtual void setFocus() const = 0; + /// + virtual bool hasFocus() const = 0; + /// + virtual bool visible() const = 0; + /// + virtual void greyOut() const = 0; + /// + virtual void setScrollbarParams(int height, int pos, int line_height) = 0; + + /// a selection exists + virtual void haveSelection(bool) const = 0; + /// + virtual string const getClipboard() const = 0; + /// + virtual void putClipboard(string const &) const = 0; + // Signals + /// + boost::signal0 workAreaExpose; + /// + boost::signal1 scrollDocView; + /// + boost::signal2 workAreaKeyPress; + /// + boost::signal3 workAreaButtonPress; + /// + boost::signal3 workAreaButtonRelease; + /// + boost::signal3 workAreaMotionNotify; + /// + boost::signal0 workAreaFocus; + /// + boost::signal0 workAreaUnfocus; + /// + boost::signal3 workAreaDoubleClick; + /// + boost::signal3 workAreaTripleClick; + /// emitted when an X client has requested our selection + boost::signal0 selectionRequested; + /// emitted when another X client has stolen our selection + boost::signal0 selectionLost; +}; + +#endif // WORKAREA_H diff --git a/src/frontends/WorkAreaFactory.h b/src/frontends/WorkAreaFactory.h new file mode 100644 index 0000000000..ce276bfe4c --- /dev/null +++ b/src/frontends/WorkAreaFactory.h @@ -0,0 +1,22 @@ +/** + * \file WorkAreaFactory.h + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#ifndef WORKAREAFACTORY_H +#define WORKAREAFACTORY_H + +class WorkArea; + +namespace WorkAreaFactory { + /** + * Make a work area. Used because we want to generate + * a toolkit-specific instance. + */ + WorkArea * create(int x, int y, int w, int h); +} + +#endif // WORKAREA_FACTORY_H diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 0f31d13f40..9e3a53cd15 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,7 @@ +2002-06-16 Lars Gullik Bjønnes + + * changes to simplify function setup, removal of a lot of includes. + 2002-06-12 Angus Leeming * ControlParagraph.[Ch]: forward declare ParagraphParameters. @@ -7,11 +11,11 @@ * ControlInset.tmpl: add missing header file, ButtonControllerBase.h. 2002-06-11 Edwin Leuven - - * ControlParagraph.[Ch]: new paragraph controller - * GUI.h: add new controller - * Makefile.am: ditto - + + * ControlParagraph.[Ch]: new paragraph controller + * GUI.h: add new controller + * Makefile.am: ditto + 2002-06-10 Lars Gullik Bjønnes * GUI.h: do not include ButtonController.tmpl diff --git a/src/frontends/controllers/ControlAboutlyx.C b/src/frontends/controllers/ControlAboutlyx.C index ddde313cfc..f7815b97cc 100644 --- a/src/frontends/controllers/ControlAboutlyx.C +++ b/src/frontends/controllers/ControlAboutlyx.C @@ -14,10 +14,7 @@ #pragma implementation #endif -#include "ViewBase.h" -#include "ButtonControllerBase.h" #include "ControlAboutlyx.h" -#include "Dialogs.h" #include "frontends/LyXView.h" #include "Lsstream.h" #include "BufferView.h" @@ -25,17 +22,14 @@ #include "support/filetools.h" // FileSearch #include "version.h" -#include - // needed for the browser extern string system_lyxdir; extern string user_lyxdir; + ControlAboutlyx::ControlAboutlyx(LyXView & lv, Dialogs & d) : ControlDialogBI(lv, d) -{ - d_.showAboutlyx = boost::bind(&ControlAboutlyx::show, this); -} +{} stringstream & ControlAboutlyx::getCredits(stringstream & ss) const @@ -65,21 +59,25 @@ stringstream & ControlAboutlyx::getCredits(stringstream & ss) const return ss; } + string const ControlAboutlyx::getCopyright() const { return _("LyX is Copyright (C) 1995 by Matthias Ettrich,\n1995-2001 LyX Team"); } + string const ControlAboutlyx::getLicense() const { return _("This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version."); } + string const ControlAboutlyx::getDisclaimer() const { return _("LyX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\nSee the GNU General Public License for more details.\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA."); } + string const ControlAboutlyx::getVersion() const { stringstream ss; diff --git a/src/frontends/controllers/ControlBibitem.C b/src/frontends/controllers/ControlBibitem.C index 04be99188c..288bfff455 100644 --- a/src/frontends/controllers/ControlBibitem.C +++ b/src/frontends/controllers/ControlBibitem.C @@ -19,23 +19,12 @@ #endif #include "ControlBibitem.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "Dialogs.h" -#include "buffer.h" #include "BufferView.h" -#include "frontends/LyXView.h" - -#include - -#include ControlBibitem::ControlBibitem(LyXView & lv, Dialogs & d) : ControlCommand(lv, d) -{ - d_.showBibitem = boost::bind(&ControlBibitem::showInset, this, _1); -} +{} void ControlBibitem::applyParamsToInset() diff --git a/src/frontends/controllers/ControlBibtex.C b/src/frontends/controllers/ControlBibtex.C index 22927cae4e..43e7557cb3 100644 --- a/src/frontends/controllers/ControlBibtex.C +++ b/src/frontends/controllers/ControlBibtex.C @@ -19,11 +19,7 @@ #pragma implementation #endif -#include "ViewBase.h" -#include "ButtonControllerBase.h" #include "ControlBibtex.h" -#include "Dialogs.h" -#include "buffer.h" #include "BufferView.h" #include "lyxrc.h" #include "helper_funcs.h" @@ -31,18 +27,13 @@ #include "frontends/LyXView.h" -#include - -#include - using std::pair; -using std::make_pair; + ControlBibtex::ControlBibtex(LyXView & lv, Dialogs & d) : ControlCommand(lv, d) -{ - d_.showBibtex = boost::bind(&ControlBibtex::showInset, this, _1); -} +{} + void ControlBibtex::applyParamsToInset() { diff --git a/src/frontends/controllers/ControlCharacter.C b/src/frontends/controllers/ControlCharacter.C index f0e2e78901..a12534fe85 100644 --- a/src/frontends/controllers/ControlCharacter.C +++ b/src/frontends/controllers/ControlCharacter.C @@ -16,7 +16,6 @@ #include "ViewBase.h" #include "ButtonControllerBase.h" #include "buffer.h" -#include "Dialogs.h" #include "Liason.h" #include "bufferview_funcs.h" // ToggleAndShow #include "gettext.h" @@ -25,21 +24,13 @@ #include "frontends/LyXView.h" -#include - -#include - using Liason::setMinibuffer; -using std::vector; ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d), font_(0), toggleall_(false) -{ - d_.showCharacter = boost::bind(&ControlCharacter::show, this); - d_.setUserFreeFont = boost::bind(&ControlCharacter::apply, this); -} +{} void ControlCharacter::setParams() diff --git a/src/frontends/controllers/ControlCharacter.h b/src/frontends/controllers/ControlCharacter.h index b8d3938849..108025de0a 100644 --- a/src/frontends/controllers/ControlCharacter.h +++ b/src/frontends/controllers/ControlCharacter.h @@ -61,9 +61,9 @@ public: /// bool getToggleAll() const; -private: /// Get changed parameters and Dispatch them to the kernel. virtual void apply(); +private: /// set the params before show or update. virtual void setParams(); diff --git a/src/frontends/controllers/ControlCitation.C b/src/frontends/controllers/ControlCitation.C index 5af344ed4a..d1069ef90e 100644 --- a/src/frontends/controllers/ControlCitation.C +++ b/src/frontends/controllers/ControlCitation.C @@ -18,30 +18,16 @@ #endif #include "ControlCitation.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "buffer.h" -#include "Dialogs.h" -#include "frontends/LyXView.h" - -#include - -#include - -using std::pair; using std::vector; +using std::pair; vector ControlCitation::citeStyles_; + ControlCitation::ControlCitation(LyXView & lv, Dialogs & d) : ControlCommand(lv, d, LFUN_CITATION_INSERT) -{ - // These are permanent connections so we won't bother - // storing a copy because we won't be disconnecting. - d_.showCitation = boost::bind(&ControlCitation::showInset, this, _1); - d_.createCitation = boost::bind(&ControlCitation::createInset, this, _1); -} +{} void ControlCitation::clearDaughterParams() diff --git a/src/frontends/controllers/ControlDialog.tmpl b/src/frontends/controllers/ControlDialog.tmpl index adfa9e424f..ff4151d581 100644 --- a/src/frontends/controllers/ControlDialog.tmpl +++ b/src/frontends/controllers/ControlDialog.tmpl @@ -72,4 +72,3 @@ void ControlDialog::hide() disconnect(); view().hide(); } - diff --git a/src/frontends/controllers/ControlERT.C b/src/frontends/controllers/ControlERT.C index 55a4ac2220..1125440686 100644 --- a/src/frontends/controllers/ControlERT.C +++ b/src/frontends/controllers/ControlERT.C @@ -17,31 +17,15 @@ #pragma implementation #endif -#include "ViewBase.h" -#include "ButtonControllerBase.h" #include "ControlERT.h" -#include "Dialogs.h" -#include "frontends/LyXView.h" -#include "buffer.h" -#include "BufferView.h" - -#include - -using std::vector; // sorry this is just a temporary hack we should include vspace.h! (Jug) extern const char * stringFromUnit(int); + ControlERT::ControlERT(LyXView & lv, Dialogs & d) : ControlInset(lv, d) -{ - d_.showERT = boost::bind(&ControlERT::showInset, this, _1); - - // We could have an extra method updateInset that calls - // view().update() rather than view().show(), but I don't see why - // it is really needed. - d_.updateERT = boost::bind(&ControlERT::showInset, this, _1); -} +{} void ControlERT::applyParamsToInset() @@ -65,6 +49,7 @@ ERTParams::ERTParams() : status(InsetERT::Collapsed) {} + ERTParams::ERTParams(InsetERT const & inset) : status(inset.status()) {} diff --git a/src/frontends/controllers/ControlError.C b/src/frontends/controllers/ControlError.C index 412c6e6691..fd3918bc84 100644 --- a/src/frontends/controllers/ControlError.C +++ b/src/frontends/controllers/ControlError.C @@ -18,21 +18,12 @@ #endif #include "ControlError.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "Dialogs.h" -#include "buffer.h" #include "insets/inseterror.h" -#include "frontends/LyXView.h" - -#include ControlError::ControlError(LyXView & lv, Dialogs & d) : ControlInset(lv, d) -{ - d_.showError = boost::bind(&ControlError::showInset, this, _1); -} +{} string const ControlError::getParams(InsetError const & inset) diff --git a/src/frontends/controllers/ControlExternal.C b/src/frontends/controllers/ControlExternal.C index 8436ef787e..7a5d3c36f9 100644 --- a/src/frontends/controllers/ControlExternal.C +++ b/src/frontends/controllers/ControlExternal.C @@ -19,35 +19,20 @@ #pragma implementation #endif -#include "BufferView.h" -#include "ButtonControllerBase.h" #include "ControlExternal.h" -#include "Dialogs.h" -#include "Liason.h" -#include "frontends/LyXView.h" -#include "ViewBase.h" -#include "buffer.h" -#include "frontends/Alert.h" +#include "BufferView.h" #include "gettext.h" #include "helper_funcs.h" #include "lyxrc.h" #include "support/filetools.h" -#include "support/lstrings.h" - -#include -#include -#include #include -using std::make_pair; using std::vector; ControlExternal::ControlExternal(LyXView & lv, Dialogs & d) : ControlInset(lv, d) -{ - d_.showExternal = boost::bind(&ControlExternal::showInset, this, _1); -} +{} InsetExternal::Params const ControlExternal::getParams(string const &) diff --git a/src/frontends/controllers/ControlFloat.C b/src/frontends/controllers/ControlFloat.C index 2e8891a3c9..a04eb8dd48 100644 --- a/src/frontends/controllers/ControlFloat.C +++ b/src/frontends/controllers/ControlFloat.C @@ -16,30 +16,11 @@ #endif #include "ControlFloat.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "Dialogs.h" -#include "buffer.h" -#include "BufferView.h" - -#include "insets/insetfloat.h" -#include "frontends/LyXView.h" - -#include - -using std::vector; ControlFloat::ControlFloat(LyXView & lv, Dialogs & d) : ControlInset(lv, d) -{ - d_.showFloat = boost::bind(&ControlFloat::showInset, this, _1); - - // We could have an extra method updateInset that calls - // view().update() rather than view().show(), but I don't see why - // it is really needed. - //d_.updateFloat.connect(slot(this, &ControlFloat::showInset)); -} +{} void ControlFloat::applyParamsToInset() diff --git a/src/frontends/controllers/ControlForks.C b/src/frontends/controllers/ControlForks.C index 962790f165..80f65f43f7 100644 --- a/src/frontends/controllers/ControlForks.C +++ b/src/frontends/controllers/ControlForks.C @@ -13,15 +13,12 @@ #endif #include "ControlForks.h" -#include "ButtonControllerBase.h" #include "ViewBase.h" #include "BufferView.h" #include "frontends/LyXView.h" #include "lyxfunc.h" -#include "frontends/Dialogs.h" - #include "support/forkedcontr.h" #include "support/lstrings.h" @@ -32,9 +29,7 @@ using std::vector; ControlForks::ControlForks(LyXView & lv, Dialogs & d) : ControlDialogBI(lv, d) -{ - d_.showForks = boost::bind(&ControlForks::show, this); -} +{} vector const ControlForks::getPIDs() const diff --git a/src/frontends/controllers/ControlGraphics.C b/src/frontends/controllers/ControlGraphics.C index c43807c0cd..cb799c2f27 100644 --- a/src/frontends/controllers/ControlGraphics.C +++ b/src/frontends/controllers/ControlGraphics.C @@ -18,8 +18,6 @@ #pragma implementation #endif -#include "ViewBase.h" -#include "ButtonControllerBase.h" #include "ControlGraphics.h" #include "helper_funcs.h" @@ -42,13 +40,8 @@ #include "support/filetools.h" #include "support/FileInfo.h" -#include - -#include - using std::pair; using std::make_pair; -using std::ifstream; using std::vector; namespace { @@ -103,9 +96,7 @@ string const xforms_pattern() ControlGraphics::ControlGraphics(LyXView & lv, Dialogs & d) : ControlInset(lv, d) -{ - d_.showGraphics = boost::bind(&ControlGraphics::showInset, this, _1); -} +{} InsetGraphicsParams const ControlGraphics::getParams(string const &) @@ -209,6 +200,7 @@ size_t const rorigin_size = sizeof(rorigin_lyx_strs) / sizeof(char *); } // namespace anon + vector getRotationOriginData() { static vector data; @@ -217,8 +209,8 @@ vector getRotationOriginData() data.resize(rorigin_size); for (lyx::size_type i = 0; i < rorigin_size; ++i) { - data[i] = std::make_pair(_(rorigin_gui_strs[i]), - rorigin_lyx_strs[i]); + data[i] = make_pair(_(rorigin_gui_strs[i]), + rorigin_lyx_strs[i]); } return data; diff --git a/src/frontends/controllers/ControlInclude.C b/src/frontends/controllers/ControlInclude.C index 5c01ad3839..bc2f698920 100644 --- a/src/frontends/controllers/ControlInclude.C +++ b/src/frontends/controllers/ControlInclude.C @@ -9,19 +9,14 @@ */ #include -#include #ifdef __GNUG__ #pragma implementation #endif #include "ControlInclude.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "buffer.h" #include "Alert.h" #include "BufferView.h" -#include "Dialogs.h" #include "lyxfunc.h" #include "gettext.h" #include "helper_funcs.h" @@ -29,18 +24,14 @@ #include "support/filetools.h" -#include "frontends/LyXView.h" - -#include +#include using std::pair; -using std::make_pair; + ControlInclude::ControlInclude(LyXView & lv, Dialogs & d) : ControlInset(lv, d) -{ - d_.showInclude = boost::bind(&ControlInclude::showInset, this, _1); -} +{} void ControlInclude::applyParamsToInset() diff --git a/src/frontends/controllers/ControlIndex.C b/src/frontends/controllers/ControlIndex.C index 6ed48c5b36..a74bea85fd 100644 --- a/src/frontends/controllers/ControlIndex.C +++ b/src/frontends/controllers/ControlIndex.C @@ -18,18 +18,8 @@ #endif #include "ControlIndex.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "buffer.h" -#include "Dialogs.h" -#include "frontends/LyXView.h" - -#include ControlIndex::ControlIndex(LyXView & lv, Dialogs & d) : ControlCommand(lv, d, LFUN_INDEX_INSERT) -{ - d_.showIndex = boost::bind(&ControlIndex::showInset, this, _1); - d_.createIndex = boost::bind(&ControlIndex::createInset, this, _1); -} +{} diff --git a/src/frontends/controllers/ControlInset.tmpl b/src/frontends/controllers/ControlInset.tmpl index 7b36a70529..fe88747c36 100644 --- a/src/frontends/controllers/ControlInset.tmpl +++ b/src/frontends/controllers/ControlInset.tmpl @@ -16,7 +16,10 @@ #include "buffer.h" #include "debug.h" #include "frontends/LyXView.h" +#include "insets/insetfloat.h" +#include "insets/insetgraphics.h" #include "support/LAssert.h" + #include template diff --git a/src/frontends/controllers/ControlLog.C b/src/frontends/controllers/ControlLog.C index 2bc2873432..bcaa49bb67 100644 --- a/src/frontends/controllers/ControlLog.C +++ b/src/frontends/controllers/ControlLog.C @@ -19,21 +19,14 @@ #endif #include "ControlLog.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "Dialogs.h" -#include "lyxrc.h" #include "BufferView.h" #include "frontends/LyXView.h" -#include ControlLog::ControlLog(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d) -{ - d_.showLogFile = boost::bind(&ControlLog::show, this); -} +{} void ControlLog::setParams() diff --git a/src/frontends/controllers/ControlMinipage.C b/src/frontends/controllers/ControlMinipage.C index 017abd6e4d..2ebc759a4c 100644 --- a/src/frontends/controllers/ControlMinipage.C +++ b/src/frontends/controllers/ControlMinipage.C @@ -18,29 +18,12 @@ #endif #include "ControlMinipage.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "Dialogs.h" -#include "frontends/LyXView.h" -#include "buffer.h" #include "BufferView.h" -#include "helper_funcs.h" - -#include - -using std::vector; ControlMinipage::ControlMinipage(LyXView & lv, Dialogs & d) : ControlInset(lv, d) -{ - d_.showMinipage = boost::bind(&ControlMinipage::showInset, this, _1); - - // We could have an extra method updateInset that calls - // view().update() rather than view().show(), but I don't see why - // it is really needed. - d_.updateMinipage = boost::bind(&ControlMinipage::showInset, this, _1); -} +{} void ControlMinipage::applyParamsToInset() diff --git a/src/frontends/controllers/ControlParagraph.C b/src/frontends/controllers/ControlParagraph.C index e554cb1e5a..0438e044b0 100644 --- a/src/frontends/controllers/ControlParagraph.C +++ b/src/frontends/controllers/ControlParagraph.C @@ -13,11 +13,9 @@ #pragma implementation #endif -#include "ViewBase.h" -#include "ButtonControllerBase.h" #include "ControlParagraph.h" +#include "ViewBase.h" #include "ParagraphParameters.h" -#include "Dialogs.h" #include "Liason.h" #include "LyXView.h" #include "BufferView.h" @@ -27,16 +25,12 @@ #include "lyxtextclasslist.h" #include "support/LAssert.h" -#include - using Liason::setMinibuffer; ControlParagraph::ControlParagraph(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d), pp_(0), ininset_(false) -{ - d_.showParagraph = boost::bind(&ControlParagraph::show, this); -} +{} ControlParagraph::~ControlParagraph() @@ -83,13 +77,13 @@ void ControlParagraph::apply() pp_->noindent()); // Actually apply these settings - lv_.view()->update(text, + lv_.view()->update(text, BufferView::SELECT | BufferView::FITCUR | BufferView::CHANGE); - + lv_.buffer()->markDirty(); - + setMinibuffer(&lv_, _("Paragraph layout set")); } @@ -101,13 +95,13 @@ void ControlParagraph::setParams() /// get paragraph Paragraph const * par_ = lv_.view()->getLyXText()->cursor.par(); - + /// Set the paragraph parameters - *pp_ = par_->params(); - + *pp_ = par_->params(); + /// this needs to be done separately pp_->labelWidthString(par_->getLabelWidthString()); - + /// alignment LyXTextClass const & tclass = textclasslist[lv_.view()->buffer()->params.textclass]; @@ -118,5 +112,5 @@ void ControlParagraph::setParams() alignpos_ = tclass[par_->layout()].alignpossible; /// is paragraph in inset - ininset_ = par_->inInset(); + ininset_ = par_->inInset(); } diff --git a/src/frontends/controllers/ControlParagraph.h b/src/frontends/controllers/ControlParagraph.h index b089a07ec9..343e0dd28a 100644 --- a/src/frontends/controllers/ControlParagraph.h +++ b/src/frontends/controllers/ControlParagraph.h @@ -54,4 +54,3 @@ private: }; #endif // CONTROLPARAGRAPH_H - diff --git a/src/frontends/controllers/ControlPreamble.C b/src/frontends/controllers/ControlPreamble.C index 4f3485c84b..7f30834f55 100644 --- a/src/frontends/controllers/ControlPreamble.C +++ b/src/frontends/controllers/ControlPreamble.C @@ -12,26 +12,20 @@ #pragma implementation #endif -#include "ViewBase.h" -#include "ButtonControllerBase.h" #include "ControlPreamble.h" +#include "ViewBase.h" #include "frontends/LyXView.h" -#include "Dialogs.h" #include "buffer.h" -#include "lyxrc.h" #include "Liason.h" #include "gettext.h" #include "BufferView.h" #include "support/LAssert.h" -#include ControlPreamble::ControlPreamble(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d), params_(0) -{ - d_.showPreamble = boost::bind(&ControlPreamble::show, this); -} +{} void ControlPreamble::apply() @@ -56,15 +50,13 @@ string & ControlPreamble::params() const void ControlPreamble::setParams() { - if (params_) delete params_; + delete params_; params_ = new string(lv_.buffer()->params.preamble); } void ControlPreamble::clearParams() { - if (params_) { - delete params_; - params_ = 0; - } + delete params_; + params_ = 0; } diff --git a/src/frontends/controllers/ControlPreamble.h b/src/frontends/controllers/ControlPreamble.h index 3042abce12..893bd11a52 100644 --- a/src/frontends/controllers/ControlPreamble.h +++ b/src/frontends/controllers/ControlPreamble.h @@ -16,6 +16,8 @@ #include "ControlDialog_impl.h" +#include "LString.h" + /** A controller for Preamble dialogs. */ class ControlPreamble : public ControlDialogBD { diff --git a/src/frontends/controllers/ControlPrint.C b/src/frontends/controllers/ControlPrint.C index 6c0609734c..8e5ba18f4f 100644 --- a/src/frontends/controllers/ControlPrint.C +++ b/src/frontends/controllers/ControlPrint.C @@ -12,17 +12,15 @@ */ #include -#include #ifdef __GNUG__ #pragma implementation #endif +#include "ControlPrint.h" #include "ViewBase.h" #include "ButtonControllerBase.h" -#include "ControlPrint.h" #include "buffer.h" -#include "Dialogs.h" #include "frontends/LyXView.h" #include "PrinterParams.h" #include "Liason.h" @@ -32,18 +30,14 @@ #include "BufferView.h" #include "support/LAssert.h" -#include - using Liason::printBuffer; using Liason::getPrinterParams; -using std::make_pair; + ControlPrint::ControlPrint(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d), params_(0) -{ - d_.showPrint = boost::bind(&ControlPrint::show, this); -} +{} void ControlPrint::apply() diff --git a/src/frontends/controllers/ControlPrint.h b/src/frontends/controllers/ControlPrint.h index d88362ceb6..211787f389 100644 --- a/src/frontends/controllers/ControlPrint.h +++ b/src/frontends/controllers/ControlPrint.h @@ -21,6 +21,8 @@ #include "ControlDialog_impl.h" +#include "LString.h" + class PrinterParams; /** A controller for Print dialogs. diff --git a/src/frontends/controllers/ControlRef.C b/src/frontends/controllers/ControlRef.C index 568fc2c6ba..98e6cbc795 100644 --- a/src/frontends/controllers/ControlRef.C +++ b/src/frontends/controllers/ControlRef.C @@ -18,33 +18,19 @@ #endif #include "ControlRef.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "Dialogs.h" -#include "buffer.h" #include "lyxfunc.h" #include "bufferlist.h" -#include "debug.h" - -#include "frontends/LyXView.h" #include "support/filetools.h" // MakeAbsPath, MakeDisplayPath -#include - -#include - using std::vector; -using std::find; extern BufferList bufferlist; + ControlRef::ControlRef(LyXView & lv, Dialogs & d) : ControlCommand(lv, d, LFUN_REF_INSERT) -{ - d_.showRef = boost::bind(&ControlRef::showInset, this, _1); - d_.createRef = boost::bind(&ControlRef::createInset, this, _1); -} +{} vector const ControlRef::getLabelList(string const & name) const diff --git a/src/frontends/controllers/ControlSearch.C b/src/frontends/controllers/ControlSearch.C index 224930cea9..867ef54425 100644 --- a/src/frontends/controllers/ControlSearch.C +++ b/src/frontends/controllers/ControlSearch.C @@ -18,13 +18,9 @@ #endif #include "ControlSearch.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "Dialogs.h" #include "Liason.h" #include "buffer.h" #include "lyxfind.h" -#include "debug.h" #include "gettext.h" #include "BufferView.h" @@ -32,26 +28,20 @@ #include "support/lstrings.h" -#include - using Liason::setMinibuffer; + ControlSearch::ControlSearch(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d) -{ - d_.showSearch = boost::bind(&ControlSearch::show, this); - - // perhaps in the future we'd like a - // "search again" button/keybinding - // d_.searchAgain.connect(SigC::slot(this, &ControlSearch::FindNext)); -} +{} void ControlSearch::find(string const & search, bool casesensitive, bool matchword, bool forward) const { - bool const found = LyXFind(lv_.view(), search, - forward, false, casesensitive, matchword); + bool const found = lyxfind::LyXFind(lv_.view(), search, + forward, casesensitive, + matchword); if (!found) setMinibuffer(&lv_, _("String not found!")); @@ -65,9 +55,10 @@ void ControlSearch::replace(string const & search, string const & replace, // move on to the next instance once the present instance has been // changed bool const once = !all; - int const replace_count = LyXReplace(lv_.view(), - search, replace, true, casesensitive, - matchword, all, once); + int const replace_count = + lyxfind::LyXReplace(lv_.view(), + search, replace, true, casesensitive, + matchword, all, once); if (replace_count == 0) { setMinibuffer(&lv_, _("String not found!")); diff --git a/src/frontends/controllers/ControlSendto.C b/src/frontends/controllers/ControlSendto.C index 8aaa29b805..7eb8376e22 100644 --- a/src/frontends/controllers/ControlSendto.C +++ b/src/frontends/controllers/ControlSendto.C @@ -12,10 +12,8 @@ #pragma implementation #endif -#include "ViewBase.h" -#include "ButtonControllerBase.h" #include "ControlSendto.h" -#include "Dialogs.h" +#include "ViewBase.h" #include "frontends/LyXView.h" #include "BufferView.h" #include "buffer.h" @@ -28,19 +26,14 @@ #include "support/lstrings.h" #include "support/systemcall.h" -#include - -#include - using std::vector; + ControlSendto::ControlSendto(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d), format_(0), command_(lyxrc.custom_export_command) -{ - d_.showSendto = boost::bind(&ControlSendto::show, this); -} +{} vector const ControlSendto::allFormats() const diff --git a/src/frontends/controllers/ControlSendto.h b/src/frontends/controllers/ControlSendto.h index e4189a9b12..25a4ee08de 100644 --- a/src/frontends/controllers/ControlSendto.h +++ b/src/frontends/controllers/ControlSendto.h @@ -15,6 +15,8 @@ #endif #include "ControlDialog_impl.h" +#include "LString.h" + #include class Format; diff --git a/src/frontends/controllers/ControlShowFile.C b/src/frontends/controllers/ControlShowFile.C index 9d5e0b5ce6..a412ff4831 100644 --- a/src/frontends/controllers/ControlShowFile.C +++ b/src/frontends/controllers/ControlShowFile.C @@ -13,24 +13,13 @@ #endif #include "ControlShowFile.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "Dialogs.h" -#include "frontends/LyXView.h" -#include "BufferView.h" -#include "gettext.h" #include "support/filetools.h" // FileSearch -#include - -#include ControlShowFile::ControlShowFile(LyXView & lv, Dialogs & d) : ControlDialogBI(lv, d) -{ - d_.showFile = boost::bind(&ControlShowFile::showFile, this, _1); -} +{} void ControlShowFile::showFile(string const & file) diff --git a/src/frontends/controllers/ControlSpellchecker.C b/src/frontends/controllers/ControlSpellchecker.C index 1d7ebce2ab..329bb68c86 100644 --- a/src/frontends/controllers/ControlSpellchecker.C +++ b/src/frontends/controllers/ControlSpellchecker.C @@ -26,7 +26,6 @@ #include "language.h" #include "ViewBase.h" -#include "ButtonControllerBase.h" #include "Dialogs.h" #include "Liason.h" @@ -39,10 +38,6 @@ # include "sp_pspell.h" #endif -#include "debug.h" - -#include - #include // needed by at least on freebsd #ifdef HAVE_SYS_SELECT_H @@ -60,9 +55,7 @@ ControlSpellchecker::ControlSpellchecker(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d), rtl_(false), newval_(0.0), oldval_(0), newvalue_(0), count_(0), stop_(false), result_(SpellBase::ISP_OK), speller_(0) -{ - d_.showSpellchecker = boost::bind(&ControlSpellchecker::show, this); -} +{} void ControlSpellchecker::setParams() diff --git a/src/frontends/controllers/ControlTabularCreate.C b/src/frontends/controllers/ControlTabularCreate.C index 9eb5254229..9db249361b 100644 --- a/src/frontends/controllers/ControlTabularCreate.C +++ b/src/frontends/controllers/ControlTabularCreate.C @@ -20,20 +20,16 @@ #include "ViewBase.h" #include "ButtonControllerBase.h" #include "BufferView.h" -#include "Dialogs.h" #include "lyxfunc.h" #include "frontends/LyXView.h" #include "support/lstrings.h" -#include ControlTabularCreate::ControlTabularCreate(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d) -{ - d_.showTabularCreate = boost::bind(&ControlTabularCreate::show, this); -} +{} ControlTabularCreate::rowsCols & ControlTabularCreate::params() diff --git a/src/frontends/controllers/ControlTexinfo.C b/src/frontends/controllers/ControlTexinfo.C index ad4981069b..7637bbdccf 100644 --- a/src/frontends/controllers/ControlTexinfo.C +++ b/src/frontends/controllers/ControlTexinfo.C @@ -18,8 +18,6 @@ #endif #include "ControlTexinfo.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" #include "Dialogs.h" #include "BufferView.h" #include "gettext.h" @@ -32,16 +30,12 @@ #include "support/path.h" #include "support/lstrings.h" -#include - extern string user_lyxdir; // home of *Files.lst ControlTexinfo::ControlTexinfo(LyXView & lv, Dialogs & d) : ControlDialogBI(lv, d) -{ - d_.showTexinfo = boost::bind(&ControlTexinfo::show, this); -} +{} // build filelists of all availabe bst/cls/sty-files. done through diff --git a/src/frontends/controllers/ControlThesaurus.C b/src/frontends/controllers/ControlThesaurus.C index 29e11c01b6..19e042e612 100644 --- a/src/frontends/controllers/ControlThesaurus.C +++ b/src/frontends/controllers/ControlThesaurus.C @@ -13,27 +13,20 @@ #endif #include "ControlThesaurus.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "Dialogs.h" #include "Liason.h" #include "lyxfind.h" #include "buffer.h" -#include "debug.h" #include "gettext.h" #include "BufferView.h" #include "frontends/LyXView.h" -#include - using Liason::setMinibuffer; + ControlThesaurus::ControlThesaurus(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d) -{ - d_.showThesaurus = boost::bind(&ControlThesaurus::showEntry, this, _1); -} +{} void ControlThesaurus::showEntry(string const & entry) @@ -49,8 +42,9 @@ void ControlThesaurus::replace(string const & newstr) * on a particular charpos in a paragraph that is broken on * deletion/change ! */ - int const replace_count = LyXReplace(lv_.view(), oldstr_, newstr, - true, true, true, false, true); + int const replace_count = + lyxfind::LyXReplace(lv_.view(), oldstr_, newstr, + true, true, true, false, true); oldstr_ = newstr; diff --git a/src/frontends/controllers/ControlToc.C b/src/frontends/controllers/ControlToc.C index 5c731c0566..50cf2a5cb3 100644 --- a/src/frontends/controllers/ControlToc.C +++ b/src/frontends/controllers/ControlToc.C @@ -18,28 +18,20 @@ #endif #include "ControlToc.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" #include "buffer.h" #include "Dialogs.h" #include "lyxfunc.h" #include "gettext.h" #include "BufferView.h" -#include "frontends/LyXView.h" - #include "support/lstrings.h" // tostr -#include - using std::vector; + ControlToc::ControlToc(LyXView & lv, Dialogs & d) : ControlCommand(lv, d, LFUN_TOC_INSERT) -{ - d_.showTOC = boost::bind(&ControlToc::showInset, this, _1); - d_.createTOC = boost::bind(&ControlToc::createInset, this, _1); -} +{} void ControlToc::Goto(int const & id) const diff --git a/src/frontends/controllers/ControlUrl.C b/src/frontends/controllers/ControlUrl.C index 03e2ce7d48..97438d8606 100644 --- a/src/frontends/controllers/ControlUrl.C +++ b/src/frontends/controllers/ControlUrl.C @@ -18,18 +18,8 @@ #endif #include "ControlUrl.h" -#include "ViewBase.h" -#include "ButtonControllerBase.h" -#include "Dialogs.h" -#include "buffer.h" -#include "frontends/LyXView.h" - -#include ControlUrl::ControlUrl(LyXView & lv, Dialogs & d) : ControlCommand(lv, d, LFUN_INSERT_URL) -{ - d_.showUrl = boost::bind(&ControlUrl::showInset, this, _1); - d_.createUrl = boost::bind(&ControlUrl::createInset, this, _1); -} +{} diff --git a/src/frontends/controllers/ControlVCLog.C b/src/frontends/controllers/ControlVCLog.C index 5670d19d94..2b5f13a254 100644 --- a/src/frontends/controllers/ControlVCLog.C +++ b/src/frontends/controllers/ControlVCLog.C @@ -20,11 +20,9 @@ #include "ControlVCLog.h" #include "Lsstream.h" -#include "ViewBase.h" #include "ButtonControllerBase.h" #include "buffer.h" #include "BufferView.h" -#include "Dialogs.h" #include "lyxrc.h" #include "gettext.h" @@ -32,17 +30,15 @@ #include "support/lyxlib.h" -#include - #include using std::endl; + ControlVCLog::ControlVCLog(LyXView & lv, Dialogs & d) : ControlDialogBD(lv, d) -{ - d_.showVCLogFile = boost::bind(&ControlVCLog::show, this); -} +{} + string const ControlVCLog::getBufferFileName() const { diff --git a/src/frontends/controllers/GUI.h b/src/frontends/controllers/GUI.h index c22090ce28..49f62ea290 100644 --- a/src/frontends/controllers/GUI.h +++ b/src/frontends/controllers/GUI.h @@ -11,38 +11,7 @@ #define GUI_H #include "ButtonController.h" -#include "ButtonPolicies.h" -#include "ControlAboutlyx.h" -#include "ControlBibitem.h" -#include "ControlBibtex.h" -#include "ControlCharacter.h" -#include "ControlCitation.h" -#include "ControlError.h" -#include "ControlERT.h" -#include "ControlExternal.h" -#include "ControlFloat.h" -#include "ControlForks.h" -#include "ControlGraphics.h" -#include "insets/insetgraphicsParams.h" -#include "ControlInclude.h" -#include "ControlIndex.h" -#include "ControlLog.h" -#include "ControlMinipage.h" -#include "ControlParagraph.h" -#include "ControlPreamble.h" -#include "ControlPrint.h" -#include "ControlRef.h" -#include "ControlSearch.h" -#include "ControlSendto.h" -#include "ControlShowFile.h" -#include "ControlSpellchecker.h" -#include "ControlTabularCreate.h" -#include "ControlTexinfo.h" -#include "ControlThesaurus.h" -#include "ControlToc.h" -#include "ControlUrl.h" -#include "ControlVCLog.h" - +#include "ViewBase.h" /** This class instantiates and makes available the GUI-specific ButtonController and View. @@ -57,6 +26,45 @@ public: /// virtual ViewBase & view() { return view_; } + friend void gui_ShowAboutlyx(LyXView &, Dialogs &); + friend void gui_ShowBibitem(InsetCommand *, LyXView &, Dialogs &); + friend void gui_ShowBibtex(InsetCommand *, LyXView &, Dialogs &); + friend void gui_ShowCharacter(LyXView &, Dialogs &); + friend void gui_SetUserFreeFont(LyXView &, Dialogs &); + friend void gui_ShowCitation(InsetCommand *, LyXView &, Dialogs &); + friend void gui_CreateCitation(string const &, LyXView &, Dialogs &); + friend void gui_ShowDocument(LyXView &, Dialogs &); + friend void gui_ShowError(InsetError *, LyXView &, Dialogs &); + friend void gui_ShowERT(InsetERT *, LyXView &, Dialogs &); + friend void gui_UpdateERT(InsetERT *, LyXView &, Dialogs &); + friend void gui_ShowExternal(InsetExternal *, LyXView &, Dialogs &); + friend void gui_ShowFloat(InsetFloat *, LyXView &, Dialogs &); + friend void gui_ShowForks(LyXView &, Dialogs &); + friend void gui_ShowGraphics(InsetGraphics *, LyXView &, Dialogs &); + friend void gui_ShowInclude(InsetInclude *, LyXView &, Dialogs &); + friend void gui_ShowIndex(InsetCommand *, LyXView &, Dialogs &); + friend void gui_CreateIndex(string const &, LyXView &, Dialogs &); + friend void gui_ShowLogFile(LyXView &, Dialogs &); + friend void gui_ShowMathPanel(LyXView &, Dialogs &); + friend void gui_ShowMinipage(InsetMinipage *, LyXView &, Dialogs &); + friend void gui_UpdateMinipage(InsetMinipage *, LyXView &, Dialogs &); + friend void gui_ShowParagraph(LyXView &, Dialogs &); + friend void gui_ShowPreamble(LyXView &, Dialogs &); + friend void gui_ShowPreferences(LyXView &, Dialogs &); + friend void gui_ShowPrint(LyXView &, Dialogs &); + friend void gui_ShowRef(InsetCommand *, LyXView &, Dialogs &); + friend void gui_CreateRef(string const &, LyXView &, Dialogs &); + friend void gui_ShowSearch(LyXView &, Dialogs &); + friend void gui_ShowSendto(LyXView &, Dialogs &); + friend void gui_ShowSpellchecker(LyXView &, Dialogs &); + friend void gui_ShowTabularCreate(LyXView &, Dialogs &); + friend void gui_ShowTexinfo(LyXView &, Dialogs &); + friend void gui_ShowTOC(InsetCommand *, LyXView &, Dialogs &); + friend void gui_CreateTOC(string const &, LyXView &, Dialogs &); + friend void gui_ShowUrl(InsetCommand *, LyXView &, Dialogs &); + friend void gui_CreateUrl(string const &, LyXView &, Dialogs &); + friend void gui_ShowVCLogFile(LyXView &, Dialogs &); + private: /// ButtonController bc_; @@ -64,357 +72,4 @@ private: GUIview view_; }; -#if 0 -/** Specialization for About LyX dialog - */ -template -class GUIAboutlyx : - public GUI { -public: - /// - GUIAboutlyx(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - -/** Specialization for Bibitem dialog - */ -template -class GUIBibitem : - public GUI { -public: - /// - GUIBibitem(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Bibtex dialog - */ -template -class GUIBibtex : - public GUI { -public: - /// - GUIBibtex(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Character dialog - */ -template -class GUICharacter : public GUI -{ -public: - /// - GUICharacter(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Citation dialog - */ -template -class GUICitation : public GUI -{ -public: - /// - GUICitation(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Error dialog - */ -template -class GUIError : - public GUI { -public: - /// - GUIError(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for ERT dialog - */ -template -class GUIERT : - public GUI { -public: - /// - GUIERT(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for External dialog - */ -template -class GUIExternal : - public GUI { -public: - /// - GUIExternal(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Forks dialog - */ -template -class GUIForks : - public GUI { -public: - /// - GUIForks(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - -/** Specialization for Graphics dialog - */ -template -class GUIGraphics : - public GUI { -public: - /// - GUIGraphics(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Include dialog - */ -template -class GUIInclude : - public GUI { -public: - /// - GUIInclude(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Index dialog - */ -template -class GUIIndex : - public GUI { -public: - /// - GUIIndex(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Log dialog - */ -template -class GUILog : - public GUI { -public: - /// - GUILog(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Minipage dialog - */ -template -class GUIMinipage : - public GUI { -public: - /// - GUIMinipage(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Float dialog - */ -template -class GUIFloat : - public GUI { -public: - /// - GUIFloat(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - -/** Specialization for Paragraph dialog - */ -template -class GUIParagraph : public GUI -{ -public: - /// - GUIParagraph(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - -/** Specialization for Preamble dialog - */ -template -class GUIPreamble : - public GUI { -public: - /// - GUIPreamble(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Print dialog - */ -template -class GUIPrint : - public GUI { -public: - /// - GUIPrint(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Ref dialog - */ -template -class GUIRef : - public GUI { -public: - /// - GUIRef(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Search dialog - */ -template -class GUISearch : - public GUI { -public: - /// - GUISearch(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Sendto dialog - */ -template -class GUISendto : - public GUI { -public: - /// - GUISendto(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for ShowFile dialog - */ -template -class GUIShowFile : - public GUI { -public: - /// - GUIShowFile(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - -/** Specialization for Spellchecker dialog - */ -template -class GUISpellchecker : - public GUI { -public: - /// - GUISpellchecker(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - -/** Specialization for Toc dialog - */ -template -class GUIToc : - public GUI { -public: - /// - GUIToc(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for TabularCreate dialog - */ -template -class GUITabularCreate : - public GUI { -public: - /// - GUITabularCreate(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Texinfo dialog - */ -template -class GUITexinfo : - public GUI { -public: - /// - GUITexinfo(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - -/** Specialization for Thesaurus dialog - */ -template -class GUIThesaurus : - public GUI { -public: - /// - GUIThesaurus(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for Url dialog - */ -template -class GUIUrl : - public GUI { -public: - /// - GUIUrl(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - - -/** Specialization for VCLog dialog - */ -template -class GUIVCLog : - public GUI { -public: - /// - GUIVCLog(LyXView & lv, Dialogs & d) - : GUI(lv, d) {} -}; - -#endif - #endif // GUI_H diff --git a/src/frontends/guiapi.h b/src/frontends/guiapi.h new file mode 100644 index 0000000000..e7abe92950 --- /dev/null +++ b/src/frontends/guiapi.h @@ -0,0 +1,66 @@ +// -*- C++ -*- + +#include "LString.h" + +class LyXView; +class Dialogs; +class InsetCommand; +class InsetError; +class InsetERT; +class InsetExternal; +class InsetFloat; +class InsetGraphics; +class InsetInclude; +class InsetInfo; +class InsetMinipage; +class InsetTabular; + +extern "C" { + + void gui_ShowAboutlyx(LyXView &, Dialogs &); + void gui_ShowBibitem(InsetCommand * ic, LyXView & lv, Dialogs & d); + void gui_ShowBibtex(InsetCommand * ic, LyXView & lv, Dialogs & d); + void gui_ShowCharacter(LyXView & lv, Dialogs & d); + void gui_SetUserFreeFont(LyXView & lv, Dialogs & d); + void gui_ShowCitation(InsetCommand * ic, LyXView & lv, Dialogs & d); + void gui_CreateCitation(string const &, LyXView & lv, Dialogs & d); + void gui_ShowDocument(LyXView & lv, Dialogs & d); + void gui_ShowError(InsetError * ie, LyXView & lv, Dialogs & d); + void gui_ShowERT(InsetERT * ie, LyXView & lv, Dialogs & d); + void gui_UpdateERT(InsetERT * ie, LyXView & lv, Dialogs & d); + void gui_ShowExternal(InsetExternal * ie, LyXView & lv, Dialogs & d); + void gui_ShowFile(string const & f, LyXView & lv, Dialogs & d); + void gui_ShowFloat(InsetFloat *, LyXView & lv, Dialogs &); + void gui_ShowForks(LyXView & lv, Dialogs & d); + void gui_ShowGraphics(InsetGraphics *, LyXView & lv, Dialogs & d); + void gui_ShowInclude(InsetInclude *, LyXView & lv, Dialogs & d); + void gui_ShowIndex(InsetCommand *, LyXView & lv, Dialogs & d); + void gui_CreateIndex(string const &, LyXView & lv, Dialogs & d); + void gui_ShowInfo(InsetInfo *, LyXView & lv, Dialogs & d); + void gui_ShowLogFile(LyXView & lv, Dialogs & d); + void gui_ShowMathPanel(LyXView & lv, Dialogs & d); + void gui_ShowMinipage(InsetMinipage *, LyXView & lv, Dialogs & d); + void gui_UpdateMinipage(InsetMinipage *, LyXView & lv, Dialogs & d); + void gui_ShowParagraph(LyXView & lv, Dialogs & d); + void gui_UpdateParagraph(LyXView & lv, Dialogs & d); + void gui_ShowPreamble(LyXView & lv, Dialogs & d); + void gui_ShowPreferences(LyXView & lv, Dialogs & d); + void gui_ShowPrint(LyXView & lv, Dialogs & d); + void gui_ShowRef(InsetCommand *, LyXView &, Dialogs &); + void gui_CreateRef(string const &, LyXView &, Dialogs &); + void gui_ShowSearch(LyXView & lv, Dialogs & d); + void gui_ShowSendto(LyXView & lv, Dialogs & d); + void gui_ShowSpellchecker(LyXView & lv, Dialogs & d); + void gui_ShowSpellcheckerPreferences(LyXView & lv, Dialogs & d); + void gui_ShowTabular(InsetTabular *, LyXView &, Dialogs &); + void gui_UpdateTabular(InsetTabular *, LyXView &, Dialogs &); + void gui_ShowTabularCreate(LyXView & lv, Dialogs & d); + void gui_ShowTexinfo(LyXView & lv, Dialogs & d); + void gui_ShowThesaurus(string const &, LyXView &, Dialogs &); + void gui_ShowTOC(InsetCommand *, LyXView &, Dialogs &); + void gui_CreateTOC(string const &, LyXView &, Dialogs &); + void gui_ShowUrl(InsetCommand *, LyXView &, Dialogs &); + void gui_CreateUrl(string const &, LyXView &, Dialogs &); + void gui_ShowVCLogFile(LyXView & lv, Dialogs & d); + +} // extern "C" diff --git a/src/frontends/screen.C b/src/frontends/screen.C index 79dd6542d5..8c72d54018 100644 --- a/src/frontends/screen.C +++ b/src/frontends/screen.C @@ -1,284 +1,87 @@ -/* This file is part of -* ====================================================== -* -* LyX, The Document Processor -* -* Copyright 1995 Matthias Ettrich -* Copyright 1995-1998 The LyX Team -* -* ====================================================== */ - -#include +/** + * \file screen.C + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ #ifdef __GNUG__ #pragma implementation #endif -#include +#include #include "screen.h" #include "lyxtext.h" #include "lyxrow.h" -#include "frontends/Painter.h" -#include "frontends/WorkArea.h" -#include "buffer.h" #include "BufferView.h" +#include "buffer.h" +#include "WorkArea.h" +#include "Painter.h" #include "font_metrics.h" -#include "insets/insettext.h" -#include "frontends/xforms/ColorHandler.h" #include "language.h" +#include "debug.h" -using std::max; using std::min; - -namespace { - -GC createGC() -{ - XGCValues val; - 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_get_display(), RootWindow(fl_get_display(), 0), - GCForeground | GCFunction | GCGraphicsExposures - | GCLineWidth | GCLineStyle , &val); -} - -} // namespace anon - - -// Constructor -LScreen::LScreen(WorkArea & o) - : owner(o), force_clear(true) +using std::max; +using std::endl; + +LyXScreen::LyXScreen() + : force_clear_(true), cursor_visible_(false) { - // the cursor isnt yet visible - cursor_visible = false; - cursor_pixmap = 0; - cursor_pixmap_x = 0; - cursor_pixmap_y = 0; - cursor_pixmap_w = 0; - cursor_pixmap_h = 0; - - // We need this GC - gc_copy = createGC(); } -LScreen::~LScreen() +LyXScreen::~LyXScreen() { - XFreeGC(fl_get_display(), gc_copy); } +// FIXME: GUII these cursor methods need to decide +// whether the workarea is focused or not -void LScreen::reset() +void LyXScreen::showCursor(LyXText const * text, BufferView const * bv) { - XFreeGC(fl_get_display(), gc_copy); - // the cursor isnt yet visible - cursor_visible = false; - cursor_pixmap = 0; - cursor_pixmap_x = 0; - cursor_pixmap_y = 0; - cursor_pixmap_w = 0; - cursor_pixmap_h = 0; - - // We need this GC - gc_copy = createGC(); -} + if (cursor_visible_) + return; + workarea().getPainter().start(); -void LScreen::setCursorColor() -{ - if (!lyxColorHandler.get()) return; - - GC gc = lyxColorHandler->getGCForeground(LColor::cursor); - - XGCValues val; - XGetGCValues(fl_get_display(), - gc, GCForeground, &val); - XChangeGC(fl_get_display(), gc_copy, GCForeground, &val); -} - - -void LScreen::redraw(LyXText * text, BufferView * bv) -{ - drawFromTo(text, bv, 0, owner.workHeight(), 0, 0, text == bv->text); - expose(0, 0, owner.workWidth(), owner.workHeight()); - if (cursor_visible) { - cursor_visible = false; - bv->showCursor(); - } -} - - -void LScreen::expose(int x, int y, int exp_width, int exp_height) -{ - XCopyArea(fl_get_display(), - owner.getPixmap(), - owner.getWin(), - gc_copy, - x, y, - exp_width, exp_height, - x + owner.xpos(), - y + owner.ypos()); -} - - -void LScreen::drawFromTo(LyXText * text, BufferView * bv, - int y1, int y2, int y_offset, int x_offset, - bool internal) -{ - int y_text = text->first_y + y1; - - // get the first needed row - Row * row = text->getRowNearY(y_text); - // y_text is now the real beginning of the row - - int y = y_text - text->first_y; - // y1 is now the real beginning of row on the screen - - while (row != 0 && y < y2) { - LyXText::text_status st = text->status(); - text->getVisibleRow(bv, y + y_offset, - x_offset, row, y + text->first_y); - internal = internal && (st != LyXText::CHANGED_IN_DRAW); - while (internal && text->status() == LyXText::CHANGED_IN_DRAW) { - text->fullRebreak(bv); - st = LyXText::NEED_MORE_REFRESH; - text->setCursor(bv, text->cursor.par(), - text->cursor.pos()); - text->status(bv, st); - // we should be sure our row-pointer is still valid, so it's - // better to recompute it. - y_text = y + text->first_y; - row = text->getRowNearY(y_text); - y = y_text - text->first_y; - text->getVisibleRow(bv, y + y_offset, - x_offset, row, y + text->first_y); - } - y += row->height(); - row = row->next(); - } - force_clear = false; - - // maybe we have to clear the screen at the bottom - if ((y < y2) && text->bv_owner) { - owner.getPainter().fillRectangle(0, y, - owner.workWidth(), - y2 - y, - LColor::bottomarea); - } -} - - -void LScreen::drawOneRow(LyXText * text, BufferView * bv, Row * row, - int y_text, int y_offset, int x_offset) -{ - int const y = y_text - text->first_y + y_offset; - - if (((y + row->height()) > 0) && - ((y - row->height()) <= static_cast(owner.workHeight()))) { - // ok there is something visible - text->getVisibleRow(bv, y, x_offset, row, y + text->first_y); - } - force_clear = false; -} - - -/* draws the screen, starting with textposition y. uses as much already - * printed pixels as possible */ -void LScreen::draw(LyXText * text, BufferView * bv, unsigned int y) -{ - if (cursor_visible) hideCursor(); - - int const old_first = text->first_y; - bool internal = (text == bv->text); - text->first_y = y; - - // is any optimiziation possible? - if ((y - old_first) < owner.workHeight() - && (old_first - y) < owner.workHeight()) - { - if (text->first_y < old_first) { - drawFromTo(text, bv, 0, - old_first - text->first_y, 0, 0, internal); - XCopyArea (fl_get_display(), - owner.getWin(), - owner.getWin(), - gc_copy, - owner.xpos(), - owner.ypos(), - owner.workWidth(), - owner.workHeight() - old_first + text->first_y, - owner.xpos(), - owner.ypos() + old_first - text->first_y - ); - // expose the area drawn - expose(0, 0, - owner.workWidth(), - old_first - text->first_y); - } else { - drawFromTo(text, bv, - owner.workHeight() + old_first - text->first_y, - owner.workHeight(), 0, 0, internal); - XCopyArea (fl_get_display(), - owner.getWin(), - owner.getWin(), - gc_copy, - owner.xpos(), - owner.ypos() + text->first_y - old_first, - owner.workWidth(), - owner.workHeight() + old_first - text->first_y, - owner.xpos(), - owner.ypos()); - // expose the area drawn - expose(0, owner.workHeight() + old_first - text->first_y, - owner.workWidth(), text->first_y - old_first); - } - } else { - // make a dumb new-draw - drawFromTo(text, bv, 0, owner.workHeight(), 0, 0, internal); - expose(0, 0, owner.workWidth(), owner.workHeight()); - } -} - - -void LScreen::showCursor(LyXText const * text, BufferView const * bv) -{ - if (!cursor_visible) { - Cursor_Shape shape = BAR_SHAPE; - if (text->real_current_font.language() != - bv->buffer()->params.language - || text->real_current_font.isVisibleRightToLeft() - != bv->buffer()->params.language->RightToLeft()) - shape = (text->real_current_font.isVisibleRightToLeft()) - ? REVERSED_L_SHAPE : L_SHAPE; - showManualCursor(text, text->cursor.x(), text->cursor.y(), - font_metrics::maxAscent(text->real_current_font), - font_metrics::maxDescent(text->real_current_font), - shape); + Cursor_Shape shape = BAR_SHAPE; + BufferParams const & bp(bv->buffer()->params); + LyXFont const & realfont(text->real_current_font); + + if (realfont.language() != bp.language + || realfont.isVisibleRightToLeft() + != bp.language->RightToLeft()) { + shape = (realfont.isVisibleRightToLeft()) + ? REVERSED_L_SHAPE : L_SHAPE; } + + showManualCursor(text, text->cursor.x(), text->cursor.y(), + font_metrics::maxAscent(realfont), + font_metrics::maxDescent(realfont), + shape); + + workarea().getPainter().end(); } -/* returns true if first has changed, otherwise false */ -bool LScreen::fitManualCursor(LyXText * text, BufferView * bv, - int /*x*/, int y, int asc, int desc) +bool LyXScreen::fitManualCursor(BufferView * bv, LyXText * text, + int /*x*/, int y, int asc, int desc) { + int const vheight = workarea().workHeight(); int newtop = text->first_y; - - if (y + desc - text->first_y >= static_cast(owner.workHeight())) - newtop = y - 3 * owner.workHeight() / 4; // the scroll region must be so big!! + + if (y + desc - text->first_y >= vheight) + newtop = y - 3 * vheight / 4; // the scroll region must be so big!! else if (y - asc < text->first_y && text->first_y > 0) { - newtop = y - owner.workHeight() / 4; + newtop = y - vheight / 4; } newtop = max(newtop, 0); // can newtop ever be < 0? (Lgb) - + if (newtop != text->first_y) { draw(text, bv, newtop); text->first_y = newtop; @@ -288,124 +91,26 @@ bool LScreen::fitManualCursor(LyXText * text, BufferView * bv, } -void LScreen::showManualCursor(LyXText const * text, int x, int y, - int asc, int desc, Cursor_Shape shape) +void LyXScreen::cursorToggle(BufferView * bv) const { - // Update the cursor color. - setCursorColor(); - - int const y1 = max(y - text->first_y - asc, 0); - int const y_tmp = min(y - text->first_y + desc, - static_cast(owner.workHeight())); - - // Secure against very strange situations - int const y2 = max(y_tmp, y1); - - if (cursor_pixmap) { - XFreePixmap(fl_get_display(), cursor_pixmap); - cursor_pixmap = 0; - } - - if (y2 > 0 && y1 < int(owner.workHeight())) { - cursor_pixmap_h = y2 - y1 + 1; - cursor_pixmap_y = y1; - - switch (shape) { - case BAR_SHAPE: - cursor_pixmap_w = 1; - cursor_pixmap_x = x; - break; - case L_SHAPE: - cursor_pixmap_w = cursor_pixmap_h/3; - cursor_pixmap_x = x; - break; - case REVERSED_L_SHAPE: - cursor_pixmap_w = cursor_pixmap_h/3; - cursor_pixmap_x = x - cursor_pixmap_w + 1; - break; - } - - cursor_pixmap = - XCreatePixmap (fl_get_display(), - fl_root, - cursor_pixmap_w, - cursor_pixmap_h, - fl_get_visual_depth()); - XCopyArea (fl_get_display(), - owner.getWin(), - cursor_pixmap, - gc_copy, - owner.xpos() + cursor_pixmap_x, - owner.ypos() + cursor_pixmap_y, - cursor_pixmap_w, - cursor_pixmap_h, - 0, 0); - XDrawLine(fl_get_display(), - owner.getWin(), - gc_copy, - x + owner.xpos(), - y1 + owner.ypos(), - x + owner.xpos(), - y2 + owner.ypos()); - switch (shape) { - case BAR_SHAPE: - break; - case L_SHAPE: - case REVERSED_L_SHAPE: - int const rectangle_h = (cursor_pixmap_h + 10) / 20; - XFillRectangle(fl_get_display(), - owner.getWin(), - gc_copy, - cursor_pixmap_x + owner.xpos(), - y2 - rectangle_h + 1 + owner.ypos(), - cursor_pixmap_w - 1, rectangle_h); - break; - } - - } - cursor_visible = true; -} - - -void LScreen::hideCursor() -{ - if (!cursor_visible) return; - - if (cursor_pixmap) { - XCopyArea (fl_get_display(), - cursor_pixmap, - owner.getWin(), - gc_copy, - 0, 0, - cursor_pixmap_w, cursor_pixmap_h, - cursor_pixmap_x + owner.xpos(), - cursor_pixmap_y + owner.ypos()); - } - cursor_visible = false; -} - - -void LScreen::cursorToggle(BufferView * bv) const -{ - if (cursor_visible) + if (cursor_visible_) bv->hideCursor(); else bv->showCursor(); } -/* returns a new top so that the cursor is visible */ -unsigned int LScreen::topCursorVisible(LyXCursor const & cursor, int top_y) +unsigned int LyXScreen::topCursorVisible(LyXCursor const & cursor, int top_y) { - int const vheight = owner.workHeight(); - int newtop = top_y; + int const vheight = workarea().workHeight(); + int newtop = top_y; Row * row = cursor.row(); // Is this a hack? Yes, probably... (Lgb) if (!row) return max(newtop, 0); - + if (cursor.y() - row->baseline() + row->height() - top_y >= vheight) { if (row->height() < vheight @@ -418,8 +123,8 @@ unsigned int LScreen::topCursorVisible(LyXCursor const & cursor, int top_y) newtop = cursor.y() - vheight / 2; /* the scroll region must be so big!! */ } - - } else if (static_cast(cursor.y() - row->baseline()) < + + } else if (static_cast((cursor.y()) - row->baseline()) < top_y && top_y > 0) { if (row->height() < vheight && row->height() > vheight / 4) { @@ -437,9 +142,7 @@ unsigned int LScreen::topCursorVisible(LyXCursor const & cursor, int top_y) } -/* scrolls the screen so that the cursor is visible, if necessary. -* returns true if a change was made, otherwise false */ -bool LScreen::fitCursor(LyXText * text, BufferView * bv) +bool LyXScreen::fitCursor(LyXText * text, BufferView * bv) { // Is a change necessary? int const newtop = topCursorVisible(text->cursor, text->first_y); @@ -449,28 +152,33 @@ bool LScreen::fitCursor(LyXText * text, BufferView * bv) return result; } - -void LScreen::update(LyXText * text, BufferView * bv, - int y_offset, int x_offset) + +void LyXScreen::update(LyXText * text, BufferView * bv, + int yo, int xo) { + int const vwidth = workarea().workWidth(); + int const vheight = workarea().workHeight(); + + workarea().getPainter().start(); + switch (text->status()) { case LyXText::NEED_MORE_REFRESH: { int const y = max(int(text->refresh_y - text->first_y), 0); - drawFromTo(text, bv, y, owner.workHeight(), y_offset, x_offset); + drawFromTo(text, bv, y, vheight, yo, xo); text->refresh_y = 0; // otherwise this is called ONLY from BufferView_pimpl(update) // or we should see to set this flag accordingly if (text != bv->text) text->status(bv, LyXText::UNCHANGED); - expose(0, y, owner.workWidth(), owner.workHeight() - y); + expose(0, y, vwidth, vheight - y); } break; case LyXText::NEED_VERY_LITTLE_REFRESH: { // ok I will update the current cursor row drawOneRow(text, bv, text->refresh_row, text->refresh_y, - y_offset, x_offset); + yo, xo); // this because if we had a major update the refresh_row could // have been set to 0! if (text->refresh_row) { @@ -478,8 +186,8 @@ void LScreen::update(LyXText * text, BufferView * bv, // or we should see to set this flag accordingly if (text != bv->text) text->status(bv, LyXText::UNCHANGED); - expose(0, text->refresh_y - text->first_y + y_offset, - owner.workWidth(), text->refresh_row->height()); + expose(0, text->refresh_y - text->first_y + yo, + vwidth, text->refresh_row->height()); } } break; @@ -488,12 +196,14 @@ void LScreen::update(LyXText * text, BufferView * bv, // Nothing needs done break; } + + workarea().getPainter().end(); } -void LScreen::toggleSelection(LyXText * text, BufferView * bv, +void LyXScreen::toggleSelection(LyXText * text, BufferView * bv, bool kill_selection, - int y_offset, int x_offset) + int yo, int xo) { // only if there is a selection if (!text->selection.set()) return; @@ -503,45 +213,140 @@ void LScreen::toggleSelection(LyXText * text, BufferView * bv, - text->selection.end.row()->baseline() + text->selection.end.row()->height()), text->first_y), - static_cast(text->first_y + owner.workHeight())); + static_cast(text->first_y + workarea().workHeight())); int const top = min( max(static_cast(text->selection.start.y() - text->selection.start.row()->baseline()), text->first_y), - static_cast(text->first_y + owner.workHeight())); + static_cast(text->first_y + workarea().workHeight())); if (kill_selection) text->selection.set(false); + + workarea().getPainter().start(); + drawFromTo(text, bv, top - text->first_y, bottom - text->first_y, - y_offset, x_offset); + yo, xo); expose(0, top - text->first_y, - owner.workWidth(), - bottom - text->first_y - (top - text->first_y)); + workarea().workWidth(), + bottom - text->first_y - (top - text->first_y)); + + workarea().getPainter().end(); } - - -void LScreen::toggleToggle(LyXText * text, BufferView * bv, - int y_offset, int x_offset) + + +void LyXScreen::toggleToggle(LyXText * text, BufferView * bv, + int yo, int xo) { if (text->toggle_cursor.par() == text->toggle_end_cursor.par() && text->toggle_cursor.pos() == text->toggle_end_cursor.pos()) return; - + int const top_tmp = text->toggle_cursor.y() - text->toggle_cursor.row()->baseline(); int const bottom_tmp = text->toggle_end_cursor.y() - text->toggle_end_cursor.row()->baseline() + text->toggle_end_cursor.row()->height(); - - int const offset = y_offset < 0 ? y_offset : 0; + + int const offset = yo < 0 ? yo : 0; int const bottom = min(max(bottom_tmp, text->first_y), - static_cast(text->first_y + owner.workHeight()))-offset; + static_cast(text->first_y + workarea().workHeight())) - offset; int const top = min(max(top_tmp, text->first_y), - static_cast(text->first_y + owner.workHeight()))-offset; + static_cast(text->first_y + workarea().workHeight())) - offset; + + workarea().getPainter().start(); drawFromTo(text, bv, top - text->first_y, - bottom - text->first_y, y_offset, - x_offset); - expose(0, top - text->first_y, owner.workWidth(), + bottom - text->first_y, yo, + xo); + expose(0, top - text->first_y, workarea().workWidth(), bottom - text->first_y - (top - text->first_y)); + + workarea().getPainter().end(); +} + + +void LyXScreen::redraw(LyXText * text, BufferView * bv) +{ + workarea().getPainter().start(); + + if (!text) { + greyOut(); + expose(0, 0, workarea().workWidth(), workarea().workHeight()); + workarea().getPainter().end(); + return; + } + + drawFromTo(text, bv, 0, workarea().workHeight(), 0, 0, text == bv->text); + expose(0, 0, workarea().workWidth(), workarea().workHeight()); + + workarea().getPainter().end(); + + if (cursor_visible_) { + cursor_visible_ = false; + bv->showCursor(); + } + +} + + +void LyXScreen::greyOut() +{ + workarea().getPainter().fillRectangle(0, 0, + workarea().workWidth(), + workarea().workHeight(), + LColor::bottomarea); +} + + +void LyXScreen::drawFromTo(LyXText * text, BufferView * bv, + int y1, int y2, int yo, int xo, + bool internal) +{ + int y_text = text->first_y + y1; + + // get the first needed row + Row * row = text->getRowNearY(y_text); + // y_text is now the real beginning of the row + + int y = y_text - text->first_y; + // y1 is now the real beginning of row on the screen + + while (row != 0 && y < y2) { + LyXText::text_status st = text->status(); + text->getVisibleRow(bv, y + yo, + xo, row, y + text->first_y); + internal = internal && (st != LyXText::CHANGED_IN_DRAW); + while (internal && text->status() == LyXText::CHANGED_IN_DRAW) { + text->fullRebreak(bv); + st = LyXText::NEED_MORE_REFRESH; + text->setCursor(bv, text->cursor.par(), text->cursor.pos()); + text->status(bv, st); + text->getVisibleRow(bv, y + yo, + xo, row, y + text->first_y); + } + y += row->height(); + row = row->next(); + } + force_clear_ = false; + + // maybe we have to clear the screen at the bottom + if ((y < y2) && text->bv_owner) { + workarea().getPainter().fillRectangle(0, y, + workarea().workWidth(), y2 - y, + LColor::bottomarea); + } +} + + +void LyXScreen::drawOneRow(LyXText * text, BufferView * bv, Row * row, + int y_text, int yo, int xo) +{ + int const y = y_text - text->first_y + yo; + + if (((y + row->height()) > 0) && + ((y - row->height()) <= static_cast(workarea().workHeight()))) { + text->getVisibleRow(bv, y, xo, row, y + text->first_y); + } + force_clear_ = false; } diff --git a/src/frontends/screen.h b/src/frontends/screen.h index 378d9d991e..47f092d8e5 100644 --- a/src/frontends/screen.h +++ b/src/frontends/screen.h @@ -6,29 +6,25 @@ * * \author unknown * \author John Levon - */ + */ -#ifndef LYXSCREEN_H -#define LYXSCREEN_H +#ifndef SCREEN_H +#define SCREEN_H #ifdef __GNUG__ #pragma interface #endif - -#include - + class LyXText; class LyXCursor; class WorkArea; -class Buffer; class BufferView; - struct Row; /** - * LScreen - document rendering management + * LyXScreen - document rendering management * - * This class is used to manage the on-screen rendering inside the + * This class is used to manage the on-screen rendering inside the * work area; it is responsible for deciding which LyXText rows * need re-drawing. * @@ -37,36 +33,66 @@ struct Row; * * The blinking cursor is also handled here. */ -class LScreen { +class LyXScreen { public: - /// + /// types of cursor in work area enum Cursor_Shape { - /// + /// normal I-beam BAR_SHAPE, - /// + /// L-shape for locked insets of a different language L_SHAPE, - /// + /// reverse L-shape for RTL text REVERSED_L_SHAPE }; - /// - LScreen(WorkArea &); + LyXScreen(); - /// - ~LScreen(); - - void reset(); + virtual ~LyXScreen(); + + /** + * draw the screen from a given position + * @param y the text position to draw from + * + * Uses as much of the already printed pixmap as possible + */ + virtual void draw(LyXText *, BufferView *, unsigned int y) = 0; + + /** + * showManualCursor - display the cursor on the work area + * @param text the lyx text containing the cursor + * @param x the x position of the cursor + * @param y the y position of the row's baseline + * @param asc ascent of the row + * @param desc descent of the row + * @param shape the current shape + */ + virtual void showManualCursor(LyXText const *, int x, int y, + int asc, int desc, + Cursor_Shape shape) = 0; + + /// unpaint the cursor painted by showManualCursor() + virtual void hideCursor() = 0; + + /** + * fit the cursor onto the visible work area, scrolling if necessary + * @param bv the buffer view + * @param vheight the height of the visible region + * @param base_y the top of the lyxtext to look at + * @param x the new x position + * @param y the new y position + * @param a ascent of the cursor's row + * @param d descent of the cursor's row + * @return true if the work area needs scrolling as a result + */ + bool fitManualCursor(BufferView * bv, LyXText * text, + int x, int y, int a, int d); + + /// redraw the screen, without using existing pixmap + virtual void redraw(LyXText *, BufferView *); + + /// draw the cursor if it's not already shown + virtual void showCursor(LyXText const *, BufferView const *); - /// Sets the cursor color to LColor::cursor. - void setCursorColor(); - - /** Draws the screen form textposition y. Uses as much of - the already printed pixmap as possible */ - void draw(LyXText *, BufferView *, unsigned int y); - - /// Redraws the screen, without using existing pixmap - void redraw(LyXText *, BufferView *); - /** * topCursorVisible - get a new "top" to make the cursor visible * @param c the cursor @@ -75,70 +101,71 @@ public: * This helper function calculates a new y co-ordinate for * the top of the containing region such that the cursor contained * within the LyXText is "nicely" visible. - */ - unsigned int topCursorVisible(LyXCursor const & c, int top_y); + */ + virtual unsigned int topCursorVisible(LyXCursor const & c, int top_y); - /// Redraws the screen such that the cursor is visible - bool fitCursor(LyXText *, BufferView *); - /// - void showCursor(LyXText const *, BufferView const *); - /// - void hideCursor(); - /// - void cursorToggle(BufferView *) const; - /// - void showManualCursor(LyXText const *, int x, int y, - int asc, int desc, - Cursor_Shape shape); - /// returns 1 if first has changed, otherwise 0 - bool fitManualCursor(LyXText *, BufferView *, int, int, int, int); - /// - void toggleSelection(LyXText *, BufferView *, bool = true, + /** + * fitCursor - fit the cursor onto the work area + * @param text the text containing the cursor + * @param bv the bufferview + * @return true if a change was necessary + * + * Scrolls the screen so that the cursor is visible, + */ + virtual bool fitCursor(LyXText *, BufferView *); + + /// show the cursor if it's not, and vice versa + virtual void cursorToggle(BufferView *) const; + + /** + * update - update part of the screen rendering + * @param text the containing text region + * @param bv the bufferview + * @param xo the x offset into the text + * @param yo the x offset into the text + * + * Updates part of the screen. If text->status is + * LyXText::NEED_MORE_REFRESH, we update from the + * point of change and to the end of the screen. + * If text->status is LyXText::NEED_VERY_LITTLE_REFRESH, + * we only update the current row. + */ + virtual void update(LyXText * text, BufferView * bv, int yo = 0, int xo = 0); + + /// FIXME + virtual void toggleSelection(LyXText *, BufferView *, bool = true, int y_offset = 0, int x_offset = 0); - /// - void toggleToggle(LyXText *, BufferView *, + + /// FIXME - at least change the name !! + virtual void toggleToggle(LyXText *, BufferView *, int y_offset = 0, int x_offset = 0); + + /// FIXME + virtual bool forceClear() const { return force_clear_; } - /** Updates part of the screen. If text->status is - LyXText::NEED_MORE_REFRESH, we update from the - point of change and to the end of the screen. - If text->status is LyXText::NEED_VERY_LITTLE_REFRESH, - we only update the current row. */ - void update(LyXText *, BufferView *, int y_offset=0, int x_offset=0); - /// - bool forceClear() const { return force_clear; } - - /// - bool cursor_visible; -private: - /// Copies specified area of pixmap to screen - void expose(int x, int y, int exp_width, int exp_height); +protected: + /// copies specified area of pixmap to screen + virtual void expose(int x, int y, int exp_width, int exp_height) = 0; + /// get the work area + virtual WorkArea & workarea() const = 0; + /// y1 and y2 are coordinates of the screen - void drawFromTo(LyXText *, BufferView *, int y1, int y2, - int y_offset = 0, int x_offset = 0, bool internal=false); + virtual void drawFromTo(LyXText *, BufferView *, int y1, int y2, + int y_offset = 0, int x_offset = 0, bool internal = false); /// y is a coordinate of the text - void drawOneRow(LyXText *, BufferView *, Row * row, + virtual void drawOneRow(LyXText *, BufferView *, Row * row, int y_text, int y_offset = 0, int x_offset = 0); - - /// - WorkArea & owner; - - /// - Pixmap cursor_pixmap; - /// - int cursor_pixmap_x; - /// - int cursor_pixmap_y; - /// - int cursor_pixmap_w; - /// - int cursor_pixmap_h; - /// - GC gc_copy; - /// - bool force_clear; + + /// grey out (no buffer) + void greyOut(); + + /// FIXME ? + bool force_clear_; + + /// is the blinking cursor currently drawn + bool cursor_visible_; }; -#endif +#endif // SCREEN_H diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 1f2440ee1e..a13b2c0c23 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,10 +1,37 @@ -2002-06-13 Juergen Spitzmueller +2002-06-16 Lars Gullik Bjønnes - * FormRef.C: Add Tooltips + * changes to let the function setup happen in frontends + * guiapi.C: new file -2002-06-18 Angus Leeming +2002-06-16 - * forms/.cvsignore: ignore any generated files/dirs. + * xscreen.C (draw): After drawing, we wait for X with XSync.. + + * XWorkArea.[Ch]: Xforms implementation of GUII WorkArea. + + * XPainter.[Ch]: Use XWorkArea instead of WorkArea. + + * xscreen.[Ch]: Use XWorkArea instead of WorkArea. + + * WorkAreaFactory.C: New file for GUII WorkArea. + + * LyXScreenFactory.C: WorkArea GUIIized. + +2002-06-15 Lyx Development team + + * LyXKeySymFactory.C: Added XForms implementation. + + * XLyXKeySym.[Ch]: Added XForms implementation of the LyXKeySym + stuff. + + * XWorkArea.[Ch]: Use LyXKeySym in signal interface for keypress. + +2002-06-14 Lyx Development team + + * LyXScreenFactory.C: Implementation for XForms. + + * xscreen.[Ch]: Added implementation of LyXScreen for XForms, + called XScreen (surprise!). 2002-06-14 Angus Leeming @@ -59,18 +86,18 @@ * xforms_helpers.[Ch]: removed scex, idex functions. * Most other files: minor changes associated with the above. - + 2002-06-12 John Levon * XWorkArea.h: * XWorkArea.C: move scrolling logic into here - + * ColorHandler.h: * ColorHandler.C: * XPainter.h: * XPainter.C: remove unused stuff, s/PainterBase/Painter/, s/Painter/XPainter/ - + 2002-06-12 Angus Leeming * lyx_gui.C (parse_init): exit isn't in namespace lyx_gui! @@ -82,7 +109,7 @@ 2002-05-24 Martin Vermeer - * FormMathsDelim.C: fix delimiter pre-display rendering + * FormMathsDelim.C: fix delimiter pre-display rendering mess-up bug (354) 2002-06-12 Jean-Marc Lasgouttes @@ -93,7 +120,7 @@ * XFormsView.h: * XFormsView.C: move init() back to LyXView - + 2002-06-12 John Levon * GUIRunTime.C: remove in favour of ... @@ -103,26 +130,26 @@ * XFormsView.h: * XFormsView.C: change show() prototype - + * XPainter.C: * xfont_loader.C: don't use GUIRunTime any more - + 2002-06-12 John Levon - * ColorHandler.C: + * ColorHandler.C: * FontInfo.h: * FormBase.C: * FormBaseDeprecated.C: * MathsSymbols.C: * Menubar_pimpl.C: minor cleanups - + 2002-06-12 John Levon * xformsGImage.C: * FontInfo.h: * FontInfo.C: some cleanup - - * XWorkArea.C: + + * XWorkArea.C: * XFormsView.h: * XFormsView.C: some minor cleanup, use of scoped_ptr @@ -134,12 +161,12 @@ * XWorkArea.h: * XWorkArea.C: use workHeight(), remove enter/leaveView - + 2002-06-11 John Levon * XWorkArea.h: * XWorkArea.C: remove belowMouse() and active() - + 2002-06-11 John Levon * xfont_metrics.h: @@ -147,11 +174,11 @@ * XPainter.C: X-specific metrics stuff moved into xforms/ only 2002-06-11 Edwin Leuven - - * FormParagraph.[Ch]: moved to mvc - * form_paragraph.[Ch]: idem - * forms/form_paragraph.fd: idem - * Dialogs.C: idem + + * FormParagraph.[Ch]: moved to mvc + * form_paragraph.[Ch]: idem + * forms/form_paragraph.fd: idem + * Dialogs.C: idem 2002-06-06 Jean-Marc Lasgouttes @@ -166,7 +193,7 @@ * xformsGImage.h: use FLIMAGE_H_LOCATION to include flimage.h. 2002-06-10 Lars Gullik Bjønnes - + * FormMathsPanel.C: do not include ButtonController.tmpl * FormPreferences.C: ditto * xformsBC.C: ditto @@ -190,11 +217,11 @@ 2002-06-04 John Levon * xformsGImage.h: an xforms build fix - + 2002-06-02 Michael A. Koziarski - + * Tooltips.C: fix some sigc++ -> boost errors. - + 2002-06-02 John Levon * GUIRunTime.C: @@ -206,7 +233,7 @@ 2002-05-10 Herbert Voss - * FormInclude.C (input, update): disable load-button when + * FormInclude.C (input, update): disable load-button when "use verbatim" is enabled 2002-05-30 Lars Gullik Bjønnes diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index fbb4ce3839..f4c3bf74d2 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -14,75 +14,10 @@ #endif #include "Dialogs.h" +#include "Tooltips.h" -#include "GUI.h" -#include "xformsBC.h" - -#include "combox.h" // needed for clean destruction of boost::scoped_ptr -#include "forms/form_aboutlyx.h" -#include "forms/form_bibitem.h" -#include "forms/form_bibtex.h" -#include "forms/form_browser.h" -#include "forms/form_character.h" -#include "forms/form_citation.h" -#include "forms/form_error.h" -#include "forms/form_ert.h" -#include "forms/form_external.h" -#include "forms/form_float.h" -#include "forms/form_forks.h" -#include "forms/form_graphics.h" -#include "forms/form_include.h" -#include "forms/form_index.h" -#include "forms/form_minipage.h" -#include "forms/form_paragraph.h" -#include "forms/form_preamble.h" -#include "forms/form_print.h" -#include "forms/form_ref.h" -#include "forms/form_search.h" -#include "forms/form_sendto.h" -#include "forms/form_spellchecker.h" -#include "forms/form_tabular_create.h" -#include "forms/form_texinfo.h" -#include "forms/form_thesaurus.h" -#include "forms/form_toc.h" -#include "forms/form_url.h" - -#include "FormAboutlyx.h" -#include "FormBibitem.h" -#include "FormBibtex.h" -#include "FormCharacter.h" -#include "FormCitation.h" -#include "FormError.h" -#include "FormERT.h" -#include "FormExternal.h" -#include "FormFloat.h" -#include "FormForks.h" -#include "FormGraphics.h" -#include "FormInclude.h" -#include "FormIndex.h" -#include "FormLog.h" -#include "FormMinipage.h" -#include "FormParagraph.h" -#include "FormPreamble.h" -#include "FormPrint.h" -#include "FormRef.h" -#include "FormSearch.h" -#include "FormSendto.h" -#include "FormShowFile.h" -#include "FormSpellchecker.h" -#include "FormTabularCreate.h" -#include "FormTexinfo.h" -#include "FormThesaurus.h" -#include "FormToc.h" -#include "FormUrl.h" -#include "FormVCLog.h" +LyXView * dialogs_lyxview; -#include "FormDocument.h" -#include "FormMathsPanel.h" -#include "FormPreferences.h" -#include "FormTabular.h" - -#include "Tooltips.h" /// Are the tooltips on or off? bool Dialogs::tooltipsEnabled() @@ -93,72 +28,9 @@ bool Dialogs::tooltipsEnabled() Dialogs::Dialogs(LyXView * lv) { - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); -#ifdef HAVE_LIBAIKSAURUS - add(new GUI(*lv, *this)); +#if 1 + dialogs_lyxview = lv; #endif - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - - add(new FormDocument(lv, this)); - add(new FormMathsPanel(lv, this)); - add(new FormPreferences(lv, this)); - add(new FormTabular(lv, this)); - // reduce the number of connections needed in // dialogs by a simple connection here. hideAll.connect(hideBufferDependent); diff --git a/src/frontends/xforms/FormAboutlyx.h b/src/frontends/xforms/FormAboutlyx.h index 6156600a4a..fa08318993 100644 --- a/src/frontends/xforms/FormAboutlyx.h +++ b/src/frontends/xforms/FormAboutlyx.h @@ -50,4 +50,5 @@ private: boost::scoped_ptr license_; }; + #endif // FORMABOUTLYX_H diff --git a/src/frontends/xforms/FormBaseDeprecated.h b/src/frontends/xforms/FormBaseDeprecated.h index ddcae8f444..188f980863 100644 --- a/src/frontends/xforms/FormBaseDeprecated.h +++ b/src/frontends/xforms/FormBaseDeprecated.h @@ -57,6 +57,8 @@ public: Tooltips & tooltips(); + friend void gui_ShowDocument(LyXView &, Dialogs &); + protected: // methods /// Pointer to the actual instantiation of the ButtonController. diff --git a/src/frontends/xforms/FormDocument.C b/src/frontends/xforms/FormDocument.C index 83f6a25248..ee2f78f981 100644 --- a/src/frontends/xforms/FormDocument.C +++ b/src/frontends/xforms/FormDocument.C @@ -62,10 +62,12 @@ FormDocument::FormDocument(LyXView * lv, Dialogs * d) ActCell(0), Confirmed(0), current_bullet_panel(0), current_bullet_depth(0), fbullet(0) { +#if 0 // let the dialog be shown // This is a permanent connection so we won't bother // storing a copy because we won't be disconnecting. d->showDocument = boost::bind(&FormDocument::show, this); +#endif } diff --git a/src/frontends/xforms/FormMathsPanel.C b/src/frontends/xforms/FormMathsPanel.C index 735284146b..251ace8f1d 100644 --- a/src/frontends/xforms/FormMathsPanel.C +++ b/src/frontends/xforms/FormMathsPanel.C @@ -152,7 +152,9 @@ FormMathsPanel::FormMathsPanel(LyXView * lv, Dialogs * d) ams_ops_.reset(new FormMathsBitmap(lv, d, *this, _("AMS Operators"), latex)); //showUnderMouse(false); +#if 0 d->showMathPanel = boost::bind(&FormMathsPanel::show, this); +#endif } diff --git a/src/frontends/xforms/FormMathsPanel.h b/src/frontends/xforms/FormMathsPanel.h index 1c5a65ef7f..db1af2827f 100644 --- a/src/frontends/xforms/FormMathsPanel.h +++ b/src/frontends/xforms/FormMathsPanel.h @@ -37,6 +37,7 @@ struct FD_maths_panel; */ class FormMathsPanel : public FormBaseBD { public: + friend void gui_ShowMathPanel(LyXView &, Dialogs &); /// FormMathsPanel(LyXView *, Dialogs *); /// @@ -96,7 +97,7 @@ class FormMathsSub : public FormBaseBD { public: /// FormMathsSub(LyXView *, Dialogs *, FormMathsPanel const &, - string const &, bool allowResize=true); + string const &, bool allowResize = true); protected: /// Pointer to the actual instantiation of the ButtonController. diff --git a/src/frontends/xforms/FormPreferences.C b/src/frontends/xforms/FormPreferences.C index 0a5fa59d02..9ebb191480 100644 --- a/src/frontends/xforms/FormPreferences.C +++ b/src/frontends/xforms/FormPreferences.C @@ -70,8 +70,8 @@ Converters local_converters; } // namespace anon -FormPreferences::FormPreferences(LyXView * lv, Dialogs * d) - : FormBaseBI(lv, d, _("Preferences"), false), +FormPreferences::FormPreferences(LyXView & lv, Dialogs & d) + : FormBaseBI(&lv, &d, _("Preferences"), false), colors_(*this), converters_(*this), inputs_misc_(*this), formats_(*this), interface_(*this), language_(*this), lnf_misc_(*this), outputs_misc_(*this), paths_(*this), @@ -80,8 +80,12 @@ FormPreferences::FormPreferences(LyXView * lv, Dialogs * d) // let the dialog be shown // This is a permanent connection so we won't bother // storing a copy because we won't be disconnecting. +#if 0 d->showPreferences = boost::bind(&FormPreferences::show, this); +#endif +#if 0 d->showSpellcheckerPreferences = boost::bind(&FormPreferences::showSpellPref, this); +#endif } diff --git a/src/frontends/xforms/FormPreferences.h b/src/frontends/xforms/FormPreferences.h index 81da0ba80d..6b83e07657 100644 --- a/src/frontends/xforms/FormPreferences.h +++ b/src/frontends/xforms/FormPreferences.h @@ -50,8 +50,10 @@ struct FD_preferences_spelloptions; */ class FormPreferences : public FormBaseBI { public: + friend void gui_ShowPreferences(LyXView &, Dialogs &); + friend void gui_ShowSpellcheckerPreferences(LyXView &, Dialogs &); /// - FormPreferences(LyXView *, Dialogs *); + FormPreferences(LyXView &, Dialogs &); private: /// Pointer to the actual instantiation of the ButtonController. diff --git a/src/frontends/xforms/FormRef.C b/src/frontends/xforms/FormRef.C index 4b06416c28..f66890ae91 100644 --- a/src/frontends/xforms/FormRef.C +++ b/src/frontends/xforms/FormRef.C @@ -17,7 +17,6 @@ #include "ControlRef.h" #include "FormRef.h" #include "forms/form_ref.h" -#include "Tooltips.h" #include "xforms_helpers.h" #include "insets/insetref.h" #include "helper_funcs.h" // getStringFromVector @@ -63,25 +62,6 @@ void FormRef::build() bc().addReadOnly(dialog_->button_update); bc().addReadOnly(dialog_->input_name); bc().addReadOnly(dialog_->input_ref); - - //set up the tooltip mechanism - string str = _("Show the labels of another opened document. Useful if you are working with multipart documents, where you might want to refer to another doc."); - tooltips().init(dialog_->choice_buffer, str); - - str = _("Choose a label to refer to."); - tooltips().init(dialog_->browser_refs, str); - - str = _("Type in a label name. We recommend that you use the browser instead."); - tooltips().init(dialog_->input_ref, str); - - str = _("Choose the reference style."); - tooltips().init(dialog_->choice_type, str); - - str = _("Sort labels in alphabetical order."); - tooltips().init(dialog_->check_sort, str); - - str = _("Refresh the list of labels."); - tooltips().init(dialog_->button_update, str); } diff --git a/src/frontends/xforms/FormShowFile.C b/src/frontends/xforms/FormShowFile.C index 9067ebb401..ca454c9369 100644 --- a/src/frontends/xforms/FormShowFile.C +++ b/src/frontends/xforms/FormShowFile.C @@ -19,6 +19,7 @@ #include "gettext.h" #include FORMS_H_LOCATION + FormShowFile::FormShowFile(ControlShowFile & c) : FormCB(c, string()) {} diff --git a/src/frontends/xforms/FormTabular.C b/src/frontends/xforms/FormTabular.C index ad802a295b..60150d2cc3 100644 --- a/src/frontends/xforms/FormTabular.C +++ b/src/frontends/xforms/FormTabular.C @@ -39,15 +39,17 @@ using std::bind2nd; using std::remove_if; -FormTabular::FormTabular(LyXView * lv, Dialogs * d) - : FormInset(lv, d, _("Tabular Layout")), +FormTabular::FormTabular(LyXView & lv, Dialogs & d) + : FormInset(&lv, &d, _("Tabular Layout")), inset_(0), actCell_(-1), closing_(false) { +#if 0 // let the dialog be shown // This is a permanent connection so we won't bother // storing a copy because we won't be disconnecting. d->showTabular = boost::bind(&FormTabular::showInset, this, _1); d->updateTabular = boost::bind(&FormTabular::updateInset, this, _1); +#endif } diff --git a/src/frontends/xforms/FormTabular.h b/src/frontends/xforms/FormTabular.h index fd26fe8e2b..c05e426bea 100644 --- a/src/frontends/xforms/FormTabular.h +++ b/src/frontends/xforms/FormTabular.h @@ -31,8 +31,11 @@ struct FD_tabular_longtable; */ class FormTabular : public FormInset { public: + friend void gui_ShowTabular(InsetTabular *, LyXView &, Dialogs &); + friend void gui_UpdateTabular(InsetTabular *, LyXView &, Dialogs &); + /// #FormTabular x(LyXFunc ..., Dialogs ...);# - FormTabular(LyXView *, Dialogs *); + FormTabular(LyXView &, Dialogs &); private: /// Pointer to the actual instantiation of the ButtonController. diff --git a/src/frontends/xforms/LyXKeySymFactory.C b/src/frontends/xforms/LyXKeySymFactory.C new file mode 100644 index 0000000000..798fc55b2a --- /dev/null +++ b/src/frontends/xforms/LyXKeySymFactory.C @@ -0,0 +1,22 @@ +/** + * \file LyXKeySymFactory.C + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author Asger & Juergen + */ + +#include + +#include "frontends/LyXKeySymFactory.h" + +#include "XLyXKeySym.h" + +namespace LyXKeySymFactory { + +LyXKeySym * create() +{ + return new XLyXKeySym(); +} + +} diff --git a/src/frontends/xforms/LyXScreenFactory.C b/src/frontends/xforms/LyXScreenFactory.C new file mode 100644 index 0000000000..1ce2b1c6e2 --- /dev/null +++ b/src/frontends/xforms/LyXScreenFactory.C @@ -0,0 +1,23 @@ +/** + * \file LyXScreenFactory.C + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#include + +#include "frontends/LyXScreenFactory.h" + +#include "XWorkArea.h" +#include "xscreen.h" + +namespace LyXScreenFactory { + +LyXScreen * create(WorkArea & owner) +{ + return new XScreen(static_cast(owner)); +} + +} diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index ed2b953913..f280f20d8b 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -40,6 +40,8 @@ libxforms_la_SOURCES = \ xforms_resize.h \ $(XFORMSGIMAGE) xformsBC.C \ xformsBC.h \ + xscreen.C \ + xscreen.h \ Alert_pimpl.C \ Color.C \ Color.h \ @@ -141,6 +143,9 @@ libxforms_la_SOURCES = \ FormUrl.h \ FormVCLog.C \ FormVCLog.h \ + guiapi.C \ + LyXKeySymFactory.C \ + LyXScreenFactory.C \ MathsSymbols.C \ MathsSymbols.h \ Menubar_pimpl.C \ @@ -153,8 +158,11 @@ libxforms_la_SOURCES = \ Toolbar_pimpl.h \ Tooltips.C \ Tooltips.h \ + WorkAreaFactory.C \ XFormsView.C \ XFormsView.h \ + XLyXKeySym.C \ + XLyXKeySym.h \ XPainter.C \ XPainter.h \ XWorkArea.h \ diff --git a/src/frontends/xforms/WorkAreaFactory.C b/src/frontends/xforms/WorkAreaFactory.C new file mode 100644 index 0000000000..59bd400646 --- /dev/null +++ b/src/frontends/xforms/WorkAreaFactory.C @@ -0,0 +1,22 @@ +/** + * \file WorkAreaFactory.C + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author John Levon + */ + +#include + +#include "frontends/WorkAreaFactory.h" + +#include "XWorkArea.h" + +namespace WorkAreaFactory { + +WorkArea * create(int x, int y, int w, int h) +{ + return new XWorkArea(x, y, w, h); +} + +} diff --git a/src/frontends/xforms/XLyXKeySym.C b/src/frontends/xforms/XLyXKeySym.C new file mode 100644 index 0000000000..0398507910 --- /dev/null +++ b/src/frontends/xforms/XLyXKeySym.C @@ -0,0 +1,106 @@ +/** + * \file XLyXKeySym.C + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author Asger and Juergen + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "XLyXKeySym.h" + +#include "debug.h" + +#include +#include + +using std::endl; + +XLyXKeySym::XLyXKeySym() + : LyXKeySym(), keysym(NoSymbol) +{ +} + +void XLyXKeySym::initFromKeySym(KeySym ks) +{ + keysym = ks; +} + +void XLyXKeySym::init(string const & symbolname) +{ + keysym = XStringToKeysym(symbolname.c_str()); + if (keysym == NoSymbol) { + lyxerr[Debug::KBMAP] + << "XLyXKeySym.C: No such keysym: " + << symbolname << endl; + } +} + +bool XLyXKeySym::isOK() const +{ + return keysym != NoSymbol; +} + +bool XLyXKeySym::isModifier() const +{ + // Can we be sure that this will work for all X Window + // implementations? (Lgb) + // Perhaps all of them should be explictly mentioned? + return ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R) + || keysym == XK_Mode_switch || keysym == 0x0); +} + +string +XLyXKeySym::getSymbolName() const +{ + char * name = XKeysymToString(keysym); + return name ? name : string(); +} + +char +XLyXKeySym::getISOEncoded() const +{ + if (keysym == NoSymbol) { + return 0; + } + + unsigned int c = keysym; + + switch (c & 0x0000FF00) { + // latin 1 byte 3 = 0 + case 0x00000000: break; + // latin 2 byte 3 = 1 + case 0x00000100: + // latin 3 byte 3 = 2 + case 0x00000200: + // latin 4 byte 3 = 3 + case 0x00000300: + // cyrillic KOI8 & Co + case 0x00000600: + // greek + case 0x00000700: + // latin 8 byte 3 = 18 (0x12) + case 0x00001200: + // latin 9 byte 3 = 19 (0x13) + case 0x00001300: + c &= 0x000000FF; + break; + default: + c = 0; + } + return c; +} + +bool XLyXKeySym::operator==(LyXKeySym const & k) const +{ + // This is dangerous! Ideally, we should use dynamic_cast instead, + // but on the other hand, we are sure that we will always get + // the right type, because we decide at compile time which + // frontend we use. (Asger) + return keysym == static_cast(k).keysym; +} diff --git a/src/frontends/xforms/XLyXKeySym.h b/src/frontends/xforms/XLyXKeySym.h new file mode 100644 index 0000000000..b056411614 --- /dev/null +++ b/src/frontends/xforms/XLyXKeySym.h @@ -0,0 +1,60 @@ +// -*- C++ -*- +/** + * \file XLyXKeySym.h + * Copyright 2002 the LyX Team + * Read the file COPYING + * + * \author Asger and Juergen + */ + +#ifndef XLYXKEYSYM_H +#define XLYXKEYSYM_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "LString.h" +#include +#include "frontends/LyXKeySym.h" + +/** + * This is a base class for representing a keypress. + * Each frontend has to implement this to provide + * the functionality that LyX needs in regards to + * key presses. + */ +class XLyXKeySym : public LyXKeySym { +public: + XLyXKeySym(); + + /// X11 specific initialization with an X11 KeySym + void initFromKeySym(KeySym); + + virtual void init(string const & symbolname); + + virtual ~XLyXKeySym() {} + + /// Is this a valid key? + virtual bool isOK() const; + + /// Is this a modifier key only? + virtual bool isModifier() const; + + virtual string getSymbolName() const; + + /** + * Return the value of the keysym into the local ISO encoding. + * This converts the LyXKeySym to a 8-bit encoded character. + * This relies on user to use the right encoding. + */ + virtual char getISOEncoded() const; + + virtual bool operator==(LyXKeySym const & k) const; + +private: + unsigned int keysym; +}; + +#endif + diff --git a/src/frontends/xforms/XPainter.C b/src/frontends/xforms/XPainter.C index 3c96f66256..68837a7d71 100644 --- a/src/frontends/xforms/XPainter.C +++ b/src/frontends/xforms/XPainter.C @@ -36,7 +36,7 @@ using std::endl; using std::max; -XPainter::XPainter(WorkArea & xwa) +XPainter::XPainter(XWorkArea & xwa) : Painter(), owner_(xwa) { } diff --git a/src/frontends/xforms/XPainter.h b/src/frontends/xforms/XPainter.h index 1813cf1e60..ddb5c3684b 100644 --- a/src/frontends/xforms/XPainter.h +++ b/src/frontends/xforms/XPainter.h @@ -24,14 +24,14 @@ class LyXFont; -class WorkArea; +class XWorkArea; /** * XPainter - a painter implementation for Xlib */ class XPainter : public Painter { public: - XPainter(WorkArea &); + XPainter(XWorkArea &); /// return the width of the work area in pixels virtual int paperWidth() const; @@ -120,7 +120,7 @@ public: private: /// our owner who we paint upon - WorkArea & owner_; + XWorkArea & owner_; }; #endif // XPAINTER_H diff --git a/src/frontends/xforms/XWorkArea.C b/src/frontends/xforms/XWorkArea.C index 4498937b84..6348e476e1 100644 --- a/src/frontends/xforms/XWorkArea.C +++ b/src/frontends/xforms/XWorkArea.C @@ -18,6 +18,7 @@ #include "LyXView.h" #include "lyxrc.h" // lyxrc.show_banner #include "version.h" // lyx_version +#include "XLyXKeySym.h" #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)) #include "lyxlookup.h" @@ -123,33 +124,33 @@ key_modifier::state x_key_state(unsigned int state) extern "C" { - // Just a bunch of C wrappers around static members of WorkArea + // Just a bunch of C wrappers around static members of XWorkArea static - void C_WorkArea_scroll_cb(FL_OBJECT * ob, long) + void C_XWorkArea_scroll_cb(FL_OBJECT * ob, long) { - WorkArea * area = static_cast(ob->u_vdata); + XWorkArea * area = static_cast(ob->u_vdata); area->scroll_cb(); } static - int C_WorkArea_work_area_handler(FL_OBJECT * ob, int event, + int C_XWorkArea_work_area_handler(FL_OBJECT * ob, int event, FL_Coord, FL_Coord, int key, void * xev) { - return WorkArea::work_area_handler(ob, event, + return XWorkArea::work_area_handler(ob, event, 0, 0, key, xev); } static - int C_WorkAreaEventCB(FL_FORM * form, void * xev) { - WorkArea * wa = static_cast(form->u_vdata); + int C_XWorkAreaEventCB(FL_FORM * form, void * xev) { + XWorkArea * wa = static_cast(form->u_vdata); return wa->event_cb(static_cast(xev)); } } -WorkArea::WorkArea(int x, int y, int w, int h) +XWorkArea::XWorkArea(int x, int y, int w, int h) : splash_(0), splash_text_(0), workareapixmap(0), painter_(*this) { fl_freeze_all_forms(); @@ -207,7 +208,7 @@ WorkArea::WorkArea(int x, int y, int w, int h) fl_set_object_resize(obj, FL_RESIZE_ALL); fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity); obj->u_vdata = this; - fl_set_object_callback(obj, C_WorkArea_scroll_cb, 0); + fl_set_object_callback(obj, C_XWorkArea_scroll_cb, 0); fl_set_scrollbar_bounds(scrollbar, 0.0, 0.0); fl_set_scrollbar_value(scrollbar, 0.0); fl_set_scrollbar_size(scrollbar, scrollbar->h); @@ -232,9 +233,9 @@ WorkArea::WorkArea(int x, int y, int w, int h) x + bw, y + bw, w - 15 - 2 * bw, // scrollbarwidth h - 2 * bw, "", - C_WorkArea_work_area_handler); + C_XWorkArea_work_area_handler); obj->wantkey = FL_KEY_ALL; - obj->u_vdata = this; /* This is how we pass the WorkArea + obj->u_vdata = this; /* This is how we pass the XWorkArea to the work_area_handler. */ fl_set_object_boxtype(obj,FL_DOWN_BOX); fl_set_object_resize(obj, FL_RESIZE_ALL); @@ -242,20 +243,20 @@ WorkArea::WorkArea(int x, int y, int w, int h) /// X selection hook - xforms gets it wrong fl_current_form->u_vdata = this; - fl_register_raw_callback(fl_current_form, FL_ALL_EVENT, C_WorkAreaEventCB); + fl_register_raw_callback(fl_current_form, FL_ALL_EVENT, C_XWorkAreaEventCB); fl_unfreeze_all_forms(); } -WorkArea::~WorkArea() +XWorkArea::~XWorkArea() { if (workareapixmap) XFreePixmap(fl_get_display(), workareapixmap); } -void WorkArea::resize(int xpos, int ypos, int width, int height) +void XWorkArea::resize(int xpos, int ypos, int width, int height) { fl_freeze_all_forms(); @@ -297,7 +298,7 @@ void destroy_object(FL_OBJECT * obj) } // namespace anon -void WorkArea::createPixmap(int width, int height) +void XWorkArea::createPixmap(int width, int height) { // Three calls to createPixmap are needed to draw the initial view // of LyX. Any more and the splash is destroyed. @@ -335,7 +336,7 @@ void WorkArea::createPixmap(int width, int height) } -void WorkArea::greyOut() const +void XWorkArea::greyOut() const { if (!splash_) { fl_winset(FL_ObjWin(work_area)); @@ -345,13 +346,13 @@ void WorkArea::greyOut() const } -void WorkArea::setFocus() const +void XWorkArea::setFocus() const { fl_set_focus_object(work_area->form, work_area); } -void WorkArea::setScrollbarParams(int height, int pos, int line_height) +void XWorkArea::setScrollbarParams(int height, int pos, int line_height) { // we need to cache this for scroll_cb doc_height_ = height; @@ -391,7 +392,7 @@ void WorkArea::setScrollbarParams(int height, int pos, int line_height) // callback for scrollbar slider -void WorkArea::scroll_cb() +void XWorkArea::scroll_cb() { double const val = fl_get_scrollbar_value(scrollbar); lyxerr[Debug::GUI] << "scroll: val: " << val << endl; @@ -402,7 +403,7 @@ void WorkArea::scroll_cb() } -int WorkArea::work_area_handler(FL_OBJECT * ob, int event, +int XWorkArea::work_area_handler(FL_OBJECT * ob, int event, FL_Coord, FL_Coord , int key, void * xev) { @@ -411,7 +412,7 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, static long scrollbar_value_old = -1; XEvent * ev = static_cast(xev); - WorkArea * area = static_cast(ob->u_vdata); + XWorkArea * area = static_cast(ob->u_vdata); if (!area) return 1; @@ -477,15 +478,16 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, // lyxerr << "We have " << num_keys << " keys in the returned buffer" << endl; // lyxerr << "Our dummy string is " << dummy << endl; #endif + if (lyxerr.debugging(Debug::KEY)) { char const * tmp = XKeysymToString(key); char const * tmp2 = XKeysymToString(keysym); string const stm = (tmp ? tmp : ""); string const stm2 = (tmp2 ? tmp2 : ""); - lyxerr[Debug::KEY] << "WorkArea: Key is `" << stm << "' [" + lyxerr[Debug::KEY] << "XWorkArea: Key is `" << stm << "' [" << key << "]" << endl; - lyxerr[Debug::KEY] << "WorkArea: Keysym is `" << stm2 << "' [" + lyxerr[Debug::KEY] << "XWorkArea: Keysym is `" << stm2 << "' [" << keysym << "]" << endl; } @@ -562,7 +564,11 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, last_key_pressed = xke->keycode; last_state_pressed = ret_state; - area->workAreaKeyPress(ret_key, x_key_state(ret_state)); + XLyXKeySym * xlk = new XLyXKeySym; + xlk->initFromKeySym(ret_key); + + area->workAreaKeyPress(LyXKeySymPtr(xlk), + x_key_state(ret_state)); } break; @@ -637,7 +643,7 @@ extern "C" { } // namespace anon -int WorkArea::event_cb(XEvent * xev) +int XWorkArea::event_cb(XEvent * xev) { int ret = 0; switch (xev->type) { @@ -654,7 +660,7 @@ int WorkArea::event_cb(XEvent * xev) } -void WorkArea::haveSelection(bool yes) const +void XWorkArea::haveSelection(bool yes) const { if (!yes) { XSetSelectionOwner(fl_get_display(), XA_PRIMARY, None, CurrentTime); @@ -665,7 +671,7 @@ void WorkArea::haveSelection(bool yes) const } -string const WorkArea::getClipboard() const +string const XWorkArea::getClipboard() const { clipboard_read = false; @@ -686,7 +692,7 @@ string const WorkArea::getClipboard() const } -void WorkArea::putClipboard(string const & s) const +void XWorkArea::putClipboard(string const & s) const { static string hold; hold = s; diff --git a/src/frontends/xforms/XWorkArea.h b/src/frontends/xforms/XWorkArea.h index 5caf8076d8..55de2f14fd 100644 --- a/src/frontends/xforms/XWorkArea.h +++ b/src/frontends/xforms/XWorkArea.h @@ -15,59 +15,49 @@ #pragma interface #endif +#include "frontends/WorkArea.h" #include "XPainter.h" -#include "frontends/mouse_state.h" -#include "frontends/key_state.h" - -#include -#include -#include -#include #include FORMS_H_LOCATION -#include /// -class WorkArea { +class XWorkArea : public WorkArea { public: /// - WorkArea(int xpos, int ypos, int width, int height); + XWorkArea(int xpos, int ypos, int width, int height); /// - ~WorkArea(); + ~XWorkArea(); /// - Painter & getPainter() { return painter_; } + virtual Painter & getPainter() { return painter_; } /// - int workWidth() const { return work_area->w; } + virtual int workWidth() const { return work_area->w; } /// - int workHeight() const { return work_area->h; } + virtual int workHeight() const { return work_area->h; } /// - unsigned int width() const { return work_area->w + scrollbar->w; } - //unsigned int width() const { return backgroundbox->w + 15; } + virtual unsigned int width() const { return work_area->w + scrollbar->w; } /// - int xpos() const { return work_area->x; } - //int xpos() const { return backgroundbox->x; } + virtual int xpos() const { return work_area->x; } /// - int ypos() const { return work_area->y; } - //int ypos() const { return backgroundbox->y; } + virtual int ypos() const { return work_area->y; } /// - void resize(int xpos, int ypos, int width, int height); + virtual void resize(int xpos, int ypos, int width, int height); /// - void redraw() const { + virtual void redraw() const { fl_redraw_object(work_area); fl_redraw_object(scrollbar); } /// - void setFocus() const; + virtual void setFocus() const; /// Window getWin() const { return work_area->form->window; } /// - bool hasFocus() const { return work_area->focus; } + virtual bool hasFocus() const { return work_area->focus; } /// - bool visible() const { return work_area->form->visible; } + virtual bool visible() const { return work_area->form->visible; } /// - void greyOut() const; + virtual void greyOut() const; /// - void setScrollbarParams(int height, int pos, int line_height); + virtual void setScrollbarParams(int height, int pos, int line_height); /// Pixmap getPixmap() const { return workareapixmap; } /// xforms callback @@ -78,36 +68,11 @@ public: /// xforms callback from scrollbar void scroll_cb(); /// a selection exists - void haveSelection(bool) const; - /// - string const getClipboard() const; - /// - void putClipboard(string const &) const; - // Signals - /// - boost::signal0 workAreaExpose; - /// - boost::signal1 scrollDocView; - /// - boost::signal2 workAreaKeyPress; - /// - boost::signal3 workAreaButtonPress; - /// - boost::signal3 workAreaButtonRelease; - /// - boost::signal3 workAreaMotionNotify; - /// - boost::signal0 workAreaFocus; - /// - boost::signal0 workAreaUnfocus; + virtual void haveSelection(bool) const; /// - boost::signal3 workAreaDoubleClick; + virtual string const getClipboard() const; /// - boost::signal3 workAreaTripleClick; - /// emitted when an X client has requested our selection - boost::signal0 selectionRequested; - /// emitted when another X client has stolen our selection - boost::signal0 selectionLost; + virtual void putClipboard(string const &) const; /// handles SelectionRequest X Event, to fill the clipboard int event_cb(XEvent * xev); diff --git a/src/frontends/xforms/forms/.cvsignore b/src/frontends/xforms/forms/.cvsignore index 8f7466392f..3181709fd4 100644 --- a/src/frontends/xforms/forms/.cvsignore +++ b/src/frontends/xforms/forms/.cvsignore @@ -4,6 +4,3 @@ Makefile *.h *.C *.tmp -*.lo -.deps -.libs diff --git a/src/frontends/xforms/forms/form_maths_delim.fd b/src/frontends/xforms/forms/form_maths_delim.fd index 12eddccd98..d543119de7 100644 --- a/src/frontends/xforms/forms/form_maths_delim.fd +++ b/src/frontends/xforms/forms/form_maths_delim.fd @@ -10,13 +10,13 @@ SnapGrid: 2 =============== FORM =============== Name: form_maths_delim Width: 250 -Height: 307 +Height: 221 Number of Objects: 11 -------------------- class: FL_BOX type: UP_BOX -box: 0 0 250 307 +box: 0 0 250 221 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -34,7 +34,7 @@ argument: -------------------- class: FL_BUTTON type: PUSH_BUTTON -box: 42 112 170 140 +box: 28 108 192 64 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -52,7 +52,7 @@ argument: 0 -------------------- class: FL_BUTTON type: NORMAL_BUTTON -box: 168 268 70 30 +box: 168 182 70 30 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -88,7 +88,7 @@ argument: 0 -------------------- class: FL_BUTTON type: NORMAL_BUTTON -box: 90 268 70 30 +box: 90 182 70 30 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -106,7 +106,7 @@ argument: 0 -------------------- class: FL_BUTTON type: RETURN_BUTTON -box: 12 268 70 30 +box: 14 182 70 30 boxtype: FL_UP_BOX colors: FL_COL1 FL_COL1 alignment: FL_ALIGN_CENTER @@ -135,7 +135,7 @@ label: shortcut: resize: FL_RESIZE_ALL gravity: FL_NoGravity FL_NoGravity -name: +name: callback: argument: diff --git a/src/frontends/xforms/guiapi.C b/src/frontends/xforms/guiapi.C new file mode 100644 index 0000000000..af5ef386a7 --- /dev/null +++ b/src/frontends/xforms/guiapi.C @@ -0,0 +1,534 @@ +#include + +#include "guiapi.h" + +#include "FormAboutlyx.h" +#include "forms/form_aboutlyx.h" + +#include "FormBibitem.h" +#include "forms/form_bibitem.h" + +#include "FormBibtex.h" +#include "forms/form_bibtex.h" + +#include "FormBrowser.h" +#include "forms/form_browser.h" + +#include "FormCharacter.h" +#include "forms/form_character.h" + +#include "FormCitation.h" +#include "forms/form_citation.h" + +#include "FormDocument.h" +#include "forms/form_document.h" + +#include "FormError.h" +#include "forms/form_error.h" + +#include "FormERT.h" +#include "forms/form_ert.h" + +#include "FormExternal.h" +#include "forms/form_external.h" + +#include "FormFloat.h" +#include "forms/form_float.h" + +#include "FormForks.h" +#include "forms/form_forks.h" + +#include "FormGraphics.h" +#include "forms/form_graphics.h" + +#include "FormInclude.h" +#include "forms/form_include.h" + +#include "FormIndex.h" +#include "forms/form_index.h" + +#include "FormLog.h" + +#include "FormMathsPanel.h" +#include "FormMathsBitmap.h" +#include "FormMathsDeco.h" +#include "FormMathsDelim.h" +#include "FormMathsMatrix.h" +#include "FormMathsSpace.h" +#include "FormMathsStyle.h" + +#include "forms/form_maths_deco.h" +#include "forms/form_maths_delim.h" +#include "forms/form_maths_matrix.h" +#include "forms/form_maths_panel.h" +#include "forms/form_maths_space.h" +#include "forms/form_maths_style.h" + +#include "FormMinipage.h" +#include "forms/form_minipage.h" + +#include "FormParagraph.h" +#include "forms/form_paragraph.h" + +#include "FormPreamble.h" +#include "forms/form_preamble.h" + +#include "FormPreferences.h" +#include "forms/form_preferences.h" + +#include "FormPrint.h" +#include "forms/form_print.h" + +#include "FormRef.h" +#include "forms/form_ref.h" + +#include "FormSearch.h" +#include "forms/form_search.h" + +#include "FormSendto.h" +#include "forms/form_sendto.h" + +#include "FormShowFile.h" + +#include "FormSpellchecker.h" +#include "forms/form_spellchecker.h" + +#include "FormTabular.h" +#include "forms/form_tabular.h" + +#include "FormTabularCreate.h" +#include "forms/form_tabular_create.h" + +#include "FormTexinfo.h" +#include "forms/form_texinfo.h" + +#include "FormToc.h" +#include "forms/form_toc.h" + +#include "FormUrl.h" +#include "forms/form_url.h" + +#include "FormVCLog.h" + +#include "xformsBC.h" +#include "combox.h" + +#include "controllers/GUI.h" +#include "insets/inseterror.h" + +#include "LyXView.h" + +#include "ControlAboutlyx.h" +#include "ControlBibitem.h" +#include "ControlBibtex.h" +#include "ControlCharacter.h" +#include "ControlCitation.h" +#include "ControlError.h" +#include "ControlERT.h" +#include "ControlExternal.h" +#include "ControlFloat.h" +#include "ControlForks.h" +#include "ControlGraphics.h" +#include "insets/insetgraphicsParams.h" +#include "ControlInclude.h" +#include "ControlIndex.h" +#include "ControlLog.h" +#include "ControlMinipage.h" +#include "ControlParagraph.h" +#include "ControlPreamble.h" +#include "ControlPrint.h" +#include "ControlRef.h" +#include "ControlSearch.h" +#include "ControlSendto.h" +#include "ControlShowFile.h" +#include "ControlSpellchecker.h" +#include "ControlTabularCreate.h" +#include "ControlTexinfo.h" +#include "ControlThesaurus.h" +#include "ControlToc.h" +#include "ControlUrl.h" +#include "ControlVCLog.h" + + +namespace { // anon + +// I belive that this one is buggy (Lgb) +// But not if used correctly. (Lgb) +template +class GUISingleton { +public: + static + T & get(LyXView & lv, Dialogs & d) { + static T t(lv, d); + return t; + } +}; + + +GUISingleton > +controlCharacterSingleton; + +GUISingleton > +controlCitationSingleton; + + +GUISingleton > +controlERTSingleton; + +GUISingleton > +controlIndexSingleton; + +GUISingleton > +controlMinipageSingleton; + +GUISingleton formPreferencesSingleton; + +GUISingleton > +controlRefSingleton; + +GUISingleton formTabularSingleton; + +GUISingleton > +controlTocSingleton; + +GUISingleton > +controlUrlSingleton; + +} // anon + + +extern "C" { + + void gui_ShowAboutlyx(LyXView & lv, Dialogs & d) + { + static GUI cal(lv, d); + cal.show(); + } + + + void gui_ShowBibitem(InsetCommand * ic, LyXView & lv, Dialogs & d) + { + static GUI cbi(lv, d); + cbi.showInset(ic); + } + + + void gui_ShowBibtex(InsetCommand * ic, LyXView & lv, Dialogs & d) + { + static GUI cbt(lv, d); + cbt.showInset(ic); + } + + + void gui_ShowCharacter(LyXView & lv, Dialogs & d) + { + controlCharacterSingleton.get(lv, d).show(); + } + + + void gui_SetUserFreeFont(LyXView & lv, Dialogs & d) + { + controlCharacterSingleton.get(lv, d).apply(); + } + + + void gui_ShowCitation(InsetCommand * ic, LyXView & lv, Dialogs & d) + { + controlCitationSingleton.get(lv, d).showInset(ic); + } + + + void gui_CreateCitation(string const & s, LyXView & lv, Dialogs & d) + { + controlCitationSingleton.get(lv, d).createInset(s); + } + + + void gui_ShowDocument(LyXView & lv, Dialogs & d) + { + static FormDocument fd(&lv, &d); + fd.show(); + } + + + void gui_ShowError(InsetError * ie, LyXView & lv, Dialogs & d) + { + static GUI ce(lv, d); + ce.showInset(ie); + } + + + void gui_ShowERT(InsetERT * ie, LyXView & lv, Dialogs & d) + { + controlERTSingleton.get(lv, d).showInset(ie); + } + + + void gui_UpdateERT(InsetERT * ie, LyXView & lv, Dialogs & d) + { + controlERTSingleton.get(lv, d).showInset(ie); + } + + + void gui_ShowExternal(InsetExternal * ie, LyXView & lv, Dialogs & d) + { + static GUI ce(lv, d); + ce.showInset(ie); + } + + + void gui_ShowFile(string const & f, LyXView & lv, Dialogs & d) + { + static GUI csf(lv, d); + csf.showFile(f); + } + + + void gui_ShowFloat(InsetFloat * ifl, LyXView & lv, Dialogs & d) + { + static GUI cf(lv, d); + cf.showInset(ifl); + } + + + void gui_ShowForks(LyXView & lv, Dialogs & d) + { + static GUI cf(lv, d); + cf.show(); + } + + + void gui_ShowGraphics(InsetGraphics * ig, LyXView & lv, Dialogs & d) + { + static GUI cg(lv, d); + cg.showInset(ig); + } + + + void gui_ShowInclude(InsetInclude * ii, LyXView & lv, Dialogs & d) + { + static GUI ci(lv, d); + ci.showInset(ii); + } + + + void gui_ShowIndex(InsetCommand * ic, LyXView & lv, Dialogs & d) + { + controlIndexSingleton.get(lv, d).showInset(ic); + } + + + void gui_CreateIndex(string const & s, LyXView & lv, Dialogs & d) + { + controlIndexSingleton.get(lv, d).createInset(s); + } + + +#if 0 + void gui_ShowInfo(InsetInfo *, LyXView & lv, Dialogs & d) + { + } +#endif + + + void gui_ShowLogFile(LyXView & lv, Dialogs & d) + { + static GUI cl(lv, d); + cl.show(); + } + + + void gui_ShowMathPanel(LyXView & lv, Dialogs & d) + { + static FormMathsPanel fmp(&lv, &d); + fmp.show(); + } + + + void gui_ShowMinipage(InsetMinipage * im, LyXView & lv, Dialogs & d) + { + controlMinipageSingleton.get(lv, d).showInset(im); + } + + + void gui_UpdateMinipage(InsetMinipage * im, LyXView & lv, Dialogs & d) + { + controlMinipageSingleton.get(lv, d).showInset(im); + } + + + void gui_ShowParagraph(LyXView & lv, Dialogs & d) + { + static GUI cp(lv, d); + cp.show(); + } + + +#if 0 + void gui_UpdateParagraph(LyXView & lv, Dialogs & d) + { +#warning FIXME! + // This should be the same object as in gui_ShowParagraph + static GUI cp(lv, d); +#if 0 + cp. +#endif + } +#endif + + + void gui_ShowPreamble(LyXView & lv, Dialogs & d) + { + static GUI cp(lv, d); + cp.show(); + } + + + void gui_ShowPreferences(LyXView & lv, Dialogs & d) + { + formPreferencesSingleton.get(lv, d).show(); + } + + + void gui_ShowPrint(LyXView & lv, Dialogs & d) + { + static GUI cp(lv, d); + cp.show(); + } + + + void gui_ShowRef(InsetCommand * ic, LyXView & lv, Dialogs & d) + { + controlRefSingleton.get(lv, d).showInset(ic); + } + + + void gui_CreateRef(string const & s, LyXView & lv, Dialogs & d) + { + controlRefSingleton.get(lv, d).createInset(s); + } + + + void gui_ShowSearch(LyXView & lv, Dialogs & d) + { + static GUI cs(lv, d); + cs.show(); + } + + + void gui_ShowSendto(LyXView & lv, Dialogs & d) + { + static GUI cs(lv, d); + cs.show(); + } + + + void gui_ShowSpellchecker(LyXView & lv, Dialogs & d) + { + static GUI cp(lv, d); + cp.show(); + } + + + void gui_ShowSpellcheckerPreferences(LyXView & lv, Dialogs & d) + { + formPreferencesSingleton.get(lv, d).showSpellPref(); + } + + + void gui_ShowTabular(InsetTabular * it, LyXView & lv, Dialogs & d) + { + formTabularSingleton.get(lv, d).showInset(it); + } + + + void gui_UpdateTabular(InsetTabular * it, LyXView & lv, Dialogs & d) + { + formTabularSingleton.get(lv, d).updateInset(it); + } + + + void gui_ShowTabularCreate(LyXView & lv, Dialogs & d) + { + static GUI ctc(lv, d); + ctc.show(); + } + + + void gui_ShowTexinfo(LyXView & lv, Dialogs & d) + { + static GUI ct(lv, d); + ct.show(); + } + + + void gui_ShowThesaurus(string const & /*s*/, LyXView & , Dialogs &) + { +#ifdef HAVE_LIBAIKSAURUS + static GUI ct(lv, d); + ct.showEntry(s); +#endif + } + + + void gui_ShowTOC(InsetCommand * ic, LyXView & lv, Dialogs & d) + { + controlTocSingleton.get(lv, d).showInset(ic); + } + + + void gui_CreateTOC(string const & s, LyXView & lv, Dialogs & d) + { + controlTocSingleton.get(lv, d).createInset(s); + } + + + void gui_ShowUrl(InsetCommand * ic, LyXView & lv, Dialogs & d) + { + controlUrlSingleton.get(lv, d).showInset(ic); + } + + + void gui_CreateUrl(string const & s, LyXView & lv, Dialogs & d) + { + controlUrlSingleton.get(lv, d).createInset(s); + } + + + void gui_ShowVCLogFile(LyXView & lv, Dialogs & d) + { + static GUI cv(lv, d); + cv.show(); + } + +} // extern "C" diff --git a/src/frontends/xforms/xscreen.C b/src/frontends/xforms/xscreen.C new file mode 100644 index 0000000000..715b0f3d4a --- /dev/null +++ b/src/frontends/xforms/xscreen.C @@ -0,0 +1,260 @@ +/** + * \file xscreen.C + * Copyright 1995-2002 the LyX Team + * Read the file COPYING + * + * \author unknown + * \author John Levon + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include +#include + +#include "frontends/screen.h" +#include "frontends/font_metrics.h" +#include "XWorkArea.h" +#include "xscreen.h" +#include "lyxtext.h" +#include "lyxrow.h" +#include "Painter.h" +#include "WorkArea.h" +#include "buffer.h" +#include "BufferView.h" +#include "insets/insettext.h" +#include "ColorHandler.h" +#include "language.h" + +using std::max; +using std::min; + +namespace { + +GC createGC() +{ + XGCValues val; + 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_get_display(), RootWindow(fl_get_display(), 0), + GCForeground | GCFunction | GCGraphicsExposures + | GCLineWidth | GCLineStyle , &val); +} + +} // namespace anon + + +// Constructor +XScreen::XScreen(XWorkArea & o) + : LyXScreen(), owner_(o) +{ + // the cursor isnt yet visible + cursor_pixmap = 0; + cursor_pixmap_x = 0; + cursor_pixmap_y = 0; + cursor_pixmap_w = 0; + cursor_pixmap_h = 0; + + // We need this GC + gc_copy = createGC(); +} + + +XScreen::~XScreen() +{ + XFreeGC(fl_get_display(), gc_copy); +} + + +void XScreen::setCursorColor() +{ + if (!lyxColorHandler.get()) return; + + GC gc = lyxColorHandler->getGCForeground(LColor::cursor); + + XGCValues val; + XGetGCValues(fl_get_display(), + gc, GCForeground, &val); + XChangeGC(fl_get_display(), gc_copy, GCForeground, &val); +} + + +void XScreen::showManualCursor(LyXText const * text, int x, int y, + int asc, int desc, Cursor_Shape shape) +{ + // Update the cursor color. + setCursorColor(); + + int const y1 = max(y - text->first_y - asc, 0); + int const y_tmp = min(y - text->first_y + desc, + static_cast(owner_.workHeight())); + + // Secure against very strange situations + int const y2 = max(y_tmp, y1); + + if (cursor_pixmap) { + XFreePixmap(fl_get_display(), cursor_pixmap); + cursor_pixmap = 0; + } + + if (y2 > 0 && y1 < int(owner_.workHeight())) { + cursor_pixmap_h = y2 - y1 + 1; + cursor_pixmap_y = y1; + + switch (shape) { + case BAR_SHAPE: + cursor_pixmap_w = 1; + cursor_pixmap_x = x; + break; + case L_SHAPE: + cursor_pixmap_w = cursor_pixmap_h/3; + cursor_pixmap_x = x; + break; + case REVERSED_L_SHAPE: + cursor_pixmap_w = cursor_pixmap_h/3; + cursor_pixmap_x = x - cursor_pixmap_w + 1; + break; + } + + cursor_pixmap = + XCreatePixmap (fl_get_display(), + fl_root, + cursor_pixmap_w, + cursor_pixmap_h, + fl_get_visual_depth()); + XCopyArea (fl_get_display(), + owner_.getWin(), + cursor_pixmap, + gc_copy, + owner_.xpos() + cursor_pixmap_x, + owner_.ypos() + cursor_pixmap_y, + cursor_pixmap_w, + cursor_pixmap_h, + 0, 0); + XDrawLine(fl_get_display(), + owner_.getWin(), + gc_copy, + x + owner_.xpos(), + y1 + owner_.ypos(), + x + owner_.xpos(), + y2 + owner_.ypos()); + switch (shape) { + case BAR_SHAPE: + break; + case L_SHAPE: + case REVERSED_L_SHAPE: + int const rectangle_h = (cursor_pixmap_h + 10) / 20; + XFillRectangle(fl_get_display(), + owner_.getWin(), + gc_copy, + cursor_pixmap_x + owner_.xpos(), + y2 - rectangle_h + 1 + owner_.ypos(), + cursor_pixmap_w - 1, rectangle_h); + break; + } + + } + cursor_visible_ = true; +} + + +void XScreen::hideCursor() +{ + if (!cursor_visible_) return; + + if (cursor_pixmap) { + XCopyArea (fl_get_display(), + cursor_pixmap, + owner_.getWin(), + gc_copy, + 0, 0, + cursor_pixmap_w, cursor_pixmap_h, + cursor_pixmap_x + owner_.xpos(), + cursor_pixmap_y + owner_.ypos()); + } + cursor_visible_ = false; +} + + +void XScreen::expose(int x, int y, int exp_width, int exp_height) +{ + // FIXME: here we should definitely NOT do this. + // we need to generate an expose event for the workarea + // and then copy from the pixmap to the screen. This + // is the Sane Way (tm) + XCopyArea(fl_get_display(), + owner_.getPixmap(), + owner_.getWin(), + gc_copy, + x, y, + exp_width, exp_height, + x + owner_.xpos(), + y + owner_.ypos()); +} + + +void XScreen::draw(LyXText * text, BufferView * bv, unsigned int y) +{ + if (cursor_visible_) hideCursor(); + + int const old_first = text->first_y; + bool internal = (text == bv->text); + text->first_y = y; + + // is any optimization possible? + if ((y - old_first) < owner_.workHeight() + && (old_first - y) < owner_.workHeight()) + { + if (text->first_y < old_first) { + drawFromTo(text, bv, 0, + old_first - text->first_y, 0, 0, internal); + XCopyArea (fl_get_display(), + owner_.getWin(), + owner_.getWin(), + gc_copy, + owner_.xpos(), + owner_.ypos(), + owner_.workWidth(), + owner_.workHeight() - old_first + text->first_y, + owner_.xpos(), + owner_.ypos() + old_first - text->first_y + ); + // expose the area drawn + expose(0, 0, + owner_.workWidth(), + old_first - text->first_y); + } else { + drawFromTo(text, bv, + owner_.workHeight() + old_first - text->first_y, + owner_.workHeight(), 0, 0, internal); + XCopyArea (fl_get_display(), + owner_.getWin(), + owner_.getWin(), + gc_copy, + owner_.xpos(), + owner_.ypos() + text->first_y - old_first, + owner_.workWidth(), + owner_.workHeight() + old_first - text->first_y, + owner_.xpos(), + owner_.ypos()); + // expose the area drawn + expose(0, owner_.workHeight() + old_first - text->first_y, + owner_.workWidth(), text->first_y - old_first); + } + } else { + // make a dumb new-draw + drawFromTo(text, bv, 0, owner_.workHeight(), 0, 0, internal); + expose(0, 0, owner_.workWidth(), owner_.workHeight()); + } + + XSync(fl_get_display(), 0); +} diff --git a/src/frontends/xforms/xscreen.h b/src/frontends/xforms/xscreen.h new file mode 100644 index 0000000000..2fad257118 --- /dev/null +++ b/src/frontends/xforms/xscreen.h @@ -0,0 +1,75 @@ +// -*- C++ -*- +/** + * \file xscreen.h + * Copyright 1995-2002 the LyX Team + * Read the file COPYING + * + * \author unknown + * \author John Levon + */ + +#ifndef XSCREEN_H +#define XSCREEN_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include + +#include "screen.h" + +#include "XWorkArea.h" + +/** The class XScreen is used for the main Textbody. + Concretely, the screen is held in a pixmap. This pixmap is kept up to + date and used to optimize drawing on the screen. + This class also handles the drawing of the cursor and partly the selection. + */ +class XScreen : public LyXScreen { +public: + /// + XScreen(XWorkArea &); + + /// + virtual ~XScreen(); + + /// Sets the cursor color to LColor::cursor. + virtual void setCursorColor(); + /// + virtual void hideCursor(); + /// + virtual void showManualCursor(LyXText const *, int x, int y, + int asc, int desc, + Cursor_Shape shape); + + /** Draws the screen form textposition y. Uses as much of + the already printed pixmap as possible */ + virtual void draw(LyXText *, BufferView *, unsigned int y); + +protected: + /// get the work area + virtual WorkArea & workarea() const { return owner_; } + + /// Copies specified area of pixmap to screen + virtual void expose(int x, int y, int exp_width, int exp_height); + +private: + /// our owning widget + XWorkArea & owner_; + + /// + Pixmap cursor_pixmap; + /// + int cursor_pixmap_x; + /// + int cursor_pixmap_y; + /// + int cursor_pixmap_w; + /// + int cursor_pixmap_h; + /// + GC gc_copy; +}; + +#endif diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index b10409dfeb..6a1e3004e5 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2002-06-15 LyX Development team + + * inset*.[Ch] (docbook): Added new argument to take the pernicious + mixed content. Small white spaces clean. + 2002-06-14 Angus Leeming * inseetexternal.C: remove the using std::difftime declaration. diff --git a/src/insets/inset.h b/src/insets/inset.h index 3a54462dcf..d0f14006f0 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -194,7 +194,7 @@ public: /// virtual int linuxdoc(Buffer const *, std::ostream &) const = 0; /// - virtual int docbook(Buffer const *, std::ostream &) const = 0; + virtual int docbook(Buffer const *, std::ostream &, bool) const = 0; /// Updates needed features for this inset. virtual void validate(LaTeXFeatures & features) const; /// diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index f0417a212e..494d69bd01 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -120,11 +120,11 @@ int InsetCaption::ascii(Buffer const * /*buf*/, } -int InsetCaption::docbook(Buffer const * buf, ostream & os) const +int InsetCaption::docbook(Buffer const * buf, ostream & os, bool mixcont) const { int ret; os << ""; - ret = InsetText::docbook(buf, os); + ret = InsetText::docbook(buf, os, mixcont); os << "\n"; return ret; } diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index 35da0d33cd..b9705f0623 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -54,7 +54,7 @@ public: int ascii(Buffer const * buf, std::ostream & os, int linelen) const; /// virtual - int docbook(Buffer const * buf, std::ostream & os) const; + int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const; protected: private: }; diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 00b3e869ec..b66e5e5e44 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -392,9 +392,9 @@ int InsetCollapsable::linuxdoc(Buffer const * buf, ostream & os) const } -int InsetCollapsable::docbook(Buffer const * buf, ostream & os) const +int InsetCollapsable::docbook(Buffer const * buf, ostream & os, bool mixcont) const { - return inset.docbook(buf, os); + return inset.docbook(buf, os, mixcont); } #if 0 @@ -649,7 +649,8 @@ bool InsetCollapsable::searchForward(BufferView * bv, string const & str, bool found = inset.searchForward(bv, str, cs, mw); if (first_after_edit && !found) close(bv); - first_after_edit = false; + else if (!found) + first_after_edit = false; return found; } @@ -660,7 +661,8 @@ bool InsetCollapsable::searchBackward(BufferView * bv, string const & str, bool found = inset.searchBackward(bv, str, cs, mw); if (first_after_edit && !found) close(bv); - first_after_edit = false; + else if (!found) + first_after_edit = false; return found; } diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index d3dc3945ef..a86e00df5b 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -105,7 +105,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// void validate(LaTeXFeatures & features) const; /// diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index 6fe86786ab..dd1b3afac8 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -213,7 +213,7 @@ int InsetCommand::linuxdoc(Buffer const *, ostream &) const } -int InsetCommand::docbook(Buffer const *, ostream &) const +int InsetCommand::docbook(Buffer const *, ostream &, bool) const { return 0; } diff --git a/src/insets/insetcommand.h b/src/insets/insetcommand.h index d010017f5d..466bef87f6 100644 --- a/src/insets/insetcommand.h +++ b/src/insets/insetcommand.h @@ -97,7 +97,7 @@ public: /// virtual int linuxdoc(Buffer const *, std::ostream &) const; /// - virtual int docbook(Buffer const *, std::ostream &) const; + virtual int docbook(Buffer const *, std::ostream &, bool) const; /// Inset::Code lyxCode() const { return Inset::NO_CODE; } diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index f30b90a250..b7a8172141 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -52,7 +52,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const { return 0; } /// - int docbook(Buffer const *, std::ostream &) const { return 0; } + int docbook(Buffer const *, std::ostream &, bool) const { return 0; } /// bool autoDelete() const { return true; } /// what appears in the minibuffer when opening diff --git a/src/insets/insetert.C b/src/insets/insetert.C index 7bd9562879..cb009011b8 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -414,7 +414,7 @@ int InsetERT::linuxdoc(Buffer const *, ostream & os) const } -int InsetERT::docbook(Buffer const *, ostream & os) const +int InsetERT::docbook(Buffer const *, ostream & os, bool) const { Paragraph * par = inset.paragraph(); int lines = 0; diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 8aaf1310cc..4675049f8e 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -90,7 +90,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// void validate(LaTeXFeatures &) const {} /// diff --git a/src/insets/insetexternal.C b/src/insets/insetexternal.C index fdfe4a287b..cc66ca3b20 100644 --- a/src/insets/insetexternal.C +++ b/src/insets/insetexternal.C @@ -171,7 +171,7 @@ int InsetExternal::linuxdoc(Buffer const * buf, ostream & os) const } -int InsetExternal::docbook(Buffer const * buf, ostream & os) const +int InsetExternal::docbook(Buffer const * buf, ostream & os, bool) const { return write("DocBook", buf, os); } diff --git a/src/insets/insetexternal.h b/src/insets/insetexternal.h index c0a605b804..cc3376cc53 100644 --- a/src/insets/insetexternal.h +++ b/src/insets/insetexternal.h @@ -68,7 +68,7 @@ public: /// write LinuxDoc output to the ostream virtual int linuxdoc(Buffer const *, std::ostream &) const; /// write DocBook output to the ostream - virtual int docbook(Buffer const *, std::ostream &) const; + virtual int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// Updates needed features for this inset. virtual void validate(LaTeXFeatures & features) const; diff --git a/src/insets/insetfloat.C b/src/insets/insetfloat.C index cc733c4226..7882fe3348 100644 --- a/src/insets/insetfloat.C +++ b/src/insets/insetfloat.C @@ -259,10 +259,10 @@ int InsetFloat::latex(Buffer const * buf, } -int InsetFloat::docbook(Buffer const * buf, ostream & os) const +int InsetFloat::docbook(Buffer const * buf, ostream & os, bool mixcont) const { os << "<" << floatType_ << ">"; - int const i = inset.docbook(buf, os); + int const i = inset.docbook(buf, os, mixcont); os << ""; return i; diff --git a/src/insets/insetfloat.h b/src/insets/insetfloat.h index af3f724d50..81ab93538c 100644 --- a/src/insets/insetfloat.h +++ b/src/insets/insetfloat.h @@ -46,7 +46,7 @@ public: /// int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// string const editMessage() const; /// diff --git a/src/insets/insetfloatlist.h b/src/insets/insetfloatlist.h index 19b03e8dbe..fe10608006 100644 --- a/src/insets/insetfloatlist.h +++ b/src/insets/insetfloatlist.h @@ -51,7 +51,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const { return 0; } /// - int docbook(Buffer const *, std::ostream &) const { return 0; } + int docbook(Buffer const *, std::ostream &, bool mixcont) const { return 0; } /// int ascii(Buffer const *, std::ostream &, int linelen) const; /// diff --git a/src/insets/insetfoot.C b/src/insets/insetfoot.C index 28ee366ce0..91f45fb071 100644 --- a/src/insets/insetfoot.C +++ b/src/insets/insetfoot.C @@ -79,10 +79,10 @@ int InsetFoot::latex(Buffer const * buf, } -int InsetFoot::docbook(Buffer const * buf, ostream & os) const +int InsetFoot::docbook(Buffer const * buf, ostream & os, bool mixcont) const { os << ""; - int const i = inset.docbook(buf, os); + int const i = inset.docbook(buf, os, mixcont); os << ""; return i; diff --git a/src/insets/insetfoot.h b/src/insets/insetfoot.h index e20155a777..a5198f1f5e 100644 --- a/src/insets/insetfoot.h +++ b/src/insets/insetfoot.h @@ -37,7 +37,7 @@ public: /// int latex(Buffer const *, std::ostream &, bool fragile, bool fp) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// string const editMessage() const; }; diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 2f58bbe252..601d761736 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -810,7 +810,7 @@ int InsetGraphics::linuxdoc(Buffer const *, ostream &) const // For explanation on inserting graphics into DocBook checkout: // http://linuxdoc.org/LDP/LDP-Author-Guide/inserting-pictures.html // See also the docbook guide at http://www.docbook.org/ -int InsetGraphics::docbook(Buffer const *, ostream & os) const +int InsetGraphics::docbook(Buffer const *, ostream & os, bool mixcont) const { // In DocBook v5.0, the graphic tag will be eliminated from DocBook, will // need to switch to MediaObject. However, for now this is sufficient and diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index d3e04cf76b..7aa5967d37 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -70,7 +70,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /** Tell LyX what the latex features you need i.e. what latex packages you need to be included. diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 008d510e0d..844d6d3cad 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -342,7 +342,7 @@ int InsetInclude::linuxdoc(Buffer const * buffer, ostream & os) const } -int InsetInclude::docbook(Buffer const * buffer, ostream & os) const +int InsetInclude::docbook(Buffer const * buffer, ostream & os, bool mixcont) const { string incfile(params_.cparams.getContents()); diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 9aed79b72b..106765ed4e 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -99,7 +99,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// void validate(LaTeXFeatures &) const; diff --git a/src/insets/insetindex.C b/src/insets/insetindex.C index 1e5e2c6de3..3f66ba3509 100644 --- a/src/insets/insetindex.C +++ b/src/insets/insetindex.C @@ -37,7 +37,7 @@ void InsetIndex::edit(BufferView * bv, bool) } -int InsetIndex::docbook(Buffer const *, ostream & os) const +int InsetIndex::docbook(Buffer const *, ostream & os, bool) const { os << "" << getContents() << ""; diff --git a/src/insets/insetindex.h b/src/insets/insetindex.h index 32b0e2a905..dfd8304a68 100644 --- a/src/insets/insetindex.h +++ b/src/insets/insetindex.h @@ -41,7 +41,7 @@ public: /// Inset::Code lyxCode() const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; }; diff --git a/src/insets/insetlabel.C b/src/insets/insetlabel.C index f3126eaa38..9c0167f39f 100644 --- a/src/insets/insetlabel.C +++ b/src/insets/insetlabel.C @@ -95,7 +95,7 @@ int InsetLabel::linuxdoc(Buffer const *, ostream & os) const } -int InsetLabel::docbook(Buffer const *, ostream & os) const +int InsetLabel::docbook(Buffer const *, ostream & os, bool) const { os << ""; return 0; diff --git a/src/insets/insetlabel.h b/src/insets/insetlabel.h index 823bf73071..16b1e094ec 100644 --- a/src/insets/insetlabel.h +++ b/src/insets/insetlabel.h @@ -46,7 +46,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; }; #endif diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index 31834610a7..572538bdac 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -655,7 +655,7 @@ int InsetLatexAccent::linuxdoc(Buffer const *, ostream & os) const } -int InsetLatexAccent::docbook(Buffer const *, ostream & os) const +int InsetLatexAccent::docbook(Buffer const *, ostream & os, bool) const { os << contents; return 0; diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index a314e6500b..8e80c56e59 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -61,7 +61,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// bool deletable() const; /// diff --git a/src/insets/insetnote.h b/src/insets/insetnote.h index 2c20a8e899..ca75cade01 100644 --- a/src/insets/insetnote.h +++ b/src/insets/insetnote.h @@ -44,7 +44,7 @@ public: int linuxdoc(Buffer const *, std::ostream &) const { return 0; } /// - int docbook(Buffer const *, std::ostream &) const + int docbook(Buffer const *, std::ostream &, bool) const { return 0; } /// int ascii(Buffer const *, std::ostream &, int) const diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 051b12a791..ce24a655d7 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -325,7 +325,7 @@ int InsetQuotes::linuxdoc(Buffer const *, ostream & os) const } -int InsetQuotes::docbook(Buffer const *, ostream & os) const +int InsetQuotes::docbook(Buffer const *, ostream & os, bool) const { if (times_ == DoubleQ) { if (side_ == LeftQ) diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index 7fe44c0730..44a5565add 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -96,7 +96,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// void validate(LaTeXFeatures &) const; /// diff --git a/src/insets/insetref.C b/src/insets/insetref.C index 0f39f93b84..826de68400 100644 --- a/src/insets/insetref.C +++ b/src/insets/insetref.C @@ -85,7 +85,7 @@ int InsetRef::linuxdoc(Buffer const *, ostream & os) const } -int InsetRef::docbook(Buffer const *, ostream & os) const +int InsetRef::docbook(Buffer const *, ostream & os, bool) const { if (getOptions().empty()) { os << ""; diff --git a/src/insets/insetref.h b/src/insets/insetref.h index 45c09a2270..cbf6a6f5f1 100644 --- a/src/insets/insetref.h +++ b/src/insets/insetref.h @@ -63,7 +63,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// void validate(LaTeXFeatures & features) const; private: diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index 1d727042f9..0feb09eee1 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -287,7 +287,7 @@ int InsetSpecialChar::linuxdoc(Buffer const *, ostream & os) const } -int InsetSpecialChar::docbook(Buffer const *, ostream & os) const +int InsetSpecialChar::docbook(Buffer const *, ostream & os, bool) const { switch (kind_) { case HYPHENATION: diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index 1f0547d444..d8d00452b0 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -67,7 +67,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// virtual Inset * clone(Buffer const &, bool same_id = false) const; /// diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 194b18401a..39138732fe 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -146,7 +146,7 @@ InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns) clearSelection(); need_update = INIT; in_update = false; - in_reset_pos = false; + in_reset_pos = 0; inset_x = 0; inset_y = 0; } @@ -166,7 +166,7 @@ InsetTabular::InsetTabular(InsetTabular const & tab, Buffer const & buf, clearSelection(); need_update = INIT; in_update = false; - in_reset_pos = false; + in_reset_pos = 0; inset_x = 0; inset_y = 0; } @@ -603,6 +603,7 @@ void InsetTabular::insetUnlock(BufferView * bv) the_locking_inset = 0; } hideInsetCursor(bv); + actcell = 0; oldcell = -1; locked = false; if (scroll(false) || hasSelection()) { @@ -626,15 +627,10 @@ void InsetTabular::updateLocal(BufferView * bv, UpdateCodes what, what = FULL; if (need_update < what) // only set this if it has greater update need_update = what; -#if 0 // maybe this should not be done! - if ((what == INIT) && hasSelection()) { - clearSelection(); - } -#endif // Dirty Cast! (Lgb) if (need_update != NONE) { bv->updateInset(const_cast(this), mark_dirty); - if (locked) // && (what != NONE)) + if (locked) resetPos(bv); } } @@ -1317,7 +1313,7 @@ int InsetTabular::linuxdoc(Buffer const * buf, ostream & os) const } -int InsetTabular::docbook(Buffer const * buf, ostream & os) const +int InsetTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const { int ret = 0; Inset * master; @@ -1329,12 +1325,16 @@ int InsetTabular::docbook(Buffer const * buf, ostream & os) const master = master->owner()); if (!master) { - os << "\n"; + os << ""; + if (mixcont) + os << endl; ret++; } - ret+= tabular->docBook(buf,os); + ret+= tabular->docbook(buf, os, mixcont); if (!master) { - os << "\n"; + os << ""; + if (mixcont) + os << endl; ret++; } return ret; @@ -1526,7 +1526,7 @@ void InsetTabular::resetPos(BufferView * bv) const #warning This should be fixed in the right manner (20011128 Jug) #endif // fast hack to fix infinite repaintings! - if (in_reset_pos) + if (in_reset_pos > 10) return; int cell = 0; @@ -1547,7 +1547,7 @@ void InsetTabular::resetPos(BufferView * bv) const return; } // we need this only from here on!!! - in_reset_pos = true; + ++in_reset_pos; static int const offset = ADD_TO_TABULAR_WIDTH + 2; int new_x = getCellXPos(actcell); int old_x = cursor_.x(); @@ -1598,7 +1598,7 @@ void InsetTabular::resetPos(BufferView * bv) const bv->owner()->getDialogs()->updateTabular(inset); oldcell = actcell; } - in_reset_pos = false; + in_reset_pos = 0; } @@ -2738,56 +2738,45 @@ void InsetTabular::toggleSelection(BufferView * bv, bool kill_selection) bool InsetTabular::searchForward(BufferView * bv, string const & str, bool cs, bool mw) { - nodraw(true); if (the_locking_inset) { if (the_locking_inset->searchForward(bv, str, cs, mw)) { - nodraw(false); updateLocal(bv, CELL, false); return true; } - if (tabular->IsLastCell(actcell)) { - nodraw(false); - bv->unlockInset(const_cast(this)); - return false; + } + do { + InsetText * inset = tabular->GetCellInset(actcell); + if (inset->searchForward(bv, str, cs, mw)) { + updateLocal(bv, FULL, false); + return true; } ++actcell; - } - // otherwise we have to lock the next inset and search there - UpdatableInset * inset = - static_cast(tabular->GetCellInset(actcell)); - inset->edit(bv); - bool const ret = searchForward(bv, str, cs, mw); - nodraw(false); - updateLocal(bv, CELL, false); - return ret; + } while (!tabular->IsLastCell(actcell)); + return false; } bool InsetTabular::searchBackward(BufferView * bv, string const & str, bool cs, bool mw) { - nodraw(true); if (the_locking_inset) { if (the_locking_inset->searchBackward(bv, str, cs, mw)) { - nodraw(false); updateLocal(bv, CELL, false); return true; } - if (!actcell) { // we are already in the first cell - nodraw(false); - bv->unlockInset(const_cast(this)); - return false; - } + } + if (!locked) + actcell = tabular->GetNumberOfCells(); + + while (actcell) { --actcell; + InsetText * inset = tabular->GetCellInset(actcell); + if (inset->searchBackward(bv, str, cs, mw)) { + updateLocal(bv, CELL, false); + return true; + } } - // otherwise we have to lock the next inset and search there - UpdatableInset * inset = - static_cast(tabular->GetCellInset(actcell)); - inset->edit(bv, false); - bool const ret = searchBackward(bv, str, cs, mw); - nodraw(false); - updateLocal(bv, CELL, false); - return ret; + return false; } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 2d23930560..5014ab1641 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -147,7 +147,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// void validate(LaTeXFeatures & features) const; /// @@ -352,6 +352,6 @@ private: /// bool in_update; /// - mutable bool in_reset_pos; + mutable int in_reset_pos; }; #endif diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 636f981dae..a3ed108ea8 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -1212,19 +1212,26 @@ InsetText::localDispatch(BufferView * bv, } break; case FINISHED_DOWN: - if ((result = moveDown(bv)) >= FINISHED) { + { + LyXText *lt = getLyXText(bv); + if (lt->cursor.irow()->next()) { + lt->setCursorFromCoordinates( + bv, lt->cursor.ix() + inset_x, + lt->cursor.iy() - + lt->cursor.irow()->baseline() + + lt->cursor.irow()->height() + 1); + lt->cursor.x_fix(lt->cursor.x()); updateLocal(bv, CURSOR, false); + } else { bv->unlockInset(this); } + } break; default: result = DISPATCHED; break; } the_locking_inset = 0; -#ifdef WITH_WARNINGS -#warning I changed this to always return Dispatched maybe it is wrong (20011001 Jug) -#endif updateLocal(bv, CURSOR, false); return result; } @@ -1261,7 +1268,8 @@ InsetText::localDispatch(BufferView * bv, } lt->clearSelection(); for (string::size_type i = 0; i < arg.length(); ++i) { - bv->owner()->getIntl()->getTrans().TranslateAndInsert(arg[i], lt); + bv->owner()->getIntl()->getTransManager(). + TranslateAndInsert(arg[i], lt); } } lt->selection.cursor = lt->cursor; @@ -1568,7 +1576,7 @@ int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const } -int InsetText::docbook(Buffer const * buf, ostream & os) const +int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const { Paragraph * p = par; unsigned int lines = 0; @@ -1592,14 +1600,11 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const for (; depth > p->params().depth(); --depth) { if (environment_inner[depth] != "!-- --") { item_name = "listitem"; - buf->sgmlCloseTag(os, command_depth + depth, - item_name); + lines += buf->sgmlCloseTag(os, command_depth + depth, mixcont, item_name); if (environment_inner[depth] == "varlistentry") - buf->sgmlCloseTag(os, depth+command_depth, - environment_inner[depth]); + lines += buf->sgmlCloseTag(os, depth+command_depth, mixcont, environment_inner[depth]); } - buf->sgmlCloseTag(os, depth + command_depth, - environment_stack[depth]); + lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_stack[depth]); environment_stack[depth].erase(); environment_inner[depth].erase(); } @@ -1609,16 +1614,12 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const && !environment_stack[depth].empty()) { if (environment_inner[depth] != "!-- --") { item_name= "listitem"; - buf->sgmlCloseTag(os, command_depth+depth, - item_name); + lines += buf->sgmlCloseTag(os, command_depth+depth, mixcont, item_name); if (environment_inner[depth] == "varlistentry") - buf->sgmlCloseTag(os, - depth + command_depth, - environment_inner[depth]); + lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_inner[depth]); } - buf->sgmlCloseTag(os, depth + command_depth, - environment_stack[depth]); + lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_stack[depth]); environment_stack[depth].erase(); environment_inner[depth].erase(); @@ -1627,13 +1628,11 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const // Write opening SGML tags. switch (style.latextype) { case LATEX_PARAGRAPH: - buf->sgmlOpenTag(os, depth + command_depth, - style.latexname()); + lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, style.latexname()); break; case LATEX_COMMAND: - buf->sgmlError(p, 0, - _("Error : LatexType Command not allowed here.\n")); + buf->sgmlError(p, 0, _("Error : LatexType Command not allowed here.\n")); return -1; break; @@ -1651,18 +1650,13 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const } environment_stack[depth] = style.latexname(); environment_inner[depth] = "!-- --"; - buf->sgmlOpenTag(os, depth + command_depth, - environment_stack[depth]); + lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, environment_stack[depth]); } else { if (environment_inner[depth] != "!-- --") { item_name= "listitem"; - buf->sgmlCloseTag(os, - command_depth + depth, - item_name); + lines += buf->sgmlCloseTag(os, command_depth + depth, mixcont, item_name); if (environment_inner[depth] == "varlistentry") - buf->sgmlCloseTag(os, - depth + command_depth, - environment_inner[depth]); + lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_inner[depth]); } } @@ -1671,40 +1665,26 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const if (style.latexparam() == "CDATA") os << "sgmlOpenTag(os, depth + command_depth, - style.latexparam()); + lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, style.latexparam()); } break; } desc_on = (style.labeltype == LABEL_MANUAL); - if (desc_on) - environment_inner[depth]= "varlistentry"; - else - environment_inner[depth]= "listitem"; + environment_inner[depth] = desc_on?"varlistentry":"listitem"; + lines += buf->sgmlOpenTag(os, depth + 1 + command_depth, mixcont, environment_inner[depth]); - buf->sgmlOpenTag(os, depth + 1 + command_depth, - environment_inner[depth]); + item_name = desc_on?"term":"para"; + lines += buf->sgmlOpenTag(os, depth + 1 + command_depth, mixcont, item_name); - if (desc_on) { - item_name= "term"; - buf->sgmlOpenTag(os, depth + 1 + command_depth, - item_name); - } else { - item_name= "para"; - buf->sgmlOpenTag(os, depth + 1 + command_depth, - item_name); - } break; default: - buf->sgmlOpenTag(os, depth + command_depth, - style.latexname()); + lines += buf->sgmlOpenTag(os, depth + command_depth, mixcont, style.latexname()); break; } - buf->simpleDocBookOnePar(os, p, desc_on, - depth + 1 + command_depth); + buf->simpleDocBookOnePar(os, p, desc_on, depth + 1 + command_depth); p = p->next(); string end_tag; @@ -1715,20 +1695,19 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const if (style.latexparam() == "CDATA") os << "]]>"; else - buf->sgmlCloseTag(os, depth + command_depth, - style.latexparam()); + lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, style.latexparam()); } break; case LATEX_ITEM_ENVIRONMENT: if (desc_on == 1) break; end_tag= "para"; - buf->sgmlCloseTag(os, depth + 1 + command_depth, end_tag); + lines += buf->sgmlCloseTag(os, depth + 1 + command_depth, mixcont, end_tag); break; case LATEX_PARAGRAPH: - buf->sgmlCloseTag(os, depth + command_depth, style.latexname()); + lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, style.latexname()); break; default: - buf->sgmlCloseTag(os, depth + command_depth, style.latexname()); + lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, style.latexname()); break; } } @@ -1738,15 +1717,12 @@ int InsetText::docbook(Buffer const * buf, ostream & os) const if (!environment_stack[depth].empty()) { if (environment_inner[depth] != "!-- --") { item_name = "listitem"; - buf->sgmlCloseTag(os, command_depth + depth, - item_name); + lines += buf->sgmlCloseTag(os, command_depth + depth, mixcont, item_name); if (environment_inner[depth] == "varlistentry") - buf->sgmlCloseTag(os, depth + command_depth, - environment_inner[depth]); + lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_inner[depth]); } - buf->sgmlCloseTag(os, depth + command_depth, - environment_stack[depth]); + lines += buf->sgmlCloseTag(os, depth + command_depth, mixcont, environment_stack[depth]); } } @@ -2682,53 +2658,66 @@ void InsetText::toggleSelection(BufferView * bv, bool kill_selection) bool InsetText::searchForward(BufferView * bv, string const & str, bool cs, bool mw) { + bool clear = false; + if (!lt) { + lt = getLyXText(bv); + clear = true; + } if (the_locking_inset) { if (the_locking_inset->searchForward(bv, str, cs, mw)) return true; - bool clear = false; - if (!lt) { - lt = getLyXText(bv); - clear = true; - } - Paragraph * lpar = lt->cursor.par(); - pos_type pos = lt->cursor.pos(); - if (pos < lpar->size() - 1) - ++pos; - else { - pos = 0; - lpar = lpar->next(); - } - if (!lpar) { - if (clear) - lt = 0; - // we have to unlock ourself in this function by default! - bv->unlockInset(const_cast(this)); - return false; - } - lt->setCursor(bv, lpar, pos); - if (clear) - lt = 0; - } - if (LyXFind(bv, str, true, true, cs , mw)) { - return true; + lt->cursorRight(bv, true); + } + lyxfind::SearchResult result = + lyxfind::LyXFind(bv, lt, str, true, cs, mw); + + if (result == lyxfind::SR_FOUND) { + LyXCursor cur = lt->cursor; + bv->unlockInset(bv->theLockingInset()); + if (bv->lockInset(this)) + locked = true; + lt->cursor = cur; + lt->setSelectionOverString(bv, str); + updateLocal(bv, SELECTION, false); } - // we have to unlock ourself in this function by default! - bv->unlockInset(const_cast(this)); - return false; + if (clear) + lt = 0; + return (result != lyxfind::SR_NOT_FOUND); } bool InsetText::searchBackward(BufferView * bv, string const & str, bool cs, bool mw) { - if (the_locking_inset) + if (the_locking_inset) { if (the_locking_inset->searchBackward(bv, str, cs, mw)) return true; - if (LyXFind(bv, str, false, true, cs, mw)) { - return true; } - // we have to unlock ourself in this function by default! - bv->unlockInset(const_cast(this)); - return false; + bool clear = false; + if (!lt) { + lt = getLyXText(bv); + clear = true; + } + if (!locked) { + Paragraph * p = par; + while (p->next()) + p = p->next(); + lt->setCursor(bv, p, p->size()); + } + lyxfind::SearchResult result = + lyxfind::LyXFind(bv, lt, str, false, cs, mw); + + if (result == lyxfind::SR_FOUND) { + LyXCursor cur = lt->cursor; + bv->unlockInset(bv->theLockingInset()); + if (bv->lockInset(this)) + locked = true; + lt->cursor = cur; + lt->setSelectionOverString(bv, str); + updateLocal(bv, SELECTION, false); + } + if (clear) + lt = 0; + return (result != lyxfind::SR_NOT_FOUND); } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 9655cec4b7..fefd364ff8 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -139,7 +139,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const { return 0; } /// - int docbook(Buffer const *, std::ostream &) const ; + int docbook(Buffer const *, std::ostream &, bool mixcont) const ; /// void validate(LaTeXFeatures & features) const; /// diff --git a/src/insets/insettoc.C b/src/insets/insettoc.C index b2385abd8b..77153639fe 100644 --- a/src/insets/insettoc.C +++ b/src/insets/insettoc.C @@ -80,7 +80,7 @@ int InsetTOC::linuxdoc(Buffer const *, ostream & os) const } -int InsetTOC::docbook(Buffer const *, ostream & os) const +int InsetTOC::docbook(Buffer const *, ostream & os, bool) const { if (getCmdName() == "tableofcontents") os << ""; diff --git a/src/insets/insettoc.h b/src/insets/insettoc.h index 26d75935a3..6b8d542c5a 100644 --- a/src/insets/insettoc.h +++ b/src/insets/insettoc.h @@ -46,7 +46,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; }; #endif diff --git a/src/insets/inseturl.C b/src/insets/inseturl.C index 4a61ad8593..f214d7c904 100644 --- a/src/insets/inseturl.C +++ b/src/insets/inseturl.C @@ -82,7 +82,7 @@ int InsetUrl::linuxdoc(Buffer const *, ostream & os) const } -int InsetUrl::docbook(Buffer const *, ostream & os) const +int InsetUrl::docbook(Buffer const *, ostream & os, bool) const { os << "" << getOptions() << ""; diff --git a/src/insets/inseturl.h b/src/insets/inseturl.h index f99d63244e..e6f4331025 100644 --- a/src/insets/inseturl.h +++ b/src/insets/inseturl.h @@ -52,7 +52,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; }; #endif diff --git a/src/intl.h b/src/intl.h index e2dfad5922..0e27b76d99 100644 --- a/src/intl.h +++ b/src/intl.h @@ -50,7 +50,7 @@ public: void InitKeyMapper(bool on); // Get the Translation Manager - TransManager & getTrans(); + TransManager & getTransManager(); /// using primary or secondary keymap ? Keymap keymap; @@ -68,7 +68,7 @@ private: inline -TransManager & Intl::getTrans() +TransManager & Intl::getTransManager() { return trans; } diff --git a/src/kbmap.C b/src/kbmap.C index 8849e36ed0..ee1e298527 100644 --- a/src/kbmap.C +++ b/src/kbmap.C @@ -18,56 +18,22 @@ #include "kbsequence.h" #include "debug.h" -#include - using std::endl; -// The only modifiers that we handle. We want to throw away things -// like NumLock. -enum { ModsMask = ShiftMask | ControlMask | Mod1Mask }; - - -string const kb_keymap::printKeysym(unsigned int key, key_modifier::state mod) +string const kb_keymap::printKeysym(LyXKeySymPtr key, + key_modifier::state mod) { string buf; - char const * const s = XKeysymToString(key); + string const s = key->getSymbolName(); if (mod & key_modifier::shift) buf += "S-"; if (mod & key_modifier::ctrl) buf += "C-"; if (mod & key_modifier::alt) buf += "M-"; - if (s) buf += s; + buf += s; return buf; } - -char kb_keymap::getiso(unsigned int c) -{ - switch (c & 0x0000FF00) { - // latin 1 byte 3 = 0 - case 0x00000000: break; - // latin 2 byte 3 = 1 - case 0x00000100: - // latin 3 byte 3 = 2 - case 0x00000200: - // latin 4 byte 3 = 3 - case 0x00000300: - // cyrillic KOI8 & Co - case 0x00000600: - // greek - case 0x00000700: - // latin 8 byte 3 = 18 (0x12) - case 0x00001200: - // latin 9 byte 3 = 19 (0x13) - case 0x00001300: - c &= 0x000000FF; - break; - default: - c = 0; - } - return c; -} - string const kb_keymap::printKey(kb_key const & key) const { return printKeysym(key.code, key.mod.first); @@ -97,7 +63,7 @@ string::size_type kb_keymap::bind(string const & seq, int action) } -int kb_keymap::lookup(unsigned int key, +int kb_keymap::lookup(LyXKeySymPtr key, key_modifier::state mod, kb_sequence * seq) const { if (table.empty()) { @@ -112,7 +78,7 @@ int kb_keymap::lookup(unsigned int key, key_modifier::state check = static_cast(mod & ~mask); - if (cit->code == key && cit->mod.first == check) { + if (*(cit->code) == *(key) && cit->mod.first == check) { // match found if (cit->table.get()) { // this is a prefix key - set new map @@ -148,15 +114,17 @@ string const kb_keymap::print() const void kb_keymap::defkey(kb_sequence * seq, int action, unsigned int r) { - unsigned int const code = seq->sequence[r]; - if (code == NoSymbol) return; + LyXKeySymPtr code = seq->sequence[r]; + if ( ! code->isOK() ) return; key_modifier::state const mod1 = seq->modifiers[r].first; key_modifier::state const mod2 = seq->modifiers[r].second; // check if key is already there for (Table::iterator it = table.begin(); it != table.end(); ++it) { - if (code == it->code && mod1 == it->mod.first && mod2 == it->mod.second) { + if (*(code) == *(it->code) + && mod1 == it->mod.first + && mod2 == it->mod.second) { // overwrite binding if (r + 1 == seq->length()) { lyxerr[Debug::KBMAP] diff --git a/src/kbmap.h b/src/kbmap.h index 390d63c205..482ab6c10d 100644 --- a/src/kbmap.h +++ b/src/kbmap.h @@ -17,8 +17,7 @@ #include "LString.h" #include "frontends/key_state.h" - -#include +#include "frontends/LyXKeySym.h" #include @@ -31,6 +30,7 @@ public: * Bind a key sequence to an action. * @return 0 on success, or position in string seq where error * occurs. + * See kb_sequence::parse for the syntax of the seq string */ string::size_type bind(string const & seq, int action); @@ -44,7 +44,7 @@ public: * @param seq the current key sequence so far * @return the action / LFUN_PREFIX / LFUN_UNKNOWN_ACTION */ - int lookup(unsigned int key, + int lookup(LyXKeySymPtr key, key_modifier::state mod, kb_sequence * seq) const; /// Given an action, find all keybindings. @@ -53,13 +53,11 @@ public: /** * Returns a string of the given keysym, with modifiers. - * @param key the key + * @param key the key as a keysym * @param mod the modifiers */ - static string const printKeysym(unsigned int key, key_modifier::state mod); - - /// return the ISO value of a keysym - static char getiso(unsigned int i); + static string const printKeysym(LyXKeySymPtr key, + key_modifier::state mod); typedef std::pair modifier_pair; @@ -67,7 +65,7 @@ private: /// struct kb_key { /// Keysym - unsigned int code; + LyXKeySymPtr code; /// Modifier masks modifier_pair mod; @@ -79,7 +77,6 @@ private: int action; }; - /** * Define an action for a key sequence. * @param r internal recursion level diff --git a/src/kbsequence.C b/src/kbsequence.C index b3865a1a65..cdffe37a66 100644 --- a/src/kbsequence.C +++ b/src/kbsequence.C @@ -15,13 +15,12 @@ #endif #include "frontends/mouse_state.h" +#include "frontends/LyXKeySymFactory.h" #include "kbsequence.h" #include "kbmap.h" #include "commandtags.h" #include "debug.h" -#include - using std::make_pair; using std::vector; using std::endl; @@ -29,25 +28,20 @@ using std::hex; using std::dec; -// The only modifiers that we handle. We want to throw away things -// like NumLock. -enum { ModsMask = ShiftMask | ControlMask | Mod1Mask }; - -int kb_sequence::addkey(unsigned int key, key_modifier::state mod, key_modifier::state nmod) +int kb_sequence::addkey(LyXKeySymPtr key, + key_modifier::state mod, key_modifier::state nmod) { // adding a key to a deleted sequence // starts a new sequence if (deleted_) { deleted_ = false; - length_ = 0; sequence.clear(); modifiers.clear(); } modifiers.push_back(make_pair(mod, nmod)); sequence.push_back(key); - ++length_; if (curmap) { return curmap->lookup(key, mod, this); @@ -112,13 +106,13 @@ string::size_type kb_sequence::parse(string const & s) for (; j < s.length() && s[j] != ' '; ++j) tbuf += s[j]; // (!!!check bounds :-) - KeySym key = XStringToKeysym(tbuf.c_str()); - if (key == NoSymbol) { - lyxerr[Debug::KBMAP] - << "kbmap.C: No such keysym: " - << tbuf << endl; + LyXKeySymPtr key(LyXKeySymFactory::create()); + key->init(tbuf); + + if ( ! key->isOK() ) { return j; } + i = j; addkey(key, mod, nmod); @@ -127,7 +121,7 @@ string::size_type kb_sequence::parse(string const & s) } // empty sequence? - if (!length_) + if (sequence.size() == 0) return 0; // everything is fine @@ -142,11 +136,13 @@ string const kb_sequence::print() const //if (deleted_) // return buf; - for (vector::size_type i = 0; i < length_; ++i) { + KeySequence::size_type i, length = sequence.size(); + + for (i = 0; i < length; ++i) { buf += kb_keymap::printKeysym(sequence[i], modifiers[i].first); // append a blank - if (i + 1 < length_) { + if (i + 1 < length) { buf += ' '; } } @@ -175,23 +171,17 @@ void kb_sequence::mark_deleted() } -unsigned int kb_sequence::getsym() const +LyXKeySymPtr kb_sequence::getsym() const { - if (length_ == 0) return NoSymbol; - return sequence[length_ - 1]; + if (sequence.size() == 0) + return LyXKeySymPtr(LyXKeySymFactory::create()); + return sequence.back(); } -char kb_sequence::getiso() const +char kb_sequence::getLastKeyEncoded() const { - unsigned int const c = getsym(); - - lyxerr[Debug::KBMAP] << "Raw keysym: " - << hex << c << dec << endl; - lyxerr[Debug::KBMAP] << "byte 3: " - << hex << (c & 0xff00) << dec - << endl; - return kb_keymap::getiso(c); + return getsym()->getISOEncoded(); } @@ -203,6 +193,6 @@ void kb_sequence::reset() void kb_sequence::clear() { - length_ = 0; + sequence.clear(); reset(); } diff --git a/src/kbsequence.h b/src/kbsequence.h index 46cda83795..918d29fac2 100644 --- a/src/kbsequence.h +++ b/src/kbsequence.h @@ -15,8 +15,8 @@ #include #include "frontends/key_state.h" +#include "frontends/LyXKeySym.h" #include "LString.h" - #include class kb_keymap; @@ -24,32 +24,35 @@ class kb_keymap; /// Holds a key sequence and the current and standard keymaps class kb_sequence { public: + typedef std::vector KeySequence; + friend class kb_keymap; /// kb_sequence(kb_keymap * std, kb_keymap * cur) - : stdmap(std), curmap(cur), length_(0), deleted_(false) {} - - + : stdmap(std), curmap(cur), deleted_(false) {} /** * Add a key to the key sequence and look it up in the curmap * if the latter is defined. - * @param text the text from the key event + * @param keysym the key to add * @param mod modifier mask * @param nmod which modifiers to mask out for equality test * @return the action matching this key sequence or LFUN_UNKNOWN_ACTION */ - int addkey(unsigned int text, key_modifier::state mod, - key_modifier::state nmod = key_modifier::none); + int addkey(LyXKeySymPtr keysym, key_modifier::state mod, + key_modifier::state nmod = key_modifier::none); /** * Add a sequence of keys from a string to the sequence * @return string::npos if OK, else error position in string * * Keys in the string must be separated with whitespace; - * Use the keysym names used by XStringToKeysym + * Use the keysym names used by XStringToKeysym, f.ex. + * "Space", "a", "Return", ... * Prefixes are S-, C-, M- for shift, control, meta + * Prefixes can also be ignored by using the Tilde "~" + * f.ex.: "~S-Space". */ string::size_type parse(string const & s); @@ -68,8 +71,12 @@ public: /// Mark the sequence as deleted. void mark_deleted(); - /// Return the ISO value of the last keysym in sequence, or 0 - char getiso() const; + /** + * Return the value of the last keysym in the sequence + * in the local ISO encoding. If it does not encode + * in this encoding, return 0. + */ + char getLastKeyEncoded() const; /// Reset sequence to become "deleted" void reset(); @@ -82,8 +89,8 @@ public: } /// length of sequence - std::vector::size_type length() const { - return length_; + KeySequence::size_type length() const { + return sequence.size(); } /// Keymap to use if a new sequence is starting @@ -94,21 +101,20 @@ public: private: /// get the keysym of last in sequence - unsigned int getsym() const; + LyXKeySymPtr getsym() const; /** - * Array holding the current key sequence. + * Array holding the current key sequence as KeySyms. * If sequence[length-1] < 0xff it can be used as ISO8859 char */ - std::vector sequence; + KeySequence sequence; + + typedef std::pair + modifier_pair; - typedef std::pair modifier_pair; /// modifiers for keys in the sequence std::vector modifiers; - /// Current length of key sequence - std::vector::size_type length_; - /// is keysequence deleted ? bool deleted_; }; diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 51bb428061..2e29832717 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -28,7 +28,6 @@ #include "frontends/Alert.h" #include "frontends/FileDialog.h" -#include #include "support/FileInfo.h" #include "support/filetools.h" diff --git a/src/lyxfind.C b/src/lyxfind.C index 72784eff1a..039d34985d 100644 --- a/src/lyxfind.C +++ b/src/lyxfind.C @@ -17,19 +17,7 @@ using lyx::pos_type; - -/// -// locally used enum -/// -enum SearchResult { - // - SR_NOT_FOUND = 0, - // - SR_FOUND, - // - SR_FOUND_NOUPDATE -}; - +namespace lyxfind { /// returns true if the specified string is at the specified position bool IsStringInText(Paragraph * par, pos_type pos, @@ -43,7 +31,6 @@ SearchResult SearchForward(BufferView *, LyXText * text, string const & str, SearchResult SearchBackward(BufferView *, LyXText * text, string const & str, bool const & = true, bool const & = false); - int LyXReplace(BufferView * bv, string const & searchstr, string const & replacestr, bool forward, bool casesens, bool matchwrd, bool replaceall, @@ -62,17 +49,14 @@ int LyXReplace(BufferView * bv, return 0; } - LyXText * text = bv->getLyXText(); - // now we can start searching for the first // start at top if replaceall + LyXText * text = bv->getLyXText(); bool fw = forward; if (replaceall) { text->clearSelection(); - if (text->inset_owner) { - bv->unlockInset(bv->theLockingInset()); - text = bv->text; - } + bv->unlockInset(bv->theLockingInset()); + text = bv->text; text->cursorTop(bv); // override search direction because we search top to bottom fw = true; @@ -90,7 +74,7 @@ int LyXReplace(BufferView * bv, str2 = lowercase(text->selectionAsString(bv->buffer(), false)); } if (str1 != str2) { - if (!LyXFind(bv, searchstr, fw, false, casesens, matchwrd) || + if (!LyXFind(bv, searchstr, fw, casesens, matchwrd) || !replaceall) { return 0; @@ -100,15 +84,16 @@ int LyXReplace(BufferView * bv, bool found = false; int replace_count = 0; do { + text = bv->getLyXText(); bv->hideCursor(); - bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR); + bv->update(text, BufferView::SELECT|BufferView::FITCUR); bv->toggleSelection(false); - bv->getLyXText()->replaceSelectionWithString(bv, replacestr); - bv->getLyXText()->setSelectionOverString(bv, replacestr); - bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + text->replaceSelectionWithString(bv, replacestr); + text->setSelectionOverString(bv, replacestr); + bv->update(text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); ++replace_count; if (!once) - found = LyXFind(bv, searchstr, fw, false, casesens, matchwrd); + found = LyXFind(bv, searchstr, fw, casesens, matchwrd); } while (!once && replaceall && found); if (bv->focus()) @@ -119,75 +104,83 @@ int LyXReplace(BufferView * bv, bool LyXFind(BufferView * bv, string const & searchstr, bool forward, - bool frominset, bool casesens, bool matchwrd) + bool casesens, bool matchwrd) { if (!bv->available() || searchstr.empty()) return false; - LyXText * text = bv->getLyXText(); - bv->hideCursor(); - bv->update(text, BufferView::SELECT|BufferView::FITCUR); - - if (text->selection.set()) - text->cursor = forward ? - text->selection.end : text->selection.start; + bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR); - SearchResult result = SR_NOT_FOUND; - - if (!frominset && bv->theLockingInset()) { + if (bv->theLockingInset()) { bool found = forward ? bv->theLockingInset()->searchForward(bv, searchstr, casesens, matchwrd) : bv->theLockingInset()->searchBackward(bv, searchstr, casesens, matchwrd); + // We found the stuff inside the inset so we don't have to + // do anything as the inset did all the update for us! if (found) - result = SR_FOUND_NOUPDATE; - else { - text = bv->getLyXText(); - Paragraph * par = text->cursor.par(); - pos_type pos = text->cursor.pos(); - if (forward) { - if (pos < par->size() - 1) - ++pos; - else { - pos = 0; - par = par->next(); - } - if (par) - text->setCursor(bv, par, pos); - } - if (par) { - result = forward ? - SearchForward(bv, text, searchstr, casesens, matchwrd) : - SearchBackward(bv, text, searchstr, casesens, matchwrd); - } + return true; + // We now are in the main text but if we did a forward + // search we have to put the cursor behind the inset. + if (forward) { + bv->text->cursorRight(bv, true); } - } else { - result = forward ? - SearchForward(bv, text, searchstr, casesens, matchwrd) : - SearchBackward(bv, text, searchstr, casesens, matchwrd); } + // If we arrive here we are in the main text again so we + // just start searching from the root LyXText at the position + // we are! + LyXText * text = bv->text; + + if (text->selection.set()) + text->cursor = forward ? + text->selection.end : text->selection.start; + + bv->toggleSelection(); + text->clearSelection(); + + SearchResult result = forward ? + SearchForward(bv, text, searchstr, casesens, matchwrd) : + SearchBackward(bv, text, searchstr, casesens, matchwrd); bool found = true; + // If we found the cursor inside an inset we will get back + // SR_FOUND_NOUPDATE and we don't have to do anything as the + // inset did it already. if (result == SR_FOUND) { - // the actual text pointer could have changed! - bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR); - bv->toggleSelection(); - bv->getLyXText()->clearSelection(); - bv->getLyXText()->setSelectionOverString(bv, searchstr); + bv->unlockInset(bv->theLockingInset()); + bv->update(text, BufferView::SELECT|BufferView::FITCUR); + text->setSelectionOverString(bv, searchstr); bv->toggleSelection(false); - bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR); + bv->update(text, BufferView::SELECT|BufferView::FITCUR); } else if (result == SR_NOT_FOUND) { - bv->toggleSelection(); - bv->getLyXText()->clearSelection(); - bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR); + bv->unlockInset(bv->theLockingInset()); + bv->update(text, BufferView::SELECT|BufferView::FITCUR); found = false; } - if (bv->focus()) + if (result != SR_FOUND_NOUPDATE && bv->focus()) bv->showCursor(); return found; } +SearchResult LyXFind(BufferView * bv, LyXText * text, + string const & searchstr, bool forward, + bool casesens, bool matchwrd) +{ + if (text->selection.set()) + text->cursor = forward ? + text->selection.end : text->selection.start; + + bv->toggleSelection(); + text->clearSelection(); + + SearchResult result = forward ? + SearchForward(bv, text, searchstr, casesens, matchwrd) : + SearchBackward(bv, text, searchstr, casesens, matchwrd); + + return result; +} + // returns true if the specified string is at the specified position bool IsStringInText(Paragraph * par, pos_type pos, @@ -235,12 +228,13 @@ SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str, (inset = (UpdatableInset *)par->getInset(pos)) && (inset->isTextInset())) { +#if 0 // lock the inset! text->setCursor(bv, par, pos); inset->edit(bv); +#endif if (inset->searchForward(bv, str, cs, mw)) return SR_FOUND_NOUPDATE; - text = bv->getLyXText(); } ++pos; @@ -292,12 +286,13 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text, (inset = (UpdatableInset *)par->getInset(pos)) && (inset->isTextInset())) { +#if 0 // lock the inset! text->setCursor(bv, par, pos); inset->edit(bv, false); +#endif if (inset->searchBackward(bv, str, cs, mw)) return SR_FOUND_NOUPDATE; - text = bv->getLyXText(); } } while (par && !IsStringInText(par, pos, str, cs, mw)); @@ -310,3 +305,5 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text, return SR_NOT_FOUND; } } + +} // end lyxfind namespace diff --git a/src/lyxfind.h b/src/lyxfind.h index 2e74dc3361..4a211e1be4 100644 --- a/src/lyxfind.h +++ b/src/lyxfind.h @@ -11,13 +11,43 @@ class BufferView; -int LyXReplace(BufferView * bv, string const &, string const &, +namespace lyxfind { + +enum SearchResult { + // + SR_NOT_FOUND = 0, + // + SR_FOUND, + // + SR_FOUND_NOUPDATE +}; + + +int LyXReplace(BufferView * bv, + string const &, string const &, bool, bool = true, bool = false, bool = false, bool = false); +/** + * This function is called as a general interface to find some + * text from the actual cursor position in whatever direction + * we want to go. This does also update the screen. + */ bool LyXFind(BufferView *, string const & searchstr, bool forward, - bool frominset = false, bool casesens = true, - bool matchwrd = false); + bool casesens = true, bool matchwrd = false); + +/** + * This function does search from the cursor position inside the + * passed LyXText parameter and regards this LyXText as the root + * LyXText. It will NOT update any screen stuff. It will however + * set the cursor to the new position inside LyXText, before + * returning to the calling function. + */ + +SearchResult LyXFind(BufferView *, LyXText * text, + string const & searchstr, bool forward, + bool casesens = true, bool matchwrd = false); +} // end namespace LyXFind #endif diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 26a1b6aae3..b78db82731 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -204,13 +204,13 @@ void LyXFunc::moveCursorUpdate(bool flag, bool selecting) void LyXFunc::handleKeyFunc(kb_action action) { - char c = keyseq.getiso(); + char c = keyseq.getLastKeyEncoded(); if (keyseq.length() > 1) { c = 0; } - owner->getIntl()->getTrans() + owner->getIntl()->getTransManager() .deadkey(c, get_accent(action).accent, TEXT(false)); // Need to clear, in case the minibuffer calls these // actions @@ -222,32 +222,25 @@ void LyXFunc::handleKeyFunc(kb_action action) } -void LyXFunc::processKeySym(KeySym keysym, key_modifier::state state) +void LyXFunc::processKeySym(LyXKeySymPtr keysym, + key_modifier::state state) { string argument; if (lyxerr.debugging(Debug::KEY)) { - char const * tmp = XKeysymToString(keysym); - string const stm = (tmp ? tmp : ""); lyxerr << "KeySym is " - << stm - << "[" - << keysym + << keysym->getSymbolName() << endl; } // Do nothing if we have nothing (JMarc) - if (keysym == NoSymbol) { + if ( ! keysym->isOK() ) { lyxerr[Debug::KEY] << "Empty kbd action (probably composing)" << endl; return; } - // Can we be sure that this will work for all X Window - // implementations? (Lgb) - // This code snippet makes lyx ignore some keys. Perhaps - // all of them should be explictly mentioned? - if ((keysym >= XK_Shift_L && keysym <= XK_Hyper_R) - || keysym == XK_Mode_switch || keysym == 0x0) { + // This code snippet makes lyx ignore modifier keys. + if (keysym->isModifier()) { return; } @@ -318,13 +311,11 @@ void LyXFunc::processKeySym(KeySym keysym, key_modifier::state state) if (action == LFUN_SELFINSERT) { // This is very X dependent. - unsigned int c = keysym; + char c = keysym->getISOEncoded(); string argument; - c = kb_keymap::getiso(c); - - if (c > 0) - argument = static_cast(c); + if (c != 0) + argument = c; dispatch(LFUN_SELFINSERT, argument); lyxerr[Debug::KEY] << "SelfInsert arg[`" @@ -896,7 +887,7 @@ string const LyXFunc::dispatch(kb_action action, string argument) #endif if ((action == LFUN_UNKNOWN_ACTION) && argument.empty()) { - argument = keyseq.getiso(); + argument = keyseq.getLastKeyEncoded(); } // Undo/Redo is a bit tricky for insets. if (action == LFUN_UNDO) { @@ -1044,7 +1035,7 @@ string const LyXFunc::dispatch(kb_action action, string argument) } bool fw = (action == LFUN_WORDFINDBACKWARD); if (!searched_string.empty()) { - LyXFind(owner->view(), searched_string, fw); + lyxfind::LyXFind(owner->view(), searched_string, fw); } // owner->view()->showCursor(); } diff --git a/src/lyxfunc.h b/src/lyxfunc.h index 387f85e961..9f72d2c406 100644 --- a/src/lyxfunc.h +++ b/src/lyxfunc.h @@ -14,11 +14,10 @@ #include "frontends/mouse_state.h" #include "frontends/key_state.h" +#include "frontends/LyXKeySym.h" #include -#include - class LyXView; class LyXText; @@ -57,7 +56,7 @@ public: void initMiniBuffer(); /// - void processKeySym(KeySym key, key_modifier::state state); + void processKeySym(LyXKeySymPtr key, key_modifier::state state); /// we need one internal which is called from inside LyXAction and /// can contain the string argument. @@ -81,7 +80,7 @@ public: string const getMessage() const { return dispatch_buffer; } /// Buffer to store result messages string const getStatusMessage() const { return status_buffer; } - /// Handle a accented char keysequenze + /// Handle a accented char key sequence void handleKeyFunc(kb_action action); private: diff --git a/src/lyxtext.h b/src/lyxtext.h index 47746fd127..bd27342e77 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -83,7 +83,7 @@ public: mutable LyXFont current_font; /// the current font mutable LyXFont real_current_font; - /// first visible pixel-row is set from LScreen!!! + /// first visible pixel-row is set from LyXScreen!!! // unsigned is wrong here for text-insets! int first_y; /// diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index b147f37142..d807a7c2dd 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,22 @@ +2002-06-16 André Pönitz + + * math_factory.C: + * math_support.C: fix font fall-back + + * math_specialcharinset.[Ch]: + * math_funcliminset.[Ch]: remove, it's now done by MathSymbolInset + + * math_funcinset.[Ch]: remove, it's not used + +2002-06-16 Lars Gullik Bjønnes + + * math_extern.C: add using std::endl + +2002-06-15 LyX Development team + + * formula.[Ch]: + * macroformula.[Ch] (docbook): Added argument to care about the + pernicious mixed content. 2002-05-30 André Pönitz diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 29ceacc6c7..e5ce335e4f 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -64,8 +64,6 @@ libmathed_la_SOURCES = \ math_fracinset.h \ math_fracbase.C \ math_fracbase.h \ - math_funcliminset.C \ - math_funcliminset.h \ math_gridinset.C \ math_gridinset.h \ math_hullinset.C \ @@ -92,12 +90,14 @@ libmathed_la_SOURCES = \ math_mathmlstream.h \ math_matrixinset.C \ math_matrixinset.h \ - math_metricsinfo.h \ math_metricsinfo.C \ + math_metricsinfo.h \ math_nestinset.C \ math_nestinset.h \ math_notinset.C \ math_notinset.h \ + math_numberinset.C \ + math_numberinset.h \ math_parser.C \ math_parser.h \ math_pos.C \ @@ -111,8 +111,6 @@ libmathed_la_SOURCES = \ math_sizeinset.h \ math_spaceinset.C \ math_spaceinset.h \ - math_specialcharinset.C \ - math_specialcharinset.h \ math_splitinset.C \ math_splitinset.h \ math_sqrtinset.C \ diff --git a/src/mathed/formula.C b/src/mathed/formula.C index c56e48fa4e..c87271376f 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -33,7 +33,6 @@ #include "frontends/Alert.h" #include "support/LOstream.h" #include "support/LAssert.h" -#include "support/systemcall.h" #include "support/filetools.h" // LibFileSearch #include "frontends/LyXView.h" #include "frontends/Painter.h" @@ -53,197 +52,6 @@ using std::vector; using std::getline; -namespace { - - string captureOutput(string const & cmd, string const & data) - { - string outfile = lyx::tempName(string(), "mathextern"); - string full = "echo '" + data + "' | (" + cmd + ") > " + outfile; - lyxerr << "calling: " << full << "\n"; - Systemcall dummy; - dummy.startscript(Systemcall::Wait, full); - string out = GetFileContents(outfile); - lyx::unlink(outfile); - lyxerr << "result: '" << out << "'\n"; - return out; - } - - - MathArray pipeThroughMaple(string const & extra, MathArray const & ar) - { - string header = "readlib(latex):\n"; - - // remove the \\it for variable names - //"#`latex/csname_font` := `\\it `:" - header += - "`latex/csname_font` := ``:\n"; - - // export matrices in (...) instead of [...] - header += - "`latex/latex/matrix` := " - "subs(`[`=`(`, `]`=`)`," - "eval(`latex/latex/matrix`)):\n"; - - // replace \\cdots with proper '*' - header += - "`latex/latex/*` := " - "subs(`\\,`=`\\cdot `," - "eval(`latex/latex/*`)):\n"; - - // remove spurious \\noalign{\\medskip} in matrix output - header += - "`latex/latex/matrix`:= " - "subs(`\\\\\\\\\\\\noalign{\\\\medskip}` = `\\\\\\\\`," - "eval(`latex/latex/matrix`)):\n"; - - //"#`latex/latex/symbol` " - // " := subs((\\'_\\' = \\'`\\_`\\',eval(`latex/latex/symbol`)): "; - - string trailer = "quit;"; - ostringstream os; - MapleStream ms(os); - ms << ar; - string expr = os.str().c_str(); - lyxerr << "ar: '" << ar << "'\n"; - - for (int i = 0; i < 100; ++i) { // at most 100 attempts - // try to fix missing '*' the hard way by using mint - // - // ... > echo "1A;" | mint -i 1 -S -s -q - // on line 1: 1A; - // ^ syntax error - - // Probably missing an operator such as * p - // - lyxerr << "checking expr: '" << expr << "'\n"; - string out = captureOutput("mint -i 1 -S -s -q -q", expr + ";"); - if (out.empty()) - break; // expression syntax is ok - istringstream is(out.c_str()); - string line; - getline(is, line); - if (line.find("on line") != 0) - break; // error message not identified - getline(is, line); - string::size_type pos = line.find('^'); - if (pos == string::npos || pos < 15) - break; // caret position not found - pos -= 15; // skip the "on line ..." part - if (expr[pos] == '*' || (pos > 0 && expr[pos - 1] == '*')) - break; // two '*' in a row are definitely bad - expr.insert(pos, "*"); - } - - string full = "latex(" + extra + '(' + expr + "));"; - string out = captureOutput("maple -q", header + full + trailer); - - // change \_ into _ - - // - MathArray res; - mathed_parse_cell(res, out); - return res; - } - - - MathArray pipeThroughOctave(string const &, MathArray const & ar) - { - ostringstream os; - OctaveStream vs(os); - vs << ar; - string expr = os.str().c_str(); - string out; - - for (int i = 0; i < 100; ++i) { // at most 100 attempts - // - // try to fix missing '*' the hard way - // parse error: - // >>> ([[1 2 3 ];[2 3 1 ];[3 1 2 ]])([[1 2 3 ];[2 3 1 ];[3 1 2 ]]) - // ^ - // - lyxerr << "checking expr: '" << expr << "'\n"; - out = captureOutput("octave -q 2>&1", expr); - lyxerr << "checking out: '" << out << "'\n"; - - // leave loop if expression syntax is probably ok - if (out.find("parse error:") == string::npos) - break; - - // search line with single caret - istringstream is(out.c_str()); - string line; - while (is) { - getline(is, line); - lyxerr << "skipping line: '" << line << "'\n"; - if (line.find(">>> ") != string::npos) - break; - } - - // found line with error, next line is the one with caret - getline(is, line); - string::size_type pos = line.find('^'); - lyxerr << "caret line: '" << line << "'\n"; - lyxerr << "found caret at pos: '" << pos << "'\n"; - if (pos == string::npos || pos < 4) - break; // caret position not found - pos -= 4; // skip the ">>> " part - if (expr[pos] == '*') - break; // two '*' in a row are definitely bad - expr.insert(pos, "*"); - } - - if (out.size() < 6) - return MathArray(); - - // remove 'ans = ' - out = out.substr(6); - - // parse output as matrix or single number - MathAtom at(new MathArrayInset("array", out)); - MathArrayInset const * mat = at.nucleus()->asArrayInset(); - MathArray res; - if (mat->ncols() == 1 && mat->nrows() == 1) - res.push_back(mat->cell(0)); - else { - res.push_back(MathAtom(new MathDelimInset("(", ")"))); - res.back()->cell(0).push_back(at); - } - return res; - } - - - MathArray pipeThroughExtern(string const & lang, string const & extra, - MathArray const & ar) - { - if (lang == "octave") - return pipeThroughOctave(extra, ar); - - if (lang == "maple") - return pipeThroughMaple(extra, ar); - - // create normalized expression - ostringstream os; - NormalStream ns(os); - os << "[" << extra << ' '; - ns << ar; - os << "]"; - string data = os.str().c_str(); - - // search external script - string file = LibFileSearch("mathed", "extern_" + lang); - if (file.empty()) { - lyxerr << "converter to '" << lang << "' not found\n"; - return MathArray(); - } - - // run external sript - string out = captureOutput(file, data); - MathArray res; - mathed_parse_cell(res, out); - return res; - } - -} - InsetFormula::InsetFormula() : par_(MathAtom(new MathHullInset)) @@ -315,18 +123,23 @@ int InsetFormula::ascii(Buffer const *, ostream & os, int) const int InsetFormula::linuxdoc(Buffer const * buf, ostream & os) const { - return docbook(buf, os); + return docbook(buf, os, false); } -int InsetFormula::docbook(Buffer const * buf, ostream & os) const +int InsetFormula::docbook(Buffer const * buf, ostream & os, bool) const { MathMLStream ms(os); - ms << MTag("equation") << MTag("alt"); + ms << MTag("equation"); + ms << MTag("alt"); + ms << "<[CDATA["; int res = ascii(buf, ms.os(), 0); - ms << ETag("alt") << MTag("math"); - ms << par_.nucleus(); - ms << ETag("math") << ETag("equation"); + ms << "]]>"; + ms << ETag("alt"); + ms << MTag("math"); + ms << par_.nucleus(); + ms << ETag("math"); + ms << ETag("equation"); return ms.line() + res; } @@ -490,7 +303,8 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, case LFUN_MATH_EXTERN: { bv->lockedInsetStoreUndo(Undo::EDIT); - handleExtern(arg); + if (mathcursor) + mathcursor->handleExtern(arg); // re-compute inset dimension metrics(bv); updateLocal(bv, true); @@ -502,7 +316,7 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, int x = 0; int y = 0; mathcursor->getPos(x, y); - if (hull()->getType() == LM_OT_SIMPLE) + if (getType() == LM_OT_SIMPLE) hull()->mutate(LM_OT_EQUATION); else hull()->mutate(LM_OT_SIMPLE); @@ -528,40 +342,9 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, } -void InsetFormula::handleExtern(const string & arg) -{ - // where are we? - if (!mathcursor) - return; - - string lang; - string extra; - istringstream iss(arg.c_str()); - iss >> lang >> extra; - if (extra.empty()) - extra = "noextra"; - - bool selected = mathcursor->selection(); - - MathArray ar; - if (selected) { - mathcursor->selGet(ar); - //lyxerr << "use selection: " << ar << "\n"; - } else { - mathcursor->last(); - mathcursor->stripFromLastEqualSign(); - ar = mathcursor->cursor().cell(); - mathcursor->insert('='); - //lyxerr << "use whole cell: " << ar << "\n"; - } - - mathcursor->insert(pipeThroughExtern(lang, extra, ar)); -} - - bool InsetFormula::display() const { - return hull()->getType() != LM_OT_SIMPLE; + return getType() != LM_OT_SIMPLE; } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index cefe8a8ed8..1d32ce06b8 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -56,7 +56,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream &) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// Inset * clone(Buffer const &, bool same_id = false) const; diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index af2a4e33e4..b05790d9ca 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -110,7 +110,7 @@ void InsetFormulaBase::mutateToText() string::const_iterator cit = str.begin(); string::const_iterator end = str.end(); for (; cit != end; ++cit) - view_->owner()->getIntl()->getTrans().TranslateAndInsert(*cit, lt); + view_->owner()->getIntl()->getTransManager().TranslateAndInsert(*cit, lt); // remove ourselves //view_->owner()->getLyXFunc()->dispatch(LFUN_ESCAPE); @@ -205,8 +205,9 @@ void InsetFormulaBase::insetUnlock(BufferView * bv) } -void InsetFormulaBase::getCursorPos(BufferView *, int & x, int & y) const +void InsetFormulaBase::getCursorPos(BufferView * bv, int & x, int & y) const { + metrics(bv); mathcursor->getPos(x, y); //x -= xo_; y -= yo_; @@ -265,6 +266,20 @@ void InsetFormulaBase::hideInsetCursor(BufferView * bv) } +void InsetFormulaBase::fitInsetCursor(BufferView * bv) const +{ + if (!mathcursor) + return; + + int const asc = font_metrics::maxAscent(font_); + int const desc = font_metrics::maxDescent(font_); + int x, y; + + getCursorPos(bv, x, y); + bv->fitLockedInsetCursor(x, y, asc, desc); +} + + void InsetFormulaBase::toggleInsetSelection(BufferView * bv) { if (mathcursor) @@ -281,6 +296,8 @@ vector const InsetFormulaBase::getLabelList() const void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty) { metrics(bv); + if (mathcursor) + bv->fitCursor(); bv->updateInset(this, dirty); } @@ -850,24 +867,24 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str, for (MathIterator it = current; it != iend(par().nucleus()); ++it) { if (it.cell().matchpart(ar, it.position().pos_)) { + bv->unlockInset(bv->theLockingInset()); + if (!bv->lockInset(this)) { + lyxerr << "Cannot lock inset" << endl; + return false; + } + delete mathcursor; + mathcursor = new MathCursor(this, true); + metrics(bv); mathcursor->setSelection(it.cursor(), ar.size()); current = it; it.jump(ar.size()); - // I guess some of the following can go - bv->toggleSelection(true); - hideInsetCursor(bv); - updateLocal(bv, true); - showInsetCursor(bv); - metrics(bv); + updateLocal(bv, false); return true; } } //lyxerr << "not found!\n"; lastformula = 0; - // we have to unlock ourself in this function by default! - // don't ask me why... - bv->unlockInset(this); return false; } @@ -1007,3 +1024,7 @@ void mathDispatchGreek(BufferView * bv, string const & arg) void mathDispatch(BufferView *, kb_action, string const &) {} + + +void mathDispatch(BufferView *, string const &) +{} diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index a91eed0b38..fd6c2db664 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -76,6 +76,8 @@ public: /// virtual void hideInsetCursor(BufferView *); /// + virtual void fitInsetCursor(BufferView *) const; + /// virtual void getCursorPos(BufferView *, int &, int &) const; /// virtual void toggleInsetSelection(BufferView * bv); @@ -165,5 +167,7 @@ void mathDispatchGreek(BufferView *, string const &); void mathDispatchMathImportSelection(BufferView *, string const &); // void mathDispatch(BufferView *, kb_action, string const &); +// +void mathDispatch(BufferView *, string const &); #endif diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index 7e0493644d..16f8c3c58b 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -99,7 +99,7 @@ int InsetFormulaMacro::linuxdoc(Buffer const * buf, ostream & os) const } -int InsetFormulaMacro::docbook(Buffer const * buf, ostream & os) const +int InsetFormulaMacro::docbook(Buffer const * buf, ostream & os, bool) const { return ascii(buf, os, 0); } diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index c9d61785d0..05ab42ed21 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -57,7 +57,7 @@ public: /// int linuxdoc(Buffer const *, std::ostream & os) const; /// - int docbook(Buffer const *, std::ostream &) const; + int docbook(Buffer const *, std::ostream &, bool mixcont) const; /// Inset * clone(Buffer const &, bool same_id = false) const; diff --git a/src/mathed/math_autocorrect.C b/src/mathed/math_autocorrect.C index 63315bc651..1ae1f149af 100644 --- a/src/mathed/math_autocorrect.C +++ b/src/mathed/math_autocorrect.C @@ -46,10 +46,12 @@ bool Correction::read(istream & is) is >> s1 >> s2 >> s3; if (!is) return false; + if (s2.size() != 1) + return false; MathArray ar1, ar3; mathed_parse_cell(ar1, s1); mathed_parse_cell(ar3, s3); - if (ar1.size() != 1 || s2.size() != 1 || ar3.size() !=1) + if (ar1.size() != 1 || ar3.size() != 1) return false; from1_ = ar1.front(); from2_ = s2[0]; diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index 8e74c6bc65..a212db15e7 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -122,6 +122,12 @@ void MathCharInset::normalize(NormalStream & os) const } +void MathCharInset::octavize(OctaveStream & os) const +{ + os << char_; +} + + bool MathCharInset::isRelOp() const { return char_ == '=' || char_ == '<' || char_ == '>'; diff --git a/src/mathed/math_charinset.h b/src/mathed/math_charinset.h index da50061c49..cc24898b2f 100644 --- a/src/mathed/math_charinset.h +++ b/src/mathed/math_charinset.h @@ -29,7 +29,9 @@ public: /// void write(WriteStream & os) const; /// - void normalize(NormalStream &) const; + void normalize(NormalStream & ns) const; + /// + void octavize(OctaveStream & os) const; /// identifies Charinsets MathCharInset const * asCharInset() const { return this; } /// diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index 09dcfe91a1..0f95d7d182 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -36,6 +36,7 @@ #include "math_casesinset.h" #include "math_charinset.h" #include "math_deliminset.h" +#include "math_extern.h" #include "math_factory.h" #include "math_hullinset.h" #include "math_iterator.h" @@ -46,7 +47,6 @@ #include "math_replace.h" #include "math_scriptinset.h" #include "math_spaceinset.h" -#include "math_specialcharinset.h" #include "math_support.h" #include "math_unknowninset.h" @@ -64,131 +64,15 @@ using std::ostringstream; using std::isalpha; -namespace { - -struct Selection -{ - typedef MathInset::col_type col_type; - typedef MathInset::row_type row_type; - typedef MathInset::idx_type idx_type; - - Selection() - : data_(1, 1) - {} - - void region(MathCursorPos const & i1, MathCursorPos const & i2, - row_type & r1, row_type & r2, col_type & c1, col_type & c2) - { - MathInset * p = i1.par_; - c1 = p->col(i1.idx_); - c2 = p->col(i2.idx_); - if (c1 > c2) - swap(c1, c2); - r1 = p->row(i1.idx_); - r2 = p->row(i2.idx_); - if (r1 > r2) - swap(r1, r2); - } - - void grab(MathCursor const & cursor) - { - MathCursorPos i1; - MathCursorPos i2; - cursor.getSelection(i1, i2); - // shouldn'tt we assert on i1.par_ == i2.par_? - if (i1.idx_ == i2.idx_) { - data_ = MathGridInset(1, 1); - data_.cell(0) = MathArray(i1.cell(), i1.pos_, i2.pos_); - } else { - row_type r1, r2; - col_type c1, c2; - region(i1, i2, r1, r2, c1, c2); - data_ = MathGridInset(c2 - c1 + 1, r2 - r1 + 1); - for (row_type row = 0; row < data_.nrows(); ++row) - for (col_type col = 0; col < data_.ncols(); ++col) { - idx_type i = i1.par_->index(row + r1, col + c1); - data_.cell(data_.index(row, col)) = i1.par_->cell(i); - } - } - } - - void erase(MathCursor & cursor) - { - MathCursorPos i1; - MathCursorPos i2; - cursor.getSelection(i1, i2); - if (i1.idx_ == i2.idx_) - i1.cell().erase(i1.pos_, i2.pos_); - else { - MathInset * p = i1.par_; - row_type r1, r2; - col_type c1, c2; - region(i1, i2, r1, r2, c1, c2); - for (row_type row = r1; row <= r2; ++row) - for (col_type col = c1; col <= c2; ++col) - p->cell(p->index(row, col)).erase(); - } - cursor.cursor() = i1; - } - - void paste(MathCursor & cursor) const - { - if (data_.nargs() == 1) { - // single cell/part of cell - cursor.paste(data_.cell(0)); - } else { - // mulitple cells - idx_type idx; // index of upper left cell - MathGridInset * p = cursor.enclosingGrid(idx); - col_type const numcols = min(data_.ncols(), p->ncols() - p->col(idx)); - row_type const numrows = min(data_.nrows(), p->nrows() - p->row(idx)); - for (row_type row = 0; row < numrows; ++row) { - for (col_type col = 0; col < numcols; ++col) { - idx_type i = p->index(row + p->row(idx), col + p->col(idx)); - p->cell(i).push_back(data_.cell(data_.index(row, col))); - } - // append the left over horizontal cells to the last column - idx_type i = p->index(row + p->row(idx), p->ncols() - 1); - for (col_type col = numcols; col < data_.ncols(); ++col) - p->cell(i).push_back(data_.cell(data_.index(row, col))); - } - // append the left over vertical cells to the last _cell_ - idx_type i = p->nargs() - 1; - for (row_type row = numrows; row < data_.nrows(); ++row) - for (col_type col = 0; col < data_.ncols(); ++col) - p->cell(i).push_back(data_.cell(data_.index(row, col))); - } - } - - // glues selection to one cell - MathArray glue() const - { - MathArray ar; - for (unsigned i = 0; i < data_.nargs(); ++i) - ar.push_back(data_.cell(i)); - return ar; - } - - void clear() - { - data_ = MathGridInset(1, 1); - } - - MathGridInset data_; -}; - - -Selection theSelection; - - - -} +// matheds own cut buffer +MathGridInset theCutBuffer = MathGridInset(1, 1); MathCursor::MathCursor(InsetFormulaBase * formula, bool front) : formula_(formula), autocorrect_(false), selection_(false) { front ? first() : last(); + Anchor_ = Cursor_; } @@ -218,7 +102,7 @@ void MathCursor::pushRight(MathAtom & t) bool MathCursor::popLeft() { //cerr << "Leaving atom to the left\n"; - if (Cursor_.size() <= 1) + if (depth() <= 1) return false; Cursor_.pop_back(); return true; @@ -228,7 +112,7 @@ bool MathCursor::popLeft() bool MathCursor::popRight() { //cerr << "Leaving atom "; par()->write(cerr, false); cerr << " right\n"; - if (Cursor_.size() <= 1) + if (depth() <= 1) return false; Cursor_.pop_back(); posRight(); @@ -241,8 +125,8 @@ bool MathCursor::popRight() void MathCursor::dump(char const * what) const { lyxerr << "MC: " << what << "\n"; - lyxerr << " Cursor: " << Cursor_.size() << "\n"; - for (unsigned i = 0; i < Cursor_.size(); ++i) + lyxerr << " Cursor: " << depth() << "\n"; + for (unsigned i = 0; i < depth(); ++i) lyxerr << " i: " << i << " " << Cursor_[i] << "\n"; lyxerr << " Anchor: " << Anchor_.size() << "\n"; for (unsigned i = 0; i < Anchor_.size(); ++i) @@ -256,7 +140,7 @@ bool MathCursor::popRight() bool MathCursor::isInside(MathInset const * p) const { - for (unsigned i = 0; i < Cursor_.size(); ++i) + for (unsigned i = 0; i < depth(); ++i) if (Cursor_[i].par_ == p) return true; return false; @@ -276,9 +160,9 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const if (sel) { // we can't move into anything new during selection - if (Cursor_.size() == Anchor_.size()) + if (depth() == Anchor_.size()) return false; - if (t.nucleus() != Anchor_[Cursor_.size()].par_) + if (t.nucleus() != Anchor_[depth()].par_) return false; } return true; @@ -454,28 +338,21 @@ void MathCursor::insert(char c) void MathCursor::insert(MathAtom const & t) { macroModeClose(); - - if (selection_) { - if (t->nargs()) - selCut(); - else - selClearOrDel(); - } - + selClearOrDel(); plainInsert(t); } void MathCursor::niceInsert(MathAtom const & t) { - selCut(); - insert(t); // inserting invalidates the pointer! - MathAtom & p = prevAtom(); + macroModeClose(); + MathGridInset safe = grabAndEraseSelection(); + plainInsert(t); // enter the new inset and move the contents of the selection if possible - if (p->isActive()) { - push(p); - par()->idxLast(idx(), pos()); - selPaste(); + if (t->isActive()) { + posLeft(); + pushLeft(nextAtom()); + paste(safe); } } @@ -484,7 +361,7 @@ void MathCursor::insert(MathArray const & ar) { macroModeClose(); if (selection_) - selCut(); + eraseSelection(); array().insert(pos(), ar); pos() += ar.size(); @@ -500,6 +377,35 @@ void MathCursor::paste(MathArray const & ar) } +void MathCursor::paste(MathGridInset const & data) +{ + if (data.nargs() == 1) { + // single cell/part of cell + paste(data.cell(0)); + } else { + // mulitple cells + idx_type idx; // index of upper left cell + MathGridInset * p = enclosingGrid(idx); + col_type const numcols = min(data.ncols(), p->ncols() - p->col(idx)); + row_type const numrows = min(data.nrows(), p->nrows() - p->row(idx)); + for (row_type row = 0; row < numrows; ++row) { + for (col_type col = 0; col < numcols; ++col) { + idx_type i = p->index(row + p->row(idx), col + p->col(idx)); + p->cell(i).push_back(data.cell(data.index(row, col))); + } + // append the left over horizontal cells to the last column + idx_type i = p->index(row + p->row(idx), p->ncols() - 1); + for (MathInset::col_type col = numcols; col < data.ncols(); ++col) + p->cell(i).push_back(data.cell(data.index(row, col))); + } + // append the left over vertical cells to the last _cell_ + idx_type i = p->nargs() - 1; + for (row_type row = numrows; row < data.nrows(); ++row) + for (col_type col = 0; col < data.ncols(); ++col) + p->cell(i).push_back(data.cell(data.index(row, col))); + } +} + void MathCursor::backspace() { autocorrect_ = false; @@ -641,7 +547,13 @@ void MathCursor::macroModeClose() string MathCursor::macroName() const { - return inMacroMode() ? inMacroMode()->name() : ""; + return inMacroMode() ? inMacroMode()->name() : string(); +} + + +void MathCursor::selClear() +{ + selection_ = false; } @@ -649,8 +561,10 @@ void MathCursor::selCopy() { dump("selCopy"); if (selection_) { - theSelection.grab(*this); - //selClear(); + theCutBuffer = grabSelection(); + selection_ = false; + } else { + theCutBuffer = MathGridInset(1, 1); } } @@ -658,13 +572,7 @@ void MathCursor::selCopy() void MathCursor::selCut() { dump("selCut"); - if (selection_) { - theSelection.grab(*this); - theSelection.erase(*this); - selClear(); - } else { - theSelection.clear(); - } + theCutBuffer = grabAndEraseSelection(); } @@ -672,10 +580,8 @@ void MathCursor::selDel() { dump("selDel"); if (selection_) { - theSelection.erase(*this); - if (pos() > size()) - pos() = size(); - selClear(); + eraseSelection(); + selection_ = false; } } @@ -684,9 +590,9 @@ void MathCursor::selPaste() { dump("selPaste"); selClearOrDel(); - theSelection.paste(*this); - //theSelection.grab(*this); - selClear(); + paste(theCutBuffer); + //grabSelection(); + selection_ = false; } @@ -694,8 +600,8 @@ void MathCursor::selHandle(bool sel) { if (sel == selection_) return; - //theSelection.clear(); - Anchor_ = Cursor_; + //clear(); + Anchor_ = Cursor_; selection_ = sel; } @@ -703,38 +609,27 @@ void MathCursor::selHandle(bool sel) void MathCursor::selStart() { dump("selStart 1"); - //theSelection.clear(); + //clear(); Anchor_ = Cursor_; selection_ = true; dump("selStart 2"); } -void MathCursor::selClear() -{ - dump("selClear 1"); - selection_ = false; - dump("selClear 2"); -} - - void MathCursor::selClearOrDel() { if (lyxrc.auto_region_delete) selDel(); else - selClear(); + selection_ = false; } void MathCursor::selGet(MathArray & ar) { dump("selGet"); - if (!selection_) - return; - - theSelection.grab(*this); - ar = theSelection.glue(); + if (selection_) + ar = grabSelection().glue(); } @@ -790,10 +685,7 @@ void MathCursor::handleDelim(string const & l, string const & r) void MathCursor::handleNest(MathInset * p) { - if (selection_) { - selCut(); - p->cell(0) = theSelection.glue(); - } + p->cell(0) = grabAndEraseSelection().glue(); insert(MathAtom(p)); // this invalidates p! pushRight(prevAtom()); } @@ -871,12 +763,24 @@ bool MathCursor::selection() const MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const { - for (MathInset::difference_type i = Cursor_.size() - 1; i >= 0; --i) { + for (MathInset::difference_type i = depth() - 1; i >= 0; --i) { MathGridInset * p = Cursor_[i].par_->asGridInset(); if (p) { idx = Cursor_[i].idx_; return p; - lyxerr << "found grid and idx: " << idx << "\n"; + } + } + return 0; +} + + +MathHullInset * MathCursor::enclosingHull(MathCursor::idx_type & idx) const +{ + for (MathInset::difference_type i = depth() - 1; i >= 0; --i) { + MathHullInset * p = Cursor_[i].par_->asHullInset(); + if (p) { + idx = Cursor_[i].idx_; + return p; } } return 0; @@ -885,7 +789,14 @@ MathGridInset * MathCursor::enclosingGrid(MathCursor::idx_type & idx) const void MathCursor::popToEnclosingGrid() { - while (Cursor_.size() && !Cursor_.back().par_->asGridInset()) + while (depth() && !Cursor_.back().par_->asGridInset()) + Cursor_.pop_back(); +} + + +void MathCursor::popToEnclosingHull() +{ + while (depth() && !Cursor_.back().par_->asHullInset()) Cursor_.pop_back(); } @@ -962,7 +873,7 @@ void MathCursor::normalize() // remove empty scripts if possible if (1) { for (pos_type i = 0; i < size(); ++i) { - MathScriptInset * p = array().at(i)->asScriptInset(); + MathScriptInset * p = array()[i]->asScriptInset(); if (p) { p->removeEmptyScripts(); //if (p->empty()) @@ -984,13 +895,17 @@ MathCursor::size_type MathCursor::size() const MathCursor::col_type MathCursor::hullCol() const { - return Cursor_[0].par_->asGridInset()->col(Cursor_[0].idx_); + idx_type idx = 0; + MathHullInset * p = enclosingHull(idx); + return p->col(idx); } MathCursor::row_type MathCursor::hullRow() const { - return Cursor_[0].par_->asGridInset()->row(Cursor_[0].idx_); + idx_type idx = 0; + MathHullInset * p = enclosingHull(idx); + return p->row(idx); } @@ -1009,28 +924,28 @@ bool MathCursor::hasNextAtom() const MathAtom const & MathCursor::prevAtom() const { lyx::Assert(pos() > 0); - return array().at(pos() - 1); + return array()[pos() - 1]; } MathAtom & MathCursor::prevAtom() { lyx::Assert(pos() > 0); - return array().at(pos() - 1); + return array()[pos() - 1]; } MathAtom const & MathCursor::nextAtom() const { lyx::Assert(pos() < size()); - return array().at(pos()); + return array()[pos()]; } MathAtom & MathCursor::nextAtom() { lyx::Assert(pos() < size()); - return array().at(pos()); + return array()[pos()]; } @@ -1043,8 +958,8 @@ MathArray & MathCursor::array() const return dummy; } - if (Cursor_.size() == 0) { - lyxerr << "############ Cursor_.size() == 0 not valid\n"; + if (depth() == 0) { + lyxerr << "############ depth() == 0 not valid\n"; return dummy; } @@ -1056,8 +971,8 @@ MathXArray & MathCursor::xarray() const { static MathXArray dummy; - if (Cursor_.size() == 0) { - lyxerr << "############ Cursor_.size() == 0 not valid\n"; + if (depth() == 0) { + lyxerr << "############ depth() == 0 not valid\n"; return dummy; } @@ -1096,14 +1011,15 @@ void MathCursor::breakLine() while (popRight()) ; - MathHullInset * p = formula()->par()->asHullInset(); + idx_type dummy; + MathHullInset * p = enclosingHull(dummy); if (!p) return; if (p->getType() == LM_OT_SIMPLE || p->getType() == LM_OT_EQUATION) { p->mutate(LM_OT_EQNARRAY); - idx() = 0; - pos() = size(); + idx() = 1; + pos() = 0; } else { p->addRow(hullRow()); @@ -1158,14 +1074,14 @@ void MathCursor::getSelection(MathCursorPos & i1, MathCursorPos & i2) const MathCursorPos & MathCursor::cursor() { - lyx::Assert(Cursor_.size()); + lyx::Assert(depth()); return Cursor_.back(); } MathCursorPos const & MathCursor::cursor() const { - lyx::Assert(Cursor_.size()); + lyx::Assert(depth()); return Cursor_.back(); } @@ -1301,6 +1217,22 @@ bool MathCursor::bruteFind } +bool MathCursor::idxLineFirst() +{ + idx() -= idx() % par()->ncols(); + pos() = 0; + return true; +} + + +bool MathCursor::idxLineLast() +{ + idx() -= idx() % par()->ncols(); + idx() += par()->ncols() - 1; + pos() = size(); + return true; +} + bool MathCursor::idxLeft() { return par()->idxLeft(idx(), pos()); @@ -1320,7 +1252,7 @@ bool MathCursor::interpret(string const & s) return true; //lyxerr << "char: '" << s[0] << "' int: " << int(s[0]) << endl; - //owner_->getIntl()->getTrans().TranslateAndInsert(s[0], lt); + //owner_->getIntl()->getTransManager().TranslateAndInsert(s[0], lt); //lyxerr << "trans: '" << s[0] << "' int: " << int(s[0]) << endl; if (s.size() >= 5 && s.substr(0, 5) == "cases") { @@ -1396,7 +1328,7 @@ bool MathCursor::script(bool up) } macroModeClose(); - selCut(); + MathGridInset safe = grabAndEraseSelection(); if (hasPrevAtom() && prevAtom()->asScriptInset()) { prevAtom()->asScriptInset()->ensure(up); pushRight(prevAtom()); @@ -1414,7 +1346,7 @@ bool MathCursor::script(bool up) idx() = up; pos() = 0; } - selPaste(); + paste(safe); dump("1"); return true; } @@ -1438,7 +1370,7 @@ bool MathCursor::interpret(char c) if (p && 1 <= n && n <= p->numargs()) insert(MathAtom(new MathMacroArgument(c - '0'))); else { - insert(MathAtom(new MathSpecialCharInset('#'))); + insert(createMathInset("#")); interpret(c); // try again } return true; @@ -1485,7 +1417,7 @@ bool MathCursor::interpret(char c) // just clear selection on pressing the space par if (selection_ && c == ' ') { - selClear(); + selection_ = false; return true; } @@ -1539,8 +1471,13 @@ bool MathCursor::interpret(char c) return true; } - if (c == '$' || c == '%') { - insert(MathAtom(new MathSpecialCharInset(c))); + if (c == '$') { + insert(createMathInset("$")); + return true; + } + + if (c == '%') { + insert(createMathInset("%")); return true; } @@ -1574,40 +1511,6 @@ bool MathCursor::interpret(char c) } - -MathCursorPos MathCursor::normalAnchor() const -{ - if (Anchor_.size() < Cursor_.size()) { - Anchor_ = Cursor_; - lyxerr << "unusual Anchor size\n"; - dump("1"); - } - //lyx::Assert(Anchor_.size() >= Cursor_.size()); - // use Anchor on the same level as Cursor - MathCursorPos normal = Anchor_[Cursor_.size() - 1]; - if (Cursor_.size() < Anchor_.size() && !(normal < cursor())) { - // anchor is behind cursor -> move anchor behind the inset - ++normal.pos_; - } - return normal; -} - - -void MathCursor::stripFromLastEqualSign() -{ - // find position of last '=' in the array - MathArray & ar = cursor().cell(); - MathArray::const_iterator et = ar.end(); - for (MathArray::const_iterator it = ar.begin(); it != ar.end(); ++it) - if ((*it)->getChar() == '=') - et = it; - - // delete everything behind this position - ar.erase(et - ar.begin(), ar.size()); - pos() = ar.size(); -} - - void MathCursor::setSelection(cursor_type const & where, size_type n) { selection_ = true; @@ -1628,7 +1531,7 @@ string MathCursor::info() const { ostringstream os; os << "Math editor mode "; - for (int i = 0, n = Cursor_.size(); i < n; ++i) { + for (int i = 0, n = depth(); i < n; ++i) { Cursor_[i].par_->infoize(os); os << " "; } @@ -1637,3 +1540,179 @@ string MathCursor::info() const os << " "; return os.str().c_str(); // .c_str() needed for lyxstring } + + +unsigned MathCursor::depth() const +{ + return Cursor_.size(); +} + + + + +namespace { + +void region(MathCursorPos const & i1, MathCursorPos const & i2, + MathInset::row_type & r1, MathInset::row_type & r2, + MathInset::col_type & c1, MathInset::col_type & c2) +{ + MathInset * p = i1.par_; + c1 = p->col(i1.idx_); + c2 = p->col(i2.idx_); + if (c1 > c2) + swap(c1, c2); + r1 = p->row(i1.idx_); + r2 = p->row(i2.idx_); + if (r1 > r2) + swap(r1, r2); +} + +} + + +MathGridInset MathCursor::grabSelection() const +{ + if (!selection_) + return MathGridInset(); + MathCursorPos i1; + MathCursorPos i2; + getSelection(i1, i2); + // shouldn't we assert on i1.par_ == i2.par_? + if (i1.idx_ == i2.idx_) { + MathGridInset data(1, 1); + data.cell(0) = MathArray(i1.cell(), i1.pos_, i2.pos_); + return data; + } + row_type r1, r2; + col_type c1, c2; + region(i1, i2, r1, r2, c1, c2); + MathGridInset data(c2 - c1 + 1, r2 - r1 + 1); + for (row_type row = 0; row < data.nrows(); ++row) + for (col_type col = 0; col < data.ncols(); ++col) { + idx_type i = i1.par_->index(row + r1, col + c1); + data.cell(data.index(row, col)) = i1.par_->cell(i); + } + return data; +} + + +void MathCursor::eraseSelection() +{ + MathCursorPos i1; + MathCursorPos i2; + getSelection(i1, i2); + if (i1.idx_ == i2.idx_) + i1.cell().erase(i1.pos_, i2.pos_); + else { + MathInset * p = i1.par_; + row_type r1, r2; + col_type c1, c2; + region(i1, i2, r1, r2, c1, c2); + for (row_type row = r1; row <= r2; ++row) + for (col_type col = c1; col <= c2; ++col) + p->cell(p->index(row, col)).erase(); + } + cursor() = i1; +} + + +MathGridInset MathCursor::grabAndEraseSelection() +{ + if (!selection_) + return MathGridInset(); + MathGridInset res = grabSelection(); + eraseSelection(); + selection_ = false; + return res; +} + + +MathCursorPos MathCursor::normalAnchor() const +{ + if (Anchor_.size() < depth()) { + Anchor_ = Cursor_; + lyxerr << "unusual Anchor size\n"; + } + //lyx::Assert(Anchor_.size() >= cursor.depth()); + // use Anchor on the same level as Cursor + MathCursorPos normal = Anchor_[depth() - 1]; + if (depth() < Anchor_.size() && !(normal < cursor())) { + // anchor is behind cursor -> move anchor behind the inset + ++normal.pos_; + } + return normal; +} + + + +void MathCursor::handleExtern(const string & arg) +{ + string lang; + string extra; + istringstream iss(arg.c_str()); + iss >> lang >> extra; + if (extra.empty()) + extra = "noextra"; + + + if (selection()) { + MathArray ar; + selGet(ar); + lyxerr << "use selection: " << ar << "\n"; + insert(pipeThroughExtern(lang, extra, ar)); + return; + } + + MathArray eq; + eq.push_back(MathAtom(new MathCharInset('='))); + + popToEnclosingHull(); + + idx_type idx = 0; + MathHullInset * hull = enclosingHull(idx); + lyx::Assert(hull); + idxLineFirst(); + + if (hull->getType() == LM_OT_SIMPLE) { + MathArray::size_type pos = cursor().cell().find_last(eq); + MathArray ar; + if (pos == size()) { + ar = array(); + lyxerr << "use whole cell: " << ar << "\n"; + } else { + ar = MathArray(array(), pos + 1, size()); + lyxerr << "use partial cell form pos: " << pos << "\n"; + } + end(); + insert(eq); + insert(pipeThroughExtern(lang, extra, ar)); + return; + } + + if (hull->getType() == LM_OT_EQUATION) { + lyxerr << "use equation inset\n"; + hull->mutate(LM_OT_EQNARRAY); + MathArray & ar = cursor().cell(); + lyxerr << "use cell: " << ar << "\n"; + idxRight(); + cursor().cell() = eq; + idxRight(); + cursor().cell() = pipeThroughExtern(lang, extra, ar); + idxLineLast(); + return; + } + + { + lyxerr << "use eqnarray\n"; + idxLineLast(); + MathArray ar = cursor().cell(); + lyxerr << "use cell: " << ar << "\n"; + breakLine(); + idxRight(); + cursor().cell() = eq; + idxRight(); + cursor().cell() = pipeThroughExtern(lang, extra, ar); + idxLineLast(); + } + +} diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 1d8e95950b..f6bad5629b 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -66,6 +66,8 @@ public: /// void paste(MathArray const &); /// + void paste(MathGridInset const & data); + /// void erase(); /// void backspace(); @@ -105,9 +107,13 @@ public: /// current inset MathInset * par() const; /// return the next enclosing grid inset and the cursor's index in it - MathGridInset * enclosingGrid(idx_type &) const; - /// return the next enclosing grid inset and the cursor's index in it + MathGridInset * enclosingGrid(idx_type & idx) const; + /// return the next enclosing hull inset and the cursor's index in it + MathHullInset * enclosingHull(idx_type & idx) const; + /// go up to enclosing grid void popToEnclosingGrid(); + /// go up to the hull inset + void popToEnclosingHull(); /// InsetFormulaBase * formula(); /// current offset in the current cell @@ -229,6 +235,8 @@ public: MathCursorPos & cursor(); /// reference to the last item of the path, i.e. "The Cursor" MathCursorPos const & cursor() const; + /// how deep are we nested? + unsigned depth() const; /// describe the situation string info() const; @@ -236,8 +244,6 @@ public: void seldump(char const * str) const; /// dump selection information for debugging void dump(char const * str) const; - /// - void stripFromLastEqualSign(); /// moves on void setSelection(cursor_type const & where, size_type n); /// @@ -248,24 +254,38 @@ public: /// hack for reveal codes void markInsert(); void markErase(); + void handleExtern(string const & arg); /// friend class Selection; + private: - /// moves cursor position one cell to the left - bool posLeft(); - /// moves cursor position one cell to the right - bool posRight(); /// moves cursor index one cell to the left bool idxLeft(); /// moves cursor index one cell to the right bool idxRight(); + /// moves cursor to beginning first cell of current line + bool idxLineFirst(); + /// moves cursor to end of last cell of current line + bool idxLineLast(); + /// moves cursor position one cell to the left + bool posLeft(); + /// moves cursor position one cell to the right + bool posRight(); /// moves position somehow up or down bool goUpDown(bool up); /// moves position into box bool bruteFind(int xo, int yo, int xlow, int xhigh, int ylow, int yhigh); + + /// grab grid marked by anchor and current cursor + MathGridInset grabSelection() const; + /// erase the selected part and re-sets the cursor + void eraseSelection(); + /// guess what + MathGridInset grabAndEraseSelection(); + /// string macroName() const; /// @@ -277,9 +297,9 @@ private: /// write access to cursor cell index idx_type & idx(); - /// path of positions the cursor had to go if it were leving each inset + /// path of positions the cursor had to go if it were leaving each inset cursor_type Cursor_; - /// path of positions the anchor had to go if it were leving each inset + /// path of positions the anchor had to go if it were leaving each inset mutable cursor_type Anchor_; /// pointer to enclsing LyX inset InsetFormulaBase * formula_; diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index 7ef98e0589..4aa7431b64 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -230,16 +230,10 @@ bool MathArray::matchpart(MathArray const & ar, pos_type pos) const void MathArray::replace(ReplaceData & rep) { for (size_type i = 0; i < size(); ++i) { - iterator it = begin() + i; - const_iterator rt = rep.from.begin(); - const_iterator et = rep.from.end(); - for (const_iterator jt = it; jt != end() && rt != et; ++jt, ++rt) - if (!jt->nucleus()->match(rt->nucleus())) - break; - if (rt == et) { + if (find1(rep.from, i)) { // match found lyxerr << "match found!\n"; - erase(it, it + rep.from.size()); + erase(i, i + rep.from.size()); insert(i, rep.to); } } @@ -249,22 +243,40 @@ void MathArray::replace(ReplaceData & rep) } -bool MathArray::contains(MathArray const & ar) const +bool MathArray::find1(MathArray const & ar, size_type pos) const { - for (size_type i = 0; i + ar.size() <= size(); ++i) { - const_iterator it = begin() + i; - const_iterator rt = ar.begin(); - const_iterator et = ar.end(); - for (const_iterator jt = it; rt != et; ++jt, ++rt) - if (!jt->nucleus()->match(rt->nucleus())) - break; - if (rt == et) - return true; - } + //lyxerr << "finding '" << ar << "' in '" << *this << "'\n"; + for (size_type i = 0, n = ar.size(); i < n; ++i) + if (!at(pos + i)->match(ar[i].nucleus())) + return false; + return true; +} + + +MathArray::size_type MathArray::find(MathArray const & ar) const +{ + for (int i = 0, last = size() - ar.size(); i < last; ++i) + if (find1(ar, i)) + return i; + return size(); +} + + +MathArray::size_type MathArray::find_last(MathArray const & ar) const +{ + for (int i = size() - ar.size(); i >= 0; --i) + if (find1(ar, i)) + return i; + return size(); +} + +bool MathArray::contains(MathArray const & ar) const +{ + if (find(ar) != size()) + return true; for (const_iterator it = begin(); it != end(); ++it) if (it->nucleus()->contains(ar)) return true; - return false; } diff --git a/src/mathed/math_data.h b/src/mathed/math_data.h index 2b94c69dd0..66994e7ccc 100644 --- a/src/mathed/math_data.h +++ b/src/mathed/math_data.h @@ -61,7 +61,7 @@ public: /// MathArray(); /// - MathArray(MathArray const &, size_type from, size_type to); + MathArray(MathArray const & ar, size_type from, size_type to); /// MathArray(iterator from, iterator to); @@ -74,26 +74,26 @@ public: /// void swap(MathArray &); - /// - void insert(size_type pos, MathAtom const &); - /// - void insert(size_type pos, MathArray const &); + /// inserts single atom at position pos + void insert(size_type pos, MathAtom const & at); + /// inserts multiple atoms at position pos + void insert(size_type pos, MathArray const & ar); - /// + /// erase range from pos1 to pos2 void erase(iterator pos1, iterator pos2); - /// + /// erase single atom void erase(iterator pos); - /// + /// erase range from pos1 to pos2 void erase(size_type pos1, size_type pos2); - /// + /// erase single atom void erase(size_type pos); - /// + /// erase everythng void erase(); /// - void push_back(MathAtom const &); + void push_back(MathAtom const & at); /// - void push_back(MathArray const &); + void push_back(MathArray const & ar); /// void pop_back(); /// @@ -109,22 +109,25 @@ public: /// void dump2() const; /// - void substitute(MathMacro const &); - /// looks for exact match - bool match(MathArray const &) const; - /// looks for inclusion match starting at pos - bool matchpart(MathArray const &, pos_type pos) const; - /// looks for containment - bool contains(MathArray const &) const; + void substitute(MathMacro const & macro); /// void replace(ReplaceData &); + /// looks for exact match + bool match(MathArray const & ar) const; + /// looks for inclusion match starting at pos + bool matchpart(MathArray const & ar, pos_type pos) const; + /// looks for containment, return == size mean not found + size_type find(MathArray const & ar) const; + /// looks for containment, return == size mean not found + size_type find_last(MathArray const & ar) const; /// - MathAtom & at(size_type pos); - /// - MathAtom const & at(size_type pos) const; - /// - void validate(LaTeXFeatures &) const; + bool contains(MathArray const & ar) const; + + /// write acccess to single atom + MathAtom & operator[](size_type pos) { return at(pos); } + /// read access o single atom + MathAtom const & operator[](size_type pos) const { return at(pos); } /// const_iterator begin() const; /// @@ -134,7 +137,17 @@ public: /// iterator end(); + /// + void validate(LaTeXFeatures &) const; + private: + /// is this an exact match at this position? + bool find1(MathArray const & ar, size_type pos) const; + /// write acccess to single atom + MathAtom & at(size_type pos); + /// read access o single atom + MathAtom const & at(size_type pos) const; + /// Buffer buffer_type bf_; }; diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index 502c640e2d..be0a463790 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -2,9 +2,10 @@ // information" from the unstructered layout-oriented stuff in an // MathArray. -#include +#include #include "math_amsarrayinset.h" +#include "math_arrayinset.h" #include "math_charinset.h" #include "math_deliminset.h" #include "math_diffinset.h" @@ -13,17 +14,24 @@ #include "math_fracinset.h" #include "math_matrixinset.h" #include "math_mathmlstream.h" +#include "math_numberinset.h" #include "math_scriptinset.h" #include "math_stringinset.h" #include "math_symbolinset.h" #include "math_unknowninset.h" +#include "math_parser.h" #include "Lsstream.h" #include "debug.h" +#include "support/lyxlib.h" +#include "support/systemcall.h" +#include "support/filetools.h" +#include using std::ostream; using std::istringstream; using std::find_if; +using std::endl; ostream & operator<<(ostream & os, MathArray const & ar) @@ -120,12 +128,13 @@ MathScriptInset const * asScript(MathArray::const_iterator it) // returns sequence of char with same code starting at it up to end // it might be less, though... -MathArray::const_iterator charSequence(MathArray::const_iterator it, - MathArray::const_iterator end, string & s) +string charSequence + (MathArray::const_iterator it, MathArray::const_iterator end) { + string s; for (; it != end && (*it)->asCharInset(); ++it) s += (*it)->getChar(); - return it; + return s; } @@ -133,18 +142,11 @@ void extractStrings(MathArray & ar) { //lyxerr << "\nStrings from: " << ar << "\n"; for (MathArray::size_type i = 0; i < ar.size(); ++i) { - MathArray::iterator it = ar.begin() + i; - if (!(*it)->asCharInset()) + if (!ar[i]->asCharInset()) continue; - - // create proper string inset - MathStringInset * p = new MathStringInset; - MathArray::const_iterator - jt = charSequence(it, ar.end(), p->str_); - - // clean up - (*it).reset(p); - ar.erase(i + 1, jt - ar.begin()); + string s = charSequence(ar.begin() + i, ar.end()); + ar[i].reset(new MathStringInset(s)); + ar.erase(i + 1, i + s.size()); } //lyxerr << "\nStrings to: " << ar << "\n"; } @@ -201,20 +203,16 @@ bool extractString(MathInset * p, string & str) // convert this inset somehow to a number bool extractNumber(MathArray const & ar, int & i) { - string s; - charSequence(ar.begin(), ar.end(), s); - istringstream is(s.c_str()); + istringstream is(charSequence(ar.begin(), ar.end()).c_str()); is >> i; return is; } -bool extractNumber(MathArray const & ar, double & i) +bool extractNumber(MathArray const & ar, double & d) { - string s; - charSequence(ar.begin(), ar.end(), s); - istringstream is(s.c_str()); - is >> i; + istringstream is(charSequence(ar.begin(), ar.end()).c_str()); + is >> d; return is; } @@ -345,6 +343,49 @@ void extractExps(MathArray & ar) } +// +// search numbers +// + +bool isDigitOrSimilar(char c) +{ + return ('0' <= c && c <= '9') || c == '.'; +} + + +// returns sequence of digits +string digitSequence + (MathArray::const_iterator it, MathArray::const_iterator end) +{ + string s; + for (; it != end && (*it)->asCharInset(); ++it) { + if (!isDigitOrSimilar((*it)->getChar())) + break; + s += (*it)->getChar(); + } + return s; +} + + +void extractNumbers(MathArray & ar) +{ + //lyxerr << "\nNumbers from: " << ar << "\n"; + for (MathArray::size_type i = 0; i < ar.size(); ++i) { + if (!ar[i]->asCharInset()) + continue; + if (!isDigitOrSimilar(ar[i]->asCharInset()->getChar())) + continue; + + string s = digitSequence(ar.begin() + i, ar.end()); + + ar[i].reset(new MathNumberInset(s)); + ar.erase(i + 1, i + s.size()); + } + //lyxerr << "\nNumbers to: " << ar << "\n"; +} + + + // // search deliminiters // @@ -660,7 +701,7 @@ void extractDiff(MathArray & ar) MathArray::iterator jt = it + 1; //int n = 1; MathArray & numer = f->cell(0); - if (numer.size() > 1 && numer.at(1)->asScriptInset()) { + if (numer.size() > 1 && numer[1]->asScriptInset()) { // this is something like d^n f(x) / d... or d^n / d... // FIXME //n = 1; @@ -716,6 +757,7 @@ void extractDiff(MathArray & ar) void extractStructure(MathArray & ar) { splitScripts(ar); + extractNumbers(ar); extractMatrices(ar); extractDelims(ar); extractFunctions(ar); @@ -813,3 +855,200 @@ void mathmlize(MathArray const & dat, MathMLStream & os) os << ETag("mrow"); } } + + + + +namespace { + + string captureOutput(string const & cmd, string const & data) + { + string outfile = lyx::tempName(string(), "mathextern"); + string full = "echo '" + data + "' | (" + cmd + ") > " + outfile; + lyxerr << "calling: " << full << endl; + Systemcall dummy; + dummy.startscript(Systemcall::Wait, full); + string out = GetFileContents(outfile); + lyx::unlink(outfile); + lyxerr << "result: '" << out << "'" << endl; + return out; + } + + + MathArray pipeThroughMaple(string const & extra, MathArray const & ar) + { + string header = "readlib(latex):\n"; + + // remove the \\it for variable names + //"#`latex/csname_font` := `\\it `:" + header += + "`latex/csname_font` := ``:\n"; + + // export matrices in (...) instead of [...] + header += + "`latex/latex/matrix` := " + "subs(`[`=`(`, `]`=`)`," + "eval(`latex/latex/matrix`)):\n"; + + // replace \\cdots with proper '*' + header += + "`latex/latex/*` := " + "subs(`\\,`=`\\cdot `," + "eval(`latex/latex/*`)):\n"; + + // remove spurious \\noalign{\\medskip} in matrix output + header += + "`latex/latex/matrix`:= " + "subs(`\\\\\\\\\\\\noalign{\\\\medskip}` = `\\\\\\\\`," + "eval(`latex/latex/matrix`)):\n"; + + //"#`latex/latex/symbol` " + // " := subs((\\'_\\' = \\'`\\_`\\',eval(`latex/latex/symbol`)): "; + + string trailer = "quit;"; + ostringstream os; + MapleStream ms(os); + ms << ar; + string expr = os.str().c_str(); + lyxerr << "ar: '" << ar << "'\n"; + + for (int i = 0; i < 100; ++i) { // at most 100 attempts + // try to fix missing '*' the hard way by using mint + // + // ... > echo "1A;" | mint -i 1 -S -s -q + // on line 1: 1A; + // ^ syntax error - + // Probably missing an operator such as * p + // + lyxerr << "checking expr: '" << expr << "'\n"; + string out = captureOutput("mint -i 1 -S -s -q -q", expr + ";"); + if (out.empty()) + break; // expression syntax is ok + istringstream is(out.c_str()); + string line; + getline(is, line); + if (line.find("on line") != 0) + break; // error message not identified + getline(is, line); + string::size_type pos = line.find('^'); + if (pos == string::npos || pos < 15) + break; // caret position not found + pos -= 15; // skip the "on line ..." part + if (expr[pos] == '*' || (pos > 0 && expr[pos - 1] == '*')) + break; // two '*' in a row are definitely bad + expr.insert(pos, "*"); + } + + string full = "latex(" + extra + '(' + expr + "));"; + string out = captureOutput("maple -q", header + full + trailer); + + // change \_ into _ + + // + MathArray res; + mathed_parse_cell(res, out); + return res; + } + + + MathArray pipeThroughOctave(string const &, MathArray const & ar) + { + ostringstream os; + OctaveStream vs(os); + vs << ar; + string expr = os.str().c_str(); + string out; + + lyxerr << "pipe: ar: '" << ar << "'\n"; + lyxerr << "pipe: expr: '" << expr << "'\n"; + + for (int i = 0; i < 100; ++i) { // at most 100 attempts + // + // try to fix missing '*' the hard way + // parse error: + // >>> ([[1 2 3 ];[2 3 1 ];[3 1 2 ]])([[1 2 3 ];[2 3 1 ];[3 1 2 ]]) + // ^ + // + lyxerr << "checking expr: '" << expr << "'\n"; + out = captureOutput("octave -q 2>&1", expr); + lyxerr << "checking out: '" << out << "'\n"; + + // leave loop if expression syntax is probably ok + if (out.find("parse error:") == string::npos) + break; + + // search line with single caret + istringstream is(out.c_str()); + string line; + while (is) { + getline(is, line); + lyxerr << "skipping line: '" << line << "'\n"; + if (line.find(">>> ") != string::npos) + break; + } + + // found line with error, next line is the one with caret + getline(is, line); + string::size_type pos = line.find('^'); + lyxerr << "caret line: '" << line << "'\n"; + lyxerr << "found caret at pos: '" << pos << "'\n"; + if (pos == string::npos || pos < 4) + break; // caret position not found + pos -= 4; // skip the ">>> " part + if (expr[pos] == '*') + break; // two '*' in a row are definitely bad + expr.insert(pos, "*"); + } + + if (out.size() < 6) + return MathArray(); + + // remove 'ans = ' + out = out.substr(6); + + // parse output as matrix or single number + MathAtom at(new MathArrayInset("array", out)); + MathArrayInset const * mat = at.nucleus()->asArrayInset(); + MathArray res; + if (mat->ncols() == 1 && mat->nrows() == 1) + res.push_back(mat->cell(0)); + else { + res.push_back(MathAtom(new MathDelimInset("(", ")"))); + res.back()->cell(0).push_back(at); + } + return res; + } + +} + + +MathArray pipeThroughExtern(string const & lang, string const & extra, + MathArray const & ar) +{ + if (lang == "octave") + return pipeThroughOctave(extra, ar); + + if (lang == "maple") + return pipeThroughMaple(extra, ar); + + // create normalized expression + ostringstream os; + NormalStream ns(os); + os << "[" << extra << ' '; + ns << ar; + os << "]"; + string data = os.str().c_str(); + + // search external script + string file = LibFileSearch("mathed", "extern_" + lang); + if (file.empty()) { + lyxerr << "converter to '" << lang << "' not found\n"; + return MathArray(); + } + + // run external sript + string out = captureOutput(file, data); + MathArray res; + mathed_parse_cell(res, out); + return res; +} diff --git a/src/mathed/math_extern.h b/src/mathed/math_extern.h index 6e7270e8ef..3747827375 100644 --- a/src/mathed/math_extern.h +++ b/src/mathed/math_extern.h @@ -1,6 +1,8 @@ #ifndef MATH_EXTERN_H #define MATH_EXTERN_H +#include "LString.h" + class NormalStream; class MapleStream; class MathMLStream; @@ -17,4 +19,7 @@ void octavize(MathArray const &, OctaveStream &); bool extractNumber(MathArray const & ar, int & i); bool extractNumber(MathArray const & ar, double & i); +MathArray pipeThroughExtern(string const & lang, string const & extra, + MathArray const & ar); + #endif diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index ba9b6457f8..954c3f7652 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -9,7 +9,6 @@ #include "math_decorationinset.h" #include "math_dotsinset.h" #include "math_fontinset.h" -#include "math_funcliminset.h" #include "math_fracinset.h" #include "math_kerninset.h" #include "math_lefteqninset.h" @@ -21,7 +20,6 @@ #include "math_sizeinset.h" #include "math_spaceinset.h" #include "math_splitinset.h" -#include "math_specialcharinset.h" #include "math_sqrtinset.h" #include "math_stackrelinset.h" #include "math_substackinset.h" @@ -32,12 +30,12 @@ #include "math_xymatrixinset.h" #include "math_xyarrowinset.h" - #include "math_metricsinfo.h" #include "debug.h" #include "math_support.h" #include "Lsstream.h" #include "support/filetools.h" // LibFileSearch +#include "frontends/font_loader.h" #include #include @@ -52,9 +50,9 @@ WordList theWordList; struct key_type { /// - char const * name; + string name; /// - char const * inset; + string inset; /// int id; }; @@ -63,44 +61,24 @@ struct key_type { key_type wordlist_array[] = { {"!", "space", 0}, - {"#", "special", 0}, - {"$", "special", 0}, - {"%", "special", 0}, - {"&", "special", 0}, {"(", "begin", LM_OT_SIMPLE}, {")", "end", LM_OT_SIMPLE}, {",", "space", 1}, - {".", "special", 0}, {":", "space", 2}, {";", "space", 3}, - {"Pr", "funclim", 0}, {"[", "begin", LM_OT_EQUATION}, {"]", "end", LM_OT_EQUATION}, - {"_", "special", '_'}, {"acute", "decoration", 0}, - {"arccos", "func", 0}, - {"arcsin", "func", 0}, - {"arctan", "func", 0}, - {"arg", "func", 0}, {"bar", "decoration", 0}, {"begin", "begin", 0}, {"bf", "oldfont", 0}, - {"bmod", "func", 0}, {"breve", "decoration", 0}, {"cal", "oldfont", 0}, {"cdots", "dots", 0}, {"check", "decoration", 0}, - {"cos", "func", 0}, - {"cosh", "func", 0}, - {"cot", "func", 0}, - {"coth", "func", 0}, - {"csc", "func", 0}, {"ddot", "decoration", 0}, {"dddot", "decoration", 0}, {"ddots", "dots", 0}, - {"deg", "func", 0}, - {"det", "funclim", 0}, - {"dim", "func", 0}, {"displaystyle", "style", LM_ST_DISPLAY}, {"dot", "decoration", 0}, {"dotsb", "dots", 0}, @@ -109,25 +87,14 @@ key_type wordlist_array[] = {"dotsm", "dots", 0}, {"dotso", "dots", 0}, {"end", "end", 0}, - {"exp", "func", 0}, {"frak", "font", 0}, - {"gcd", "funclim", 0}, {"grave", "decoration", 0}, {"hat", "decoration", 0}, - {"hom", "func", 0}, - {"inf", "funclim", 0}, {"it", "oldfont", 0}, - {"ker", "func", 0}, {"label", "label", 0}, {"ldots", "dots", 0}, {"left", "left", 0}, - {"lg", "func", 0}, - {"lim", "funclim", 0}, - {"liminf", "funclim", 0}, {"limits", "limit", 1 }, - {"limsup", "funclim", 0}, - {"ln", "func", 0}, - {"log", "func", 0}, {"lyxbox", "box", 0}, {"lyxnegspace", "space", 6}, {"mathbb", "font", 0}, @@ -140,9 +107,7 @@ key_type wordlist_array[] = {"mathrm", "font", 0}, {"mathsf", "font", 0}, {"mathtt", "font", 0}, - {"max", "funclim", 0}, {"mbox", "box", 0}, - {"min", "funclim", 0}, {"newcommand", "newcommand", 0 }, {"nolimits", "limit", -1}, {"nonumber", "nonum", 0}, @@ -158,12 +123,6 @@ key_type wordlist_array[] = {"rm", "oldfont", 0}, {"scriptscriptstyle", "style", LM_ST_SCRIPTSCRIPT}, {"scriptstyle", "style", LM_ST_SCRIPT}, - {"sec", "func", 0}, - {"sin", "func", 0}, - {"sinh", "func", 0}, - {"sup", "funclim", 0}, - {"tan", "func", 0}, - {"tanh", "func", 0}, {"textbf", "font", 1}, {"textit", "font", 1}, {"textmd", "font", 1}, @@ -183,12 +142,29 @@ key_type wordlist_array[] = {"vdots", "dots", 0}, {"vec", "decoration", 0}, {"widehat", "decoration", 0}, - {"widetilde", "decoration", 0}, - {"{", "special", '{'}, - {"}", "special", '}'} + {"widetilde", "decoration", 0} }; +bool math_font_available(string & name) +{ + LyXFont f; + augmentFont(f, name); + + // Do we have the font proper? + if (fontloader.available(f)) + return true; + + // can we fake it? + if (name == "eufrak") { + name = "lyxfakefrak"; + return true; + } + + lyxerr << "font " << name << " not available and I can't fake it\n"; + return false; +} + void readSymbols(string const & filename) { @@ -210,14 +186,24 @@ void readSymbols(string const & filename) continue; // tmp.inset _is_ the fontname here. - if (math_font_available(tmp.inset)) { + // create fallbacks if necessary + if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra=="special") { + lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n"; + tmp.draw = tmp.name; + } else if (math_font_available(tmp.inset)) { + lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n"; tmp.draw += char(charid); - } else { + } else if (fallbackid) { if (tmp.inset == "cmex") - tmp.inset = "lyxsymb"; + tmp.inset = "lyxsymbol"; else - tmp.inset = "lyxboldsymb"; + tmp.inset = "lyxboldsymbol"; + lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n"; tmp.draw += char(fallbackid); + } else { + lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n"; + tmp.draw = tmp.name; + tmp.inset = "lyxredtext"; } if (theWordList.find(tmp.name) != theWordList.end()) @@ -319,19 +305,7 @@ MathAtom createMathInset(string const & s) latexkeys const * l = in_word_set(s); if (l) { string const & inset = l->inset; - lyxerr[Debug::MATHED] << " fount inset: '" << inset << "'\n"; - if (inset == "funclim") - return MathAtom(new MathFuncLimInset(s)); - if (inset == "special") - return MathAtom(new MathSpecialCharInset(s[0])); - if (inset == "lyxsym" || - inset == "cmr" || - inset == "cmsy" || - inset == "cmm" || - inset == "cmex" || - inset == "msa" || - inset == "msb") - return MathAtom(new MathSymbolInset(l)); + lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n"; if (inset == "underset") return MathAtom(new MathUndersetInset); if (inset == "decoration") @@ -348,10 +322,7 @@ MathAtom createMathInset(string const & s) return MathAtom(new MathFontInset(l->name)); if (inset == "oldfont") return MathAtom(new MathFontInset(l->name)); - if (inset == "func") - return MathAtom(new MathUnknownInset(l->name, true, true)); - - return MathAtom(new MathUnknownInset(l->name)); + return MathAtom(new MathSymbolInset(l)); } if (MathMacroTable::has(s)) diff --git a/src/mathed/math_fontinset.C b/src/mathed/math_fontinset.C index b1eb6ba1f7..2d22566541 100644 --- a/src/mathed/math_fontinset.C +++ b/src/mathed/math_fontinset.C @@ -33,25 +33,26 @@ void MathFontInset::metrics(MathMetricsInfo & mi) const { MathFontSetChanger dummy(mi.base, name_.c_str()); xcell(0).metrics(mi); - width_ = xcell(0).width() + 6; ascent_ = xcell(0).ascent(); - descent_ = xcell(0).descent() + 3; + descent_ = xcell(0).descent() + 2; + width_ = xcell(0).width() + 2; } void MathFontInset::draw(MathPainterInfo & pi, int x, int y) const { //lyxerr << "MathFontInset::draw\n"; - MathNestInset::draw(pi, x, y); + //MathNestInset::draw(pi, x, y); MathFontSetChanger dummy(pi.base, name_.c_str()); - xcell(0).draw(pi, x + 3, y); - int b = x + 1; - int t = x + width() - 1; - int d = y + descent(); - pi.pain.line(b, d - 3, b, d, LColor::mathframe); - pi.pain.line(t, d - 3, t, d, LColor::mathframe); - pi.pain.line(b, d, b + 3, d, LColor::mathframe); - pi.pain.line(t - 2, d, t, d, LColor::mathframe); + xcell(0).draw(pi, x + 1, y); + if (editing()) { + int t = x + width() - 1; + int d = y + descent(); + pi.pain.line(x, d - 3, x, d, LColor::mathframe); + pi.pain.line(t, d - 3, t, d, LColor::mathframe); + pi.pain.line(x, d, x + 3, d, LColor::mathframe); + pi.pain.line(t - 2, d, t, d, LColor::mathframe); + } } diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index dbcdece874..65b4868e87 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -28,6 +28,15 @@ string verboseHLine(int n) } +////////////////////////////////////////////////////////////// + + +MathGridInset::CellInfo::CellInfo() + : dummy_(false) +{} + + + ////////////////////////////////////////////////////////////// @@ -60,7 +69,10 @@ MathGridInset::ColInfo::ColInfo() MathGridInset::MathGridInset(char v, string const & h) - : MathNestInset(guessColumns(h)), rowinfo_(2), colinfo_(guessColumns(h) + 1) + : MathNestInset(guessColumns(h)), + rowinfo_(2), + colinfo_(guessColumns(h) + 1), + cellinfo_(1 * guessColumns(h)) { setDefaults(); valign(v); @@ -68,15 +80,34 @@ MathGridInset::MathGridInset(char v, string const & h) } +MathGridInset::MathGridInset() + : MathNestInset(1), + rowinfo_(1 + 1), + colinfo_(1 + 1), + cellinfo_(1), + v_align_('c') +{ + setDefaults(); +} + + MathGridInset::MathGridInset(col_type m, row_type n) - : MathNestInset(m * n), rowinfo_(n + 1), colinfo_(m + 1), v_align_('c') + : MathNestInset(m * n), + rowinfo_(n + 1), + colinfo_(m + 1), + cellinfo_(m * n), + v_align_('c') { setDefaults(); } MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h) - : MathNestInset(m * n), rowinfo_(n + 1), colinfo_(m + 1), v_align_(v) + : MathNestInset(m * n), + rowinfo_(n + 1), + colinfo_(m + 1), + cellinfo_(m * n), + v_align_(v) { setDefaults(); valign(v); @@ -355,23 +386,23 @@ void MathGridInset::metrics(MathMetricsInfo & mi) const } -void MathGridInset::draw(MathPainterInfo & pain, int x, int y) const +void MathGridInset::draw(MathPainterInfo & pi, int x, int y) const { for (idx_type idx = 0; idx < nargs(); ++idx) - xcell(idx).draw(pain, x + cellXOffset(idx), y + cellYOffset(idx)); + xcell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx)); for (row_type row = 0; row <= nrows(); ++row) for (int i = 0; i < rowinfo_[row].lines_; ++i) { int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_ - i * hlinesep() - hlinesep()/2 - rowsep()/2; - pain.pain.line(x + 1, yy, x + width_ - 1, yy); + pi.pain.line(x + 1, yy, x + width_ - 1, yy); } for (col_type col = 0; col <= ncols(); ++col) for (int i = 0; i < colinfo_[col].lines_; ++i) { int xx = x + colinfo_[col].offset_ - i * vlinesep() - vlinesep()/2 - colsep()/2; - pain.pain.line(xx, y - ascent_ + 1, xx, y + descent_ - 1); + pi.pain.line(xx, y - ascent_ + 1, xx, y + descent_ - 1); } } @@ -507,7 +538,10 @@ string MathGridInset::eocString(col_type col) const void MathGridInset::addRow(row_type row) { rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo()); - cells_.insert(cells_.begin() + (row + 1) * ncols(), ncols(), MathXArray()); + cells_.insert + (cells_.begin() + (row + 1) * ncols(), ncols(), MathXArray()); + cellinfo_.insert + (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo()); } @@ -515,8 +549,10 @@ void MathGridInset::appendRow() { rowinfo_.push_back(RowInfo()); //cells_.insert(cells_.end(), ncols(), MathXArray()); - for (col_type col = 0; col < ncols(); ++col) + for (col_type col = 0; col < ncols(); ++col) { cells_.push_back(cells_type::value_type()); + cellinfo_.push_back(CellInfo()); + } } @@ -528,6 +564,9 @@ void MathGridInset::delRow(row_type row) cells_type::iterator it = cells_.begin() + row * ncols(); cells_.erase(it, it + ncols()); + vector::iterator jt = cellinfo_.begin() + row * ncols(); + cellinfo_.erase(jt, jt + ncols()); + rowinfo_.erase(rowinfo_.begin() + row); } @@ -537,12 +576,17 @@ void MathGridInset::addCol(col_type newcol) const col_type nc = ncols(); const row_type nr = nrows(); cells_type new_cells((nc + 1) * nr); + vector new_cellinfo((nc + 1) * nr); for (row_type row = 0; row < nr; ++row) - for (col_type col = 0; col < nc; ++col) + for (col_type col = 0; col < nc; ++col) { new_cells[row * (nc + 1) + col + (col > newcol)] = cells_[row * nc + col]; + new_cellinfo[row * (nc + 1) + col + (col > newcol)] + = cellinfo_[row * nc + col]; + } swap(cells_, new_cells); + swap(cellinfo_, new_cellinfo); ColInfo inf; inf.skip_ = defaultColSpace(newcol); @@ -557,10 +601,14 @@ void MathGridInset::delCol(col_type col) return; cells_type tmpcells; + vector tmpcellinfo; for (col_type i = 0; i < nargs(); ++i) - if (i % ncols() != col) + if (i % ncols() != col) { tmpcells.push_back(cells_[i]); + tmpcellinfo.push_back(cellinfo_[i]); + } swap(cells_, tmpcells); + swap(cellinfo_, tmpcellinfo); colinfo_.erase(colinfo_.begin() + col); } @@ -813,8 +861,11 @@ void MathGridInset::write(WriteStream & os) const os << eolString(row); } string const s = verboseHLine(rowinfo_[nrows()].lines_); - if (!s.empty() && s != " ") + if (!s.empty() && s != " ") { + if (os.fragile()) + os << "\\protect"; os << "\\\\" << s; + } } @@ -846,3 +897,4 @@ int MathGridInset::border() const { return 1; } + diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 45c824ec39..170748844b 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -18,6 +18,16 @@ class MathGridInset : public MathNestInset { + /// additional per-cell information + struct CellInfo { + /// + CellInfo(); + /// a dummy cell before a multicolumn cell + int dummy_; + /// special multi colums alignment + string align_; + }; + /// additional per-row information struct RowInfo { /// @@ -61,6 +71,8 @@ class MathGridInset : public MathNestInset { }; public: + /// sets nrows and ncols to 1 + MathGridInset(); /// constructor from columns description, creates one row MathGridInset(char valign, string const & halign); /// Note: columns first! @@ -99,6 +111,10 @@ public: const RowInfo & rowinfo(row_type row) const; /// returns topmost row if passed (-1) RowInfo & rowinfo(row_type row); + /// + const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; } + /// + CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; } /// identifies GridInset virtual MathGridInset * asGridInset() { return this; } @@ -197,6 +213,8 @@ protected: std::vector rowinfo_; /// column info std::vector colinfo_; + /// cell info + std::vector cellinfo_; /// char v_align_; // add approp. type }; diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 88850070c6..ac79102345 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -125,6 +125,22 @@ MathInset * MathHullInset::clone() const } +bool MathHullInset::idxFirst(idx_type & idx, pos_type & pos) const +{ + idx = 0; + pos = 0; + return true; +} + + +bool MathHullInset::idxLast(idx_type & idx, pos_type & pos) const +{ + idx = nargs() - 1; + pos = cell(idx).size(); + return true; +} + + char MathHullInset::defaultColAlign(col_type col) { switch (getType()) { diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 8202b807bc..c9d90deb1c 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -75,6 +75,10 @@ public: int defaultColSpace(col_type col); /// char defaultColAlign(col_type col); + /// + bool idxFirst(idx_type &, pos_type &) const; + /// + bool idxLast(idx_type &, pos_type &) const; /// MathInsetTypes getType() const; diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 379820f7f1..30396bad66 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -54,7 +54,6 @@ class MathBoxInset; class MathCharInset; class MathDelimInset; class MathFontInset; -class MathFuncInset; class MathGridInset; class MathFracInset; class MathHullInset; @@ -194,7 +193,6 @@ public: virtual MathDelimInset * asDelimInset() { return 0; } virtual MathDelimInset const * asDelimInset() const { return 0; } virtual MathFontInset const * asFontInset() const { return 0; } - virtual MathFuncInset * asFuncInset() { return 0; } virtual MathFracInset * asFracInset() { return 0; } virtual MathGridInset * asGridInset() { return 0; } virtual MathHullInset * asHullInset() { return 0; } diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 3983db44c7..b2d9655a43 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -145,11 +145,14 @@ void MathNestInset::dump() const } -void MathNestInset::draw(MathPainterInfo & pi, int x, int y) const +//void MathNestInset::draw(MathPainterInfo & pi, int x, int y) const +void MathNestInset::draw(MathPainterInfo &, int, int) const { +#if 0 if (lock_) pi.pain.fillRectangle(x, y - ascent(), width(), height(), LColor::mathlockbg); +#endif } @@ -209,3 +212,12 @@ bool MathNestInset::isActive() const { return nargs() > 0; } + + +MathArray MathNestInset::glue() const +{ + MathArray ar; + for (unsigned i = 0; i < nargs(); ++i) + ar.push_back(cell(i)); + return ar; +} diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 52e2c227b3..5d49d39d2a 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -76,6 +76,8 @@ public: void replace(ReplaceData &); /// do we contain a given pattern? bool contains(MathArray const &); + /// glue everything to a single cell + MathArray glue() const; /// debug helper void dump() const; diff --git a/src/mathed/math_notinset.C b/src/mathed/math_notinset.C index b341a1c6e1..1ad2594ce7 100644 --- a/src/mathed/math_notinset.C +++ b/src/mathed/math_notinset.C @@ -29,13 +29,13 @@ void MathNotInset::normalize(NormalStream & os) const void MathNotInset::metrics(MathMetricsInfo & mi) const { font_ = mi.base.font; - if (math_font_available("cmsy")) { - augmentFont(font_, "cmsy"); - char_ = 54; - } else { +// if (math_font_available("cmsy")) { +// augmentFont(font_, "cmsy"); +// char_ = 54; +// } else { augmentFont(font_, "mathnormal"); char_ = '/'; - } +// } mathed_char_dim(font_, char_, ascent_, descent_, width_); width_ = 0; } diff --git a/src/mathed/math_numberinset.C b/src/mathed/math_numberinset.C new file mode 100644 index 0000000000..fe22f8da8b --- /dev/null +++ b/src/mathed/math_numberinset.C @@ -0,0 +1,65 @@ +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "math_numberinset.h" +#include "math_mathmlstream.h" +#include "math_streamstr.h" +#include "math_support.h" +#include "debug.h" + + +MathNumberInset::MathNumberInset(string const & s) + : str_(s) +{} + + +MathInset * MathNumberInset::clone() const +{ + return new MathNumberInset(*this); +} + + +void MathNumberInset::metrics(MathMetricsInfo & mi) const +{ + mathed_string_dim(mi.base.font, str_, ascent_, descent_, width_); +} + + +void MathNumberInset::draw(MathPainterInfo & pi, int x, int y) const +{ + //lyxerr << "drawing '" << str_ << "' code: " << code_ << endl; + drawStr(pi, pi.base.font, x, y, str_); +} + + +void MathNumberInset::normalize(NormalStream & os) const +{ + os << "[number " << str_ << "]"; +} + + +void MathNumberInset::maplize(MapleStream & os) const +{ + os << str_; +} + + +void MathNumberInset::octavize(OctaveStream & os) const +{ + os << str_; +} + + +void MathNumberInset::mathmlize(MathMLStream & os) const +{ + os << " " << str_ << " "; +} + + +void MathNumberInset::write(WriteStream & os) const +{ + os << str_; +} diff --git a/src/mathed/math_numberinset.h b/src/mathed/math_numberinset.h new file mode 100644 index 0000000000..6c2a5c7ce5 --- /dev/null +++ b/src/mathed/math_numberinset.h @@ -0,0 +1,46 @@ +// -*- C++ -*- +#ifndef MATH_NUMBERINSET_H +#define MATH_NUMBERINSET_H + +#include "math_diminset.h" + +#ifdef __GNUG__ +#pragma interface +#endif + +/** Some inset that "is" a number + * maily for math-extern + * \author André Pönitz + */ + +class MathNumberInset : public MathDimInset { +public: + /// + explicit MathNumberInset(string const & s); + /// + MathInset * clone() const; + /// + void metrics(MathMetricsInfo & st) const; + /// + void draw(MathPainterInfo &, int x, int y) const; + /// + string str() const { return str_; } + /// + MathNumberInset * asNumberInset() { return this; } + + /// + void normalize(NormalStream &) const; + /// + void octavize(OctaveStream &) const; + /// + void maplize(MapleStream &) const; + /// + void mathmlize(MathMLStream &) const; + /// + void write(WriteStream & os) const; + +private: + /// the number as string + string str_; +}; +#endif diff --git a/src/mathed/math_parser.C b/src/mathed/math_parser.C index 804263fedc..bce39fe1e8 100644 --- a/src/mathed/math_parser.C +++ b/src/mathed/math_parser.C @@ -4,9 +4,9 @@ /* -If someone desperately needs partial "structures" (such as a few cells of -an array inset or similar) (s)he could uses the following hack as starting -point to write some macros: +If someone desperately needs partial "structures" (such as a few +cells of an array inset or similar) (s)he could uses the +following hack as starting point to write some macros: \newif\ifcomment \commentfalse @@ -43,6 +43,7 @@ point to write some macros: #include "math_boxinset.h" #include "math_charinset.h" #include "math_deliminset.h" +#include "math_extern.h" #include "math_factory.h" #include "math_kerninset.h" #include "math_macro.h" @@ -53,7 +54,6 @@ point to write some macros: #include "math_sizeinset.h" #include "math_sqrtinset.h" #include "math_scriptinset.h" -#include "math_specialcharinset.h" #include "math_sqrtinset.h" #include "math_support.h" #include "math_xyarrowinset.h" @@ -76,6 +76,7 @@ using std::fill; using std::vector; using std::atoi; + //#define FILEDEBUG @@ -124,18 +125,16 @@ inline CatCode catcode(unsigned char c) enum { - FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing process + FLAG_BRACE_LAST = 1 << 1, // last closing brace ends the parsing FLAG_RIGHT = 1 << 2, // next \\right ends the parsing process FLAG_END = 1 << 3, // next \\end ends the parsing process - FLAG_BRACK_END = 1 << 4, // next closing bracket ends the parsing process - FLAG_TEXTMODE = 1 << 5, // we are in a box + FLAG_BRACK_END = 1 << 4, // next closing bracket ends the parsing + FLAG_TEXTMODE = 1 << 5, // we are in a box FLAG_ITEM = 1 << 6, // read a (possibly braced token) - FLAG_BLOCK = 1 << 7, // next block ends the parsing process - FLAG_BLOCK2 = 1 << 8, // next block2 ends the parsing process - FLAG_LEAVE = 1 << 9, // leave the loop at the end - FLAG_SIMPLE = 1 << 10, // next $ leaves the loop - FLAG_EQUATION = 1 << 11, // next \] leaves the loop - FLAG_SIMPLE2 = 1 << 12 // next \) leaves the loop + FLAG_LEAVE = 1 << 7, // leave the loop at the end + FLAG_SIMPLE = 1 << 8, // next $ leaves the loop + FLAG_EQUATION = 1 << 9, // next \] leaves the loop + FLAG_SIMPLE2 = 1 << 10 // next \) leaves the loop }; @@ -719,7 +718,6 @@ void Parser::parse_into2(MathAtom & at, unsigned flags, bool numbered) void Parser::parse_into1(MathGridInset & grid, unsigned flags, bool numbered) { - bool panic = false; int limits = 0; MathGridInset::row_type cellrow = 0; MathGridInset::col_type cellcol = 0; @@ -756,21 +754,6 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags, bool numbered) flags |= FLAG_LEAVE; } - if (flags & FLAG_BLOCK) { - if (t.cat() == catAlign || t.isCR() || t.cs() == "end") { - putback(); - return; - } - } - - if (flags & FLAG_BLOCK2) { - if (t.cat() == catAlign || t.isCR() || t.cs() == "end" - || t.cat() == catEnd) { - putback(); - return; - } - } - // // cat codes // @@ -873,8 +856,17 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags, bool numbered) // ignore \\protect, will be re-added during output ; - else if (t.cs() == "end") - break; + else if (t.cs() == "end") { + if (flags & FLAG_END) { + // eat environment name + //string const name = + getArg('{', '}'); + // FIXME: check that we ended the correct environment + return; + } + lyxerr << "found 'end' unexpectedly, cell: '" << cell << "'\n"; + dump(); + } else if (t.cs() == ")") break; @@ -893,6 +885,39 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags, bool numbered) cell = &grid.cell(grid.index(cellrow, cellcol)); } +#if 1 + else if (t.cs() == "multicolumn") { + // extract column count and insert dummy cells + MathArray count; + parse_into(count, FLAG_ITEM); + int cols = 1; + if (!extractNumber(count, cols)) { + lyxerr << " can't extract number of cells from " << count << "\n"; + } + // resize the table if necessary + for (int i = 0; i < cols; ++i) { + ++cellcol; + if (cellcol == grid.ncols()) { + lyxerr << "adding column " << cellcol << "\n"; + grid.addCol(cellcol - 1); + } + cell = &grid.cell(grid.index(cellrow, cellcol)); + // mark this as dummy + grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = true; + } + // the last cell is the real thng, not a dummy + grid.cellinfo(grid.index(cellrow, cellcol)).dummy_ = false; + + // read special alignment + MathArray align; + parse_into(align, FLAG_ITEM); + //grid.cellinfo(grid.index(cellrow, cellcol)).align_ = extractString(align); + + // parse the remaining contents into the "real" cell + parse_into(*cell, FLAG_ITEM); + } +#endif + else if (t.cs() == "limits") limits = 1; @@ -1086,15 +1111,6 @@ void Parser::parse_into1(MathGridInset & grid, unsigned flags, bool numbered) break; } } - - if (panic) { - lyxerr << " Math Panic, expect problems!\n"; - // Search for the end command. - Token t; - do { - t = getToken(); - } while (good() && t.cs() != "end"); - } } diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index e58b4cbabc..47cb5deec8 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -185,10 +185,10 @@ void MathScriptInset::metrics(MathMetricsInfo & mi) const void MathScriptInset::metrics(MathInset const * nuc, MathMetricsInfo & mi) const { - MathScriptChanger dummy(mi.base); - MathNestInset::metrics(mi); if (nuc) nuc->metrics(mi); + MathNestInset::metrics(mi); + MathScriptChanger dummy(mi.base); ascent_ = ascent2(nuc); descent_ = descent2(nuc); width_ = width2(nuc); @@ -198,11 +198,26 @@ void MathScriptInset::metrics(MathInset const * nuc, MathMetricsInfo & mi) const void MathScriptInset::draw(MathPainterInfo & pi, int x, int y) const { //lyxerr << "unexpected call to MathScriptInset::draw()\n"; - MathScriptChanger dummy(pi.base); draw(0, pi, x, y); } +void MathScriptInset::draw(MathInset const * nuc, MathPainterInfo & pi, + int x, int y) const +{ + if (nuc) + nuc->draw(pi, x + dxx(nuc), y); + else if (editing()) + drawStr(pi, font_, x + dxx(nuc), y, "."); + + MathScriptChanger dummy(pi.base); + if (hasUp()) + up().draw(pi, x + dx1(nuc), y - dy1(nuc)); + if (hasDown()) + down().draw(pi, x + dx0(nuc), y + dy0(nuc)); +} + + void MathScriptInset::metricsT(TextMetricsInfo const & mi) const { metricsT(0, mi); @@ -224,22 +239,6 @@ void MathScriptInset::metricsT(MathInset const * nuc, } -void MathScriptInset::draw(MathInset const * nuc, MathPainterInfo & pi, - int x, int y) const -{ - MathScriptChanger dummy(pi.base); - if (nuc) - nuc->draw(pi, x + dxx(nuc), y); - else if (editing()) - drawStr(pi, font_, x + dxx(nuc), y, "."); - - if (hasUp()) - up().draw(pi, x + dx1(nuc), y - dy1(nuc)); - if (hasDown()) - down().draw(pi, x + dx0(nuc), y + dy0(nuc)); -} - - void MathScriptInset::drawT(TextPainter & pain, int x, int y) const { //lyxerr << "unexpected call to MathScriptInset::draw()\n"; diff --git a/src/mathed/math_stringinset.C b/src/mathed/math_stringinset.C index bb381f340c..220ee4013a 100644 --- a/src/mathed/math_stringinset.C +++ b/src/mathed/math_stringinset.C @@ -14,10 +14,6 @@ #include "debug.h" -MathStringInset::MathStringInset() - : str_() -{} - MathStringInset::MathStringInset(string const & s) : str_(s) {} diff --git a/src/mathed/math_stringinset.h b/src/mathed/math_stringinset.h index 54021486bb..e627bea1d9 100644 --- a/src/mathed/math_stringinset.h +++ b/src/mathed/math_stringinset.h @@ -8,14 +8,13 @@ #pragma interface #endif -/** Some cllection of chars with similar properties - \author André Pönitz +/** Some collection of chars with similar properties + * maily for math-extern + * \author André Pönitz */ class MathStringInset : public MathDimInset { public: - /// - MathStringInset(); /// explicit MathStringInset(string const & s); /// @@ -40,7 +39,7 @@ public: /// void write(WriteStream & os) const; -public: +private: /// the string string str_; }; diff --git a/src/mathed/math_support.C b/src/mathed/math_support.C index 89fd9e2913..3cd524e059 100644 --- a/src/mathed/math_support.C +++ b/src/mathed/math_support.C @@ -4,13 +4,13 @@ #include "math_support.h" #include "lyxfont.h" -#include "frontends/font_loader.h" -#include "frontends/font_metrics.h" #include "math_cursor.h" #include "math_defs.h" #include "math_inset.h" #include "math_parser.h" #include "frontends/Painter.h" +#include "frontends/font_metrics.h" +#include "frontends/font_loader.h" #include "debug.h" #include "commandtags.h" @@ -57,7 +57,7 @@ namespace { /* * Internal struct of a drawing: code n x1 y1 ... xn yn, where code is: - * 0 = end, 1 = line, 2 = polyline, 3 = square line, 4= square polyline + * 0 = end, 1 = line, 2 = polyline, 3 = square line, 4 = square polyline */ @@ -570,6 +570,7 @@ fontinfo fontinfos[] = { {"eufrak", LyXFont::EUFRAK_FAMILY, def_series, def_shape, LColor::math}, {"mathbf", def_family, LyXFont::BOLD_SERIES, def_shape, LColor::math}, {"mathcal",LyXFont::CMSY_FAMILY, def_series, def_shape, LColor::math}, + {"mathfrak", LyXFont::EUFRAK_FAMILY, def_series, def_shape, LColor::math}, {"mathnormal", def_family,def_series, LyXFont::UP_SHAPE, LColor::math}, {"mathrm", LyXFont::ROMAN_FAMILY, def_series, def_shape, LColor::math}, {"mathsf", LyXFont::SANS_FAMILY, def_series, def_shape, LColor::math}, @@ -588,7 +589,21 @@ fontinfo fontinfos[] = { {"lyxtex", def_family, def_series, def_shape, LColor::latex}, {"lyxsymbol", LyXFont::SYMBOL_FAMILY, def_series, def_shape, LColor::math}, - {"lyxitsymbol", LyXFont::SYMBOL_FAMILY, def_series, LyXFont::ITALIC_SHAPE, LColor::math}, + {"lyxboldsymbol", + LyXFont::SYMBOL_FAMILY, LyXFont::BOLD_SERIES, def_shape, LColor::math}, + {"lyxitsymbol", LyXFont::SYMBOL_FAMILY, + def_series, LyXFont::ITALIC_SHAPE, LColor::math}, + {"lyxredtext", LyXFont::ROMAN_FAMILY, + LyXFont::MEDIUM_SERIES, LyXFont::UP_SHAPE, LColor::red}, + {"lyxblacktext", LyXFont::ROMAN_FAMILY, + LyXFont::MEDIUM_SERIES, LyXFont::UP_SHAPE, LColor::black}, + + {"lyxfakebb", LyXFont::TYPEWRITER_FAMILY, LyXFont::BOLD_SERIES, + LyXFont::UP_SHAPE, LColor::math}, + {"lyxfakecal", LyXFont::SANS_FAMILY, LyXFont::MEDIUM_SERIES, + LyXFont::ITALIC_SHAPE, LColor::math}, + {"lyxfakefrak", LyXFont::ROMAN_FAMILY, LyXFont::BOLD_SERIES, + LyXFont::ITALIC_SHAPE, LColor::math} }; @@ -605,58 +620,47 @@ fontinfo * searchFont(string const & name) } +LyXFont getFont(string const & name) +{ + LyXFont font; + augmentFont(font, name); + return font; +} + + +void fakeFont(string const & orig, string const & fake) +{ + fontinfo * forig = searchFont(orig); + fontinfo * ffake = searchFont(fake); + if (forig && ffake) { + forig->family_ = ffake->family_; + forig->series_ = ffake->series_; + forig->shape_ = ffake->shape_; + forig->color_ = ffake->color_; + } else { + lyxerr << "Can't fake font '" << orig << "' with '" << fake << "'\n"; + } +} + void augmentFont(LyXFont & font, string const & name) { static bool initialized = false; - if (!initialized) { initialized = true; - LyXFont f1; - augmentFont(f1, "msb"); - if (!fontloader.available(f1)) { - lyxerr << "faking msb\n"; - fontinfo * info = searchFont("msb"); - info->family_ = LyXFont::TYPEWRITER_FAMILY; - info->series_ = LyXFont::BOLD_SERIES; - } - - LyXFont f2; - augmentFont(f2, "msex"); - if (!fontloader.available(f2)) { - lyxerr << "faking msex\n"; - fontinfo * info = searchFont("msex"); - info->family_ = LyXFont::SANS_FAMILY; - info->series_ = LyXFont::BOLD_SERIES; - info->shape_ = LyXFont::ITALIC_SHAPE; - } - - //{"fakebb", LyXFont::TYPEWRITER_FAMILY, LyXFont::BOLD_SERIES, - // LyXFont::UP_SHAPE, LColor::math}, - //{"fakecal", LyXFont::SANS_FAMILY, LyXFont::MEDIUM_SERIES, - // LyXFont::ITALIC_SHAPE, LColor::math}, - //{"fakefrak", LyXFont::SANS_FAMILY, LyXFont::BOLD_SERIES, - // LyXFont::ITALIC_SHAPE, LColor::math} - + // fake fonts if necessary + if (!fontloader.available(getFont("mathfrak"))) + fakeFont("mathfrak", "lyxfakefrak"); + if (!fontloader.available(getFont("mathcal"))) + fakeFont("mathcal", "lyxfakecal"); } - - fontinfo * info = searchFont(name); if (info->family_ != def_family) font.setFamily(info->family_); - if (info->series_ != def_series) font.setSeries(info->series_); - if (info->shape_ != def_shape) font.setShape(info->shape_); - if (info->color_ != LColor::none) font.setColor(info->color_); } - - -bool math_font_available(string const & /*name*/) -{ - return true; -} diff --git a/src/mathed/math_support.h b/src/mathed/math_support.h index b2e104e730..0ea86a78db 100644 --- a/src/mathed/math_support.h +++ b/src/mathed/math_support.h @@ -39,8 +39,6 @@ void drawChar(MathPainterInfo & pain, void math_font_max_dim(LyXFont const &, int & asc, int & desc); -bool math_font_available(string const & name); - string convertDelimToLatexName(string const & name); void augmentFont(LyXFont & f, string const & cmd); diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 7ff59dc436..57d8d7b2bc 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -48,6 +48,7 @@ void MathSymbolInset::metrics(MathMetricsInfo & mi) const // << "'\n"; MathFontSetChanger dummy(mi.base, sym_->inset.c_str()); mathed_string_dim(mi.base.font, sym_->draw, ascent_, descent_, width_); + // correct height for broken cmex font if (sym_->inset == "cmex") { h_ = 4 * descent_ / 5; ascent_ += h_; @@ -55,7 +56,11 @@ void MathSymbolInset::metrics(MathMetricsInfo & mi) const } if (isRelOp()) width_ += 6; - scriptable_ = (mi.base.style == LM_ST_DISPLAY && sym_->inset == "cmex"); + + scriptable_ = false; + if (mi.base.style == LM_ST_DISPLAY) + if (sym_->inset == "cmex" || sym_->extra == "funclim") + scriptable_ = true; } @@ -86,7 +91,10 @@ bool MathSymbolInset::isScriptable() const bool MathSymbolInset::takesLimits() const { - return sym_->inset == "cmex" || sym_->inset == "lyxboldsymb"; + return + sym_->inset == "cmex" || + sym_->inset == "lyxboldsymb" || + sym_->extra == "funclim"; } diff --git a/src/tabular.C b/src/tabular.C index f8631459c2..d3653e8662 100644 --- a/src/tabular.C +++ b/src/tabular.C @@ -2362,7 +2362,7 @@ int LyXTabular::docbookRow(Buffer const * buf, ostream & os, int row) const } os << ">"; - ret += GetCellInset(cell)->docbook(buf, os); + ret += GetCellInset(cell)->docbook(buf, os, true); os << "\n"; ++cell; } @@ -2371,7 +2371,7 @@ int LyXTabular::docbookRow(Buffer const * buf, ostream & os, int row) const } -int LyXTabular::docBook(Buffer const * buf, ostream & os) const +int LyXTabular::docbook(Buffer const * buf, ostream & os, bool mixcont) const { int ret = 0; diff --git a/src/tabular.h b/src/tabular.h index b3432cfcfe..75f9feacf0 100644 --- a/src/tabular.h +++ b/src/tabular.h @@ -297,7 +297,7 @@ public: /// int latex(Buffer const *, std::ostream &, bool, bool) const; /// - int docBook(Buffer const * buf, std::ostream & os) const; + int docbook(Buffer const * buf, std::ostream & os, bool mixcont) const; /// int ascii(Buffer const *, std::ostream &, int const depth, bool onlydata, unsigned char delim) const; -- 2.39.2