From ee1229d7431f99788d04e99fcd8c57de69b4acaf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Fri, 10 Dec 1999 00:07:59 +0000 Subject: [PATCH] the buffer patch, moved Buffer::text to BufferView, moved Buffer::update(short) to BufferView::update(short), some whitespace changes git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@362 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 32 +- acinclude.m4 | 1 + src/BufferView.C | 674 +++++++++- src/BufferView.h | 15 + src/LyXSendto.C | 2 +- src/LyXView.C | 12 +- src/ParagraphExtra.C | 12 + src/TableLayout.C | 236 +++- src/buffer.C | 352 +++++- src/buffer.h | 38 +- src/bufferlist.C | 54 +- src/insets/figinset.C | 21 +- src/insets/insetbib.C | 5 + src/insets/insetinclude.h | 2 +- src/insets/insetparent.C | 2 +- src/intl.C | 11 +- src/intl.h | 23 +- src/lyx_cb.C | 992 +++++++++++++-- src/lyx_gui_misc.C | 2 +- src/lyx_main.C | 80 +- src/lyx_main.h | 8 +- src/lyxfr1.C | 66 +- src/lyxfunc.C | 2457 ++++++++++++++++++++++++++++++++++--- src/lyxvc.C | 8 +- src/menus.C | 333 ++++- src/minibuffer.C | 2 +- src/trans.C | 6 +- src/trans_mgr.C | 15 +- src/trans_mgr.h | 3 +- src/vc-backend.C | 16 +- src/vspace.C | 4 + 31 files changed, 4993 insertions(+), 491 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3568570682..4541d5b595 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,33 @@ +1999-12-10 Lars Gullik Bjønnes + + * src/buffer.h: removed the two friends from Buffer. Some changes + because of this. Buffer::getFileName and Buffer::setFileName + renamed to Buffer::fileName() and Buffer::fileName(...). + +1999-12-09 Lars Gullik Bjønnes + + * buffer.[Ch], BufferView.[Ch] + other files: Moved Buffer::text + and Buffer::update(short) to BufferView. This move is currently + controlled by a define MOVE_TEXT, this will be removed when all + shows to be ok. This move paves the way for better separation + between buffer contents and buffer view. One side effect is that + the BufferView needs a rebreak when swiching buffers, if we want + to avoid this we can add a cache that holds pointers to LyXText's + that is not currently in use. + + * buffer.[Ch], lyx_main.C: small changes to the "-export" patch by + André Pönitz. + +1999-11-18 André Pönitz + + * buffer.[Ch]: Dispatch() - new dispatcher on the buffer level + + * lyx_main.C: new command line option -x (or --execute) and + -e (or --export). Now direct conversion from .lyx to .tex + (.dvi, .ps, ...) is possible ('lyx file.lyx --export latex') + Unfortunately, X is still needed and the GUI pops up during the + process... + 1999-12-07 Jean-Marc Lasgouttes * src/Spacing.C: add a using directive to bring stream stuff into @@ -400,7 +430,7 @@ * lib/reLyX/configure.in: make sure that the prefix is set correctly in LYX_DIR. -1999-11-18 Andre' Poenitz +1999-11-18 André Pönitz * src/commandtags.h: introduction of a new tag 'LFUN_SEQUENCE' to be used by 'command-sequence' this allows to bind a key to a diff --git a/acinclude.m4 b/acinclude.m4 index a48ff69764..f0712c8862 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -184,6 +184,7 @@ dnl Check the version of g++ elif test $ac_cv_prog_cxx_g = yes; then case $gxx_version in 2.7*) CXXFLAGS="$lyx_opt";; + 2.95.1) CXXFLAGS="-g $lyx_opt -fpermissive";; 2.95.*) CXXFLAGS="-g $lyx_opt";; *) CXXFLAGS="-g $lyx_opt -fno-exceptions -fno-rtti";; esac diff --git a/src/BufferView.C b/src/BufferView.C index 1db4d7fd70..9f051925fc 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -55,6 +55,7 @@ extern void ToggleFloat(); extern void MenuPasteSelection(char at); extern InsetUpdateStruct *InsetUpdateList; extern void UpdateInsetUpdateList(); +extern void FreeUpdateTimer(); // This is _very_ temporary FL_OBJECT * figinset_canvas; @@ -64,7 +65,9 @@ BufferView::BufferView(LyXView *o, int xpos, int ypos, : owner_(o) { buffer_ = 0; - +#ifdef MOVE_TEXT + text = 0; +#endif screen = 0; work_area = 0; figinset_canvas = 0; @@ -82,12 +85,22 @@ BufferView::BufferView(LyXView *o, int xpos, int ypos, } +BufferView::~BufferView() +{ +#ifdef MOVE_TEXT + delete text; +#endif +} + + void BufferView::buffer(Buffer *b) { lyxerr[Debug::INFO] << "Setting buffer in BufferView" << endl; if (buffer_) { buffer_->InsetSleep(); buffer_->delUser(this); + delete text; + text = 0; } // Set current buffer @@ -110,12 +123,21 @@ void BufferView::buffer(Buffer *b) buffer_->addUser(this); owner_->getMenus()->showMenus(); // If we don't have a text object for this, we make one +#ifdef MOVE_TEXT + if (text == 0) + resizeCurrentBuffer(); + else { + updateScreen(); + updateScrollbar(); + } +#else if (buffer_->text == 0) resizeCurrentBuffer(); else { updateScreen(); updateScrollbar(); } +#endif screen->first = screen->TopCursorVisible(); redraw(); updateAllVisibleBufferRelatedPopups(); @@ -138,12 +160,21 @@ void BufferView::updateScreen() // Regenerate the screen. if (screen) delete screen; +#ifdef MOVE_TEXT + screen = new LyXScreen(FL_ObjWin(work_area), + work_area->w, + work_area->h, + work_area->x, + work_area->y, + text); +#else screen = new LyXScreen(FL_ObjWin(work_area), work_area->w, work_area->h, work_area->x, work_area->y, buffer_->text); +#endif } @@ -199,8 +230,13 @@ void BufferView::updateScrollbar() long cbth = 0; long cbsf = 0; +#ifdef MOVE_TEXT + if (text) + cbth = text->height; +#else if (buffer_->text) cbth = buffer_->text->height; +#endif if (screen) cbsf = screen->first; @@ -230,16 +266,20 @@ void BufferView::updateScrollbar() fl_set_slider_bounds(scrollbar, 0, maximum_height - work_area->h); #if FL_REVISION > 85 +#ifdef MOVE_TEXT + double lineh = text->DefaultHeight(); +#else double lineh = buffer_->text->DefaultHeight(); +#endif fl_set_slider_increment(scrollbar, work_area->h-lineh, lineh); #endif - if (maxfloat>0){ - if ((hfloat/maxfloat) * float(height2) < 3) + if (maxfloat > 0){ + if ((hfloat / maxfloat) * float(height2) < 3) fl_set_slider_size(scrollbar, - 3/float(height2)); + 3 / float(height2)); else fl_set_slider_size(scrollbar, - hfloat/maxfloat); + hfloat / maxfloat); } else fl_set_slider_size(scrollbar, hfloat); fl_set_slider_precision(scrollbar, 0); @@ -249,10 +289,17 @@ void BufferView::updateScrollbar() void BufferView::redoCurrentBuffer() { lyxerr[Debug::INFO] << "BufferView::redoCurrentBuffer" << endl; +#ifdef MOVE_TEXT + if (text) { + resize(); + owner_->updateLayoutChoice(); + } +#else if (buffer_ && buffer_->text) { resize(); owner_->updateLayoutChoice(); } +#endif } @@ -273,6 +320,20 @@ int BufferView::resizeCurrentBuffer() owner_->getMiniBuffer()->Set(_("Formatting document...")); +#ifdef MOVE_TEXT + if (text) { + par = text->cursor.par; + pos = text->cursor.pos; + selstartpar = text->sel_start_cursor.par; + selstartpos = text->sel_start_cursor.pos; + selendpar = text->sel_end_cursor.par; + selendpos = text->sel_end_cursor.pos; + selection = text->selection; + mark_set = text->mark_set; + delete text; + } + text = new LyXText(work_area->w, buffer_); +#else if (buffer_->text) { par = buffer_->text->cursor.par; pos = buffer_->text->cursor.pos; @@ -285,9 +346,32 @@ int BufferView::resizeCurrentBuffer() delete buffer_->text; } buffer_->text = new LyXText(work_area->w, buffer_); +#endif updateScreen(); - + +#ifdef MOVE_TEXT + if (par) { + text->selection = true; + /* at this point just + * to avoid the Delete- + * Empty-Paragraph + * Mechanism when + * setting the cursor */ + text->mark_set = mark_set; + if (selection) { + text->SetCursor(selstartpar, selstartpos); + text->sel_cursor = text->cursor; + text->SetCursor(selendpar, selendpos); + text->SetSelection(); + text->SetCursor(par, pos); + } else { + text->SetCursor(par, pos); + text->sel_cursor = text->cursor; + text->selection = false; + } + } +#else if (par) { buffer_->text->selection = true; /* at this point just @@ -308,6 +392,7 @@ int BufferView::resizeCurrentBuffer() buffer_->text->selection = false; } } +#endif screen->first = screen->TopCursorVisible(); /* this will scroll the * screen such that the * cursor becomes @@ -331,9 +416,33 @@ void BufferView::gotoError() screen->HideCursor(); BeforeChange(); +#ifdef MOVE_TEXT + update(-2); +#else buffer_->update(-2); +#endif LyXCursor tmp; - + +#ifdef MOVE_TEXT + if (!text->GotoNextError()) { + if (text->cursor.pos + || text->cursor.par != text->FirstParagraph()) { + tmp = text->cursor; + text->cursor.par = text->FirstParagraph(); + text->cursor.pos = 0; + if (!text->GotoNextError()) { + text->cursor = tmp; + owner_->getMiniBuffer()->Set(_("No more errors")); + LyXBell(); + } + } else { + owner_->getMiniBuffer()->Set(_("No more errors")); + LyXBell(); + } + } + update(0); + text->sel_cursor = text->cursor; +#else if (!buffer_->text->GotoNextError()) { if (buffer_->text->cursor.pos || buffer_->text->cursor.par != @@ -355,6 +464,7 @@ void BufferView::gotoError() buffer_->update(0); buffer_->text->sel_cursor = buffer_->text->cursor; +#endif } @@ -563,7 +673,11 @@ void BufferView::ScrollCB(FL_OBJECT * ob, long) view->screen->Draw(view->current_scrollbar_value); if (cursor_follows_scrollbar) { +#ifdef MOVE_TEXT + LyXText * vbt = view->text; +#else LyXText * vbt = view->buffer_->text; +#endif int height = vbt->DefaultHeight(); if (vbt->cursor.y < view->screen->first + height) { @@ -617,13 +731,22 @@ int BufferView::ScrollUp(long time) if (value == 0) return 0; + +#ifdef MOVE_TEXT + float add_value = (text->DefaultHeight() + + float(time) * float(time) * 0.125); + if (add_value > work_area->h) + add_value = float(work_area->h - + text->DefaultHeight()); +#else float add_value = (buffer_->text->DefaultHeight() + float(time) * float(time) * 0.125); if (add_value > work_area->h) add_value = float(work_area->h - buffer_->text->DefaultHeight()); +#endif value -= add_value; @@ -649,13 +772,22 @@ int BufferView::ScrollDown(long time) if (value == max) return 0; + +#ifdef MOVE_TEXT + float add_value = (text->DefaultHeight() + + float(time) * float(time) * 0.125); + if (add_value > work_area->h) + add_value = float(work_area->h - + text->DefaultHeight()); +#else float add_value = (buffer_->text->DefaultHeight() + float(time) * float(time) * 0.125); if (add_value > work_area->h) add_value = float(work_area->h - buffer_->text->DefaultHeight()); +#endif value += add_value; @@ -678,8 +810,11 @@ void BufferView::ScrollUpOnePage(long /*time*/) long y = screen->first; if (!y) return; - - Row* row = buffer_->text->GetRowNearY(y); +#ifdef MOVE_TEXT + Row * row = text->GetRowNearY(y); +#else + Row * row = buffer_->text->GetRowNearY(y); +#endif y = y - work_area->h + row->height; fl_set_slider_value(scrollbar, y); @@ -697,13 +832,20 @@ void BufferView::ScrollDownOnePage(long /*time*/) double min, max; fl_get_slider_bounds(scrollbar, &min, &max); long y = screen->first; + +#ifdef MOVE_TEXT + if (y > text->height - work_area->h) + return; + y += work_area->h; + text->GetRowNearY(y); +#else if (y > buffer_->text->height - work_area->h) return; y += work_area->h; buffer_->text->GetRowNearY(y); - +#endif fl_set_slider_value(scrollbar, y); ScrollCB(scrollbar, 0); @@ -778,12 +920,20 @@ int BufferView::work_area_handler(FL_OBJECT * ob, int event, if (view->buffer_ && !view->buffer_->the_locking_inset) { if (view->screen && ev->xbutton.button == 1) { view->screen->HideCursor(); - view->screen->ToggleSelection(); + view->screen->ToggleSelection(); +#ifdef MOVE_TEXT + view->text->SelectWord(); +#else view->buffer_->text->SelectWord(); +#endif view->screen->ToggleSelection(false); /* This will fit the cursor on the screen - * if necessary */ - view->buffer_->update(0); + * if necessary */ +#ifdef MOVE_TEXT + view->update(0); +#else + view->buffer_->update(0); +#endif } } break; @@ -791,16 +941,27 @@ int BufferView::work_area_handler(FL_OBJECT * ob, int event, // select a line if (view->buffer_ && view->screen && ev->xbutton.button == 1) { view->screen->HideCursor(); - view->screen->ToggleSelection(); + view->screen->ToggleSelection(); +#ifdef MOVE_TEXT + view->text->CursorHome(); + view->text->sel_cursor = view->text->cursor; + view->text->CursorEnd(); + view->text->SetSelection(); +#else view->buffer_->text->CursorHome(); view->buffer_->text->sel_cursor = view->buffer_->text->cursor; view->buffer_->text->CursorEnd(); view->buffer_->text->SetSelection(); +#endif view->screen->ToggleSelection(false); /* This will fit the cursor on the screen - * if necessary */ - view->buffer_->update(0); + * if necessary */ +#ifdef MOVE_TEXT + view->update(0); +#else + view->buffer_->update(0); +#endif } break; case FL_OTHER: @@ -822,7 +983,11 @@ int BufferView::WorkAreaMotionNotify(FL_OBJECT *ob, Window, // Check for inset locking if (buffer_->the_locking_inset) { +#ifdef MOVE_TEXT + LyXCursor cursor = text->cursor; +#else LyXCursor cursor = buffer_->text->cursor; +#endif buffer_->the_locking_inset-> InsetMotionNotify(ev->xbutton.x - ob->x - cursor.x, ev->xbutton.y - ob->y - @@ -840,6 +1005,16 @@ int BufferView::WorkAreaMotionNotify(FL_OBJECT *ob, Window, if (selection_possible) { screen->HideCursor(); +#ifdef MOVE_TEXT + text->SetCursorFromCoordinates(ev->xbutton.x - ob->x, + ev->xbutton.y - ob->y + + screen->first); + + if (!text->selection) + update(-3); // Maybe an empty line was deleted + + text->SetSelection(); +#else buffer_->text-> SetCursorFromCoordinates(ev->xbutton.x - ob->x, ev->xbutton.y - ob->y + @@ -849,6 +1024,7 @@ int BufferView::WorkAreaMotionNotify(FL_OBJECT *ob, Window, buffer_->update(-3); // Maybe an empty line was deleted buffer_->text->SetSelection(); +#endif screen->ToggleToggle(); if (screen->FitCursor()) updateScrollbar(); @@ -860,6 +1036,168 @@ int BufferView::WorkAreaMotionNotify(FL_OBJECT *ob, Window, extern int bibitemMaxWidth(LyXFont const &); +#ifdef MOVE_TEXT +// Single-click on work area +int BufferView::WorkAreaButtonPress(FL_OBJECT *ob, Window, + int /*w*/, int /*h*/, XEvent *ev, void */*d*/) +{ + last_click_x = -1; + last_click_y = -1; + + if (buffer_ == 0) return 0; + if (!screen) return 0; + + int const x = ev->xbutton.x - ob->x; + int const y = ev->xbutton.y - ob->y; + // If we hit an inset, we have the inset coordinates in these + // and inset_hit points to the inset. If we do not hit an + // inset, inset_hit is 0, and inset_x == x, inset_y == y. + int inset_x = x; + int inset_y = y; + Inset * inset_hit = checkInsetHit(inset_x, inset_y); + + // ok ok, this is a hack. + int button = ev->xbutton.button; + if (button == 4 || button == 5) goto wheel; + + { + + if (buffer_->the_locking_inset) { + // We are in inset locking mode + + /* Check whether the inset was hit. If not reset mode, + otherwise give the event to the inset */ + if (inset_hit != 0) { + buffer_->the_locking_inset-> + InsetButtonPress(inset_x, inset_y, button); + return 0; + } else { + UnlockInset(buffer_->the_locking_inset); + } + } + + selection_possible = true; + screen->HideCursor(); + + // Right button mouse click on a table + if (button == 3 && + (text->cursor.par->table || + text->MouseHitInTable(x, y + screen->first))) { + // Set the cursor to the press-position + text->SetCursorFromCoordinates(x, y + screen->first); + bool doit = true; + + // Only show the table popup if the hit is in the table, too + if (!text->HitInTable(text->cursor.row, x)) + doit = false; + + // Hit above or below the table? + if (doit) { + if (!text->selection) { + screen->ToggleSelection(); + text->ClearSelection(); + text->FullRebreak(); + screen->Update(); + updateScrollbar(); + } + // Popup table popup when on a table. + // This is obviously temporary, since we should be + // able to + // popup various context-sensitive-menus with the + // the right mouse. So this should be done more + // general in the future. Matthias. + selection_possible = false; + owner_->getLyXFunc()->Dispatch(LFUN_LAYOUT_TABLE, + "true"); + return 0; + } + } + + int screen_first = screen->first; + + // Middle button press pastes if we have a selection + bool paste_internally = false; + if (button == 2 // && !buffer_->the_locking_inset + && text->selection) { + owner_->getLyXFunc()->Dispatch(LFUN_COPY); + paste_internally = true; + } + + // Clear the selection + screen->ToggleSelection(); + text->ClearSelection(); + text->FullRebreak(); + screen->Update(); + updateScrollbar(); + + // Single left click in math inset? + if (inset_hit != 0 && inset_hit->Editable() == 2) { + // Highly editable inset, like math + selection_possible = false; + owner_->updateLayoutChoice(); + owner_->getMiniBuffer()->Set(inset_hit->EditMessage()); + inset_hit->Edit(inset_x, inset_y); + return 0; + } + + // Right click on a footnote flag opens float menu + if (button == 3) { + selection_possible = false; + return 0; + } + + text->SetCursorFromCoordinates(x, y + screen_first); + text->FinishUndo(); + text->sel_cursor = text->cursor; + text->cursor.x_fix = text->cursor.x; + + owner_->updateLayoutChoice(); + if (screen->FitCursor()){ + updateScrollbar(); + selection_possible = false; + } + + // Insert primary selection with middle mouse + // if there is a local selection in the current buffer, insert this + if (button == 2) { // && !buffer_->the_locking_inset){ + if (paste_internally) + owner_->getLyXFunc()->Dispatch(LFUN_PASTE); + else + owner_->getLyXFunc()->Dispatch(LFUN_PASTESELECTION, + "paragraph"); + selection_possible = false; + return 0; + } + } + goto out; + wheel: { + // I am not quite sure if this is the correct place to put this, + // but it will not cause any harm. + // Patch from Mark Huang (markman@mit.edu) to make LyX recognise + // button 4 and 5. This enables LyX use use the scrollwhell on + // certain mice for something useful. (Lgb) + // Added wheel acceleration detection code. (Rvdk) + static Time lastTime = 0; + int diff = ev->xbutton.time - lastTime; + int scroll = int(1.0 + (4.0/(abs(diff)+1.0))*200.0); + switch (button) { + case 4: + ScrollUp(scroll); + break; + case 5: + ScrollDown(scroll); + break; + } + lastTime = ev->xbutton.time; + return 0; + } + out: + last_click_x = x; + last_click_y = y; + + return 0; +} +#else // Single-click on work area int BufferView::WorkAreaButtonPress(FL_OBJECT *ob, Window, int /*w*/, int /*h*/, XEvent *ev, void */*d*/) @@ -1020,8 +1358,163 @@ int BufferView::WorkAreaButtonPress(FL_OBJECT *ob, Window, return 0; } +#endif + +#ifdef MOVE_TEXT +int BufferView::WorkAreaButtonRelease(FL_OBJECT * ob, Window , + int /*w*/, int /*h*/, XEvent * ev, void * /*d*/) +{ + if (buffer_ == 0 || screen == 0) return 0; + + int const x = ev->xbutton.x - ob->x; + int const y = ev->xbutton.y - ob->y; + + // If we hit an inset, we have the inset coordinates in these + // and inset_hit points to the inset. If we do not hit an + // inset, inset_hit is 0, and inset_x == x, inset_y == y. + int inset_x = x; + int inset_y = y; + Inset * inset_hit = checkInsetHit(inset_x, inset_y); + + if (buffer_->the_locking_inset) { + // We are in inset locking mode. + + /* LyX does a kind of work-area grabbing for insets. + Only a ButtonPress Event outside the inset will + force a InsetUnlock. */ + buffer_->the_locking_inset-> + InsetButtonRelease(inset_x, inset_y, + ev->xbutton.button); + return 0; + } + + selection_possible = false; + if (text->cursor.par->table) { + int cell = text-> + NumberOfCell(text->cursor.par, + text->cursor.pos); + if (text->cursor.par->table->IsContRow(cell) && + text->cursor.par->table-> + CellHasContRow(text->cursor.par->table-> + GetCellAbove(cell))<0) { + text->CursorUp(); + } + } + + if (ev->xbutton.button >= 2) + return 0; + + // Make sure that the press was not far from the release + if ((abs(last_click_x - x) >= 5) || + (abs(last_click_y - y) >= 5)) { + return 0; + } + + // Did we hit an editable inset? + if (inset_hit != 0) { + // Inset like error, notes and figures + selection_possible = false; +#ifdef WITH_WARNINGS +#warning fix this proper in 0.13 +#endif + // Following a ref shouldn't issue + // a push on the undo-stack + // anylonger, now that we have + // keybindings for following + // references and returning from + // references. IMHO though, it + // should be the inset's own business + // to push or not push on the undo + // stack. They don't *have* to + // alter the document... + // (Joacim) + // ...or maybe the SetCursorParUndo() + // below isn't necessary at all anylonger? + if (inset_hit->LyxCode() == Inset::REF_CODE) { + text->SetCursorParUndo(); + } + + owner_->getMiniBuffer()->Set(inset_hit->EditMessage()); + inset_hit->Edit(inset_x, inset_y); + return 0; + } + + // check whether we want to open a float + if (text) { + bool hit = false; + char c = ' '; + if (text->cursor.pos < + text->cursor.par->Last()) { + c = text->cursor.par-> + GetChar(text->cursor.pos); + } + if (c == LyXParagraph::META_FOOTNOTE + || c == LyXParagraph::META_MARGIN + || c == LyXParagraph::META_FIG + || c == LyXParagraph::META_TAB + || c == LyXParagraph::META_WIDE_FIG + || c == LyXParagraph::META_WIDE_TAB + || c == LyXParagraph::META_ALGORITHM){ + hit = true; + } else if (text->cursor.pos - 1 >= 0) { + c = text->cursor.par-> + GetChar(text->cursor.pos - 1); + if (c == LyXParagraph::META_FOOTNOTE + || c == LyXParagraph::META_MARGIN + || c == LyXParagraph::META_FIG + || c == LyXParagraph::META_TAB + || c == LyXParagraph::META_WIDE_FIG + || c == LyXParagraph::META_WIDE_TAB + || c == LyXParagraph::META_ALGORITHM){ + // We are one step too far to the right + text->CursorLeft(); + hit = true; + } + } + if (hit == true) { + ToggleFloat(); + selection_possible = false; + return 0; + } + } + // Do we want to close a float? (click on the float-label) + if (text->cursor.row->par->footnoteflag == + LyXParagraph::OPEN_FOOTNOTE + && text->cursor.pos == 0 + && text->cursor.row->previous && + text->cursor.row->previous->par-> + footnoteflag != LyXParagraph::OPEN_FOOTNOTE){ + LyXFont font (LyXFont::ALL_SANE); + font.setSize(LyXFont::SIZE_SMALL); + + int box_x = 20; // LYX_PAPER_MARGIN; + box_x += font.textWidth("Mwide-figM", 10); + int screen_first = screen->first; + + if (x < box_x + && y + screen_first > text->cursor.y - + text->cursor.row->baseline + && y + screen_first < text->cursor.y - + text->cursor.row->baseline + + font.maxAscent()*1.2 + font.maxDescent()*1.2) { + ToggleFloat(); + selection_possible = false; + return 0; + } + } + + // Maybe we want to edit a bibitem ale970302 + if (text->cursor.par->bibkey && x < 20 + + bibitemMaxWidth(textclasslist.TextClass(buffer_-> + params.textclass).defaultfont())) { + text->cursor.par->bibkey->Edit(0, 0); + } + + return 0; +} +#else int BufferView::WorkAreaButtonRelease(FL_OBJECT *ob, Window , int /*w*/, int /*h*/, XEvent *ev, void */*d*/) { @@ -1175,13 +1668,55 @@ int BufferView::WorkAreaButtonRelease(FL_OBJECT *ob, Window , return 0; } - +#endif /* * Returns an inset if inset was hit. 0 otherwise. * If hit, the coordinates are changed relative to the inset. * Otherwise coordinates are not changed, and false is returned. */ +#ifdef MOVE_TEXT +Inset * BufferView::checkInsetHit(int & x, int & y) +{ + if (!getScreen()) + return 0; + + int y_tmp = y + getScreen()->first; + + LyXCursor cursor = text->cursor; + if (cursor.pos < cursor.par->Last() + && cursor.par->GetChar(cursor.pos) == LyXParagraph::META_INSET + && cursor.par->GetInset(cursor.pos) + && cursor.par->GetInset(cursor.pos)->Editable()) { + + // Check whether the inset really was hit + Inset * tmpinset = cursor.par->GetInset(cursor.pos); + LyXFont font = text->GetFont(cursor.par, cursor.pos); + if (x > cursor.x + && x < cursor.x + tmpinset->Width(font) + && y_tmp > cursor.y - tmpinset->Ascent(font) + && y_tmp < cursor.y + tmpinset->Descent(font)) { + x = x - cursor.x; + // The origin of an inset is on the baseline + y = y_tmp - (cursor.y); + return tmpinset; + } + } else if (cursor.pos - 1 >= 0 + && cursor.par->GetChar(cursor.pos - 1) == LyXParagraph::META_INSET + && cursor.par->GetInset(cursor.pos - 1) + && cursor.par->GetInset(cursor.pos - 1)->Editable()) { + text->CursorLeft(); + Inset * result = checkInsetHit(x, y); + if (result == 0) { + text->CursorRight(); + return 0; + } else { + return result; + } + } + return 0; +} +#else Inset * BufferView::checkInsetHit(int & x, int & y) { if (!getScreen()) @@ -1196,7 +1731,7 @@ Inset * BufferView::checkInsetHit(int & x, int & y) && cursor.par->GetInset(cursor.pos)->Editable()) { // Check whether the inset really was hit - Inset* tmpinset = cursor.par->GetInset(cursor.pos); + Inset * tmpinset = cursor.par->GetInset(cursor.pos); LyXFont font = buffer_->text->GetFont(cursor.par, cursor.pos); if (x > cursor.x && x < cursor.x + tmpinset->Width(font) @@ -1222,7 +1757,7 @@ Inset * BufferView::checkInsetHit(int & x, int & y) } return 0; } - +#endif int BufferView::workAreaExpose() { @@ -1437,6 +1972,13 @@ int BufferView::WorkAreaSelectionNotify(FL_OBJECT *, Window win, XFlush(fl_display); if (uc){ +#ifdef MOVE_TEXT + if (!ascii_type) { + text->InsertStringA(reinterpret_cast(uc)); + } else { + text->InsertStringB(reinterpret_cast(uc)); + } +#else if (!ascii_type) { buffer_->text-> InsertStringA(reinterpret_cast(uc)); @@ -1444,16 +1986,60 @@ int BufferView::WorkAreaSelectionNotify(FL_OBJECT *, Window win, buffer_->text-> InsertStringB(reinterpret_cast(uc)); } +#endif free(uc); uc = 0; } - + +#ifdef MOVE_TEXT + update(1); +#else buffer_->update(1); +#endif } return 0; } +#ifdef MOVE_TEXT +void BufferView::cursorPrevious() +{ + if (!text->cursor.row->previous) return; + + long y = getScreen()->first; + Row * cursorrow = text->cursor.row; + text->SetCursorFromCoordinates(text->cursor.x_fix, y); + text->FinishUndo(); + // this is to allow jumping over large insets + if ((cursorrow == text->cursor.row)) + text->CursorUp(); + + if (text->cursor.row->height < work_area->h) + getScreen()->Draw(text->cursor.y + - text->cursor.row->baseline + + text->cursor.row->height + - work_area->h +1 ); +} + + +void BufferView::cursorNext() +{ + if (!text->cursor.row->next) return; + + long y = getScreen()->first; + text->GetRowNearY(y); + Row * cursorrow = text->cursor.row; + text->SetCursorFromCoordinates(text->cursor.x_fix, y + work_area->h); + text->FinishUndo(); + /* this is to allow jumping over large insets */ + if ((cursorrow == text->cursor.row)) + text->CursorDown(); + + if (text->cursor.row->height < work_area->h) + getScreen()->Draw(text->cursor.y + - text->cursor.row->baseline); +} +#else void BufferView::cursorPrevious() { if (!buffer()->text->cursor.row->previous) return; @@ -1497,20 +2083,30 @@ void BufferView::cursorNext() getScreen()->Draw(buffer()->text->cursor.y - buffer()->text->cursor.row->baseline); } - +#endif bool BufferView::available() const { +#ifdef MOVE_TEXT + if (buffer_ && text) return true; +#else if (buffer_ && buffer_->text) return true; +#endif return false; } void BufferView::savePosition() { +#ifdef MOVE_TEXT + backstack.push(buffer()->fileName(), + text->cursor.x, + text->cursor.y); +#else backstack.push(buffer()->getFileName(), buffer()->text->cursor.x, buffer()->text->cursor.y); +#endif } @@ -1525,6 +2121,42 @@ void BufferView::restorePosition() Buffer * b = (bufferlist.exists(fname)) ? bufferlist.getBuffer(fname): bufferlist.loadLyXFile(fname); // don't ask, just load it buffer(b); +#ifdef MOVE_TEXT + text->SetCursorFromCoordinates(x, y); + update(0); +#else buffer()->text->SetCursorFromCoordinates(x, y); buffer()->update(0); +#endif } + + +#ifdef MOVE_TEXT +// candidate for move to BufferView +void BufferView::update(signed char f) +{ + owner()->updateLayoutChoice(); + + if (!text->selection && f > -3) + text->sel_cursor = text->cursor; + + FreeUpdateTimer(); + text->FullRebreak(); + + update(); + + if (f != 3 && f != -3) { + fitCursor(); + updateScrollbar(); + } + + if (f == 1 || f == -1) { + if (buffer()->isLyxClean()) { + buffer()->markDirty(); + owner()->getMiniBuffer()->setTimer(4); + } else { + buffer()->markDirty(); + } + } +} +#endif diff --git a/src/BufferView.h b/src/BufferView.h index 39b50c9d9f..e89b6b2cfe 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -18,6 +18,9 @@ #include FORMS_H_LOCATION #include "BackStack.h" +#include "lyxtext.h" + +#define MOVE_TEXT 1 class LyXView; class Buffer; @@ -30,6 +33,8 @@ public: /// BufferView(LyXView *owner, int , int , int, int); /// + ~BufferView(); + /// Buffer * buffer() const { return buffer_; } /// FL_OBJECT * getWorkArea() { return work_area; } @@ -43,6 +48,10 @@ public: void fitCursor(); /// void update(); +#ifdef MOVE_TEXT + /// + void update(signed char f); +#endif /// void updateScrollbar(); /// @@ -69,6 +78,12 @@ public: void savePosition(); /// void restorePosition(); +#ifdef MOVE_TEXT + /** This holds the mapping between buffer paragraphs and screen rows. + This should be private...but not yet. (Lgb) + */ + LyXText * text; +#endif private: /// Update pixmap of screen void updateScreen(); diff --git a/src/LyXSendto.C b/src/LyXSendto.C index 57c30c97d4..805599c551 100644 --- a/src/LyXSendto.C +++ b/src/LyXSendto.C @@ -85,7 +85,7 @@ void SendtoApplyCB(FL_OBJECT *, long) command = subst(command, "$$FName", fname); command += " &"; // execute in background // push directorypath, if necessary - string path = OnlyPath(buffer->getFileName()); + string path = OnlyPath(buffer->fileName()); if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){ path = buffer->tmppath; } diff --git a/src/LyXView.C b/src/LyXView.C index ad9e37c922..04d99bcc58 100644 --- a/src/LyXView.C +++ b/src/LyXView.C @@ -86,7 +86,11 @@ void LyXView::UpdateTimerCB(FL_OBJECT * ob, long) return; view->view()->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + view->view()->update(-2); +#else view->buffer()->update(-2); +#endif /* This update can happen, even when the work area has lost * the focus. So suppress the cursor in that case */ updatetimer = 0; @@ -310,8 +314,12 @@ void LyXView::updateLayoutChoice() } // we need to do this. toolbar->combox->Redraw(); - + +#ifdef MOVE_TEXT + char layout = bufferview->text->cursor.par->GetLayout(); +#else char layout = buffer()->text->cursor.par->GetLayout(); +#endif if (layout != current_layout){ toolbar->combox->select(layout + 1); @@ -364,7 +372,7 @@ void LyXView::updateWindowTitle() { string title = "LyX"; if (view()->available()) { - string cur_title = buffer()->getFileName(); + string cur_title = buffer()->fileName(); if (!cur_title.empty()){ title += ": " + OnlyFilename(cur_title); if (!buffer()->isLyxClean()) diff --git a/src/ParagraphExtra.C b/src/ParagraphExtra.C index 8f3562e2ff..68556bd83c 100644 --- a/src/ParagraphExtra.C +++ b/src/ParagraphExtra.C @@ -76,7 +76,11 @@ bool UpdateParagraphExtra() bool update = false; if (current_view->getScreen() && current_view->available()) { update = true; +#ifdef MOVE_TEXT + LyXParagraph * par = current_view->text->cursor.par; +#else LyXParagraph * par = current_view->buffer()->text->cursor.par; +#endif EnableParagraphExtra(); @@ -171,7 +175,11 @@ void ParagraphExtraApplyCB(FL_OBJECT *, long) FD_form_paragraph_extra const * fd = fd_form_paragraph_extra; char const * width = fl_get_input(fd->input_pextra_width); char const * widthp = fl_get_input(fd->input_pextra_widthp); +#ifdef MOVE_TEXT + LyXText * text = current_view->text; +#else LyXText * text = current_view->buffer()->text; +#endif int type = LyXParagraph::PEXTRA_NONE; LyXParagraph::MINIPAGE_ALIGNMENT alignment = LyXParagraph::MINIPAGE_ALIGN_TOP; @@ -197,7 +205,11 @@ void ParagraphExtraApplyCB(FL_OBJECT *, long) } text->SetParagraphExtraOpt(type, width, widthp, alignment, hfill, start_minipage); +#ifdef MOVE_TEXT + current_view->update(1); +#else current_view->buffer()->update(1); +#endif minibuffer->Set(_("ParagraphExtra layout set")); } return; diff --git a/src/TableLayout.C b/src/TableLayout.C index 56700481db..a0ff8eb436 100644 --- a/src/TableLayout.C +++ b/src/TableLayout.C @@ -36,6 +36,190 @@ static int extra_col_cursor_x; // need no y's, one-line input fields static int extra_multicol_cursor_x; // Joacim +#ifdef MOVE_TEXT +bool UpdateLayoutTable(int flag) +{ + bool update = true; + if (!current_view->getScreen() || !current_view->available()) + update = false; + + if (update && current_view->text->cursor.par->table) { + char buf[12]; + string pwidth, special; + + LyXTable * table = current_view->text->cursor.par->table; + + int cell = current_view->text-> + NumberOfCell(current_view->text->cursor.par, + current_view->text->cursor.pos); + ActCell = cell; + int column = table->column_of_cell(cell)+1; + fl_set_object_label(fd_form_table_options->text_warning, ""); + Confirmed = false; + fl_activate_object(fd_form_table_extra->input_special_alignment); + fl_activate_object(fd_form_table_extra->input_special_multialign); + fl_activate_object(fd_form_table_options->input_column_width); + sprintf(buf, "%d", column); + fl_set_input(fd_form_table_options->input_table_column, buf); + fl_deactivate_object(fd_form_table_options->input_table_column); + int row = table->row_of_cell(cell)+1; + sprintf(buf, "%d", row); + fl_set_input(fd_form_table_options->input_table_row, buf); + fl_deactivate_object(fd_form_table_options->input_table_row); + if (table->IsMultiColumn(cell)) + fl_set_button(fd_form_table_options->radio_multicolumn, 1); + else + fl_set_button(fd_form_table_options->radio_multicolumn, 0); + if (table->RotateCell(cell)) + fl_set_button(fd_form_table_options->radio_rotate_cell, 1); + else + fl_set_button(fd_form_table_options->radio_rotate_cell, 0); + if (table->TopLine(cell)) + fl_set_button(fd_form_table_options->radio_border_top, 1); + else + fl_set_button(fd_form_table_options->radio_border_top, 0); + if (table->BottomLine(cell)) + fl_set_button(fd_form_table_options->radio_border_bottom, 1); + else + fl_set_button(fd_form_table_options->radio_border_bottom, 0); + if (table->LeftLine(cell)) + fl_set_button(fd_form_table_options->radio_border_left, 1); + else + fl_set_button(fd_form_table_options->radio_border_left, 0); + if (table->RightLine(cell)) + fl_set_button(fd_form_table_options->radio_border_right, 1); + else + fl_set_button(fd_form_table_options->radio_border_right, 0); + int align = table->GetAlignment(cell); + fl_set_button(fd_form_table_options->radio_align_left, 0); + fl_set_button(fd_form_table_options->radio_align_right, 0); + fl_set_button(fd_form_table_options->radio_align_center, 0); + special = table->GetAlignSpecial(cell, LyXTable::SET_SPECIAL_COLUMN); + if (flag) + { + fl_set_input(fd_form_table_extra->input_special_alignment, + special.c_str()); + fl_set_input_cursorpos(fd_form_table_extra->input_special_alignment, + extra_col_cursor_x, 0); // restore the cursor + } + if (current_view->buffer()->isReadonly()) + fl_deactivate_object(fd_form_table_extra->input_special_alignment); + special = table->GetAlignSpecial(cell, LyXTable::SET_SPECIAL_MULTI); + if (flag) + { + fl_set_input(fd_form_table_extra->input_special_multialign, + special.c_str()); + fl_set_input_cursorpos(fd_form_table_extra->input_special_multialign, + extra_multicol_cursor_x, 0); // restore the cursor + } + if (current_view->buffer()->isReadonly()) + fl_deactivate_object(fd_form_table_extra->input_special_multialign); + pwidth = table->GetPWidth(cell); + if (flag) + fl_set_input(fd_form_table_options->input_column_width, pwidth.c_str()); + if (current_view->buffer()->isReadonly()) + fl_deactivate_object(fd_form_table_options->input_column_width); + if (!pwidth.empty()) { + fl_activate_object(fd_form_table_options->radio_linebreak_cell); + fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell, + FL_BLACK); + fl_set_button(fd_form_table_options->radio_linebreak_cell, + table->Linebreaks(table->FirstVirtualCell(cell))); + } else { + fl_deactivate_object(fd_form_table_options->radio_linebreak_cell); + fl_set_object_lcol(fd_form_table_options->radio_linebreak_cell, + FL_INACTIVE); + fl_set_button(fd_form_table_options->radio_linebreak_cell, 0); + } + if ((!pwidth.empty() && !table->IsMultiColumn(cell)) || + (align == LYX_ALIGN_LEFT)) + fl_set_button(fd_form_table_options->radio_align_left, 1); + else if (align == LYX_ALIGN_RIGHT) + fl_set_button(fd_form_table_options->radio_align_right, 1); + else + fl_set_button(fd_form_table_options->radio_align_center, 1); + if (!pwidth.empty() && !table->IsMultiColumn(cell)) { + fl_deactivate_object(fd_form_table_options->radio_align_left); + fl_deactivate_object(fd_form_table_options->radio_align_right); + fl_deactivate_object(fd_form_table_options->radio_align_center); + fl_set_object_lcol(fd_form_table_options->radio_align_left, + FL_INACTIVE); + fl_set_object_lcol(fd_form_table_options->radio_align_right, + FL_INACTIVE); + fl_set_object_lcol(fd_form_table_options->radio_align_center, + FL_INACTIVE); + } else { + fl_activate_object(fd_form_table_options->radio_align_left); + fl_activate_object(fd_form_table_options->radio_align_right); + fl_activate_object(fd_form_table_options->radio_align_center); + fl_set_object_lcol(fd_form_table_options->radio_align_left, + FL_BLACK); + fl_set_object_lcol(fd_form_table_options->radio_align_right, + FL_BLACK); + fl_set_object_lcol(fd_form_table_options->radio_align_center, + FL_BLACK); + } + fl_set_button(fd_form_table_options->radio_longtable, table->IsLongTable()); + if (table->IsLongTable()) { + fl_activate_object(fd_form_table_options->radio_lt_firsthead); + fl_activate_object(fd_form_table_options->radio_lt_head); + fl_activate_object(fd_form_table_options->radio_lt_foot); + fl_activate_object(fd_form_table_options->radio_lt_lastfoot); + fl_activate_object(fd_form_table_options->radio_lt_newpage); + fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead, + FL_BLACK); + fl_set_object_lcol(fd_form_table_options->radio_lt_head, + FL_BLACK); + fl_set_object_lcol(fd_form_table_options->radio_lt_foot, + FL_BLACK); + fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot, + FL_BLACK); + fl_set_object_lcol(fd_form_table_options->radio_lt_newpage, + FL_BLACK); + fl_set_button(fd_form_table_options->radio_lt_firsthead, + table->RowOfLTFirstHead(cell)); + fl_set_button(fd_form_table_options->radio_lt_head, + table->RowOfLTHead(cell)); + fl_set_button(fd_form_table_options->radio_lt_foot, + table->RowOfLTFoot(cell)); + fl_set_button(fd_form_table_options->radio_lt_lastfoot, + table->RowOfLTLastFoot(cell)); + fl_set_button(fd_form_table_options->radio_lt_newpage, + table->LTNewPage(cell)); + } else { + fl_deactivate_object(fd_form_table_options->radio_lt_firsthead); + fl_deactivate_object(fd_form_table_options->radio_lt_head); + fl_deactivate_object(fd_form_table_options->radio_lt_foot); + fl_deactivate_object(fd_form_table_options->radio_lt_lastfoot); + fl_deactivate_object(fd_form_table_options->radio_lt_newpage); + fl_set_button(fd_form_table_options->radio_lt_firsthead, 0); + fl_set_button(fd_form_table_options->radio_lt_head, 0); + fl_set_button(fd_form_table_options->radio_lt_foot, 0); + fl_set_button(fd_form_table_options->radio_lt_lastfoot, 0); + fl_set_button(fd_form_table_options->radio_lt_newpage, 0); + fl_set_object_lcol(fd_form_table_options->radio_lt_firsthead, + FL_INACTIVE); + fl_set_object_lcol(fd_form_table_options->radio_lt_head, + FL_INACTIVE); + fl_set_object_lcol(fd_form_table_options->radio_lt_foot, + FL_INACTIVE); + fl_set_object_lcol(fd_form_table_options->radio_lt_lastfoot, + FL_INACTIVE); + fl_set_object_lcol(fd_form_table_options->radio_lt_newpage, + FL_INACTIVE); + } + fl_set_button(fd_form_table_options->radio_rotate_table, + table->RotateTable()); + fl_set_focus_object(fd_form_table_options->form_table_options, + fd_form_table_options->button_table_delete); + } else if (fd_form_table_options->form_table_options->visible) { + fl_set_focus_object(fd_form_table_options->form_table_options, + fd_form_table_options->button_table_delete); + fl_hide_form(fd_form_table_options->form_table_options); + } + return update; +} +#else bool UpdateLayoutTable(int flag) { bool update = true; @@ -218,7 +402,7 @@ bool UpdateLayoutTable(int flag) } return update; } - +#endif void OpenLayoutTableExtra() { @@ -258,13 +442,28 @@ void MenuLayoutTable(int flag) void TableOptionsCB(FL_OBJECT * ob, long) { LyXTable * table = 0; - int - s, - num = 0; - string - special, - str; + int s, num = 0; + string special, str; +#ifdef MOVE_TEXT + if (!current_view->available() + || !(table = current_view->text->cursor.par->table)) { + MenuLayoutTable(0); + return; + } + int cell = current_view->text-> + NumberOfCell(current_view->text->cursor.par, + current_view->text->cursor.pos); + if (ActCell != cell) { + MenuLayoutTable(0); + fl_set_object_label(fd_form_table_options->text_warning, + _("Warning: Wrong Cursor position, updated window")); + fl_show_object(fd_form_table_options->text_warning); + extra_col_cursor_x = 0; // would rather place it at the end, but... + extra_multicol_cursor_x = 0; + return; + } +#else if (!current_view->available() || !(table = current_view->buffer()->text->cursor.par->table)) { @@ -283,6 +482,7 @@ void TableOptionsCB(FL_OBJECT * ob, long) extra_multicol_cursor_x = 0; return; } +#endif // No point in processing directives that you can't do anything with // anyhow, so exit now if the buffer is read-only. if (current_view->buffer()->isReadonly()) { @@ -424,6 +624,18 @@ void TableOptionsCB(FL_OBJECT * ob, long) return; if (current_view->available()){ current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + if (!current_view->text->selection){ + BeforeChange(); + current_view->update(-2); + } + if ((num == LyXTable::SET_SPECIAL_COLUMN) || + (num == LyXTable::SET_SPECIAL_MULTI)) + current_view->text->TableFeatures(num, special); + else + current_view->text->TableFeatures(num); + current_view->update(1); +#else if (!current_view->buffer()->text->selection){ BeforeChange(); current_view->buffer()->update(-2); @@ -434,6 +646,7 @@ void TableOptionsCB(FL_OBJECT * ob, long) else current_view->buffer()->text->TableFeatures(num); current_view->buffer()->update(1); +#endif } if (num == LyXTable::DELETE_TABLE) { fl_set_focus_object(fd_form_table_options->form_table_options, @@ -476,12 +689,21 @@ void SetPWidthCB(FL_OBJECT *ob, long) } if (current_view->available()){ current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + if (!current_view->text->selection){ + BeforeChange(); + current_view->update(-2); + } + current_view->text->TableFeatures(LyXTable::SET_PWIDTH, str); + current_view->update(1); +#else if (!current_view->buffer()->text->selection){ BeforeChange(); current_view->buffer()->update(-2); } current_view->buffer()->text->TableFeatures(LyXTable::SET_PWIDTH, str); current_view->buffer()->update(1); +#endif } MenuLayoutTable(0); // update for alignment } diff --git a/src/buffer.C b/src/buffer.C index a587a127c2..a669a7454d 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -43,6 +43,7 @@ using std::setw; #include "bufferlist.h" #include "lyx_main.h" #include "lyx_gui_misc.h" +#include "LyXAction.h" #include "lyxrc.h" #include "lyxlex.h" #include "tex-strings.h" @@ -103,6 +104,16 @@ extern void SmallUpdate(signed char); extern unsigned char GetCurrentTextClass(); extern void BeforeChange(); +extern void MenuMakeLaTeX(Buffer *); +extern void MenuMakeLinuxDoc(Buffer *); +extern void MenuMakeDocBook(Buffer *); +extern void MenuRunLaTeX(Buffer *); +extern void MenuPrint(Buffer *); +extern void MenuMakeAscii(Buffer *); +extern void MenuSendto(); +extern LyXAction lyxaction; + + static const float LYX_FORMAT = 2.15; extern int tex_code_break_column; @@ -116,7 +127,9 @@ Buffer::Buffer(string const & file, LyXRC * lyxrc, bool ronly) filename = file; filepath = OnlyPath(file); paragraph = 0; +#ifndef MOVE_TEXT text = 0; +#endif the_locking_inset = 0; lyx_clean = true; bak_clean = true; @@ -156,7 +169,9 @@ Buffer::~Buffer() par = tmppar; } paragraph = 0; +#ifndef MOVE_TEXT delete text; +#endif } @@ -192,7 +207,7 @@ void Buffer::resetAutosaveTimers() } -void Buffer::setFileName(string const & newfile) +void Buffer::fileName(string const & newfile) { filename = MakeAbsPath(newfile); filepath = OnlyPath(filename); @@ -200,17 +215,24 @@ void Buffer::setFileName(string const & newfile) updateTitles(); } + +// candidate for move to BufferView void Buffer::InsetUnlock() { if (the_locking_inset) { if (!inset_slept) the_locking_inset->InsetUnlock(); the_locking_inset = 0; +#ifdef MOVE_TEXT + users->text->FinishUndo(); +#else text->FinishUndo(); +#endif inset_slept = false; } } +// candidate for move to BufferView // Inserts a file into current document bool Buffer::insertLyXFile(string const & filen) // @@ -251,6 +273,15 @@ bool Buffer::insertLyXFile(string const & filen) bool res = true; +#ifdef MOVE_TEXT + if (c == '#') { + lyxerr.debug() << "Will insert file with header" << endl; + res = readFile(lex, users->text->cursor.par); + } else { + lyxerr.debug() << "Will insert file without header" << endl; + res = readLyXformat2(lex, users->text->cursor.par); + } +#else if (c == '#') { lyxerr.debug() << "Will insert file with header" << endl; res = readFile(lex, text->cursor.par); @@ -258,11 +289,14 @@ bool Buffer::insertLyXFile(string const & filen) lyxerr.debug() << "Will insert file without header" << endl; res = readLyXformat2(lex, text->cursor.par); } +#endif resize(); return res; } +// candidate for move to BufferView +// (at least some parts in the beginning of the func) // // Uwe C. Schroeder // changed to be public and have one parameter @@ -290,8 +324,13 @@ bool Buffer::readLyXformat2(LyXLex & lex, LyXParagraph * par) if(!par) { par = new LyXParagraph; } else { +#ifdef MOVE_TEXT + users->text->BreakParagraph(); + return_par = users->text->FirstParagraph(); +#else text->BreakParagraph(); return_par = text->FirstParagraph(); +#endif pos = 0; markDirty(); // We don't want to adopt the parameters from the @@ -1401,22 +1440,24 @@ void Buffer::writeFileAscii(string const & filename, int linelen) break; } if (ltype_depth > depth) { - for(j = ltype_depth-1; j>depth; j--) + for(j = ltype_depth - 1; j > depth; --j) ofs << " "; currlinelen += (ltype_depth-depth)*2; } if (par->table) { - for(j = 0;j depth) { - for(j = ltype_depth; j>depth; j--) + for(j = ltype_depth; + j > depth; --j) ofs << " "; currlinelen += (ltype_depth-depth)*2; } @@ -1451,32 +1492,34 @@ void Buffer::writeFileAscii(string const & filename, int linelen) for(j = actpos; j < clen[cell-1];j++) ofs << ' '; ofs << " |\n"; - for(j = 0; j depth) { - for(j = ltype_depth; j>depth; j--) + for(j = ltype_depth; j > depth; --j) ofs << " "; - currlinelen += (ltype_depth-depth)*2; + currlinelen += (ltype_depth-depth) * 2; } - for(j = 0;j depth) { - for(j = ltype_depth; j>depth; j--) + for(j = ltype_depth; + j > depth; --j) ofs << " "; currlinelen += (ltype_depth-depth)*2; } ofs << "| "; cell = 1; } else { - for(j = actpos; j depth) { - for(j = ltype_depth; j>depth; j--) + for(j = ltype_depth; + j > depth; --j) ofs << " "; - currlinelen += (ltype_depth-depth)*2; + currlinelen += (ltype_depth - depth) * 2; } } break; @@ -1529,15 +1573,15 @@ void Buffer::writeFileAscii(string const & filename, int linelen) for(j = actpos; j < clen[cell - 1]; ++j) ofs << ' '; ofs << " |\n"; - for(j = 0; j depth) { for(j = ltype_depth; j > depth; --j) ofs << " "; - currlinelen += (ltype_depth-depth)*2; + currlinelen += (ltype_depth - depth) * 2; } - for(j = 0;jtext->cursor; +#else LyXCursor cursor = text->cursor; +#endif LyXCursor tmpcursor = cursor; cursor.par = tmpcursor.par->ParFromPos(tmpcursor.pos); cursor.pos = tmpcursor.par->PositionInParFromPos(tmpcursor.pos); @@ -3134,11 +3184,19 @@ bool Buffer::removeAutoInsets() if (par->AutoDeleteInsets()){ a = true; if (par->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){ +#ifdef MOVE_TEXT + /* this is possible now, since SetCursor takes + care about footnotes */ + users->text->SetCursorIntern(par, 0); + users->text->RedoParagraphs(users->text->cursor, users->text->cursor.par->Next()); + users->text->FullRebreak(); +#else /* this is possible now, since SetCursor takes care about footnotes */ text->SetCursorIntern(par, 0); text->RedoParagraphs(text->cursor, text->cursor.par->Next()); text->FullRebreak(); +#endif } } par = par->next; @@ -3146,7 +3204,11 @@ bool Buffer::removeAutoInsets() /* avoid forbidden cursor positions caused by error removing */ if (cursor.pos > cursor.par->Last()) cursor.pos = cursor.par->Last(); +#ifdef MOVE_TEXT + users->text->SetCursorIntern(cursor.par, cursor.pos); +#else text->SetCursorIntern(cursor.par, cursor.pos); +#endif return a; } @@ -3154,7 +3216,11 @@ bool Buffer::removeAutoInsets() int Buffer::runLaTeX() { +#ifdef MOVE_TEXT + if (!users->text) return 0; +#else if (!text) return 0; +#endif ProhibitInput(); @@ -3217,7 +3283,11 @@ int Buffer::runLaTeX() int Buffer::runLiterate() { +#ifdef MOVE_TEXT + if (!users->text) return 0; +#else if (!text) return 0; +#endif ProhibitInput(); @@ -3286,7 +3356,11 @@ int Buffer::runLiterate() int Buffer::buildProgram() { +#ifdef MOVE_TEXT + if (!users->text) return 0; +#else if (!text) return 0; +#endif ProhibitInput(); @@ -3357,7 +3431,11 @@ int Buffer::buildProgram() // Other flags: -wall -v0 -x int Buffer::runChktex() { +#ifdef MOVE_TEXT + if (!users->text) return 0; +#else if (!text) return 0; +#endif ProhibitInput(); @@ -3410,10 +3488,16 @@ int Buffer::runChktex() extern void AllFloats(char, char); +// candidate for move to BufferView void Buffer::insertErrors(TeXErrors & terr) { +#ifdef MOVE_TEXT + // Save the cursor position + LyXCursor cursor = users->text->cursor; +#else // Save the cursor position LyXCursor cursor = text->cursor; +#endif // This is drastic, but it's the only fix, I could find. (Asger) AllFloats(1, 0); @@ -3433,29 +3517,47 @@ void Buffer::insertErrors(TeXErrors & terr) texrow.getIdFromRow(errorrow, tmpid, tmppos); - LyXParagraph* texrowpar; + LyXParagraph * texrowpar = 0; +#ifdef MOVE_TEXT + if (tmpid == -1) { + texrowpar = users->text->FirstParagraph(); + tmppos = 0; + } else { + texrowpar = users->text->GetParFromID(tmpid); + } +#else if (tmpid == -1) { texrowpar = text->FirstParagraph(); tmppos = 0; } else { texrowpar = text->GetParFromID(tmpid); } +#endif if (texrowpar == 0) continue; InsetError * new_inset = new InsetError(msgtxt); - +#ifdef MOVE_TEXT + users->text->SetCursorIntern(texrowpar, tmppos); + users->text->InsertInset(new_inset); + users->text->FullRebreak(); + } + // Restore the cursor position + users->text->SetCursorIntern(cursor.par, cursor.pos); +#else text->SetCursorIntern(texrowpar, tmppos); text->InsertInset(new_inset); text->FullRebreak(); } // Restore the cursor position text->SetCursorIntern(cursor.par, cursor.pos); +#endif } +// candidate for move to BufferView void Buffer::setCursorFromRow (int row) { int tmpid = -1; @@ -3463,8 +3565,17 @@ void Buffer::setCursorFromRow (int row) texrow.getIdFromRow(row, tmpid, tmppos); - LyXParagraph* texrowpar; + LyXParagraph * texrowpar; +#ifdef MOVE_TEXT + if (tmpid == -1) { + texrowpar = users->text->FirstParagraph(); + tmppos = 0; + } else { + texrowpar = users->text->GetParFromID(tmpid); + } + users->text->SetCursor(texrowpar, tmppos); +#else if (tmpid == -1) { texrowpar = text->FirstParagraph(); tmppos = 0; @@ -3472,6 +3583,7 @@ void Buffer::setCursorFromRow (int row) texrowpar = text->GetParFromID(tmpid); } text->SetCursor(texrowpar, tmppos); +#endif } @@ -3622,17 +3734,19 @@ void Buffer::markDviDirty() } +#ifndef MOVE_TEXT +// candidate for move to BufferView void Buffer::update(signed char f) { if (!users) return; users->owner()->updateLayoutChoice(); - if (!text->selection && f > -3) text->sel_cursor = text->cursor; FreeUpdateTimer(); text->FullRebreak(); + users->update(); if (f != 3 && f != -3) { @@ -3649,7 +3763,7 @@ void Buffer::update(signed char f) } } } - +#endif void Buffer::validate(LaTeXFeatures & features) { @@ -3762,6 +3876,60 @@ void Buffer::setOldPaperStuff() } #endif +#ifdef MOVE_TEXT +// candidate for move to BufferView +void Buffer::insertInset(Inset * inset, string const & lout, + bool no_table) +{ + // check for table/list in tables + if (no_table && users->text->cursor.par->table){ + WriteAlert(_("Impossible Operation!"), + _("Cannot insert table/list in table."), + _("Sorry.")); + return; + } + // not quite sure if we want this... + users->text->SetCursorParUndo(); + users->text->FreezeUndo(); + + BeforeChange(); + if (!lout.empty()) { + users->update(-2); + users->text->BreakParagraph(); + users->update(-1); + + if (users->text->cursor.par->Last()) { + users->text->CursorLeft(); + + users->text->BreakParagraph(); + users->update(-1); + } + + int lay = textclasslist.NumberOfLayout(params.textclass, + lout).second; + if (lay == -1) // layout not found + // use default layout "Standard" (0) + lay = 0; + + users->text->SetLayout(lay); + + users->text->SetParagraph(0, 0, + 0, 0, + VSpace(VSpace::NONE), VSpace(VSpace::NONE), + LYX_ALIGN_LAYOUT, + string(), + 0); + users->update(-1); + + users->text->current_font.setLatex(LyXFont::OFF); + } + + users->text->InsertInset(inset); + users->update(-1); + + users->text->UnFreezeUndo(); +} +#else void Buffer::insertInset(Inset * inset, string const & lout, bool no_table) { @@ -3813,17 +3981,27 @@ void Buffer::insertInset(Inset * inset, string const & lout, text->UnFreezeUndo(); } - +#endif // Open and lock an updatable inset +// candidate for move to BufferView void Buffer::open_new_inset(UpdatableInset * new_inset) { +#ifdef MOVE_TEXT + BeforeChange(); + users->text->FinishUndo(); + insertInset(new_inset); + users->text->CursorLeft(); + users->update(1); + new_inset->Edit(0, 0); +#else BeforeChange(); text->FinishUndo(); insertInset(new_inset); text->CursorLeft(); update(1); new_inset->Edit(0, 0); +#endif } @@ -3862,12 +4040,12 @@ string Buffer::getReferenceList(char delim) /// if this is a child document and the parent is already loaded /// Use the parent's list instead [ale990407] if (!params.parentname.empty() && bufferlist.exists(params.parentname)) { - Buffer *tmp = bufferlist.getBuffer(params.parentname); + Buffer * tmp = bufferlist.getBuffer(params.parentname); if (tmp) return tmp->getReferenceList(delim); } - LyXParagraph *par = paragraph; + LyXParagraph * par = paragraph; LyXParagraph::size_type pos; Inset * inset; string lst; @@ -3894,7 +4072,7 @@ string Buffer::getBibkeyList(char delim) /// if this is a child document and the parent is already loaded /// Use the parent's list instead [ale990412] if (!params.parentname.empty() && bufferlist.exists(params.parentname)) { - Buffer *tmp = bufferlist.getBuffer(params.parentname); + Buffer * tmp = bufferlist.getBuffer(params.parentname); if (tmp) return tmp->getBibkeyList(delim); } @@ -3942,6 +4120,7 @@ string Buffer::getBibkeyList(char delim) } +// candidate for move to BufferView /* This is also a buffer property (ale) */ // Not so sure about that. a goto Label function can not be buffer local, just // think how this will work in a multiwindo/buffer environment, all the @@ -3958,11 +4137,19 @@ bool Buffer::gotoLabel(string const & label) while ((inset = par->ReturnNextInsetPointer(pos))){ for (int i = 0; i < inset->GetNumberOfLabels(); i++) { if (label == inset->getLabel(i)) { +#ifdef MOVE_TEXT + BeforeChange(); + users->text->SetCursor(par, pos); + users->text->sel_cursor = users->text->cursor; + users->update(0); + return true; +#else BeforeChange(); text->SetCursor(par, pos); text->sel_cursor = text->cursor; update(0); return true; +#endif } } pos++; @@ -4004,3 +4191,104 @@ void Buffer::markDepClean(string const & name) } } } + +void Buffer::Dispatch(const string & command) +{ + // Split command string into command and argument + string cmd, line = frontStrip(command); + string arg = strip(frontStrip(split(line, cmd, ' '))); + + return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str()); +} + +void Buffer::Dispatch(int action, const string & argument) +{ + switch (action) { + case LFUN_EXPORT: { + // latex + if (argument == "latex") { + // make sure that this buffer is not linuxdoc + MenuMakeLaTeX(this); + } + // linuxdoc + else if (argument == "linuxdoc") { + // make sure that this buffer is not latex + MenuMakeLinuxDoc(this); + } + // docbook + else if (argument == "docbook") { + // make sure that this buffer is not latex or linuxdoc + MenuMakeDocBook(this); + } + // dvi + else if (argument == "dvi") { + // Run LaTeX as "Update dvi..." Bernhard. + // We want the dvi in the current directory. This + // is achieved by temporarily disabling use of + // temp directory. As a side-effect, we get + // *.log and *.aux files also. (Asger) + bool flag = lyxrc->use_tempdir; + lyxrc->use_tempdir = false; + MenuRunLaTeX(this); + lyxrc->use_tempdir = flag; + } + // postscript + else if (argument == "postscript") { + // Start Print-dialog. Not as good as dvi... Bernhard. + MenuPrint(this); + // Since the MenuPrint is a pop-up, we can't use + // the same trick as above. (Asger) + // MISSING: Move of ps-file :-| + } + // ascii + else if (argument == "ascii") { + MenuMakeAscii(this); + } + else if (argument == "custom") { + MenuSendto(); + break; + } + // HTML + else if (argument == "html" && lyxrc->html_command != "none") { + // First, create LaTeX file + MenuMakeLaTeX(this); + + // And now, run the converter + string file = fileName(); + Path path(OnlyPath(file)); + // the tex file name has to be correct for + // latex, but the html file name can be + // anything. + string result = ChangeExtension(file, ".html", false); + file = ChangeExtension(MakeLatexName(file), ".tex", false); + string tmp = lyxrc->html_command; + tmp = subst(tmp, "$$FName", file); + tmp = subst(tmp, "$$OutName", result); + Systemcalls one; + /*int res = */ one.startscript(Systemcalls::System, tmp); + // + // Hi, Asger. This time I plead guilty and I promise to clean it up + // + // if (res == 0) { + // setMessage(N_("Document exported as HTML to file `") + // + MakeDisplayPath(result) +'\ ''); + // } else { + // setErrorMessage(N_("Unable to convert to HTML the file `") + // + MakeDisplayPath(file) + // + '\''); + // } + } + else { + // setErrorMessage(N_("Unknown export type: ") + // + argument); + } + } + break; + + default: + lyxerr << "A truly unknown func!" << endl; + break; + + } // end of switch + +} diff --git a/src/buffer.h b/src/buffer.h index a4322ffe0b..870d697cdc 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -34,6 +34,7 @@ #include "lyxtext.h" #include "support/filetools.h" +#define MOVE_TEXT 1 class LyXRC; class TeXErrors; @@ -79,15 +80,26 @@ public: */ bool saveParamsAsDefaults(); + /** high-level interface to buffer functionality + This function parses a command string and executes it + */ + void Dispatch(const string & command); + + /// Maybe we know the function already by number... + void Dispatch(int ac, const string & argument); + /// should be changed to work for a list. void resize() { if (users) { users->resize(); - } else if (text) { + } +#ifndef MOVE_TEXT + else if (text) { delete text; text = 0; } +#endif } /// Update window titles of all users @@ -106,9 +118,11 @@ public: Since we only can have one at the moment, we just reset it. */ void delUser(BufferView *){ users = 0; } - + +#ifndef MOVE_TEXT /// void update(signed char f); +#endif /// void redraw() { @@ -231,7 +245,7 @@ public: } /// - string getFileName() const { return filename; } + string const & fileName() const { return filename; } /// A transformed version of the file name, adequate for LaTeX string getLatexName() const { @@ -239,7 +253,7 @@ public: } /// Change name of buffer. Updates "read-only" flag. - void setFileName(string const & newfile); + void fileName(string const & newfile); /// Name of the document's parent void setParentName(string const &); @@ -329,13 +343,14 @@ public: /** is a list of paragraphs. */ LyXParagraph * paragraph; - + +#ifndef MOVE_TEXT /** This holds the mapping between buffer paragraphs and screen rows. Should be moved to BufferView. (Asger) */ LyXText * text; - - /// +#endif + /// per view not per buffer? UpdatableInset * the_locking_inset; /// RCS object @@ -350,7 +365,7 @@ public: /** While writing as LaTeX, tells whether we are doing a 'nice' LaTeX file */ bool niceFile; -protected: + /// void InsetUnlock(); @@ -377,7 +392,7 @@ private: /// void DocBookHandleCaption(ostream & os, string & inner_tag, int const depth, int desc_on, - LyXParagraph * &par); + LyXParagraph * & par); /// void DocBookHandleFootnote(ostream & os, LyXParagraph * & par, int const depth); @@ -446,11 +461,6 @@ private: */ BufferView * users; - /// - friend class BufferList; - /// - friend class BufferView; - /// Used when typesetting to place errorboxes. TexRow texrow; }; diff --git a/src/bufferlist.C b/src/bufferlist.C index 5373667768..55bbcb650d 100644 --- a/src/bufferlist.C +++ b/src/bufferlist.C @@ -96,7 +96,7 @@ bool BufferList::QwriteAll() it != bstore.end(); ++it) { if (!(*it)->isLyxClean()) { switch(AskConfirmation(_("Changes in document:"), - MakeDisplayPath((*it)->filename, + MakeDisplayPath((*it)->fileName(), 50), _("Save document?"))) { case 1: // Yes @@ -104,7 +104,7 @@ bool BufferList::QwriteAll() break; case 2: // No askMoreConfirmation = true; - unsaved += MakeDisplayPath((*it)->filename, 50); + unsaved += MakeDisplayPath((*it)->fileName(), 50); unsaved += "\n"; break; case 3: // Cancel @@ -127,14 +127,14 @@ bool BufferList::QwriteAll() bool BufferList::write(Buffer * buf, bool makeBackup) { minibuffer->Set(_("Saving document"), - MakeDisplayPath(buf->filename), "..."); + MakeDisplayPath(buf->fileName()), "..."); // We don't need autosaves in the immediate future. (Asger) buf->resetAutosaveTimers(); // make a backup if (makeBackup) { - string s = buf->filename + '~'; + string s = buf->fileName() + '~'; // Rename is the wrong way of making a backup, // this is the correct way. /* truss cp fil fil2: @@ -159,7 +159,7 @@ bool BufferList::write(Buffer * buf, bool makeBackup) // Doing it this way, also makes the inodes stay the same. // This is still not a very good solution, in particular we // might loose the owner of the backup. - FileInfo finfo(buf->filename); + FileInfo finfo(buf->fileName()); if (finfo.exist()) { mode_t fmode = finfo.getMode(); @@ -169,7 +169,7 @@ bool BufferList::write(Buffer * buf, bool makeBackup) times->modtime = finfo.getModificationTime(); long blksize = finfo.getBlockSize(); lyxerr.debug() << "BlockSize: " << blksize << endl; - FilePtr fin(buf->filename, FilePtr::read); + FilePtr fin(buf->fileName(), FilePtr::read); FilePtr fout(s, FilePtr::truncate); if (fin() && fout()) { char * cbuf = new char[blksize+1]; @@ -196,16 +196,16 @@ bool BufferList::write(Buffer * buf, bool makeBackup) } } - if (buf->writeFile(buf->filename, false)) { + if (buf->writeFile(buf->fileName(), false)) { buf->markLyxClean(); minibuffer->Set(_("Document saved as"), - MakeDisplayPath(buf->filename)); + MakeDisplayPath(buf->fileName())); // now delete the autosavefile - string a = OnlyPath(buf->filename); + string a = OnlyPath(buf->fileName()); a += '#'; - a += OnlyFilename(buf->filename); + a += OnlyFilename(buf->fileName()); a += '#'; FileInfo fileinfo(a); if (fileinfo.exist()) { @@ -217,8 +217,8 @@ bool BufferList::write(Buffer * buf, bool makeBackup) } else { // Saving failed, so backup is not backup if (makeBackup) { - string s = buf->filename + '~'; - rename(s.c_str(), buf->filename.c_str()); + string s = buf->fileName() + '~'; + rename(s.c_str(), buf->fileName().c_str()); } minibuffer->Set(_("Save failed!")); return false; @@ -254,11 +254,11 @@ bool BufferList::close(Buffer * buf) if (buf->paragraph && !buf->isLyxClean() && !quitting) { ProhibitInput(); switch(AskConfirmation(_("Changes in document:"), - MakeDisplayPath(buf->filename, 50), + MakeDisplayPath(buf->fileName(), 50), _("Save document?"))){ case 1: // Yes if (write(buf)) { - lastfiles->newFile(buf->filename); + lastfiles->newFile(buf->fileName()); } else { AllowInput(); return false; @@ -284,7 +284,7 @@ void BufferList::makePup(int pup) int ant = 0; for(BufferStorage::iterator it = bstore.begin(); it != bstore.end(); ++it) { - string relbuf = MakeDisplayPath((*it)->filename, 30); + string relbuf = MakeDisplayPath((*it)->fileName(), 30); fl_addtopup(pup, relbuf.c_str()); ++ant; } @@ -310,11 +310,19 @@ void BufferList::updateInset(Inset * inset, bool mark_dirty) { for (BufferStorage::iterator it = bstore.begin(); it != bstore.end(); ++it) { +#ifdef MOVE_TEXT + if ((*it)->getUser() && (*it)->getUser()->text->UpdateInset(inset)) { + if (mark_dirty) + (*it)->markDirty(); + break; + } +#else if ((*it)->text && (*it)->text->UpdateInset(inset)) { if (mark_dirty) (*it)->markDirty(); break; } +#endif } } @@ -340,7 +348,7 @@ void BufferList::updateIncludedTeXfiles(string const & mastertmpdir) if (!(*it)->isDepClean(mastertmpdir)) { string writefile = mastertmpdir; writefile += '/'; - writefile += ChangeExtension((*it)->getFileName(), + writefile += ChangeExtension((*it)->fileName(), ".tex", true); (*it)->makeLaTeXFile(writefile, mastertmpdir, false, true); @@ -360,7 +368,7 @@ void BufferList::emergencyWriteAll() lyxerr <<_("lyx: Attempting to save" " document ") - << (*it)->filename + << (*it)->fileName() << _(" as...") << endl; for (int i = 0; i < 3 && !madeit; ++i) { @@ -371,13 +379,13 @@ void BufferList::emergencyWriteAll() // 2) In HOME directory. // 3) In "/tmp" directory. if (i == 0) { - s = (*it)->filename; + s = (*it)->fileName(); } else if (i == 1) { s = AddName(GetEnvPath("HOME"), - (*it)->filename); + (*it)->fileName()); } else { // MakeAbsPath to prepend the current drive letter on OS/2 s = AddName(MakeAbsPath("/tmp/"), - (*it)->filename); + (*it)->fileName()); } s += ".emergency"; @@ -473,7 +481,7 @@ bool BufferList::exists(string const & s) { for (BufferStorage::iterator it = bstore.begin(); it != bstore.end(); ++it) { - if ((*it)->filename == s) + if ((*it)->fileName() == s) return true; } return false; @@ -484,7 +492,7 @@ Buffer * BufferList::getBuffer(string const & s) { for(BufferStorage::iterator it = bstore.begin(); it != bstore.end(); ++it) { - if ((*it)->filename == s) + if ((*it)->fileName() == s) return (*it); } return 0; @@ -600,7 +608,7 @@ Buffer * BufferList::loadLyXFile(string const & filename, bool tolastfiles) } if (b && tolastfiles) - lastfiles->newFile(b->getFileName()); + lastfiles->newFile(b->fileName()); return b; } diff --git a/src/insets/figinset.C b/src/insets/figinset.C index b1442aeb58..50f3ddee0f 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -1113,7 +1113,7 @@ void InsetFig::Write(ostream & os) Regenerate(); os << "Figure size " << wid << " " << hgh << "\n"; if (!fname.empty()) { - string buf1 = OnlyPath(owner->getFileName()); + string buf1 = OnlyPath(owner->fileName()); string fname2 = MakeRelPath(fname, buf1); os << "file " << fname2 << "\n"; } @@ -1145,7 +1145,7 @@ void InsetFig::Read(LyXLex & lex) } else if (token == "file") { if (lex.next()) { buf = lex.GetString(); - string buf1 = OnlyPath(owner->getFileName()); + string buf1 = OnlyPath(owner->fileName()); fname = MakeAbsPath(buf, buf1); changedfname = true; } @@ -1354,7 +1354,7 @@ void InsetFig::Regenerate() return; } - string buf1 = OnlyPath(owner->getFileName()); + string buf1 = OnlyPath(owner->fileName()); string fname2 = MakeRelPath(fname, buf1); string gcmd = "\\includegraphics{" + fname2 + '}'; @@ -1486,7 +1486,7 @@ void InsetFig::TempRegenerate() return; } - string buf1 = OnlyPath(owner->getFileName()); + string buf1 = OnlyPath(owner->fileName()); string fname2 = MakeRelPath(tfname, buf1); // \includegraphics*[][]{file} string gcmd = "\\includegraphics{" + fname2 + '}'; @@ -1894,7 +1894,7 @@ void InsetFig::CallbackFig(long arg) angle = atof(fl_get_input(form->Angle)); p = fl_get_input(form->EpsFile); if (p && *p) { - string buf1 = OnlyPath(owner->getFileName()); + string buf1 = OnlyPath(owner->fileName()); fname = MakeAbsPath(p, buf1); changedfname = true; } else { @@ -1935,6 +1935,7 @@ void InsetFig::CallbackFig(long arg) fl_hide_form(form->Figure); #if FL_REVISION == 89 #warning Reactivate this free_form calls +#warning Jug, is this still a problem? #else fl_free_form(form->Figure); free(form); @@ -2067,7 +2068,7 @@ void InsetFig::RestoreForm() sprintf(buf, "%g", angle); fl_set_input(form->Angle, buf); if (!fname.empty()){ - string buf1 = OnlyPath(owner->getFileName()); + string buf1 = OnlyPath(owner->fileName()); string fname2 = MakeRelPath(fname, buf1); fl_set_input(form->EpsFile, fname2.c_str()); } @@ -2093,7 +2094,7 @@ void InsetFig::Preview(char const * p) return; // parent process } - string buf1 = OnlyPath(owner->getFileName()); + string buf1 = OnlyPath(owner->fileName()); string buf2 = MakeAbsPath(p, buf1); lyxerr << "Error during rendering " @@ -2113,17 +2114,17 @@ void InsetFig::BrowseFile() if (lyxerr.debugging()) { lyxerr << "Filename: " - << owner->getFileName() << endl; + << owner->fileName() << endl; } string p = fl_get_input(form->EpsFile); - string buf = MakeAbsPath(owner->getFileName()); + string buf = MakeAbsPath(owner->fileName()); string buf2 = OnlyPath(buf); if (!p.empty()) { buf = MakeAbsPath(p, buf2); buf = OnlyPath(buf); } else { - buf = OnlyPath(owner->getFileName().c_str()); + buf = OnlyPath(owner->fileName().c_str()); } // Does user clipart directory exist? diff --git a/src/insets/insetbib.C b/src/insets/insetbib.C index 44d8fa9f06..d20d627ec4 100644 --- a/src/insets/insetbib.C +++ b/src/insets/insetbib.C @@ -61,8 +61,13 @@ extern "C" void bibitem_cb(FL_OBJECT *, long data) inset->setOptions(fl_get_input(bibitem_form->label)); fl_hide_form(bibitem_form->bibitem_form); // Does look like a hack? It is! (but will change at 0.13) +#ifdef MOVE_TEXT + current_view->text->RedoParagraph(); + current_view->update(1); +#else current_view->buffer()->text->RedoParagraph(); current_view->buffer()->update(1); +#endif break; } // fall through to Cancel on RO-mode } diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index 360a23aa8b..95e9136dc1 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -78,7 +78,7 @@ public: /// void setFilename(string const & n) { setContents(n); } /// - string getMasterFilename() const { return master->getFileName(); } + string getMasterFilename() const { return master->fileName(); } /// string getFileName() const { return filename; diff --git a/src/insets/insetparent.C b/src/insets/insetparent.C index 6201487165..8738e04d5b 100644 --- a/src/insets/insetparent.C +++ b/src/insets/insetparent.C @@ -32,7 +32,7 @@ InsetParent::InsetParent(string const & fn, Buffer * owner) : InsetCommand("lyxparent") { if (owner) - setContents(MakeAbsPath(fn, OnlyPath(owner->getFileName()))); + setContents(MakeAbsPath(fn, OnlyPath(owner->fileName()))); else setContents(fn); } diff --git a/src/intl.C b/src/intl.C index 86d1860d07..f59e997cba 100644 --- a/src/intl.C +++ b/src/intl.C @@ -48,11 +48,6 @@ Intl::Intl() } -Intl::~Intl() -{ -} - - int Intl::SetPrimary(string const & lang) { if (lyxerr.debugging(Debug::KBMAP)) @@ -129,19 +124,17 @@ void Intl::ToggleKeyMap() void Intl::KeyMapPrim() { - int i; - string p; - fl_set_button(fd_form_keymap->KeyOffBtn, 0); fl_set_button(fd_form_keymap->KeyOnBtn, 1); fl_set_button(fd_form_keymap->KeyOnBtn2, 0); /* read text from choice */ - i = Language->get(); + int i = Language->get(); if (lyxerr.debugging(Debug::KBMAP)) lyxerr << "Table: " << tex_babel[i-1] << endl; + string p; if (i == otherkeymap) p = fl_get_input(fd_form_keymap->OtherKeymap); else diff --git a/src/intl.h b/src/intl.h index 35bb46e3cb..8cf5bf36d5 100644 --- a/src/intl.h +++ b/src/intl.h @@ -31,8 +31,6 @@ class Intl public: /// Intl(); - /// - ~Intl(); /// show key mapping dialog void MenuKeymap(); @@ -52,23 +50,18 @@ public: /// int SetSecondary(string const &); - // insert correct stuff into paragraph - //void TranslateAndInsert(char c, LyXText *text); - /// initialize key mapper void InitKeyMapper(bool on); /// Get the Translation Manager - inline TransManager *getTrans(); + inline TransManager * getTrans(); /// bool keymapon; /// - char *chsetcode; + char * chsetcode; /// - static void DispatchCallback(FL_OBJECT*, long); + static void DispatchCallback(FL_OBJECT *, long); private: - /// - //int SelectCharset(char const *code); /// void update(); /// @@ -85,21 +78,21 @@ private: int otherkeymap; /// - FD_KeyMap *fd_form_keymap; + FD_KeyMap * fd_form_keymap; /// - Combox *Language; + Combox * Language; /// - Combox *Language2; + Combox * Language2; /// string & prim_lang; /// string & sec_lang; /// - TransManager *trans; + TransManager * trans; }; -TransManager* Intl::getTrans() +TransManager * Intl::getTrans() { return trans; } diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 9e0882f2bb..8223a89ff7 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -291,29 +291,45 @@ void SetUpdateTimer(float time) } +// candidate for move to BufferView void BeforeChange() { current_view->getScreen()->ToggleSelection(); +#ifdef MOVE_TEXT + current_view->text->ClearSelection(); +#else current_view->buffer()->text->ClearSelection(); +#endif FreeUpdateTimer(); } +// candidate for move to BufferView void SmallUpdate(signed char f) { current_view->getScreen()->SmallUpdate(); if (current_view->getScreen()->TopCursorVisible() != current_view->getScreen()->first){ +#ifdef MOVE_TEXT + current_view->update(f); +#else current_view->buffer()->update(f); +#endif return; } current_view->fitCursor(); current_view->updateScrollbar(); - + +#ifdef MOVE_TEXT + if (!current_view->text->selection) + current_view->text->sel_cursor = + current_view->text->cursor; +#else if (!current_view->buffer()->text->selection) current_view->buffer()->text->sel_cursor = current_view->buffer()->text->cursor; +#endif if (f == 1 || f == -1) { if (current_view->buffer()->isLyxClean()) { @@ -340,7 +356,7 @@ void MenuWrite(Buffer * buf) { XFlush(fl_display); if (!bufferlist.write(buf)) { - string fname = buf->getFileName(); + string fname = buf->fileName(); string s = MakeAbsPath(fname); if (AskQuestion(_("Save failed. Rename and try again?"), MakeDisplayPath(s, 50), @@ -348,7 +364,7 @@ void MenuWrite(Buffer * buf) MenuWriteAs(buf); } } else { - lastfiles->newFile(buf->getFileName()); + lastfiles->newFile(buf->fileName()); } } @@ -356,9 +372,13 @@ void MenuWrite(Buffer * buf) // should be moved to BufferView.C void MenuWriteAs(Buffer * buffer) { +#ifdef MOVE_TEXT + if (!current_view->text) return; +#else if (!buffer->text) return; +#endif - string fname = buffer->getFileName(); + string fname = buffer->fileName(); string oldname = fname; LyXFileDlg fileDlg; @@ -402,7 +422,7 @@ void MenuWriteAs(Buffer * buffer) bufferlist.close(bufferlist.getBuffer(s)); // Ok, change the name of the buffer, but don't save! - buffer->setFileName(s); + buffer->fileName(s); buffer->markDirty(); minibuffer->Set(_("Document renamed to '"), @@ -420,7 +440,7 @@ void MenuWriteAs(Buffer * buffer) } // Ok, change the name of the buffer - buffer->setFileName(s); + buffer->fileName(s); buffer->markDirty(); // And save // Small bug: If the save fails, we have irreversible changed the name @@ -434,11 +454,11 @@ int MenuRunLaTeX(Buffer * buffer) int ret = 0; if (buffer->isLinuxDoc()) - ret = RunLinuxDoc(1, buffer->getFileName()); + ret = RunLinuxDoc(1, buffer->fileName()); else if (buffer->isLiterate()) ret = buffer->runLiterate(); else if (buffer->isDocBook()) - ret = RunDocBook(1, buffer->getFileName()); + ret = RunDocBook(1, buffer->fileName()); else ret = buffer->runLaTeX(); @@ -522,12 +542,17 @@ int MenuRunChktex(Buffer * buffer) int MakeDVIOutput(Buffer * buffer) { +#ifdef MOVE_TEXT + if (!(current_view->text)) + return 1; +#else if (!(buffer->text)) return 1; +#endif int ret = 0; - string path = OnlyPath(buffer->getFileName()); + string path = OnlyPath(buffer->fileName()); if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) { path = buffer->tmppath; } @@ -614,8 +639,13 @@ bool RunScript(Buffer * buffer, bool wait, // Returns false if we fail bool MenuRunDvips(Buffer * buffer, bool wait = false) { +#ifdef MOVE_TEXT + if (!current_view->text) + return false; +#else if (!buffer->text) return false; +#endif ProhibitInput(); @@ -625,7 +655,7 @@ bool MenuRunDvips(Buffer * buffer, bool wait = false) return false; } // Generate postscript file - string psname = ChangeExtension (buffer->getFileName(), + string psname = ChangeExtension (buffer->fileName(), ".ps_tmp", true); string paper; @@ -686,7 +716,7 @@ bool MenuRunDvips(Buffer * buffer, bool wait = false) command += lyxrc->print_landscape_flag; } // push directorypath, if necessary - string path = OnlyPath(buffer->getFileName()); + string path = OnlyPath(buffer->fileName()); if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){ path = buffer->tmppath; } @@ -700,8 +730,13 @@ bool MenuRunDvips(Buffer * buffer, bool wait = false) // Returns false if we fail bool MenuPreviewPS(Buffer * buffer) { +#ifdef MOVE_TEXT + if (!current_view->text) + return false; +#else if (!buffer->text) return false; +#endif // Generate postscript file if (!MenuRunDvips(buffer, true)) { @@ -710,10 +745,10 @@ bool MenuPreviewPS(Buffer * buffer) // Start postscript viewer ProhibitInput(); - string ps = ChangeExtension (buffer->getFileName(), + string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true); // push directorypath, if necessary - string path = OnlyPath(buffer->getFileName()); + string path = OnlyPath(buffer->fileName()); if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){ path = buffer->tmppath; } @@ -726,8 +761,13 @@ bool MenuPreviewPS(Buffer * buffer) void MenuFax(Buffer * buffer) { +#ifdef MOVE_TEXT + if (!current_view->text) + return; +#else if (!buffer->text) return; +#endif // Generate postscript file if (!MenuRunDvips(buffer, true)) { @@ -735,8 +775,8 @@ void MenuFax(Buffer * buffer) } // Send fax - string ps = ChangeExtension (buffer->getFileName(), ".ps_tmp", true); - string path = OnlyPath (buffer->getFileName()); + string ps = ChangeExtension (buffer->fileName(), ".ps_tmp", true); + string path = OnlyPath (buffer->fileName()); if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)) { path = buffer->tmppath; } @@ -753,9 +793,13 @@ void MenuFax(Buffer * buffer) // Returns false if we fail bool MenuPreview(Buffer * buffer) { +#ifdef MOVE_TEXT + if (!current_view->text) + return false; +#else if (!buffer->text) return false; - +#endif string paper; char real_papersize = buffer->params.papersize; @@ -800,7 +844,7 @@ bool MenuPreview(Buffer * buffer) } // push directorypath, if necessary - string path = OnlyPath(buffer->getFileName()); + string path = OnlyPath(buffer->fileName()); if (lyxrc->use_tempdir || (IsDirWriteable(path) < 1)){ path = buffer->tmppath; } @@ -814,128 +858,150 @@ bool MenuPreview(Buffer * buffer) void MenuMakeLaTeX(Buffer * buffer) { - if (buffer->text) { - // Get LaTeX-Filename - string s = buffer->getLatexName(); - - FileInfo fi(s); - if (fi.readable() && - !AskQuestion(_("File already exists:"), - MakeDisplayPath(s, 50), - _("Do you want to overwrite the file?"))) { - minibuffer->Set(_("Canceled")); - return; - } - - if (buffer->isDocBook()) - minibuffer->Set(_("DocBook does not have a latex backend")); - else { - if (buffer->isLinuxDoc()) - RunLinuxDoc(0, buffer->getFileName()); - else - buffer->makeLaTeXFile(s, string(), true); - minibuffer->Set(_("Nice LaTeX file saved as"), - MakeDisplayPath(s)); - buffer->markDviDirty(); +#ifdef MOVE_TEXT + if (!current_view->text) + return; +#else + if (!buffer->text) + return; +#endif + + // Get LaTeX-Filename + string s = buffer->getLatexName(); + + FileInfo fi(s); + if (fi.readable() && + !AskQuestion(_("File already exists:"), + MakeDisplayPath(s, 50), + _("Do you want to overwrite the file?"))) { + minibuffer->Set(_("Canceled")); + return; } + + if (buffer->isDocBook()) + minibuffer->Set(_("DocBook does not have a latex backend")); + else { + if (buffer->isLinuxDoc()) + RunLinuxDoc(0, buffer->fileName()); + else + buffer->makeLaTeXFile(s, string(), true); + minibuffer->Set(_("Nice LaTeX file saved as"), + MakeDisplayPath(s)); + buffer->markDviDirty(); } } void MenuMakeLinuxDoc(Buffer * buffer) { - if (buffer->text) { - if (!buffer->isLinuxDoc()) { - WriteAlert(_("Error!"), _("Document class must be linuxdoc.")); - return; - } - - // Get LinuxDoc-Filename - string s = ChangeExtension (buffer->getFileName(), - ".sgml", false); - - FileInfo fi(s); - if (fi.readable() && - !AskQuestion(_("File already exists:"), - MakeDisplayPath(s, 50), - _("Do you want to overwrite the file?"))) { - minibuffer->Set(_("Canceled")); - return; - } - - minibuffer->Set(_("Building LinuxDoc SGML file `"), - MakeDisplayPath(s), "'..."); - - buffer->makeLinuxDocFile(s, 65); - buffer->redraw(); - minibuffer->Set(_("LinuxDoc SGML file save as"), - MakeDisplayPath(s)); +#ifdef MOVE_TEXT + if (!current_view->text) return; +#else + if (!buffer->text) return; +#endif + + if (!buffer->isLinuxDoc()) { + WriteAlert(_("Error!"), _("Document class must be linuxdoc.")); + return; } + + // Get LinuxDoc-Filename + string s = ChangeExtension (buffer->fileName(), + ".sgml", false); + + FileInfo fi(s); + if (fi.readable() && + !AskQuestion(_("File already exists:"), + MakeDisplayPath(s, 50), + _("Do you want to overwrite the file?"))) { + minibuffer->Set(_("Canceled")); + return; + } + + minibuffer->Set(_("Building LinuxDoc SGML file `"), + MakeDisplayPath(s), "'..."); + + buffer->makeLinuxDocFile(s, 65); + buffer->redraw(); + minibuffer->Set(_("LinuxDoc SGML file save as"), + MakeDisplayPath(s)); } void MenuMakeDocBook(Buffer * buffer) { - if (buffer->text) { - if (!buffer->isDocBook()) { - WriteAlert(_("Error!"), - _("Document class must be docbook.")); - return; - } - - // Get DocBook-Filename - string s = ChangeExtension (buffer->getFileName(), - ".sgml", false); - - FileInfo fi(s); - if (fi.readable() && - !AskQuestion(_("File already exists:"), - MakeDisplayPath(s, 50), - _("Do you want to overwrite the file?"))) { - minibuffer->Set(_("Canceled")); - return; - } - - minibuffer->Set(_("Building DocBook SGML file `"), - MakeDisplayPath(s), "'..."); - - buffer->makeDocBookFile(s, 65); - buffer->redraw(); - minibuffer->Set(_("DocBook SGML file save as"), - MakeDisplayPath(s)); +#ifdef MOVE_TEXT + if (!current_view->text) return; +#else + if (!buffer->text) return; +#endif + + if (!buffer->isDocBook()) { + WriteAlert(_("Error!"), + _("Document class must be docbook.")); + return; } + + // Get DocBook-Filename + string s = ChangeExtension (buffer->fileName(), + ".sgml", false); + + FileInfo fi(s); + if (fi.readable() && + !AskQuestion(_("File already exists:"), + MakeDisplayPath(s, 50), + _("Do you want to overwrite the file?"))) { + minibuffer->Set(_("Canceled")); + return; + } + + minibuffer->Set(_("Building DocBook SGML file `"), + MakeDisplayPath(s), "'..."); + + buffer->makeDocBookFile(s, 65); + buffer->redraw(); + minibuffer->Set(_("DocBook SGML file save as"), + MakeDisplayPath(s)); } void MenuMakeAscii(Buffer * buffer) { - if (buffer->text) { - /* get LaTeX-Filename */ - string s = ChangeExtension (buffer->getFileName(), - ".txt", false); - - FileInfo fi(s); - if (fi.readable() && - !AskQuestion(_("File already exists:"), - MakeDisplayPath(s, 50), - _("Do you want to overwrite the file?"))) { - minibuffer->Set(_("Canceled")); - return; - } - - buffer->writeFileAscii(s, lyxrc->ascii_linelen); - - minibuffer->Set(_("Ascii file saved as"), MakeDisplayPath(s)); +#ifdef MOVE_TEXT + if (!current_view->text) return; +#else + if (!buffer->text) return; +#endif + + /* get LaTeX-Filename */ + string s = ChangeExtension (buffer->fileName(), + ".txt", false); + + FileInfo fi(s); + if (fi.readable() && + !AskQuestion(_("File already exists:"), + MakeDisplayPath(s, 50), + _("Do you want to overwrite the file?"))) { + minibuffer->Set(_("Canceled")); + return; } + + buffer->writeFileAscii(s, lyxrc->ascii_linelen); + + minibuffer->Set(_("Ascii file saved as"), MakeDisplayPath(s)); } void MenuPrint(Buffer * buffer) { - if (!buffer->text) +#ifdef MOVE_TEXT + if (!current_view->text) return; - - string input_file = ChangeExtension(buffer->getFileName(), +#else + if (!buffer->text) + return; +#endif + string input_file = ChangeExtension(buffer->fileName(), lyxrc->print_file_extension, true); fl_set_input(fd_form_print->input_file, input_file.c_str()); @@ -994,9 +1060,9 @@ void AutoSave() minibuffer->Set(_("Autosaving current document...")); // create autosave filename - string fname = OnlyPath(current_view->buffer()->getFileName()); + string fname = OnlyPath(current_view->buffer()->fileName()); fname += "#"; - fname += OnlyFilename(current_view->buffer()->getFileName()); + fname += OnlyFilename(current_view->buffer()->fileName()); fname += "#"; // tmp_ret will be located (usually) in /tmp @@ -1072,7 +1138,7 @@ Buffer * NewLyxFile(string const & filename) // find a free buffer Buffer * tmpbuf = bufferlist.newFile(name, tmpname); if (tmpbuf) - lastfiles->newFile(tmpbuf->getFileName()); + lastfiles->newFile(tmpbuf->fileName()); return tmpbuf; } @@ -1123,12 +1189,21 @@ void InsertAsciiFile(string const & f, bool asParagraph) // clear the selection BeforeChange(); +#ifdef MOVE_TEXT + if (!asParagraph) + current_view->text->InsertStringA(tmppar->text); + else + current_view->text->InsertStringB(tmppar->text); + delete tmppar; + current_view->update(1); +#else if (!asParagraph) current_view->buffer()->text->InsertStringA(tmppar->text); else current_view->buffer()->text->InsertStringB(tmppar->text); delete tmppar; current_view->buffer()->update(1); +#endif } @@ -1207,6 +1282,7 @@ void MenuPasteSelection(char at) } +// candidate for move to BufferView extern "C" void FootCB(FL_OBJECT *, long) { if (!current_view->available()) @@ -1214,12 +1290,19 @@ extern "C" void FootCB(FL_OBJECT *, long) minibuffer->Set(_("Inserting Footnote...")); current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + current_view->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE); + current_view->update(1); +#else current_view->buffer()->update(-2); current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::FOOTNOTE); current_view->buffer()->update(1); +#endif } +// candidate for move to LyXView void LayoutsCB(int sel, void *) { string tmp = tostr(sel); @@ -1362,12 +1445,17 @@ int RunDocBook(int flag, string const & filename) } +// candidate for move to BufferView void AllFloats(char flag, char figmar) { if (!current_view->available()) return; - + +#ifdef MOVE_TEXT + LyXCursor cursor = current_view->text->cursor; +#else LyXCursor cursor = current_view->buffer()->text->cursor; +#endif if (!flag && cursor.par->footnoteflag != LyXParagraph::NO_FOOTNOTE && ((figmar @@ -1406,9 +1494,17 @@ void AllFloats(char flag, char figmar) if (par->previous && par->previous->footnoteflag != LyXParagraph::CLOSED_FOOTNOTE){ /* should be */ +#ifdef MOVE_TEXT + current_view->text + ->SetCursorIntern(par + ->previous, + 0); + current_view->text->OpenFootnote(); +#else current_view->buffer()->text->SetCursorIntern(par->previous, 0); current_view->buffer()->text->OpenFootnote(); +#endif } } } @@ -1436,14 +1532,23 @@ void AllFloats(char flag, char figmar) ) ) ){ +#ifdef MOVE_TEXT + current_view->text->SetCursorIntern(par, 0); + current_view->text->CloseFootnote(); +#else current_view->buffer()->text->SetCursorIntern(par, 0); current_view->buffer()->text->CloseFootnote(); +#endif } } par = par->next; } +#ifdef MOVE_TEXT + current_view->text->SetCursorIntern(cursor.par, cursor.pos); +#else current_view->buffer()->text->SetCursorIntern(cursor.par, cursor.pos); +#endif current_view->redraw(); current_view->fitCursor(); current_view->updateScrollbar(); @@ -1533,6 +1638,130 @@ inline void EnableParagraphLayout () } +#ifdef MOVE_TEXT +bool UpdateLayoutParagraph() +{ + if (!current_view->getScreen() || !current_view->available()) { + if (fd_form_paragraph->form_paragraph->visible) + fl_hide_form(fd_form_paragraph->form_paragraph); + return false; + } + + Buffer * buf = current_view->buffer(); + + fl_set_input(fd_form_paragraph->input_labelwidth, + current_view->text->cursor.par->GetLabelWidthString().c_str()); + fl_set_button(fd_form_paragraph->radio_align_right, 0); + fl_set_button(fd_form_paragraph->radio_align_left, 0); + fl_set_button(fd_form_paragraph->radio_align_center, 0); + fl_set_button(fd_form_paragraph->radio_align_block, 0); + + int align = current_view->text->cursor.par->GetAlign(); + if (align == LYX_ALIGN_LAYOUT) + align = textclasslist.Style(buf->params.textclass, + current_view->text->cursor.par->GetLayout()).align; + + switch (align) { + case LYX_ALIGN_RIGHT: + fl_set_button(fd_form_paragraph->radio_align_right, 1); + break; + case LYX_ALIGN_LEFT: + fl_set_button(fd_form_paragraph->radio_align_left, 1); + break; + case LYX_ALIGN_CENTER: + fl_set_button(fd_form_paragraph->radio_align_center, 1); + break; + default: + fl_set_button(fd_form_paragraph->radio_align_block, 1); + break; + } + + fl_set_button(fd_form_paragraph->check_lines_top, + current_view->text->cursor.par->FirstPhysicalPar()->line_top); + fl_set_button(fd_form_paragraph->check_lines_bottom, + current_view->text->cursor.par->FirstPhysicalPar()->line_bottom); + fl_set_button(fd_form_paragraph->check_pagebreaks_top, + current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_top); + fl_set_button(fd_form_paragraph->check_pagebreaks_bottom, + current_view->text->cursor.par->FirstPhysicalPar()->pagebreak_bottom); + fl_set_button(fd_form_paragraph->check_noindent, + current_view->text->cursor.par->FirstPhysicalPar()->noindent); + fl_set_input (fd_form_paragraph->input_space_above, ""); + + switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.kind()) { + case VSpace::NONE: + fl_set_choice (fd_form_paragraph->choice_space_above, 1); + break; + case VSpace::DEFSKIP: + fl_set_choice (fd_form_paragraph->choice_space_above, 2); + break; + case VSpace::SMALLSKIP: + fl_set_choice (fd_form_paragraph->choice_space_above, 3); + break; + case VSpace::MEDSKIP: + fl_set_choice (fd_form_paragraph->choice_space_above, 4); + break; + case VSpace::BIGSKIP: + fl_set_choice (fd_form_paragraph->choice_space_above, 5); + break; + case VSpace::VFILL: + fl_set_choice (fd_form_paragraph->choice_space_above, 6); + break; + case VSpace::LENGTH: + fl_set_choice (fd_form_paragraph->choice_space_above, 7); + fl_set_input (fd_form_paragraph->input_space_above, + current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.length().asString().c_str()); + break; + } + fl_set_button (fd_form_paragraph->check_space_above, + current_view->text->cursor.par->FirstPhysicalPar()->added_space_top.keep()); + fl_set_input (fd_form_paragraph->input_space_below, ""); + switch (current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.kind()) { + case VSpace::NONE: + fl_set_choice (fd_form_paragraph->choice_space_below, + 1); + break; + case VSpace::DEFSKIP: + fl_set_choice (fd_form_paragraph->choice_space_below, + 2); + break; + case VSpace::SMALLSKIP: + fl_set_choice (fd_form_paragraph->choice_space_below, + 3); + break; + case VSpace::MEDSKIP: + fl_set_choice (fd_form_paragraph->choice_space_below, + 4); + break; + case VSpace::BIGSKIP: + fl_set_choice (fd_form_paragraph->choice_space_below, + 5); + break; + case VSpace::VFILL: + fl_set_choice (fd_form_paragraph->choice_space_below, + 6); + break; + case VSpace::LENGTH: + fl_set_choice (fd_form_paragraph->choice_space_below, + 7); + fl_set_input (fd_form_paragraph->input_space_below, + current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.length().asString().c_str()); + break; + } + fl_set_button (fd_form_paragraph->check_space_below, + current_view->text->cursor.par->FirstPhysicalPar()->added_space_bottom.keep()); + + fl_set_button(fd_form_paragraph->check_noindent, + current_view->text->cursor.par->FirstPhysicalPar()->noindent); + + if (current_view->buffer()->isReadonly()) { + DisableParagraphLayout(); + } else { + EnableParagraphLayout(); + } + return true; +} +#else bool UpdateLayoutParagraph() { if (!current_view->getScreen() || !current_view->available()) { @@ -1655,7 +1884,7 @@ bool UpdateLayoutParagraph() } return true; } - +#endif void MenuLayoutParagraph() { @@ -2030,6 +2259,7 @@ void MenuLayoutSave() } +// candidate for move to BufferView void NoteCB() { InsetInfo * new_inset = new InsetInfo(); @@ -2038,32 +2268,47 @@ void NoteCB() } +// candidate for move to BufferView void OpenStuff() { if (current_view->available()) { minibuffer->Set(_("Open/Close...")); current_view->getScreen()->HideCursor(); BeforeChange(); +#ifdef MOVE_TEXT + current_view->update(-2); + current_view->text->OpenStuff(); + current_view->update(0); +#else current_view->buffer()->update(-2); current_view->buffer()->text->OpenStuff(); current_view->buffer()->update(0); +#endif } } +// candidate for move to BufferView void ToggleFloat() { if (current_view->available()) { minibuffer->Set(_("Open/Close...")); current_view->getScreen()->HideCursor(); BeforeChange(); +#ifdef MOVE_TEXT + current_view->update(-2); + current_view->text->ToggleFootnote(); + current_view->update(0); +#else current_view->buffer()->update(-2); current_view->buffer()->text->ToggleFootnote(); current_view->buffer()->update(0); +#endif } } +// candidate for move to BufferView void MenuUndo() { /* if (current_view->buffer()->the_locking_inset) { @@ -2075,15 +2320,24 @@ void MenuUndo() minibuffer->Set(_("Undo")); current_view->getScreen()->HideCursor(); BeforeChange(); +#ifdef MOVE_TEXT + current_view->update(-2); + if (!current_view->text->TextUndo()) + minibuffer->Set(_("No further undo information")); + else + current_view->update(-1); +#else current_view->buffer()->update(-2); if (!current_view->buffer()->text->TextUndo()) minibuffer->Set(_("No further undo information")); else current_view->buffer()->update(-1); +#endif } } +// candidate for move to BufferView void MenuRedo() { if (current_view->buffer()->the_locking_inset) { @@ -2095,20 +2349,33 @@ void MenuRedo() minibuffer->Set(_("Redo")); current_view->getScreen()->HideCursor(); BeforeChange(); +#ifdef MOVE_TEXT + current_view->update(-2); + if (!current_view->text->TextRedo()) + minibuffer->Set(_("No further redo information")); + else + current_view->update(-1); +#else current_view->buffer()->update(-2); if (!current_view->buffer()->text->TextRedo()) minibuffer->Set(_("No further redo information")); else current_view->buffer()->update(-1); +#endif } } +// candidate for move to BufferView void HyphenationPoint() { if (current_view->available()) { current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); +#else current_view->buffer()->update(-2); +#endif InsetSpecialChar * new_inset = new InsetSpecialChar(InsetSpecialChar::HYPHENATION); current_view->buffer()->insertInset(new_inset); @@ -2116,11 +2383,16 @@ void HyphenationPoint() } +// candidate for move to BufferView void Ldots() { if (current_view->available()) { current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); +#else current_view->buffer()->update(-2); +#endif InsetSpecialChar * new_inset = new InsetSpecialChar(InsetSpecialChar::LDOTS); current_view->buffer()->insertInset(new_inset); @@ -2128,11 +2400,16 @@ void Ldots() } +// candidate for move to BufferView void EndOfSentenceDot() { if (current_view->available()) { current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); +#else current_view->buffer()->update(-2); +#endif InsetSpecialChar * new_inset = new InsetSpecialChar(InsetSpecialChar::END_OF_SENTENCE); current_view->buffer()->insertInset(new_inset); @@ -2140,11 +2417,16 @@ void EndOfSentenceDot() } +// candidate for move to BufferView void MenuSeparator() { if (current_view->available()) { current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); +#else current_view->buffer()->update(-2); +#endif InsetSpecialChar * new_inset = new InsetSpecialChar(InsetSpecialChar::MENU_SEPARATOR); current_view->buffer()->insertInset(new_inset); @@ -2152,35 +2434,56 @@ void MenuSeparator() } +// candidate for move to BufferView void Newline() { if (current_view->available()) { current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + current_view->text->InsertChar(LyXParagraph::META_NEWLINE); + current_view->update(-1); +#else current_view->buffer()->update(-2); current_view->buffer()->text->InsertChar(LyXParagraph::META_NEWLINE); current_view->buffer()->update(-1); +#endif } } +// candidate for move to BufferView void ProtectedBlank() { if (current_view->available()) { current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + current_view->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR); + current_view->update(-1); +#else current_view->buffer()->update(-2); current_view->buffer()->text->InsertChar(LyXParagraph::META_PROTECTED_SEPARATOR); current_view->buffer()->update(-1); +#endif } } +// candidate for move to BufferView void HFill() { if (current_view->available()) { current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + current_view->text->InsertChar(LyXParagraph::META_HFILL); + current_view->update(-1); +#else current_view->buffer()->update(-2); current_view->buffer()->text->InsertChar(LyXParagraph::META_HFILL); current_view->buffer()->update(-1); +#endif } } @@ -2275,6 +2578,27 @@ void StyleResetCB() * future perhaps we could try to implement a callback to the button-bar. * That is, `light' the bold button when the font is currently bold, etc. */ +#ifdef MOVE_TEXT +string CurrentState() +{ + string state; + if (current_view->available()) { + // I think we should only show changes from the default + // font. (Asger) + Buffer * buffer = current_view->buffer(); + LyXFont font = current_view->text->real_current_font; + LyXFont defaultfont = textclasslist.TextClass(buffer-> + params.textclass).defaultfont(); + font.reduce(defaultfont); + state = _("Font: ") + font.stateText(); + + int depth = current_view->text->GetDepth(); + if (depth > 0) + state += string(_(", Depth: ")) + tostr(depth); + } + return state; +} +#else string CurrentState() { string state; @@ -2294,8 +2618,9 @@ string CurrentState() } return state; } +#endif - +// candidate for move to BufferView /* -------> Does the actual toggle job of the XxxCB() calls above. * Also shows the current font state. */ @@ -2304,9 +2629,15 @@ void ToggleAndShow(LyXFont const & font) { if (current_view->available()) { current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + current_view->text->ToggleFree(font, toggleall); + current_view->update(1); +#else current_view->buffer()->update(-2); current_view->buffer()->text->ToggleFree(font, toggleall); current_view->buffer()->update(1); +#endif } // removed since it overrides the ToggleFree Message about the style // Since Styles are more "High Level" than raw fonts I think the user @@ -2315,14 +2646,21 @@ void ToggleAndShow(LyXFont const & font) } +// candidate for move to BufferView extern "C" void MarginCB(FL_OBJECT *, long) { if (current_view->available()) { minibuffer->Set(_("Inserting margin note...")); current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + current_view->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN); + current_view->update(1); +#else current_view->buffer()->update(-2); current_view->buffer()->text->InsertFootnoteEnvironment(LyXParagraph::MARGIN); current_view->buffer()->update(1); +#endif } } @@ -2351,61 +2689,110 @@ extern "C" void TableCB(FL_OBJECT *, long) } +// candidate for move to BufferView void CopyEnvironmentCB() { if (current_view->available()) { +#ifdef MOVE_TEXT + current_view->text->copyEnvironmentType(); + /* clear the selection, even if mark_set */ + current_view->getScreen()->ToggleSelection(); + current_view->text->ClearSelection(); + current_view->update(-2); + minibuffer->Set(_("Paragraph environment type copied")); +#else current_view->buffer()->text->copyEnvironmentType(); /* clear the selection, even if mark_set */ current_view->getScreen()->ToggleSelection(); current_view->buffer()->text->ClearSelection(); current_view->buffer()->update(-2); minibuffer->Set(_("Paragraph environment type copied")); +#endif } } +// candidate for move to BufferView void PasteEnvironmentCB() { if (current_view->available()) { +#ifdef MOVE_TEXT + current_view->text->pasteEnvironmentType(); + minibuffer->Set(_("Paragraph environment type set")); + current_view->update(1); +#else current_view->buffer()->text->pasteEnvironmentType(); minibuffer->Set(_("Paragraph environment type set")); current_view->buffer()->update(1); +#endif } } +// candidate for move to BufferView void CopyCB() { if (current_view->available()) { +#ifdef MOVE_TEXT + current_view->text->CopySelection(); + /* clear the selection, even if mark_set */ + current_view->getScreen()->ToggleSelection(); + current_view->text->ClearSelection(); + current_view->update(-2); + minibuffer->Set(_("Copy")); +#else current_view->buffer()->text->CopySelection(); /* clear the selection, even if mark_set */ current_view->getScreen()->ToggleSelection(); current_view->buffer()->text->ClearSelection(); current_view->buffer()->update(-2); minibuffer->Set(_("Copy")); +#endif } } +// candidate for move to BufferView void CutCB() { if (current_view->available()) { current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + current_view->text->CutSelection(); + current_view->update(1); +#else current_view->buffer()->update(-2); current_view->buffer()->text->CutSelection(); current_view->buffer()->update(1); +#endif minibuffer->Set(_("Cut")); } } +// candidate for move to BufferView void PasteCB() { if (!current_view->available()) return; minibuffer->Set(_("Paste")); current_view->getScreen()->HideCursor(); + /* clear the selection */ +#ifdef MOVE_TEXT + current_view->getScreen()->ToggleSelection(); + current_view->text->ClearSelection(); + current_view->update(-2); + + /* paste */ + current_view->text->PasteSelection(); + current_view->update(1); + /* clear the selection */ + current_view->getScreen()->ToggleSelection(); + current_view->text->ClearSelection(); + current_view->update(-2); +#else current_view->getScreen()->ToggleSelection(); current_view->buffer()->text->ClearSelection(); current_view->buffer()->update(-2); @@ -2418,9 +2805,11 @@ void PasteCB() current_view->getScreen()->ToggleSelection(); current_view->buffer()->text->ClearSelection(); current_view->buffer()->update(-2); +#endif } +// candidate for move to BufferView extern "C" void MeltCB(FL_OBJECT *, long) { if (!current_view->available()) return; @@ -2428,12 +2817,19 @@ extern "C" void MeltCB(FL_OBJECT *, long) minibuffer->Set(_("Melt")); current_view->getScreen()->HideCursor(); BeforeChange(); +#ifdef MOVE_TEXT + current_view->update(-2); + current_view->text->MeltFootnoteEnvironment(); + current_view->update(1); +#else current_view->buffer()->update(-2); current_view->buffer()->text->MeltFootnoteEnvironment(); current_view->buffer()->update(1); +#endif } +// candidate for move to BufferView // Change environment depth. // if decInc == 0, depth change taking mouse button number into account // if decInc == 1, increment depth @@ -2453,12 +2849,21 @@ extern "C" void DepthCB(FL_OBJECT * ob, long decInc) if (current_view->available()) { current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + if (button == 1) + current_view->text->IncDepth(); + else + current_view->text->DecDepth(); + current_view->update(1); +#else current_view->buffer()->update(-2); if (button == 1) current_view->buffer()->text->IncDepth(); else current_view->buffer()->text->DecDepth(); current_view->buffer()->update(1); +#endif minibuffer->Set(_("Changed environment depth" " (in possible range, maybe not)")); } @@ -2685,7 +3090,19 @@ extern "C" void ParagraphApplyCB(FL_OBJECT *, long) labelwidthstring = fl_get_input(fd_form_paragraph->input_labelwidth); noindent = fl_get_button(fd_form_paragraph->check_noindent); - + +#ifdef MOVE_TEXT + current_view->text->SetParagraph(line_top, + line_bottom, + pagebreak_top, + pagebreak_bottom, + space_top, + space_bottom, + align, + labelwidthstring, + noindent); + current_view->update(1); +#else current_view->buffer()->text->SetParagraph(line_top, line_bottom, pagebreak_top, @@ -2696,6 +3113,7 @@ extern "C" void ParagraphApplyCB(FL_OBJECT *, long) labelwidthstring, noindent); current_view->buffer()->update(1); +#endif minibuffer->Set(_("Paragraph layout set")); } @@ -2880,6 +3298,14 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long) // successfully loaded redo = true; minibuffer->Set(_("Converting document to new document class...")); +#ifdef MOVE_TEXT + int ret = current_view->text-> + SwitchLayoutsBetweenClasses(current_view->buffer()-> + params.textclass, + new_class, + current_view->buffer()-> + paragraph); +#else int ret = current_view->buffer()-> text-> SwitchLayoutsBetweenClasses(current_view->buffer()-> @@ -2887,6 +3313,7 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long) new_class, current_view->buffer()-> paragraph); +#endif if (ret){ string s; @@ -3012,6 +3439,42 @@ extern "C" void DocumentBulletsCB(FL_OBJECT *, long) } +// candidate for move to BufferView +#ifdef MOVE_TEXT +void GotoNote() +{ + if (!current_view->getScreen()) + return; + + current_view->getScreen()->HideCursor(); + BeforeChange(); + current_view->update(-2); + LyXCursor tmp; + + if (!current_view->text->GotoNextNote()) { + if (current_view->text->cursor.pos + || current_view->text->cursor.par != + current_view->text->FirstParagraph()) + { + tmp = current_view->text->cursor; + current_view->text->cursor.par = + current_view->text->FirstParagraph(); + current_view->text->cursor.pos = 0; + if (!current_view->text->GotoNextNote()) { + current_view->text->cursor = tmp; + minibuffer->Set(_("No more notes")); + LyXBell(); + } + } else { + minibuffer->Set(_("No more notes")); + LyXBell(); + } + } + current_view->update(0); + current_view->text->sel_cursor = + current_view->text->cursor; +} +#else void GotoNote() { if (!current_view->getScreen()) @@ -3045,17 +3508,25 @@ void GotoNote() current_view->buffer()->text->sel_cursor = current_view->buffer()->text->cursor; } +#endif - +// candidate for move to BufferView void InsertCorrectQuote() { Buffer * cbuffer = current_view->buffer(); char c; +#ifdef MOVE_TEXT + if (current_view->text->cursor.pos ) + c = current_view->text->cursor.par->GetChar(current_view->text->cursor.pos - 1); + else + c = ' '; +#else if (cbuffer->text->cursor.pos ) c = cbuffer->text->cursor.par->GetChar(cbuffer->text->cursor.pos - 1); else c = ' '; +#endif cbuffer->insertInset(new InsetQuotes(c, cbuffer->params)); } @@ -3145,6 +3616,85 @@ extern "C" void PreambleOKCB(FL_OBJECT * ob, long data) /* callbacks for form form_table */ +#ifdef MOVE_TEXT +extern "C" void TableApplyCB(FL_OBJECT *, long) +{ + if (!current_view->getScreen()) + return; + + // check for tables in tables + if (current_view->text->cursor.par->table){ + WriteAlert(_("Impossible Operation!"), + _("Cannot insert table in table."), + _("Sorry.")); + return; + } + + minibuffer->Set(_("Inserting table...")); + + int ysize = int(fl_get_slider_value(fd_form_table->slider_columns) + 0.5); + int xsize = int(fl_get_slider_value(fd_form_table->slider_rows) + 0.5); + + + current_view->getScreen()->HideCursor(); + BeforeChange(); + current_view->update(-2); + + current_view->text->SetCursorParUndo(); + current_view->text->FreezeUndo(); + + current_view->text->BreakParagraph(); + current_view->update(-1); + + if (current_view->text->cursor.par->Last()) { + current_view->text->CursorLeft(); + + current_view->text->BreakParagraph(); + current_view->update(-1); + } + + current_view->text->current_font.setLatex(LyXFont::OFF); + //if (!fl_get_button(fd_form_table->check_latex)){ + // insert the new wysiwy table + current_view->text->SetLayout(0); // standard layout + if (current_view->text->cursor.par->footnoteflag == + LyXParagraph::NO_FOOTNOTE) { + current_view->text + ->SetParagraph(0, 0, + 0, 0, + VSpace (0.3 * current_view->buffer()-> + params.spacing.getValue(), + LyXLength::CM), + VSpace (0.3 * current_view->buffer()-> + params.spacing.getValue(), + LyXLength::CM), + LYX_ALIGN_CENTER, + string(), + 0); + } + else + current_view->text + ->SetParagraph(0, 0, + 0, 0, + VSpace(VSpace::NONE), + VSpace(VSpace::NONE), + LYX_ALIGN_CENTER, + string(), + 0); + + current_view->text->cursor.par->table = + new LyXTable(xsize, ysize); + + for (int i = 0; i < xsize * ysize - 1; ++i) + current_view->text->cursor.par->InsertChar(0, LyXParagraph::META_NEWLINE); + current_view->text->RedoParagraph(); + + current_view->text->UnFreezeUndo(); + + current_view->update(1); + minibuffer->Set(_("Table inserted")); +} +#else extern "C" void TableApplyCB(FL_OBJECT *, long) { if (!current_view->getScreen()) @@ -3222,7 +3772,7 @@ extern "C" void TableApplyCB(FL_OBJECT *, long) current_view->buffer()->update(1); minibuffer->Set(_("Table inserted")); } - +#endif extern "C" void TableCancelCB(FL_OBJECT *, long) { @@ -3256,7 +3806,7 @@ extern "C" void PrintApplyCB(FL_OBJECT *, long) if (!current_view->available()) return; Buffer * buffer = current_view->buffer(); - string path = OnlyPath(buffer->getFileName()); + string path = OnlyPath(buffer->fileName()); string pageflag; if (fl_get_button(fd_form_print->radio_even_pages)) @@ -3418,7 +3968,76 @@ extern "C" void PrintOKCB(FL_OBJECT * ob, long data) /* callbacks for form form_figure */ +#ifdef MOVE_TEXT +extern "C" void FigureApplyCB(FL_OBJECT *, long) +{ + if (!current_view->available()) + return; + + Buffer * buffer = current_view->buffer(); + if(buffer->isReadonly()) // paranoia + return; + + minibuffer->Set(_("Inserting figure...")); + if (fl_get_button(fd_form_figure->radio_inline) + || current_view->text->cursor.par->table) { + InsetFig * new_inset = new InsetFig(100, 20, buffer); + buffer->insertInset(new_inset); + minibuffer->Set(_("Figure inserted")); + new_inset->Edit(0, 0); + return; + } + + current_view->getScreen()->HideCursor(); + current_view->update(-2); + BeforeChange(); + + current_view->text->SetCursorParUndo(); + current_view->text->FreezeUndo(); + + current_view->text->BreakParagraph(); + current_view->update(-1); + + if (current_view->text->cursor.par->Last()) { + current_view->text->CursorLeft(); + + current_view->text->BreakParagraph(); + current_view->update(-1); + } + // The standard layout should always be numer 0; + current_view->text->SetLayout(0); + + if (current_view->text->cursor.par->footnoteflag == + LyXParagraph::NO_FOOTNOTE) { + current_view->text-> + SetParagraph(0, 0, + 0, 0, + VSpace (0.3 * buffer->params.spacing.getValue(), + LyXLength::CM), + VSpace (0.3 * + buffer->params.spacing.getValue(), + LyXLength::CM), + LYX_ALIGN_CENTER, string(), 0); + } else + current_view->text->SetParagraph(0, 0, + 0, 0, + VSpace(VSpace::NONE), + VSpace(VSpace::NONE), + LYX_ALIGN_CENTER, + string(), + 0); + + current_view->update(-1); + + Inset * new_inset = new InsetFig(100, 100, buffer); + buffer->insertInset(new_inset); + new_inset->Edit(0, 0); + current_view->update(0); + minibuffer->Set(_("Figure inserted")); + current_view->text->UnFreezeUndo(); +} +#else extern "C" void FigureApplyCB(FL_OBJECT *, long) { if (!current_view->available()) @@ -3487,7 +4106,7 @@ extern "C" void FigureApplyCB(FL_OBJECT *, long) minibuffer->Set(_("Figure inserted")); buffer->text->UnFreezeUndo(); } - +#endif extern "C" void FigureCancelCB(FL_OBJECT *, long) { @@ -3568,6 +4187,7 @@ void Reconfigure() } +// candidate for move to BufferView /* these functions are for the spellchecker */ char * NextWord(float & value) { @@ -3575,45 +4195,89 @@ char * NextWord(float & value) value = 1; return 0; } - + +#ifdef MOVE_TEXT + char * string = current_view->text->SelectNextWord(value); +#else char * string = current_view->buffer()->text->SelectNextWord(value); +#endif return string; } +// candidate for move to BufferView void SelectLastWord() { if (!current_view->available()) return; current_view->getScreen()->HideCursor(); - BeforeChange(); + BeforeChange(); +#ifdef MOVE_TEXT + current_view->text->SelectSelectedWord(); + current_view->getScreen()->ToggleSelection(false); + current_view->update(0); +#else current_view->buffer()->text->SelectSelectedWord(); current_view->getScreen()->ToggleSelection(false); current_view->buffer()->update(0); +#endif } +// candidate for move to BufferView void EndOfSpellCheck() { if (!current_view->available()) return; current_view->getScreen()->HideCursor(); - BeforeChange(); + BeforeChange(); +#ifdef MOVE_TEXT + current_view->text->SelectSelectedWord(); + current_view->text->ClearSelection(); + current_view->update(0); +#else current_view->buffer()->text->SelectSelectedWord(); current_view->buffer()->text->ClearSelection(); current_view->buffer()->update(0); +#endif } +// candidate for move to BufferView void ReplaceWord(string const & replacestring) { if (!current_view->getScreen()) return; current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + + /* clear the selection (if there is any) */ + current_view->getScreen()->ToggleSelection(false); + current_view->update(-2); + + /* clear the selection (if there is any) */ + current_view->getScreen()->ToggleSelection(false); + current_view->text-> + ReplaceSelectionWithString(replacestring.c_str()); + + current_view->text->SetSelectionOverString(replacestring.c_str()); + + // Go back so that replacement string is also spellchecked + for (string::size_type i = 0; i < replacestring.length() + 1; ++i) { + current_view->text->CursorLeftIntern(); + } + current_view->update(1); +#else + current_view->buffer()->update(-2); + + /* clear the selection (if there is any) */ + current_view->getScreen()->ToggleSelection(false); + current_view->buffer()->update(-2); /* clear the selection (if there is any) */ @@ -3628,6 +4292,7 @@ void ReplaceWord(string const & replacestring) current_view->buffer()->text->CursorLeftIntern(); } current_view->buffer()->update(1); +#endif } // End of spellchecker stuff @@ -3674,11 +4339,19 @@ extern "C" void TocSelectCB(FL_OBJECT * ob, long) } if (par) { +#ifdef MOVE_TEXT + BeforeChange(); + current_view->text->SetCursor(par, 0); + current_view->text->sel_cursor = + current_view->text->cursor; + current_view->update(0); +#else BeforeChange(); current_view->buffer()->text->SetCursor(par, 0); current_view->buffer()->text->sel_cursor = current_view->buffer()->text->cursor; current_view->buffer()->update(0); +#endif } else { WriteAlert(_("Error"), @@ -3759,7 +4432,7 @@ extern "C" void TocUpdateCB(FL_OBJECT *, long) } line[pos] = ' '; - pos++; + ++pos; /* now the contents */ LyXParagraph::size_type i = 0; @@ -3769,7 +4442,7 @@ extern "C" void TocUpdateCB(FL_OBJECT *, long) line[pos] = c; pos++; } - i++; + ++i; } line[pos] = '\0'; fl_add_browser_line(fd_form_toc->browser_toc, line); @@ -3785,7 +4458,7 @@ extern "C" void TocUpdateCB(FL_OBJECT *, long) tmptoclist->next = 0; int a = 0; - for (a = 0; a<6; a++){ + for (a = 0; a < 6; ++a) { tmptoclist->counter[a] = par->GetFirstCounter(a); } tmptoclist->appendix = par->appendix; @@ -3848,8 +4521,6 @@ extern "C" void RefUpdateCB(FL_OBJECT *, long) char const * const btmp = fl_get_browser_line(brow, fl_get_browser(brow)); string currentstr = btmp ? btmp : ""; - //string currentstr = fl_get_browser_line(brow, - // fl_get_browser(brow)); fl_clear_browser(brow); @@ -3910,6 +4581,7 @@ extern "C" void RefHideCB(FL_OBJECT *, long) } +// candidate for move to BufferView void UpdateInset(Inset * inset, bool mark_dirty) { if (!inset) @@ -3917,6 +4589,18 @@ void UpdateInset(Inset * inset, bool mark_dirty) /* very first check for locking insets*/ if (current_view->buffer()->the_locking_inset == inset){ +#ifdef MOVE_TEXT + if (current_view->text->UpdateInset(inset)){ + current_view->update(); + if (mark_dirty){ + if (current_view->buffer()->isLyxClean()) + minibuffer->setTimer(4); + current_view->buffer()->markDirty(); + } + current_view->updateScrollbar(); + return; + } +#else if (current_view->buffer()->text->UpdateInset(inset)){ current_view->update(); if (mark_dirty){ @@ -3927,11 +4611,22 @@ void UpdateInset(Inset * inset, bool mark_dirty) current_view->updateScrollbar(); return; } +#endif } /* first check the current buffer */ if (current_view->available()){ current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-3); + if (current_view->text->UpdateInset(inset)){ + if (mark_dirty) + current_view->update(1); + else + current_view->update(3); + return; + } +#else current_view->buffer()->update(-3); if (current_view->buffer()->text->UpdateInset(inset)){ if (mark_dirty) @@ -3940,6 +4635,7 @@ void UpdateInset(Inset * inset, bool mark_dirty) current_view->buffer()->update(3); return; } +#endif } // check all buffers @@ -3948,6 +4644,7 @@ void UpdateInset(Inset * inset, bool mark_dirty) } +// candidate for move to BufferView /* these functions return 1 if an error occured, otherwise 0 */ int LockInset(UpdatableInset * inset) @@ -3960,63 +4657,92 @@ int LockInset(UpdatableInset * inset) } +// candidate for move to BufferView void ShowLockedInsetCursor(long x, long y, int asc, int desc) { if (current_view->buffer()->the_locking_inset && current_view->getScreen()){ +#ifdef MOVE_TEXT + y += current_view->text->cursor.y; +#else y += current_view->buffer()->text->cursor.y; +#endif current_view->getScreen()->ShowManualCursor(x, y, asc, desc); } } +// candidate for move to BufferView void HideLockedInsetCursor(long x, long y, int asc, int desc) { if (current_view->buffer()->the_locking_inset && current_view->getScreen()){ +#ifdef MOVE_TEXT + y += current_view->text->cursor.y; +#else y += current_view->buffer()->text->cursor.y; +#endif current_view->getScreen()->HideManualCursor(x, y, asc, desc); } } +// candidate for move to BufferView void FitLockedInsetCursor(long x, long y, int asc, int desc) { if (current_view->buffer()->the_locking_inset && current_view->getScreen()){ +#ifdef MOVE_TEXT + y += current_view->text->cursor.y; +#else y += current_view->buffer()->text->cursor.y; +#endif if (current_view->getScreen()->FitManualCursor(x, y, asc, desc)) current_view->updateScrollbar(); } } +// candidate for move to BufferView int UnlockInset(UpdatableInset * inset) { if (inset && current_view->buffer()->the_locking_inset == inset){ inset->InsetUnlock(); current_view->buffer()->the_locking_inset = 0; +#ifdef MOVE_TEXT + current_view->text->FinishUndo(); +#else current_view->buffer()->text->FinishUndo(); +#endif return 0; } return bufferlist.unlockInset(inset); } +// candidate for move to BufferView void LockedInsetStoreUndo(Undo::undo_kind kind) { if (!current_view->buffer()->the_locking_inset) return; // shouldn't happen if (kind == Undo::EDIT) // in this case insets would not be stored! kind = Undo::FINISH; +#ifdef MOVE_TEXT + current_view->text->SetUndo(kind, + current_view->text->cursor.par-> + ParFromPos(current_view->text->cursor.pos)->previous, + current_view->text->cursor.par-> + ParFromPos(current_view->text->cursor.pos)->next); +#else current_view->buffer()->text->SetUndo(kind, current_view->buffer()->text->cursor.par-> ParFromPos(current_view->buffer()->text->cursor.pos)->previous, current_view->buffer()->text->cursor.par-> - ParFromPos(current_view->buffer()->text->cursor.pos)->next); + ParFromPos(current_view->buffer()->text->cursor.pos)->next); +#endif } diff --git a/src/lyx_gui_misc.C b/src/lyx_gui_misc.C index 802d3b7d78..6eaaee45ee 100644 --- a/src/lyx_gui_misc.C +++ b/src/lyx_gui_misc.C @@ -413,6 +413,6 @@ void WarnReadonly() { WriteAlert(_("Any changes will be ignored"), _("The document is read-only:"), - current_view->buffer()->getFileName()); + current_view->buffer()->fileName()); } diff --git a/src/lyx_main.C b/src/lyx_main.C index a20a9cc14e..01f9c504e0 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -114,6 +114,16 @@ LyX::LyX(int * argc, char * argv[]) lyxerr.debug() << "Yes we loaded some files." << endl; lyxGUI->regBuf(last_loaded); } + + // Execute batch commands if available + if (!batch_command.empty() && last_loaded) { + lyxerr << "About to handle -x '" << batch_command << "'" << endl; + //Buffer buffer("Script Buffer"); + //buffer.Dispatch(batch_command); + last_loaded->Dispatch(batch_command); + lyxerr << "We are done!" << endl; + return; // Maybe we could do something more clever than aborting.. + } // Let the ball begin... lyxGUI->runTime(); @@ -473,30 +483,30 @@ bool LyX::easyParse(int * argc, char * argv[]) string arg = argv[i]; // Check for -dbg int if (arg == "-dbg") { - if (i+1 < *argc) { - setDebuggingLevel(argv[i+1]); + if (i + 1 < *argc) { + setDebuggingLevel(argv[i + 1]); // Now, remove these two arguments by shifting // the following two places down. (*argc) -= 2; - for (int j= i; j < (*argc); j++) - argv[j] = argv[j+2]; - i--; // After shift, check this number again. + for (int j = i; j < (*argc); ++j) + argv[j] = argv[j + 2]; + --i; // After shift, check this number again. } else lyxerr << _("Missing number for -dbg switch!") << endl; } // Check for "-sysdir" else if (arg == "-sysdir") { - if (i+1 < *argc) { - system_lyxdir = argv[i+1]; + if (i + 1 < *argc) { + system_lyxdir = argv[i + 1]; // Now, remove these two arguments by shifting // the following two places down. (*argc) -= 2; - for (int j= i; j < (*argc); j++) - argv[j] = argv[j+2]; - i--; // After shift, check this number again. + for (int j= i; j < (*argc); ++j) + argv[j] = argv[j + 2]; + --i; // After shift, check this number again. } else lyxerr << _("Missing directory for -sysdir switch!") << endl; @@ -509,6 +519,56 @@ bool LyX::easyParse(int * argc, char * argv[]) else if (arg == "-nw") { gui = false; } + + // Check for "-x": Execute commands + else if (arg == "-x" || arg == "--execute") { + if (i + 1 < *argc) { + batch_command = string(argv[i + 1]); + + // Now, remove these two arguments by shifting + // the following two places down. + (*argc) -= 2; + for (int j = i; j < (*argc); ++j) + argv[j] = argv[j + 2]; + --i; // After shift, check this number again. + + } + else + lyxerr << _("Missing command string after -x switch!") << endl; + + // Argh. Setting gui to false segfaults.. + //gui = false; + } + + else if (arg == "-e" || arg == "--export") { + if (i + 1 < *argc) { + string type(argv[i+1]); + + (*argc) -= 2; + for (int j = i; j < (*argc); ++j) + argv[j] = argv[j + 2]; + --i; // After shift, check this number again. + + if (type == "tex") + type = "latex"; + else if (type == "ps") + type = "postscript"; + else if (type == "text" || type == "txt") + type = "ascii"; + + if (type == "latex" || type == "postscript" + || type == "ascii" || type == "html") + batch_command = "buffer-export " + type; + else + lyxerr << _("Unknown file type '") + << type << _("' after ") + << arg << _(" switch!") << endl; + } + else + lyxerr << _("Missing file type [eg latex, " + "ps...] after ") + << arg << _(" switch!") << endl; + } } return gui; } diff --git a/src/lyx_main.h b/src/lyx_main.h index 668e5dd7e9..cd7ac85e91 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -44,7 +44,7 @@ public: /**@name Constructors and Deconstructors */ //@{ /// the only allowed constructor - LyX(int *argc, char *argv[]); // constructor + LyX(int * argc, char * argv[]); // constructor // Always is useful a destructor ~LyX(); //@} @@ -58,9 +58,9 @@ private: /**@name Constructors and Deconstructors */ //@{ /// not allowed - LyX(const LyX &){;} // not allowed + LyX(const LyX &) {} // not allowed /// not allowed - LyX(){;} // not allowed + LyX() {} // not allowed //@} /**@name Private variables */ @@ -68,6 +68,8 @@ private: /// does this user start lyx for the first time? bool first_start; /// + string batch_command; + /// struct sigaction act_; //@} /**@name Private Members */ diff --git a/src/lyxfr1.C b/src/lyxfr1.C index c85a579eda..ea73c58e69 100644 --- a/src/lyxfr1.C +++ b/src/lyxfr1.C @@ -131,16 +131,19 @@ void LyXFindReplace1::StartSearch() LyXFindReplace0::StartSearch(); SetReplaceEnabled(!current_view->buffer()->isReadonly()); searchForward = true; +#ifdef MOVE_TEXT + if (lsSearch.empty()) + SetSearchString(GetSelectionOrWordAtCursor(current_view->text)); +#else if (lsSearch.empty()) SetSearchString(GetSelectionOrWordAtCursor(current_view->buffer()->text)); +#endif } // TODO?: the user can insert multiple spaces with this routine (1999-01-11, dnaber) void LyXFindReplace1::SearchReplaceCB() { - LyXText *ltCur; - if (!current_view->getScreen()) return; if (current_view->buffer()->isReadonly()) @@ -159,9 +162,23 @@ void LyXFindReplace1::SearchReplaceCB() string const replacestring = ReplaceString(); current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + + LyXText * ltCur = current_view->text; + if (ltCur->selection) { + // clear the selection (if there is any) + current_view->getScreen()->ToggleSelection(false); + current_view->text-> + ReplaceSelectionWithString(replacestring.c_str()); + current_view->text-> + SetSelectionOverString(replacestring.c_str()); + current_view->update(1); + } +#else current_view->buffer()->update(-2); - ltCur = current_view->buffer()->text; + LyXText * ltCur = current_view->buffer()->text; if (ltCur->selection) { // clear the selection (if there is any) current_view->getScreen()->ToggleSelection(false); @@ -171,6 +188,7 @@ void LyXFindReplace1::SearchReplaceCB() SetSelectionOverString(replacestring.c_str()); current_view->buffer()->update(1); } +#endif // jump to next match: SearchCB( searchForward ); @@ -180,7 +198,7 @@ void LyXFindReplace1::SearchReplaceCB() // replaces all occurences of a string (1999-01-15, dnaber@mini.gt.owl.de) void LyXFindReplace1::SearchReplaceAllCB() { - LyXText *ltCur; + LyXText * ltCur; if (!current_view->getScreen()) return; @@ -201,6 +219,26 @@ void LyXFindReplace1::SearchReplaceAllCB() current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + // start at top + current_view->text->ClearSelection(); + current_view->text->CursorTop(); + + int replace_count = 0; + do { + ltCur = current_view->text; + if (ltCur->selection) { + current_view->update(-2); + current_view->getScreen()->ToggleSelection(false); + current_view->text-> + ReplaceSelectionWithString(replacestring.c_str()); + current_view->text-> + SetSelectionOverString(replacestring.c_str()); + current_view->update(1); + ++replace_count; + } + } while( SearchCB(true) ); +#else // start at top current_view->buffer()->text->ClearSelection(); current_view->buffer()->text->CursorTop(); @@ -219,7 +257,7 @@ void LyXFindReplace1::SearchReplaceAllCB() replace_count++; } } while( SearchCB(true) ); - +#endif if( replace_count == 0 ) { LyXBell(); minibuffer->Set(_("String not found!")); @@ -237,7 +275,7 @@ void LyXFindReplace1::SearchReplaceAllCB() bool LyXFindReplace1::SearchCB(bool fForward) { - LyXText *ltCur; + LyXText * ltCur; bool result; // store search direction @@ -247,8 +285,13 @@ bool LyXFindReplace1::SearchCB(bool fForward) return(false); current_view->getScreen()->HideCursor(); +#ifdef MOVE_TEXT + current_view->update(-2); + ltCur = current_view->text; +#else current_view->buffer()->update(-2); ltCur = current_view->buffer()->text; +#endif if (ltCur->selection) ltCur->cursor = fForward ? ltCur->sel_end_cursor : ltCur->sel_start_cursor; @@ -258,6 +301,16 @@ bool LyXFindReplace1::SearchCB(bool fForward) if (!ValidSearchData() || (fForward ? SearchForward(ltCur) : SearchBackward(ltCur))) { +#ifdef MOVE_TEXT + current_view->update(-2); + + // clear the selection (if there is any) + current_view->getScreen()->ToggleSelection(); + current_view->text->ClearSelection(); + + // set the new selection + SetSelectionOverLenChars(current_view->text, iLenSelected); +#else current_view->buffer()->update(-2); // clear the selection (if there is any) @@ -266,6 +319,7 @@ bool LyXFindReplace1::SearchCB(bool fForward) // set the new selection SetSelectionOverLenChars(current_view->buffer()->text, iLenSelected); +#endif current_view->getScreen()->ToggleSelection(false); minibuffer->Set(_("Found.")); result = true; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index b18ceb47f9..4099b02136 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -167,6 +167,16 @@ LyXFunc::LyXFunc(LyXView * o) inline void LyXFunc::moveCursorUpdate(bool selecting) { +#ifdef MOVE_TEXT + if (selecting || owner->view()->text->mark_set) { + owner->view()->text->SetSelection(); + owner->view()->getScreen()->ToggleToggle(); + owner->view()->update(0); + } else { + owner->view()->update(-2); // this IS necessary + // (Matthias) + } +#else if (selecting || owner->buffer()->text->mark_set) { owner->buffer()->text->SetSelection(); owner->view()->getScreen()->ToggleToggle(); @@ -175,6 +185,7 @@ void LyXFunc::moveCursorUpdate(bool selecting) owner->buffer()->update(-2); // this IS necessary // (Matthias) } +#endif owner->view()->getScreen()->ShowCursor(); /* ---> Everytime the cursor is moved, show the current font state. */ @@ -217,7 +228,11 @@ int LyXFunc::processKeyEvent(XEvent * ev) owner->buffer()->the_locking_inset && keysym_return == XK_Escape) { UnlockInset(owner->buffer()->the_locking_inset); +#ifdef MOVE_TEXT + owner->view()->text->CursorRight(); +#else owner->buffer()->text->CursorRight(); +#endif return 0; } @@ -253,193 +268,2285 @@ int LyXFunc::processKeyEvent(XEvent * ev) if (action == 0) action = LFUN_PREFIX; - if (lyxerr.debugging(Debug::KEY)) { - char buf[100]; - keyseq.print(buf, 100); - lyxerr << "Key [" - << action << "][" - << buf << "][" - << num_bytes << "]" << endl; + if (lyxerr.debugging(Debug::KEY)) { + char buf[100]; + keyseq.print(buf, 100); + lyxerr << "Key [" + << action << "][" + << buf << "][" + << num_bytes << "]" << endl; + } + + // already here we know if it any point in going further + // why not return already here if action == -1 and + // num_bytes == 0? (Lgb) + + if(keyseq.length>1 || keyseq.length<-1){ + char buf[100]; + keyseq.print(buf, 100); + owner->getMiniBuffer()->Set(buf); + } + + if (action == -1) { + if (keyseq.length<-1) { // unknown key sequence... + char buf[100]; + LyXBell(); + keyseq.print(buf, 100); + owner->getMiniBuffer()->Set(_("Unknown sequence:"), buf); + return 0; + } + + char isochar = keyseq.getiso(); + if (!(keyevent->state&ControlMask) && + !(keyevent->state&Mod1Mask) && + (isochar && keysym_return < 0xF000)) { + argument += isochar; + } + if (argument.empty()) { + lyxerr.debug() << "Empty argument!" << endl; + // This can`t possibly be of any use + // so we`ll skip the dispatch. + return 0; + } + } else + if (action == LFUN_SELFINSERT) { + argument = s_r[0]; + } + + bool tmp_sc = show_sc; + show_sc = false; + Dispatch(action, argument.c_str()); + show_sc = tmp_sc; + + return 0; +} + + +LyXFunc::func_status LyXFunc::getStatus(int ac) const +{ + kb_action action; + func_status flag = LyXFunc::OK; + string argument; + Buffer * buf = owner->buffer(); + + if (lyxaction.isPseudoAction(ac)) + action = lyxaction.retrieveActionArg(ac, argument); + else + action = static_cast(ac); + + if (action == LFUN_UNKNOWN_ACTION) { + setErrorMessage(N_("Unknown action")); + return LyXFunc::Unknown; + } + + // Check whether we need a buffer + if (!lyxaction.funcHasFlag(action, LyXAction::NoBuffer)) { + // Yes we need a buffer, do we have one? + if (buf) { + // yes + // Can we use a readonly buffer? + if (buf->isReadonly() && + !lyxaction.funcHasFlag(action, + LyXAction::ReadOnly)) { + // no + setErrorMessage(N_("Document is read-only")); + flag = func_status(flag | LyXFunc::Disabled); + } + } else { + // no + setErrorMessage(N_("Command not allowed with" + "out any document open")); + flag = func_status(flag | LyXFunc::Disabled); + } + } + + if (flag & LyXFunc::Disabled) + return flag; + + static bool noLaTeX = lyxrc->latex_command == "none"; + bool disable = false; + switch (action) { + case LFUN_PREVIEW: + disable = noLaTeX || lyxrc->view_dvi_command == "none"; + break; + case LFUN_PREVIEWPS: + disable = noLaTeX || lyxrc->view_ps_command == "none"; + break; + case LFUN_RUNLATEX: + case LFUN_RUNDVIPS: + disable = noLaTeX; + break; + case LFUN_MENUPRINT: + disable = noLaTeX || lyxrc->print_command == "none"; + break; + case LFUN_FAX: + disable = noLaTeX || lyxrc->fax_command == "none"; + break; + case LFUN_IMPORT: + if (argument == "latex") + disable = lyxrc->relyx_command == "none"; + break; + case LFUN_EXPORT: + if (argument == "dvi" || argument == "postscript") + disable = noLaTeX; + if (argument == "html") + disable = lyxrc->html_command == "none"; + break; + case LFUN_UNDO: + disable = buf->undostack.empty(); + break; + case LFUN_REDO: + disable = buf->redostack.empty(); + break; + case LFUN_SPELLCHECK: + disable = lyxrc->isp_command == "none"; + break; + case LFUN_RUNCHKTEX: + disable = lyxrc->chktex_command == "none"; + break; + case LFUN_LAYOUT_TABLE: +#ifdef MOVE_TEXT + disable = ! owner->view()->text->cursor.par->table; +#else + disable = ! buf->text->cursor.par->table; +#endif + break; + default: + break; + } + if (disable) + flag |= LyXFunc::Disabled; + + if (buf) { + func_status box = LyXFunc::ToggleOff; +#ifdef MOVE_TEXT + LyXFont font = owner->view()->text->real_current_font; +#else + LyXFont font = buf->text->real_current_font; +#endif + switch (action) { + case LFUN_EMPH: + if (font.emph() == LyXFont::ON) + box = LyXFunc::ToggleOn; + break; + case LFUN_NOUN: + if (font.noun() == LyXFont::ON) + box = LyXFunc::ToggleOn; + break; + case LFUN_BOLD: + if (font.series() == LyXFont::BOLD_SERIES) + box = LyXFunc::ToggleOn; + break; + case LFUN_TEX: + if (font.latex() == LyXFont::ON) + box = LyXFunc::ToggleOn; + break; + default: + box = LyXFunc::OK; + break; + } + flag |= box; + } + + + return flag; +} + + +string LyXFunc::Dispatch(string const & s) +{ + // Split command string into command and argument + string cmd, line = frontStrip(s); + string arg = strip(frontStrip(split(line, cmd, ' '))); + + return Dispatch(lyxaction.LookupFunc(cmd.c_str()), arg.c_str()); +} + + +#ifdef MOVE_TEXT +string LyXFunc::Dispatch(int ac, + char const * do_not_use_this_arg) +{ + string argument; + kb_action action; + + FL_OBJECT * ob = 0; // This will disapear soon + + // we have not done anything wrong yet. + errorstat = false; + dispatch_buffer.clear(); + + // if action is a pseudo-action, we need the real action + if (lyxaction.isPseudoAction(ac)) { + string tmparg; + action = static_cast + (lyxaction.retrieveActionArg(ac, tmparg)); + if (!tmparg.empty()) + argument = tmparg; + } else { + action = static_cast(ac); + if (do_not_use_this_arg) + argument = do_not_use_this_arg; // except here + } + + selection_possible = false; + + if (owner->view()->available() + && owner->view()->getScreen()) + owner->view()->getScreen()->HideCursor(); + + // We cannot use this function here + if (getStatus(action) & Disabled) + goto exit_with_message; + + commandshortcut.clear(); + + if (lyxrc->display_shortcuts && show_sc) { + if (action != LFUN_SELFINSERT) { + // Put name of command and list of shortcuts + // for it in minibuffer + string comname = lyxaction.getActionName(action); + + int pseudoaction = action; + bool argsadded = false; + + if (!argument.empty()) { + // If we have the command with argument, + // this is better + pseudoaction = + lyxaction.searchActionArg(action, + argument.c_str()); + + if (pseudoaction == -1) { + pseudoaction = action; + } else { + comname += " " + argument; + argsadded = true; + } + } + + string shortcuts = toplevel_keymap->findbinding(pseudoaction); + + if (!shortcuts.empty()) { + comname += ": " + shortcuts; + } else if (!argsadded) { + comname += " " + argument; + } + + if (!comname.empty()) { + comname = strip(comname); + commandshortcut = "(" + comname + ')'; + owner->getMiniBuffer()->Set(commandshortcut); + // Here we could even add a small pause, + // to annoy the user and make him learn + // the shortcuts. + // No! That will just annoy, not teach + // anything. The user will read the messages + // if they are interested. (Asger) + } + } + } + + // If in math mode pass the control to + // the math inset [asierra060396] + if (owner->view()->available() && + owner->buffer()->the_locking_inset) { + if (action > 1 + || (action == LFUN_UNKNOWN_ACTION && keyseq.length>= -1)) { + if (action == LFUN_UNKNOWN_ACTION && argument.empty()) { + argument = keyseq.getiso(); + } + // Undo/Redo pre 0.13 is a bit tricky for insets. + if (action == LFUN_UNDO) { + int slx, sly; + UpdatableInset * inset = + owner->buffer()->the_locking_inset; + inset->GetCursorPos(slx, sly); + UnlockInset(inset); + MenuUndo(); + inset = static_cast(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos)); + if (inset) + inset->Edit(slx, sly); + return string(); + } else + if (action == LFUN_REDO) { + int slx, sly; + UpdatableInset * inset = owner->buffer()->the_locking_inset; + inset->GetCursorPos(slx, sly); + UnlockInset(inset); + MenuRedo(); + inset = static_cast(owner->view()->text->cursor.par->GetInset(owner->view()->text->cursor.pos)); + if (inset) + inset->Edit(slx, sly); + return string(); + } else + if (owner->buffer()->the_locking_inset->LocalDispatch(action, argument.c_str())) + return string(); + else { + setMessage(N_("Text mode")); + if (action == LFUN_RIGHT || action == -1) + owner->view()->text->CursorRight(); + if (action == LFUN_LEFT || action == LFUN_RIGHT) + return string(); + } + } + } + + switch(action) { + // --- Misc ------------------------------------------- + case LFUN_WORDFINDFORWARD : + case LFUN_WORDFINDBACKWARD : { + static string last_search; + string searched_string; + + if (!argument.empty()) { + last_search = argument; + searched_string = argument; + } else { + searched_string = last_search; + } + + LyXText * ltCur = owner->view()->text ; + + if (!searched_string.empty() && + ((action == LFUN_WORDFINDBACKWARD) ? + ltCur->SearchBackward(searched_string.c_str()) : + ltCur->SearchForward(searched_string.c_str()))) { + + // ??? What is that ??? + owner->view()->update(-2); + + // ??? Needed ??? + // clear the selection (if there is any) + owner->view()->getScreen()->ToggleSelection(); + owner->view()->text->ClearSelection(); + + // Move cursor so that successive C-s 's will not stand in place. + if( action == LFUN_WORDFINDFORWARD ) + owner->view()->text->CursorRightOneWord(); + owner->view()->text->FinishUndo(); + moveCursorUpdate(false); + + // ??? Needed ??? + // set the new selection + // SetSelectionOverLenChars(owner->view()->currentBuffer()->text, iLenSelected); + owner->view()->getScreen()->ToggleSelection(false); + } else + LyXBell(); + + // REMOVED : if (owner->view()->getWorkArea()->focus) + owner->view()->getScreen()->ShowCursor(); + } + break; + + case LFUN_PREFIX: + { + if (owner->view()->available() + && owner->view()->getScreen()) { + owner->view()->update(-2); + } + char buf[100]; + keyseq.print(buf, 100, true); + owner->getMiniBuffer()->Set(buf, string(), string(), 1); + } + break; + + // --- Misc ------------------------------------------- + case LFUN_EXEC_COMMAND: + owner->getMiniBuffer()->ExecCommand(); + break; + + case LFUN_CANCEL: // RVDK_PATCH_5 + keyseq.reset(); + meta_fake_bit = 0; + if(owner->view()->available()) + // cancel any selection + Dispatch(LFUN_MARK_OFF, 0); + setMessage(N_("Cancel")); + break; + + case LFUN_META_FAKE: // RVDK_PATCH_5 + { + meta_fake_bit = Mod1Mask; + char buf[100]; + keyseq.print(buf, 98, true); + string res = string("M-") + buf; + setMessage(buf); // RVDK_PATCH_5 + } + break; + + case LFUN_READ_ONLY_TOGGLE: + if (owner->buffer()->lyxvc.inUse()) { + owner->buffer()->lyxvc.toggleReadOnly(); + } else { + owner->buffer()->setReadonly( + !owner->buffer()->isReadonly()); + } + break; + + case LFUN_CENTER: // this is center and redraw. + BeforeChange(); + if (owner->view()->text->cursor.y > + owner->view()->getWorkArea()->h / 2) { + owner->view()->getScreen()-> + Draw(owner->view()->text->cursor.y - + owner->view()->getWorkArea()->h/2); + } else { // <= + owner->view()->getScreen()-> + Draw(0); + } + owner->view()->update(0); + owner->view()->redraw(); + break; + + case LFUN_APPENDIX: + if (owner->view()->available()) { + owner->view()->text->toggleAppendix(); + owner->view()->update(1); + } + break; + + // --- Menus ----------------------------------------------- + case LFUN_MENUNEW: + MenuNew(false); + break; + + case LFUN_MENUNEWTMPLT: + MenuNew(true); + break; + + case LFUN_MENUOPEN: + MenuOpen(); + break; + + case LFUN_CLOSEBUFFER: + CloseBuffer(); + break; + + case LFUN_MENUWRITE: + MenuWrite(owner->buffer()); + break; + + case LFUN_MENUWRITEAS: + MenuWriteAs(owner->buffer()); + break; + + case LFUN_MENURELOAD: + reloadBuffer(); + break; + + case LFUN_PREVIEW: + MenuPreview(owner->buffer()); + break; + + case LFUN_PREVIEWPS: + MenuPreviewPS(owner->buffer()); + break; + + case LFUN_RUNLATEX: + MenuRunLaTeX(owner->buffer()); + break; + + case LFUN_BUILDPROG: + MenuBuildProg(owner->buffer()); + break; + + case LFUN_RUNCHKTEX: + MenuRunChktex(owner->buffer()); + break; + + case LFUN_RUNDVIPS: + MenuRunDvips(owner->buffer(), false); + break; + + case LFUN_MENUPRINT: + MenuPrint(owner->buffer()); + break; + + case LFUN_FAX: + MenuFax(owner->buffer()); + break; + + case LFUN_EXPORT: + { + //needs argument as string + string extyp = argument; + + // latex + if (extyp == "latex") { + // make sure that this buffer is not linuxdoc + MenuMakeLaTeX(owner->buffer()); + } + // linuxdoc + else if (extyp == "linuxdoc") { + // make sure that this buffer is not latex + MenuMakeLinuxDoc(owner->buffer()); + } + // docbook + else if (extyp == "docbook") { + // make sure that this buffer is not latex or linuxdoc + MenuMakeDocBook(owner->buffer()); + } + // dvi + else if (extyp == "dvi") { + // Run LaTeX as "Update dvi..." Bernhard. + // We want the dvi in the current directory. This + // is achieved by temporarily disabling use of + // temp directory. As a side-effect, we get + // *.log and *.aux files also. (Asger) + bool flag = lyxrc->use_tempdir; + lyxrc->use_tempdir = false; + MenuRunLaTeX(owner->buffer()); + lyxrc->use_tempdir = flag; + } + // postscript + else if (extyp == "postscript") { + // Start Print-dialog. Not as good as dvi... Bernhard. + MenuPrint(owner->buffer()); + // Since the MenuPrint is a pop-up, we can't use + // the same trick as above. (Asger) + // MISSING: Move of ps-file :-( + } + // ascii + else if (extyp == "ascii") { + MenuMakeAscii(owner->buffer()); + } + else if (extyp == "custom") { + MenuSendto(); + break; + } + // HTML + else if (extyp == "html" && lyxrc->html_command != "none") { + // First, create LaTeX file + MenuMakeLaTeX(owner->buffer()); + + // And now, run the converter + string file = owner->buffer()->fileName(); + Path path(OnlyPath(file)); + // the tex file name has to be correct for + // latex, but the html file name can be + // anything. + string result = ChangeExtension(file, ".html", false); + string infile = owner->buffer()->getLatexName(); + string tmp = lyxrc->html_command; + tmp = subst(tmp, "$$FName", infile); + tmp = subst(tmp, "$$OutName", result); + Systemcalls one; + int res = one.startscript(Systemcalls::System, tmp); + if (res == 0) { + setMessage(N_("Document exported as HTML to file `") + + MakeDisplayPath(result) +'\''); + } else { + setErrorMessage(N_("Unable to convert to HTML the file `") + + MakeDisplayPath(infile) + + '\''); + } + } + else { + setErrorMessage(N_("Unknown export type: ") + + extyp); + } + } + break; + + case LFUN_IMPORT: + { + //needs argument as string + string imtyp = argument; + + // latex + if (imtyp == "latex") { + doImportLaTeX(false); + } + // ascii + else if (imtyp == "ascii") { + doImportASCII(false); + } else if (imtyp == "asciiparagraph") { + doImportASCII(true); + // noweb + } else if (imtyp == "noweb") { + doImportLaTeX(true); + } else { + setErrorMessage(string(N_("Unknown import type: ")) + + imtyp); + } + break; + } + + case LFUN_QUIT: + QuitLyX(); + break; + + case LFUN_TOCVIEW: + TocUpdateCB(ob, 0); + if (fd_form_toc->form_toc->visible) { + fl_raise_form(fd_form_toc->form_toc); + } else { + static int ow = -1, oh; + fl_show_form(fd_form_toc->form_toc, + FL_PLACE_MOUSE | + FL_FREE_SIZE, FL_FULLBORDER, + _("Table of Contents")); + if (ow < 0) { + ow = fd_form_toc->form_toc->w; + oh = fd_form_toc->form_toc->h; + } + fl_set_form_minsize(fd_form_toc->form_toc, ow, oh); + } + break; + + case LFUN_TOC_INSERT: + { + Inset * new_inset = new InsetTOC(owner->buffer()); + owner->buffer()->insertInset(new_inset, "Standard", true); + break; + } + + case LFUN_LOF_INSERT: + { + Inset * new_inset = new InsetLOF(owner->buffer()); + owner->buffer()->insertInset(new_inset, "Standard", true); + break; + } + + case LFUN_LOA_INSERT: + { + Inset * new_inset = new InsetLOA(owner->buffer()); + owner->buffer()->insertInset(new_inset, "Standard", true); + break; + } + + case LFUN_LOT_INSERT: + { + Inset * new_inset = new InsetLOT(owner->buffer()); + owner->buffer()->insertInset(new_inset, "Standard", true); + break; + } + + case LFUN_TABLE: + TableCB(ob, 0); + break; + + case LFUN_FIGURE: + FigureCB(ob, 0); + break; + + case LFUN_AUTOSAVE: + AutoSave(); + break; + + case LFUN_UNDO: + MenuUndo(); + break; + + case LFUN_REDO: + MenuRedo(); + break; + + case LFUN_MENUSEARCH: + MenuSearch(); + break; + + case LFUN_PASTE: + PasteCB(); + break; + + case LFUN_PASTESELECTION: + { + bool asPara = false; + if (argument == "paragraph") asPara = true; + MenuPasteSelection(asPara); + break; + } + + case LFUN_CUT: + CutCB(); + break; + + case LFUN_COPY: + CopyCB(); + break; + + case LFUN_LAYOUT_COPY: + CopyEnvironmentCB(); + break; + + case LFUN_LAYOUT_PASTE: + PasteEnvironmentCB(); + break; + + case LFUN_GOTOERROR: + owner->view()->gotoError(); + break; + + case LFUN_REMOVEERRORS: + if (owner->buffer()->removeAutoInsets()) { + owner->view()->redraw(); + owner->view()->fitCursor(); + owner->view()->updateScrollbar(); + } + break; + + case LFUN_GOTONOTE: + GotoNote(); + break; + + case LFUN_OPENSTUFF: + OpenStuff(); + break; + + case LFUN_HYPHENATION: + HyphenationPoint(); + break; + + case LFUN_LDOTS: + Ldots(); + break; + + case LFUN_END_OF_SENTENCE: + EndOfSentenceDot(); + break; + + case LFUN_MENU_SEPARATOR: + MenuSeparator(); + break; + + case LFUN_HFILL: + HFill(); + break; + + case LFUN_DEPTH: + DepthCB(ob, 0); + break; + + case LFUN_DEPTH_MIN: + DepthCB(ob, -1); + break; + + case LFUN_DEPTH_PLUS: + DepthCB(ob, 1); + break; + + case LFUN_FREE: + FreeCB(); + break; + + case LFUN_TEX: + TexCB(); + break; + + case LFUN_MELT: + MeltCB(ob, 0); + break; + + case LFUN_RECONFIGURE: + Reconfigure(); + break; + + case LFUN_FOOTMELT: + if (owner->view()->available() + && !owner->view()->text->selection + && owner->view()->text->cursor.par->footnoteflag + != LyXParagraph::NO_FOOTNOTE) + { // only melt footnotes with FOOTMELT, not margins etc + if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::FOOTNOTE) + MeltCB(ob, 0); + } + else + FootCB(ob, 0); + break; + + case LFUN_MARGINMELT: + if (owner->view()->available() + && !owner->view()->text->selection + && owner->view()->text->cursor.par->footnoteflag + != LyXParagraph::NO_FOOTNOTE) { + // only melt margins + if(owner->view()->text->cursor.par->footnotekind == LyXParagraph::MARGIN) + MeltCB(ob, 0); + } + else + MarginCB(ob, 0); + break; + + // --- version control ------------------------------- + case LFUN_VC_REGISTER: + { + if (!owner->buffer()->lyxvc.inUse()) + owner->buffer()->lyxvc.registrer(); + } + break; + + case LFUN_VC_CHECKIN: + { + if (owner->buffer()->lyxvc.inUse() + && !owner->buffer()->isReadonly()) + owner->buffer()->lyxvc.checkIn(); + } + break; + + case LFUN_VC_CHECKOUT: + { + if (owner->buffer()->lyxvc.inUse() + && owner->buffer()->isReadonly()) + owner->buffer()->lyxvc.checkOut(); + } + break; + + case LFUN_VC_REVERT: + { + owner->buffer()->lyxvc.revert(); + } + break; + + case LFUN_VC_UNDO: + { + owner->buffer()->lyxvc.undoLast(); + } + break; + + case LFUN_VC_HISTORY: + { + owner->buffer()->lyxvc.showLog(); + break; + } + + // --- buffers ---------------------------------------- + case LFUN_PREVBUFFER: +#ifdef WITH_WARNINGS +#warning fix this please +#endif + // it is the LyXView or the BufferView that should + // remember the previous buffer, not bufferlist. +// if (owner->view()->available()){ +// BeforeChange(); +// owner->buffer()->update(-2); +// } +// owner->view()->setBuffer(bufferlist.prev()); + +// owner->view()-> +// resizeCurrentBufferPseudoExpose(); + break; + + case LFUN_FILE_INSERT: + { + MenuInsertLyXFile(argument); + } + break; + + case LFUN_FILE_INSERT_ASCII: + { + bool asPara = (argument == "paragraph"); + InsertAsciiFile(string(), asPara); + } + break; + + case LFUN_FILE_NEW: + { + // servercmd: argument must be :