diff --git a/ChangeLog b/ChangeLog index d6ed026a4e..c5d31555d4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2000-06-21 Lars Gullik Bjønnes + + * src/Timeout.[Ch]: Change to use signals instead of callbacks.  + * src/LyXView.h (struct FD_form_main): remove, LyXView inherits + from SigC::Object + (form_main_): remove + + * src/LyXView.C (LyXView_AutosaveTimerCB): remove + (create_form_form_main): remove FD_form_main stuff, connect to + autosave_timeout signal + + * src/LyXView.[Ch] (getMainForm): remove + (UpdateTimerCB): remove + * src/BufferView_pimpl.h: inherit from SigC::Object + + * src/BufferView_pimpl.C (Pimpl): connect to cursor_timeout with + signal instead of callback + + * src/BufferView.[Ch] (cursorToggleCB): remove + 2000-06-20 Lars Gullik Bjønnes * src/BufferView_pimpl.C: changes because of the one below diff --git a/src/BufferView.C b/src/BufferView.C index e1a72466a6..4fb7f0eb6d 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -185,14 +185,6 @@ void BufferView::workAreaExpose() } -// // Callback for cursor timer -void BufferView::cursorToggleCB(void * ob) -{ - BufferView * view = static_cast(ob); - view->pimpl_->cursorToggle(); -} - - void BufferView::cursorPrevious() { pimpl_->cursorPrevious(); diff --git a/src/BufferView.h b/src/BufferView.h index 91033dbc6c..e714c63d33 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -205,9 +205,6 @@ public: /// A callback for the slider in the scrollbar. void scrollCB(double); - /// - static void cursorToggleCB(void * ob); - /// void setState(); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 1229b15e02..6f9ecaffa3 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -28,6 +28,10 @@ #include "support/LAssert.h" #include "frontends/Dialogs.h" +#ifdef SIGC_CXX_NAMESPACES +using SigC::slot; +#endif + using std::pair; using std::endl; using std::vector; @@ -74,7 +78,8 @@ BufferView::Pimpl::Pimpl(BufferView * b, LyXView * o, workarea_ = new WorkArea(bv_, xpos, ypos, width, height); screen_ = 0; - cursor_timeout.callback(BufferView::cursorToggleCB, bv_); + cursor_timeout.timeout.connect(slot(this, + &BufferView::Pimpl::cursorToggle)); current_scrollbar_value = 0; cursor_timeout.start(); workarea_->setFocus(); @@ -320,7 +325,7 @@ void BufferView::Pimpl::updateScreen() { // Regenerate the screen. delete screen_; - screen_ = new LyXScreen(*workarea_); //, bv_->text); + screen_ = new LyXScreen(*workarea_); } @@ -1271,6 +1276,7 @@ void BufferView::Pimpl::restorePosition() update(BufferView::SELECT|BufferView::FITCUR); } + bool BufferView::Pimpl::NoSavedPositions() { return backstack.empty(); diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index 5f855c2e61..e7db7acae9 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -16,7 +16,7 @@ class LyXView; class WorkArea; class LyXScreen; -struct BufferView::Pimpl { +struct BufferView::Pimpl : public SigC::Object { Pimpl(BufferView * i, LyXView * o, int xpos, int ypos, int width, int height); /// diff --git a/src/LyXView.C b/src/LyXView.C index 7c2c426bf2..4a1c93f551 100644 --- a/src/LyXView.C +++ b/src/LyXView.C @@ -56,7 +56,6 @@ using SigC::slot; #endif LyXView::LyXView(int width, int height) -// : update_timeout(300) { create_form_form_main(width, height); fl_set_form_atclose(form_, C_LyXView_atCloseMainFormCB, 0); @@ -106,12 +105,6 @@ BufferView * LyXView::view() const } -FD_form_main * LyXView::getMainForm() const -{ - return form_main_; -} - - FL_FORM * LyXView::getForm() const { return form_; @@ -157,14 +150,6 @@ void LyXView::AutoSave() } -// Wrapper for the above -static -void LyXView_AutosaveTimerCB(void * ob) -{ - LyXView * view = static_cast(ob); - view->AutoSave(); -} - /// Reset autosave timer void LyXView::resetAutosaveTimer() { @@ -211,14 +196,9 @@ void LyXView::create_form_form_main(int width, int height) * are presented (and rightly so) in GUI popups. Asger. */ { - FD_form_main * fdui = static_cast - (fl_calloc(1, sizeof(FD_form_main))); - - form_main_ = fdui; - // the main form - form_ = fdui->form_main = fl_bgn_form(FL_NO_BOX, width, height); - fdui->form_main->u_vdata = this; + form_ = fl_bgn_form(FL_NO_BOX, width, height); + form_->u_vdata = this; FL_OBJECT * obj = fl_add_box(FL_FLAT_BOX, 0, 0, width, height, ""); fl_set_object_color(obj, FL_MCOL, FL_MCOL); @@ -263,8 +243,8 @@ void LyXView::create_form_form_main(int width, int height) // TIMERS // - autosave_timeout.callback(LyXView_AutosaveTimerCB, this); - + autosave_timeout.timeout.connect(slot(this, &LyXView::AutoSave)); + // // Misc // @@ -280,16 +260,17 @@ void LyXView::create_form_form_main(int width, int height) 0, 0, 0); // this leaks - fl_set_form_icon(fdui->form_main, lyx_p, lyx_mask); + fl_set_form_icon(form_, lyx_p, lyx_mask); // set min size - fl_set_form_minsize(fdui->form_main, 50, 50); + fl_set_form_minsize(form_, 50, 50); fl_end_form(); } -extern "C" int C_LyXView_KeyPressMask_raw_callback(FL_FORM * fl, void * xev); +extern "C" +int C_LyXView_KeyPressMask_raw_callback(FL_FORM * fl, void * xev); void LyXView::init() { @@ -299,13 +280,10 @@ void LyXView::init() UpdateDocumentClassChoice(); // Start autosave timer - if (lyxrc.autosave) -#if 0 - fl_set_timer(form_main_->timer_autosave, lyxrc.autosave); -#else - autosave_timeout.setTimeout(lyxrc.autosave * 1000); - autosave_timeout.start(); -#endif + if (lyxrc.autosave) { + autosave_timeout.setTimeout(lyxrc.autosave * 1000); + autosave_timeout.start(); + } // Install the raw callback for keyboard events fl_register_raw_callback(form_, @@ -338,7 +316,8 @@ void LyXView::updateLayoutChoice() if (toolbar->combox->empty() || (last_textclass != int(buffer()->params.textclass))) { toolbar->combox->clear(); - LyXTextClass const & tc = textclasslist.TextClass(buffer()->params.textclass); + LyXTextClass const & tc = + textclasslist.TextClass(buffer()->params.textclass); for (LyXTextClass::const_iterator cit = tc.begin(); cit != tc.end(); ++cit) { if ((*cit).obsoleted_by().empty()) @@ -352,7 +331,8 @@ void LyXView::updateLayoutChoice() // we need to do this. toolbar->combox->Redraw(); - LyXTextClass::size_type layout = bufferview->text->cursor.par()->GetLayout(); + LyXTextClass::size_type layout = + bufferview->text->cursor.par()->GetLayout(); if (layout != current_layout){ toolbar->combox->select(layout + 1); @@ -431,7 +411,8 @@ int LyXView::KeyPressMask_raw_callback(FL_FORM * fl, void * xev) // wrapper for the above -extern "C" int C_LyXView_KeyPressMask_raw_callback(FL_FORM * fl, void * xev) +extern "C" +int C_LyXView_KeyPressMask_raw_callback(FL_FORM * fl, void * xev) { return LyXView::KeyPressMask_raw_callback(fl, xev); } diff --git a/src/LyXView.h b/src/LyXView.h index e8c99e22cb..5fab87d125 100644 --- a/src/LyXView.h +++ b/src/LyXView.h @@ -29,19 +29,13 @@ class Menus; class BufferView; class Dialogs; -/// -struct FD_form_main { - /// - FL_FORM * form_main; -}; - /** This class is the form containing the view of the buffer. The actual buffer view is supposed (at least IMHO) to be another class, that shows its output in one or more LyXView's. */ -class LyXView { +class LyXView : public SigC::Object { public: /// constructor LyXView(int w, int h); @@ -67,9 +61,6 @@ public: /// BufferView * view() const; - /// returns a pointer to the main form. - FD_form_main * getMainForm() const; - /// returns a pointer to the form. FL_FORM * getForm() const; @@ -129,16 +120,12 @@ public: static int atCloseMainFormCB(FL_FORM *, void *); /// A callback void AutoSave(); - /// A callback - static void UpdateTimerCB(void *); private: /// Timeout autosave_timeout; /// makes the main form. void create_form_form_main(int width, int height); /// A pointer to the form. - FD_form_main * form_main_; - /// A pointer to the form. FL_FORM * form_; /** The last textclass layout list in the layout choice selector This should probably be moved to the toolbar, but for now it's diff --git a/src/Timeout.C b/src/Timeout.C index fc0a8c5045..4005c83884 100644 --- a/src/Timeout.C +++ b/src/Timeout.C @@ -12,19 +12,19 @@ extern "C" { void C_intern_timeout_cb(int, void * data) { Timeout * to = static_cast(data); - to->callback(); + to->emit(); } } Timeout::Timeout() - : type(ONETIME), timeout(0), timeout_id(-1), - callback_(0), data_(0) {} + : type(ONETIME), timeout_ms(0), timeout_id(-1) +{} Timeout::Timeout(int msec, Type t) - : type(t), timeout(msec), timeout_id(-1), - callback_(0), data_(0) {} + : type(t), timeout_ms(msec), timeout_id(-1) +{} Timeout::~Timeout() @@ -44,7 +44,7 @@ void Timeout::start() { if (timeout_id != -1) lyxerr << "Timeout::start: already running!" << endl; - timeout_id = fl_add_timeout(timeout, + timeout_id = fl_add_timeout(timeout_ms, C_intern_timeout_cb, this); } @@ -58,18 +58,10 @@ void Timeout::stop() } -void Timeout::callback(TimeoutCallback cb, void * data) -{ - callback_ = cb; - data_ = data; -} - - -void Timeout::callback() +void Timeout::emit() { timeout_id = -1; - if (callback_) - callback_(data_); + timeout.emit(); if (type == CONTINOUS) start(); } @@ -83,5 +75,5 @@ void Timeout::setType(Type t) void Timeout::setTimeout(int msec) { - timeout = msec; + timeout_ms = msec; } diff --git a/src/Timeout.h b/src/Timeout.h index fb6797116a..7afefc3f33 100644 --- a/src/Timeout.h +++ b/src/Timeout.h @@ -2,15 +2,18 @@ #ifndef TIMEOUT_H #define TIMEOUT_H +#include + +#ifdef SIGC_CXX_NAMESPACES +using SigC::Signal0; +#endif + /** This class executes the callback when the timeout expires. This class currently uses a regular callback, later it will use signals and slots to provide the same. */ class Timeout { public: - /// - typedef void (*TimeoutCallback)(void *); - /// enum Type { ONETIME, @@ -29,9 +32,9 @@ public: /// void restart(); /// - void callback(TimeoutCallback cb, void * data); + Signal0 timeout; /// - void callback(); + void emit(); /// void setType(Type t); /// @@ -40,13 +43,9 @@ private: /// Type type; /// - int timeout; + int timeout_ms; /// int timeout_id; - /// - TimeoutCallback callback_; - /// - void * data_; }; #endif diff --git a/src/WorkArea.C b/src/WorkArea.C index b20ec6b298..d261fed540 100644 --- a/src/WorkArea.C +++ b/src/WorkArea.C @@ -273,7 +273,7 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, if (!area) return 1; - switch (event){ + switch (event){ case FL_DRAW: if (!area->work_area || !area->work_area->form->visible) @@ -281,6 +281,7 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, lyxerr.debug() << "Workarea event: DRAW" << endl; area->createPixmap(area->workWidth(), area->height()); Lgb_bug_find_hack = true; + //workAreaExpose(); area->owner_->workAreaExpose(); Lgb_bug_find_hack = false; break; @@ -288,6 +289,10 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, if (!ev) break; // Should really have used xbutton.state lyxerr.debug() << "Workarea event: PUSH" << endl; + //workAreaButtonPress(ev->xbutton.x - ob->x, + // ev->xbutton.y - ob->y, + // ev->xbutton.button); + area->owner_->workAreaButtonPress(ev->xbutton.x - ob->x, ev->xbutton.y - ob->y, ev->xbutton.button); @@ -296,6 +301,9 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, if (!ev) break; // Should really have used xbutton.state lyxerr.debug() << "Workarea event: RELEASE" << endl; + //workAreaButtonRelease(ev->xbutton.x - ob->x, + // ev->xbutton.y - ob->y, + // ev->xbutton.button); area->owner_->workAreaButtonRelease(ev->xbutton.x - ob->x, ev->xbutton.y - ob->y, ev->xbutton.button); @@ -307,6 +315,10 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, fl_get_scrollbar_value(area->scrollbar) != scrollbar_value_old ) { lyxerr.debug() << "Workarea event: MOUSE" << endl; + //workAreaMotionNotify(ev->xmotion.x - ob->x, + // ev->xmotion.y - ob->y, + // ev->xbutton.state); + area->owner_->workAreaMotionNotify(ev->xmotion.x - ob->x, ev->xmotion.y - ob->y, ev->xbutton.state); @@ -316,21 +328,28 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, // case FL_KEYBOARD: WorkAreaKeyPress(ob, 0,0,0,ev,0); break; case FL_FOCUS: lyxerr.debug() << "Workarea event: FOCUS" << endl; + //workAreaFocus(); break; case FL_UNFOCUS: lyxerr.debug() << "Workarea event: UNFOCUS" << endl; + //workAreaUnfocus(); break; case FL_ENTER: lyxerr.debug() << "Workarea event: ENTER" << endl; + //workAreaEnter(); area->owner_->enterView(); break; case FL_LEAVE: lyxerr.debug() << "Workarea event: LEAVE" << endl; + //workAreaLeave(); area->owner_->leaveView(); break; case FL_DBLCLICK: if (!ev) break; lyxerr.debug() << "Workarea event: DBLCLICK" << endl; + //workAreaDoubleClick(ev->xbutton.x - ob->x, + // ev->xbutton.y - ob->y, + // ev->xbutton.button); area->owner_->doubleClick(ev->xbutton.x - ob->x, ev->xbutton.y - ob->y, ev->xbutton.button); @@ -338,6 +357,9 @@ int WorkArea::work_area_handler(FL_OBJECT * ob, int event, case FL_TRPLCLICK: if (!ev) break; lyxerr.debug() << "Workarea event: TRPLCLICK" << endl; + //workAreaTripleClick(ev->xbutton.x - ob->x, + // ev->xbutton.y - ob->y, + // ev->xbutton.button); area->owner_->tripleClick(ev->xbutton.x - ob->x, ev->xbutton.y - ob->y, ev->xbutton.button); diff --git a/src/WorkArea.h b/src/WorkArea.h index b57f3e713d..651b2a033c 100644 --- a/src/WorkArea.h +++ b/src/WorkArea.h @@ -18,9 +18,16 @@ #include +//#include + #include FORMS_H_LOCATION #include "Painter.h" +//#ifdef SIGC_CXX_NAMESPACES +//using SigC::Signal0; +//using SigC::Signal3; +//#endif + class BufferView; @@ -98,6 +105,27 @@ public: /// BufferView * owner() const { return owner_; } + // Signals + /// + //Signal0 workAreaExpose; + /// + //Signal3 workAreaButtonPress; + /// + //Signal3 workAreaButtonRelease; + /// + //Signal3 workAreaMotionNotify; + /// + //Signal0 workAreaFocus; + /// + //Signal0 workAreaUnfocus; + /// + //Signal0 workAreaEnter; + /// + //Signal0 workAreaLeave; + /// + //Signal3 workAreaDoubleClick; + /// + //Signal3 workAreaTripleClick; private: /// void createPixmap(int, int); diff --git a/src/insets/Makefile.am b/src/insets/Makefile.am index f8555a96cc..3c098202bb 100644 --- a/src/insets/Makefile.am +++ b/src/insets/Makefile.am @@ -4,7 +4,7 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in noinst_LTLIBRARIES = libinsets.la LIBS = ETAGS_ARGS = --lang=c++ -INCLUDES = -I${srcdir}/../ +INCLUDES = -I${srcdir}/../ $(SIGC_CFLAGS) libinsets_la_SOURCES = \ BoundingBox.h \ diff --git a/src/insets/figinset.C b/src/insets/figinset.C index 1b66a0fc15..546a92c80e 100644 --- a/src/insets/figinset.C +++ b/src/insets/figinset.C @@ -405,7 +405,7 @@ void InitFigures() if (lyxrc.use_gui) { fl_add_canvas_handler(figinset_canvas, ClientMessage, GhostscriptMsg, - current_view->owner()->getMainForm()); + current_view->owner()->getForm()); local_gc_copy = createGC(); diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 1f14e9ce62..78cfe28e45 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -4,7 +4,7 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in noinst_LTLIBRARIES = libmathed.la LIBS= ETAGS_ARGS = --lang=c++ -INCLUDES = -I${top_srcdir}/images -I${srcdir}/../ +INCLUDES = -I${top_srcdir}/images -I${srcdir}/../ $(SIGC_CFLAGS) libmathed_la_SOURCES = array.h \ formula.C \