From: Abdelrazak Younes Date: Mon, 26 Jun 2006 16:55:35 +0000 (+0000) Subject: GUI API Cleanup step 2: merge of the "younes" branch. X-Git-Tag: 1.6.10~13062 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=3287c44f3322973eb6a31709dcdd7e0feb9f27a2;p=features.git GUI API Cleanup step 2: merge of the "younes" branch. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14231 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView.C b/src/BufferView.C index d52233651d..baad2b98d1 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -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 @@ using std::vector; 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)) {} @@ -147,6 +148,12 @@ void BufferView::updateScrollbar() } +ScrollbarParameters const & BufferView::scrollbarParameters() const +{ + return pimpl_->scrollbarParameters(); +} + + void BufferView::scrollDocView(int value) { pimpl_->scrollDocView(value); @@ -195,7 +202,7 @@ void BufferView::switchKeyMap() int BufferView::workWidth() const { - return pimpl_->workarea().width(); + return pimpl_->width(); } @@ -241,9 +248,9 @@ void BufferView::selectionLost() } -void BufferView::workAreaResize() +void BufferView::workAreaResize(int width, int height) { - pimpl_->workAreaResize(); + pimpl_->workAreaResize(width, height); } @@ -339,7 +346,7 @@ void BufferView::haveSelection(bool sel) int BufferView::workHeight() const { - return pimpl_->workarea().height(); + return pimpl_->height(); } diff --git a/src/BufferView.h b/src/BufferView.h index 5723cb72cd..357ab9acbb 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -38,6 +38,7 @@ class ParIterator; namespace lyx { namespace frontend { class Painter; +class WorkArea; } } @@ -61,6 +62,23 @@ inline flags operator&(flags const f, flags const g) } // namespace +/// Scrollbar Parameters +struct ScrollbarParameters +{ + void reset(int h = 0, int p = 0, int l = 0) + { + height = h; + position = p; + lineScrollHeight = l; + } + + /// The total document height in pixels + int height; + /// The current position in the document, in pixels + int position; + /// the line-scroll amount, in pixels + int lineScrollHeight; +}; /** * A buffer view encapsulates a view onto a particular @@ -76,7 +94,7 @@ public: * 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(); @@ -114,6 +132,8 @@ public: bool fitCursor(); /// reset the scrollbar to reflect current view position void updateScrollbar(); + /// return the Scrollbar Parameters + ScrollbarParameters const & scrollbarParameters() const; /// FIXME bool available() const; @@ -185,10 +205,10 @@ public: void selectionLost(); /// - void workAreaResize(); + void workAreaResize(int width, int height); - /// 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); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index 0976075911..709f702da6 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -137,23 +137,19 @@ T * getInsetByCode(LCursor & cur, InsetBase::Code code) } // 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(); @@ -341,6 +337,18 @@ lyx::frontend::Painter & BufferView::Pimpl::painter() const } +int BufferView::Pimpl::width() const +{ + return width_; +} + + +int BufferView::Pimpl::height() const +{ + return height_; +} + + void BufferView::Pimpl::setBuffer(Buffer * b) { lyxerr[Debug::INFO] << BOOST_CURRENT_FUNCTION @@ -405,7 +413,6 @@ void BufferView::Pimpl::setBuffer(Buffer * b) } update(); - updateScrollbar(); owner_->updateMenubar(); owner_->updateToolbars(); owner_->updateLayoutChoice(); @@ -450,8 +457,6 @@ void BufferView::Pimpl::resizeCurrentBuffer() // Reset the "Formatting..." message owner_->clearMessage(); - - updateScrollbar(); } @@ -460,7 +465,7 @@ void BufferView::Pimpl::updateScrollbar() if (!bv_->text()) { lyxerr[Debug::DEBUG] << BOOST_CURRENT_FUNCTION << " no text in updateScrollbar" << endl; - workArea_->setScrollbarParams(0, 0, 0); + scrollbarParameters_.reset(); return; } @@ -482,7 +487,7 @@ void BufferView::Pimpl::updateScrollbar() // estimated average paragraph height: if (wh_ == 0) - wh_ = workArea_->height() / 4; + wh_ = height_ / 4; int h = t.getPar(anchor_ref_).height(); // Normalize anchor/offset (MV): @@ -495,7 +500,7 @@ void BufferView::Pimpl::updateScrollbar() int sumh = 0; int nh = 0; for (lyx::pit_type pit = anchor_ref_; pit <= parsize; ++pit) { - if (sumh > workArea_->height()) + if (sumh > height_) break; int const h2 = t.getPar(pit).height(); sumh += h2; @@ -506,9 +511,15 @@ void BufferView::Pimpl::updateScrollbar() if (hav > wh_) wh_ = hav; - workArea_->setScrollbarParams((parsize + 1) * wh_, - anchor_ref_ * wh_ + int(offset_ref_ * wh_ / float(h)), - int(wh_ * defaultRowHeight() / float(h))); + scrollbarParameters_.height = (parsize + 1) * wh_; + scrollbarParameters_.position = anchor_ref_ * wh_ + int(offset_ref_ * wh_ / float(h)); + scrollbarParameters_.lineScrollHeight = int(wh_ * defaultRowHeight() / float(h)); +} + + +ScrollbarParameters const & BufferView::Pimpl::scrollbarParameters() const +{ + return scrollbarParameters_; } @@ -539,7 +550,7 @@ void BufferView::Pimpl::scrollDocView(int value) int const height = 2 * defaultRowHeight(); int const first = height; - int const last = workArea_->height() - height; + int const last = height_ - height; LCursor & cur = cursor_; bv_funcs::CurStatus st = bv_funcs::status(bv_, cur); @@ -583,7 +594,7 @@ void BufferView::Pimpl::scroll(int /*lines*/) // scrollDocView(new_top_y); // // // Update the scrollbar. -// workArea_->.setScrollbarParams(t->height(), top_y(), defaultRowHeight()); +// workArea_->setScrollbarParams(t->height(), top_y(), defaultRowHeight()); } @@ -642,17 +653,14 @@ void BufferView::Pimpl::selectionLost() } -void BufferView::Pimpl::workAreaResize() +void BufferView::Pimpl::workAreaResize(int width, int height) { - static int workArea_width; - static int workArea_height; - - bool const widthChange = workArea_->width() != workArea_width; - bool const heightChange = workArea_->height() != workArea_height; + bool const widthChange = width != width_; + bool const heightChange = height != height_; // Update from work area - workArea_width = workArea_->width(); - workArea_height = workArea_->height(); + width_ = width; + height_ = height; if (buffer_ && widthChange) { // The visible LyXView need a resize @@ -662,8 +670,6 @@ void BufferView::Pimpl::workAreaResize() if (widthChange || heightChange) update(); - // Always make sure that the scrollbar is sane. - updateScrollbar(); owner_->updateLayoutChoice(); } @@ -675,7 +681,7 @@ bool BufferView::Pimpl::fitCursor() int const asc = font_metrics::maxAscent(font); int const des = font_metrics::maxDescent(font); Point const p = bv_funcs::getPos(cursor_, cursor_.boundary()); - if (p.y_ - asc >= 0 && p.y_ + des < workArea_->height()) + if (p.y_ - asc >= 0 && p.y_ + des < height_) return false; } center(); @@ -739,8 +745,6 @@ void BufferView::Pimpl::update(Update::flags flags) } else workArea_->greyOut(); - // And the scrollbar - updateScrollbar(); owner_->view_state_changed(); } @@ -876,7 +880,7 @@ void BufferView::Pimpl::center() Paragraph const & par = bot.text()->paragraphs()[pit]; anchor_ref_ = pit; offset_ref_ = bv_funcs::coordOffset(cursor_, cursor_.boundary()).y_ - + par.ascent() - workArea_->height() / 2; + + par.ascent() - height_ / 2; } @@ -1013,7 +1017,7 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd0) // surrounding LyXText will handle this event. // Build temporary cursor. - cmd.y = min(max(cmd.y, -1), workArea_->height()); + cmd.y = min(max(cmd.y, -1), height_); InsetBase * inset = bv_->text()->editXY(cur, cmd.x, cmd.y); //lyxerr << BOOST_CURRENT_FUNCTION // << " * hit inset at tip: " << inset << endl; diff --git a/src/BufferView_pimpl.h b/src/BufferView_pimpl.h index bf66462773..c5c74862f8 100644 --- a/src/BufferView_pimpl.h +++ b/src/BufferView_pimpl.h @@ -57,7 +57,7 @@ class GuiCursor; 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; /// @@ -75,10 +75,12 @@ public: /// bool loadLyXFile(std::string const &, bool); /// - void workAreaResize(); + void workAreaResize(int width, int height); /// void updateScrollbar(); /// + ScrollbarParameters const & scrollbarParameters() const; + /// void scrollDocView(int value); /// Wheel mouse scroll, move by multiples of text->defaultRowHeight(). void scroll(int lines); @@ -124,7 +126,25 @@ public: /// the clipboard lyx::frontend::Clipboard & clipboard() const; + /// Width and height of the BufferView in Pixels + /** + This is set externally by the workAreaResize method. + */ + int width() const; + /// Height of the BufferView in Pixels + /** + This is set externally by the workAreaResize method. + */ + int height() const; + private: + /// + int width_; + /// + int height_; + /// + ScrollbarParameters scrollbarParameters_; + /// An error list (replaces the error insets) ErrorList errorlist_; /// add an error to the list @@ -192,7 +212,6 @@ private: void menuInsertLyXFile(std::string const & filen); lyx::frontend::WorkArea * workArea_; - int workAreaId_; /// this is used to handle XSelection events in the right manner struct { diff --git a/src/frontends/Gui.h b/src/frontends/Gui.h index 2d1c9eee1e..9676e62f49 100644 --- a/src/frontends/Gui.h +++ b/src/frontends/Gui.h @@ -16,6 +16,12 @@ #include "frontends/GuiCursor.h" +#include + +#include + +class LyXView; + namespace lyx { namespace frontend { @@ -32,18 +38,31 @@ public: virtual ~Gui() {} /// - virtual Clipboard& clipboard() = 0; + virtual Clipboard & clipboard() = 0; + + /// + virtual int newView(unsigned int width, unsigned int height) = 0; /// - virtual int newWorkArea(int w, int h) = 0; + virtual LyXView & view(int id) = 0; /// - virtual WorkArea& workArea(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; /// GuiCursor & guiCursor() {return cursor_;} +protected: + /// view of a buffer. Eventually there will be several. + std::map > buffer_views_; + private: + /// GuiCursor cursor_; }; diff --git a/src/frontends/GuiCursor.C b/src/frontends/GuiCursor.C index 7187c49746..77f6eaed08 100644 --- a/src/frontends/GuiCursor.C +++ b/src/frontends/GuiCursor.C @@ -42,10 +42,6 @@ #include "support/filetools.h" // LibFileSearch -#include -#include -#include - using lyx::support::libFileSearch; using std::endl; @@ -57,7 +53,7 @@ namespace lyx { namespace frontend { GuiCursor::GuiCursor() - : cursor_visible_(false), work_area_(NULL) + : cursor_visible_(false), work_area_(0) { } @@ -80,7 +76,7 @@ void GuiCursor::show(BufferView & bv) if (!bv.available()) return; - Cursor_Shape shape = BAR_SHAPE; + CursorShape shape = BAR_SHAPE; LyXText const & text = *bv.getLyXText(); LyXFont const & realfont = text.real_current_font; @@ -146,4 +142,3 @@ void GuiCursor::prepare() } // namespace frontend } // namespace lyx - diff --git a/src/frontends/GuiCursor.h b/src/frontends/GuiCursor.h index cc45d8c143..e6ee467414 100644 --- a/src/frontends/GuiCursor.h +++ b/src/frontends/GuiCursor.h @@ -11,6 +11,22 @@ * Full author contact details are available in file CREDITS. */ +// X11 use a define called CursorShape, and we really want to use +// that name our selves. Therefore we do something similar to what is done +// in kde/fixx11h.h: +namespace X { +#ifdef CursorShape +#ifndef FIXX11H_CursorShape +#define FIXX11H_CursorShape +int const XCursorShape = CursorShape; +#undef CursorShape +int const CursorShape = CursorShape; +#endif +#undef CursorShape +#endif + +} // namespace X + #ifndef GUI_CURSOR_H #define GUI_CURSOR_H @@ -26,7 +42,7 @@ namespace frontend { class WorkArea; /// types of cursor in work area -enum Cursor_Shape { +enum CursorShape { /// normal I-beam BAR_SHAPE, /// L-shape for locked insets of a different language diff --git a/src/frontends/LyXView.C b/src/frontends/LyXView.C index 2256cd1d97..7f53e0ed5e 100644 --- a/src/frontends/LyXView.C +++ b/src/frontends/LyXView.C @@ -12,6 +12,7 @@ #include #include "LyXView.h" +#include "Gui.h" #include "Dialogs.h" #include "Timeout.h" #include "Toolbars.h" @@ -46,6 +47,8 @@ # include #endif +using lyx::frontend::Gui; + using lyx::support::makeDisplayPath; using lyx::support::onlyFilename; @@ -56,18 +59,29 @@ using lyx::frontend::ControlCommandBuffer; 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 @@ Buffer * LyXView::buffer() const } -boost::shared_ptr const & LyXView::view() const +BufferView * LyXView::view() const { return bufferview_; } @@ -132,7 +146,7 @@ void LyXView::autoSave() lyxerr[Debug::INFO] << "Running autoSave()" << endl; if (view()->available()) { - ::autoSave(view().get()); + ::autoSave(view()); } } diff --git a/src/frontends/LyXView.h b/src/frontends/LyXView.h index 29e51c1dbf..77316e6124 100644 --- a/src/frontends/LyXView.h +++ b/src/frontends/LyXView.h @@ -33,12 +33,8 @@ class Timeout; class FuncRequest; namespace lyx { - namespace frontend { class Gui; -} // namespace frontend - -namespace frontend { class ControlCommandBuffer; } // namespace frontend @@ -60,10 +56,12 @@ class ControlCommandBuffer; 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 @@ public: 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 const & view() const; + BufferView * view() const; /// return the buffer currently shown in this window Buffer * buffer() const; @@ -148,19 +146,24 @@ public: */ 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_; + /// current bufferview (view of a buffer). + /** + \todo FIXME: this should be moved out of LyXView. + */ + BufferView * bufferview_; /// view's menubar boost::scoped_ptr menubar_; private: + lyx::frontend::Gui & owner_; /** * setWindowTitle - set title of window * @param t main window title diff --git a/src/frontends/WorkArea.C b/src/frontends/WorkArea.C index 9f20119a5f..acc34663e3 100644 --- a/src/frontends/WorkArea.C +++ b/src/frontends/WorkArea.C @@ -118,8 +118,8 @@ SplashScreen::SplashScreen() 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 @@ WorkArea::WorkArea(LyXView & owner, int w, int h) } +void WorkArea::setBufferView(BufferView * buffer_view) +{ + buffer_view_ = buffer_view; +} + + void WorkArea::checkAndGreyOut() { if (greyed_out_) @@ -141,7 +147,7 @@ void WorkArea::redraw(BufferView & bv, ViewMetricsInfo const & vi) { 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 = diff --git a/src/frontends/WorkArea.h b/src/frontends/WorkArea.h index b3ee602e57..113f2ce936 100644 --- a/src/frontends/WorkArea.h +++ b/src/frontends/WorkArea.h @@ -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 Painter; */ 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; @@ -66,7 +66,7 @@ public: void greyOut(); /// paint the cursor and store the background - virtual void showCursor(int x, int y, int h, Cursor_Shape shape) = 0; + virtual void showCursor(int x, int y, int h, CursorShape shape) = 0; /// hide the cursor virtual void removeCursor() = 0; @@ -75,6 +75,9 @@ protected: /// 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(); diff --git a/src/frontends/controllers/Kernel.C b/src/frontends/controllers/Kernel.C index b4a0e57c1f..e411c6c43d 100644 --- a/src/frontends/controllers/Kernel.C +++ b/src/frontends/controllers/Kernel.C @@ -49,7 +49,7 @@ void Kernel::disconnect(string const & name) const bool Kernel::isBufferAvailable() const { - if (!lyxview_.view().get()) + if (!lyxview_.view()) return false; return lyxview_.view()->available(); } @@ -90,13 +90,13 @@ void Kernel::redrawGUI() const BufferView * Kernel::bufferview() { - return lyxview_.view().get(); + return lyxview_.view(); } BufferView const * Kernel::bufferview() const { - return lyxview_.view().get(); + return lyxview_.view(); } diff --git a/src/frontends/gtk/GMiniBuffer.C b/src/frontends/gtk/GMiniBuffer.C index 9c920957de..e22185baba 100644 --- a/src/frontends/gtk/GMiniBuffer.C +++ b/src/frontends/gtk/GMiniBuffer.C @@ -82,7 +82,7 @@ GMiniBuffer::GMiniBuffer(GView * view, ControlCommandBuffer & control) : focusTimer_->timeout.connect( boost::bind(&GMiniBuffer::focusTimeout, this)); idleTimer_->start(); - messageMode(); + //messageMode(); } diff --git a/src/frontends/gtk/GPainter.C b/src/frontends/gtk/GPainter.C index e39dade622..2d38d771ab 100644 --- a/src/frontends/gtk/GPainter.C +++ b/src/frontends/gtk/GPainter.C @@ -232,7 +232,7 @@ void GPainter::text(int x, int y, char const * s, size_t ls, LyXFont const & f) XftFont * fontS = getXftFont(smallfont); char c; int tmpx = x; - for (int i = 0; i < ls; ++i) { + for (unsigned int i = 0; i < ls; ++i) { c = lyx::support::uppercase(s[i]); if (c != s[i]) { XftDrawString8(draw, xftClr, fontS, tmpx, y, diff --git a/src/frontends/gtk/GScreen.C b/src/frontends/gtk/GScreen.C index 2014e73463..b5a48bab06 100644 --- a/src/frontends/gtk/GScreen.C +++ b/src/frontends/gtk/GScreen.C @@ -32,6 +32,7 @@ #include "frontends/font_metrics.h" #include "frontends/Painter.h" +#include "frontends/GuiCursor.h" #include "insets/insettext.h" @@ -64,7 +65,7 @@ void GScreen::setCursorColor(Glib::RefPtr gc) } -void GScreen::showCursor(int x, int y, int h, Cursor_Shape shape) +void GScreen::showCursor(int x, int y, int h, CursorShape shape) { // Update the cursor color. setCursorColor(owner_.getGC()); diff --git a/src/frontends/gtk/GScreen.h b/src/frontends/gtk/GScreen.h index 8e9a169454..1aae24e9cb 100644 --- a/src/frontends/gtk/GScreen.h +++ b/src/frontends/gtk/GScreen.h @@ -39,7 +39,7 @@ public: /// virtual void removeCursor(); /// - virtual void showCursor(int x, int y, int h, Cursor_Shape shape); + virtual void showCursor(int x, int y, int h, CursorShape shape); /// Copies specified area of pixmap to screen virtual void expose(int x, int y, int w, int h); diff --git a/src/frontends/gtk/GView.C b/src/frontends/gtk/GView.C index f07b198315..edaa95f853 100644 --- a/src/frontends/gtk/GView.C +++ b/src/frontends/gtk/GView.C @@ -57,7 +57,7 @@ void add_el(Gtk::Box::BoxList & list, Gtk::Box & box, bool shrink) } // namespace anon -GView::GView() : frontend_(*this) +GView::GView(Gui & owner) : LyXView(owner) { // The physical store for the boxes making up the layout. box_store_.push_back(BoxPtr(new Gtk::VBox)); @@ -93,7 +93,6 @@ GView::GView() : frontend_(*this) // Define the components making up the window. menubar_.reset(new GMenubar(this, menubackend)); getToolbars().init(); - bufferview_.reset(new BufferView(this, 300, 300)); minibuffer_.reset(new GMiniBuffer(this, *controlcommand_)); focus_command_buffer.connect( @@ -119,7 +118,7 @@ GView::GView() : frontend_(*this) } set_default_size(width, height); // Make sure the buttons are disabled if needed. - updateToolbars(); + //updateToolbars(); string const iconName = support::libFileSearch("images", "lyx", "xpm"); if (!iconName.empty()) diff --git a/src/frontends/gtk/GView.h b/src/frontends/gtk/GView.h index cc796a66f3..ce0c3be837 100644 --- a/src/frontends/gtk/GView.h +++ b/src/frontends/gtk/GView.h @@ -16,8 +16,6 @@ #include "frontends/LyXView.h" -#include "GuiImplementation.h" - #include #include @@ -37,7 +35,7 @@ public: Center }; - GView(); + GView(Gui & owner); ~GView(); Gtk::Box & getBox(Position pos); @@ -58,9 +56,6 @@ public: // returns true if this view has the focus. virtual bool hasFocus() const; - /// - Gui & gui() { return frontend_; } - private: void showViewState(); bool onFocusIn(GdkEventFocus * event); @@ -79,8 +74,6 @@ private: boost::scoped_ptr minibuffer_; Gtk::Widget * workArea_; - /// - GuiImplementation frontend_; }; } // namespace frontend diff --git a/src/frontends/gtk/GWorkArea.C b/src/frontends/gtk/GWorkArea.C index 0b39199cb5..5eda32f739 100644 --- a/src/frontends/gtk/GWorkArea.C +++ b/src/frontends/gtk/GWorkArea.C @@ -332,7 +332,7 @@ bool GWorkArea::onConfigure(GdkEventConfigure * /*event*/) gtk_im_context_set_client_window( imContext_, workArea_.get_window()->gobj()); } - view_.view()->workAreaResize(); + view_.view()->workAreaResize(workArea_.get_width(), workArea_.get_height()); return true; } diff --git a/src/frontends/gtk/GWorkArea.h b/src/frontends/gtk/GWorkArea.h index eea296c85d..46160aa451 100644 --- a/src/frontends/gtk/GWorkArea.h +++ b/src/frontends/gtk/GWorkArea.h @@ -58,7 +58,7 @@ private: class GWorkArea : public sigc::trackable { public: GWorkArea(LyXView & owner, int width, int height); - ~GWorkArea(); + virtual ~GWorkArea(); virtual Painter & getPainter(); /// @@ -97,7 +97,7 @@ private: bool onKeyPress(GdkEventKey * event); void onClipboardGet(Gtk::SelectionData & selection_data, guint info); void onClipboardClear(); - LyXView & view_; + LyXView & view_; Gtk::HBox hbox_; Gtk::DrawingArea workArea_; Gtk::VScrollbar vscrollbar_; diff --git a/src/frontends/gtk/GuiClipboard.h b/src/frontends/gtk/GuiClipboard.h index f8bff11131..36b264dc7c 100644 --- a/src/frontends/gtk/GuiClipboard.h +++ b/src/frontends/gtk/GuiClipboard.h @@ -19,15 +19,13 @@ namespace lyx { namespace frontend { -typedef GWorkArea FWorkArea; - /** * The GTK version of the Clipboard. */ class GuiClipboard: public lyx::frontend::Clipboard { public: - GuiClipboard(FWorkArea * work_area) + GuiClipboard(GWorkArea * work_area) : old_work_area_(work_area) { } @@ -54,7 +52,7 @@ public: //@} private: - FWorkArea * old_work_area_; + GWorkArea * old_work_area_; }; } // namespace frontend diff --git a/src/frontends/gtk/GuiImplementation.C b/src/frontends/gtk/GuiImplementation.C new file mode 100644 index 0000000000..98d4d879f7 --- /dev/null +++ b/src/frontends/gtk/GuiImplementation.C @@ -0,0 +1,52 @@ +// -*- C++ -*- +/** + * \file gtk/GuiImplementation.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include "GuiImplementation.h" + +#include "GView.h" +#include "BufferView.h" + +namespace lyx { +namespace frontend { + +int GuiImplementation::newView(unsigned int /*w*/, unsigned int /*h*/) +{ + view_.reset(new GView(*this)); + return 0; +} + + +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())); + clipboard_.reset(new GuiClipboard(old_work_area_.get())); + guiCursor().connect(work_area_.get()); + + // FIXME BufferView creation should be independant of WorkArea creation + buffer_views_[0].reset(new BufferView(view_.get(), work_area_.get())); + work_area_->setBufferView(buffer_views_[0].get()); + view_->setBufferView(buffer_views_[0].get()); + return 0; +} + + +void GuiImplementation::destroyWorkArea(int /*id*/) +{ + clipboard_.reset(); + work_area_.reset(); + old_work_area_.reset(); + old_screen_.reset(); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/gtk/GuiImplementation.h b/src/frontends/gtk/GuiImplementation.h index 6113a803cf..a0720d9a3b 100644 --- a/src/frontends/gtk/GuiImplementation.h +++ b/src/frontends/gtk/GuiImplementation.h @@ -23,21 +23,16 @@ #include -#include - namespace lyx { namespace frontend { -typedef GScreen FScreen; -typedef GWorkArea FWorkArea; - /** * The Gui class is the interface to all GTK components. */ class GuiImplementation: public lyx::frontend::Gui { public: - GuiImplementation(LyXView & owner): owner_(owner) + GuiImplementation() { } @@ -45,45 +40,43 @@ public: { } - lyx::frontend::Clipboard& clipboard() + lyx::frontend::Clipboard & clipboard() { return *clipboard_; } - int newWorkArea(int w, int h) + int newView(unsigned int w, unsigned int h); + + LyXView & view(int /*id*/) { - old_work_area_.reset(new FWorkArea(owner_, w, h)); - old_screen_.reset(new FScreen(*old_work_area_.get())); - work_area_.reset(new GuiWorkArea(owner_, w, h, old_screen_.get(), old_work_area_.get())); - clipboard_.reset(new GuiClipboard(old_work_area_.get())); - guiCursor().connect(work_area_.get()); - return 0; + return *view_; } - lyx::frontend::WorkArea& workArea(int id) + void destroyView(int /*id*/) { - return *work_area_; + view_.reset(); } - void destroyWorkArea(int id) + int newWorkArea(unsigned int w, unsigned int h, int /*view_id*/); + + lyx::frontend::WorkArea & workArea(int /*id*/) { - clipboard_.reset(); - work_area_.reset(); - old_work_area_.reset(); - old_screen_.reset(); + return *work_area_; } + void destroyWorkArea(int /*id*/); + private: /// boost::shared_ptr clipboard_; /// boost::shared_ptr work_area_; /// - boost::shared_ptr old_work_area_; + boost::shared_ptr view_; /// - boost::shared_ptr old_screen_; + boost::shared_ptr old_work_area_; /// - LyXView & owner_; + boost::shared_ptr old_screen_; }; } // namespace frontend diff --git a/src/frontends/gtk/GuiWorkArea.h b/src/frontends/gtk/GuiWorkArea.h index 8e6ca041f5..d688888a2a 100644 --- a/src/frontends/gtk/GuiWorkArea.h +++ b/src/frontends/gtk/GuiWorkArea.h @@ -20,19 +20,14 @@ namespace lyx { namespace frontend { -typedef GScreen FScreen; -typedef GWorkArea FWorkArea; - /** * Temporary wrapper around GWorkArea and GScreen. * Please refer to the Qt4 implementation for a proper cleanup of the API. */ class GuiWorkArea: public lyx::frontend::WorkArea { public: - GuiWorkArea(LyXView & owner, int w, int h, - FScreen * screen, FWorkArea * work_area) - : lyx::frontend::WorkArea(owner, w, h), - old_screen_(screen), old_work_area_(work_area) + GuiWorkArea(GScreen * screen, GWorkArea * work_area) + : old_screen_(screen), old_work_area_(work_area) { } @@ -69,7 +64,7 @@ public: /// paint the cursor and store the background - virtual void showCursor(int x, int y, int h, Cursor_Shape shape) + virtual void showCursor(int x, int y, int h, CursorShape shape) { old_screen_->showCursor(x, y, h, shape); } @@ -88,8 +83,8 @@ protected: } private: - FScreen * old_screen_; - FWorkArea * old_work_area_; + GScreen * old_screen_; + GWorkArea * old_work_area_; }; } // namespace frontend diff --git a/src/frontends/gtk/Makefile.am b/src/frontends/gtk/Makefile.am index 2ad37f86c5..515d74b8a2 100644 --- a/src/frontends/gtk/Makefile.am +++ b/src/frontends/gtk/Makefile.am @@ -138,10 +138,10 @@ libgtk_la_SOURCES = \ ghelpers.C \ ghelpers.h \ GuiImplementation.h \ + GuiImplementation.C \ io_callback.C \ io_callback.h \ lyx_gui.C \ xftFontLoader.C \ xftFontLoader.h \ xftFontMetrics.C - diff --git a/src/frontends/gtk/lyx_gui.C b/src/frontends/gtk/lyx_gui.C index 5aa788bdb0..1f2bef7b6d 100644 --- a/src/frontends/gtk/lyx_gui.C +++ b/src/frontends/gtk/lyx_gui.C @@ -43,6 +43,7 @@ #include "lyxsocket.h" #include "BufferView.h" +#include "GuiImplementation.h" #include "GView.h" #include "GtkmmX.h" @@ -75,6 +76,8 @@ using std::string; using lyx::support::package; using lyx::frontend::colorCache; +using lyx::frontend::Gui; +using lyx::frontend::GuiImplementation; using lyx::frontend::GView; @@ -99,10 +102,25 @@ 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; void lyx_gui::exec(int & argc, char * argv[]) { - new Gtk::Main(argc, argv); + theApp = new Application(argc, argv); using namespace lyx::graphics; Image::newImage = boost::bind(&LyXGdkImage::newImage); @@ -125,10 +143,12 @@ void lyx_gui::parse_lyxrc() void lyx_gui::start(string const & batch, std::vector const & files, unsigned int width, unsigned int height, int posx, int posy, bool) { - boost::shared_ptr view_ptr(new GView); - LyX::ref().addLyXView(view_ptr); + 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); - GView & view = *view_ptr.get(); view.show(); view.init(); @@ -146,7 +166,7 @@ void lyx_gui::start(string const & batch, std::vector const & files, view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch)); } - Gtk::Main::run(); + theApp->run(); // FIXME: breaks emergencyCleanup delete lyxsocket; @@ -157,7 +177,7 @@ void lyx_gui::start(string const & batch, std::vector const & files, void lyx_gui::exit(int /*status*/) { // FIXME: Don't ignore status - Gtk::Main::quit(); + theApp->quit(); } diff --git a/src/frontends/qt3/GuiImplementation.h b/src/frontends/qt3/GuiImplementation.h index d210d14e43..adf345b7b6 100644 --- a/src/frontends/qt3/GuiImplementation.h +++ b/src/frontends/qt3/GuiImplementation.h @@ -13,19 +13,22 @@ #define GUI_IMPLEMENTATION_H #include "frontends/Gui.h" -#include "frontends/LyXView.h" +#include "QtView.h" #include "qscreen.h" #include "QWorkArea.h" #include "GuiClipboard.h" #include "GuiWorkArea.h" +#include "BufferView.h" + #include namespace lyx { namespace frontend { +typedef QtView FView; typedef QScreen FScreen; typedef QWorkArea FWorkArea; @@ -35,7 +38,7 @@ typedef QWorkArea FWorkArea; class GuiImplementation: public lyx::frontend::Gui { public: - GuiImplementation(LyXView & owner): owner_(owner) + GuiImplementation() { } @@ -48,22 +51,45 @@ public: return *clipboard_; } - int newWorkArea(int w, int h) + int newView(unsigned int /*w*/, unsigned int /*h*/) + { + view_.reset(new FView(*this)); + return 0; + } + + + LyXView& view(int /*id*/) + { + return *view_; + } + + + void destroyView(int /*id*/) + { + view_.reset(); + } + + int newWorkArea(unsigned int w, unsigned int h, int /*view_id*/) { - old_work_area_.reset(new FWorkArea(owner_, w, h)); + old_work_area_.reset(new FWorkArea(*view_.get(), w, h)); old_screen_.reset(new FScreen(*old_work_area_.get())); - work_area_.reset(new GuiWorkArea(owner_, w, h, old_screen_.get(), old_work_area_.get())); + work_area_.reset(new GuiWorkArea(old_screen_.get(), old_work_area_.get())); clipboard_.reset(new GuiClipboard(old_work_area_.get())); guiCursor().connect(work_area_.get()); + + // FIXME BufferView creation should be independant of WorkArea creation + buffer_views_[0].reset(new BufferView(view_.get(), work_area_.get())); + work_area_->setBufferView(buffer_views_[0].get()); + view_->setBufferView(buffer_views_[0].get()); return 0; } - lyx::frontend::WorkArea& workArea(int id) + lyx::frontend::WorkArea& workArea(int /*id*/) { return *work_area_; } - void destroyWorkArea(int id) + void destroyWorkArea(int /*id*/) { clipboard_.reset(); work_area_.reset(); @@ -77,11 +103,11 @@ private: /// boost::shared_ptr work_area_; /// + boost::shared_ptr view_; + /// boost::shared_ptr old_work_area_; /// boost::shared_ptr old_screen_; - /// - LyXView & owner_; }; } // namespace frontend diff --git a/src/frontends/qt3/GuiWorkArea.h b/src/frontends/qt3/GuiWorkArea.h index bdf3fc8ef5..a4879d17b5 100644 --- a/src/frontends/qt3/GuiWorkArea.h +++ b/src/frontends/qt3/GuiWorkArea.h @@ -29,10 +29,8 @@ typedef QWorkArea FWorkArea; */ class GuiWorkArea: public lyx::frontend::WorkArea { public: - GuiWorkArea(LyXView & owner, int w, int h, - FScreen * screen, FWorkArea * work_area) - : lyx::frontend::WorkArea(owner, w, h), - old_screen_(screen), old_work_area_(work_area) + GuiWorkArea(FScreen * screen, FWorkArea * work_area) + : old_screen_(screen), old_work_area_(work_area) { } @@ -69,7 +67,7 @@ public: /// paint the cursor and store the background - virtual void showCursor(int x, int y, int h, Cursor_Shape shape) + virtual void showCursor(int x, int y, int h, CursorShape shape) { old_screen_->showCursor(x, y, h, shape); } diff --git a/src/frontends/qt3/QContentPane.C b/src/frontends/qt3/QContentPane.C index a9b16162ed..a244db3734 100644 --- a/src/frontends/qt3/QContentPane.C +++ b/src/frontends/qt3/QContentPane.C @@ -337,15 +337,17 @@ void QContentPane::resizeEvent(QResizeEvent *) } pixmap_->resize(width(), height()); - wa_->view().view()->workAreaResize(); + wa_->view().view()->workAreaResize(width(), height()); } void QContentPane::paintEvent(QPaintEvent * e) { + BufferView * buffer_view_ = wa_->view().view(); + if (!pixmap_.get()) { pixmap_.reset(new QPixmap(width(), height())); - wa_->view().view()->workAreaResize(); + buffer_view_->workAreaResize(width(), height()); return; } @@ -354,6 +356,14 @@ void QContentPane::paintEvent(QPaintEvent * e) QPainter q(this); q.drawPixmap(QPoint(r.x(), r.y()), *pixmap_.get(), r); + + buffer_view_->updateScrollbar(); + ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters(); + + wa_->scrollbar_->setTracking(false); + wa_->setScrollbarParams(scroll_.height, scroll_.position, + scroll_.lineScrollHeight); + wa_->scrollbar_->setTracking(true); } diff --git a/src/frontends/qt3/QtView.C b/src/frontends/qt3/QtView.C index e79be58db6..4b4847e98c 100644 --- a/src/frontends/qt3/QtView.C +++ b/src/frontends/qt3/QtView.C @@ -37,8 +37,6 @@ #include #include -#include - using std::string; FontLoader fontloader; @@ -56,14 +54,28 @@ int const statusbar_timer_value = 3000; } // namespace anon - -QtView::QtView() - : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this) +QtView::QtView(Gui & owner) + : QMainWindow(), LyXView(owner), commandbuffer_(0) { qApp->setMainWidget(this); - bufferview_.reset(new BufferView(this, width(), height())); +#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. + string const iconname = libFileSearch("images", "lyx", "xpm"); + if (!iconname.empty()) + setIcon(QPixmap(toqstr(iconname))); +#endif +} + + +QtView::~QtView() +{ +} + +void QtView::init() +{ menubar_.reset(new QLMenubar(this, menubackend)); getToolbars().init(); @@ -72,25 +84,14 @@ QtView::QtView() view_state_changed.connect(boost::bind(&QtView::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. - string const iconname = libFileSearch("images", "lyx", "xpm"); - if (!iconname.empty()) - setIcon(QPixmap(toqstr(iconname))); -#endif - // make sure the buttons are disabled if needed updateToolbars(); // allowing the toolbars to tear off is too easily done, // and we don't save their orientation anyway. Disable the handle. setToolBarsMovable(false); -} - - -QtView::~QtView() -{ + + LyXView::init(); } @@ -182,13 +183,13 @@ void QtView::resizeEvent(QResizeEvent *) void QtView::moveEvent(QMoveEvent *) { - updateFloatingGeometry(); + updateFloatingGeometry(); } void QtView::closeEvent(QCloseEvent *) { - updateFloatingGeometry(); + updateFloatingGeometry(); QRect geometry = floatingGeometry_; Session & session = LyX::ref().session(); diff --git a/src/frontends/qt3/QtView.h b/src/frontends/qt3/QtView.h index 75286f8d06..a87533b7c3 100644 --- a/src/frontends/qt3/QtView.h +++ b/src/frontends/qt3/QtView.h @@ -13,13 +13,10 @@ #ifndef QTVIEW_H #define QTVIEW_H -// Must be here because of moc. #include #include "frontends/LyXView.h" -#include "GuiImplementation.h" - #include #include @@ -38,11 +35,14 @@ class QCommandBuffer; class QtView : public QMainWindow, public LyXView { Q_OBJECT public: - /// create a main window - QtView(); + /// create a main window of the given dimensions + QtView(Gui & owner); ~QtView(); + /// initialise the object members (menubars, toolbars, etc..) + void init(); + /// show - display the top-level window void show(); @@ -64,9 +64,6 @@ public: // returns true if this view has the focus. virtual bool hasFocus() const; - // - lyx::frontend::Gui & gui() { return frontend_; } - /// void initFloatingGeometry(QRect const &); @@ -102,9 +99,6 @@ private: /// command buffer QCommandBuffer * commandbuffer_; - /// - GuiImplementation frontend_; - /// void updateFloatingGeometry(); /// diff --git a/src/frontends/qt3/lyx_gui.C b/src/frontends/qt3/lyx_gui.C index 7336f7f616..b0930f3da1 100644 --- a/src/frontends/qt3/lyx_gui.C +++ b/src/frontends/qt3/lyx_gui.C @@ -40,6 +40,7 @@ #include #include +#include "GuiImplementation.h" #include "QtView.h" #include "lcolorcache.h" #include "qfont_loader.h" @@ -62,6 +63,8 @@ using lyx::support::ltrim; using lyx::support::package; +using lyx::frontend::Gui; +using lyx::frontend::GuiImplementation; using lyx::frontend::QtView; namespace os = lyx::support::os; @@ -121,12 +124,19 @@ class LQApplication : public QApplication { public: LQApplication(int & argc, char ** argv); + // + Gui & gui() { return gui_; } + #ifdef Q_WS_X11 bool x11EventFilter (XEvent * ev) { return lyxX11EventFilter(ev); } #endif #ifdef Q_WS_MACX bool macEventFilter(EventRef event); #endif + +private: + /// + GuiImplementation gui_; }; @@ -155,6 +165,7 @@ bool LQApplication::macEventFilter(EventRef event) } #endif +LQApplication * theApp; namespace lyx_gui { @@ -167,6 +178,7 @@ void exec(int & argc, char * argv[]) FontLoader::initFontPath(); LQApplication app(argc, argv); + theApp = &app; #if QT_VERSION >= 0x030200 // install translation file for Qt built-in dialogs @@ -227,14 +239,15 @@ void start(string const & batch, vector const & files, // this can't be done before because it needs the Languages object initEncodings(); - boost::shared_ptr view_ptr(new QtView); - LyX::ref().addLyXView(view_ptr); + int view_id = theApp->gui().newView(width, height); + QtView & view = static_cast (theApp->gui().view(view_id)); + theApp->gui().newWorkArea(width, height, 0); - QtView & view = *view_ptr.get(); + LyX::ref().addLyXView(&view); view.init(); - if (width != -1 && height != -1) { + if (width != -1 && height != -1) { view.initFloatingGeometry(QRect(posx, posy, width, height)); view.resize(width, height); if (posx != -1 && posy != -1) diff --git a/src/frontends/qt3/qscreen.C b/src/frontends/qt3/qscreen.C index ba4cf89dea..4ca1498eed 100644 --- a/src/frontends/qt3/qscreen.C +++ b/src/frontends/qt3/qscreen.C @@ -60,7 +60,7 @@ void QScreen::expose(int x, int y, int w, int h) } -void QScreen::showCursor(int x, int y, int h, Cursor_Shape shape) +void QScreen::showCursor(int x, int y, int h, CursorShape shape) { if (!qApp->focusWidget()) return; diff --git a/src/frontends/qt3/qscreen.h b/src/frontends/qt3/qscreen.h index fed647d2e8..f00efa7a9f 100644 --- a/src/frontends/qt3/qscreen.h +++ b/src/frontends/qt3/qscreen.h @@ -40,7 +40,7 @@ public: virtual void expose(int x, int y, int exp_width, int exp_height); /// paint the cursor and store the background - virtual void showCursor(int x, int y, int h, lyx::frontend::Cursor_Shape shape); + virtual void showCursor(int x, int y, int h, lyx::frontend::CursorShape shape); /// hide the cursor virtual void removeCursor(); diff --git a/src/frontends/qt4/Action.C b/src/frontends/qt4/Action.C index 83381bdadf..edfc308f19 100644 --- a/src/frontends/qt4/Action.C +++ b/src/frontends/qt4/Action.C @@ -19,7 +19,7 @@ #include -#include "LyXView.h" +#include "frontends/LyXView.h" #include "qt_helpers.h" #include "Action.h" diff --git a/src/frontends/qt4/FontLoader.h b/src/frontends/qt4/FontLoader.h index f0b4512ab4..3dbf151c1d 100644 --- a/src/frontends/qt4/FontLoader.h +++ b/src/frontends/qt4/FontLoader.h @@ -97,6 +97,4 @@ private: QLFontInfo * fontinfo_[LyXFont::NUM_FAMILIES][2][4][10]; }; -extern FontLoader fontloader; - #endif // QFONT_LOADER_H diff --git a/src/frontends/qt4/GuiImplementation.C b/src/frontends/qt4/GuiImplementation.C index 459176d31a..d66aa4e956 100644 --- a/src/frontends/qt4/GuiImplementation.C +++ b/src/frontends/qt4/GuiImplementation.C @@ -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 @@ Clipboard& GuiImplementation::clipboard() } -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)); + return id; } -WorkArea& GuiImplementation::workArea(int id) + +LyXView& GuiImplementation::view(int id) { - BOOST_ASSERT(work_areas_.find(id) != work_areas_.end()); + 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()); + return *work_areas_[id].get(); } diff --git a/src/frontends/qt4/GuiImplementation.h b/src/frontends/qt4/GuiImplementation.h index 4cd8bfc817..ad1ebc614b 100644 --- a/src/frontends/qt4/GuiImplementation.h +++ b/src/frontends/qt4/GuiImplementation.h @@ -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 +class LyXView; + namespace lyx { namespace frontend { @@ -32,27 +34,34 @@ class GuiView; 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 > views_; + /// std::map > 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 diff --git a/src/frontends/qt4/GuiView.C b/src/frontends/qt4/GuiView.C index 07b77b3c72..16d35c9748 100644 --- a/src/frontends/qt4/GuiView.C +++ b/src/frontends/qt4/GuiView.C @@ -34,6 +34,7 @@ #include #include "GuiView.h" +#include "GuiImplementation.h" #include "QLMenubar.h" #include "FontLoader.h" #include "QCommandBuffer.h" @@ -45,6 +46,8 @@ #include #include #include +//#include +//#include #include "support/lstrings.h" @@ -52,8 +55,6 @@ using std::string; using std::endl; -FontLoader fontloader; - namespace lyx { using support::subst; @@ -68,26 +69,15 @@ int const statusbar_timer_value = 3000; } // namespace anon -GuiView::GuiView() - : QMainWindow(), LyXView(), commandbuffer_(0), frontend_(*this) +GuiView::GuiView(Gui & owner) + : QMainWindow(), LyXView(owner), commandbuffer_(0) { mainWidget_ = this; // setToolButtonStyle(Qt::ToolButtonIconOnly); // setIconSize(QSize(12,12)); - // -geometry could set the width and hight - bufferview_.reset(new BufferView(this, geometry().width(), geometry().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())); +// bufferview_.reset(new BufferView(this, width, height)); #ifndef Q_WS_MACX // assign an icon to main form. We do not do it under Qt/Mac, @@ -96,9 +86,6 @@ GuiView::GuiView() if (!iconname.empty()) setWindowIcon(QPixmap(toqstr(iconname))); #endif - - // make sure the buttons are disabled if needed - updateToolbars(); } @@ -106,6 +93,25 @@ GuiView::~GuiView() { } + +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(); diff --git a/src/frontends/qt4/GuiView.h b/src/frontends/qt4/GuiView.h index f77fbc7989..6173ac5fbb 100644 --- a/src/frontends/qt4/GuiView.h +++ b/src/frontends/qt4/GuiView.h @@ -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 -#include "GuiImplementation.h" - #include "frontends/LyXView.h" #include "funcrequest.h" @@ -43,16 +41,19 @@ QWidget* mainWindow(); /** * 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 - GuiView(); + /// create a main window of the given dimensions + GuiView(Gui & owner); ~GuiView(); + /// initialize the object + virtual void init(); + /// show - display the top-level window void show(); @@ -71,12 +72,10 @@ public: /// 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: @@ -118,8 +117,6 @@ private: /// static QMainWindow* mainWidget_; - GuiImplementation frontend_; - /// void updateFloatingGeometry(); /// diff --git a/src/frontends/qt4/GuiWorkArea.C b/src/frontends/qt4/GuiWorkArea.C index 324a134cfa..31c12467b3 100644 --- a/src/frontends/qt4/GuiWorkArea.C +++ b/src/frontends/qt4/GuiWorkArea.C @@ -13,10 +13,13 @@ #include +// 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" @@ -38,10 +41,14 @@ #include -// Abdel (09/06/2006): -// I want the drawing to be fast without Keyboard buffering so when working -// on optimization, please set the following macro to 0: -#define USE_KEY_BUFFERING 0 +// Abdel (26/06/2006): +// On windows-XP the UserGuide PageDown scroll test is faster without event pruning (16 s) +// than with it (23 s). +#ifdef Q_WS_WIN + #define USE_EVENT_PRUNING 0 +#else + #define USE_EVENT_PRUNING 0 +#endif using std::endl; using std::string; @@ -111,14 +118,12 @@ SyntheticMouseEvent::SyntheticMouseEvent() {} -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); @@ -155,7 +160,7 @@ GuiWorkArea::GuiWorkArea(LyXView & owner, int w, int h) << "\n viewport height\t" << viewport()->height() << endl; - if (USE_KEY_BUFFERING) { + if (USE_EVENT_PRUNING) { // This is the keyboard buffering stuff... // I don't see any need for this under windows. The keyboard is reactive // enough... @@ -168,20 +173,16 @@ GuiWorkArea::GuiWorkArea(LyXView & owner, int w, int h) step_timer_.start(50, true); } - /////////////////////////////////////////////////////////////////////// - // Specific stuff goes here... - -#if USE_INPUT_METHODS - // to make qt-immodule work - setInputMethodEnabled(true); -#endif - + // Enables input methods for asian languages. + // Must be set when creating custom text editing widgets. + setAttribute(Qt::WA_InputMethodEnabled, true); } GuiWorkArea::~GuiWorkArea() { } + void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step) { // do what cursor movement does (some grey) @@ -193,6 +194,7 @@ void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step verticalScrollBar()->setLineStep(scroll_line_step); } + void GuiWorkArea::adjustViewWithScrollBar(int) { /* @@ -205,7 +207,7 @@ void GuiWorkArea::adjustViewWithScrollBar(int) << " linestep=" << verticalScrollBar()->lineStep() << endl; */ - view_.view()->scrollDocView(verticalScrollBar()->sliderPosition()); + buffer_view_->scrollDocView(verticalScrollBar()->sliderPosition()); } @@ -229,7 +231,7 @@ void GuiWorkArea::dropEvent(QDropEvent* event) 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 +243,13 @@ void GuiWorkArea::mousePressEvent(QMouseEvent * e) 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 +260,7 @@ void GuiWorkArea::mouseReleaseEvent(QMouseEvent * e) 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 +320,7 @@ void GuiWorkArea::mouseMoveEvent(QMouseEvent * e) 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 +350,7 @@ void GuiWorkArea::generateSyntheticMouseEvent() 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); } } @@ -362,17 +364,18 @@ void GuiWorkArea::keyPressEvent(QKeyEvent * e) << " key=" << e->key() << endl; - if (USE_KEY_BUFFERING) { + if (USE_EVENT_PRUNING) { keyeventQueue_.push(boost::shared_ptr(new QKeyEvent(*e))); } else { boost::shared_ptr 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... + +// This is used only if USE_EVENT_PRUNING is defined... void GuiWorkArea::keyeventTimeout() { bool handle_autos = true; @@ -387,17 +390,17 @@ void GuiWorkArea::keyeventTimeout() continue; } - boost::shared_ptr sym(new QLyXKeySym); + boost::shared_ptr sym(new QLyXKeySym); sym->set(ev.get()); - lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION - << " count=" << ev->count() - << " text=" << (const char *) ev->text() - << " isAutoRepeat=" << ev->isAutoRepeat() - << " key=" << ev->key() - << endl; + lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION + << " count=" << ev->count() + << " text=" << (const char *) ev->text() + << " isAutoRepeat=" << ev->isAutoRepeat() + << " 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 +423,7 @@ void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e) 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 +438,7 @@ void GuiWorkArea::resizeEvent(QResizeEvent *) // paint_device_ = QImage(viewport()->width(), viewport()->height(), QImage::Format_RGB32); paint_device_ = QPixmap(viewport()->width(), viewport()->height()); - view_.view()->workAreaResize(); + buffer_view_->workAreaResize(viewport()->width(), viewport()->height()); /* lyxerr[Debug::GUI] << BOOST_CURRENT_FUNCTION @@ -484,6 +487,15 @@ void GuiWorkArea::paintEvent(QPaintEvent * e) if (show_hcursor_) q.drawPixmap(cursor_x_, cursor_y_ + cursor_h_ - 1, hcursor_); + + buffer_view_->updateScrollbar(); + + ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters(); + + verticalScrollBar()->setTracking(false); + setScrollbarParams(scroll_.height, scroll_.position, + scroll_.lineScrollHeight); + verticalScrollBar()->setTracking(true); } @@ -510,7 +522,7 @@ void GuiWorkArea::expose(int x, int y, int w, int h) } -void GuiWorkArea::showCursor(int x, int y, int h, Cursor_Shape shape) +void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape) { if (!qApp->focusWidget()) return; @@ -554,7 +566,7 @@ void GuiWorkArea::showCursor(int x, int y, int h, Cursor_Shape shape) // We cache two pixmaps: // 1 the vertical line of the cursor. // 2 the horizontal line of the L-shaped cursor (if necessary). - + // Draw the new (vertical) cursor. vcursor_ = QPixmap(cursor_w_, cursor_h_); vcursor_.fill(cursor_color_); @@ -578,20 +590,17 @@ void GuiWorkArea::removeCursor() viewport()->update(cursor_x_, cursor_y_, cursor_w_, cursor_h_); } -/////////////////////////////////////////////////////////////// -/////////////////////////////////////////////////////////////// -// Specific stuff - -//////////////////////////////////////////////////////////////////////// -// qt-immodule specific stuff goes here... - -#if USE_INPUT_METHODS -// to make qt-immodule work void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e) { - QString const text = e->text(); + QString const & text = e->commitString(); if (!text.isEmpty()) { + + lyxerr[Debug::KEY] << BOOST_CURRENT_FUNCTION + << " preeditString =" << (const char *) e->preeditString() + << " commitString =" << (const char *) e->commitString() + << endl; + int key = 0; // needed to make math superscript work on some systems // ideally, such special coding should not be necessary @@ -602,7 +611,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * e) } e->accept(); } -#endif + } // namespace frontend } // namespace lyx diff --git a/src/frontends/qt4/GuiWorkArea.h b/src/frontends/qt4/GuiWorkArea.h index 9a041c00cc..b44cad93c2 100644 --- a/src/frontends/qt4/GuiWorkArea.h +++ b/src/frontends/qt4/GuiWorkArea.h @@ -14,15 +14,10 @@ #ifndef WORKAREA_H #define WORKAREA_H -#if (defined(Q_WS_X11) && QT_VERSION >= 0x030200) -#define USE_INPUT_METHODS 1 -#endif - #ifdef emit #undef emit #endif -#include "frontends/LyXView.h" #include "frontends/WorkArea.h" #include "QLPainter.h" @@ -52,6 +47,8 @@ class QMouseEvent; namespace lyx { namespace frontend { +class GuiView; + /// for emulating triple click class double_click { public: @@ -104,7 +101,7 @@ class GuiWorkArea: public QAbstractScrollArea, public WorkArea { 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 @@ -138,14 +135,12 @@ public: QPixmap is implicitely shared so no need to pass by reference. */ 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); /// paint the cursor and store the background - virtual void showCursor(int x, int y, int h, Cursor_Shape shape); + virtual void showCursor(int x, int y, int h, CursorShape shape); /// hide the cursor virtual void removeCursor(); @@ -169,11 +164,9 @@ protected: /// key press void keyPressEvent(QKeyEvent * e); -#if USE_INPUT_METHODS protected: /// IM events void inputMethodEvent(QInputMethodEvent * e); -#endif public slots: @@ -190,9 +183,6 @@ public slots: void adjustViewWithScrollBar(int action = 0); private: - /// - LyXView & view_; - /// Buffer view width. int workWidth_; @@ -244,7 +234,7 @@ private: /// QColor cursor_color_; /// - Cursor_Shape cursor_shape_; + CursorShape cursor_shape_; }; } // namespace frontend diff --git a/src/frontends/qt4/QLPainter.C b/src/frontends/qt4/QLPainter.C index 1124a426c0..8bc90f1d92 100644 --- a/src/frontends/qt4/QLPainter.C +++ b/src/frontends/qt4/QLPainter.C @@ -15,10 +15,12 @@ #include "GuiWorkArea.h" #include "QLImage.h" - #include "ColorCache.h" #include "FontLoader.h" +#include "Application.h" + +#include "debug.h" #include "language.h" #include "LColor.h" @@ -212,8 +214,8 @@ void QLPainter::smallCapsText(int x, int y, 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); @@ -254,7 +256,7 @@ void QLPainter::text(int x, int y, char const * s, size_t ls, if (f.realShape() != LyXFont::SMALLCAPS_SHAPE) { setQPainterPen(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); diff --git a/src/frontends/qt4/lyx_gui.C b/src/frontends/qt4/lyx_gui.C index 32ef21f94f..9c74df9a56 100644 --- a/src/frontends/qt4/lyx_gui.C +++ b/src/frontends/qt4/lyx_gui.C @@ -59,6 +59,7 @@ using lyx::support::ltrim; using lyx::support::package; +using lyx::frontend::GuiImplementation; using lyx::frontend::GuiView; using lyx::frontend::Application; @@ -78,6 +79,8 @@ using std::string; LyXServer * lyxserver; LyXServerSocket * lyxsocket; +lyx::frontend::Application * theApp; + namespace { int getDPI() @@ -133,6 +136,8 @@ void exec(int & argc, char * argv[]) Application app(argc, argv); #endif + theApp = &app; + // install translation file for Qt built-in dialogs // These are only installed since Qt 3.2.x @@ -194,14 +199,17 @@ void start(string const & batch, vector const & files, // this can't be done before because it needs the Languages object initEncodings(); - boost::shared_ptr view_ptr(new GuiView); + int view_id = theApp->gui().newView(width, height); + GuiView & view = static_cast (theApp->gui().view(view_id)); - LyX::ref().addLyXView(view_ptr); + // 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_); - GuiView & view = *view_ptr.get(); + LyX::ref().addLyXView(&view); view.init(); - + // only true when the -geometry option was NOT used if (width != -1 && height != -1) { if (posx != -1 && posy != -1) { @@ -317,13 +325,13 @@ void update_color(LColor_color) void update_fonts() { - fontloader.update(); + theApp->fontLoader().update(); } bool font_available(LyXFont const & font) { - return fontloader.available(font); + return theApp->fontLoader().available(font); } diff --git a/src/frontends/qt4/qfont_metrics.C b/src/frontends/qt4/qfont_metrics.C index 378c55c668..04d0908315 100644 --- a/src/frontends/qt4/qfont_metrics.C +++ b/src/frontends/qt4/qfont_metrics.C @@ -15,6 +15,7 @@ #include "frontends/lyx_gui.h" #include "FontLoader.h" +#include "Application.h" #include "language.h" @@ -28,7 +29,7 @@ int maxAscent(LyXFont const & f) { if (!lyx_gui::use_gui) return 1; - return fontloader.metrics(f).ascent(); + return theApp->fontLoader().metrics(f).ascent(); } @@ -38,7 +39,7 @@ int maxDescent(LyXFont const & f) 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 @@ int ascent(char c, LyXFont const & f) { 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 @@ int descent(char c, LyXFont const & f) { 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 @@ int lbearing(char c, LyXFont const & f) { if (!lyx_gui::use_gui) return 1; - return fontloader.metrics(f).leftBearing(c); + return theApp->fontLoader().metrics(f).leftBearing(c); } @@ -86,7 +87,7 @@ int rbearing(char c, LyXFont const & f) { 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 @@ int smallcapswidth(char const * s, size_t ls, LyXFont const & f) 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 @@ int width(char const * s, size_t ls, LyXFont const & f) 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 @@ int signedWidth(string const & s, LyXFont const & f) 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 rectText(string const & str, LyXFont const & f, 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; diff --git a/src/frontends/xforms/GuiClipboard.h b/src/frontends/xforms/GuiClipboard.h index 04ab2f2a34..34a4589345 100644 --- a/src/frontends/xforms/GuiClipboard.h +++ b/src/frontends/xforms/GuiClipboard.h @@ -19,15 +19,13 @@ namespace lyx { namespace frontend { -typedef XWorkArea FWorkArea; - /** * The XForms version of the Clipboard. */ class GuiClipboard: public lyx::frontend::Clipboard { public: - GuiClipboard(FWorkArea * work_area) + GuiClipboard(XWorkArea * work_area) : old_work_area_(work_area) { } @@ -54,7 +52,7 @@ public: //@} private: - FWorkArea * old_work_area_; + XWorkArea * old_work_area_; }; } // namespace frontend diff --git a/src/frontends/xforms/GuiImplementation.C b/src/frontends/xforms/GuiImplementation.C new file mode 100644 index 0000000000..c8c8377586 --- /dev/null +++ b/src/frontends/xforms/GuiImplementation.C @@ -0,0 +1,54 @@ +// -*- C++ -*- +/** + * \file xforms/GuiImplementation.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author Abdelrazak Younes + * + * Full author contact details are available in file CREDITS. + */ + +#include "GuiImplementation.h" + +#include "XFormsView.h" +#include "BufferView.h" + + +namespace lyx { +namespace frontend { + +int GuiImplementation::newView(unsigned int w, unsigned int h) +{ + view_.reset(new XFormsView(*this, w, h)); + return 0; +} + + +int GuiImplementation::newWorkArea(unsigned int w, unsigned int h, int /*view_id*/) +{ + old_work_area_.reset(new XWorkArea(*view_.get(), w, h)); + old_screen_.reset(new XScreen(*old_work_area_)); + work_area_.reset(new GuiWorkArea(boost::static_pointer_cast(old_screen_).get(), + boost::static_pointer_cast(old_work_area_).get())); + clipboard_.reset(new GuiClipboard(boost::static_pointer_cast(old_work_area_).get())); + guiCursor().connect(work_area_.get()); + + // FIXME BufferView creation should be independant of WorkArea creation + buffer_views_[0].reset(new BufferView(view_.get(), work_area_.get())); + work_area_->setBufferView(buffer_views_[0].get()); + view_->setBufferView(buffer_views_[0].get()); + return 0; +} + + +void GuiImplementation::destroyWorkArea(int /*id*/) +{ + clipboard_.reset(); + work_area_.reset(); + old_work_area_.reset(); + old_screen_.reset(); +} + +} // namespace frontend +} // namespace lyx diff --git a/src/frontends/xforms/GuiImplementation.h b/src/frontends/xforms/GuiImplementation.h index 3ecca0bdce..3f088ca3a9 100644 --- a/src/frontends/xforms/GuiImplementation.h +++ b/src/frontends/xforms/GuiImplementation.h @@ -23,21 +23,16 @@ #include -#include - namespace lyx { namespace frontend { -typedef XScreen FScreen; -typedef XWorkArea FWorkArea; - /** * The Gui class is the interface to all XForms components. */ -class GuiImplementation: public lyx::frontend::Gui +class GuiImplementation : public lyx::frontend::Gui { public: - GuiImplementation(LyXView & owner): owner_(owner) + GuiImplementation() { } @@ -45,45 +40,45 @@ public: { } - lyx::frontend::Clipboard& clipboard() + lyx::frontend::Clipboard & clipboard() { return *clipboard_; } - int newWorkArea(int w, int h) + int newView(unsigned int w, unsigned int h); + + + LyXView & view(int /*id*/) { - old_work_area_.reset(new FWorkArea(owner_, w, h)); - old_screen_.reset(new FScreen(*old_work_area_.get())); - work_area_.reset(new GuiWorkArea(owner_, w, h, old_screen_.get(), old_work_area_.get())); - clipboard_.reset(new GuiClipboard(old_work_area_.get())); - guiCursor().connect(work_area_.get()); - return 0; + return *view_; } - lyx::frontend::WorkArea& workArea(int id) + + void destroyView(int /*id*/) { - return *work_area_; + view_.reset(); } - void destroyWorkArea(int id) + int newWorkArea(unsigned int w, unsigned int h, int view_id); + + lyx::frontend::WorkArea & workArea(int /*id*/) { - clipboard_.reset(); - work_area_.reset(); - old_work_area_.reset(); - old_screen_.reset(); + return *work_area_; } + void destroyWorkArea(int id); + private: /// boost::shared_ptr clipboard_; /// boost::shared_ptr work_area_; /// - boost::shared_ptr old_work_area_; + boost::shared_ptr view_; /// - boost::shared_ptr old_screen_; + boost::shared_ptr old_work_area_; /// - LyXView & owner_; + boost::shared_ptr old_screen_; }; } // namespace frontend diff --git a/src/frontends/xforms/GuiWorkArea.h b/src/frontends/xforms/GuiWorkArea.h index a595e6fc7b..a59c5731c1 100644 --- a/src/frontends/xforms/GuiWorkArea.h +++ b/src/frontends/xforms/GuiWorkArea.h @@ -20,19 +20,14 @@ namespace lyx { namespace frontend { -typedef XScreen FScreen; -typedef XWorkArea FWorkArea; - /** * Temporary wrapper around XWorkArea and XScreen. * Please refer to the Qt4 implementation for a proper cleanup of the API. */ class GuiWorkArea: public lyx::frontend::WorkArea { public: - GuiWorkArea(LyXView & owner, int w, int h, - FScreen * screen, FWorkArea * work_area) - : lyx::frontend::WorkArea(owner, w, h), - old_screen_(screen), old_work_area_(work_area) + GuiWorkArea(XScreen * screen, XWorkArea * work_area) + : old_screen_(screen), old_work_area_(work_area) { } @@ -69,7 +64,7 @@ public: /// paint the cursor and store the background - virtual void showCursor(int x, int y, int h, Cursor_Shape shape) + virtual void showCursor(int x, int y, int h, CursorShape shape) { old_screen_->showCursor(x, y, h, shape); } @@ -88,8 +83,8 @@ protected: } private: - FScreen * old_screen_; - FWorkArea * old_work_area_; + XScreen * old_screen_; + XWorkArea * old_work_area_; }; } // namespace frontend diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index a7afd7cd64..79548de620 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -158,6 +158,7 @@ libxforms_la_SOURCES = \ FormWrap.h \ GuiClipboard.h \ GuiImplementation.h \ + GuiImplementation.C \ GuiWorkArea.h \ LayoutEngine.C \ LayoutEngine.h \ diff --git a/src/frontends/xforms/XFormsView.C b/src/frontends/xforms/XFormsView.C index 62410a03e4..c6d0ee12dc 100644 --- a/src/frontends/xforms/XFormsView.C +++ b/src/frontends/xforms/XFormsView.C @@ -71,10 +71,10 @@ void print_metrics(std::ostream & os, std::string const & name, Box const & box) } -XFormsView::XFormsView(int width, int height) - : LyXView(), +XFormsView::XFormsView(Gui & owner, int width, int height) + : LyXView(owner), window_(Box(width, height)), - icon_pixmap_(0), icon_mask_(0), frontend_(*this) + icon_pixmap_(0), icon_mask_(0) { int const air = 2; @@ -108,7 +108,6 @@ XFormsView::XFormsView(int width, int height) menubar_.reset(new XFormsMenubar(this, menubackend)); getToolbars().init(); - bufferview_.reset(new BufferView(this, width, height)); minibuffer_.reset(new XMiniBuffer(*this, *controlcommand_)); // Assign an icon to the main form. @@ -138,7 +137,7 @@ XFormsView::XFormsView(int width, int height) focus_command_buffer.connect(boost::bind(&XMiniBuffer::focus, minibuffer_.get())); // Make sure the buttons are disabled if needed. - updateToolbars(); + //updateToolbars(); redraw_con = getDialogs().redrawGUI().connect(boost::bind(&XFormsView::redraw, this)); } diff --git a/src/frontends/xforms/XFormsView.h b/src/frontends/xforms/XFormsView.h index 91099b00db..79bb4f84b2 100644 --- a/src/frontends/xforms/XFormsView.h +++ b/src/frontends/xforms/XFormsView.h @@ -12,7 +12,6 @@ #ifndef LyXView_H #define LyXView_H -#include "GuiImplementation.h" #include "LayoutEngine.h" #include "forms_fwd.h" @@ -44,7 +43,7 @@ public: }; /// create a main window of the given dimensions - XFormsView(int w, int h); + XFormsView(Gui & owner, int w, int h); ~XFormsView(); @@ -83,9 +82,6 @@ public: // returns true if this view has the focus. virtual bool hasFocus() const; - /// - Gui & gui() { return frontend_; } - private: /** * setWindowTitle - set title of window @@ -120,8 +116,6 @@ private: Pixmap icon_pixmap_; /// Pixmap icon_mask_; - /// - GuiImplementation frontend_; }; } // namespace frontend diff --git a/src/frontends/xforms/XWorkArea.C b/src/frontends/xforms/XWorkArea.C index b4e131ef75..e329173abc 100644 --- a/src/frontends/xforms/XWorkArea.C +++ b/src/frontends/xforms/XWorkArea.C @@ -109,13 +109,20 @@ int C_event_cb(FL_FORM * form, void * xev) XWorkArea::XWorkArea(LyXView & owner, int w, int h) - : view_(owner), workareapixmap(0), painter_(*this) + : view_(owner), workareapixmap(0), painter_(*this) { fl_freeze_all_forms(); FL_OBJECT * obj; FL_OBJECT * frame; + XFormsView & xview = dynamic_cast(owner); + + // Set the current form so that objects have something to get + // added to. + //fl_addto_form(fl_current_form); + fl_addto_form(xview.getForm()); + // A frame around the work area. frame = obj = fl_add_box(FL_BORDER_BOX, 0, 0, w, h, ""); fl_set_object_resize(obj, FL_RESIZE_ALL); @@ -150,7 +157,6 @@ XWorkArea::XWorkArea(LyXView & owner, int w, int h) // Hand control of the layout of these widgets to the // Layout Engine. - XFormsView & xview = dynamic_cast(owner); BoxList & boxlist = xview.getBox(XFormsView::Center)->children(); wa_box_ = boxlist.push_back(Box(0,0)); @@ -179,6 +185,8 @@ XWorkArea::XWorkArea(LyXView & owner, int w, int h) val.function = GXcopy; copy_gc = XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0), GCFunction, &val); + + fl_end_form(); } @@ -220,7 +228,7 @@ void XWorkArea::redraw(int width, int height) height, fl_get_visual_depth()); - view_.view()->workAreaResize(); + view_.view()->workAreaResize(width, height); } diff --git a/src/frontends/xforms/XWorkArea.h b/src/frontends/xforms/XWorkArea.h index 2f83c933a6..23209825b7 100644 --- a/src/frontends/xforms/XWorkArea.h +++ b/src/frontends/xforms/XWorkArea.h @@ -31,7 +31,7 @@ public: /// XWorkArea(LyXView & owner, int width, int height); /// - ~XWorkArea(); + virtual ~XWorkArea(); /// virtual Painter & getPainter() { return painter_; } /// @@ -66,8 +66,8 @@ public: /// handles SelectionRequest X Event, to fill the clipboard int event_cb(XEvent * xev); private: - LyXView & view_; - + LyXView & view_; + /// generate the pixmap, and copy backing pixmap to it, /// and send resize event if needed void redraw(int, int); diff --git a/src/frontends/xforms/lyx_gui.C b/src/frontends/xforms/lyx_gui.C index c6c0bfb061..5e9a6b421d 100644 --- a/src/frontends/xforms/lyx_gui.C +++ b/src/frontends/xforms/lyx_gui.C @@ -16,6 +16,7 @@ #include "xfont_loader.h" #include "xforms_helpers.h" #include "xformsImage.h" +#include "GuiImplementation.h" #include "XFormsView.h" #include "bufferlist.h" @@ -54,6 +55,8 @@ using lyx::frontend::fontloader; using lyx::frontend::lyxColorHandler; using lyx::frontend::LyXColorHandler; using lyx::frontend::XformsColor; +using lyx::frontend::Gui; +using lyx::frontend::GuiImplementation; using lyx::frontend::XFormsView; namespace os = lyx::support::os; @@ -280,25 +283,30 @@ void start(string const & batch, vector const & files, lyxerr[Debug::GUI] << "Creating view: " << width << 'x' << height << '+' << posx << '+' << posy << endl; - boost::shared_ptr view(new XFormsView(width, height)); - LyX::ref().addLyXView(view); + GuiImplementation * gui = new GuiImplementation; - view->show(posx == -1 ? (WidthOfScreen(s) - width) / 2 : posx, + int view_id = gui->newView(width, height); + XFormsView & view = static_cast (gui->view(view_id)); + int workArea_id_ = gui->newWorkArea(width, height, 0); + + LyX::ref().addLyXView(&view); + + view.show(posx == -1 ? (WidthOfScreen(s) - width) / 2 : posx, posy == -1 ? (HeightOfScreen(s) - height) / 2 : posy, "LyX"); - view->init(); + view.init(); // FIXME: some code below needs moving - lyxserver = new LyXServer(&view->getLyXFunc(), lyxrc.lyxpipes); - lyxsocket = new LyXServerSocket(&view->getLyXFunc(), + lyxserver = new LyXServer(&view.getLyXFunc(), lyxrc.lyxpipes); + lyxsocket = new LyXServerSocket(&view.getLyXFunc(), os::internal_path(package().temp_dir() + "/lyxsocket")); for_each(files.begin(), files.end(), - bind(&BufferView::loadLyXFile, view->view(), _1, true)); + bind(&BufferView::loadLyXFile, view.view(), _1, true)); // handle the batch commands the user asked for if (!batch.empty()) - view->getLyXFunc().dispatch(lyxaction.lookupFunc(batch)); + view.getLyXFunc().dispatch(lyxaction.lookupFunc(batch)); // enter the event loop while (!finished) { diff --git a/src/frontends/xforms/xscreen.C b/src/frontends/xforms/xscreen.C index 640b881f63..3051d350bc 100644 --- a/src/frontends/xforms/xscreen.C +++ b/src/frontends/xforms/xscreen.C @@ -73,7 +73,7 @@ void XScreen::setCursorColor() } -void XScreen::showCursor(int x, int y, int h, Cursor_Shape shape) +void XScreen::showCursor(int x, int y, int h, CursorShape shape) { // Update the cursor color. (a little slow doing it like this ??) setCursorColor(); diff --git a/src/frontends/xforms/xscreen.h b/src/frontends/xforms/xscreen.h index 27f1d2c3f4..878bbc1b30 100644 --- a/src/frontends/xforms/xscreen.h +++ b/src/frontends/xforms/xscreen.h @@ -13,10 +13,10 @@ #ifndef XSCREEN_H #define XSCREEN_H -#include "frontends/GuiCursor.h" - #include // for Pixmap, GC +#include "frontends/GuiCursor.h" + class WorkArea; namespace lyx { @@ -44,7 +44,7 @@ public: virtual void expose(int x, int y, int w, int h); /// paint the cursor and store the background - virtual void showCursor(int x, int y, int h, Cursor_Shape shape); + virtual void showCursor(int x, int y, int h, CursorShape shape); /// hide the cursor virtual void removeCursor(); diff --git a/src/importer.C b/src/importer.C index 41aa3dd954..1c84d3d147 100644 --- a/src/importer.C +++ b/src/importer.C @@ -76,7 +76,7 @@ bool Importer::Import(LyXView * lv, string const & filename, 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)); } diff --git a/src/lyx_main.C b/src/lyx_main.C index 226bbb998f..cd9d079844 100644 --- a/src/lyx_main.C +++ b/src/lyx_main.C @@ -188,7 +188,7 @@ lyx::Session const & LyX::session() const } -void LyX::addLyXView(boost::shared_ptr const & lyxview) +void LyX::addLyXView(LyXView * lyxview) { views_.push_back(lyxview); } diff --git a/src/lyx_main.h b/src/lyx_main.h index 550619784a..d69e86a9d4 100644 --- a/src/lyx_main.h +++ b/src/lyx_main.h @@ -58,7 +58,7 @@ public: lyx::Session & session(); lyx::Session const & session() const; - void addLyXView(boost::shared_ptr 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,10 +105,10 @@ private: /// lyx session, containing lastfiles, lastfilepos, and lastopened boost::scoped_ptr session_; /// - typedef std::list > ViewList; + typedef std::list ViewList; ViewList views_; - /// + /// bool geometryOption_; }; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 41b04b281e..fa2ecf9cfc 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -724,7 +724,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd) dispatch_buffer.erase(); // redraw the screen at the end (first of the two drawing steps). - //This is done unless explicitely requested otherwise + //This is done unless explicitely requested otherwise bool update = true; // also do the second redrawing step. Only done if requested. bool updateforce = false; @@ -1157,7 +1157,6 @@ void LyXFunc::dispatch(FuncRequest const & cmd) view()->center(); // see BufferView_pimpl::center() - view()->updateScrollbar(); break; } @@ -1950,7 +1949,7 @@ string const LyXFunc::viewStatusMessage() BufferView * LyXFunc::view() const { BOOST_ASSERT(owner); - return owner->view().get(); + return owner->view(); } diff --git a/src/text3.C b/src/text3.C index 73604c8d50..d74494cefd 100644 --- a/src/text3.C +++ b/src/text3.C @@ -213,7 +213,6 @@ bool LyXText::cursorPrevious(LCursor & cur) updated |= cursorUp(cur); } - cur.bv().updateScrollbar(); finishUndo(); return updated; } @@ -236,7 +235,6 @@ bool LyXText::cursorNext(LCursor & cur) updated |= cursorDown(cur); } - cur.bv().updateScrollbar(); finishUndo(); return updated; } @@ -1167,7 +1165,6 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd) cur.resetAnchor(); moveCursor(cur, false); - bv->updateScrollbar(); break; }