From bed3713ff0e1c9c28c64bc802ffc8c7011fab164 Mon Sep 17 00:00:00 2001 From: Baruch Even Date: Wed, 28 Mar 2001 11:14:05 +0000 Subject: [PATCH] Fixed compilation problems. Added infrastructure for MVC dialogs and implemented FormUrl as an MVC dialog. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1841 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gnome/ChangeLog | 23 ++ src/frontends/gnome/Dialogs.C | 119 +++++-- src/frontends/gnome/FormCitation.h | 6 +- src/frontends/gnome/FormCopyright.h | 4 +- src/frontends/gnome/FormError.h | 6 +- src/frontends/gnome/FormIndex.h | 6 +- src/frontends/gnome/FormToc.h | 4 + src/frontends/gnome/FormUrl.C | 324 ++++++++---------- src/frontends/gnome/FormUrl.h | 137 ++++---- src/frontends/gnome/GUIRunTime.C | 2 + src/frontends/gnome/GnomeBase.C | 46 +++ src/frontends/gnome/GnomeBase.h | 101 ++++++ src/frontends/gnome/Makefile.am | 140 ++++---- src/frontends/gnome/Menubar_pimpl.C | 3 + src/frontends/gnome/Timeout_pimpl.C | 56 +++ src/frontends/gnome/Timeout_pimpl.h | 47 +++ .../gnome/dialogs/diainserturl.glade | 42 ++- src/frontends/gnome/gnomeBC.C | 54 +++ src/frontends/gnome/gnomeBC.h | 81 +++++ src/frontends/gnome/gnome_helpers.h | 36 ++ 20 files changed, 850 insertions(+), 387 deletions(-) create mode 100644 src/frontends/gnome/GnomeBase.C create mode 100644 src/frontends/gnome/GnomeBase.h create mode 100644 src/frontends/gnome/Timeout_pimpl.C create mode 100644 src/frontends/gnome/Timeout_pimpl.h create mode 100644 src/frontends/gnome/gnomeBC.C create mode 100644 src/frontends/gnome/gnomeBC.h create mode 100644 src/frontends/gnome/gnome_helpers.h diff --git a/src/frontends/gnome/ChangeLog b/src/frontends/gnome/ChangeLog index 2748fdedb4..450d5ca8d2 100644 --- a/src/frontends/gnome/ChangeLog +++ b/src/frontends/gnome/ChangeLog @@ -1,3 +1,26 @@ +2001-03-26 Baruch Even + + * Various files: Fixes to get the gnome frontend to compile again. + Removed most xforms dialogs in order to reduce compilation breaks caused + by the moves to MVC in the xforms frontend. + + * GUIRuntime.C: Added libglade library initialization. + + * gnomeBC.h: + * gnomeBC.C: Added file for the MVC support. + + * gnome_helpers.h: Added file with support functions. + + * GnomeBase.h: + * GnomeBase.C: Added file to be the base class of MVC dialogs that use + libglade. + + * FormUrl.h: + * FormUrl.C: Recreated the dialog in the MVC way. + + * Timeout_pimpl.h: + * Timeout_pimpl.C: Implementation of the Timeout pimpl. + 2001-03-15 Lars Gullik Bjønnes * several files: remove CXX_WORKING_NAMESPACES diff --git a/src/frontends/gnome/Dialogs.C b/src/frontends/gnome/Dialogs.C index 7247dcb39c..210f26804d 100644 --- a/src/frontends/gnome/Dialogs.C +++ b/src/frontends/gnome/Dialogs.C @@ -1,66 +1,117 @@ +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995-2001 The LyX Team. + * + * ====================================================== + */ + #include -#include FORMS_H_LOCATION + +#ifdef __GNUG__ +#pragma implementation +#endif #include "Dialogs.h" + +#include "gnomeBC.h" + +#include "ControlBibitem.h" +#include "ControlBibtex.h" +#include "ControlCharacter.h" +#include "ControlCitation.h" +#include "ControlCopyright.h" +#include "ControlCredits.h" +#include "ControlInclude.h" +#include "ControlLog.h" +#include "ControlUrl.h" +#include "ControlVCLog.h" + +#include "GUI.h" + +#include "FormUrl.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 "FormDocument.h" #include "FormError.h" +#include "FormExternal.h" #include "FormGraphics.h" +#include "FormInclude.h" #include "FormIndex.h" +#include "FormMathsPanel.h" #include "FormParagraph.h" +#include "FormPreamble.h" #include "FormPreferences.h" #include "FormPrint.h" #include "FormRef.h" +#include "FormSearch.h" #include "FormSplash.h" #include "FormTabular.h" +#include "FormTabularCreate.h" #include "FormToc.h" #include "FormUrl.h" - -#ifdef __GNUG__ -#pragma implementation -#endif - -// temporary till ported -extern void ShowCredits(); +#include "FormMinipage.h" +*/ // Signal enabling all visible popups to be redrawn if so desired. // E.g., when the GUI colours have been remapped. -Signal0 Dialogs::redrawGUI; +SigC::Signal0 Dialogs::redrawGUI; Dialogs::Dialogs(LyXView * lv) { - dialogs_.push_back(new FormCitation(lv, this)); - dialogs_.push_back(new FormCopyright(lv, this)); - dialogs_.push_back(new FormDocument(lv, this)); - dialogs_.push_back(new FormError(lv, this)); - dialogs_.push_back(new FormGraphics(lv, this)); - dialogs_.push_back(new FormIndex(lv, this)); - dialogs_.push_back(new FormPreferences(lv, this)); - dialogs_.push_back(new FormParagraph(lv, this)); - dialogs_.push_back(new FormPrint(lv, this)); - dialogs_.push_back(new FormRef(lv, this)); - dialogs_.push_back(new FormSplash(lv, this)); - dialogs_.push_back(new FormTabular(lv, this)); - dialogs_.push_back(new FormToc(lv, this)); - dialogs_.push_back(new FormUrl(lv, this)); + add(new GUIUrl(*lv, *this)); +/* + splash_.reset(new FormSplash(lv, this)); + + add(new GUIBibitem(*lv, *this)); + 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)); + + // For now we use the gnome non MVC dialogs + add(new FormCitation(lv, this)); + add(new FormCopyright(lv, this)); + + add(new FormDocument(lv, this)); + add(new FormError(lv, this)); + add(new FormExternal(lv, this)); + add(new FormGraphics(lv, this)); + add(new FormInclude(lv, this)); + add(new FormIndex(lv, this)); + add(new FormMathsPanel(lv, this)); + add(new FormParagraph(lv, this)); + add(new FormPreamble(lv, this)); + add(new FormPreferences(lv, this)); + add(new FormPrint(lv, this)); + add(new FormRef(lv, this)); + add(new FormSearch(lv, this)); + add(new FormSplash(lv, this)); + add(new FormTabular(lv, this)); + add(new FormTabularCreate(lv, this)); + add(new FormToc(lv, this)); + add(new FormUrl(lv, this)); + add(new FormMinipage(lv, this)); +*/ // reduce the number of connections needed in // dialogs by a simple connection here. hideAll.connect(hideBufferDependent.slot()); } - -Dialogs::~Dialogs() -{ - for (vector::iterator iter = dialogs_.begin(); - iter != dialogs_.end(); - ++iter) { - delete *iter; - } -} - - /***************************************************************************** Q. WHY does Dialogs::Dialogs pass `this' to dialog constructors? diff --git a/src/frontends/gnome/FormCitation.h b/src/frontends/gnome/FormCitation.h index d0b3ce0c70..48b7a8b1ca 100644 --- a/src/frontends/gnome/FormCitation.h +++ b/src/frontends/gnome/FormCitation.h @@ -125,11 +125,11 @@ private: /// the nitty-griity. What is modified and passed back InsetCommandParams params; /// Update connection. - Connection u_; + SigC::Connection u_; /// Hide connection. - Connection h_; + SigC::Connection h_; /// inset::hide connection. - Connection ih_; + SigC::Connection ih_; /// Real GUI implementation. Gtk::Container * dialog_; diff --git a/src/frontends/gnome/FormCopyright.h b/src/frontends/gnome/FormCopyright.h index 961559d9ca..2e5489e21a 100644 --- a/src/frontends/gnome/FormCopyright.h +++ b/src/frontends/gnome/FormCopyright.h @@ -49,9 +49,9 @@ private: */ Dialogs * d_; /// Hide connection. - Connection h_; + SigC::Connection h_; /// Destroy connection. - Connection destroy_; + SigC::Connection destroy_; }; #endif diff --git a/src/frontends/gnome/FormError.h b/src/frontends/gnome/FormError.h index 5a3d9c82cd..ee39e17f64 100644 --- a/src/frontends/gnome/FormError.h +++ b/src/frontends/gnome/FormError.h @@ -58,11 +58,11 @@ private: /// pointer to the inset passed through showInset (if any) InsetError * inset_; /// Update connection. - Connection u_; + SigC::Connection u_; /// Hide connection. - Connection h_; + SigC::Connection h_; /// inset::hide connection. - Connection ih_; + SigC::Connection ih_; /// Real GUI implementation. Gtk::Container * dialog_; diff --git a/src/frontends/gnome/FormIndex.h b/src/frontends/gnome/FormIndex.h index 540ed7377b..28132b648b 100644 --- a/src/frontends/gnome/FormIndex.h +++ b/src/frontends/gnome/FormIndex.h @@ -64,11 +64,11 @@ private: /// the nitty-griity. What is modified and passed back InsetCommandParams params; /// Update connection. - Connection u_; + SigC::Connection u_; /// Hide connection. - Connection h_; + SigC::Connection h_; /// inset::hide connection. - Connection ih_; + SigC::Connection ih_; /// Real GUI implementation. Gtk::Container * dialog_; diff --git a/src/frontends/gnome/FormToc.h b/src/frontends/gnome/FormToc.h index 68f73e678c..b03363a133 100644 --- a/src/frontends/gnome/FormToc.h +++ b/src/frontends/gnome/FormToc.h @@ -1,3 +1,6 @@ +// THIS FILE IS NOT IN USE DUE TO API CHANGES. +#include "frontends/xforms/FormToc.h" +#if 0 // -*- C++ -*- /* This file is part of * ====================================================== @@ -84,3 +87,4 @@ private: }; #endif +#endif diff --git a/src/frontends/gnome/FormUrl.C b/src/frontends/gnome/FormUrl.C index d26e96faa0..0b4ea0fd08 100644 --- a/src/frontends/gnome/FormUrl.C +++ b/src/frontends/gnome/FormUrl.C @@ -1,232 +1,180 @@ // -*- C++ -*- /* This file is part of - * ====================================================== + * ================================================= + * + * LyX, The Document Processor + * Copyright 1995-2000 The LyX Team. * - * LyX, The Document Processor + * ================================================= * - * Copyright 2000 The LyX Team. - * - * ====================================================== + * \author Baruch Even */ -#include - #ifdef __GNUG__ #pragma implementation #endif +#include -#include "gettext.h" -#include "Dialogs.h" +#include "gnomeBC.h" #include "FormUrl.h" -#include "LyXView.h" -#include "buffer.h" -#include "lyxfunc.h" -#include -#include -#include -#include -#include -#include +#include +#include +#include -// temporary solution for LyXView -#include "mainapp.h" -extern GLyxAppWin * mainAppWin; +FormUrl::FormUrl(ControlUrl & c) + : FormCB(c, "diainserturl.glade", "DiaInsertUrl") + , dialog_(0) +{} -namespace { -// configuration keys -string const CONF_ENTRY_URL("FormUrl_url"); -string const CONF_ENTRY_NAME("FormUrl_name"); +FormUrl::~FormUrl() +{ + // Note that there is no need to destroy the class itself, it seems + // like everything is managed inside it. Deleting the class itself will + // a crash at the end of the program. + dialog_->destroy(); +} -} // namespace anon + +void FormUrl::build() +{ + // Make sure the dialog is loaded. + dialog_ = dialog(); + + // Connect the buttons. + ok_btn()->clicked.connect(SigC::slot(this, &FormUrl::OKClicked)); + cancel_btn()->clicked.connect(SigC::slot(this, &FormUrl::CancelClicked)); + apply_btn()->clicked.connect(SigC::slot(this, &FormUrl::ApplyClicked)); + restore_btn()->clicked.connect(SigC::slot(this, &FormUrl::RestoreClicked)); + + // Manage the buttons state + bc().setOK(ok_btn()); + bc().setCancel(cancel_btn()); + bc().setApply(apply_btn()); + bc().setUndoAll(restore_btn()); + + // Make sure everything is in the correct state. + bc().refresh(); + + // Manage the read-only aware widgets. + bc().addReadOnly(html()); + bc().addReadOnly(name()); + bc().addReadOnly(url()); +} -FormUrl::FormUrl(LyXView * lv, Dialogs * d) - : lv_(lv), d_(d), inset_(0), u_(0), h_(0), ih_(0), dialog_(0) +void FormUrl::connect_signals() { - // let the dialog be shown - // These are permanent connections so we won't bother - // storing a copy because we won't be disconnecting. - d->showUrl.connect(slot(this, &FormUrl::showInset)); - d->createUrl.connect(slot(this, &FormUrl::createInset)); + // Get notifications on input change + slot_url_ = url()->changed.connect(SigC::slot(this, &FormUrl::InputChanged)); + slot_name_ = name()->changed.connect(SigC::slot(this, &FormUrl::InputChanged)); + slot_html_ = html()->toggled.connect(SigC::slot(this, &FormUrl::InputChanged)); } -FormUrl::~FormUrl() +void FormUrl::disconnect_signals() { - hide(); + slot_url_.disconnect(); + slot_name_.disconnect(); + slot_html_.disconnect(); } -void FormUrl::showInset( InsetCommand * const inset ) + +void FormUrl::show() { - if( dialog_!=0 || inset == 0 ) return; - - inset_ = inset; - ih_ = inset_->hideDialog.connect(slot(this, &FormUrl::hide)); - - params = inset->params(); - show(); + if (!dialog_) + build(); + + update(); + dialog_->show(); } -void FormUrl::createInset( string const & arg ) +void FormUrl::hide() { - if( dialog_!=0 ) return; - - params.setFromString( arg ); - show(); + dialog_->hide(); } -void FormUrl::show() + +void FormUrl::apply() { - if (!dialog_) - { - using namespace Gtk::Box_Helpers; - - Gtk::Label * label; - Gtk::Table * table = manage( new Gtk::Table(2, 2, FALSE) ); - Gtk::Box * mbox = manage( new Gtk::HBox() ); - Gtk::ButtonBox * bbox = manage( new Gtk::VButtonBox() ); - Gtk::Separator * sep = manage( new Gtk::VSeparator() ); - - url_ = manage( new Gnome::Entry() ); - name_ = manage( new Gnome::Entry() ); - html_type_ = manage( new Gtk::CheckButton(_("HTML type")) ); - - b_ok = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_OK) ) ); - b_cancel = Gtk::wrap( GTK_BUTTON( gnome_stock_button(GNOME_STOCK_BUTTON_CANCEL) ) ); - - // set up spacing - table->set_row_spacings(2); - table->set_col_spacings(2); - mbox->set_spacing(2); - bbox->set_spacing(4); - - // configure entries - url_->set_history_id(CONF_ENTRY_URL); - url_->set_max_saved(10); - url_->load_history(); - url_->set_use_arrows_always(true); - - name_->set_history_id(CONF_ENTRY_NAME); - name_->set_max_saved(10); - name_->load_history(); - name_->set_use_arrows_always(true); - - // pack widgets - bbox->children().push_back(Element(*b_ok, false, false)); - bbox->children().push_back(Element(*b_cancel, false, false)); - - label = manage( new Gtk::Label(_("URL")) ); - table->attach( *label, 0, 1, 0, 1, 0, 0 ); - label = manage( new Gtk::Label(_("Name")) ); - table->attach( *label, 0, 1, 1, 2, 0, 0 ); - table->attach( *url_, 1, 2, 0, 1 ); - table->attach( *name_, 1, 2, 1, 2 ); - - mbox->children().push_back(Element(*table)); - mbox->children().push_back(Element(*html_type_, false, false)); - mbox->children().push_back(Element(*sep, false, false)); - mbox->children().push_back(Element(*bbox, false, false)); - - // packing dialog to main window - dialog_ = mbox; - mainAppWin->add_action(*dialog_, _(" URL ")); - - // setting focus - GTK_WIDGET_SET_FLAGS (GTK_WIDGET(url_->get_entry()->gtkobj()), GTK_CAN_DEFAULT); - gtk_widget_grab_focus (GTK_WIDGET(url_->get_entry()->gtkobj())); - gtk_widget_grab_default (GTK_WIDGET(url_->get_entry()->gtkobj())); - - // connecting signals - b_ok->clicked.connect(slot(this, &FormUrl::apply)); - name_->get_entry()->activate.connect(slot(this, &FormUrl::apply)); - - b_cancel->clicked.connect(slot(mainAppWin, &GLyxAppWin::remove_action)); - - dialog_->destroy.connect(slot(this, &FormUrl::free)); - - u_ = d_->updateBufferDependent.connect(slot(this, &FormUrl::updateSlot)); - h_ = d_->hideBufferDependent.connect(slot(this, &FormUrl::hide)); - - updateSlot(); // make sure its up-to-date - } -} - -void FormUrl::updateSlot(bool switched) -{ - if (switched) - { - hide(); - return; - } - - if (dialog_ != 0 && - lv_->view()->available()) - { - url_->get_entry()->set_text(params.getContents().c_str()); - name_->get_entry()->set_text(params.getOptions().c_str()); - - html_type_->set_active( (params.getCmdName() == "htmlurl") ); - - bool sens = (!(lv_->buffer()->isReadonly())); - - html_type_->set_sensitive(sens); - url_->set_sensitive(sens); - name_->set_sensitive(sens); - b_ok->set_sensitive(sens); - } + controller().params().setContents(url()->get_text()); + controller().params().setOptions(name()->get_text()); + + string cmdname("url"); + if (html()->get_active()) + cmdname = "htmlurl"; + + controller().params().setCmdName(cmdname); } -void FormUrl::hide() + +void FormUrl::update() { - if (dialog_!=0) mainAppWin->remove_action(); + // Disconnect signals so we dont trigger the input changed state. + // This avoids the problem of having the buttons enabled when the dialog + // starts. + disconnect_signals(); + + url()->set_text(controller().params().getContents()); + name()->set_text(controller().params().getOptions()); + + html()->set_active("url" != controller().params().getCmdName()); + + // Reconnect the signals. + connect_signals(); } -void FormUrl::free() + +bool FormUrl::validate() const { - if (dialog_!=0) - { - dialog_ = 0; - u_.disconnect(); - h_.disconnect(); - inset_ = 0; - ih_.disconnect(); - } + // Always valid! (not really so, needs fixing). + return true; } -void FormUrl::apply() + +Gnome::Dialog * FormUrl::dialog() +{ + return getWidget("DiaInsertUrl"); +} + +Gtk::Entry * FormUrl::url() const +{ + return getWidget("url"); +} + +Gtk::Entry * FormUrl::name() const +{ + return getWidget("name"); +} + +Gtk::CheckButton * FormUrl::html() const +{ + return getWidget("html_type"); +} + + +Gtk::Button * FormUrl::ok_btn() const +{ + return getWidget("button_ok"); +} + + +Gtk::Button * FormUrl::cancel_btn() const +{ + return getWidget("button_cancel"); +} + + +Gtk::Button * FormUrl::apply_btn() const +{ + return getWidget("button_apply"); +} + + +Gtk::Button * FormUrl::restore_btn() const { - if( lv_->buffer()->isReadonly() ) return; - - params.setContents( url_->get_entry()->get_text() ); - params.setOptions( name_->get_entry()->get_text() ); - - if (html_type_->get_active()) - params.setCmdName("htmlurl"); - else - params.setCmdName("url"); - - if( inset_ != 0 ) - { - // Only update if contents have changed - if( params != inset_->params() ) { - inset_->setParams( params ); - lv_->view()->updateInset( inset_, true ); - } - } - else - { - lv_->getLyXFunc()->Dispatch( LFUN_INSERT_URL, - params.getAsString() ); - } - - // save history - url_->save_history(); - name_->save_history(); - - // hide the dialog - hide(); + return getWidget("button_restore"); } diff --git a/src/frontends/gnome/FormUrl.h b/src/frontends/gnome/FormUrl.h index 6c8aeb221c..eeca5b50a7 100644 --- a/src/frontends/gnome/FormUrl.h +++ b/src/frontends/gnome/FormUrl.h @@ -1,13 +1,15 @@ // -*- C++ -*- /* This file is part of - * ====================================================== + * ================================================= + * + * LyX, The Document Processor + * Copyright 1995 Matthias Ettrich. + * Copyright 1995-2000 The LyX Team. * - * LyX, The Document Processor + * ================================================= * - * Copyright 2000 The LyX Team. - * - * ====================================================== - */ + * \author Baruch Even + * */ #ifndef FORMURL_H #define FORMURL_H @@ -16,75 +18,78 @@ #pragma interface #endif -#include "DialogBase.h" -#include "LString.h" -#include "insets/insetcommand.h" +#include "ControlUrl.h" +#include "GnomeBase.h" + +//#include +namespace Gnome { +class Dialog; +} -#include -#include -#include -#include +namespace Gtk { +class Button; +class CheckButton; +class Entry; +} -/** This class provides an Gnome implementation of the FormUrl Dialog. +/** + * This class implements the dialog to insert/modify urls. */ -class FormUrl : public DialogBase { +class FormUrl : public FormCB { public: - /**@name Constructors and Destructors */ - //@{ - /// - FormUrl(LyXView *, Dialogs *); - /// - ~FormUrl(); - //@} - + /// + FormUrl(ControlUrl & c); + /// + ~FormUrl(); + + void apply(); + void hide(); + void show(); + void update(); + private: - /// Slot launching dialog to (possibly) create a new inset - void createInset( string const & ); - /// Slot launching dialog to an existing inset - void showInset( InsetCommand * const ); - - /// Update dialog before showing it - virtual void update() { } - virtual void updateSlot(bool = false); - /// Apply from dialog (modify or create inset) - virtual void apply(); - /// Explicitly free the dialog. - void free(); - /// Create the dialog if necessary, update it and display it. - void show(); - /// Hide the dialog. - void hide(); - - /** Which LyXFunc do we use? - We could modify Dialogs to have a visible LyXFunc* instead and - save a couple of bytes per dialog. - */ - LyXView * lv_; - /** Which Dialogs do we belong to? - Used so we can get at the signals we have to connect to. - */ - Dialogs * d_; - /// pointer to the inset passed through showInset (if any) - InsetCommand * inset_; - /// the nitty-griity. What is modified and passed back - InsetCommandParams params; - /// Update connection. - Connection u_; - /// Hide connection. - Connection h_; - /// inset::hide connection. - Connection ih_; + /// Build the dialog + void build(); + + /// Returns true if the dialog input is in a valid state. + bool validate() const; - /// Real GUI implementation. - Gtk::Container * dialog_; + /// Do the connection of signals + void connect_signals(); + /// Disconnect the signals. + void disconnect_signals(); - Gtk::CheckButton * html_type_; + void OKClicked() { OKButton(); } + void CancelClicked() { CancelButton(); } + void ApplyClicked() { ApplyButton(); } + void RestoreClicked() { RestoreButton(); } + void InputChanged() { bc().valid(validate()); } + + /// Get the dialog + Gnome::Dialog * dialog(); + /// The url entry + Gtk::Entry * url() const; + /// The name entry + Gtk::Entry * name() const; + /// The html type checkbutton + Gtk::CheckButton * html() const; + /// The ok button + Gtk::Button * ok_btn() const; + /// The cancel button + Gtk::Button * cancel_btn() const; + /// The apply button + Gtk::Button * apply_btn() const; + /// The restore button + Gtk::Button * restore_btn() const; - Gnome::Entry * url_; - Gnome::Entry * name_; + // Hold the dialog. + //boost::shared_ptr dialog_; + Gnome::Dialog * dialog_; - Gtk::Button * b_ok; - Gtk::Button * b_cancel; + /// Keeps the connection to the input validator. + SigC::Connection slot_url_; + SigC::Connection slot_name_; + SigC::Connection slot_html_; }; #endif diff --git a/src/frontends/gnome/GUIRunTime.C b/src/frontends/gnome/GUIRunTime.C index d87fee67b7..b650a37c0c 100644 --- a/src/frontends/gnome/GUIRunTime.C +++ b/src/frontends/gnome/GUIRunTime.C @@ -20,6 +20,7 @@ #include #include "mainapp.h" +#include using std::endl; @@ -73,6 +74,7 @@ int GUIRunTime::initApplication(int, char * argv[]) static string app_id(PACKAGE); static string app_version(VERSION); static Gnome::Main a(app_id, app_version, 1, argv); + glade_gnome_init(); // Initialize the glade library. static GLyxAppWin appWin; mainAppWin = &appWin; diff --git a/src/frontends/gnome/GnomeBase.C b/src/frontends/gnome/GnomeBase.C new file mode 100644 index 0000000000..631d5f2c50 --- /dev/null +++ b/src/frontends/gnome/GnomeBase.C @@ -0,0 +1,46 @@ +// -*- C++ -*- +/* This file is part of + * ================================================= + * + * LyX, The Document Processor + * Copyright 1995 Matthias Ettrich. + * Copyright 1995-2000 The LyX Team. + * + * ================================================= */ + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include +#include "GnomeBase.h" +#include "support/LAssert.h" +#include "debug.h" +#include "support/filetools.h" +#include + +GnomeBase::GnomeBase(ControlBase & c, string const & glade_file, string const & name) + : ViewBC(c), file_(glade_file), widget_name_(name), xml_(0) +{} + +GnomeBase::~GnomeBase() +{ + gtk_object_unref(GTK_OBJECT(xml_)); +} + + +void GnomeBase::loadXML() const +{ +#warning Change this before declaring it production code! (be 20010325) + string const path("src/frontends/gnome/dialogs/;frontends/gnome/dialogs/;/home/baruch/prog/lyx/graphics/src/frontends/gnome/dialogs/"); + string const file = FileOpenSearch(path, file_, "glade"); + + if (file.empty()) { + lyxerr << "Cannot find glade file. Aborting." << std::endl; + Assert(true); + } + + lyxerr[Debug::GUI] << "Glade file to open is " << file << '\n'; + + xml_ = glade_xml_new(file.c_str(), widget_name_.c_str()); +} diff --git a/src/frontends/gnome/GnomeBase.h b/src/frontends/gnome/GnomeBase.h new file mode 100644 index 0000000000..d982e8b505 --- /dev/null +++ b/src/frontends/gnome/GnomeBase.h @@ -0,0 +1,101 @@ +// -*- C++ -*- +/* This file is part of + * ================================================= + * + * LyX, The Document Processor + * Copyright 1995-2000 The LyX Team. + * + * ================================================= + * + * \author Baruch Even + **/ + +#ifndef GnomeBase_H +#define GnomeBase_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "ViewBase.h" +#include "gnomeBC.h" +#include +#include "gnome_helpers.h" + +namespace Gtk { +class Button; +class Entry; +}; + +namespace Gnome { +class Dialog; +}; + +/** + * This is a base class for Gnome dialogs. Basically it handles all the common + * work that is needed for all dialogs. + */ +class GnomeBase : public ViewBC, public SigC::Object { +public: + /// + GnomeBase(ControlBase & c, string const & glade_file, string const & name); + /// + virtual ~GnomeBase(); + +protected: + template + T* getWidget(char const * name) const; + +private: + /// Loads the glade file to memory. + void loadXML() const; + + /// The glade file name + string file_; + /// The widget name + string widget_name_; + /// The XML representation of the dialogs. + mutable GladeXML * xml_; +}; + + +template +T* GnomeBase::getWidget(char const * name) const +{ + if (xml_ == 0) + loadXML(); + return getWidgetPtr(xml_, name); +} + +/** + * This class is used to provide a simple automatic casting of the controller. + * We chose not to make GnomeBase a template since it has some size and we + * have no reason to duplicate it by making it a template. + * + * Basically the FormCB template instantiates GnomeBase and passes + * the parameters to it and it also adds the controller() method to give us + * a reference to the controller of the correct type (the type is set by the + * template parameter). +*/ +template +class FormCB : public GnomeBase { +public: + FormCB(Controller & c, string const & file, string const & name); + +protected: + Controller & controller(); +}; + +template +FormCB::FormCB(Controller & c, string const & file, string const & name) + : GnomeBase(c, file, name) +{} + +template +Controller & +FormCB::controller() +{ + return static_cast(controller_); +} + +#endif diff --git a/src/frontends/gnome/Makefile.am b/src/frontends/gnome/Makefile.am index 5789ec5751..9789632a9c 100644 --- a/src/frontends/gnome/Makefile.am +++ b/src/frontends/gnome/Makefile.am @@ -4,51 +4,62 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in noinst_LTLIBRARIES = libgnome.la BOOST_INCLUDES = -I$(top_srcdir)/boost INCLUDES = ${FRONTEND_INCLUDES} -I${top_srcdir}/src/ \ - -I${top_srcdir}/src/frontends/ -I${top_srcdir}/src/frontends/xforms \ + -I${top_srcdir}/src/frontends/ \ + -I${top_srcdir}/src/frontends/xforms \ + -I${top_srcdir}/src/frontends/controllers \ ${SIGC_CFLAGS} $(BOOST_INCLUDES) + libgnome_la_OBJADD = \ - ../xforms/ButtonController.lo \ - ../xforms/Color.lo \ + ../xforms/xforms_helpers.lo \ + ../xforms/Toolbar_pimpl.lo \ + ../xforms/combox.lo \ + ../xforms/MathsSymbols.lo \ + ../xforms/FormMathsBitmap.lo \ + ../xforms/FormMathsDeco.lo \ + ../xforms/FormMathsDelim.lo \ + ../xforms/FormMathsMatrix.lo \ + ../xforms/FormMathsPanel.lo \ + ../xforms/FormMathsSpace.lo \ ../xforms/FileDialog.lo \ ../xforms/FormFiledialog.lo \ - ../xforms/form_filedialog.lo \ - ../xforms/FormBase.lo \ - ../xforms/FormCitation.lo \ - ../xforms/form_citation.lo \ - ../xforms/FormCopyright.lo \ - ../xforms/form_copyright.lo \ - ../xforms/FormDocument.lo \ - ../xforms/form_document.lo \ - ../xforms/FormError.lo \ - ../xforms/form_error.lo \ - ../xforms/FormGraphics.lo \ - ../xforms/form_graphics.lo \ - ../xforms/FormIndex.lo \ - ../xforms/form_index.lo \ - ../xforms/FormInset.lo \ - ../xforms/FormParagraph.lo \ - ../xforms/form_paragraph.lo \ - ../xforms/FormPreferences.lo \ - ../xforms/form_preferences.lo \ - ../xforms/FormPrint.lo \ - ../xforms/form_print.lo \ - ../xforms/FormRef.lo \ - ../xforms/form_ref.lo \ - ../xforms/FormSplash.lo \ - ../xforms/form_splash.lo \ - ../xforms/FormTabular.lo \ - ../xforms/form_tabular.lo \ - ../xforms/FormTabularCreate.lo \ - ../xforms/form_tabular_create.lo \ - ../xforms/FormToc.lo \ - ../xforms/form_toc.lo \ - ../xforms/FormUrl.lo \ - ../xforms/form_url.lo \ - ../xforms/input_validators.lo \ - ../xforms/RadioButtonGroup.lo \ - ../xforms/Timeout_pimpl.lo \ - ../xforms/Toolbar_pimpl.lo \ - ../xforms/xforms_helpers.lo + ../xforms/form_filedialog.lo +# ../xforms/Timeout_pimpl.lo \ +# ../xforms/Color.lo \ +# ../xforms/FormFiledialog.lo \ +# ../xforms/form_filedialog.lo \ +# ../xforms/FormBase.lo \ +# ../xforms/FormCitation.lo \ +# ../xforms/form_citation.lo \ +# ../xforms/FormCopyright.lo \ +# ../xforms/form_copyright.lo \ +# ../xforms/FormDocument.lo \ +# ../xforms/form_document.lo \ +# ../xforms/FormError.lo \ +# ../xforms/form_error.lo \ +# ../xforms/FormGraphics.lo \ +# ../xforms/form_graphics.lo \ +# ../xforms/FormIndex.lo \ +# ../xforms/form_index.lo \ +# ../xforms/FormInset.lo \ +# ../xforms/FormParagraph.lo \ +# ../xforms/form_paragraph.lo \ +# ../xforms/FormPreferences.lo \ +# ../xforms/form_preferences.lo \ +# ../xforms/FormPrint.lo \ +# ../xforms/form_print.lo \ +# ../xforms/FormRef.lo \ +# ../xforms/form_ref.lo \ +# ../xforms/FormSplash.lo \ +# ../xforms/form_splash.lo \ +# ../xforms/FormTabular.lo \ +# ../xforms/form_tabular.lo \ +# ../xforms/FormTabularCreate.lo \ +# ../xforms/form_tabular_create.lo \ +# ../xforms/FormToc.lo \ +# ../xforms/form_toc.lo \ +# ../xforms/input_validators.lo \ +# ../xforms/RadioButtonGroup.lo \ + LIBS= LDFLAGS= $(libgnome_la_OBJADD) LYXDATADIRS = @@ -56,49 +67,22 @@ LYXDATADIRS = libgnome_la_SOURCES = \ Dialogs.C \ GUIRunTime.C \ - FormCitation.C \ - FormCitation.h \ - FormCopyright.C \ - FormCopyright.h \ - FormError.C \ - FormError.h \ - FormPrint.C \ - FormPrint.h \ - FormRef.C \ - FormRef.h \ - FormUrl.C \ - FormUrl.h \ - FormIndex.C \ - FormIndex.h \ - FormToc.C \ - FormToc.h \ Menubar_pimpl.C \ Menubar_pimpl.h \ + Timeout_pimpl.C \ + Timeout_pimpl.h \ + gnomeBC.C \ + gnomeBC.h \ + gnome_helpers.h \ mainapp.C \ mainapp.h \ support.c \ support.h \ - diaprint_callbacks.c \ - diaprint_callbacks.h \ - diaprint_interface.c \ - diaprint_interface.h \ - diainserturl_callbacks.c \ - diainserturl_interface.c \ - diainserturl_callbacks.h \ - diainserturl_interface.h \ - diainsertindex_callbacks.c \ - diainsertindex_interface.c \ - diainsertindex_callbacks.h \ - diainsertindex_interface.h \ - diatoc_callbacks.c \ - diatoc_interface.c \ - diatoc_callbacks.h \ - diatoc_interface.h \ - diainsertcitation_interface.c \ - diainsertcitation_interface.h \ - diainsertcitation_callbacks.c \ - diainsertcitation_callbacks.h \ - pixbutton.h + pixbutton.h \ + GnomeBase.C \ + GnomeBase.h \ + FormUrl.C \ + FormUrl.h # These still have to be added. Sooner or later. ARRae-20000411 # GUI_defaults.C \ diff --git a/src/frontends/gnome/Menubar_pimpl.C b/src/frontends/gnome/Menubar_pimpl.C index 4dbebc6471..ff30401f8a 100644 --- a/src/frontends/gnome/Menubar_pimpl.C +++ b/src/frontends/gnome/Menubar_pimpl.C @@ -92,12 +92,15 @@ void Menubar::Pimpl::set(string const & menu_name) void Menubar::Pimpl::updateAllLists() { +#warning Implement me! (be 20010324) +#if 0 // update lists if (toc_.size() > 0) { vector toclist = (owner_->view()->buffer()->getTocList())[Buffer::TOC_TOC]; updateList(&toclist, &toc_); } +#endif } int const max_number_of_items = 25; diff --git a/src/frontends/gnome/Timeout_pimpl.C b/src/frontends/gnome/Timeout_pimpl.C new file mode 100644 index 0000000000..ba31cc2207 --- /dev/null +++ b/src/frontends/gnome/Timeout_pimpl.C @@ -0,0 +1,56 @@ +/** + * \file Timeout_pimpl.C + * Copyright 2001 LyX Team + * Read COPYING + * + * \author Baruch Even + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include +#include "Timeout_pimpl.h" +#include "debug.h" + + +Timeout::Pimpl::Pimpl(Timeout * owner) + : owner_(owner) +{ +} + + +void Timeout::Pimpl::reset() +{ + stop(); +} + + +void Timeout::Pimpl::start() +{ + if (conn_.connected()) { + lyxerr << "Timeout::start: already running!" << std::endl; + stop(); + } + + conn_ = Gnome::Main::timeout.connect( + SigC::slot(this, &Timeout::Pimpl::timeoutEvent), + owner_->timeout_ms + ); +} + + +void Timeout::Pimpl::stop() +{ + conn_.disconnect(); +} + + +gint Timeout::Pimpl::timeoutEvent() +{ + owner_->emit(); + return 0; // discontinue emitting timeouts. +} diff --git a/src/frontends/gnome/Timeout_pimpl.h b/src/frontends/gnome/Timeout_pimpl.h new file mode 100644 index 0000000000..92308e2802 --- /dev/null +++ b/src/frontends/gnome/Timeout_pimpl.h @@ -0,0 +1,47 @@ +/** + * \file Timeout_pimpl.h + * Copyright 2001 LyX Team + * Read COPYING + * + * \author Baruch Even + */ +#ifndef TIMEOUTPIMPL_H +#define TIMEOUTPIMPL_H + +#include + +#include "frontends/Timeout.h" +#include "glib.h" // for gint + +#include + +#ifdef __GNUG__ +#pragma interface +#endif + +/** + * This class executes the callback when the timeout expires + * using Gnome mechanisms + */ +struct Timeout::Pimpl : public SigC::Object { +public: + /// + Pimpl(Timeout * owner_); + /// start the timer + void start(); + /// stop the timer + void stop(); + /// reset + void reset(); + +public: + /// The timeout signal, this gets called when the timeout passed. + gint timeoutEvent(); +private: + /// the owning timer + Timeout * owner_; + /// Timer connection + SigC::Connection conn_; +}; + +#endif diff --git a/src/frontends/gnome/dialogs/diainserturl.glade b/src/frontends/gnome/dialogs/diainserturl.glade index 5c12b415df..f29a0498a4 100644 --- a/src/frontends/gnome/dialogs/diainserturl.glade +++ b/src/frontends/gnome/dialogs/diainserturl.glade @@ -5,14 +5,15 @@ diainserturl diainserturl - src + pixmaps C True True + True False - False False + True diainserturl_interface.c diainserturl_interface.h diainserturl_callbacks.c @@ -23,6 +24,7 @@ GnomeDialog DiaInsertUrl 2 + False Insert URL GTK_WINDOW_DIALOG GTK_WIN_POS_NONE @@ -31,7 +33,7 @@ True False False - False + True GtkVBox @@ -49,7 +51,7 @@ GtkHButtonBox GnomeDialog:action_area dialog-action_area1 - GTK_BUTTONBOX_END + GTK_BUTTONBOX_DEFAULT_STYLE 8 85 27 @@ -62,6 +64,15 @@ GTK_PACK_END + + GtkButton + button_restore + True + True + + GNOME_STOCK_PIXMAP_UNDO + + GtkButton button_ok @@ -70,10 +81,19 @@ GNOME_STOCK_BUTTON_OK + + GtkButton + button_apply + True + True + GNOME_STOCK_BUTTON_APPLY + + GtkButton button_cancel True + True True GNOME_STOCK_BUTTON_CANCEL @@ -107,13 +127,14 @@ GtkLabel label2 - + GTK_JUSTIFY_LEFT False 0.5 0.5 0 0 + name 0 1 @@ -133,13 +154,14 @@ GtkLabel label1 - + GTK_JUSTIFY_LEFT False 0.5 0.5 0 0 + url 0 1 @@ -158,7 +180,7 @@ GnomeEntry - url + url1 1 diainserturl_url 10 @@ -180,7 +202,7 @@ GtkEntry GnomeEntry:entry - combo-entry1 + url True True True @@ -194,7 +216,7 @@ GnomeEntry - name + name1 1 diainserturl_name 10 @@ -216,7 +238,7 @@ GtkEntry GnomeEntry:entry - combo-entry2 + name True True True diff --git a/src/frontends/gnome/gnomeBC.C b/src/frontends/gnome/gnomeBC.C new file mode 100644 index 0000000000..76b88e9384 --- /dev/null +++ b/src/frontends/gnome/gnomeBC.C @@ -0,0 +1,54 @@ +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "gnomeBC.h" +#include "gtk--/widget.h" +#include "gtk--/button.h" + +gnomeBC::gnomeBC(string const & cancel, string const & close) + : ButtonControllerBase(cancel, close), + okay_(0), apply_(0), cancel_(0), undo_all_(0) +{} + + +void gnomeBC::setSensitive(Gtk::Button * btn, ButtonPolicy::Button id) +{ + if (btn) { + bool const enabled = bp().buttonStatus(id); + btn->set_sensitive(enabled); + } +} + + +void gnomeBC::refresh() +{ + setSensitive(okay_, ButtonPolicy::OKAY); + setSensitive(apply_, ButtonPolicy::APPLY); + setSensitive(undo_all_, ButtonPolicy::UNDO_ALL); + +#warning Handle the cancel button correctly! (be 20010327) +#if 0 + if (cancel_) { + bool const enabled = bp().buttonStatus(ButtonPolicy::CANCEL); +// if (enabled) +// Change label to cancel_label_ +// else +// Change label to close_label_ +//Need to adapt it somehow since we use stock Gnome buttons. + } +#endif + + if (!read_only_.empty()) { + bool enable = true; + if (bp().isReadOnly()) enable = false; + + WidgetList::const_iterator end = read_only_.end(); + for (WidgetList::const_iterator iter = read_only_.begin(); + iter != end; ++iter) { + (*iter)->set_sensitive(enable); + } + } +} diff --git a/src/frontends/gnome/gnomeBC.h b/src/frontends/gnome/gnomeBC.h new file mode 100644 index 0000000000..8f0524e440 --- /dev/null +++ b/src/frontends/gnome/gnomeBC.h @@ -0,0 +1,81 @@ +// -*- C++ -*- +/* This file is part of + * ====================================================== + * + * LyX, The Document Processor + * + * Copyright 1995-2000 The LyX Team. + * + * ====================================================== + * + * Author: Baruch Even + */ + +#ifndef GNOMEBC_H +#define GNOMEBC_H + +#include "ButtonController.h" +#include + +#ifdef __GNUG__ +#pragma interface +#endif + +namespace Gtk { +class Button; +class Widget; +} + +class gnomeBC : public ButtonControllerBase +{ +public: + /// + gnomeBC(string const & cancel, string const & close); + + /* Initialise Button Functions */ + /// Call refresh() when finished setting the buttons. + void setOK(Gtk::Button * obj) { + okay_ = obj; + } + /// + void setApply(Gtk::Button * obj) { + apply_ = obj; + } + /// + void setCancel(Gtk::Button * obj) { + cancel_ = obj; + } + /// + void setUndoAll(Gtk::Button * obj) { + undo_all_ = obj; + } + /// + void addReadOnly(Gtk::Widget * obj) { + read_only_.push_front(obj); + } + /// + void eraseReadOnly() { + read_only_.clear(); + } + + /* Action Functions */ + /// force a refresh of the buttons + virtual void refresh(); + +private: + /// Updates the button sensitivity (enabled/disabled) + void setSensitive(Gtk::Button * btn, ButtonPolicy::Button id); + /// + Gtk::Button * okay_; + /// + Gtk::Button * apply_; + /// + Gtk::Button * cancel_; + /// + Gtk::Button * undo_all_; + /// List of items to be deactivated when in one of the read-only states + typedef std::list WidgetList; + WidgetList read_only_; +}; + +#endif // GNOMEBC_H diff --git a/src/frontends/gnome/gnome_helpers.h b/src/frontends/gnome/gnome_helpers.h new file mode 100644 index 0000000000..c67ef97175 --- /dev/null +++ b/src/frontends/gnome/gnome_helpers.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +/* This file is part of + * ================================================= + * + * LyX, The Document Processor + * Copyright 1995-2000 The LyX Team. + * + * ================================================= */ + +#ifndef GNOME_HELPERS_H +#define GNOME_HELPERS_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "debug.h" +#include +#include + +// Glade Helper Function. +template +T* getWidgetPtr(GladeXML* xml, const char* name) +{ + T* result = static_cast(Gtk::wrap_auto((GtkObject*)glade_xml_get_widget(xml, name))); + if (result == NULL) + { + lyxerr << "** ERROR **: unable to load widget: " << name << endl; + g_assert(result != NULL); + } + return result; +} + + + +#endif -- 2.39.2