Hello,
Here is the next step on my GUI API cleanup. Only qt4 for now.
Committed to the "younes" branch. Comments welcome.
Abdel.
Log:
* BufferView::BufferView(LyXView * owner, lyx::frontend::WorkArea *
workArea)
- now need a valid WorkArea on construction
- but no more need for width and height
* BufferView_pimpl::BufferView_pimpl:
- as above plus WorkArea creation is not done there anymore.
The goal is to void the need for this WorkArea pointer.
WorkArea shall use the BufferView and not the other way around.
* LyXView:
- buffer_view_ is now a simple (BufferView *) that can be set via the
setBufferView() method.
This buffer_view_ member should go eventually.
- new "Gui & owner_" member set on construction.
* qt4/GuiView:
- implememted above LyXView changes.
- GuiView::init() new method overloaded from LyXView::init()
* controllers/Kernel.C: adapted to LyXView changes.
* importer.C: ditto
* lyx_main.[Ch]: ditto
* lyxfunc.C: ditto
* Action.C: added frontends/ path to #include
* Application.h:
- font_loader_: new FontLoader member that replace the global one.
- gui_ : new GuiImplementation member that replace the instance in
GuiView
* qt4/FontLoader.h: removed the global variable.
* qt4/qfont_metrics.C: adapted to FontLoader and Application Change
* qt4/QLPainter.C: ditto
* frontends/Gui :
- 3 new pure virtual methods that handle the LyXView creation/deletion
and reference.
- buffer_views_ : contains the needed BufferViews
* qt4/GuiImplementation:
- now manage also GuiView and BufferView creations. For now a new
BufferView is created at the same time as a WorkArea but this might
change in the feature.
* frontends/WorkArea:
- WorkArea::WorkArea() now only need a BufferView (no more LyXView)
- BufferView * buffer_view_: new member.
* frontends/qt4/GuiWorkArea: implemented the above changes.
* qt4/lyx_gui.C :
- a new LyXView and a new WorkArea are created there using theApp->Gui()
- use theApp->fontLoader()
* lyx_main.h: now needs a simple (LyXView *).
Index: BufferView.C
===================================================================
--- BufferView.C (revision 14165)
+++ BufferView.C (working copy)
@@ -48,6 +48,7 @@
#include "insets/insetcommand.h" // ChangeRefs
#include "insets/insettext.h"
+
using lyx::support::bformat;
using lyx::cap::setSelectionRange;
@@ -61,8 +62,8 @@
extern BufferList bufferlist;
-BufferView::BufferView(LyXView * owner, int width, int height)
- : pimpl_(new Pimpl(*this, owner, width, height))
+BufferView::BufferView(LyXView * owner, lyx::frontend::WorkArea * workArea)
+ : pimpl_(new Pimpl(*this, owner, workArea))
{}
Index: BufferView.h
===================================================================
--- BufferView.h (revision 14165)
+++ BufferView.h (working copy)
@@ -38,6 +38,7 @@
namespace lyx {
namespace frontend {
class Painter;
+class WorkArea;
}
}
@@ -76,7 +77,7 @@
* Create a view with the given owner main window,
* of the given dimensions.
*/
- BufferView(LyXView * owner, int w, int h);
+ BufferView(LyXView * owner, lyx::frontend::WorkArea * workArea);
~BufferView();
@@ -186,10 +187,10 @@
///
void workAreaResize();
+
+ /// Receive a keypress
+ void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
- /// Receive a keypress
- void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
-
/// a function should be executed from the workarea
bool workAreaDispatch(FuncRequest const & ev);
Index: BufferView_pimpl.C
===================================================================
--- BufferView_pimpl.C (revision 14165)
+++ BufferView_pimpl.C (working copy)
@@ -137,23 +137,19 @@
} // anon namespace
-BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner,
- int width, int height)
- : bv_(&bv), owner_(owner), buffer_(0), wh_(0), cursor_timeout(400),
+BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner, WorkArea * workArea)
+ : bv_(&bv), owner_(owner), workArea_(workArea), buffer_(0), wh_(0),
cursor_timeout(400),
using_xterm_cursor(false), cursor_(bv),
anchor_ref_(0), offset_ref_(0)
{
xsel_cache_.set = false;
- workAreaId_ = owner_->gui().newWorkArea(width, height);
- workArea_ = & owner_->gui().workArea(workAreaId_);
-
// Setup the signals
timecon = cursor_timeout.timeout
.connect(boost::bind(&BufferView::Pimpl::cursorToggle, this));
-
+
cursor_timeout.start();
-
+
saved_positions.resize(saved_positions_num);
// load saved bookmarks
lyx::Session::BookmarkList & bmList =
LyX::ref().session().loadBookmarks();
@@ -583,7 +579,7 @@
// scrollDocView(new_top_y);
//
// // Update the scrollbar.
-// workArea_->.setScrollbarParams(t->height(), top_y(),
defaultRowHeight());
+// workArea_->setScrollbarParams(t->height(), top_y(), defaultRowHeight());
}
Index: BufferView_pimpl.h
===================================================================
--- BufferView_pimpl.h (revision 14165)
+++ BufferView_pimpl.h (working copy)
@@ -57,7 +57,7 @@
class BufferView::Pimpl : public boost::signals::trackable {
public:
///
- Pimpl(BufferView & bv, LyXView * owner, int width, int height);
+ Pimpl(BufferView & bv, LyXView * owner, lyx::frontend::WorkArea *
workArea);
///
lyx::frontend::Painter & painter() const;
///
@@ -192,7 +192,7 @@
void menuInsertLyXFile(std::string const & filen);
lyx::frontend::WorkArea * workArea_;
- int workAreaId_;
/// this is used to handle XSelection events in the right manner
struct {
Index: frontends/controllers/Kernel.C
===================================================================
--- frontends/controllers/Kernel.C (revision 14165)
+++ frontends/controllers/Kernel.C (working copy)
@@ -49,7 +49,7 @@
bool Kernel::isBufferAvailable() const
{
- if (!lyxview_.view().get())
+ if (!lyxview_.view())
return false;
return lyxview_.view()->available();
}
@@ -90,13 +90,13 @@
BufferView * Kernel::bufferview()
{
- return lyxview_.view().get();
+ return lyxview_.view();
}
BufferView const * Kernel::bufferview() const
{
- return lyxview_.view().get();
+ return lyxview_.view();
}
Index: frontends/Gui.h
===================================================================
--- frontends/Gui.h (revision 14165)
+++ frontends/Gui.h (working copy)
@@ -16,6 +16,10 @@
#include "frontends/GuiCursor.h"
+#include <boost/shared_ptr.hpp>
+
+class LyXView;
+
namespace lyx {
namespace frontend {
@@ -33,9 +37,17 @@
///
virtual Clipboard& clipboard() = 0;
+
///
- virtual int newWorkArea(int w, int h) = 0;
+ virtual int newView(unsigned int width, unsigned int height) = 0;
///
+ virtual LyXView& view(int id) = 0;
+ ///
+ virtual void destroyView(int id) = 0;
+
+ ///
+ virtual int newWorkArea(unsigned int width, unsigned int height, int
view_id) = 0;
+ ///
virtual WorkArea& workArea(int id) = 0;
///
virtual void destroyWorkArea(int id) = 0;
@@ -43,7 +55,12 @@
///
GuiCursor & guiCursor() {return cursor_;}
+protected:
+ /// view of a buffer. Eventually there will be several.
+ std::map<int, boost::shared_ptr<BufferView> > buffer_views_;
+
private:
+ ///
GuiCursor cursor_;
};
Index: frontends/LyXView.C
===================================================================
--- frontends/LyXView.C (revision 14165)
+++ frontends/LyXView.C (working copy)
@@ -12,6 +12,7 @@
#include <config.h>
#include "LyXView.h"
+#include "Gui.h"
#include "Dialogs.h"
#include "Timeout.h"
#include "Toolbars.h"
@@ -46,6 +47,8 @@
# include <unistd.h>
#endif
+using lyx::frontend::Gui;
+
using lyx::support::makeDisplayPath;
using lyx::support::onlyFilename;
@@ -56,19 +59,30 @@
string current_layout;
+Gui & LyXView::gui()
+{
+ return owner_;
+}
-LyXView::LyXView()
- : toolbars_(new Toolbars(*this)),
+LyXView::LyXView(Gui & owner)
+ : owner_(owner),
+ toolbars_(new Toolbars(*this)),
intl_(new Intl),
autosave_timeout_(new Timeout(5000)),
lyxfunc_(new LyXFunc(this)),
dialogs_(new Dialogs(*this)),
- controlcommand_(new ControlCommandBuffer(*this))
+ controlcommand_(new ControlCommandBuffer(*this)),
+ bufferview_(0)
{
lyxerr[Debug::INIT] << "Initializing LyXFunc" << endl;
}
+void LyXView::setBufferView(BufferView * buffer_view)
+{
+ bufferview_ = buffer_view;
+}
+
LyXView::~LyXView()
{
}
@@ -96,7 +110,7 @@
}
-boost::shared_ptr<BufferView> const & LyXView::view() const
+BufferView * LyXView::view() const
{
return bufferview_;
}
@@ -132,7 +146,7 @@
lyxerr[Debug::INFO] << "Running autoSave()" << endl;
if (view()->available()) {
- ::autoSave(view().get());
+ ::autoSave(view());
}
}
Index: frontends/LyXView.h
===================================================================
--- frontends/LyXView.h (revision 14165)
+++ frontends/LyXView.h (working copy)
@@ -33,12 +33,8 @@
class FuncRequest;
namespace lyx {
-
namespace frontend {
class Gui;
-} // namespace frontend
-
-namespace frontend {
class ControlCommandBuffer;
} // namespace frontend
@@ -60,10 +56,12 @@
class LyXView : public boost::signals::trackable, boost::noncopyable {
public:
- LyXView();
+ LyXView(lyx::frontend::Gui & owner);
virtual ~LyXView();
+ void setBufferView(BufferView * buffer_view);
+
/**
* This is called after the concrete view has been created.
* We have to have the toolbar and the other stuff created
@@ -80,7 +78,7 @@
Returned as a shared_ptr so that anything wanting to cache the
buffer view can do so safely using a boost::weak_ptr.
*/
- boost::shared_ptr<BufferView> const & view() const;
+ BufferView * view() const;
/// return the buffer currently shown in this window
Buffer * buffer() const;
@@ -148,19 +146,24 @@
*/
Buffer const * const updateInset(InsetBase const *) const;
- // returns true if this view has the focus.
+ /// returns true if this view has the focus.
virtual bool hasFocus() const = 0;
- virtual lyx::frontend::Gui & gui() = 0;
+ ///
+ virtual lyx::frontend::Gui & gui();
protected:
- /// view of a buffer. Eventually there will be several.
- boost::shared_ptr<BufferView> bufferview_;
+ /// current bufferview (view of a buffer).
+ /**
+ \todo FIXME: this should be moved out of LyXView.
+ */
+ BufferView * bufferview_;
/// view's menubar
boost::scoped_ptr<Menubar> menubar_;
private:
+ lyx::frontend::Gui & owner_;
/**
* setWindowTitle - set title of window
* @param t main window title
Index: frontends/qt4/Action.C
===================================================================
--- frontends/qt4/Action.C (revision 14165)
+++ frontends/qt4/Action.C (working copy)
@@ -19,7 +19,7 @@
#include <boost/bind.hpp>
-#include "LyXView.h"
+#include "frontends/LyXView.h"
#include "qt_helpers.h"
#include "Action.h"
Index: frontends/qt4/Application.h
===================================================================
--- frontends/qt4/Application.h (revision 14165)
+++ frontends/qt4/Application.h (working copy)
@@ -13,6 +13,9 @@
#ifndef LYX_APPLICATION_H
#define LYX_APPLICATION_H
+#include "GuiImplementation.h"
+#include "FontLoader.h"
+
#include <QApplication>
///////////////////////////////////////////////////////////////
@@ -41,12 +44,23 @@
public:
Application(int & argc, char ** argv);
+ //
+ Gui & gui() { return gui_; }
+ ///
+ FontLoader & fontLoader() { return font_loader_; }
+
void connect(GuiWorkArea * work_area);
private:
///
GuiWorkArea * work_area_;
+ ///
+ GuiImplementation gui_;
+
+ ///
+ FontLoader font_loader_;
+
#ifdef Q_WS_X11
public:
bool x11EventFilter (XEvent * ev);
@@ -65,4 +79,7 @@
} // namespace frontend
} // namespace lyx
+extern lyx::frontend::Application * theApp;
+
+
#endif // LYX_APPLICATION_H
Index: frontends/qt4/FontLoader.h
===================================================================
--- frontends/qt4/FontLoader.h (revision 14165)
+++ frontends/qt4/FontLoader.h (working copy)
@@ -97,6 +97,4 @@
QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10];
};
-extern FontLoader fontloader;
-
#endif // QFONT_LOADER_H
Index: frontends/qt4/GuiImplementation.C
===================================================================
--- frontends/qt4/GuiImplementation.C (revision 14165)
+++ frontends/qt4/GuiImplementation.C (working copy)
@@ -10,16 +10,21 @@
* Full author contact details are available in file CREDITS.
*/
+// This include must be declared before everything else because
+// of boost/Qt/LyX clash...
+#include "GuiView.h"
+
#include "GuiImplementation.h"
#include "GuiWorkArea.h"
-#include "GuiView.h"
+#include "BufferView.h"
+
using boost::shared_ptr;
namespace lyx {
namespace frontend {
-GuiImplementation::GuiImplementation(GuiView & owner): owner_(owner),
max_id_(0)
+GuiImplementation::GuiImplementation(): max_view_id_(0), max_wa_id_(0)
{
}
@@ -30,20 +35,57 @@
}
-int GuiImplementation::newWorkArea(int w, int h)
+int GuiImplementation::newView(unsigned int w, unsigned int h)
{
- size_t const id = max_id_;
- ++max_id_;
- work_areas_[id].reset(new GuiWorkArea(owner_, w, h));
+ size_t const id = max_view_id_;
+ ++max_view_id_;
+
+ views_[id].reset(new GuiView(*this, w, h));
+
return id;
}
+
+LyXView& GuiImplementation::view(int id)
+{
+ BOOST_ASSERT(views_.find(id) != views_.end());
+
+ return *views_[id].get();
+}
+
+
+void GuiImplementation::destroyView(int id)
+{
+ views_.erase(id);
+}
+
+
+int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int view_id)
+{
+ size_t const id = max_wa_id_;
+ ++max_wa_id_;
+
+ GuiView * view = views_[view_id].get();
+
+ work_areas_[id].reset(new GuiWorkArea(w, h, view));
+
+ // FIXME BufferView creation should be independant of WorkArea creation
+ buffer_views_[id].reset(new BufferView(view, work_areas_[id].get()));
+ work_areas_[id]->setBufferView(buffer_views_[id].get());
+ view->setBufferView(buffer_views_[id].get());
+
+ view->mainWidget()->setCentralWidget(work_areas_[id].get());
+
+ guiCursor().connect(work_areas_[id].get());
+
+ return id;
+}
+
+
WorkArea& GuiImplementation::workArea(int id)
{
BOOST_ASSERT(work_areas_.find(id) != work_areas_.end());
- guiCursor().connect(work_areas_[id].get());
-
return *work_areas_[id].get();
}
Index: frontends/qt4/GuiImplementation.h
===================================================================
--- frontends/qt4/GuiImplementation.h (revision 14165)
+++ frontends/qt4/GuiImplementation.h (working copy)
@@ -10,8 +10,8 @@
* Full author contact details are available in file CREDITS.
*/
-#ifndef GUI_IMPLEMENTATION_H
-#define GUI_IMPLEMENTATION_H
+#ifndef GUI_H
+#define GUI_H
#include "frontends/Gui.h"
#include "GuiClipboard.h"
@@ -20,6 +20,8 @@
#include <map>
+class LyXView;
+
namespace lyx {
namespace frontend {
@@ -32,27 +34,34 @@
class GuiImplementation: public Gui
{
public:
- GuiImplementation(GuiView & owner);
+ GuiImplementation();
virtual ~GuiImplementation() {}
Clipboard& clipboard();
+ int newView(unsigned int width, unsigned int height);
+ LyXView& view(int id);
+ void destroyView(int id);
+ int newWorkArea(unsigned int width, unsigned int height, int view_id);
int newWorkArea(int w, int h);
WorkArea& workArea(int id);
void destroyWorkArea(int id);
+
private:
///
GuiClipboard clipboard_;
///
+ std::map<int, boost::shared_ptr<GuiView> > views_;
+ ///
std::map<int, boost::shared_ptr<GuiWorkArea> > work_areas_;
///
- GuiView & owner_;
+ size_t max_view_id_;
///
- size_t max_id_;
+ size_t max_wa_id_;
};
} // namespace frontend
} // namespace lyx
-#endif // GUI_IMPLEMENTATION_H
+#endif // GUI_H
Index: frontends/qt4/GuiView.C
===================================================================
--- frontends/qt4/GuiView.C (revision 14165)
+++ frontends/qt4/GuiView.C (working copy)
@@ -34,6 +34,7 @@
#include <boost/bind.hpp>
#include "GuiView.h"
+#include "GuiImplementation.h"
#include "QLMenubar.h"
#include "FontLoader.h"
#include "QCommandBuffer.h"
@@ -54,8 +55,6 @@
using std::string;
using std::endl;
-FontLoader fontloader;
-
namespace lyx {
using support::subst;
@@ -70,26 +69,16 @@
} // namespace anon
-GuiView::GuiView(unsigned int width, unsigned int height)
- : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this)
+GuiView::GuiView(Gui & owner, unsigned int width, unsigned int height)
+ : QMainWindow(), LyXView(owner), commandbuffer_(0)
{
mainWidget_ = this;
// setToolButtonStyle(Qt::ToolButtonIconOnly);
// setIconSize(QSize(12,12));
- bufferview_.reset(new BufferView(this, width, height));
+// bufferview_.reset(new BufferView(this, width, height));
- menubar_.reset(new QLMenubar(this, menubackend));
- connect(menuBar(), SIGNAL(triggered(QAction *)), this,
SLOT(updateMenu(QAction *)));
-
- getToolbars().init();
-
- statusBar()->setSizeGripEnabled(false);
-
- view_state_changed.connect(boost::bind(&GuiView::update_view_state,
this));
- connect(&statusbar_timer_, SIGNAL(timeout()), this,
SLOT(update_view_state_qt()));
-
#ifndef Q_WS_MACX
// assign an icon to main form. We do not do it under Qt/Mac,
// since the icon is provided in the application bundle.
@@ -97,9 +86,6 @@
if (!iconname.empty())
setWindowIcon(QPixmap(toqstr(iconname)));
#endif
-
- // make sure the buttons are disabled if needed
- updateToolbars();
}
@@ -107,6 +93,25 @@
{
}
+
+void GuiView::init()
+{
+ menubar_.reset(new QLMenubar(this, menubackend));
+ QObject::connect(menuBar(), SIGNAL(triggered(QAction *)), this,
SLOT(updateMenu(QAction *)));
+
+ getToolbars().init();
+
+ statusBar()->setSizeGripEnabled(false);
+
+ view_state_changed.connect(boost::bind(&GuiView::update_view_state,
this));
+ QObject::connect(&statusbar_timer_, SIGNAL(timeout()), this,
SLOT(update_view_state_qt()));
+
+ // make sure the buttons are disabled if needed
+ updateToolbars();
+
+ LyXView::init();
+}
+
void GuiView::updateMenu(QAction *action)
{
menubar_->update();
Index: frontends/qt4/GuiView.h
===================================================================
--- frontends/qt4/GuiView.h (revision 14165)
+++ frontends/qt4/GuiView.h (working copy)
@@ -11,14 +11,12 @@
* Full author contact details are available in file CREDITS.
*/
-#ifndef GUIVIEW_H
-#define GUIVIEW_H
+#ifndef GUI_VIEW_H
+#define GUI_VIEW_H
// Must be here because of moc.
#include <config.h>
-#include "GuiImplementation.h"
-
#include "frontends/LyXView.h"
#include "funcrequest.h"
@@ -43,16 +41,18 @@
/**
* GuiView - Qt4 implementation of LyXView
*
- * Qt-private implementation of the main LyX window.
+ * qt4-private implementation of the main LyX window.
*/
class GuiView : public QMainWindow, public LyXView {
Q_OBJECT
public:
/// create a main window of the given dimensions
- GuiView(unsigned int w, unsigned int h);
+ GuiView(Gui & owner, unsigned int w, unsigned int h);
~GuiView();
+ void init();
+
/// show - display the top-level window
void show();
@@ -71,12 +71,9 @@
/// menu item has been selected
void activated(FuncRequest const &);
- // returns true if this view has the focus.
+ /// returns true if this view has the focus.
virtual bool hasFocus() const;
- //
- Gui & gui() { return frontend_; }
-
static QMainWindow* mainWidget();
public slots:
@@ -90,6 +87,7 @@
/// make sure we quit cleanly
virtual void closeEvent(QCloseEvent * e);
private:
+
/// focus the command buffer widget
void focus_command_widget();
@@ -110,11 +108,9 @@
///
static QMainWindow* mainWidget_;
-
- GuiImplementation frontend_;
};
} // namespace frontend
} // namespace lyx
-#endif // GUIVIEW_H
+#endif // GUI_VIEW_H
Index: frontends/qt4/GuiWorkArea.C
===================================================================
--- frontends/qt4/GuiWorkArea.C (revision 14165)
+++ frontends/qt4/GuiWorkArea.C (working copy)
@@ -13,10 +13,13 @@
#include <boost/current_function.hpp>
+// This include must be declared before everything else because
+// of boost/Qt/LyX clash...
+#include "GuiView.h"
+
#include "GuiWorkArea.h"
#include "QLPainter.h"
#include "QLyXKeySym.h"
-#include "GuiView.h"
#include "ColorCache.h"
#include "qt_helpers.h"
@@ -111,14 +114,12 @@
{}
-GuiWorkArea::GuiWorkArea(LyXView & owner, int w, int h)
-: QAbstractScrollArea(GuiView::mainWidget()), WorkArea(owner, w, h),
view_(owner), painter_(this)
+GuiWorkArea::GuiWorkArea(int w, int h, QWidget * parent, BufferView *
buffer_view)
+: QAbstractScrollArea(parent), WorkArea(buffer_view), painter_(this)
{
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- GuiView::mainWidget()->setCentralWidget(this);
-
setAcceptDrops(true);
setMinimumSize(100, 70);
@@ -182,6 +183,7 @@
{
}
+
void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int
scroll_line_step)
{
// do what cursor movement does (some grey)
@@ -193,6 +195,7 @@
verticalScrollBar()->setLineStep(scroll_line_step);
}
+
void GuiWorkArea::adjustViewWithScrollBar(int)
{
/*
@@ -205,7 +208,7 @@
<< " linestep=" << verticalScrollBar()->lineStep()
<< endl;
*/
- view_.view()->scrollDocView(verticalScrollBar()->sliderPosition());
+ buffer_view_->scrollDocView(verticalScrollBar()->sliderPosition());
}
@@ -229,7 +232,7 @@
for (int i = 0; i!=files.size(); ++i) {
string const file =
os::internal_path(fromqstr(files.at(i).toString()));
if (!file.empty())
-
view_.view()->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file));
+
buffer_view_->workAreaDispatch(FuncRequest(LFUN_FILE_OPEN, file));
}
}
@@ -241,13 +244,13 @@
FuncRequest cmd(LFUN_MOUSE_TRIPLE,
dc_event_.x, dc_event_.y,
q_button_state(dc_event_.state));
- view_.view()->workAreaDispatch(cmd);
+ buffer_view_->workAreaDispatch(cmd);
return;
}
FuncRequest const cmd(LFUN_MOUSE_PRESS, e->x(), e->y(),
q_button_state(e->button()));
- view_.view()->workAreaDispatch(cmd);
+ buffer_view_->workAreaDispatch(cmd);
}
@@ -258,7 +261,7 @@
FuncRequest const cmd(LFUN_MOUSE_RELEASE, e->x(), e->y(),
q_button_state(e->button()));
- view_.view()->workAreaDispatch(cmd);
+ buffer_view_->workAreaDispatch(cmd);
}
@@ -318,7 +321,7 @@
synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
// ... and dispatch the event to the LyX core.
- view_.view()->workAreaDispatch(cmd);
+ buffer_view_->workAreaDispatch(cmd);
}
}
@@ -348,7 +351,7 @@
synthetic_mouse_event_.scrollbar_value_old = scrollbar_value;
// ... and dispatch the event to the LyX core.
- view_.view()->workAreaDispatch(synthetic_mouse_event_.cmd);
+ buffer_view_->workAreaDispatch(synthetic_mouse_event_.cmd);
}
}
@@ -368,10 +371,11 @@
else {
boost::shared_ptr<QLyXKeySym> sym(new QLyXKeySym);
sym->set(e);
- view_.view()->workAreaKeyPress(sym, q_key_state(e->state()));
+ buffer_view_->workAreaKeyPress(sym, q_key_state(e->state()));
}
}
+
// This is used only if USE_KEY_BUFFERING is defined...
void GuiWorkArea::keyeventTimeout()
{
@@ -397,7 +401,7 @@
<< " key=" << ev->key()
<< endl;
- view_.view()->workAreaKeyPress(sym, q_key_state(ev->state()));
+ buffer_view_->workAreaKeyPress(sym, q_key_state(ev->state()));
keyeventQueue_.pop();
handle_autos = false;
@@ -420,7 +424,7 @@
FuncRequest cmd(LFUN_MOUSE_DOUBLE,
dc_event_.x, dc_event_.y,
q_button_state(dc_event_.state));
- view_.view()->workAreaDispatch(cmd);
+ buffer_view_->workAreaDispatch(cmd);
}
@@ -435,7 +439,7 @@
// paint_device_ = QImage(viewport()->width(), viewport()->height(),
QImage::Format_RGB32);
paint_device_ = QPixmap(viewport()->width(), viewport()->height());
- view_.view()->workAreaResize();
+ buffer_view_->workAreaResize();
/*
lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION
Index: frontends/qt4/GuiWorkArea.h
===================================================================
--- frontends/qt4/GuiWorkArea.h (revision 14165)
+++ frontends/qt4/GuiWorkArea.h (working copy)
@@ -22,7 +22,6 @@
#undef emit
#endif
-#include "frontends/LyXView.h"
#include "frontends/WorkArea.h"
#include "QLPainter.h"
@@ -52,6 +51,8 @@
namespace lyx {
namespace frontend {
+class GuiView;
+
/// for emulating triple click
class double_click {
public:
@@ -104,7 +105,7 @@
public:
- GuiWorkArea(LyXView & owner, int w, int h);
+ GuiWorkArea(int width, int height, QWidget * parent, BufferView *
buffer_view = 0);
virtual ~GuiWorkArea();
/// return the width of the content pane
@@ -139,8 +140,6 @@
*/
void drawScreen(int x, int y, QPixmap pixmap);
- LyXView & view() { return view_; }
-
/// copies specified area of pixmap to screen
virtual void expose(int x, int y, int exp_width, int exp_height);
@@ -190,9 +189,6 @@
void adjustViewWithScrollBar(int action = 0);
private:
- ///
- LyXView & view_;
-
/// Buffer view width.
int workWidth_;
Index: frontends/qt4/lyx_gui.C
===================================================================
--- frontends/qt4/lyx_gui.C (revision 14165)
+++ frontends/qt4/lyx_gui.C (working copy)
@@ -59,9 +59,9 @@
using lyx::support::ltrim;
using lyx::support::package;
+using lyx::frontend::GuiImplementation;
using lyx::frontend::GuiView;
using lyx::frontend::Application;
-using lyx::frontend::Application;
namespace os = lyx::support::os;
@@ -79,6 +79,8 @@
LyXServer * lyxserver;
LyXServerSocket * lyxsocket;
+lyx::frontend::Application * theApp;
+
namespace {
int getDPI()
@@ -134,7 +136,9 @@
Application app(argc, argv);
#endif
+ theApp = &app;
+
// install translation file for Qt built-in dialogs
// These are only installed since Qt 3.2.x
QTranslator qt_trans;
@@ -195,11 +199,15 @@
// this can't be done before because it needs the Languages object
initEncodings();
- boost::shared_ptr<GuiView> view_ptr(new GuiView(width, height));
- LyX::ref().addLyXView(view_ptr);
+ int view_id = theApp->gui().newView(width, height);
+ GuiView & view = static_cast<GuiView &> (theApp->gui().view(view_id));
- GuiView & view = *view_ptr.get();
+ // FIXME: for now we assume that there is only one LyXView with id = 0.
+ int workArea_id_ = theApp->gui().newWorkArea(width, height, 0);
+ //WorkArea * workArea_ = & theApp->gui().workArea(workArea_id_);
+ LyX::ref().addLyXView(&view);
+
view.init();
if (posx != -1 && posy != -1) {
@@ -304,13 +312,13 @@
void update_fonts()
{
- fontloader.update();
+ theApp->fontLoader().update();
}
bool font_available(LyXFont const & font)
{
- return fontloader.available(font);
+ return theApp->fontLoader().available(font);
}
Index: frontends/qt4/qfont_metrics.C
===================================================================
--- frontends/qt4/qfont_metrics.C (revision 14165)
+++ frontends/qt4/qfont_metrics.C (working copy)
@@ -15,6 +15,7 @@
#include "frontends/lyx_gui.h"
#include "FontLoader.h"
+#include "Application.h"
#include "language.h"
@@ -28,7 +29,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- return fontloader.metrics(f).ascent();
+ return theApp->fontLoader().metrics(f).ascent();
}
@@ -38,7 +39,7 @@
return 1;
// We add 1 as the value returned by QT is different than X
// See http://doc.trolltech.com/2.3/qfontmetrics.html#200b74
- return fontloader.metrics(f).descent() + 1;
+ return theApp->fontLoader().metrics(f).descent() + 1;
}
@@ -46,7 +47,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- QRect const & r = fontloader.metrics(f).boundingRect(c);
+ QRect const & r = theApp->fontLoader().metrics(f).boundingRect(c);
// Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
// value by the height: (x, -y-height, width, height).
// Other versions return: (x, -y, width, height)
@@ -62,7 +63,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- QRect const & r = fontloader.metrics(f).boundingRect(c);
+ QRect const & r = theApp->fontLoader().metrics(f).boundingRect(c);
// Qt/Win 3.2.1nc (at least) corrects the GetGlyphOutlineA|W y
// value by the height: (x, -y-height, width, height).
// Other versions return: (x, -y, width, height)
@@ -78,7 +79,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- return fontloader.metrics(f).leftBearing(c);
+ return theApp->fontLoader().metrics(f).leftBearing(c);
}
@@ -86,7 +87,7 @@
{
if (!lyx_gui::use_gui)
return 1;
- QFontMetrics const & m = fontloader.metrics(f);
+ QFontMetrics const & m = theApp->fontLoader().metrics(f);
// Qt rbearing is from the right edge of the char's width().
return m.width(c) - m.rightBearing(c);
@@ -111,8 +112,8 @@
LyXFont smallfont = f;
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
- QFontMetrics const & qm = fontloader.metrics(f);
- QFontMetrics const & qsmallm = fontloader.metrics(smallfont);
+ QFontMetrics const & qm = theApp->fontLoader().metrics(f);
+ QFontMetrics const & qsmallm = theApp->fontLoader().metrics(smallfont);
Encoding const * encoding = fontencoding(f);
@@ -139,7 +140,7 @@
return smallcapswidth(s, ls, f);
Encoding const * encoding = fontencoding(f);
- QLFontInfo & fi = fontloader.fontinfo(f);
+ QLFontInfo & fi = theApp->fontLoader().fontinfo(f);
if (ls == 1)
return fi.width(encoding->ucs(s[0]));
@@ -164,7 +165,7 @@
void rectText(string const & str, LyXFont const & f,
int & w, int & ascent, int & descent)
{
- QFontMetrics const & m = fontloader.metrics(f);
+ QFontMetrics const & m = theApp->fontLoader().metrics(f);
static int const d = 2;
w = width(str, f) + d * 2 + 2;
ascent = m.ascent() + d;
@@ -176,7 +177,7 @@
void buttonText(string const & str, LyXFont const & f,
int & w, int & ascent, int & descent)
{
- QFontMetrics const & m = fontloader.metrics(f);
+ QFontMetrics const & m = theApp->fontLoader().metrics(f);
static int const d = 3;
w = width(str, f) + d * 2 + 2;
ascent = m.ascent() + d;
Index: frontends/qt4/QLPainter.C
===================================================================
--- frontends/qt4/QLPainter.C (revision 14165)
+++ frontends/qt4/QLPainter.C (working copy)
@@ -15,10 +15,11 @@
#include "GuiWorkArea.h"
#include "QLImage.h"
-
#include "ColorCache.h"
#include "FontLoader.h"
+#include "Application.h"
+
#include "debug.h"
#include "language.h"
#include "LColor.h"
@@ -203,8 +204,8 @@
LyXFont smallfont(f);
smallfont.decSize().decSize().setShape(LyXFont::UP_SHAPE);
- QFont const & qfont = fontloader.get(f);
- QFont const & qsmallfont = fontloader.get(smallfont);
+ QFont const & qfont = theApp->fontLoader().get(f);
+ QFont const & qsmallfont = theApp->fontLoader().get(smallfont);
QFontMetrics const & qfontm = QFontMetrics(qfont);
QFontMetrics const & qsmallfontm = QFontMetrics(qsmallfont);
@@ -247,7 +248,7 @@
if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) {
QPainter qp(qwa_->paintDevice());
setQPainterPen(qp, f.realColor());
- qp.setFont(fontloader.get(f));
+ qp.setFont(theApp->fontLoader().get(f));
// We need to draw the text as LTR as we use our own bidi code.
qp.setLayoutDirection(Qt::LeftToRight);
qp.drawText(x, y, str);
Index: frontends/WorkArea.C
===================================================================
--- frontends/WorkArea.C (revision 14165)
+++ frontends/WorkArea.C (working copy)
@@ -118,8 +118,8 @@
loader_.reset(file);
}
-WorkArea::WorkArea(LyXView & owner, int w, int h)
- : greyed_out_(true)
+WorkArea::WorkArea(BufferView * buffer_view)
+ : buffer_view_(buffer_view), greyed_out_(true)
{
// Start loading the pixmap as soon as possible
if (lyxrc.show_banner) {
@@ -130,6 +130,12 @@
}
+void WorkArea::setBufferView(BufferView * buffer_view)
+{
+ buffer_view_ = buffer_view;
+}
+
+
void WorkArea::checkAndGreyOut()
{
if (greyed_out_)
@@ -141,7 +147,7 @@
{
greyed_out_ = false;
getPainter().start();
- paintText(bv, vi);
+ paintText(*buffer_view_, vi);
lyxerr[Debug::DEBUG] << "Redraw screen" << endl;
int const ymin = std::max(vi.y1, 0);
int const ymax =
Index: frontends/WorkArea.h
===================================================================
--- frontends/WorkArea.h (revision 14165)
+++ frontends/WorkArea.h (working copy)
@@ -19,8 +19,6 @@
#include "frontends/key_state.h"
#include "frontends/LyXKeySym.h"
-class LyXView;
-class FuncRequest;
class BufferView;
class ViewMetricsInfo;
@@ -38,10 +36,12 @@
*/
class WorkArea {
public:
- WorkArea(LyXView & owner, int w, int h);
+ WorkArea(BufferView * buffer_view = 0);
virtual ~WorkArea() {}
+ void setBufferView(BufferView * buffer_view);
+
/// return the painter object for this work area
virtual Painter & getPainter() = 0;
@@ -75,6 +75,9 @@
/// cause the display of the given area of the work area
virtual void expose(int x, int y, int w, int h) = 0;
+ ///
+ BufferView * buffer_view_;
+
private:
///
void checkAndGreyOut();
Index: importer.C
===================================================================
--- importer.C (revision 14165)
+++ importer.C (working copy)
@@ -76,7 +76,7 @@
string filename2 = (loader_format == format) ? filename
: changeExtension(filename,
formats.extension(loader_format));
- insertAsciiFile(lv->view().get(), filename2, as_paragraphs);
+ insertAsciiFile(lv->view(), filename2, as_paragraphs);
lv->dispatch(FuncRequest(LFUN_MARK_OFF));
}
Index: lyx_main.C
===================================================================
--- lyx_main.C (revision 14165)
+++ lyx_main.C (working copy)
@@ -188,7 +188,7 @@
}
-void LyX::addLyXView(boost::shared_ptr<LyXView> const & lyxview)
+void LyX::addLyXView(LyXView * lyxview)
{
views_.push_back(lyxview);
}
Index: lyx_main.h
===================================================================
--- lyx_main.h (revision 14165)
+++ lyx_main.h (working copy)
@@ -58,7 +58,7 @@
lyx::Session & session();
lyx::Session const & session() const;
- void addLyXView(boost::shared_ptr<LyXView> const & lyxview);
+ void addLyXView(LyXView * lyxview);
/** redraw \c inset in all the BufferViews in which it is currently
* visible. If successful return a pointer to the owning Buffer.
@@ -105,7 +105,7 @@
/// lyx session, containing lastfiles, lastfilepos, and lastopened
boost::scoped_ptr<lyx::Session> session_;
///
- typedef std::list<boost::shared_ptr<LyXView> > ViewList;
+ typedef std::list<LyXView * > ViewList;
ViewList views_;
};
Index: lyxfunc.C
===================================================================
--- lyxfunc.C (revision 14165)
+++ lyxfunc.C (working copy)
@@ -1949,8 +1949,8 @@
BufferView * LyXFunc::view() const
{
- BOOST_ASSERT(owner);
- return owner->view().get();
+// BOOST_ASSERT(owner);
+ return owner->view();
}