From 021ad027a9d378b5d6e2e78ed768428867e1f7a8 Mon Sep 17 00:00:00 2001 From: John Levon Date: Wed, 12 Jun 2002 10:31:34 +0000 Subject: [PATCH] refactor topCursorVisible() prototype a little. Compile fix git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4378 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView_pimpl.C | 4 +-- src/ChangeLog | 5 ++++ src/frontends/ChangeLog | 5 ++++ src/frontends/screen.C | 39 +++++++++++++++-------------- src/frontends/screen.h | 44 ++++++++++++++++++++++----------- src/graphics/ChangeLog | 4 +++ src/graphics/GraphicsImageXPM.C | 2 +- src/insets/ChangeLog | 5 ++++ src/insets/insettext.C | 4 +-- 9 files changed, 74 insertions(+), 38 deletions(-) diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index b4d62a1439..771836d9e6 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -233,7 +233,7 @@ void BufferView::Pimpl::buffer(Buffer * b) updateScreen(); updateScrollbar(); } - bv_->text->first_y = screen().topCursorVisible(bv_->text); + bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y); owner_->updateMenubar(); owner_->updateToolbar(); // Similarly, buffer-dependent dialogs should be updated or @@ -390,7 +390,7 @@ int BufferView::Pimpl::resizeCurrentBuffer() bv_->theLockingInset(the_locking_inset); } - bv_->text->first_y = screen().topCursorVisible(bv_->text); + bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y); // this will scroll the screen such that the cursor becomes visible updateScrollbar(); diff --git a/src/ChangeLog b/src/ChangeLog index 63d60e37ec..fd8b28ed9f 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2002-06-12 John Levon + + * BufferView_pimpl.C: topCursorVisible + prototype change + 2002-06-12 John Levon * Makefile.am: diff --git a/src/frontends/ChangeLog b/src/frontends/ChangeLog index 3de546ddcb..b0bede0952 100644 --- a/src/frontends/ChangeLog +++ b/src/frontends/ChangeLog @@ -1,3 +1,8 @@ +2002-06-12 John Levon + + * screen.h: + * screen.C: change topCursorVisible() prototype + 2002-06-12 Angus Leeming * font_metrics.h: remove trailing semi-colon after the brace closing diff --git a/src/frontends/screen.C b/src/frontends/screen.C index e9f64b0e29..79dd6542d5 100644 --- a/src/frontends/screen.C +++ b/src/frontends/screen.C @@ -395,38 +395,39 @@ void LScreen::cursorToggle(BufferView * bv) const /* returns a new top so that the cursor is visible */ -unsigned int LScreen::topCursorVisible(LyXText const * text) +unsigned int LScreen::topCursorVisible(LyXCursor const & cursor, int top_y) { - int newtop = text->first_y; + int const vheight = owner.workHeight(); + int newtop = top_y; - Row * row = text->cursor.row(); + Row * row = cursor.row(); // Is this a hack? Yes, probably... (Lgb) if (!row) return max(newtop, 0); - if (text->cursor.y() - row->baseline() + row->height() - - text->first_y >= owner.workHeight()) { - if (row->height() < owner.workHeight() - && row->height() > owner.workHeight() / 4) { - newtop = text->cursor.y() + if (cursor.y() - row->baseline() + row->height() + - top_y >= vheight) { + if (row->height() < vheight + && row->height() > vheight / 4) { + newtop = cursor.y() + row->height() - - row->baseline() - owner.workHeight(); + - row->baseline() - vheight; } else { // scroll down - newtop = text->cursor.y() - - owner.workHeight() / 2; /* the scroll region must be so big!! */ + newtop = cursor.y() + - vheight / 2; /* the scroll region must be so big!! */ } - } else if (static_cast((text->cursor.y()) - row->baseline()) < - text->first_y && text->first_y > 0) { - if (row->height() < owner.workHeight() - && row->height() > owner.workHeight() / 4) { - newtop = text->cursor.y() - row->baseline(); + } else if (static_cast(cursor.y() - row->baseline()) < + top_y && top_y > 0) { + if (row->height() < vheight + && row->height() > vheight / 4) { + newtop = cursor.y() - row->baseline(); } else { // scroll up - newtop = text->cursor.y() - owner.workHeight() / 2; - newtop = min(newtop, text->first_y); + newtop = cursor.y() - vheight / 2; + newtop = min(newtop, top_y); } } @@ -441,7 +442,7 @@ unsigned int LScreen::topCursorVisible(LyXText const * text) bool LScreen::fitCursor(LyXText * text, BufferView * bv) { // Is a change necessary? - int const newtop = topCursorVisible(text); + int const newtop = topCursorVisible(text->cursor, text->first_y); bool const result = (newtop != text->first_y); if (result) draw(text, bv, newtop); diff --git a/src/frontends/screen.h b/src/frontends/screen.h index b1c8dba237..378d9d991e 100644 --- a/src/frontends/screen.h +++ b/src/frontends/screen.h @@ -1,13 +1,12 @@ // -*- C++ -*- -/* This file is part of - * ====================================================== +/** + * \file screen.h + * Copyright 1995-2002 the LyX Team + * Read the file COPYING * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich - * Copyright 1995-2001 The LyX Team - * - * ====================================================== */ + * \author unknown + * \author John Levon + */ #ifndef LYXSCREEN_H #define LYXSCREEN_H @@ -19,16 +18,24 @@ #include class LyXText; +class LyXCursor; class WorkArea; class Buffer; class BufferView; struct Row; -/** The class LScreen is used for the main Textbody. - Concretely, the screen is held in a pixmap. This pixmap is kept up to - date and used to optimize drawing on the screen. - This class also handles the drawing of the cursor and partly the selection. +/** + * LScreen - document rendering management + * + * This class is used to manage the on-screen rendering inside the + * work area; it is responsible for deciding which LyXText rows + * need re-drawing. + * + * This class will arrange for LyXText to paint onto a pixmap + * provided by the WorkArea widget. + * + * The blinking cursor is also handled here. */ class LScreen { public: @@ -60,8 +67,17 @@ public: /// Redraws the screen, without using existing pixmap void redraw(LyXText *, BufferView *); - /// Returns a new top so that the cursor is visible - unsigned int topCursorVisible(LyXText const *); + /** + * topCursorVisible - get a new "top" to make the cursor visible + * @param c the cursor + * @param top_y the current y location of the containing region + * + * This helper function calculates a new y co-ordinate for + * the top of the containing region such that the cursor contained + * within the LyXText is "nicely" visible. + */ + unsigned int topCursorVisible(LyXCursor const & c, int top_y); + /// Redraws the screen such that the cursor is visible bool fitCursor(LyXText *, BufferView *); /// diff --git a/src/graphics/ChangeLog b/src/graphics/ChangeLog index 2e0bec6294..29ea143be6 100644 --- a/src/graphics/ChangeLog +++ b/src/graphics/ChangeLog @@ -1,3 +1,7 @@ +2002-06-12 John Levon + + * GraphicsCache.C: use right colormap incantation + 2002-06-12 John Levon * GraphicsCache.C: use lyx_gui namespace diff --git a/src/graphics/GraphicsImageXPM.C b/src/graphics/GraphicsImageXPM.C index a165a2904b..e3a16dfbf5 100644 --- a/src/graphics/GraphicsImageXPM.C +++ b/src/graphics/GraphicsImageXPM.C @@ -613,7 +613,7 @@ void mapcolor(char const * c_color, char ** g_color_ptr, char ** m_color_ptr) return; Display * display = fl_get_display(); - Colormap cmap = fl_colormap; + Colormap cmap = fl_state[fl_get_vclass()].colormap; XColor xcol; XColor ccol; if (XLookupColor(display, cmap, c_color, &xcol, &ccol) == 0) diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index cc3fc13921..dbf08d3113 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2002-06-12 John Levon + + * insettext.C: change of topCursorVisible() + prototype + 2002-06-12 John Levon * insettext.h: diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 3592cb546e..636f981dae 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -2374,7 +2374,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const inset_y = ciy(bv) + drawTextYOffset; } - t->first_y = bv->screen().topCursorVisible(t); + t->first_y = bv->screen().topCursorVisible(t->cursor, t->first_y); if (!owner()) { updateLocal(bv, FULL, false); // this will scroll the screen such that the cursor becomes visible @@ -2412,7 +2412,7 @@ void InsetText::reinitLyXText() const inset_x = cix(bv) - top_x + drawTextXOffset; inset_y = ciy(bv) + drawTextYOffset; } - t->first_y = bv->screen().topCursorVisible(t); + t->first_y = bv->screen().topCursorVisible(t->cursor, t->first_y); if (!owner()) { updateLocal(bv, FULL, false); // this will scroll the screen such that the cursor becomes visible