From 063994371eb9d3465ddeda0a41aa450f891043be Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Fri, 22 Sep 2006 21:00:42 +0000 Subject: [PATCH] make it compile again git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15132 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/GView.C | 2 +- src/frontends/gtk/GView.h | 2 +- src/frontends/gtk/GWorkArea.C | 31 ------- src/frontends/gtk/GWorkArea.h | 4 - src/frontends/gtk/GuiApplication.C | 125 ++++++++++++++++++++++++++ src/frontends/gtk/GuiApplication.h | 80 +++++++++++++++++ src/frontends/gtk/GuiImplementation.C | 4 +- src/frontends/gtk/GuiImplementation.h | 16 ---- src/frontends/gtk/GuiSelection.C | 39 ++++++++ src/frontends/gtk/GuiSelection.h | 17 ++-- src/frontends/gtk/Makefile.am | 2 + src/frontends/gtk/lyx_gui.C | 79 +++------------- 12 files changed, 267 insertions(+), 134 deletions(-) create mode 100644 src/frontends/gtk/GuiApplication.C create mode 100644 src/frontends/gtk/GuiApplication.h diff --git a/src/frontends/gtk/GView.C b/src/frontends/gtk/GView.C index d38a91ac46..dae159db6a 100644 --- a/src/frontends/gtk/GView.C +++ b/src/frontends/gtk/GView.C @@ -59,7 +59,7 @@ void add_el(Gtk::Box::BoxList & list, Gtk::Box & box, bool shrink) } // namespace anon -GView::GView(Gui & owner) : LyXView(owner) +GView::GView() : LyXView() { // The physical store for the boxes making up the layout. box_store_.push_back(BoxPtr(new Gtk::VBox)); diff --git a/src/frontends/gtk/GView.h b/src/frontends/gtk/GView.h index e73b45eafd..655cdb4646 100644 --- a/src/frontends/gtk/GView.h +++ b/src/frontends/gtk/GView.h @@ -35,7 +35,7 @@ public: Center }; - GView(Gui & owner); + GView(); ~GView(); Gtk::Box & getBox(Position pos); diff --git a/src/frontends/gtk/GWorkArea.C b/src/frontends/gtk/GWorkArea.C index 3867841a25..9b4e3585fb 100644 --- a/src/frontends/gtk/GWorkArea.C +++ b/src/frontends/gtk/GWorkArea.C @@ -493,36 +493,5 @@ bool GWorkArea::onKeyPress(GdkEventKey * event) return true; } - -void GWorkArea::onClipboardGet(Gtk::SelectionData & /*selection_data*/, - guint /*info*/) -{ - lyx::docstring const sel = view_.view()->requestSelection(); - if (!sel.empty()) - view_.gui().selection().put(sel); -} - - -void GWorkArea::onClipboardClear() -{ -// clearSelection(); -} - - -void GWorkArea::haveSelection(bool toHave) -{ - if (toHave) { - Glib::RefPtr clipboard = - Gtk::Clipboard::get(GDK_SELECTION_PRIMARY); - std::vector listTargets; - listTargets.push_back(Gtk::TargetEntry("UTF8_STRING")); - clipboard->set(listTargets, - sigc::mem_fun(const_cast(*this), - &GWorkArea::onClipboardGet), - sigc::mem_fun(const_cast(*this), - &GWorkArea::onClipboardClear)); - } -} - } // namespace frontend } // namespace lyx diff --git a/src/frontends/gtk/GWorkArea.h b/src/frontends/gtk/GWorkArea.h index 3ee079c23a..aef07a4349 100644 --- a/src/frontends/gtk/GWorkArea.h +++ b/src/frontends/gtk/GWorkArea.h @@ -82,8 +82,6 @@ public: ColorHandler & getColorHandler(); virtual void setScrollbarParams(int height, int pos, int line_height); - /// a selection exists - virtual void haveSelection(bool); void inputCommit(gchar * str); LyXView & view() @@ -100,8 +98,6 @@ private: bool onButtonRelease(GdkEventButton * event); bool onMotionNotify(GdkEventMotion * event); bool onKeyPress(GdkEventKey * event); - void onClipboardGet(Gtk::SelectionData & selection_data, guint info); - void onClipboardClear(); LyXView & view_; Gtk::HBox hbox_; Gtk::DrawingArea workArea_; diff --git a/src/frontends/gtk/GuiApplication.C b/src/frontends/gtk/GuiApplication.C new file mode 100644 index 0000000000..6ef58f073a --- /dev/null +++ b/src/frontends/gtk/GuiApplication.C @@ -0,0 +1,125 @@ +/** + * \file qt4/GuiApplication.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author unknown + * \author John Levon + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "GuiApplication.h" + +#include "GView.h" +#include "GuiWorkArea.h" +#include "GtkmmX.h" + +#include "BufferView.h" + +#include "graphics/LoaderQueue.h" + +#include "support/lstrings.h" +#include "support/os.h" +#include "support/package.h" + +#include "lyx_main.h" +#include "lyxrc.h" +#include "debug.h" + +#include + +#include "LyXGdkImage.h" + + +using lyx::support::subst; + +using std::string; +using std::endl; + + +namespace { + +/// estimate DPI from X server +int getDPI() +{ + //TODO use GDK instead + Screen * scr = ScreenOfDisplay(getDisplay(), getScreen()); + return int(((HeightOfScreen(scr) * 25.4 / HeightMMOfScreen(scr)) + + (WidthOfScreen(scr) * 25.4 / WidthMMOfScreen(scr))) / 2); +} + +} // namespace anon + + +namespace lyx { +namespace frontend { + +GuiApplication::GuiApplication(int & argc, char ** argv) + : Gtk::Main(argc, argv), Application(argc, argv) +{ + using namespace lyx::graphics; + Image::newImage = boost::bind(&LyXGdkImage::newImage); + Image::loadableFormats = boost::bind(&LyXGdkImage::loadableFormats); + + // needs to be done before reading lyxrc + lyxrc.dpi = getDPI(); + + LoaderQueue::setPriority(10,100); +} + + +Clipboard& GuiApplication::clipboard() +{ + return clipboard_; +} + + +Selection& GuiApplication::selection() +{ + return selection_; +} + + +int const GuiApplication::exec() +{ + run(); + return EXIT_SUCCESS; +} + + +void GuiApplication::exit(int /*status*/) +{ + // FIXME: Don't ignore status + guiApp->quit(); +} + + +// FIXME: this whole method needs to be moved to Application. +LyXView & GuiApplication::createView(unsigned int width, + unsigned int height, + int posx, int posy, + bool maximize) +{ + // FIXME: for now we assume that there is only one LyXView with id = 0. + /*int workArea_id_ =*/ gui().newWorkArea(width, height, 0); + //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_); + + int view_id = gui().newView(width, height); + GView & view = static_cast(gui().view(view_id)); + + lyxfunc_.reset(new LyXFunc(&view)); + + LyX::ref().addLyXView(&view); + + view.show(); + view.init(); + + return view; +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/gtk/GuiApplication.h b/src/frontends/gtk/GuiApplication.h new file mode 100644 index 0000000000..c90bfa68cd --- /dev/null +++ b/src/frontends/gtk/GuiApplication.h @@ -0,0 +1,80 @@ +/** + * \file gtk/GuiApplication.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author unknown + * \author John Levon + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef GTK_APPLICATION_H +#define GTK_APPLICATION_H + +#include "GuiClipboard.h" +#include "GuiImplementation.h" +#include "GuiSelection.h" +#include "xftFontLoader.h" + +#include "frontends/Application.h" + +#include + +/////////////////////////////////////////////////////////////// + +class BufferView; + +namespace lyx { +namespace frontend { + +class GuiWorkArea; + +/// The Gtk main application class +/** +There should be only one instance of this class. No Gtk object +initialisation should be done before the instanciation of this class. + +\todo The work areas handling could be moved to a base virtual class +comon to all frontends. +*/ +class GuiApplication : public Gtk::Main, public Application +{ +public: + GuiApplication(int & argc, char ** argv); + + /// Method inherited from \c Application class + //@{ + virtual Clipboard& clipboard(); + virtual Selection& selection(); + virtual int const exec(); + virtual Gui & gui() { return gui_; } + virtual void exit(int status); + //@} + + /// + xftFontLoader & fontLoader() { return font_loader_; } + + /// + LyXView & createView(unsigned int width, unsigned int height, + int posx, int posy, bool maximize); + +private: + /// + GuiImplementation gui_; + /// + GuiClipboard clipboard_; + /// + GuiSelection selection_; + /// + xftFontLoader font_loader_; +}; // GuiApplication + +} // namespace frontend +} // namespace lyx + +extern lyx::frontend::GuiApplication * guiApp; + + +#endif // GTK_APPLICATION_H diff --git a/src/frontends/gtk/GuiImplementation.C b/src/frontends/gtk/GuiImplementation.C index 6a350c9e78..1e903216d8 100644 --- a/src/frontends/gtk/GuiImplementation.C +++ b/src/frontends/gtk/GuiImplementation.C @@ -32,7 +32,7 @@ namespace frontend { int GuiImplementation::newView(unsigned int /*w*/, unsigned int /*h*/) { - view_.reset(new GView(*this)); + view_.reset(new GView); return 0; } @@ -42,7 +42,6 @@ int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int /*view_id old_work_area_.reset(new GWorkArea(*view_.get(), w, h)); old_screen_.reset(new GScreen(*old_work_area_.get())); work_area_.reset(new GuiWorkArea(old_screen_.get(), old_work_area_.get())); - selection_.reset(new GuiSelection(old_work_area_.get())); // FIXME BufferView creation should be independant of WorkArea creation buffer_views_[0].reset(new BufferView(view_.get())); @@ -54,7 +53,6 @@ int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int /*view_id void GuiImplementation::destroyWorkArea(int /*id*/) { - selection_.reset(); work_area_.reset(); old_work_area_.reset(); old_screen_.reset(); diff --git a/src/frontends/gtk/GuiImplementation.h b/src/frontends/gtk/GuiImplementation.h index c102bf50e3..e18a760678 100644 --- a/src/frontends/gtk/GuiImplementation.h +++ b/src/frontends/gtk/GuiImplementation.h @@ -18,8 +18,6 @@ #include "GScreen.h" #include "GWorkArea.h" -#include "GuiClipboard.h" -#include "GuiSelection.h" #include "GuiWorkArea.h" #include @@ -41,16 +39,6 @@ public: { } - lyx::frontend::Clipboard & clipboard() - { - return clipboard_; - } - - lyx::frontend::Selection & selection() - { - return *selection_; - } - int newView(unsigned int w, unsigned int h); LyXView & view(int /*id*/) @@ -73,10 +61,6 @@ public: void destroyWorkArea(int /*id*/); private: - /// - GuiClipboard clipboard_; - /// - boost::shared_ptr selection_; /// boost::shared_ptr work_area_; /// diff --git a/src/frontends/gtk/GuiSelection.C b/src/frontends/gtk/GuiSelection.C index 350c08ccdd..c1193f1ece 100644 --- a/src/frontends/gtk/GuiSelection.C +++ b/src/frontends/gtk/GuiSelection.C @@ -21,8 +21,14 @@ #endif #include "GuiSelection.h" + +#include "BufferView.h" #include "debug.h" +#include "frontends/Application.h" +#include "frontends/Gui.h" +#include "frontends/LyXView.h" + #include using std::endl; @@ -50,5 +56,38 @@ void GuiSelection::put(docstring const & str) clipboard->set_text(utf8); } + +void GuiSelection::onClipboardGet(Gtk::SelectionData & /*selection_data*/, + guint /*info*/) +{ + // FIXME: This assumes only one LyXView + lyx::docstring const sel = theApp->gui().view(0).view()->requestSelection(); + if (!sel.empty()) + put(sel); +} + + +void GuiSelection::onClipboardClear() +{ + // FIXME: This assumes only one LyXView + theApp->gui().view(0).view()->clearSelection(); +} + + +void GuiSelection::haveSelection(bool toHave) +{ + if (toHave) { + Glib::RefPtr clipboard = + Gtk::Clipboard::get(GDK_SELECTION_PRIMARY); + std::vector listTargets; + listTargets.push_back(Gtk::TargetEntry("UTF8_STRING")); + clipboard->set(listTargets, + sigc::mem_fun(const_cast(*this), + &GuiSelection::onClipboardGet), + sigc::mem_fun(const_cast(*this), + &GuiSelection::onClipboardClear)); + } +} + } // namespace frontend } // namespace lyx diff --git a/src/frontends/gtk/GuiSelection.h b/src/frontends/gtk/GuiSelection.h index 6d2118deab..544605507c 100644 --- a/src/frontends/gtk/GuiSelection.h +++ b/src/frontends/gtk/GuiSelection.h @@ -14,7 +14,8 @@ #include "frontends/Selection.h" -#include "GWorkArea.h" +#include +#include namespace lyx { namespace frontend { @@ -25,28 +26,22 @@ namespace frontend { class GuiSelection: public lyx::frontend::Selection { public: - GuiSelection(GWorkArea * work_area) - : old_work_area_(work_area) - { - } + GuiSelection() {} virtual ~GuiSelection() {} /** Selection overloaded methods */ //@{ - void haveSelection(bool own) - { - old_work_area_->haveSelection(own); - } + void haveSelection(bool own); docstring const get() const; void put(docstring const & str); //@} - private: - GWorkArea * old_work_area_; + void onClipboardGet(Gtk::SelectionData & selection_data, guint info); + void onClipboardClear(); }; } // namespace frontend diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index 7351f5798a..718f4bc1ec 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -138,6 +138,8 @@ libgtk_la_SOURCES = \ LyXKeySymFactory.C \ ghelpers.C \ ghelpers.h \ + GuiApplication.C \ + GuiApplication.h \ GuiImplementation.h \ GuiImplementation.C \ io_callback.C \ diff --git a/src/frontends/gtk/lyx_gui.C b/src/frontends/gtk/lyx_gui.C index 3076e741f8..23d3de2c87 100644 --- a/src/frontends/gtk/lyx_gui.C +++ b/src/frontends/gtk/lyx_gui.C @@ -37,17 +37,16 @@ #include "io_callback.h" // FIXME: move this stuff out again -#include "bufferlist.h" #include "lyxfunc.h" #include "lyxserver.h" #include "lyxsocket.h" #include "BufferView.h" +#include "GuiApplication.h" #include "GuiImplementation.h" #include "GView.h" #include "GtkmmX.h" -#include "xftFontLoader.h" #include "GWorkArea.h" #include "support/lyxlib.h" @@ -57,8 +56,6 @@ #include -#include "LyXGdkImage.h" - #include #include #include @@ -77,16 +74,11 @@ using lyx::support::package; using lyx::frontend::colorCache; using lyx::frontend::Gui; +using lyx::frontend::GuiApplication; using lyx::frontend::GuiImplementation; using lyx::frontend::GView; -extern BufferList bufferlist; - -// FIXME: wrong place ! -LyXServer * lyxserver; -LyXServerSocket * lyxsocket; - bool lyx_gui::use_gui = true; namespace { @@ -102,34 +94,13 @@ int getDPI() } // namespace anon -class Application: public Gtk::Main -{ -public: - /// - Application(int & argc, char * argv[]): Gtk::Main(argc, argv) - {} - /// - Gui & gui() { return gui_; } - -private: - /// - GuiImplementation gui_; -}; - -Application * theApp; +lyx::frontend::Application * theApp; +GuiApplication * guiApp; int lyx_gui::exec(int & argc, char * argv[]) { - theApp = new Application(argc, argv); - - using namespace lyx::graphics; - Image::newImage = boost::bind(&LyXGdkImage::newImage); - Image::loadableFormats = boost::bind(&LyXGdkImage::loadableFormats); - - locale_init(); - - // must do this /before/ lyxrc gets read - lyxrc.dpi = getDPI(); + guiApp = new GuiApplication(argc, argv); + theApp = guiApp; return LyX::ref().exec2(argc, argv); } @@ -141,47 +112,21 @@ void lyx_gui::parse_lyxrc() LyXView * lyx_gui::create_view(unsigned int width, unsigned int height, - int /*posx*/, int /*posy*/, bool) + int posx, int posy, bool maximize) { - int view_id = theApp->gui().newView(width, height); - GView & view = static_cast (theApp->gui().view(view_id)); - theApp->gui().newWorkArea(width, height, 0); - - LyX::ref().addLyXView(&view); - - view.show(); - view.init(); - - return &view; + return &guiApp->createView(width, height, posx, posy, maximize); } -int lyx_gui::start(LyXView * view, string const & batch) +int lyx_gui::start(LyXView *, string const & batch) { - // FIXME: server code below needs moving - - lyxserver = new LyXServer(&view->getLyXFunc(), lyxrc.lyxpipes); - lyxsocket = new LyXServerSocket(&view->getLyXFunc(), - os::internal_path(package().temp_dir() + "/lyxsocket")); - - // handle the batch commands the user asked for - if (!batch.empty()) { - view->getLyXFunc().dispatch(lyxaction.lookupFunc(batch)); - } - - theApp->run(); - - // FIXME: breaks emergencyCleanup - delete lyxsocket; - delete lyxserver; - return EXIT_SUCCESS; + return guiApp->start(batch); } -void lyx_gui::exit(int /*status*/) +void lyx_gui::exit(int status) { - // FIXME: Don't ignore status - theApp->quit(); + guiApp->exit(status); } -- 2.39.2