From d553558b199b3408df05653a59ea44a8c7696534 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 27 Mar 2001 13:00:41 +0000 Subject: [PATCH] Implemented controller-view split for Splash screen. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1836 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/controllers/ChangeLog | 7 ++- src/frontends/controllers/ControlSplash.C | 63 +++++++++++++++++++++ src/frontends/controllers/ControlSplash.h | 57 +++++++++++++++++++ src/frontends/controllers/GUI.h | 17 ++++++ src/frontends/controllers/Makefile.am | 2 + src/frontends/controllers/ViewBase.h | 25 +++++++++ src/frontends/xforms/ChangeLog | 3 +- src/frontends/xforms/Dialogs.C | 7 ++- src/frontends/xforms/FormSplash.C | 67 +++++++++++------------ src/frontends/xforms/FormSplash.h | 29 +++++----- 10 files changed, 221 insertions(+), 56 deletions(-) create mode 100644 src/frontends/controllers/ControlSplash.C create mode 100644 src/frontends/controllers/ControlSplash.h diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index c2533d5c0c..9af84c78ea 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,6 +1,11 @@ 2001-03-27 Angus Leeming - * ControlPrint.[Ch]: new file; controller for the Print popups. + * ControlPrint.[Ch]: + * ControlSplash.[Ch]: new files; controller for the Print popup and + Splash screen respectively. + + * ViewBase.h (ViewSplash): new base class for GUI-specific Splash + screens. * GUI.h: * Makefile.am: associated changes. diff --git a/src/frontends/controllers/ControlSplash.C b/src/frontends/controllers/ControlSplash.C new file mode 100644 index 0000000000..fd18e80073 --- /dev/null +++ b/src/frontends/controllers/ControlSplash.C @@ -0,0 +1,63 @@ +/** + * \file ControlSplash.C + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author Allan Rae + * \author John Levon + * \author Angus Leeming, a.leeming@ic.ac.uk + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "ControlSplash.h" +#include "Dialogs.h" +#include "ViewBase.h" +#include "version.h" +#include "support/filetools.h" +#include "lyxrc.h" // show_banner + +ControlSplash::ControlSplash(Dialogs & d) + : d_(d) +{ + c_ = d.showSplash.connect(SigC::slot(this, &ControlSplash::show)); +} + + +string const & ControlSplash::bannerFile() const +{ + return banner_file_; +} + + +string const & ControlSplash::LyXVersion() const +{ + return version_; +} + + +void ControlSplash::show() +{ + if (!lyxrc.show_banner) + return; + + banner_file_ = LibFileSearch("images", "banner", "xpm"); + if (banner_file_.empty()) + return; + + version_ = LYX_VERSION; + + view().show(); +} + + +void ControlSplash::hide() +{ + view().hide(); + c_.disconnect(); + d_.destroySplash(); +} diff --git a/src/frontends/controllers/ControlSplash.h b/src/frontends/controllers/ControlSplash.h new file mode 100644 index 0000000000..d3385c94c9 --- /dev/null +++ b/src/frontends/controllers/ControlSplash.h @@ -0,0 +1,57 @@ +/** + * \file ControlSplash.h + * Copyright 2001 the LyX Team + * Read the file COPYING + * + * \author Allan Rae + * \author John Levon + * \author Angus Leeming, a.leeming@ic.ac.uk + */ + +#ifndef CONTROLSPLASH_H +#define CONTROLSPLASH_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "DialogBase.h" +#include "LString.h" + +class Dialogs; +class ViewSplash; + +/** The startup splash screen + */ +class ControlSplash : public DialogBase { +public: + /// + ControlSplash(Dialogs &); + /// + string const & bannerFile() const; + /// + string const & LyXVersion() const; + /// hide (and destroy) the dialog + void hide(); + +private: + /** Allow the Controller to access the View. This method must be + instantiated in a daughter class that creates the actual instance + of the View. */ + virtual ViewSplash & view() = 0; + + /// show the dialog + void show(); + + /// our container + Dialogs & d_; + /// the show connection + SigC::Connection c_; + + /// + string banner_file_; + /// + string version_; +}; + +#endif // CONTROLSPLASH_H diff --git a/src/frontends/controllers/GUI.h b/src/frontends/controllers/GUI.h index c322ac6ffa..fbe6a4ddf2 100644 --- a/src/frontends/controllers/GUI.h +++ b/src/frontends/controllers/GUI.h @@ -9,6 +9,23 @@ #ifndef GUI_H #define GUI_H +/** This class instantiates and makes available the GUI-specific + View for the Splash screen controller. + */ +template +class GUISplash : public ControlSplash { +public: + /// + GUISplash(Dialogs & d) : ControlSplash(d), view_(*this) {} + /// + virtual ViewSplash & view() { return view_; } + +private: + /// + GUIview view_; +}; + + /** This class instantiates and makes available the GUI-specific ButtonController and View. */ diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index 8bf3b7b28f..66752dc88e 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -46,6 +46,8 @@ libcontrollers_la_SOURCES=\ ControlRef.h \ ControlSearch.C \ ControlSearch.h \ + ControlSplash.C \ + ControlSplash.h \ ControlTabularCreate.C \ ControlTabularCreate.h \ ControlUrl.C \ diff --git a/src/frontends/controllers/ViewBase.h b/src/frontends/controllers/ViewBase.h index a99d51f1ae..37a4ca9cef 100644 --- a/src/frontends/controllers/ViewBase.h +++ b/src/frontends/controllers/ViewBase.h @@ -16,6 +16,7 @@ #include #include "ControlBase.h" +#include "ControlSplash.h" class ViewBase { public: @@ -53,6 +54,30 @@ protected: }; +class ViewSplash { +public: + /// + ViewSplash(ControlSplash & c) : controller_(c) {} + /// + virtual ~ViewSplash() {} + + /// Hide the dialog. + virtual void hide() = 0; + /// Create the dialog and show it. + virtual void show() = 0; + + /** The shortcut allows (e.g. xform's) global callback functions + access without making the whole controller_ public. + */ + /// + void Hide() { controller_.hide(); } + +protected: + /// The view is, after all, controlled! + ControlSplash & controller_; +}; + + /** A generic class to cast the ButtonController controller_.bc_ to it's daughter class. */ template diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 0fc3c04cba..3a4af75365 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,7 +1,8 @@ 2001-03-27 Angus Leeming * FormPrint.[Ch]: - * forms/form_print.fd: implemented controller-view split. + * forms/form_print.fd: + * FormSplash.[Ch]: implemented controller-view split. * Dialogs.C: associated changes. diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 0f7771f295..94f5d602fd 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -31,6 +31,7 @@ #include "ControlPrint.h" #include "ControlRef.h" #include "ControlSearch.h" +#include "ControlSplash.h" #include "ControlTabularCreate.h" #include "ControlUrl.h" #include "ControlVCLog.h" @@ -50,6 +51,7 @@ #include "form_print.h" #include "form_ref.h" #include "form_search.h" +#include "form_splash.h" #include "form_tabular_create.h" #include "form_url.h" @@ -65,6 +67,7 @@ #include "FormPrint.h" #include "FormRef.h" #include "FormSearch.h" +#include "FormSplash.h" #include "FormTabularCreate.h" #include "FormUrl.h" #include "FormVCLog.h" @@ -77,7 +80,6 @@ #include "FormParagraph.h" #include "FormPreamble.h" #include "FormPreferences.h" -#include "FormSplash.h" #include "FormTabular.h" #include "FormToc.h" #include "FormMinipage.h" @@ -88,7 +90,7 @@ SigC::Signal0 Dialogs::redrawGUI; Dialogs::Dialogs(LyXView * lv) { - splash_.reset(new FormSplash(lv, this)); + splash_.reset(new GUISplash(*this)); add(new GUIBibitem(*lv, *this)); add(new GUIBibtex(*lv, *this)); @@ -114,7 +116,6 @@ Dialogs::Dialogs(LyXView * lv) add(new FormParagraph(lv, this)); add(new FormPreamble(lv, this)); add(new FormPreferences(lv, this)); - add(new FormSplash(lv, this)); add(new FormTabular(lv, this)); add(new FormToc(lv, this)); add(new FormMinipage(lv, this)); diff --git a/src/frontends/xforms/FormSplash.C b/src/frontends/xforms/FormSplash.C index d5ed5e6a0b..e06bf4923b 100644 --- a/src/frontends/xforms/FormSplash.C +++ b/src/frontends/xforms/FormSplash.C @@ -10,56 +10,57 @@ #include #include FORMS_H_LOCATION - + #ifdef __GNUG__ #pragma implementation #endif -#include "Dialogs.h" -#include "LyXView.h" -#include "form_splash.h" +#include "ControlSplash.h" #include "FormSplash.h" -#include "version.h" -#include "support/filetools.h" -#include "lyxrc.h" - -using SigC::slot; +#include "form_splash.h" +#include "form_splash.h" +#include "support/LAssert.h" -extern "C" int C_FormSplashCloseCB(FL_FORM * forms, void *) +extern "C" int C_FormSplashCloseCB(FL_FORM * form, void *) { - Assert(forms); - FormSplash * form = static_cast(forms->u_vdata); - form->hide(); - return 0; + Assert(form && form->u_vdata); + FormSplash * pre = static_cast(form->u_vdata); + pre->Hide(); + return FL_CANCEL; } extern "C" void C_FormSplashCB(FL_OBJECT * ob, long) { - FormSplash * form = static_cast(ob->form->u_vdata); - form->hide(); + Assert(ob && ob->form && ob->form->u_vdata); + FormSplash * pre = static_cast(ob->form->u_vdata); + pre->Hide(); } -FormSplash::FormSplash(LyXView *, Dialogs * d) - : d_(d) +FormSplash::FormSplash(ControlSplash & c) + : ViewSplash(c) +{} + + +ControlSplash & FormSplash::controller() const { - c_ = d->showSplash.connect(slot(this, &FormSplash::show)); + return static_cast(controller_); + //return dynamic_cast(controller_); } void FormSplash::show() { - if (!lyxrc.show_banner) - return; - if (!dialog_.get()) { build(); fl_set_form_atclose(dialog_->form, C_FormSplashCloseCB, 0); } - int const xpos = WidthOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)); - int const ypos = HeightOfScreen(ScreenOfDisplay(fl_get_display(), fl_screen)); + int const xpos = WidthOfScreen(ScreenOfDisplay(fl_get_display(), + fl_screen)); + int const ypos = HeightOfScreen(ScreenOfDisplay(fl_get_display(), + fl_screen)); fl_set_form_position(dialog_->form, xpos, ypos); @@ -69,41 +70,37 @@ void FormSplash::show() if (dialog_->form->visible) fl_raise_form(dialog_->form); else + // Workaround dumb xforms sizing bug + fl_set_form_minsize(dialog_->form, + dialog_->form->w, + dialog_->form->h); fl_show_form(dialog_->form, FL_PLACE_CENTER, FL_NOBORDER, ""); } void FormSplash::hide() { - c_.disconnect(); if (dialog_->form && dialog_->form->visible) fl_hide_form(dialog_->form); - d_->destroySplash(); } void FormSplash::build() { - string banner_file = LibFileSearch("images", "banner", "xpm"); - if (banner_file.empty()) - return; - dialog_.reset(build_splash()); - // Workaround dumb xforms sizing bug - fl_set_form_minsize(dialog_->form, dialog_->form->w, dialog_->form->h); - fl_set_form_dblbuffer(dialog_->form, 1); // use dbl buffer fl_addto_form(dialog_->form); FL_OBJECT * obj = fl_add_pixmapbutton(FL_NORMAL_BUTTON, 0, 0, 425, 290, ""); - fl_set_pixmapbutton_file(obj, banner_file.c_str()); + fl_set_pixmapbutton_file(obj, controller().bannerFile().c_str()); fl_set_pixmapbutton_focus_outline(obj, 3); fl_set_button_shortcut(obj, "^M ^[", 1); fl_set_object_boxtype(obj, FL_NO_BOX); fl_set_object_callback(obj, C_FormSplashCB, 0); - obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, LYX_VERSION); + obj = fl_add_text(FL_NORMAL_TEXT, 248, 265, 170, 16, + controller().LyXVersion().c_str()); fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_mapcolor(FL_FREE_COL2, 0x05, 0x2e, 0x4c); fl_mapcolor(FL_FREE_COL3, 0xe1, 0xd2, 0x9b); diff --git a/src/frontends/xforms/FormSplash.h b/src/frontends/xforms/FormSplash.h index b550f6aeed..e648ef0b69 100644 --- a/src/frontends/xforms/FormSplash.h +++ b/src/frontends/xforms/FormSplash.h @@ -16,37 +16,34 @@ #pragma interface #endif -#include "DialogBase.h" -#include "xformsBC.h" - +#include "ViewBase.h" + +class ControlSplash; struct FD_form_splash; -class Dialogs; -class LyXView; /** The startup splash screen */ -class FormSplash : public DialogBase { +class FormSplash : public ViewSplash { public: /// - FormSplash(LyXView *, Dialogs *); + FormSplash(ControlSplash &); - /// hide (and destroy) the dialog - void hide(); - private: - /// show the dialog - void show(); /// Build the dialog void build(); + /// hide the dialog + void hide(); + /// show the dialog + void show(); + + /// The parent controller + ControlSplash & controller() const; + /// Fdesign generated method FD_form_splash * build_splash(); /// Real GUI implementation. boost::scoped_ptr dialog_; - /// our container - Dialogs * d_; - /// the show connection - SigC::Connection c_; }; #endif // FORMSPLASH_H -- 2.39.2