From e68157b7741f9195ce277c467a99b7c86a05daa7 Mon Sep 17 00:00:00 2001 From: Angus Leeming Date: Tue, 27 Apr 2004 14:48:13 +0000 Subject: [PATCH] The minimum changes needed to give the Gtk frontend dynamic toolbars, displayed at the expected position on the LyX screen. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8700 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/gtk/ChangeLog | 14 +++++++ src/frontends/gtk/GMenubar.C | 5 +-- src/frontends/gtk/GMiniBuffer.C | 15 ++++--- src/frontends/gtk/GToolbar.C | 74 ++++++++++++++++++++++----------- src/frontends/gtk/GToolbar.h | 5 ++- src/frontends/gtk/GView.C | 71 +++++++++++++++++++++++++++---- src/frontends/gtk/GView.h | 33 ++++++++++++--- src/frontends/gtk/GWorkArea.C | 4 +- 8 files changed, 173 insertions(+), 48 deletions(-) diff --git a/src/frontends/gtk/ChangeLog b/src/frontends/gtk/ChangeLog index 10df8f91dd..a57c88b2a3 100644 --- a/src/frontends/gtk/ChangeLog +++ b/src/frontends/gtk/ChangeLog @@ -1,3 +1,17 @@ +2004-04-27 Angus Leeming + + * GView.[Ch]: split the window into 'top', 'left', 'center', + 'right' and 'bottom' boxes. + (getBox): accessor for a particular box. + + * GMenubar.C (c-tor): + * GMiniBuffer.C (c-tor): + * GWorkArea.C (c-tor): + * GToolbar.C (add): access the correct Box in GView. + + * GToolbar.[Ch] (add, displayToolbar): show only those toolbars that + are flagged as 'ON'. + 2004-04-27 Angus Leeming * ghelpers.[Ch]: new files. diff --git a/src/frontends/gtk/GMenubar.C b/src/frontends/gtk/GMenubar.C index 91f60fba3e..80d211577e 100644 --- a/src/frontends/gtk/GMenubar.C +++ b/src/frontends/gtk/GMenubar.C @@ -68,7 +68,6 @@ GMenubar::GMenubar(LyXView *lyxView, MenuBackend const & /*menuBackend*/) : view_(lyxView) { GView * gview = static_cast(lyxView); - Gtk::VBox& vbox = gview->getVBox(); Menu const & menu = menubackend.getMenubar(); Menu::const_iterator i = menu.begin(); Menu::const_iterator end = menu.end(); @@ -90,8 +89,8 @@ GMenubar::GMenubar(LyXView *lyxView, MenuBackend const & /*menuBackend*/) : mainMenuNames_.push_back(i->submenuname()); } menubar_.show(); - vbox.children().push_back(Gtk::Box_Helpers::Element(menubar_, - Gtk::PACK_SHRINK)); + gview->getBox(GView::Top).children().push_back( + Gtk::Box_Helpers::Element(menubar_, Gtk::PACK_SHRINK)); } diff --git a/src/frontends/gtk/GMiniBuffer.C b/src/frontends/gtk/GMiniBuffer.C index 79a3ca9579..070a46777a 100644 --- a/src/frontends/gtk/GMiniBuffer.C +++ b/src/frontends/gtk/GMiniBuffer.C @@ -40,14 +40,16 @@ GMiniBuffer::GMiniBuffer(GView * view, ControlCommandBuffer & control) : listSel_ = listView_.get_selection(); listSel_->signal_changed().connect( SigC::slot(*this, &GMiniBuffer::onSelected)); + listView_.show(); scrolledWindow_.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); scrolledWindow_.set_size_request(300, 150); scrolledWindow_.add(listView_); - view_->getVBox().children().push_back( - Gtk::Box_Helpers::Element(scrolledWindow_, - Gtk::PACK_SHRINK)); + + view_->getBox(GView::Bottom).children().push_back( + Gtk::Box_Helpers::Element(scrolledWindow_,Gtk::PACK_SHRINK)); + entry_.signal_key_press_event().connect( SigC::slot(*this, &GMiniBuffer::onKeyPress)); entry_.signal_focus_in_event().connect( @@ -57,9 +59,10 @@ GMiniBuffer::GMiniBuffer(GView * view, ControlCommandBuffer & control) : entry_.signal_activate().connect( SigC::slot(*this, &GMiniBuffer::onCommit)); entry_.show(); - view_->getVBox().children().push_back( - Gtk::Box_Helpers::Element(entry_, - Gtk::PACK_SHRINK)); + + view_->getBox(GView::Bottom).children().push_back( + Gtk::Box_Helpers::Element(entry_, Gtk::PACK_SHRINK)); + infoTimer_.reset(new Timeout(1500)); idleTimer_.reset(new Timeout(6000)); focusTimer_.reset(new Timeout(50)); diff --git a/src/frontends/gtk/GToolbar.C b/src/frontends/gtk/GToolbar.C index 5799d5077a..5d975cdaac 100644 --- a/src/frontends/gtk/GToolbar.C +++ b/src/frontends/gtk/GToolbar.C @@ -31,6 +31,25 @@ using std::string; namespace { +GView::Position getPosition(ToolbarBackend::Flags const & flags) + { + if (flags & ToolbarBackend::TOP) + return GView::Top; + if (flags & ToolbarBackend::BOTTOM) + return GView::Bottom; + if (flags & ToolbarBackend::LEFT) + return GView::Left; + if (flags & ToolbarBackend::RIGHT) + return GView::Right; + return GView::Top; +} + + +LyXTextClass const & getTextClass(LyXView const & lv) +{ + return lv.buffer()->params().getLyXTextClass(); +} + char const * gToolData = "tool_data"; @@ -64,32 +83,35 @@ GToolbar::GToolbar(LyXView * lyxView, int /*x*/, int /*y*/) combo_.get_entry()->signal_changed().connect( SigC::slot(*this, >oolbar::onLayoutSelected)); - GView * gview = static_cast(lyxView); - vbox_.show(); - Gtk::VBox & vbox = gview->getVBox(); - vbox.children().push_back(Gtk::Box_Helpers::Element(vbox_, - Gtk::PACK_SHRINK)); } GToolbar::~GToolbar() -{ -} +{} -void GToolbar::add(ToolbarBackend::Toolbar const & tb) +void GToolbar::add(ToolbarBackend::Toolbar const & tbb) { Gtk::Toolbar * toolbar = manage(new Gtk::Toolbar); - ToolbarBackend::item_iterator it = tb.items.begin(); - ToolbarBackend::item_iterator end = tb.items.end(); + ToolbarBackend::item_iterator it = tbb.items.begin(); + ToolbarBackend::item_iterator end = tbb.items.end(); for (; it != end; ++it) add(toolbar, *it); toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS); - toolbar->show(); - vbox_.children().push_back( - Gtk::Box_Helpers::Element(*toolbar, - Gtk::PACK_SHRINK)); - toolbars_.push_back(toolbar); + + GView::Position const position = getPosition(tbb.flags); + + if (position == GView::Left || position == GView::Right) + toolbar->set_orientation(Gtk::ORIENTATION_VERTICAL); + + GView * gview = static_cast(view_); + gview->getBox(position).children().push_back( + Gtk::Box_Helpers::Element(*toolbar, Gtk::PACK_SHRINK)); + + if (tbb.flags & ToolbarBackend::ON) + toolbar->show(); + + toolbars_[tbb.name] = toolbar; } @@ -162,8 +184,7 @@ void GToolbar::onLayoutSelected() // we get two signal, one of it is empty and useless if (layoutGuiName.empty()) return; - LyXTextClass const & tc = - view_->buffer()->params().getLyXTextClass(); + LyXTextClass const & tc = getTextClass(*view_); LyXTextClass::const_iterator end = tc.end(); for (LyXTextClass::const_iterator cit = tc.begin(); @@ -181,17 +202,24 @@ void GToolbar::onLayoutSelected() } -void GToolbar::displayToolbar(ToolbarBackend::Toolbar const & /*tb*/, bool /*show*/) +void GToolbar::displayToolbar(ToolbarBackend::Toolbar const & tbb, bool show_it) { + ToolbarMap::iterator it = toolbars_.find(tbb.name); + BOOST_ASSERT(it != toolbars_.end()); + + if (show_it) + it->second->show(); + else + it->second->hide(); } void GToolbar::update() { - std::vector::iterator itToolbar; + ToolbarMap::iterator itToolbar; for (itToolbar = toolbars_.begin(); itToolbar != toolbars_.end(); ++itToolbar) { - Gtk::Toolbar * toolbar = *itToolbar; + Gtk::Toolbar * toolbar = itToolbar->second; Gtk::Toolbar_Helpers::ToolList::iterator it; for (it = toolbar->tools().begin(); it != toolbar->tools().end(); ++it) { @@ -234,8 +262,7 @@ void GToolbar::update() void GToolbar::setLayout(string const & layout) { - LyXTextClass const & tc = - view_->buffer()->params().getLyXTextClass(); + LyXTextClass const & tc = getTextClass(*view_); internal_ = true; combo_.get_entry()->set_text(tc[layout]->name()); internal_ = false; @@ -244,8 +271,7 @@ void GToolbar::setLayout(string const & layout) void GToolbar::updateLayoutList() { - LyXTextClass const & tc = - view_->buffer()->params().getLyXTextClass(); + LyXTextClass const & tc = getTextClass(*view_); LyXTextClass::const_iterator end = tc.end(); std::vector strings; for (LyXTextClass::const_iterator cit = tc.begin(); diff --git a/src/frontends/gtk/GToolbar.h b/src/frontends/gtk/GToolbar.h index 01b82a44c4..418e564430 100644 --- a/src/frontends/gtk/GToolbar.h +++ b/src/frontends/gtk/GToolbar.h @@ -15,6 +15,7 @@ #include #include "frontends/Toolbar.h" #include "ToolbarBackend.h" +#include class GToolbar : public Toolbar, public SigC::Object @@ -51,8 +52,8 @@ public: private: void onButtonClicked(FuncRequest); void onLayoutSelected(); - Gtk::VBox vbox_; - std::vector toolbars_; + typedef std::map ToolbarMap; + ToolbarMap toolbars_; Gtk::Combo combo_; LyXView * view_; bool internal_; diff --git a/src/frontends/gtk/GView.C b/src/frontends/gtk/GView.C index 9eaa217c09..66d2b2b55a 100644 --- a/src/frontends/gtk/GView.C +++ b/src/frontends/gtk/GView.C @@ -12,17 +12,22 @@ #include #include "GView.h" -#include "MenuBackend.h" -#include "support/filetools.h" #include "GMenubar.h" +#include "GMiniBuffer.h" #include "GToolbar.h" +#include "GWorkArea.h" + #include "BufferView.h" -#include "XWorkArea.h" #include "lyx_cb.h" -#include "GMiniBuffer.h" #include "lyxfunc.h" +#include "MenuBackend.h" + +#include "support/filetools.h" + #include +#include + using std::string; @@ -31,18 +36,65 @@ BufferView * current_view; GView * GView::view_ = 0; +namespace { + +void add_el(Gtk::Box::BoxList & list, Gtk::Box & box, bool shrink) +{ + Gtk::PackOptions const packing = + shrink ? Gtk::PACK_SHRINK : Gtk::PACK_EXPAND_WIDGET; + list.push_back(Gtk::Box_Helpers::Element(box, packing)); +} + +} // namespace anon + + GView::GView() { view_ = this; - vbox_.reset(new Gtk::VBox); - add(*vbox_.get()); + + // The physical store for the boxes making up the layout. + box_store_.push_back(boost::shared_ptr(new Gtk::VBox)); + box_store_.push_back(boost::shared_ptr(new Gtk::HBox)); + box_store_.push_back(boost::shared_ptr(new Gtk::VBox)); + box_store_.push_back(boost::shared_ptr(new Gtk::HBox)); + box_store_.push_back(boost::shared_ptr(new Gtk::HBox)); + box_store_.push_back(boost::shared_ptr(new Gtk::HBox)); + + // Lay them out correctly. + add(top_box_); + + Gtk::Box::BoxList & layout1 = top_box_.children(); + add_el(layout1, *box_store_[0], true); + add_el(layout1, *box_store_[1], true); + add_el(layout1, *box_store_[2], true); + + Gtk::Box::BoxList & layout2 = box_store_[1]->children(); + add_el(layout2, *box_store_[3], true); + add_el(layout2, *box_store_[4], false); + add_el(layout2, *box_store_[5], true); + + // Define accessors to the various Boxes. + box_map_[Top] = box_store_[0]; + box_map_[Bottom] = box_store_[2]; + box_map_[Left] = box_store_[3]; + box_map_[Center] = box_store_[4]; + box_map_[Right] = box_store_[5]; + + // Make all Boxes visible. + top_box_.show(); + BoxStore::iterator it = box_store_.begin(); + BoxStore::iterator const end = box_store_.end(); + for (; it != end; ++it) + (*it)->show(); + + // Define the components making up the window. menubar_.reset(new GMenubar(this, menubackend)); toolbar_.reset(new GToolbar(this, 0, 0)); toolbar_->init(); bufferview_.reset(new BufferView(this, 0, 0, 300, 300)); ::current_view = bufferview_.get(); minibuffer_.reset(new GMiniBuffer(this, *controlcommand_)); - vbox_->show(); + focus_command_buffer.connect( boost::bind(&GMiniBuffer::editMode, minibuffer_.get())); view_state_changed.connect(boost::bind(&GView::showViewState, this)); @@ -58,7 +110,12 @@ GView::GView() GView::~GView() +{} + + +Gtk::Box & GView::getBox(Position pos) { + return *box_map_[pos]; } diff --git a/src/frontends/gtk/GView.h b/src/frontends/gtk/GView.h index 039532bca5..a5b238bf70 100644 --- a/src/frontends/gtk/GView.h +++ b/src/frontends/gtk/GView.h @@ -14,22 +14,34 @@ #include "frontends/LyXView.h" #include "bufferview_funcs.h" -#include +#include + class GMiniBuffer; class GView : public LyXView, public Gtk::Window { public: - virtual ~GView(); + enum Position { + Top, + Bottom, + Left, + Right, + Center + }; + + GView(); + ~GView(); + + Gtk::Box & getBox(Position pos); virtual void prohibitInput() const; virtual void allowInput() const; virtual void message(std::string const &); - Gtk::VBox & getVBox() { return *vbox_.get(); } - GView(); + bool on_delete_event(GdkEventAny * event); void focusWorkArea() { workArea_->grab_focus(); } void setGWorkArea(Gtk::Widget * w) { workArea_ = w; } + static GView * instance() { return view_; } /// show busy cursor virtual void busy(bool) const; @@ -40,7 +52,18 @@ private: bool onFocusIn(GdkEventFocus * event); virtual void setWindowTitle(std::string const & t, std::string const & it); static GView * view_; - std::auto_ptr vbox_; + + // The top-most box containing all other boxes. + Gtk::VBox top_box_; + + // The physical store for the boxes making up the layout. + typedef boost::shared_ptr BoxPtr; + typedef std::vector BoxStore; + BoxStore box_store_; + + // Accessors to the various Boxes. + std::map box_map_; + boost::scoped_ptr minibuffer_; Gtk::Widget * workArea_; }; diff --git a/src/frontends/gtk/GWorkArea.C b/src/frontends/gtk/GWorkArea.C index ff57cd0460..42ba3bd2ef 100644 --- a/src/frontends/gtk/GWorkArea.C +++ b/src/frontends/gtk/GWorkArea.C @@ -177,8 +177,10 @@ GWorkArea::GWorkArea(int width, int height) hbox_.children().push_back( Gtk::Box_Helpers::Element(vscrollbar_,Gtk::PACK_SHRINK)); hbox_.show(); - GView::instance()->getVBox().children().push_back( + + GView::instance()->getBox(GView::Center).children().push_back( Gtk::Box_Helpers::Element(hbox_)); + workArea_.set_flags(workArea_.get_flags() | Gtk::CAN_DEFAULT | Gtk::CAN_FOCUS); workArea_.grab_default(); -- 2.39.5