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
This commit is contained in:
Angus Leeming 2004-04-27 14:48:13 +00:00
parent f439fef46d
commit e68157b774
8 changed files with 175 additions and 50 deletions

View File

@ -1,3 +1,17 @@
2004-04-27 Angus Leeming <leeming@lyx.org>
* 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 <leeming@lyx.org>
* ghelpers.[Ch]: new files.

View File

@ -68,7 +68,6 @@ GMenubar::GMenubar(LyXView *lyxView, MenuBackend const & /*menuBackend*/) :
view_(lyxView)
{
GView * gview = static_cast<GView*>(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));
}

View File

@ -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));

View File

@ -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,
&GToolbar::onLayoutSelected));
GView * gview = static_cast<GView*>(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);
GView::Position const position = getPosition(tbb.flags);
if (position == GView::Left || position == GView::Right)
toolbar->set_orientation(Gtk::ORIENTATION_VERTICAL);
GView * gview = static_cast<GView*>(view_);
gview->getBox(position).children().push_back(
Gtk::Box_Helpers::Element(*toolbar, Gtk::PACK_SHRINK));
if (tbb.flags & ToolbarBackend::ON)
toolbar->show();
vbox_.children().push_back(
Gtk::Box_Helpers::Element(*toolbar,
Gtk::PACK_SHRINK));
toolbars_.push_back(toolbar);
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<Gtk::Toolbar*>::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<Glib::ustring> strings;
for (LyXTextClass::const_iterator cit = tc.begin();

View File

@ -15,6 +15,7 @@
#include <gtkmm.h>
#include "frontends/Toolbar.h"
#include "ToolbarBackend.h"
#include <map>
class GToolbar : public Toolbar, public SigC::Object
@ -51,8 +52,8 @@ public:
private:
void onButtonClicked(FuncRequest);
void onLayoutSelected();
Gtk::VBox vbox_;
std::vector<Gtk::Toolbar*> toolbars_;
typedef std::map<std::string, Gtk::Toolbar*> ToolbarMap;
ToolbarMap toolbars_;
Gtk::Combo combo_;
LyXView * view_;
bool internal_;

View File

@ -12,17 +12,22 @@
#include <gtkmm.h>
#include "GView.h"
#include "MenuBackend.h"
#include "support/filetools.h"
#include "GMenubar.h"
#include "GToolbar.h"
#include "BufferView.h"
#include "XWorkArea.h"
#include "lyx_cb.h"
#include "GMiniBuffer.h"
#include "GToolbar.h"
#include "GWorkArea.h"
#include "BufferView.h"
#include "lyx_cb.h"
#include "lyxfunc.h"
#include "MenuBackend.h"
#include "support/filetools.h"
#include <boost/bind.hpp>
#include <vector>
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<Gtk::Box>(new Gtk::VBox));
box_store_.push_back(boost::shared_ptr<Gtk::Box>(new Gtk::HBox));
box_store_.push_back(boost::shared_ptr<Gtk::Box>(new Gtk::VBox));
box_store_.push_back(boost::shared_ptr<Gtk::Box>(new Gtk::HBox));
box_store_.push_back(boost::shared_ptr<Gtk::Box>(new Gtk::HBox));
box_store_.push_back(boost::shared_ptr<Gtk::Box>(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];
}

View File

@ -14,22 +14,34 @@
#include "frontends/LyXView.h"
#include "bufferview_funcs.h"
#include <memory>
#include <map>
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<Gtk::VBox> 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<Gtk::Box> BoxPtr;
typedef std::vector<BoxPtr> BoxStore;
BoxStore box_store_;
// Accessors to the various Boxes.
std::map<Position, BoxPtr> box_map_;
boost::scoped_ptr<GMiniBuffer> minibuffer_;
Gtk::Widget * workArea_;
};

View File

@ -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();