diff --git a/src/frontends/gnome/ChangeLog b/src/frontends/gnome/ChangeLog index 3e28aefc68..66cbe1a3f8 100644 --- a/src/frontends/gnome/ChangeLog +++ b/src/frontends/gnome/ChangeLog @@ -1,3 +1,33 @@ +2003-02-01 Michael A. Koziarski + + Major changes to make the gnome frontend compile and work again. + + Credit to Martin Craig who + actually did the work, I just cleaned his patch up. + + Removed Files: + * GUIRuntime.C + + Added Files: + * Dialogs2.C + * Dialogs_impl.h + * lyx_gui.C + + Changed Files: + * Dialogs.C + * FileDialog.C + * GAbout.[Ch] + * GERT.[Ch] + * GError.[Ch] + * GFloat.[Ch] + * GLog.[Ch] + * GPreamble.[Ch] + * GTabularCreate.[Ch] + * GUrl.[Ch] + * GnomeBase.[Ch] + * Makefile.am + * Timeout_pimpl.C + 2002-12-16 Angus Leeming * Makefile.am: remove the if USE_BASIC_IMAGE_LOADER test. diff --git a/src/frontends/gnome/Dialogs.C b/src/frontends/gnome/Dialogs.C index fb0f66d4b3..103f52831f 100644 --- a/src/frontends/gnome/Dialogs.C +++ b/src/frontends/gnome/Dialogs.C @@ -1,8 +1,10 @@ /** * \file gnome/Dialogs.C + * Copyright 1995 Matthias Ettrich * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * + * \author Allan Rae * \author Angus Leeming * * Full author contact details are available in file CREDITS @@ -14,49 +16,70 @@ #pragma implementation #endif +#include "Dialogs_impl.h" -#include "Dialogs.h" - -#include "GUI.h" -#include "gnomeBC.h" - -#include "frontends/LyXView.h" - -#include "GAbout.h" -#include "GError.h" -#include "GERT.h" -#include "GFloat.h" -#include "GLog.h" -#include "GPreamble.h" -#include "GTabularCreate.h" -#include "GUrl.h" - -#include "Tooltips.h" - -bool Dialogs::tooltipsEnabled() +Dialogs::Dialogs(LyXView & lv) + : pimpl_(new Impl(lv, *this)) { - return Tooltips::enabled(); -} -Dialogs::Dialogs(LyXView * lv) -{ - - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv,*this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); - add(new GUI(*lv, *this)); // reduce the number of connections needed in // dialogs by a simple connection here. hideAll.connect(hideBufferDependent); } + + +Dialogs::~Dialogs() +{} + + +void Dialogs::toggleTooltips() +{ + Tooltips::toggleEnabled(); +} + + +/// Are the tooltips on or off? +bool Dialogs::tooltipsEnabled() +{ + return Tooltips::enabled(); +} + + +Dialogs::Impl::Impl(LyXView & lv, Dialogs & d) + : aboutlyx(lv, d), + bibitem(lv, d), + bibtex(lv, d), + character(lv, d), + citation(lv, d), + document(lv, d), + error(lv, d), + ert(lv, d), + external(lv, d), + file(lv, d), + floats(lv, d), + forks(lv, d), + graphics(lv, d), + include(lv, d), + index(lv, d), + logfile(lv, d), + mathpanel(lv, d), + minipage(lv, d), + paragraph(lv, d), + preamble(lv, d), + preferences(lv, d), + print(lv, d), + ref(lv, d), + search(lv, d), + sendto(lv, d), + spellchecker(lv, d), + tabular(lv, d), + tabularcreate(lv, d), + texinfo(lv, d), +#ifdef HAVE_LIBAIKSAURUS + thesaurus(lv, d), +#endif + + toc(lv, d), + url(lv, d), + vclogfile(lv, d), + wrap(lv, d) +{} diff --git a/src/frontends/gnome/Dialogs2.C b/src/frontends/gnome/Dialogs2.C new file mode 100644 index 0000000000..46541712eb --- /dev/null +++ b/src/frontends/gnome/Dialogs2.C @@ -0,0 +1,292 @@ +/** + * \file gnome/Dialogs2.C + * Copyright 1995 Matthias Ettrich + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Allan Rae + * \author Angus Leeming + * + * Full author contact details are available in file CREDITS + */ + +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "Dialogs_impl.h" + + +void Dialogs::showAboutlyx() +{ + pimpl_->aboutlyx.controller().show(); +} + + +void Dialogs::showBibitem(InsetCommand * ic) +{ + pimpl_->bibitem.controller().showInset(ic); +} + + +void Dialogs::showBibtex(InsetCommand * ic) +{ + pimpl_->bibtex.controller().showInset(ic); +} + + +void Dialogs::showCharacter() +{ + pimpl_->character.controller().show(); +} + + +void Dialogs::setUserFreeFont() +{ + pimpl_->character.controller().apply(); +} + + +void Dialogs::showCitation(InsetCommand * ic) +{ + pimpl_->citation.controller().showInset(ic); +} + + +void Dialogs::createCitation(string const & s) +{ + pimpl_->citation.controller().createInset(s); +} + + +void Dialogs::showDocument() +{ + pimpl_->document.controller().show(); +} + + +void Dialogs::showError(InsetError * ie) +{ + pimpl_->error.controller().showInset(ie); +} + + +void Dialogs::showERT(InsetERT * ie) +{ + pimpl_->ert.controller().showInset(ie); +} + + +void Dialogs::updateERT(InsetERT * ie) +{ + pimpl_->ert.controller().showInset(ie); +} + + +void Dialogs::showExternal(InsetExternal * ie) +{ + pimpl_->external.controller().showInset(ie); +} + + +void Dialogs::showFile(string const & f) +{ + pimpl_->file.controller().showFile(f); +} + + +void Dialogs::showFloat(InsetFloat * ifl) +{ + pimpl_->floats.controller().showInset(ifl); +} + + +void Dialogs::showForks() +{ + pimpl_->forks.controller().show(); +} + + +void Dialogs::showGraphics(InsetGraphics * ig) +{ + pimpl_->graphics.controller().showInset(ig); +} + + +void Dialogs::showInclude(InsetInclude * ii) +{ + pimpl_->include.controller().showInset(ii); +} + + +void Dialogs::showIndex(InsetCommand * ic) +{ + pimpl_->index.controller().showInset(ic); +} + + +void Dialogs::createIndex() +{ + pimpl_->index.controller().createInset(string()); +} + + +void Dialogs::showLogFile() +{ + pimpl_->logfile.controller().show(); +} + + +void Dialogs::showMathPanel() +{ + pimpl_->mathpanel.controller().show(); +} + + +void Dialogs::showMinipage(InsetMinipage * im) +{ + pimpl_->minipage.controller().showInset(im); +} + + +void Dialogs::updateMinipage(InsetMinipage * im) +{ + pimpl_->minipage.controller().showInset(im); +} + + +void Dialogs::showParagraph() +{ + pimpl_->paragraph.controller().show(); +} + + +void Dialogs::updateParagraph() +{ + pimpl_->paragraph.controller().changedParagraph(); +} + + +void Dialogs::showPreamble() +{ + pimpl_->preamble.controller().show(); +} + + +void Dialogs::showPreferences() +{ + pimpl_->preferences.controller().show(); +} + + +void Dialogs::showPrint() +{ + pimpl_->print.controller().show(); +} + + +void Dialogs::showRef(InsetCommand * ic) +{ + pimpl_->ref.controller().showInset(ic); +} + + +void Dialogs::createRef(string const & s) +{ + pimpl_->ref.controller().createInset(s); +} + + +void Dialogs::showSearch() +{ + pimpl_->search.controller().show(); +} + + +void Dialogs::showSendto() +{ + pimpl_->sendto.controller().show(); +} + + +void Dialogs::showSpellchecker() +{ + pimpl_->spellchecker.controller().show(); +} + + +void Dialogs::showTabular(InsetTabular * it) +{ + pimpl_->tabular.controller().showInset(it); +} + + +void Dialogs::updateTabular(InsetTabular * it) +{ + pimpl_->tabular.controller().updateInset(it); +} + + +void Dialogs::showTabularCreate() +{ + pimpl_->tabularcreate.controller().show(); +} + + +void Dialogs::showTexinfo() +{ + pimpl_->texinfo.controller().show(); +} + + +#ifdef HAVE_LIBAIKSAURUS + +void Dialogs::showThesaurus(string const & s) +{ + pimpl_->thesaurus.controller().showEntry(s); +} + +#else + +void Dialogs::showThesaurus(string const &) +{} + +#endif + + +void Dialogs::showTOC(InsetCommand * ic) +{ + pimpl_->toc.controller().showInset(ic); +} + + +void Dialogs::createTOC(string const & s) +{ + pimpl_->toc.controller().createInset(s); +} + + +void Dialogs::showUrl(InsetCommand * ic) +{ + pimpl_->url.controller().showInset(ic); +} + + +void Dialogs::createUrl(string const & s) +{ + pimpl_->url.controller().createInset(s); +} + + +void Dialogs::showVCLogFile() +{ + pimpl_->vclogfile.controller().show(); +} + + +void Dialogs::showWrap(InsetWrap * iw) +{ + pimpl_->wrap.controller().showInset(iw); +} diff --git a/src/frontends/gnome/Dialogs_impl.h b/src/frontends/gnome/Dialogs_impl.h new file mode 100644 index 0000000000..276dd68cdc --- /dev/null +++ b/src/frontends/gnome/Dialogs_impl.h @@ -0,0 +1,305 @@ +// -*- C++ -*- +/** + * \file xforms/Dialogs_impl.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * \author Angus Leeming + * + * Full author contact details are available in file CREDITS + */ + +#ifndef DIALOGS_IMPL_H +#define DIALOGS_IMP_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "Dialogs.h" +#include "controllers/GUI.h" + +#include "Tooltips.h" +#include "xformsBC.h" +#include "gnomeBC.h" +#include "combox.h" + +#include "ControlAboutlyx.h" +#include "GAbout.h" + +#include "ControlBibitem.h" +#include "FormBibitem.h" +#include "forms/form_bibitem.h" + +#include "ControlBibtex.h" +#include "FormBibtex.h" +#include "forms/form_bibtex.h" + +#include "FormBrowser.h" +#include "forms/form_browser.h" + +#include "ControlCharacter.h" +#include "FormCharacter.h" +#include "forms/form_character.h" + +#include "ControlCitation.h" +#include "FormCitation.h" +#include "forms/form_citation.h" + +#include "ControlDocument.h" +#include "FormDocument.h" +#include "forms/form_document.h" + +#include "ControlError.h" +#include "GError.h" + +#include "ControlERT.h" +#include "GERT.h" + +#include "ControlExternal.h" +#include "FormExternal.h" +#include "forms/form_external.h" + +#include "ControlFloat.h" +#include "GFloat.h" + +#include "ControlForks.h" +#include "FormForks.h" +#include "forms/form_forks.h" + +#include "ControlGraphics.h" +#include "FormGraphics.h" +#include "forms/form_graphics.h" + +#include "ControlInclude.h" +#include "FormInclude.h" +#include "forms/form_include.h" + +#include "ControlIndex.h" +#include "FormIndex.h" +#include "forms/form_index.h" + +#include "ControlLog.h" +#include "GLog.h" + +#include "ControlShowFile.h" +#include "FormShowFile.h" + +#include "ControlMath.h" +#include "FormMathsPanel.h" +#include "forms/form_maths_panel.h" + +#include "ControlMinipage.h" +#include "FormMinipage.h" +#include "forms/form_minipage.h" + +#include "ControlParagraph.h" +#include "FormParagraph.h" +#include "forms/form_paragraph.h" + +#include "ControlPreamble.h" +#include "GPreamble.h" + +#include "ControlPrefs.h" +#include "FormPreferences.h" +#include "forms/form_preferences.h" + +#include "ControlPrint.h" +#include "FormPrint.h" +#include "forms/form_print.h" + +#include "ControlRef.h" +#include "FormRef.h" +#include "forms/form_ref.h" + +#include "ControlSearch.h" +#include "FormSearch.h" +#include "forms/form_search.h" + +#include "ControlSendto.h" +#include "FormSendto.h" +#include "forms/form_sendto.h" + +#include "ControlSpellchecker.h" +#include "FormSpellchecker.h" +#include "forms/form_spellchecker.h" + +#include "ControlTabular.h" +#include "FormTabular.h" +#include "forms/form_tabular.h" + +#include "ControlTabularCreate.h" +#include "GTabularCreate.h" + +#include "ControlTexinfo.h" +#include "FormTexinfo.h" +#include "forms/form_texinfo.h" + +#ifdef HAVE_LIBAIKSAURUS +#include "ControlThesaurus.h" +#include "FormThesaurus.h" +#include "forms/form_thesaurus.h" +#endif + +#include "ControlToc.h" +#include "FormToc.h" +#include "forms/form_toc.h" + +#include "ControlUrl.h" +#include "GUrl.h" + +#include "ControlVCLog.h" +#include "FormVCLog.h" + +#include "ControlWrap.h" +#include "FormWrap.h" +#include "forms/form_wrap.h" + + +typedef GUI +AboutlyxDialog; + +typedef GUI +BibitemDialog; + +typedef GUI +BibtexDialog; + +typedef GUI +CharacterDialog; + +typedef GUI +CitationDialog; + +typedef GUI +DocumentDialog; + +typedef GUI +ErrorDialog; + +typedef GUI +ERTDialog; + +typedef GUI +ExternalDialog; + +typedef GUI +FileDialog; + +typedef GUI +FloatDialog; + +typedef GUI +ForksDialog; + +typedef GUI +GraphicsDialog; + +typedef GUI +IncludeDialog; + +typedef GUI +IndexDialog; + +typedef GUI +LogFileDialog; + +typedef GUI +MathPanelDialog; + +typedef GUI +MinipageDialog; + +typedef GUI +ParagraphDialog; + +typedef GUI +PreambleDialog; + +typedef GUI +PreferencesDialog; + +typedef GUI +PrintDialog; + +typedef GUI +RefDialog; + +typedef GUI +SearchDialog; + +typedef GUI +SendtoDialog; + +typedef GUI +SpellcheckerDialog; + +typedef GUI +TabularDialog; + +typedef GUI +TabularCreateDialog; + +typedef GUI +TexinfoDialog; + +#ifdef HAVE_LIBAIKSAURUS +typedef GUI +ThesaurusDialog; +#endif + +typedef GUI +TocDialog; + +typedef GUI +UrlDialog; + +typedef GUI +VCLogFileDialog; + +typedef GUI +WrapDialog; + +struct Dialogs::Impl { + Impl(LyXView & lv, Dialogs & d); + + AboutlyxDialog aboutlyx; + BibitemDialog bibitem; + BibtexDialog bibtex; + CharacterDialog character; + CitationDialog citation; + DocumentDialog document; + ErrorDialog error; + ERTDialog ert; + ExternalDialog external; + FileDialog file; + FloatDialog floats; + ForksDialog forks; + GraphicsDialog graphics; + IncludeDialog include; + IndexDialog index; + LogFileDialog logfile; + MathPanelDialog mathpanel; + MinipageDialog minipage; + ParagraphDialog paragraph; + PreambleDialog preamble; + PreferencesDialog preferences; + PrintDialog print; + RefDialog ref; + SearchDialog search; + SendtoDialog sendto; + SpellcheckerDialog spellchecker; + TabularDialog tabular; + TabularCreateDialog tabularcreate; + TexinfoDialog texinfo; + +#ifdef HAVE_LIBAIKSAURUS + ThesaurusDialog thesaurus; +#endif + + TocDialog toc; + UrlDialog url; + VCLogFileDialog vclogfile; + WrapDialog wrap; +}; + +#endif // DIALOGS_IMPL_H diff --git a/src/frontends/gnome/FileDialog.C b/src/frontends/gnome/FileDialog.C index d00faf6f4c..2ef8a635b0 100644 --- a/src/frontends/gnome/FileDialog.C +++ b/src/frontends/gnome/FileDialog.C @@ -16,12 +16,9 @@ #include "FileDialog.h" #include "debug.h" #include "support/lstrings.h" -#include -#include +#include #include -#include - #include "frontends/LyXView.h" // This is only needed while we have the xforms part! #include "bufferview_funcs.h" // FileDialog::Private @@ -49,9 +46,9 @@ private: FileDialog::Private::Private(string const & title) : sel_(title), modal_(false) { - sel_.get_ok_button()->clicked.connect(slot(this, + sel_.get_ok_button()->signal_clicked().connect(slot(*this, &FileDialog::Private::ok_clicked)); - sel_.get_cancel_button()->clicked.connect(slot(this, + sel_.get_cancel_button()->signal_clicked().connect(slot(*this, &FileDialog::Private::cancel_clicked)); } @@ -60,7 +57,8 @@ string const FileDialog::Private::exec() canceled_ = false; sel_.set_modal(modal_); sel_.show(); - Gnome::Main::run(); + + sel_.run(); // Find if its canceled or oked and return as needed. if (canceled_) @@ -73,7 +71,6 @@ void FileDialog::Private::button_clicked(bool canceled) { canceled_ = canceled; sel_.hide(); - Gnome::Main::quit(); } // FileDialog @@ -94,7 +91,7 @@ FileDialog::~FileDialog() FileDialog::Result const -FileDialog::Select(string const & path, string const & mask, +FileDialog::open(string const & path, string const & mask, string const & suggested) { // For some reason we need to ignore the asynchronous method... @@ -122,3 +119,15 @@ FileDialog::Select(string const & path, string const & mask, // Collect the info and return it for synchronous dialog. return FileDialog::Result(Chosen, filename); } + +FileDialog::Result const +FileDialog::opendir(string const & path, + string const & suggested) +{ + return open(path, "*/", suggested); +} + +FileDialog::Result const FileDialog::save(string const & path, string const & mask, string const & suggested) +{ + return open(path, mask, suggested); +} diff --git a/src/frontends/gnome/GAbout.C b/src/frontends/gnome/GAbout.C index 1df4a355fc..530b0ddab3 100644 --- a/src/frontends/gnome/GAbout.C +++ b/src/frontends/gnome/GAbout.C @@ -17,15 +17,15 @@ #include "support/lstrings.h" #include "Lsstream.h" - +#include "gnome_helpers.h" #include "gnomeBC.h" #include "GAbout.h" #include #include -GAbout::GAbout(ControlAboutlyx & c) - : GnomeCB(c, "GAbout") +GAbout::GAbout() + : GnomeCB("GAbout") {} @@ -69,21 +69,26 @@ void GAbout::update() istringstream ss(in.str()); string s; - string out; - Gtk::TextIter e; + Glib::RefPtr buf = credits()->get_buffer(); + addDefaultTags(buf); while (getline(ss, s)) { - if (prefixIs(s, "@b")) - out += s.substr(2); + if (prefixIs(s, "@b")) + buf->insert_with_tag(buf->end(), + Glib::locale_to_utf8(s.substr(2)), + "bold"); else if (prefixIs(s, "@i")) - out += s.substr(2); + buf->insert_with_tag(buf->end(), + Glib::locale_to_utf8(s.substr(2)), + "italic"); else - out += s.substr(2); + buf->insert(buf->end(), + Glib::locale_to_utf8(s.substr(2))); + buf->insert(buf->end(),"\n"); - out += "\n"; } - credits()->get_buffer()->set_text(out); + } diff --git a/src/frontends/gnome/GAbout.h b/src/frontends/gnome/GAbout.h index b1d7fc74a1..3c89e0be03 100644 --- a/src/frontends/gnome/GAbout.h +++ b/src/frontends/gnome/GAbout.h @@ -31,7 +31,7 @@ namespace Gtk { class GAbout : public GnomeCB { public: /// - GAbout(ControlAboutlyx & c); + GAbout(); /// ~GAbout(); diff --git a/src/frontends/gnome/GERT.C b/src/frontends/gnome/GERT.C index 5c0ffc1fe6..d5c9dadb85 100644 --- a/src/frontends/gnome/GERT.C +++ b/src/frontends/gnome/GERT.C @@ -20,8 +20,8 @@ #include #include -GERT::GERT(ControlERT & c) - : GnomeCB(c, "GERT") +GERT::GERT() + : GnomeCB("GERT") {} diff --git a/src/frontends/gnome/GERT.h b/src/frontends/gnome/GERT.h index 6021fc0fa9..61bc5896f8 100644 --- a/src/frontends/gnome/GERT.h +++ b/src/frontends/gnome/GERT.h @@ -30,7 +30,7 @@ namespace Gtk { class GERT : public GnomeCB { public: /// - GERT(ControlERT & c); + GERT(); /// ~GERT(); diff --git a/src/frontends/gnome/GError.C b/src/frontends/gnome/GError.C index d6b13e34d0..76f3566d49 100644 --- a/src/frontends/gnome/GError.C +++ b/src/frontends/gnome/GError.C @@ -21,8 +21,8 @@ #include #include -GErrorDialog::GErrorDialog(ControlError & c) - : GnomeCB(c, "GError") +GErrorDialog::GErrorDialog() + : GnomeCB("GError") {} diff --git a/src/frontends/gnome/GError.h b/src/frontends/gnome/GError.h index 0602fca936..4f39558256 100644 --- a/src/frontends/gnome/GError.h +++ b/src/frontends/gnome/GError.h @@ -33,7 +33,7 @@ class TextView; class GErrorDialog : public GnomeCB { public: /// - GErrorDialog(ControlError & c); + GErrorDialog(); /// ~GErrorDialog() {} /// @@ -49,7 +49,7 @@ private: bool validate() const { return true; } /// - void CloseClicked() { CancelButton(); } + void CloseClicked() { CancelClicked(); } /// generated by accessors.py Gtk::Button * button_close() const; diff --git a/src/frontends/gnome/GFloat.C b/src/frontends/gnome/GFloat.C index 7186cdfed9..d424da2f3a 100644 --- a/src/frontends/gnome/GFloat.C +++ b/src/frontends/gnome/GFloat.C @@ -23,8 +23,8 @@ #include #include -GFloat::GFloat(ControlFloat & c) - : GnomeCB(c, "GFloat") +GFloat::GFloat() + : GnomeCB("GFloat") {} diff --git a/src/frontends/gnome/GFloat.h b/src/frontends/gnome/GFloat.h index a2b0eece85..d00dc72124 100644 --- a/src/frontends/gnome/GFloat.h +++ b/src/frontends/gnome/GFloat.h @@ -32,7 +32,7 @@ namespace Gtk { class GFloat : public GnomeCB { public: /// - GFloat(ControlFloat & c); + GFloat(); /// ~GFloat(); diff --git a/src/frontends/gnome/GLog.C b/src/frontends/gnome/GLog.C index 219edf1ab6..d0d46c4107 100644 --- a/src/frontends/gnome/GLog.C +++ b/src/frontends/gnome/GLog.C @@ -22,8 +22,8 @@ #include #include -GLog::GLog(ControlLog & c) - : GnomeCB(c, "GLog") +GLog::GLog() + : GnomeCB("GLog") {} diff --git a/src/frontends/gnome/GLog.h b/src/frontends/gnome/GLog.h index 482f616123..c014e1e392 100644 --- a/src/frontends/gnome/GLog.h +++ b/src/frontends/gnome/GLog.h @@ -30,7 +30,7 @@ namespace Gtk { class GLog : public GnomeCB { public: /// - GLog(ControlLog & c); + GLog(); /// ~GLog(); diff --git a/src/frontends/gnome/GPreamble.C b/src/frontends/gnome/GPreamble.C index 2e87d6c0e2..15341b266b 100644 --- a/src/frontends/gnome/GPreamble.C +++ b/src/frontends/gnome/GPreamble.C @@ -20,8 +20,8 @@ #include #include -GPreamble::GPreamble(ControlPreamble & c) - : GnomeCB(c, "GPreamble") +GPreamble::GPreamble() + : GnomeCB("GPreamble") {} @@ -44,9 +44,9 @@ void GPreamble::build() void GPreamble::apply() { - controller().params() = preamble()->get_buffer()->get_text(preamble()->get_buffer()->get_start_iter(), - preamble()->get_buffer()->get_end_iter(), - false); +// controller().params() = preamble()->get_buffer()->get_text(preamble()->get_buffer()->get_start_iter(), +// preamble()->get_buffer()->get_end_iter(), +// false); } diff --git a/src/frontends/gnome/GPreamble.h b/src/frontends/gnome/GPreamble.h index 1a81e1400e..51dd3bdffb 100644 --- a/src/frontends/gnome/GPreamble.h +++ b/src/frontends/gnome/GPreamble.h @@ -30,7 +30,7 @@ class TextView; class GPreamble : public GnomeCB { public: /// - GPreamble(ControlPreamble & c); + GPreamble(); /// ~GPreamble(); diff --git a/src/frontends/gnome/GTabularCreate.C b/src/frontends/gnome/GTabularCreate.C index 1cd44be20a..c636fb656d 100644 --- a/src/frontends/gnome/GTabularCreate.C +++ b/src/frontends/gnome/GTabularCreate.C @@ -21,8 +21,8 @@ #include #include -GTabularCreate::GTabularCreate(ControlTabularCreate & c) - : GnomeCB(c, "GTabularCreate") +GTabularCreate::GTabularCreate() + : GnomeCB("GTabularCreate") {} @@ -38,7 +38,7 @@ void GTabularCreate::build() cancel_btn()->signal_clicked().connect(SigC::slot(*this, >abularCreate::CancelClicked)); apply_btn()->signal_clicked().connect(SigC::slot(*this, - >abularCreate::ApplyClicked)); + >abularCreate::ApplyClicked)); // Manage the buttons state bc().setOK(ok_btn()); @@ -52,8 +52,8 @@ void GTabularCreate::build() void GTabularCreate::apply() { - unsigned int ysize = (unsigned int)(rows()->get_value_as_int()); - unsigned int xsize = (unsigned int)(cols()->get_value_as_int()); + unsigned int xsize = (unsigned int)(rows()->get_value_as_int()); + unsigned int ysize = (unsigned int)(cols()->get_value_as_int()); controller().params() = std::make_pair(xsize, ysize); } diff --git a/src/frontends/gnome/GTabularCreate.h b/src/frontends/gnome/GTabularCreate.h index 4829a43358..1eb01642a5 100644 --- a/src/frontends/gnome/GTabularCreate.h +++ b/src/frontends/gnome/GTabularCreate.h @@ -30,7 +30,7 @@ namespace Gtk { class GTabularCreate : public GnomeCB { public: /// - GTabularCreate(ControlTabularCreate & c); + GTabularCreate(); /// ~GTabularCreate(); @@ -44,9 +44,9 @@ private: bool validate() const; void update(); - void OKClicked() { OKButton(); } - void CancelClicked() { CancelButton(); } - void ApplyClicked() { ApplyButton(); } + void OKClicked() { getController().OKButton(); } + void CancelClicked() { getController().CancelButton(); } + void ApplyClicked() { getController().ApplyButton(); } /// generated by accessors.py Gtk::Button * ok_btn() const; diff --git a/src/frontends/gnome/GUIRunTime.C b/src/frontends/gnome/GUIRunTime.C deleted file mode 100644 index b26b3ff32c..0000000000 --- a/src/frontends/gnome/GUIRunTime.C +++ /dev/null @@ -1,180 +0,0 @@ -/** - * \file GUIRunTime.C - * This file is part of LyX, the document processor. - * Licence details can be found in the file COPYING. - * - * \author unknown - * - * Full author contact details are available in file CREDITS - */ - -#include - -#ifdef __GNUG__ -#pragma implementation -#endif - -#include FORMS_H_LOCATION -#include "gnome_helpers.h" -#include "GUIRunTime.h" -#include "debug.h" - -#include -#include - -#include - -// For now we use the xforms image loader if we can. -// In the future, this will be replaced by a gnome equivalent. -#if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP) -#include "xforms/xformsGImage.h" -#else -#include "graphics/GraphicsImageXPM.h" -#endif - -using std::endl; - - -extern bool finished; - -namespace { - -int const xforms_include_version = FL_INCLUDE_VERSION; - -} // namespace anon - - -int GUIRunTime::initApplication(int & argc , char * argv[]) -{ - // Check the XForms version in the forms.h header against - // the one in the libforms. If they don't match quit the - // execution of LyX. Better with a clean fast exit than - // a strange segfault later. - // I realize that this check have to be moved when we - // support several toolkits, but IMO all the toolkits - // should try to have the same kind of check. This could - // be done by having a CheckHeaderAndLib function in - // all the toolkit implementations, this function is - // responsible for notifing the user. - // if (!CheckHeaderAndLib()) { - // // header vs. lib version failed - // return 1; - // } - int xforms_lib_version = fl_library_version(0, 0); - if (xforms_include_version != xforms_lib_version) { - cerr << "You are either running LyX with wrong " - "version of a dynamic XForms library\n" - "or you have build LyX with conflicting header " - "and library (different\n" - "versions of XForms. Sorry but there is no point " - "in continuing executing LyX!" << endl; - return 1; - } - - // I belive that this should be done at a later stage, in - // lyx_gui, the same place as xforms does the same. (Lgb) - string app_id(PACKAGE); - string app_version(VERSION); - new Gtk::Main (argc, argv); - - return 0; -} - -void GUIRunTime::processEvents() -{ - while (Gtk::Main::events_pending()) - Gtk::Main::iteration(false); -} - - -void GUIRunTime::runTime() -{ - XEvent ev; - while (!finished) { - processEvents(); - if (fl_check_forms() == FL_EVENT) { - fl_XNextEvent(&ev); - lyxerr << "Received unhandled X11 event" << endl; - lyxerr << "Type: 0x" << hex << ev.xany.type << - "Target: 0x" << hex << ev.xany.window << endl; - } - } -} - - -void GUIRunTime::setDefaults() -{ - FL_IOPT cntl; - cntl.buttonFontSize = FL_NORMAL_SIZE; - cntl.browserFontSize = FL_NORMAL_SIZE; - cntl.labelFontSize = FL_NORMAL_SIZE; - cntl.choiceFontSize = FL_NORMAL_SIZE; - cntl.inputFontSize = FL_NORMAL_SIZE; - cntl.menuFontSize = FL_NORMAL_SIZE; - cntl.borderWidth = -1; - cntl.vclass = FL_DefaultVisual; - fl_set_defaults(FL_PDVisual - | FL_PDButtonFontSize - | FL_PDBrowserFontSize - | FL_PDLabelFontSize - | FL_PDChoiceFontSize - | FL_PDInputFontSize - | FL_PDMenuFontSize - | FL_PDBorderWidth, &cntl); -} - - -#include "XFormsView.h" -LyXView * GUIRunTime::createMainView(int w, int h) -{ - return new XFormsView(w, h); -} - - -// Called by the graphics cache to connect the appropriate frontend -// image loading routines to the LyX kernel. -void GUIRunTime::initialiseGraphics() -{ - using namespace grfx; - -#if defined(HAVE_FLIMAGE_DUP) && defined(HAVE_FLIMAGE_TO_PIXMAP) - // connect the image loader based on the xforms library - GImage::newImage.connect(boost::bind(&xformsGImage::newImage)); - GImage::loadableFormats.connect(boost::bind(&xformsGImage::loadableFormats)); -#else - // connect the image loader based on the XPM library - GImage::newImage.connect(boost::bind(&GImageXPM::newImage)); - GImage::loadableFormats.connect(boost::bind(&GImageXPM::loadableFormats)); -#endif -} - - -Display * GUIRunTime::x11Display() -{ - return fl_get_display(); -} - - -int GUIRunTime::x11Screen() -{ - return fl_screen; -} - - -Colormap GUIRunTime::x11Colormap() -{ - return fl_state[fl_get_vclass()].colormap; -} - - -int GUIRunTime::x11VisualDepth() -{ - return fl_get_visual_depth(); -} - -float GUIRunTime::getScreenDPI() -{ - Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); - return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) + - (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2; -} diff --git a/src/frontends/gnome/GUrl.C b/src/frontends/gnome/GUrl.C index 82a0e87f3b..30d1cdd493 100644 --- a/src/frontends/gnome/GUrl.C +++ b/src/frontends/gnome/GUrl.C @@ -22,8 +22,8 @@ #include #include -GUrl::GUrl(ControlUrl & c) - : GnomeCB(c, "GUrl") +GUrl::GUrl() + : GnomeCB("GUrl") {} diff --git a/src/frontends/gnome/GUrl.h b/src/frontends/gnome/GUrl.h index 908259f9e6..1a5b97b90b 100644 --- a/src/frontends/gnome/GUrl.h +++ b/src/frontends/gnome/GUrl.h @@ -32,7 +32,7 @@ class Entry; class GUrl : public GnomeCB { public: /// - GUrl(ControlUrl & c); + GUrl(); /// ~GUrl(); diff --git a/src/frontends/gnome/GnomeBase.C b/src/frontends/gnome/GnomeBase.C index 805afe37a9..8771defe28 100644 --- a/src/frontends/gnome/GnomeBase.C +++ b/src/frontends/gnome/GnomeBase.C @@ -17,14 +17,18 @@ #include "support/LAssert.h" #include "debug.h" #include "support/filetools.h" +#include "ControlButtons.h" #include #include -GnomeBase::GnomeBase(ControlButtons & c, - string const & name) - : ViewBC(c) - , file_(name + ".glade"), widget_name_(name), xml_(0) - , dialog_(0) +GnomeBase::GnomeBase(string const & name) + : ViewBase(), + updating_(false), + file_(name + ".glade"), + title_(name), + widget_name_(name), + xml_(0), + dialog_(0) { loadXML(); } @@ -32,13 +36,18 @@ GnomeBase::GnomeBase(ControlButtons & c, GnomeBase::~GnomeBase() {} +gnomeBC & GnomeBase::bc() +{ + return static_cast(getController().bc()); +} void GnomeBase::loadXML() { #ifdef WITH_WARNINGS #warning Change this before declaring it production code! (be 20010325) #endif - string const path("src/frontends/gnome/dialogs/;frontends/gnome/dialogs/;"); + string const path("src/frontends/gnome/dialogs/;frontends/gnome/dialogs/;"); + string const file = FileOpenSearch(path, file_, "glade"); if (file.empty()) { @@ -64,7 +73,7 @@ void GnomeBase::hide() dialog()->hide(); } -bool GnomeBase::validate() +bool GnomeBase::isValid() { return true; } @@ -72,30 +81,30 @@ bool GnomeBase::validate() void GnomeBase::OKClicked() { lyxerr[Debug::GUI] << "GnomeBase::OKClicked()\n"; - OKButton(); + getController().OKButton(); } void GnomeBase::CancelClicked() { lyxerr[Debug::GUI] << "GnomeBase::CancelClicked()\n"; - CancelButton(); + getController().CancelButton(); } void GnomeBase::ApplyClicked() { lyxerr[Debug::GUI] << "GnomeBase::ApplyClicked()\n"; - ApplyButton(); + getController().ApplyButton(); } void GnomeBase::RestoreClicked() { lyxerr[Debug::GUI] << "GnomeBase::RestoreClicked()\n"; - RestoreButton(); + getController().RestoreButton(); } void GnomeBase::InputChanged() { - bc().valid(validate()); + bc().valid(isValid()); } Gtk::Dialog * GnomeBase::dialog() @@ -105,3 +114,8 @@ Gtk::Dialog * GnomeBase::dialog() return dialog_; } + +bool GnomeBase::isVisible() const +{ + return dialog_ && dialog_->is_visible(); +} diff --git a/src/frontends/gnome/GnomeBase.h b/src/frontends/gnome/GnomeBase.h index 259d32bc10..74fcc9992d 100644 --- a/src/frontends/gnome/GnomeBase.h +++ b/src/frontends/gnome/GnomeBase.h @@ -24,7 +24,6 @@ #include "ViewBase.h" #include "gnomeBC.h" - namespace Gtk { class Dialog; }; @@ -33,10 +32,10 @@ namespace Gtk { * This is a base class for Gnome dialogs. It handles all the common * work that is needed for all dialogs. */ -class GnomeBase : public ViewBC, public SigC::Object { +class GnomeBase : public ViewBase, public SigC::Object { public: /// - GnomeBase(ControlButtons & c, string const & name); + GnomeBase(string const & name); /// virtual ~GnomeBase(); @@ -55,7 +54,9 @@ protected: /// Build the dialog. Also connects signals and prepares it for work. virtual void build() = 0; /// Dialog is valid - virtual bool validate(); + virtual bool isValid(); + /// dialog is visible + virtual bool isVisible() const; /// Default OK behaviour virtual void OKClicked(); /// Default Cancel behaviour @@ -67,6 +68,11 @@ protected: /// Default changed input behaviour virtual void InputChanged(); + /// + gnomeBC & bc(); + + /// are we updating ? + bool updating_; private: /// Loads the glade file to memory. void loadXML(); @@ -83,6 +89,9 @@ private: * of the libglade GladeXML structure. */ Gtk::Dialog * dialog_; + + /// dialog title, displayed by WM. + string title_; }; @@ -105,21 +114,21 @@ T* GnomeBase::getWidget(const string & name) const template class GnomeCB : public GnomeBase { public: - GnomeCB(Controller & c, string const & name); + GnomeCB(string const & name); protected: Controller & controller(); }; template -GnomeCB::GnomeCB(Controller & c, string const & name) - : GnomeBase(c, name) +GnomeCB::GnomeCB(string const & name) + : GnomeBase(name) {} template Controller & GnomeCB::controller() { - return static_cast(controller_); + return static_cast(getController()); } #endif diff --git a/src/frontends/gnome/Makefile.am b/src/frontends/gnome/Makefile.am index 2551c5813b..ac9a70b4e0 100644 --- a/src/frontends/gnome/Makefile.am +++ b/src/frontends/gnome/Makefile.am @@ -8,49 +8,112 @@ INCLUDES = $(FRONTEND_INCLUDES) -I$(top_srcdir)/src/ \ -I$(top_srcdir)/src/frontends/controllers \ $(BOOST_INCLUDES) +# These are the XForms GUI classes we still need because they +# haven't been implemented in Gnome. # alphabetised xforms_objects = \ ../xforms/Alert_pimpl.lo \ ../xforms/bmtable.lo \ + ../xforms/checkedwidgets.lo \ ../xforms/combox.lo \ ../xforms/Color.lo \ ../xforms/ColorHandler.lo \ ../xforms/DropDown.lo \ - ../xforms/FeedbackController.lo \ - ../xforms/FileDialog.lo \ + ../xforms/fdesign_base.lo \ ../xforms/FontInfo.lo \ - ../xforms/FormBaseDeprecated.lo \ - ../xforms/FormFiledialog.lo \ - ../xforms/form_filedialog.lo \ + ../xforms/FormAboutlyx.lo \ + ../xforms/FormBase.lo \ + ../xforms/FormBibitem.lo \ + ../xforms/FormBibtex.lo \ + ../xforms/FormBrowser.lo \ + ../xforms/FormCharacter.lo \ + ../xforms/FormCitation.lo \ + ../xforms/FormDocument.lo \ + ../xforms/FormExternal.lo \ + ../xforms/FormForks.lo \ + ../xforms/FormGraphics.lo \ + ../xforms/FormInclude.lo \ + ../xforms/FormIndex.lo \ ../xforms/FormMathsBitmap.lo \ - ../xforms/FormMathsDeco.lo \ - ../xforms/form_maths_deco.lo \ ../xforms/FormMathsDelim.lo \ - ../xforms/form_maths_delim.lo \ ../xforms/FormMathsMatrix.lo \ - ../xforms/form_maths_matrix.lo \ ../xforms/FormMathsPanel.lo \ - ../xforms/form_maths_panel.lo \ ../xforms/FormMathsSpace.lo \ - ../xforms/form_maths_space.lo \ ../xforms/FormMathsStyle.lo \ - ../xforms/form_maths_style.lo \ - ../xforms/lyxlookup.lo \ - ../xforms/MathsSymbols.lo \ + ../xforms/FormMinipage.lo \ + ../xforms/FormParagraph.lo \ + ../xforms/FormPreferences.lo \ + ../xforms/FormPrint.lo \ + ../xforms/FormRef.lo \ + ../xforms/forms_gettext.lo \ + ../xforms/FormSearch.lo \ + ../xforms/FormSendto.lo \ + ../xforms/FormShowFile.lo \ + ../xforms/FormSpellchecker.lo \ + ../xforms/FormTabular.lo \ + ../xforms/FormTexinfo.lo \ + ../xforms/FormThesaurus.lo \ + ../xforms/FormToc.lo \ + ../xforms/FormVCLog.lo \ + ../xforms/FormWrap.lo \ + ../xforms/input_validators.lo \ + ../xforms/LyXKeySymFactory.lo \ + ../xforms/LyXScreenFactory.lo \ ../xforms/Menubar_pimpl.lo \ + ../xforms/RadioButtonGroup.lo \ ../xforms/Toolbar_pimpl.lo \ ../xforms/Tooltips.lo \ + ../xforms/WorkAreaFactory.lo \ ../xforms/xfont_loader.lo \ ../xforms/xfont_metrics.lo \ ../xforms/xforms_helpers.lo \ ../xforms/xforms_resize.lo \ ../xforms/xformsBC.lo \ + ../xforms/xformsImage.lo \ ../xforms/XFormsView.lo \ + ../xforms/XLyXKeySym.lo \ + ../xforms/XMiniBuffer.lo \ ../xforms/XPainter.lo \ + ../xforms/xscreen.lo \ ../xforms/XWorkArea.lo \ - ../xforms/xformsImage.lo + ../xforms/forms/form_aboutlyx.lo \ + ../xforms/forms/form_bibitem.lo \ + ../xforms/forms/form_bibtex.lo \ + ../xforms/forms/form_browser.lo \ + ../xforms/forms/form_character.lo \ + ../xforms/forms/form_citation.lo \ + ../xforms/forms/form_document.lo \ + ../xforms/forms/form_error.lo \ + ../xforms/forms/form_ert.lo \ + ../xforms/forms/form_external.lo \ + ../xforms/forms/form_filedialog.lo \ + ../xforms/forms/form_float.lo \ + ../xforms/forms/form_forks.lo \ + ../xforms/forms/form_graphics.lo \ + ../xforms/forms/form_include.lo \ + ../xforms/forms/form_index.lo \ + ../xforms/forms/form_maths_delim.lo \ + ../xforms/forms/form_maths_matrix.lo \ + ../xforms/forms/form_maths_panel.lo \ + ../xforms/forms/form_maths_space.lo \ + ../xforms/forms/form_maths_style.lo \ + ../xforms/forms/form_minipage.lo \ + ../xforms/forms/form_paragraph.lo \ + ../xforms/forms/form_preamble.lo \ + ../xforms/forms/form_preferences.lo \ + ../xforms/forms/form_print.lo \ + ../xforms/forms/form_ref.lo \ + ../xforms/forms/form_search.lo \ + ../xforms/forms/form_sendto.lo \ + ../xforms/forms/form_spellchecker.lo \ + ../xforms/forms/form_tabular_create.lo \ + ../xforms/forms/form_tabular.lo \ + ../xforms/forms/form_texinfo.lo \ + ../xforms/forms/form_thesaurus.lo \ + ../xforms/forms/form_toc.lo \ + ../xforms/forms/form_url.lo \ + ../xforms/forms/form_wrap.lo -libgnome.la: xforms.lo $(libgnome_la_OBJECTS) $(libgnome_la_DEPENDENCIES) xforms.lo: $(xforms_objects) $(CXXLINK) $(xforms_objects) @@ -61,6 +124,9 @@ xforms.lo: $(xforms_objects) libgnome_la_SOURCES = \ Dialogs.C \ + Dialogs2.C \ + Dialogs_impl.h \ + FileDialog.C \ GAbout.C \ GAbout.h \ GError.C \ @@ -83,7 +149,9 @@ libgnome_la_SOURCES = \ GnomeBase.h \ gnomeBC.C \ gnomeBC.h \ - GUIRunTime.C \ - pixbutton.h \ + lyx_gui.C \ Timeout_pimpl.C \ - Timeout_pimpl.h + Timeout_pimpl.h \ + pixbutton.h + +libgnome.la: xforms.lo $(libgnome_la_OBJECTS) $(libgnome_la_DEPENDENCIES) diff --git a/src/frontends/gnome/Timeout_pimpl.C b/src/frontends/gnome/Timeout_pimpl.C index e68528f60c..d6c6ad6bcd 100644 --- a/src/frontends/gnome/Timeout_pimpl.C +++ b/src/frontends/gnome/Timeout_pimpl.C @@ -15,17 +15,15 @@ #pragma implementation #endif -#include +#include #include "Timeout_pimpl.h" #include "debug.h" - Timeout::Pimpl::Pimpl(Timeout * owner) - : owner_(owner) + : owner_(owner) { } - void Timeout::Pimpl::reset() { stop(); @@ -43,7 +41,7 @@ void Timeout::Pimpl::start() stop(); } - conn_ = Gtk::Main::signal_timeout().connect( + conn_ = Glib::signal_timeout().connect( SigC::slot(*this, &Timeout::Pimpl::timeoutEvent), owner_->timeout_ms ); diff --git a/src/frontends/gnome/dialogs/GAbout.glade b/src/frontends/gnome/dialogs/GAbout.glade index 28f59d8eef..93533fc7e7 100644 --- a/src/frontends/gnome/dialogs/GAbout.glade +++ b/src/frontends/gnome/dialogs/GAbout.glade @@ -113,7 +113,7 @@ True True GTK_JUSTIFY_LEFT - GTK_WRAP_NONE + GTK_WRAP_WORD True 0 0 @@ -165,7 +165,7 @@ True True GTK_JUSTIFY_LEFT - GTK_WRAP_NONE + GTK_WRAP_WORD True 0 0 diff --git a/src/frontends/gnome/gnome_helpers.C b/src/frontends/gnome/gnome_helpers.C index 3200987d6e..6d1f9268b9 100644 --- a/src/frontends/gnome/gnome_helpers.C +++ b/src/frontends/gnome/gnome_helpers.C @@ -12,3 +12,17 @@ #include "gnome_helpers.h" +#include + +void addDefaultTags(Glib::RefPtr & buf) { + Glib::RefPtr italicTag = Gtk::TextTag::create("italic"); + italicTag->property_style() = Pango::STYLE_ITALIC; + + Glib::RefPtr boldTag = Gtk::TextTag::create("bold"); + boldTag->property_weight() = Pango::WEIGHT_BOLD; + + buf->get_tag_table()->add(italicTag); + buf->get_tag_table()->add(boldTag); + +} + diff --git a/src/frontends/gnome/gnome_helpers.h b/src/frontends/gnome/gnome_helpers.h index d6793291fe..0177bdda39 100644 --- a/src/frontends/gnome/gnome_helpers.h +++ b/src/frontends/gnome/gnome_helpers.h @@ -22,4 +22,14 @@ #undef Value #undef DestroyNotify +#include + + +/** + * This helper function adds default tags to a TextBuffer + * + * Hopefully gtk will come with its own one day, but until then... + */ +void addDefaultTags(Glib::RefPtr &); + #endif diff --git a/src/frontends/gnome/lyx_gui.C b/src/frontends/gnome/lyx_gui.C new file mode 100644 index 0000000000..70bcade967 --- /dev/null +++ b/src/frontends/gnome/lyx_gui.C @@ -0,0 +1,397 @@ +/** + * \file xforms/lyx_gui.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author unknown + * \author John Levon + * + * Full author contact details are available in file CREDITS + */ + +#include + +#include "lyx_gui.h" + +#include "support/lyxlib.h" +#include "support/os.h" +#include "support/filetools.h" + +#include "debug.h" +#include "gettext.h" + +#include "lyx_main.h" +#include "lyxrc.h" +#include "lyxfont.h" + +// FIXME: move this stuff out again +#include "bufferlist.h" +#include "lyxfunc.h" +#include "lyxserver.h" +#include "BufferView.h" +#include "XFormsView.h" + +#include FORMS_H_LOCATION +#include "ColorHandler.h" +#include "xforms_helpers.h" +#include "xfont_loader.h" +#include "xformsImage.h" + +#include "Lsstream.h" +#include +#include +#include + +#include "gnome_helpers.h" +#include +#include + +#ifndef CXX_GLOBAL_CSTD +using std::exit; +#endif + +using std::vector; +using std::hex; +using std::dec; +using std::endl; +using std::setbase; +using std::setfill; +using std::setw; + +extern BufferList bufferlist; + +// FIXME: wrong place ! +LyXServer * lyxserver; + +namespace { + +/// quit lyx +bool finished = false; + +/// estimate DPI from X server +float getDPI() +{ + Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); + return ((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) + + (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2; +} + + +/// set default GUI configuration +void setDefaults() +{ + FL_IOPT cntl; + cntl.buttonFontSize = FL_NORMAL_SIZE; + cntl.browserFontSize = FL_NORMAL_SIZE; + cntl.labelFontSize = FL_NORMAL_SIZE; + cntl.choiceFontSize = FL_NORMAL_SIZE; + cntl.inputFontSize = FL_NORMAL_SIZE; + cntl.menuFontSize = FL_NORMAL_SIZE; + cntl.borderWidth = -1; + cntl.vclass = FL_DefaultVisual; + fl_set_defaults(FL_PDVisual + | FL_PDButtonFontSize + | FL_PDBrowserFontSize + | FL_PDLabelFontSize + | FL_PDChoiceFontSize + | FL_PDInputFontSize + | FL_PDMenuFontSize + | FL_PDBorderWidth, &cntl); +} + + +extern "C" { + +int LyX_XErrHandler(Display * display, XErrorEvent * xeev) { + // We don't abort on BadWindow + if (xeev->error_code == BadWindow) { + lyxerr << "BadWindow received !" << endl; + lyxerr << "If you're using xforms 1.0 or greater, " + << " please report this to lyx-devel@lists.lyx.org" << endl; + return 0; + } + + // emergency cleanup + LyX::emergencyCleanup(); + + // Get the reason for the crash. + char etxt[513]; + XGetErrorText(display, xeev->error_code, etxt, 512); + lyxerr << etxt << " id: " << xeev->resourceid << endl; + // By doing an abort we get a nice backtrace. (hopefully) + lyx::abort(); + return 0; +} + +} + +/// read in geometry specification +char geometry[40]; + +} // namespace anon + + +void lyx_gui::parse_init(int & argc, char * argv[]) +{ + setDefaults(); + + FL_CMD_OPT cmdopt[] = { + {"-geometry", "*.geometry", XrmoptionSepArg, "690x510"} + }; + + FL_resource res[] = { + {"geometry", "geometryClass", FL_STRING, geometry, "", 40} + }; + + const int num_res = sizeof(res)/sizeof(FL_resource); + + fl_initialize(&argc, argv, "LyX", cmdopt, num_res); + + // It appears that, in xforms >=0.89.5, fl_initialize() + // calls setlocale() and ruins our LC_NUMERIC setting. + locale_init(); + + fl_get_app_resources(res, num_res); + + Display * display = fl_get_display(); + + if (!display) { + lyxerr << "LyX: unable to access X display, exiting" << endl; + os::warn("Unable to access X display, exiting"); + ::exit(1); + } + + fcntl(ConnectionNumber(display), F_SETFD, FD_CLOEXEC); + + XSetErrorHandler(LyX_XErrHandler); + + lyxColorHandler.reset(new LyXColorHandler()); + + using namespace grfx; + + // connect the image loader based on the xforms library + Image::newImage = boost::bind(&xformsImage::newImage); + Image::loadableFormats = boost::bind(&xformsImage::loadableFormats); + + // must do this /before/ lyxrc gets read + lyxrc.dpi = getDPI(); + + new Gtk::Main (argc, argv); +} + + +void lyx_gui::parse_lyxrc() +{ + XformsColor::read(AddName(user_lyxdir, "preferences.xform")); + + if (lyxrc.popup_font_encoding.empty()) + lyxrc.popup_font_encoding = lyxrc.font_norm; + // Set the font name for popups and menus + string boldfontname = lyxrc.popup_bold_font + + "-*-*-*-?-*-*-*-*-" + + lyxrc.popup_font_encoding; + // "?" means "scale that font" + string fontname = lyxrc.popup_normal_font + + "-*-*-*-?-*-*-*-*-" + + lyxrc.popup_font_encoding; + + int bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str()); + int normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str()); + if (bold < 0) + lyxerr << "Could not set menu font to " + << boldfontname << endl; + + if (normal < 0) + lyxerr << "Could not set popup font to " + << fontname << endl; + + if (bold < 0 && normal < 0) { + lyxerr << "Using 'helvetica' font for menus" << endl; + boldfontname = "-*-helvetica-bold-r-*-*-*-?-*-*-*-*-iso8859-1"; + fontname = "-*-helvetica-medium-r-*-*-*-?-*-*-*-*-iso8859-1"; + bold = fl_set_font_name(FL_BOLD_STYLE, boldfontname.c_str()); + normal = fl_set_font_name(FL_NORMAL_STYLE, fontname.c_str()); + + if (bold < 0 && normal < 0) { + lyxerr << "Could not find helvetica font. Using 'fixed'." << endl; + fl_set_font_name(FL_NORMAL_STYLE, "fixed"); + normal = bold = 0; + } + } + if (bold < 0) + fl_set_font_name(FL_BOLD_STYLE, fontname.c_str()); + else if (normal < 0) + fl_set_font_name(FL_NORMAL_STYLE, boldfontname.c_str()); + + fl_setpup_fontstyle(FL_NORMAL_STYLE); + fl_setpup_fontsize(FL_NORMAL_SIZE); + fl_setpup_color(FL_MCOL, FL_BLACK); + fl_set_goodies_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE); + fl_set_tooltip_font(FL_NORMAL_STYLE, FL_NORMAL_SIZE); +} + +void lyx_gui::start(string const & batch, vector const & files) +{ + // initial geometry + int xpos = -1; + int ypos = -1; + unsigned int width = 690; + unsigned int height = 510; + + int const geometryBitmask = + XParseGeometry(geometry, + &xpos, &ypos, &width, &height); + + // if width is not set by geometry, check it against monitor width + if (!(geometryBitmask & WidthValue)) { + Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); + if (WidthOfScreen(scr) - 8 < int(width)) + width = WidthOfScreen(scr) - 8; + } + + // if height is not set by geometry, check it against monitor height + if (!(geometryBitmask & HeightValue)) { + Screen * scr = ScreenOfDisplay(fl_get_display(), fl_screen); + if (HeightOfScreen(scr) - 24 < int(height)) + height = HeightOfScreen(scr) - 24; + } + + Screen * s = ScreenOfDisplay(fl_get_display(), fl_screen); + + // recalculate xpos if it's not set + if (xpos == -1) + xpos = (WidthOfScreen(s) - width) / 2; + + // recalculate ypos if it's not set + if (ypos == -1) + ypos = (HeightOfScreen(s) - height) / 2; + + lyxerr[Debug::GUI] << "Creating view: " << width << 'x' << height + << '+' << xpos << '+' << ypos << endl; + + XFormsView view(width, height); + view.show(xpos, ypos, "LyX"); + view.init(); + + Buffer * last = 0; + + // FIXME: some code below needs moving + + lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes); + + vector::const_iterator cit = files.begin(); + vector::const_iterator end = files.end(); + for (; cit != end; ++cit) { + Buffer * b = bufferlist.loadLyXFile(*cit); + if (b) { + last = b; + } + } + + // switch to the last buffer successfully loaded + if (last) { + view.view()->buffer(last); + } + + // handle the batch commands the user asked for + if (!batch.empty()) { + view.getLyXFunc().dispatch(batch); + } + + // enter the event loop + while (!finished) { + while (Gtk::Main::events_pending()) + Gtk::Main::iteration(false); + if (fl_check_forms() == FL_EVENT) { + XEvent ev; + fl_XNextEvent(&ev); + lyxerr[Debug::GUI] + << "Received unhandled X11 event" << endl + << "Type: " << ev.xany.type + << " Target: 0x" << hex << ev.xany.window + << dec << endl; + } + + } + + // FIXME: breaks emergencyCleanup + delete lyxserver; +} + +void lyx_gui::exit() +{ + finished = true; +} + + +FuncStatus lyx_gui::getStatus(FuncRequest const & /*ev*/) +{ + // Nothing interesting to do here + return FuncStatus(); +} + +string const lyx_gui::hexname(LColor::color col) +{ + string const name = lcolor.getX11Name(col); + Display * const display = fl_get_display(); + Colormap const cmap = fl_state[fl_get_vclass()].colormap; + XColor xcol, ccol; + + if (XLookupColor(display, cmap, name.c_str(), &xcol, &ccol) == 0) { + lyxerr << "X can't find color \"" + << lcolor.getLyXName(col) + << '"' << endl; + return string(); + } + + ostringstream os; + + // Note that X stores the RGB values in the range 0 - 65535 + // whilst we require them in the range 0 - 255. + os << setbase(16) << setfill('0') + << setw(2) << (xcol.red / 256) + << setw(2) << (xcol.green / 256) + << setw(2) << (xcol.blue / 256); + + return STRCONV(os.str()); +} + + +void lyx_gui::update_color(LColor::color col) +{ + lyxColorHandler->updateColor(col); +} + + +void lyx_gui::update_fonts() +{ + fontloader.update(); +} + + +bool lyx_gui::font_available(LyXFont const & font) +{ + return fontloader.available(font); +} + +namespace { + +extern "C" +void C_read_callback(int, void * data) +{ + LyXComm * comm = static_cast(data); + comm->read_ready(); +} + +} + +void lyx_gui::set_read_callback(int fd, LyXComm * comm) +{ + fl_add_io_callback(fd, FL_READ, C_read_callback, comm); +} + + +void lyx_gui::remove_read_callback(int fd) +{ + fl_remove_io_callback(fd, FL_READ, C_read_callback); +}