} // 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));
Center
};
- GView(Gui & owner);
+ GView();
~GView();
Gtk::Box & getBox(Position pos);
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<Gtk::Clipboard> clipboard =
- Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
- std::vector<Gtk::TargetEntry> listTargets;
- listTargets.push_back(Gtk::TargetEntry("UTF8_STRING"));
- clipboard->set(listTargets,
- sigc::mem_fun(const_cast<GWorkArea&>(*this),
- &GWorkArea::onClipboardGet),
- sigc::mem_fun(const_cast<GWorkArea&>(*this),
- &GWorkArea::onClipboardClear));
- }
-}
-
} // namespace frontend
} // namespace lyx
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()
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_;
--- /dev/null
+/**
+ * \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 <config.h>
+
+#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 <gtkmm.h>
+
+#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<GView &>(gui().view(view_id));
+
+ lyxfunc_.reset(new LyXFunc(&view));
+
+ LyX::ref().addLyXView(&view);
+
+ view.show();
+ view.init();
+
+ return view;
+}
+
+} // namespace frontend
+} // namespace lyx
--- /dev/null
+/**
+ * \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 <gtkmm.h>
+
+///////////////////////////////////////////////////////////////
+
+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
int GuiImplementation::newView(unsigned int /*w*/, unsigned int /*h*/)
{
- view_.reset(new GView(*this));
+ view_.reset(new GView);
return 0;
}
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()));
void GuiImplementation::destroyWorkArea(int /*id*/)
{
- selection_.reset();
work_area_.reset();
old_work_area_.reset();
old_screen_.reset();
#include "GScreen.h"
#include "GWorkArea.h"
-#include "GuiClipboard.h"
-#include "GuiSelection.h"
#include "GuiWorkArea.h"
#include <boost/shared_ptr.hpp>
{
}
- lyx::frontend::Clipboard & clipboard()
- {
- return clipboard_;
- }
-
- lyx::frontend::Selection & selection()
- {
- return *selection_;
- }
-
int newView(unsigned int w, unsigned int h);
LyXView & view(int /*id*/)
void destroyWorkArea(int /*id*/);
private:
- ///
- GuiClipboard clipboard_;
- ///
- boost::shared_ptr<GuiSelection> selection_;
///
boost::shared_ptr<GuiWorkArea> work_area_;
///
#endif
#include "GuiSelection.h"
+
+#include "BufferView.h"
#include "debug.h"
+#include "frontends/Application.h"
+#include "frontends/Gui.h"
+#include "frontends/LyXView.h"
+
#include <gtkmm.h>
using std::endl;
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<Gtk::Clipboard> clipboard =
+ Gtk::Clipboard::get(GDK_SELECTION_PRIMARY);
+ std::vector<Gtk::TargetEntry> listTargets;
+ listTargets.push_back(Gtk::TargetEntry("UTF8_STRING"));
+ clipboard->set(listTargets,
+ sigc::mem_fun(const_cast<GuiSelection&>(*this),
+ &GuiSelection::onClipboardGet),
+ sigc::mem_fun(const_cast<GuiSelection&>(*this),
+ &GuiSelection::onClipboardClear));
+ }
+}
+
} // namespace frontend
} // namespace lyx
#include "frontends/Selection.h"
-#include "GWorkArea.h"
+#include <gtkmm.h>
+#include <gtk/gtk.h>
namespace lyx {
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
LyXKeySymFactory.C \
ghelpers.C \
ghelpers.h \
+ GuiApplication.C \
+ GuiApplication.h \
GuiImplementation.h \
GuiImplementation.C \
io_callback.C \
#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"
#include <gtkmm.h>
-#include "LyXGdkImage.h"
-
#include <boost/bind.hpp>
#include <boost/function.hpp>
#include <boost/shared_ptr.hpp>
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 {
} // 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);
}
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<GView &> (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);
}