From: Angus Leeming Date: Thu, 22 Mar 2001 11:24:36 +0000 (+0000) Subject: Reorganised, cleaned-up and improved documentation of controllers. X-Git-Tag: 1.6.10~21424 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=8a4455d459e52510b5c86dd872bcd8c65cc41903;p=features.git Reorganised, cleaned-up and improved documentation of controllers. Implemented controller-view split for Copyright and Credits popups. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1803 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/frontends/controllers/ButtonController.h b/src/frontends/controllers/ButtonController.h index c3fec57b00..891889e3a1 100644 --- a/src/frontends/controllers/ButtonController.h +++ b/src/frontends/controllers/ButtonController.h @@ -1,5 +1,7 @@ -// -*- C++ -*- -/* This file is part of +/* + * \file ButtonController.h + * + * This file is part of * ====================================================== * * LyX, The Document Processor @@ -8,8 +10,7 @@ * * ====================================================== * - * \file ButtonController.h - * \author Allan Rae + * \author Allan Rae, rae@lyx.org */ #ifndef BUTTONCONTROLLER_H diff --git a/src/frontends/controllers/ButtonPolicies.h b/src/frontends/controllers/ButtonPolicies.h index 8f386ca422..bf8a758374 100644 --- a/src/frontends/controllers/ButtonPolicies.h +++ b/src/frontends/controllers/ButtonPolicies.h @@ -1,8 +1,10 @@ -// -*- C++ -*- -/* ButtonPolicies.h +/* + * \file ButtonPolicies.h + * \author Allan Rae, rae@lyx.org + * * Provides a state machine implementation of the various button policies * used by the dialogs. - * Author: Allan Rae + * * This file is part of * ====================================================== * diff --git a/src/frontends/controllers/ChangeLog b/src/frontends/controllers/ChangeLog index 91015ea4e0..10458537b9 100644 --- a/src/frontends/controllers/ChangeLog +++ b/src/frontends/controllers/ChangeLog @@ -1,3 +1,50 @@ +2001-03-22 Angus Leeming + + * lots of header files: improved explanatory notes. + + * ControlBase.[Ch]: removed LyXView & lv_ and methods using it. + ControlBase is now a class that only controls the interaction of the + View with the ButtonController. + + * ControlConnections.[Ch]: added LyXView & lv_ and associated methods + to ControlConnectBase. The class controls the connection/disconnection + of signals from the LyX kernel and makes available the kernel (through + lv_) to daughter controller classes. + Moved out class ControlConnectInset to a new file ControlDialogs.h. + + * ControlDialogs.h: new file. Contains the definition of two template + controller classes, ControlDialog and ControlInset (was + ControlConnectInset). ControlInset is a parent class for controllers + of inset-popups. ControlDialogs is the rather uninspired name for + the base class of all non-inset popups. (Eg, Document and Paragraph.) + ControlDialogs is reaching a state of maturity as several popups now use + it and its functionality becomes clear. ControlInset is still in a state + of flux. It is likely that functionality will be moved out of + ControlCommands and into it. + + * GUI.h: new file. Moved all the template GUIXXX classes out of the + individual Controller header files and into one place. These classes + serve only as convenient wrappers to simplify code in the respective + frontends' Dialogs::c-tor. Now all derived from a templatised parent. + + * ControlCharacter.[Ch] (show, update, hide): + * ControlLog.[Ch] (show, update, hide): + * ControlVCLog.[Ch] (show, update, hide): moved back into + the ControlDialogs base class. + (setParams, clearParams): new methods containing controller-specific + code to set/reset the parameters manipulated by the view. + + * ControlCommand.[Ch] (clearParams): a new virtual method, by default + empty. + (hide): calls clearParams. + + * ControlCitation.[Ch] (hide): renamed as clearParams, a method called + by ControlCommand::hide(). + + * ControlCopyright.[Ch]: + * ControlCredits.[Ch]: new files; controllers for the copyright and + credits popups, respectively. + 2001-03-21 Lars Gullik Bjønnes * ControlCharacter.C: fix typo diff --git a/src/frontends/controllers/ControlBase.C b/src/frontends/controllers/ControlBase.C index 8d3ea35846..f1d03f02df 100644 --- a/src/frontends/controllers/ControlBase.C +++ b/src/frontends/controllers/ControlBase.C @@ -18,11 +18,8 @@ #include -#include "buffer.h" #include "ButtonController.h" #include "ControlBase.h" -#include "LyXView.h" -#include "support/LAssert.h" void ControlBase::ApplyButton() { @@ -51,9 +48,3 @@ void ControlBase::RestoreButton() update(); bc().undoAll(); } - - -bool ControlBase::isReadonly() const -{ - return lv_.buffer()->isReadonly(); -} diff --git a/src/frontends/controllers/ControlBase.h b/src/frontends/controllers/ControlBase.h index d3c73ef7dc..84e4a1bfb1 100644 --- a/src/frontends/controllers/ControlBase.h +++ b/src/frontends/controllers/ControlBase.h @@ -1,4 +1,3 @@ -// -*- C++ -*- /* This file is part of * ====================================================== * @@ -11,11 +10,17 @@ * \file ControlBase.h * \author Angus Leeming * - * The Controller connects the GUI-dependent popup to any appropriate + * ControlBase serves only to control the activation of the Ok, Apply, Cancel + * and Restore buttons on the View popup. + * + * More generally, the class is part of a hierarchy of controller classes + * that together connect the GUI-dependent popup to any appropriate * signals and dispatches any changes to the kernel. - * It has no knowledge of the actual instantiation of the + * + * These controllers have no knowledge of the actual instantiation of the * GUI-dependent View and ButtonController, which should therefore * be created elsewhere. + * * Once created, the Controller will take care of their initialisation, * management and, ultimately, destruction. */ @@ -30,8 +35,6 @@ #include "DialogBase.h" // This can go eventually #include "ButtonController.h" -class Dialogs; -class LyXView; class ViewBase; /** Abstract base class for Controllers with a ButtonController. @@ -40,7 +43,7 @@ class ControlBase : public DialogBase { public: // methods /// - ControlBase(LyXView & lv) : lv_(lv) {} + ControlBase() {} /// virtual ~ControlBase() {}; @@ -54,9 +57,6 @@ public: // methods /// void RestoreButton(); - /// The View may need to know if the buffer is read-only. - bool isReadonly() const; - /** Allow the view to access the ButtonController. This method must be instantiated in a daughter class that creates the actual instance of the ButtonController. */ @@ -74,9 +74,6 @@ protected: instantiated in a daughter class that creates the actual instance of the View. */ virtual ViewBase & view() = 0; - - /// Get at the kernel Dispatch methods we need to apply() parameters. - LyXView & lv_; }; #include "ViewBase.h" diff --git a/src/frontends/controllers/ControlBibitem.h b/src/frontends/controllers/ControlBibitem.h index f2c5176ac1..27263b2425 100644 --- a/src/frontends/controllers/ControlBibitem.h +++ b/src/frontends/controllers/ControlBibitem.h @@ -35,30 +35,4 @@ protected: virtual void apply(); }; -/** This class instantiates and makes available the GUI-specific - ButtonController and View. - */ -template -class GUIBibitem : public ControlBibitem { -public: - /// - GUIBibitem(LyXView &, Dialogs &); - /// - virtual ButtonControllerBase & bc() { return bc_; } - /// - virtual ViewBase & view() { return view_; } - -private: - /// - ButtonController bc_; - /// - GUIview view_; -}; - -template -GUIBibitem::GUIBibitem(LyXView & lv, Dialogs & d) - : ControlBibitem(lv, d), - view_(*this) -{} - #endif // CONTROLBIBITEM_H diff --git a/src/frontends/controllers/ControlBibtex.h b/src/frontends/controllers/ControlBibtex.h index 42789a18c9..2be3c6c241 100644 --- a/src/frontends/controllers/ControlBibtex.h +++ b/src/frontends/controllers/ControlBibtex.h @@ -35,30 +35,4 @@ protected: virtual void apply(); }; -/** This class instantiates and makes available the GUI-specific - ButtonController and View. - */ -template -class GUIBibtex : public ControlBibtex { -public: - /// - GUIBibtex(LyXView &, Dialogs &); - /// - virtual ButtonControllerBase & bc() { return bc_; } - /// - virtual ViewBase & view() { return view_; } - -private: - /// - ButtonController bc_; - /// - GUIview view_; -}; - -template -GUIBibtex::GUIBibtex(LyXView & lv, Dialogs & d) - : ControlBibtex(lv, d), - view_(*this) -{} - #endif // CONTROLBIBTEX_H diff --git a/src/frontends/controllers/ControlCharacter.C b/src/frontends/controllers/ControlCharacter.C index 13b0f116f4..0c5d73d7dd 100644 --- a/src/frontends/controllers/ControlCharacter.C +++ b/src/frontends/controllers/ControlCharacter.C @@ -28,46 +28,27 @@ using SigC::slot; using std::vector; ControlCharacter::ControlCharacter(LyXView & lv, Dialogs & d) - : ControlConnectBD(lv, d), font_(0), toggleall_(false) + : ControlDialog(lv, d), + font_(0), toggleall_(false) { d.showLayoutCharacter.connect(slot(this, &ControlCharacter::show)); d.setUserFreeFont.connect(slot(this, &ControlCharacter::apply)); } -void ControlCharacter::show() +void ControlCharacter::setParams() { - if (!lv_.view()->available()) return; - if (font_) delete font_; font_ = new LyXFont(LyXFont::ALL_IGNORE); - - bc().readOnly(isReadonly()); - view().show(); } -void ControlCharacter::update() -{ - if (!lv_.view()->available()) return; - - if (font_) delete font_; - font_ = new LyXFont(LyXFont::ALL_IGNORE); - - bc().readOnly(isReadonly()); - view().update(); -} - - -void ControlCharacter::hide() +void ControlCharacter::clearParams() { if (font_) { delete font_; font_ = 0; } - - disconnect(); - view().hide(); } diff --git a/src/frontends/controllers/ControlCharacter.h b/src/frontends/controllers/ControlCharacter.h index 92a671fbf3..4eb44ca0b6 100644 --- a/src/frontends/controllers/ControlCharacter.h +++ b/src/frontends/controllers/ControlCharacter.h @@ -13,13 +13,13 @@ #pragma interface #endif -#include "ControlConnections.h" +#include "ControlDialogs.h" #include "lyxfont.h" #include "LColor.h" /** A controller for Character dialogs. */ -class ControlCharacter : public ControlConnectBD +class ControlCharacter : public ControlDialog { public: /// @@ -74,12 +74,10 @@ public: protected: /// Get changed parameters and Dispatch them to the kernel. virtual void apply(); - /// Show the dialog. - virtual void show(); - /// Update the dialog. - virtual void update(); - /// Hide the dialog. - virtual void hide(); + /// set the params before show or update. + virtual void setParams(); + /// clean-up on hide. + virtual void clearParams(); private: LyXFont * font_; @@ -101,30 +99,4 @@ std::vector const getColorData(); /// std::vector const getLanguageData(); -/** This class instantiates and makes available the GUI-specific - ButtonController and View. - */ -template -class GUICharacter : public ControlCharacter { -public: - /// - GUICharacter(LyXView &, Dialogs &); - /// - virtual ButtonControllerBase & bc() { return bc_; } - /// - virtual ViewBase & view() { return view_; } - -private: - /// - ButtonController bc_; - /// - GUIview view_; -}; - -template -GUICharacter::GUICharacter(LyXView & lv, Dialogs & d) - : ControlCharacter(lv, d), - view_(*this) -{} - #endif // CONTROLCHARACTER_H diff --git a/src/frontends/controllers/ControlCitation.C b/src/frontends/controllers/ControlCitation.C index 05a409e4c9..7a882f7f17 100644 --- a/src/frontends/controllers/ControlCitation.C +++ b/src/frontends/controllers/ControlCitation.C @@ -45,10 +45,9 @@ ControlCitation::ControlCitation(LyXView & lv, Dialogs & d) } -void ControlCitation::hide() +void ControlCitation::clearParams() { bibkeysInfo_.clear(); - ControlCommand::hide(); } diff --git a/src/frontends/controllers/ControlCitation.h b/src/frontends/controllers/ControlCitation.h index fc6b2c56a9..166264ec5e 100644 --- a/src/frontends/controllers/ControlCitation.h +++ b/src/frontends/controllers/ControlCitation.h @@ -56,38 +56,11 @@ public: string const getBibkeyInfo(string const &); private: /// Clean up, then hide dialog. - virtual void hide(); + virtual void clearParams(); /// The info associated with each key InfoMap bibkeysInfo_; }; - -/** This class instantiates and makes available the GUI-specific - ButtonController and View. - */ -template -class GUICitation : public ControlCitation { -public: - /// - GUICitation(LyXView &, Dialogs &); - /// - virtual ButtonControllerBase & bc() { return bc_; } - /// - virtual ViewBase & view() { return view_; } - -private: - /// - ButtonController bc_; - /// - GUIview view_; -}; - -template -GUICitation::GUICitation(LyXView & lv, Dialogs & d) - : ControlCitation(lv, d), - view_(*this) -{} - /** Helper functions, of possible use to all frontends */ diff --git a/src/frontends/controllers/ControlCommand.C b/src/frontends/controllers/ControlCommand.C index b728bed8de..1ed0c12fa6 100644 --- a/src/frontends/controllers/ControlCommand.C +++ b/src/frontends/controllers/ControlCommand.C @@ -26,7 +26,7 @@ #include "support/LAssert.h" ControlCommand::ControlCommand(LyXView & lv, Dialogs & d, kb_action ac) - : ControlConnectInset(lv, d), + : ControlInset(lv, d), params_(0), action_(ac) {} @@ -84,6 +84,8 @@ void ControlCommand::hide() params_ = 0; } + clearParams(); + disconnect(); view().hide(); } diff --git a/src/frontends/controllers/ControlCommand.h b/src/frontends/controllers/ControlCommand.h index b5373a49fb..996a84d326 100644 --- a/src/frontends/controllers/ControlCommand.h +++ b/src/frontends/controllers/ControlCommand.h @@ -11,10 +11,13 @@ * \file ControlCommand.h * \author Angus Leeming * - * Defines a Controller class for dialogs that create or modify + * ControlCommand is a controller class for dialogs that create or modify * an inset derived from InsetCommand. - * Also defines the abstract base class from which the GUI-dependent Views - * of this dialog should be derived. + * + * The class is likely to be changed as other Inset controllers are created + * and it becomes clear just what functionality can be moved back into + * ControlInset. + * */ #ifndef CONTROLCOMMAND_H @@ -24,14 +27,14 @@ #pragma interface #endif -#include "ControlConnections.h" +#include "ControlDialogs.h" #include "insets/insetcommand.h" #include "commandtags.h" // kb_action /** The Inset dialog controller. Connects/disconnects signals, launches GUI-dependent View and returns the output from this View to the kernel. */ -class ControlCommand : public ControlConnectInset +class ControlCommand : public ControlInset { public: /// @@ -58,6 +61,10 @@ protected: /// Update dialog before showing it. virtual void update(); + /// clean-up on hide. + virtual void clearParams() {} + + private: /** A local copy of the inset's params. Memory is allocated only whilst the dialog is visible. diff --git a/src/frontends/controllers/ControlConnections.C b/src/frontends/controllers/ControlConnections.C index a98c1d4df4..050a00d9c8 100644 --- a/src/frontends/controllers/ControlConnections.C +++ b/src/frontends/controllers/ControlConnections.C @@ -20,13 +20,13 @@ #include "ControlConnections.h" #include "Dialogs.h" -#include "insets/lyxinset.h" +#include "LyXView.h" +#include "buffer.h" using SigC::slot; ControlConnectBase::ControlConnectBase(LyXView & lv, Dialogs & d) - : ControlBase(lv), - d_(d), h_(0), r_(0) + : lv_(lv), d_(d), h_(0), r_(0) {} @@ -49,6 +49,15 @@ void ControlConnectBase::redraw() } +bool ControlConnectBase::isReadonly() const +{ + if (!lv_.buffer()) + return true; + + return lv_.buffer()->isReadonly(); +} + + ControlConnectBI::ControlConnectBI(LyXView & lv, Dialogs & d) : ControlConnectBase(lv, d) {} diff --git a/src/frontends/controllers/ControlConnections.h b/src/frontends/controllers/ControlConnections.h index 63a3b5883b..7a295c9610 100644 --- a/src/frontends/controllers/ControlConnections.h +++ b/src/frontends/controllers/ControlConnections.h @@ -1,4 +1,3 @@ -// -*- C++ -*- /* This file is part of * ====================================================== * @@ -10,6 +9,22 @@ * * \file ControlConnections.h * \author Angus Leeming + * + * ControlConnections.h contains the definition of three controller classes, + * ControlConnectBase, ControlConnectBI and ControlConnectBD. + * + * Together they control the connection/disconnection of signals with the LyX + * kernel. Controllers of individual popups interacting with the kernel through + * signals/slots will all be derived from ControlConnectBI or ControlConnectBD. + * + * A popup is classed as "Buffer Dependent" if its contents change with the + * buffer (document). An example would be the Citation popup. Such a popup + * would be derived, therefore, from ControlConnectBD. + * + * Conversely, a popup is "Buffer Independent" if its contents do not change + * when the buffer changes. An example would be the Copyright popup. Such a + * popup, is therefore derived from ControlConnectBI. + * */ #ifndef CONTROLCONNECTIONS_H @@ -21,6 +36,9 @@ #include "ControlBase.h" +class Dialogs; +class LyXView; + /** Base class to control connection/disconnection of signals with the LyX kernel. It is meant to be used solely as the parent class to ControlConnectBI and ControlConnectBD. @@ -30,8 +48,13 @@ class ControlConnectBase : public ControlBase public: /// ControlConnectBase(LyXView &, Dialogs &); + /// The View may need to know if the buffer is read-only. + bool isReadonly() const; protected: + /// True if the dialog depends on the buffer, else false. + virtual bool isBufferDependent() const = 0; + /// Connect signals virtual void connect(); /// Disconnect signals @@ -42,6 +65,8 @@ protected: */ void redraw(); + /// Get at the kernel Dispatch methods we need to apply() parameters. + LyXView & lv_; /// Contains the signals we have to connect to. Dialogs & d_; /// Hide connection. @@ -64,6 +89,8 @@ public: ControlConnectBI(LyXView &, Dialogs &); protected: + /// + virtual bool isBufferDependent() const { return false; } /// Connect signals virtual void connect(); }; @@ -79,6 +106,8 @@ public: ControlConnectBD(LyXView &, Dialogs &); protected: + /// + virtual bool isBufferDependent() const { return true; } /** Slot connected to update signal. Bool indicates if a buffer switch took place. Default behaviour is to ignore this and simply update(). @@ -94,87 +123,4 @@ private: SigC::Connection u_; }; -/** Base class to control connection/disconnection of signals with the LyX - kernel for Inset dialogs. - */ -class Inset; - -template -class ControlConnectInset : public ControlConnectBD -{ -public: - /// - ControlConnectInset(LyXView &, Dialogs &); - -protected: - /// Slot connected to update signal. - virtual void updateSlot(bool); - /// Connect signals - void connectInset(Inset * = 0); - /// Disconnect signals - virtual void disconnect(); - /// - void disconnectInset(); - -protected: - /// pointer to the inset passed through connectInset - Inset * inset_; - -private: - /// inset::hide connection. - SigC::Connection ih_; -}; - - -template -ControlConnectInset::ControlConnectInset(LyXView & lv, Dialogs & d) - : ControlConnectBD(lv, d), - inset_(0), ih_(0) -{} - - -template -void ControlConnectInset::updateSlot(bool switched) -{ - if (switched) - hide(); - else - update(); -} - - -template -void ControlConnectInset::disconnect() -{ - inset_ = 0; - ih_.disconnect(); - ControlConnectBD::disconnect(); -} - - -template -void ControlConnectInset::connectInset(Inset * inset) -{ - // If connected to another inset, disconnect from it. - if (inset_) { - ih_.disconnect(); - inset_ = 0; - } - - if (inset) { - inset_ = inset; - ih_ = inset->hideDialog.connect( - SigC::slot(this, &ControlConnectInset::hide)); - } - connect(); -} - - -template -void ControlConnectInset::disconnectInset() -{ - ih_.disconnect(); -} - - #endif // CONTROLCONNECTIONS_H diff --git a/src/frontends/controllers/ControlCopyright.C b/src/frontends/controllers/ControlCopyright.C new file mode 100644 index 0000000000..0e78135b77 --- /dev/null +++ b/src/frontends/controllers/ControlCopyright.C @@ -0,0 +1,43 @@ +/* + * \file ControlCopyright.C + * Copyright 2000-2001 The LyX Team. + * See the file COPYING. + * + * \author Allan Rae + * \author Angus Leeming, a.leeming@.ac.uk + */ + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include + +#include "ControlCopyright.h" +#include "Dialogs.h" +#include "LyXView.h" +#include "BufferView.h" + +using SigC::slot; + +ControlCopyright::ControlCopyright(LyXView & lv, Dialogs & d) + : ControlDialog(lv, d) +{ + d_.showCopyright.connect(slot(this, &ControlCopyright::show)); +} + + +string const ControlCopyright::getCopyright() const +{ + return _("LyX is Copyright (C) 1995 by Matthias Ettrich,\n1995-2001 LyX Team"); +} + +string const ControlCopyright::getLicence() const +{ + return _("This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version."); +} + +string const ControlCopyright::getDisclaimer() const +{ + return _("LyX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\nSee the GNU General Public License for more details.\nYou should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA."); +} diff --git a/src/frontends/controllers/ControlCopyright.h b/src/frontends/controllers/ControlCopyright.h new file mode 100644 index 0000000000..ef26fcb627 --- /dev/null +++ b/src/frontends/controllers/ControlCopyright.h @@ -0,0 +1,64 @@ +/* + * \file ControlCopyright.C + * Copyright 2000-2001 The LyX Team. + * See the file COPYING. + * + * \author Allan Rae + * \author Angus Leeming, a.leeming@.ac.uk + */ + +#ifndef CONTROLCOPYRIGHT_H +#define CONTROLCOPYRIGHT_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "ControlDialogs.h" + +/** A controller for Copyright dialogs. + */ +class ControlCopyright : public ControlDialog { +public: + /// + ControlCopyright(LyXView &, Dialogs &); + + /// + string const getCopyright() const; + /// + string const getLicence() const; + /// + string const getDisclaimer() const; + +private: + /// not needed. + virtual void apply() {} +}; + +/** This class instantiates and makes available the GUI-specific + ButtonController and View. + */ +template +class GUICopyright : public ControlCopyright { +public: + /// + GUICopyright(LyXView &, Dialogs &); + /// + virtual ButtonControllerBase & bc() { return bc_; } + /// + virtual ViewBase & view() { return view_; } + +private: + /// + ButtonController bc_; + /// + GUIview view_; +}; + +template +GUICopyright::GUICopyright(LyXView & lv, Dialogs & d) + : ControlCopyright(lv, d), + view_(*this) +{} +#endif // CONTROLCOPYRIGHT_H + diff --git a/src/frontends/controllers/ControlCredits.C b/src/frontends/controllers/ControlCredits.C new file mode 100644 index 0000000000..22db81a77c --- /dev/null +++ b/src/frontends/controllers/ControlCredits.C @@ -0,0 +1,72 @@ +/** + * \file ControlCredits.C + * Copyright 2001 The LyX Team. + * See the file COPYING. + * + * \author Edwin Leuven, leuven@fee.uva.nl + * \author Angus Leeming, a.leeming@.ac.uk + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include + +#include "ControlCredits.h" +#include "Dialogs.h" +#include "LyXView.h" +#include "BufferView.h" +#include "gettext.h" +#include "support/filetools.h" // FileSearch + +using SigC::slot; +using std::getline; +using std::ifstream; +using std::ios_base; +using std::vector; + +ControlCredits::ControlCredits(LyXView & lv, Dialogs & d) + : ControlDialog(lv, d) +{ + d_.showCredits.connect(slot(this, &ControlCredits::show)); +} + + +// needed for the browser +extern string system_lyxdir; + +vector const ControlCredits::getCredits() const +{ + vector data; + + string const name = FileSearch(system_lyxdir, "CREDITS"); + + bool found = (!name.empty()); + + if (found) { + ifstream in(name.c_str()); + found = (in.get()); + + if (found) { + in.seekg(0, ios_base::beg); // rewind to the beginning + + for(;;) { + string line; + getline(in, line); + if (!in.good()) break; + data.push_back(line); + } + } + } + + if (!found) { + data.push_back(_("ERROR: LyX wasn't able to read CREDITS file")); + data.push_back(_("Please install correctly to estimate the great")); + data.push_back(_("amount of work other people have done for the LyX project.")); + } + + return data; +} diff --git a/src/frontends/controllers/ControlCredits.h b/src/frontends/controllers/ControlCredits.h new file mode 100644 index 0000000000..193d3b0aa4 --- /dev/null +++ b/src/frontends/controllers/ControlCredits.h @@ -0,0 +1,37 @@ +/** + * \file ControlCredits.h + * Copyright 2001 The LyX Team. + * See the file COPYING. + * + * \author Edwin Leuven, leuven@fee.uva.nl + * \author Angus Leeming + */ + +#ifndef CONTROLCREDITS_H +#define CONTROLCREDITS_H + +#include + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "ControlDialogs.h" + +/** A controller for the Credits dialogs. + */ +class ControlCredits : public ControlDialog { +public: + /// + ControlCredits(LyXView &, Dialogs &); + + /// + std::vector const getCredits() const; + +private: + /// not needed. + virtual void apply() {} +}; + +#endif // CONTROLCREDITS_H + diff --git a/src/frontends/controllers/ControlDialogs.h b/src/frontends/controllers/ControlDialogs.h new file mode 100644 index 0000000000..4026d20daa --- /dev/null +++ b/src/frontends/controllers/ControlDialogs.h @@ -0,0 +1,193 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 2001 The LyX Team. + * + * ====================================================== + * + * \file ControlDialogs.h + * \author Angus Leeming + * + * ControlDialogs.h contains the definition of two template controller classes, + * ControlDialog and ControlInset, rather clumsy names for classes that + * control the showing, updating and hiding of popups. + * + * ControlInset is to be used as a parent class for popups that display and + * can perhaps modify the contents of an individual inset. An example being the + * ubiquitous Citation popup. + * + * ControlDialog is to be used as a parent class for popups that are not + * Inset-popups. (An ugly description I know, but I hope the meaning is clear! + * Can anyone do any better?) Examples would be the Document and Paragraph + * popups. + * + * At the moment, ControlDialog is reaching a state of maturity as several + * controllers are now derived from it and its required functionality + * becaomes clear. + * + * ControlInset is still in a state of flux as currently only InsetCommand-type + * insets have a controller. + * + */ + +#ifndef CONTROLCONNECTIONS2_H +#define CONTROLCONNECTIONS2_H + +#include "ControlConnections.h" +#include "LyXView.h" + +/** Base class to control connection/disconnection of signals with the LyX + kernel for dialogs NOT used with insets. + The Base class will be either ControlConnectBI or ControlConnectBD. + */ +template +class ControlDialog : public Base +{ +public: + /// + ControlDialog(LyXView &, Dialogs &); + +protected: + /// Show the dialog. + virtual void show(); + /// Hide the dialog. + virtual void hide(); + /// Update the dialog. + virtual void update(); + + /// set the params before show or update + virtual void setParams() {} + /// clean-up on hide. + virtual void clearParams() {} +}; + + +/** Base class to control connection/disconnection of signals with the LyX + kernel for Inset dialogs. + */ +class Inset; + +template +class ControlInset : public ControlConnectBD +{ +public: + /// + ControlInset(LyXView &, Dialogs &); + +protected: + /// Slot connected to update signal. + virtual void updateSlot(bool); + /// Connect signals + void connectInset(Inset * = 0); + /// Disconnect signals + virtual void disconnect(); + /// + void disconnectInset(); + +protected: + /// pointer to the inset passed through connectInset + Inset * inset_; + +private: + /// inset::hide connection. + SigC::Connection ih_; +}; + + + + + +template +ControlDialog::ControlDialog(LyXView & lv, Dialogs & d) + : Base(lv, d) +{} + + +template +void ControlDialog::show() +{ + if (isBufferDependent() && !lv_.view()->available()) + return; + + setParams(); + + bc().readOnly(isReadonly()); + view().show(); +} + +template +void ControlDialog::update() +{ + if (isBufferDependent() && !lv_.view()->available()) + return; + + setParams(); + + bc().readOnly(isReadonly()); + view().update(); +} + +template +void ControlDialog::hide() +{ + clearParams(); + + disconnect(); + view().hide(); +} + + +template +ControlInset::ControlInset(LyXView & lv, Dialogs & d) + : ControlConnectBD(lv, d), + inset_(0), ih_(0) +{} + + +template +void ControlInset::updateSlot(bool switched) +{ + if (switched) + hide(); + else + update(); +} + + +template +void ControlInset::disconnect() +{ + inset_ = 0; + ih_.disconnect(); + ControlConnectBD::disconnect(); +} + + +template +void ControlInset::connectInset(Inset * inset) +{ + // If connected to another inset, disconnect from it. + if (inset_) { + ih_.disconnect(); + inset_ = 0; + } + + if (inset) { + inset_ = inset; + ih_ = inset->hideDialog.connect( + SigC::slot(this, &ControlInset::hide)); + } + connect(); +} + + +template +void ControlInset::disconnectInset() +{ + ih_.disconnect(); +} + + +#endif // CONTROLCONNECTIONS2_H diff --git a/src/frontends/controllers/ControlLog.C b/src/frontends/controllers/ControlLog.C index 5e0a7a41e8..40fee20f9b 100644 --- a/src/frontends/controllers/ControlLog.C +++ b/src/frontends/controllers/ControlLog.C @@ -22,43 +22,22 @@ #include "Dialogs.h" #include "lyxrc.h" -using std::make_pair; using SigC::slot; ControlLog::ControlLog(LyXView & lv, Dialogs & d) - : ControlConnectBD(lv, d) + : ControlDialog(lv, d) { d_.showLogFile.connect(slot(this, &ControlLog::show)); } -void ControlLog::show() +void ControlLog::setParams() { - if (!lv_.view()->available()) - return; - - logfile_ = lv_.view()->buffer()->getLogName(); - - bc().readOnly(isReadonly()); - view().show(); -} - - -void ControlLog::update() -{ - if (!lv_.view()->available()) - return; - logfile_ = lv_.view()->buffer()->getLogName(); - - bc().readOnly(isReadonly()); - view().update(); } -void ControlLog::hide() +void ControlLog::clearParams() { logfile_.second.erase(); - disconnect(); - view().hide(); } diff --git a/src/frontends/controllers/ControlLog.h b/src/frontends/controllers/ControlLog.h index 63d66e6540..22f0270740 100644 --- a/src/frontends/controllers/ControlLog.h +++ b/src/frontends/controllers/ControlLog.h @@ -22,13 +22,13 @@ #pragma interface #endif -#include "ControlConnections.h" +#include "ControlDialogs.h" #include "buffer.h" // Buffer::LogType /** * A controller for a read-only text browser. */ -class ControlLog : public ControlConnectBD { +class ControlLog : public ControlDialog { public: /// ControlLog(LyXView &, Dialogs &); @@ -39,42 +39,13 @@ public: protected: /// virtual void apply() {} - /// Show the dialog. - virtual void show(); - /// Update the dialog. - virtual void update(); - /// Hide the dialog. - virtual void hide(); + /// set the params before show or update + virtual void setParams(); + /// clean-up on hide. + virtual void clearParams(); private: std::pair logfile_; }; - -/** A class to instantiate and make available the GUI-specific - ButtonController and View. - */ -template -class GUILog : public ControlLog { -public: - /// - GUILog(LyXView &, Dialogs &); - /// - virtual ButtonControllerBase & bc() { return bc_; } - /// - virtual ViewBase & view() { return view_; } - -private: - /// - ButtonController bc_; - /// - GUIview view_; -}; - -template -GUILog::GUILog(LyXView & lv, Dialogs & d) - : ControlLog(lv, d), - view_(*this) -{} - #endif // CONTROLLOG_H diff --git a/src/frontends/controllers/ControlVCLog.C b/src/frontends/controllers/ControlVCLog.C index f6d357abd0..791f83b1f0 100644 --- a/src/frontends/controllers/ControlVCLog.C +++ b/src/frontends/controllers/ControlVCLog.C @@ -26,41 +26,19 @@ using SigC::slot; ControlVCLog::ControlVCLog(LyXView & lv, Dialogs & d) - : ControlConnectBD(lv, d) + : ControlDialog(lv, d) { d_.showVCLogFile.connect(slot(this, &ControlVCLog::show)); } -void ControlVCLog::show() +void ControlVCLog::setParams() { - if (!lv_.view()->available()) - return; - logfile_ = lv_.view()->buffer()->lyxvc.getLogFile(); - - bc().readOnly(isReadonly()); - view().show(); -} - - -void ControlVCLog::update() -{ - if (!lv_.view()->available()) - return; - - logfile_ = lv_.view()->buffer()->lyxvc.getLogFile(); - - bc().readOnly(isReadonly()); - view().update(); - - lyx::unlink(logfile_); } -void ControlVCLog::hide() +void ControlVCLog::clearParams() { logfile_.erase(); - disconnect(); - view().hide(); } diff --git a/src/frontends/controllers/ControlVCLog.h b/src/frontends/controllers/ControlVCLog.h index 6da6c7b96d..9644225dc5 100644 --- a/src/frontends/controllers/ControlVCLog.h +++ b/src/frontends/controllers/ControlVCLog.h @@ -22,12 +22,12 @@ #pragma interface #endif -#include "ControlConnections.h" +#include "ControlDialogs.h" /** * A controller for the Version Control log viewer. */ -class ControlVCLog : public ControlConnectBD { +class ControlVCLog : public ControlDialog { public: /// ControlVCLog(LyXView &, Dialogs &); @@ -37,42 +37,13 @@ public: protected: /// virtual void apply() {} - /// Show the dialog. - virtual void show(); - /// Update the dialog. - virtual void update(); - /// Hide the dialog. - virtual void hide(); + /// set the params before show or update + virtual void setParams(); + /// clean-up on hide. + virtual void clearParams(); private: string logfile_; }; - -/** A class to instantiate and make available the GUI-specific - ButtonController and View. - */ -template -class GUIVCLog : public ControlVCLog { -public: - /// - GUIVCLog(LyXView &, Dialogs &); - /// - virtual ButtonControllerBase & bc() { return bc_; } - /// - virtual ViewBase & view() { return view_; } - -private: - /// - ButtonController bc_; - /// - GUIview view_; -}; - -template -GUIVCLog::GUIVCLog(LyXView & lv, Dialogs & d) - : ControlVCLog(lv, d), - view_(*this) -{} - #endif // CONTROLVCLOG_H diff --git a/src/frontends/controllers/GUI.h b/src/frontends/controllers/GUI.h new file mode 100644 index 0000000000..8d934df7c7 --- /dev/null +++ b/src/frontends/controllers/GUI.h @@ -0,0 +1,139 @@ +/** + * \file GUI.h + * Copyright 2001 The LyX Team. + * See the file COPYING. + * + * \author Angus Leeming + */ + +#ifndef GUI_H +#define GUI_H + +/** This class instantiates and makes available the GUI-specific + ButtonController and View. + */ +template +class GUI : public Controller { +public: + /// + GUI(LyXView & lv, Dialogs & d) : Controller(lv, d), view_(*this) {} + /// + virtual ButtonControllerBase & bc() { return bc_; } + /// + virtual ViewBase & view() { return view_; } + +private: + /// + ButtonController bc_; + /// + GUIview view_; +}; + +/// Forward declaration of ButtonPolicies +class OkCancelPolicy; +class OkCancelReadOnlyPolicy; +class NoRepeatedApplyReadOnlyPolicy; + + +/** Specialization for Bibitem dialog + */ +class ControlBibitem; + +template +class GUIBibitem : + public GUI { +public: + /// + GUIBibitem(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + + +/** Specialization for Bibtex dialog + */ +class ControlBibtex; + +template +class GUIBibtex : + public GUI { +public: + /// + GUIBibtex(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + + +/** Specialization for Character dialog + */ +class ControlCharacter; + +template +class GUICharacter : public GUI +{ +public: + /// + GUICharacter(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + + +/** Specialization for Citation dialog + */ +class ControlCitation; + +template +class GUICitation : public GUI +{ +public: + /// + GUICitation(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + + +/** Specialization for Credits dialog + */ +class ControlCredits; + +template +class GUICredits : + public GUI { +public: + /// + GUICredits(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + + +/** Specialization for Log dialog + */ +class ControlLog; + +template +class GUILog : + public GUI { +public: + /// + GUILog(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + + +/** Specialization for VCLog dialog + */ +class ControlVCLog; + +template +class GUIVCLog : + public GUI { +public: + /// + GUIVCLog(LyXView & lv, Dialogs & d) + : GUI(lv, d) {} +}; + +#endif // GUI_H diff --git a/src/frontends/controllers/Makefile.am b/src/frontends/controllers/Makefile.am index bda959c5f7..704b535f4a 100644 --- a/src/frontends/controllers/Makefile.am +++ b/src/frontends/controllers/Makefile.am @@ -28,10 +28,15 @@ libcontrollers_la_SOURCES=\ ControlCommand.h \ ControlConnections.C \ ControlConnections.h \ + ControlCopyright.C \ + ControlCredits.h \ + ControlCredits.C \ + ControlCopyright.h \ ControlLog.C \ ControlLog.h \ ControlVCLog.C \ ControlVCLog.h \ + GUI.h \ ViewBase.h \ helper_funcs.C \ helper_funcs.h diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index f01740649d..8890cc9f71 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,17 @@ +2001-03-22 Angus Leeming + + * FormCopyright.[Ch]: + * forms/form_copyright.fd: implemented controller-view split. + + * FormCredits.[Ch]: + * forms/form_credits.fd: implemented controller-view split. + + * Dialogs.C: associated changes. + + * xforms_helpers.C (formatted): improved the function so that it now + repects '\n' characters in the input string. Ie, the user can now + specify line breaks explicitly. + 2001-03-21 Angus Leeming * FormCharacter.[Ch]: @@ -35,13 +49,6 @@ * Dialogs.C: associated changes. -2001-03-19 Angus Leeming - - * FormBibtex.[Ch]: - * forms/form_bibtex.fd: implemented controller-view split. - - * Dialogs.C: associated changes. - 2001-03-19 Angus Leeming * FormBaseDeprecated.[Ch]: rename title as title_. diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index 23dd91174f..a9461eb573 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -4,7 +4,7 @@ * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX Team. + * Copyright 1995-2001 The LyX Team. * * ====================================================== */ @@ -23,25 +23,31 @@ #include "ControlBibtex.h" #include "ControlCharacter.h" #include "ControlCitation.h" +#include "ControlCopyright.h" +#include "ControlCredits.h" #include "ControlLog.h" #include "ControlVCLog.h" -#include "combox.h" // needed for clean destructtion of boost::scoped ptr +#include "GUI.h" + +#include "combox.h" // needed for clean destruction of boost::scoped_ptr #include "form_bibitem.h" #include "form_bibtex.h" #include "form_browser.h" #include "form_character.h" #include "form_citation.h" +#include "form_copyright.h" +#include "form_credits.h" #include "FormBibitem.h" #include "FormBibtex.h" #include "FormCharacter.h" #include "FormCitation.h" +#include "FormCopyright.h" +#include "FormCredits.h" #include "FormLog.h" #include "FormVCLog.h" -#include "FormCopyright.h" -#include "FormCredits.h" #include "FormDocument.h" #include "FormError.h" #include "FormExternal.h" @@ -74,11 +80,11 @@ Dialogs::Dialogs(LyXView * lv) add(new GUIBibtex(*lv, *this)); add(new GUICharacter(*lv, *this)); add(new GUICitation(*lv, *this)); + add(new GUICopyright(*lv, *this)); + add(new GUICredits(*lv, *this)); add(new GUILog(*lv, *this)); add(new GUIVCLog(*lv, *this)); - add(new FormCopyright(lv, this)); - add(new FormCredits(lv, this)); add(new FormDocument(lv, this)); add(new FormError(lv, this)); add(new FormExternal(lv, this)); diff --git a/src/frontends/xforms/FormCharacter.C b/src/frontends/xforms/FormCharacter.C index 2277964076..fbd953b655 100644 --- a/src/frontends/xforms/FormCharacter.C +++ b/src/frontends/xforms/FormCharacter.C @@ -81,12 +81,13 @@ void FormCharacter::build() fl_addto_choice(dialog_->choice_color, choice.c_str()); // xforms appears to need this to prevent a crash... - // fl_addto_choice(dialog_->choice_language, - // _(" English %l| German | French ")); + fl_addto_choice(dialog_->choice_language, "prevent crash"); // insert default language box manually fl_addto_form(dialog_->form); FL_OBJECT * ob = dialog_->choice_language; + fl_deactivate_object(dialog_->choice_language); + combo_language2_.reset(new Combox(FL_COMBOX_DROPLIST)); combo_language2_->add(ob->x, ob->y, ob->w, ob->h, 250); combo_language2_->shortcut("#L", 1); diff --git a/src/frontends/xforms/FormCharacter.h b/src/frontends/xforms/FormCharacter.h index 03ddeaffbe..493b12ff51 100644 --- a/src/frontends/xforms/FormCharacter.h +++ b/src/frontends/xforms/FormCharacter.h @@ -1,4 +1,3 @@ -// -*- C++ -*- /** * \file FormCharacter.h * Copyright 2001 The LyX Team. diff --git a/src/frontends/xforms/FormCopyright.C b/src/frontends/xforms/FormCopyright.C index fb182f7231..1a42f0d6f1 100644 --- a/src/frontends/xforms/FormCopyright.C +++ b/src/frontends/xforms/FormCopyright.C @@ -1,57 +1,48 @@ -/* FormCopyright.C - * FormCopyright Interface Class Implementation +/* + * \file FormCopyright.C + * Copyright 2000-2001 The LyX Team. + * See the file COPYING. + * + * \author Allan Rae + * \author Angus Leeming, a.leeming@.ac.uk */ -#include - -#include FORMS_H_LOCATION - #ifdef __GNUG__ #pragma implementation #endif -#include "Dialogs.h" -#include "LyXView.h" -#include "form_copyright.h" +#include + +#include "xformsBC.h" +#include "ControlCopyright.h" #include "FormCopyright.h" +#include "form_copyright.h" #include "xforms_helpers.h" -using SigC::slot; - -FormCopyright::FormCopyright( LyXView * lv, Dialogs * d ) - : FormBaseBI(lv, d, _("Copyright and Warranty")) -{ - // let the dialog be shown - // This is a permanent connection so we won't bother - // storing a copy because we won't be disconnecting. - d->showCopyright.connect(slot(this, &FormCopyright::show)); -} +typedef FormCB > base_class; - -FL_FORM * FormCopyright::form() const -{ - if (dialog_.get()) return dialog_->form; - return 0; -} +FormCopyright::FormCopyright(ControlCopyright & c) + : base_class(c, _("Copyright and Warranty")) +{} void FormCopyright::build() { dialog_.reset(build_copyright()); - string str = _("LyX is Copyright (C) 1995 by Matthias Ettrich, 1995-2001 LyX Team"); - str = formatted(str, dialog_->text_copyright->w-10, - FL_NORMAL_SIZE, FL_NORMAL_STYLE); + string str = formatted(controller().getCopyright(), + dialog_->text_copyright->w-10); + fl_set_object_label(dialog_->text_copyright, str.c_str()); - str = _("This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version."); - str = formatted(str, dialog_->text_licence->w-10, - FL_NORMAL_SIZE, FL_NORMAL_STYLE); + str = formatted(controller().getLicence(), + dialog_->text_licence->w-10); + fl_set_object_label(dialog_->text_licence, str.c_str()); - str = _("LyX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA."); - str = formatted(str, dialog_->text_disclaimer->w-10, - FL_NORMAL_SIZE, FL_NORMAL_STYLE); + str = formatted(controller().getDisclaimer(), + dialog_->text_disclaimer->w-10); + fl_set_object_label(dialog_->text_disclaimer, str.c_str()); // Manage the cancel/close button diff --git a/src/frontends/xforms/FormCopyright.h b/src/frontends/xforms/FormCopyright.h index edd124628a..a11c95725d 100644 --- a/src/frontends/xforms/FormCopyright.h +++ b/src/frontends/xforms/FormCopyright.h @@ -1,59 +1,51 @@ -// -*- C++ -*- -/* FormCopyright.h - * FormCopyright Interface Class +/** + * \file FormCopyright.h * This file is part of * ====================================================== * * LyX, The Document Processor * * Copyright 1995 Matthias Ettrich - * Copyright 1995-2000 The LyX Team. + * Copyright 1995-2001 The LyX Team. * - * This file Copyright 2000 + * This file Copyright 2000-2001 * Allan Rae * ====================================================== + * + * \author Allan Rae + * \author Angus Leeming, a.leeming@.ac.uk */ #ifndef FORMCOPYRIGHT_H #define FORMCOPYRIGHT_H -#include - #ifdef __GNUG__ #pragma interface #endif -#include "FormBaseDeprecated.h" +#include "FormBase.h" +class ControlCopyright; struct FD_form_copyright; /** This class provides an XForms implementation of the FormCopyright Dialog. */ -class FormCopyright : public FormBaseBI { +class FormCopyright + : public FormCB > { public: - /// #FormCopyright x(LyXFunc ..., Dialogs ...);# - FormCopyright(LyXView *, Dialogs *); + /// + FormCopyright(ControlCopyright &); + private: - /// Pointer to the actual instantiation of the ButtonController. - virtual xformsBC & bc(); + /// not needed. + virtual void apply() {} + /// not needed. + virtual void update() {} /// Build the dialog virtual void build(); - /// Pointer to the actual instantiation of the xforms form - virtual FL_FORM * form() const; + /// Fdesign generated method FD_form_copyright * build_copyright(); - - /// Real GUI implementation. - boost::scoped_ptr dialog_; - /// The ButtonController - ButtonController bc_; }; - -inline -xformsBC & FormCopyright::bc() -{ - return bc_; -} -#endif - +#endif // FORMCOPYRIGHT_H diff --git a/src/frontends/xforms/FormCredits.C b/src/frontends/xforms/FormCredits.C index 09251155a7..0a0aed3c00 100644 --- a/src/frontends/xforms/FormCredits.C +++ b/src/frontends/xforms/FormCredits.C @@ -4,69 +4,43 @@ * See the file COPYING. * * \author Edwin Leuven, leuven@fee.uva.nl + * \author Angus Leeming, a.leeming@.ac.uk */ -#include - -#include FORMS_H_LOCATION - #ifdef __GNUG__ #pragma implementation #endif -#include "Dialogs.h" -#include "LyXView.h" -#include "form_credits.h" +#include + +#include "xformsBC.h" +#include "ControlCredits.h" #include "FormCredits.h" +#include "form_credits.h" #include "xforms_helpers.h" -#include "support/filetools.h" -using SigC::slot; +using std::vector; -FormCredits::FormCredits( LyXView * lv, Dialogs * d ) - : FormBaseBI(lv, d, _("Credits")) -{ - // let the dialog be shown - // This is a permanent connection so we won't bother - // storing a copy because we won't be disconnecting. - d->showCredits.connect(slot(this, &FormCredits::show)); -} +typedef FormCB > base_class; +FormCredits::FormCredits(ControlCredits & c) + : base_class(c, _("Credits")) +{} -FL_FORM * FormCredits::form() const -{ - if (dialog_.get()) - return dialog_->form; - return 0; -} - -// needed for the browser -extern string system_lyxdir; void FormCredits::build() { - dialog_.reset(build_credits()); + dialog_.reset(build_credits()); + + // Manage the cancel/close button + bc().setCancel(dialog_->button_cancel); + bc().refresh(); + + vector data = controller().getCredits(); - // Manage the cancel/close button - bc_.setCancel(dialog_->button_cancel); - bc_.refresh(); - - /* read the credits into the browser */ - - /* try file LYX_DIR/CREDITS */ - string real_file = AddName (system_lyxdir, "CREDITS"); - - if (!fl_load_browser(dialog_->browser_credits, - real_file.c_str())) { - fl_add_browser_line(dialog_->browser_credits, - _("ERROR: LyX wasn't able to read" - " CREDITS file")); - fl_add_browser_line(dialog_->browser_credits, ""); - fl_add_browser_line(dialog_->browser_credits, - _("Please install correctly to estimate" - " the great")); - fl_add_browser_line(dialog_->browser_credits, - _("amount of work other people have done" - " for the LyX project.")); - } + /* read the credits into the browser */ + for (vector::const_iterator it = data.begin(); + it < data.end(); ++it) { + fl_add_browser_line(dialog_->browser_credits, it->c_str()); + } } diff --git a/src/frontends/xforms/FormCredits.h b/src/frontends/xforms/FormCredits.h index 50adc74124..712c815023 100644 --- a/src/frontends/xforms/FormCredits.h +++ b/src/frontends/xforms/FormCredits.h @@ -4,49 +4,39 @@ * See the file COPYING. * * \author Edwin Leuven, leuven@fee.uva.nl + * \author Angus Leeming, a.leeming@.ac.uk */ #ifndef FORMCREDITS_H #define FORMCREDITS_H -#include - #ifdef __GNUG__ #pragma interface #endif -#include "FormBaseDeprecated.h" +#include "FormBase.h" +class ControlCredits; struct FD_form_credits; /** This class provides an XForms implementation of the FormCredits Dialog. */ -class FormCredits : public FormBaseBI { +class FormCredits : public FormCB > { public: - /// #FormCopyright x(LyXFunc ..., Dialogs ...);# - FormCredits(LyXView *, Dialogs *); + /// + FormCredits(ControlCredits &); private: - /// Pointer to the actual instantiation of the ButtonController. - virtual xformsBC & bc(); + /// not needed. + virtual void apply() {} + /// not needed. + virtual void update() {} /// Build the dialog virtual void build(); - /// Pointer to the actual instantiation of the xforms form - virtual FL_FORM * form() const; + /// Fdesign generated method FD_form_credits * build_credits(); - - /// Real GUI implementation. - boost::scoped_ptr dialog_; - /// The ButtonController - ButtonController bc_; }; - -inline -xformsBC & FormCredits::bc() -{ - return bc_; -} #endif diff --git a/src/frontends/xforms/form_copyright.C b/src/frontends/xforms/form_copyright.C index 371744a8ec..3d9425c06e 100644 --- a/src/frontends/xforms/form_copyright.C +++ b/src/frontends/xforms/form_copyright.C @@ -45,7 +45,7 @@ FD_form_copyright * FormCopyright::build_copyright() fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_gravity(obj, FL_South, FL_South); fl_set_object_resize(obj, FL_RESIZE_NONE); - fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 0); + fl_set_object_callback(obj, C_FormBaseCancelCB, 0); fl_end_form(); fdui->form->fdui = fdui; diff --git a/src/frontends/xforms/form_copyright.h b/src/frontends/xforms/form_copyright.h index f98680d5f9..ee94cb3cd6 100644 --- a/src/frontends/xforms/form_copyright.h +++ b/src/frontends/xforms/form_copyright.h @@ -5,7 +5,7 @@ #define FD_form_copyright_h_ /** Callbacks, globals and object handlers **/ -extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long); +extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long); /**** Forms and Objects ****/ diff --git a/src/frontends/xforms/form_credits.C b/src/frontends/xforms/form_credits.C index d6e86320a1..7a36aad285 100644 --- a/src/frontends/xforms/form_credits.C +++ b/src/frontends/xforms/form_credits.C @@ -29,7 +29,7 @@ FD_form_credits * FormCredits::build_credits() fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_gravity(obj, FL_South, FL_South); fl_set_object_resize(obj, FL_RESIZE_NONE); - fl_set_object_callback(obj, C_FormBaseDeprecatedCancelCB, 0); + fl_set_object_callback(obj, C_FormBaseCancelCB, 0); obj = fl_add_text(FL_NORMAL_TEXT, 10, 40, 480, 30, _("Matthias")); fl_set_object_lsize(obj, FL_NORMAL_SIZE); fl_set_object_lalign(obj, FL_ALIGN_CENTER|FL_ALIGN_INSIDE); diff --git a/src/frontends/xforms/form_credits.h b/src/frontends/xforms/form_credits.h index a77b214469..ef9791d423 100644 --- a/src/frontends/xforms/form_credits.h +++ b/src/frontends/xforms/form_credits.h @@ -5,7 +5,7 @@ #define FD_form_credits_h_ /** Callbacks, globals and object handlers **/ -extern "C" void C_FormBaseDeprecatedCancelCB(FL_OBJECT *, long); +extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long); /**** Forms and Objects ****/ diff --git a/src/frontends/xforms/forms/form_copyright.fd b/src/frontends/xforms/forms/form_copyright.fd index 1c4297503c..cc16d01bd3 100644 --- a/src/frontends/xforms/forms/form_copyright.fd +++ b/src/frontends/xforms/forms/form_copyright.fd @@ -99,7 +99,7 @@ shortcut: resize: FL_RESIZE_NONE gravity: FL_South FL_South name: button_cancel -callback: C_FormBaseDeprecatedCancelCB +callback: C_FormBaseCancelCB argument: 0 ============================== diff --git a/src/frontends/xforms/forms/form_credits.fd b/src/frontends/xforms/forms/form_credits.fd index 6f489eecc3..56bce85c7d 100644 --- a/src/frontends/xforms/forms/form_credits.fd +++ b/src/frontends/xforms/forms/form_credits.fd @@ -45,7 +45,7 @@ shortcut: ^M resize: FL_RESIZE_NONE gravity: FL_South FL_South name: button_cancel -callback: C_FormBaseDeprecatedCancelCB +callback: C_FormBaseCancelCB argument: 0 -------------------- diff --git a/src/frontends/xforms/xforms_helpers.C b/src/frontends/xforms/xforms_helpers.C index 77b9b3ee7b..f8601b7517 100644 --- a/src/frontends/xforms/xforms_helpers.C +++ b/src/frontends/xforms/xforms_helpers.C @@ -51,34 +51,50 @@ string formatted(string const & sin, int w, int size, int style) if ((*sit) == ' ' || (*sit) == '\n') { sentence.push_back(word); word.erase(); + if ((*sit) == '\n') word += '\n'; + } else { word += (*sit); } } + // Flush remaining contents of word if (!word.empty() ) sentence.push_back(word); - string line, l1; + string line, line_plus_word; for (vector::const_iterator vit = sentence.begin(); vit != sentence.end(); ++vit) { - if (!l1.empty() ) l1 += ' '; - l1 += (*vit); - int length = fl_get_string_width(style, size, l1.c_str(), - int(l1.length())); + string word = *vit; + + char c = word[0]; + if (c == '\n') { + sout += line + '\n'; + word = word.substr(1); + line_plus_word.erase(); + line.erase(); + } + + if (!line_plus_word.empty() ) line_plus_word += ' '; + line_plus_word += word; + + int length = fl_get_string_width(style, size, + line_plus_word.c_str(), + int(line_plus_word.length())); if (length >= w) { - if (!sout.empty() ) sout += '\n'; - sout += line; - l1 = (*vit); + sout += line + '\n'; + line_plus_word = word; } - line = l1; + line = line_plus_word; } // Flush remaining contents of line if (!line.empty()) { - if (!sout.empty() ) sout += '\n'; sout += line; } - + + if (sout[sout.length()-1] == '\n') + sout.erase(sout.length()-1); + return sout; }