This patch moves the horrible xforms scrollbar logic into xforms/ and leaves a more sensible API in palce for GUII
It's not /entirely/ trivial like the rest of the stuff I've committed so I'm sending this for approval from some kind soul (Also my Painter split patch is still waiting, and that /is/ trivial :) The merge is getting smaller now : 44 files changed, 1676 insertions, 1468 deletions and that's not including painter split, and is including some questionable half-finished patches that shouldn't go in the tree Please give the nod to this one thanks john ? a.diff ? lg.diff ? gui.diff ? scroll.diff ? frontends/xforms/a.diff Index: BufferView.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.C,v retrieving revision 1.90 diff -u -r1.90 BufferView.C --- BufferView.C 12 Jun 2002 02:54:15 -0000 1.90 +++ BufferView.C 12 Jun 2002 13:05:49 -0000 @@ -101,7 +101,7 @@ } -void BufferView::scrollCB(double value) +void BufferView::scrollCB(int value) { pimpl_->scrollCB(value); } Index: BufferView.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView.h,v retrieving revision 1.87 diff -u -r1.87 BufferView.h --- BufferView.h 12 Jun 2002 02:54:15 -0000 1.87 +++ BufferView.h 12 Jun 2002 13:05:49 -0000 @@ -186,7 +186,7 @@ /// void focus(bool); /// A callback for the slider in the scrollbar. - void scrollCB(double); + void scrollCB(int); /// void setState(); Index: BufferView_pimpl.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.C,v retrieving revision 1.251 diff -u -r1.251 BufferView_pimpl.C --- BufferView_pimpl.C 12 Jun 2002 11:34:11 -0000 1.251 +++ BufferView_pimpl.C 12 Jun 2002 13:05:57 -0000 @@ -417,51 +417,24 @@ { if (!bv_->text) { lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl; - workarea().setScrollbar(0, 1.0); + workarea().setScrollbarParams(0, 0, 0); return; } - long const text_height = bv_->text->height; - long const work_height = workarea().workHeight(); - - double const lineh = bv_->text->defaultHeight(); - double const slider_size = - (text_height == 0) ? 1.0 : 1.0 / double(text_height); - - lyxerr[Debug::GUI] << "text_height now " << text_height << endl; - lyxerr[Debug::GUI] << "work_height " << work_height << endl; - - /* If the text is smaller than the working area, the scrollbar - * maximum must be the working area height. No scrolling will - * be possible */ - if (text_height <= work_height) { - lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl; - workarea().setScrollbarBounds(0.0, 0.0); - current_scrollbar_value = bv_->text->first_y; - workarea().setScrollbar(current_scrollbar_value, 1.0); - return; - } - - workarea().setScrollbarBounds(0.0, text_height - work_height); - workarea().setScrollbarIncrements(lineh); - current_scrollbar_value = bv_->text->first_y; - workarea().setScrollbar(current_scrollbar_value, slider_size); + LyXText const & t = *bv_->text; + + workarea().setScrollbarParams(t.height, t.first_y, t.defaultHeight()); } // Callback for scrollbar slider -void BufferView::Pimpl::scrollCB(double value) +void BufferView::Pimpl::scrollCB(int value) { lyxerr[Debug::GUI] << "scrollCB of " << value << endl; if (!buffer_) return; - current_scrollbar_value = long(value); - - if (current_scrollbar_value < 0) - current_scrollbar_value = 0; - - screen().draw(bv_->text, bv_, current_scrollbar_value); + screen().draw(bv_->text, bv_, value); if (!lyxrc.cursor_follows_scrollbar) { waitForX(); @@ -483,77 +456,25 @@ } -int BufferView::Pimpl::scrollUp(long time) +int BufferView::Pimpl::scroll(long time) { if (!buffer_) return 0; - double value = workarea().getScrollbarValue(); - - if (value == 0) - return 0; - -#if 1 - float add_value = (bv_->text->defaultHeight() - + float(time) * float(time) * 0.125); - - if (add_value > workarea().workHeight()) - add_value = float(workarea().workHeight() - - bv_->text->defaultHeight()); -#else - float add_value = float(workarea().workHeight()) * float(time) / 100; -#endif - - value -= add_value; - - if (value < 0) - value = 0; - - workarea().setScrollbarValue(value); - - scrollCB(value); + LyXText const * t = bv_->text; + + double const diff = t->defaultHeight() + + double(time) * double(time) * 0.125; + + scrollCB(int(diff)); + workarea().setScrollbarParams(t->height, t->first_y, t->defaultHeight()); return 0; } -int BufferView::Pimpl::scrollDown(long time) +void BufferView::Pimpl::workAreaKeyPress(KeySym key, key_modifier::state state) { - if (!buffer_) - return 0; - - double value = workarea().getScrollbarValue(); - pair<float, float> p = workarea().getScrollbarBounds(); - double const max = p.second; - - if (value == max) - return 0; - -#if 1 - float add_value = (bv_->text->defaultHeight() - + float(time) * float(time) * 0.125); - - if (add_value > workarea().workHeight()) - add_value = float(workarea().workHeight() - - bv_->text->defaultHeight()); -#else - float add_value = float(workarea().workHeight()) * float(time) / 100; -#endif - - value += add_value; - - if (value > max) - value = max; - - workarea().setScrollbarValue(value); - - scrollCB(value); - return 0; -} - - -void BufferView::Pimpl::workAreaKeyPress(KeySym keysym, key_modifier::state state) -{ - bv_->owner()->getLyXFunc()->processKeySym(keysym, state); + bv_->owner()->getLyXFunc()->processKeySym(key, state); } @@ -629,15 +550,14 @@ return; // ok ok, this is a hack (for xforms) - if (button == mouse_button::button4) { - scrollUp(lyxrc.wheel_jump); + scroll(-lyxrc.wheel_jump); // We shouldn't go further down as we really should only do the // scrolling and be done with this. Otherwise we may open some // dialogs (Jug 20020424). return; } else if (button == mouse_button::button5) { - scrollDown(lyxrc.wheel_jump); + scroll(lyxrc.wheel_jump); // We shouldn't go further down as we really should only do the // scrolling and be done with this. Otherwise we may open some // dialogs (Jug 20020424). Index: BufferView_pimpl.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/BufferView_pimpl.h,v retrieving revision 1.57 diff -u -r1.57 BufferView_pimpl.h --- BufferView_pimpl.h 12 Jun 2002 02:54:17 -0000 1.57 +++ BufferView_pimpl.h 12 Jun 2002 13:05:57 -0000 @@ -69,19 +69,17 @@ /// void updateScrollbar(); /// - void scrollCB(double value); + void scrollCB(int value); /** * Returns an inset if inset was hit, or 0 if not. * * If hit, the coordinates are changed relative to the inset. */ Inset * checkInsetHit(LyXText *, int & x, int & y); + /// wheel mouse scroll + int scroll(long time); /// - int scrollUp(long time); - /// - int scrollDown(long time); - /// - void workAreaKeyPress(KeySym, key_modifier::state state); + void workAreaKeyPress(KeySym key, key_modifier::state state); /// void workAreaMotionNotify(int x, int y, mouse_button::state state); /// @@ -210,4 +208,4 @@ /// void MenuInsertLyXFile(string const & filen); }; -#endif +#endif // BUFFERVIEW_PIMPL_H Index: ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.759 diff -u -r1.759 ChangeLog --- ChangeLog 12 Jun 2002 11:34:11 -0000 1.759 +++ ChangeLog 12 Jun 2002 13:06:19 -0000 @@ -1,5 +1,13 @@ 2002-06-12 John Levon <[EMAIL PROTECTED]> + * BufferView.h: + * BufferView.C: + * BufferView_pimpl.h: + * BufferView_pimpl.C: move bogus scrolling logic + to xforms + +2002-06-12 John Levon <[EMAIL PROTECTED]> + * lyxfunc.C: * BufferView_pimpl.C: view->resize() change Index: frontends/xforms/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/ChangeLog,v retrieving revision 1.410 diff -u -r1.410 ChangeLog --- frontends/xforms/ChangeLog 12 Jun 2002 11:34:13 -0000 1.410 +++ frontends/xforms/ChangeLog 12 Jun 2002 13:09:15 -0000 @@ -1,5 +1,10 @@ 2002-06-12 John Levon <[EMAIL PROTECTED]> + * XWorkArea.h: + * XWorkArea.C: move scrolling logic into here + +2002-06-12 John Levon <[EMAIL PROTECTED]> + * XFormsView.h: * XFormsView.C: move init() back to LyXView Index: frontends/xforms/XWorkArea.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/XWorkArea.C,v retrieving revision 1.6 diff -u -r1.6 XWorkArea.C --- frontends/xforms/XWorkArea.C 12 Jun 2002 02:54:18 -0000 1.6 +++ frontends/xforms/XWorkArea.C 12 Jun 2002 13:09:58 -0000 @@ -1,12 +1,11 @@ -/* This file is part of - * ====================================================== +/** + * \file XWorkArea.C + * 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 <[EMAIL PROTECTED]> + */ #include <config.h> @@ -16,12 +15,12 @@ #include "XWorkArea.h" #include "debug.h" -#include "frontends/LyXView.h" +#include "LyXView.h" #include "lyxrc.h" // lyxrc.show_banner #include "version.h" // lyx_version #if FL_VERSION < 1 && (FL_REVISION < 89 || (FL_REVISION == 89 && FL_FIXLEVEL < 5)) -#include "frontends/xforms/lyxlookup.h" +#include "lyxlookup.h" #endif #include "support/filetools.h" // LibFileSearch @@ -34,7 +33,7 @@ // xforms doesn't define this (but it should be in <forms.h>). extern "C" FL_APPEVENT_CB fl_set_preemptive_callback(Window, FL_APPEVENT_CB, void *); - + using std::endl; using std::abs; using std::hex; @@ -47,6 +46,21 @@ XSync(fl_get_display(), 0); } + +void setXtermCursor(Window win) +{ + static Cursor cursor; + static bool cursor_undefined = true; + if (cursor_undefined) { + cursor = XCreateFontCursor(fl_get_display(), XC_xterm); + XFlush(fl_get_display()); + cursor_undefined = false; + } + XDefineCursor(fl_get_display(), win, cursor); + XFlush(fl_get_display()); +} + + // FIXME ! mouse_button::state x_button_state(unsigned int button) { @@ -111,9 +125,10 @@ extern "C" { // Just a bunch of C wrappers around static members of WorkArea static - void C_WorkArea_scroll_cb(FL_OBJECT * ob, long buf) + void C_WorkArea_scroll_cb(FL_OBJECT * ob, long) { - WorkArea::scroll_cb(ob, buf); + WorkArea * area = static_cast<WorkArea*>(ob->u_vdata); + area->scroll_cb(); } @@ -150,7 +165,7 @@ backgroundbox = obj = fl_add_box(FL_BORDER_BOX, x, y, w - 15, - h,""); + h, ""); fl_set_object_resize(obj, FL_RESIZE_ALL); fl_set_object_gravity(obj, NorthWestGravity, SouthEastGravity); @@ -193,13 +208,15 @@ fl_set_object_gravity(obj, NorthEastGravity, SouthEastGravity); obj->u_vdata = this; fl_set_object_callback(obj, C_WorkArea_scroll_cb, 0); - setScrollbarBounds(0.0, 0.0); - + fl_set_scrollbar_bounds(scrollbar, 0.0, 0.0); + fl_set_scrollbar_value(scrollbar, 0.0); + fl_set_scrollbar_size(scrollbar, scrollbar->h); + /// /// The free object int const bw = int(abs(fl_get_border_width())); - + // Create the workarea pixmap createPixmap(w - 15 - 2 * bw, h - 2 * bw); @@ -334,33 +351,54 @@ } -void WorkArea::setScrollbar(double pos, double length_fraction) const +void WorkArea::setScrollbarParams(int height, int pos, int line_height) { - fl_set_scrollbar_value(scrollbar, pos); - fl_set_scrollbar_size(scrollbar, scrollbar->h * length_fraction); -} + // we need to cache this for scroll_cb + doc_height_ = height; + if (height == 0) { + fl_set_scrollbar_value(scrollbar, 0.0); + fl_set_scrollbar_size(scrollbar, scrollbar->h); + return; + } -void WorkArea::setScrollbarBounds(double l1, double l2) const -{ - fl_set_scrollbar_bounds(scrollbar, l1, l2); -} + long const work_height = workHeight(); + lyxerr[Debug::GUI] << "scroll: height now " << height << endl; + lyxerr[Debug::GUI] << "scroll: work_height " << work_height << endl; + + /* If the text is smaller than the working area, the scrollbar + * maximum must be the working area height. No scrolling will + * be possible */ + if (height <= work_height) { + lyxerr[Debug::GUI] << "scroll: doc smaller than workarea !" << endl; + fl_set_scrollbar_bounds(scrollbar, 0.0, 0.0); + fl_set_scrollbar_value(scrollbar, pos); + fl_set_scrollbar_size(scrollbar, scrollbar->h); + return; + } -void WorkArea::setScrollbarIncrements(double inc) const -{ - fl_set_scrollbar_increment(scrollbar, work_area->h - inc, inc); + fl_set_scrollbar_bounds(scrollbar, 0.0, height - work_height); + fl_set_scrollbar_increment(scrollbar, work_area->h - line_height, line_height); + + fl_set_scrollbar_value(scrollbar, pos); + + double const slider_size = + (height == 0) ? 1.0 : 1.0 / double(height); + + fl_set_scrollbar_size(scrollbar, scrollbar->h * slider_size); } -// Callback for scrollbar slider -void WorkArea::scroll_cb(FL_OBJECT * ob, long) +// callback for scrollbar slider +void WorkArea::scroll_cb() { - WorkArea * area = static_cast<WorkArea*>(ob->u_vdata); - // If we really want the accellerating scroll we can do that - // from here. IMHO that is a waste of effort since we already - // have other ways to move fast around in the document. (Lgb) - area->scrollCB(fl_get_scrollbar_value(ob)); + double const val = fl_get_scrollbar_value(scrollbar); + double const height = scrollbar->h; + lyxerr[Debug::GUI] << "scroll: val: " << val << endl; + lyxerr[Debug::GUI] << "scroll: height: " << height << endl; + lyxerr[Debug::GUI] << "scroll: docheight: " << doc_height_ << endl; + scrollCB(val); waitForX(); } Index: frontends/xforms/XWorkArea.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/frontends/xforms/XWorkArea.h,v retrieving revision 1.4 diff -u -r1.4 XWorkArea.h --- frontends/xforms/XWorkArea.h 12 Jun 2002 00:51:45 -0000 1.4 +++ frontends/xforms/XWorkArea.h 12 Jun 2002 13:09:58 -0000 @@ -1,13 +1,12 @@ // -*- C++ -*- -/* This file is part of - * ====================================================== +/** + * \file XWorkArea.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 <[EMAIL PROTECTED]> + */ #ifndef XWORKAREA_H #define XWORKAREA_H @@ -67,34 +66,17 @@ bool visible() const { return work_area->form->visible; } /// void greyOut() const; - /// - void setScrollbar(double pos, double length_fraction) const; - /// - void setScrollbarValue(double y) const { - fl_set_scrollbar_value(scrollbar, y); - } - /// - void setScrollbarBounds(double, double) const; - /// - void setScrollbarIncrements(double inc) const; - /// - double getScrollbarValue() const { - return fl_get_scrollbar_value(scrollbar); - } - /// - std::pair<float, float> const getScrollbarBounds() const { - std::pair<float, float> p; - fl_get_scrollbar_bounds(scrollbar, &p.first, &p.second); - return p; - } + /// + void setScrollbarParams(int height, int pos, int line_height); /// Pixmap getPixmap() const { return workareapixmap; } /// xforms callback static int work_area_handler(FL_OBJECT *, int event, FL_Coord, FL_Coord, int /*key*/, void * xev); - /// xforms callback - static void scroll_cb(FL_OBJECT *, long); + + /// xforms callback from scrollbar + void scroll_cb(); /// a selection exists void haveSelection(bool) const; /// @@ -105,7 +87,7 @@ /// boost::signal0<void> workAreaExpose; /// - boost::signal1<void, double> scrollCB; + boost::signal1<void, int> scrollCB; /// boost::signal2<void, KeySym, key_modifier::state> workAreaKeyPress; /// @@ -149,5 +131,8 @@ Painter painter_; /// if we call redraw with true needed for locking-insets bool screen_cleared; + /// the current document's height (for scrollbar) + int doc_height_; }; -#endif + +#endif // XWORKAREA_H