gtk vspace dialog

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9257 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Spray 2004-11-16 00:20:59 +00:00
parent 827306f2ae
commit 59cd5ec173
9 changed files with 517 additions and 5 deletions

View File

@ -1,11 +1,14 @@
2004-11-15 John Spray <spray_john@users.sourceforge.net>
* The VSpace Dialog:
Dialogs.C, Makefile.am, GVSpace.C, GVSpace.h
* The Note Dialog:
Dialogs.C, Makefile.am, GNote.C, GNote.h
* The Float Dialog:
Dialogs.C, Makefile.am, GFloat.C, GFloat.h
* ghelpers.[Ch]: getGTKStockIcon added to choose gtk
stock icons for FuncRequests
stock icons for FuncRequests, buildLengthNoRelUnitList()
to get vector of units not containing "%"
* GToolbar.C: use getGTKStockIcon for toolbutton icons
* GMenubar.C: add icons to menu items

View File

@ -87,7 +87,7 @@
#include "GTableCreate.h"
#include "GToc.h"
#include "GUrl.h"
#include "FormVSpace.h"
#include "GVSpace.h"
#include "FormWrap.h"
#ifdef HAVE_LIBAIKSAURUS
@ -523,8 +523,9 @@ Dialogs::DialogPtr Dialogs::build(string const & name)
dialog->setView(new GUrl(*dialog));
dialog->bc().bp(new NoRepeatedApplyReadOnlyPolicy);
} else if (name == "vspace") {
dialog->bc().view(new GBC(dialog->bc()));
dialog->setController(new ControlVSpace(*dialog));
dialog->setView(new FormVSpace(*dialog));
dialog->setView(new GVSpace(*dialog));
dialog->bc().bp(new OkApplyCancelReadOnlyPolicy);
} else if (name == "wrap") {
dialog->setController(new ControlWrap(*dialog));

View File

@ -132,7 +132,7 @@ void GSpellchecker::partialUpdate(int s)
void GSpellchecker::onSuggestionActivate(
Gtk::TreeModel::Path const & path,
Gtk::TreeViewColumn * col)
Gtk::TreeViewColumn * /*col*/)
{
Glib::ustring const suggestion =
(*suggestionsstore_->get_iter(path))[listCol_];

164
src/frontends/gtk/GVSpace.C Normal file
View File

@ -0,0 +1,164 @@
/**
* \file GVSpace.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Spray
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "GVSpace.h"
#include "ControlVSpace.h"
#include "ghelpers.h"
#include <libglademm.h>
using std::string;
using std::vector;
namespace lyx {
namespace frontend {
namespace {
string defaultUnit("cm");
} // namespace anon
GVSpace::GVSpace(Dialog & parent)
: GViewCB<ControlVSpace, GViewGladeB>(parent, _("VSpace Settings"), false)
{}
void GVSpace::doBuild()
{
string const gladeName = findGladeFile("vspace");
xml_ = Gnome::Glade::Xml::create(gladeName);
Gtk::Button * button;
xml_->get_widget("Cancel", button);
setCancel(button);
xml_->get_widget("Insert", button);
setOK(button);
xml_->get_widget("Spacing", spacingcombo_);
xml_->get_widget("Value", valuespin_);
xml_->get_widget("ValueUnits", valueunitscombo_);
xml_->get_widget("Protect", protectcheck_);
cols_.add(stringcol_);
PopulateComboBox(valueunitscombo_, buildLengthNoRelUnitList());
spacingcombo_->signal_changed().connect(
sigc::mem_fun(*this, &GVSpace::onSpacingComboChanged));
}
void GVSpace::PopulateComboBox(Gtk::ComboBox * combo,
vector<string> const & strings)
{
Glib::RefPtr<Gtk::ListStore> model = Gtk::ListStore::create(cols_);
vector<string>::const_iterator it = strings.begin();
vector<string>::const_iterator end = strings.end();
for (int rowindex = 0; it != end; ++it, ++rowindex) {
Gtk::TreeModel::iterator row = model->append();
(*row)[stringcol_] = *it;
}
combo->set_model(model);
Gtk::CellRendererText * cell = Gtk::manage(new Gtk::CellRendererText);
combo->pack_start(*cell, true);
combo->add_attribute(*cell, "text", 0);
}
void GVSpace::update()
{
// set the right default unit
defaultUnit = getDefaultUnit();
VSpace const space = controller().params();
int pos = 0;
switch (space.kind()) {
case VSpace::DEFSKIP:
pos = 0;
break;
case VSpace::SMALLSKIP:
pos = 1;
break;
case VSpace::MEDSKIP:
pos = 2;
break;
case VSpace::BIGSKIP:
pos = 3;
break;
case VSpace::VFILL:
pos = 4;
break;
case VSpace::LENGTH:
pos = 5;
break;
}
spacingcombo_->set_active(pos);
protectcheck_->set_active(space.keep());
bool const custom_vspace = space.kind() == VSpace::LENGTH;
if (custom_vspace) {
LyXLength length(space.length().asString());
valuespin_->get_adjustment()->set_value(length.value());
unitsComboFromLength(valueunitscombo_, stringcol_,
length, defaultUnit);
} else {
valuespin_->get_adjustment()->set_value(0.0f);
unitsComboFromLength(valueunitscombo_, stringcol_,
LyXLength(defaultUnit), defaultUnit);
}
}
void GVSpace::apply()
{
VSpace space;
switch (spacingcombo_->get_active_row_number()) {
case 0:
space = VSpace(VSpace::DEFSKIP);
break;
case 1:
space = VSpace(VSpace::SMALLSKIP);
break;
case 2:
space = VSpace(VSpace::MEDSKIP);
break;
case 3:
space = VSpace(VSpace::BIGSKIP);
break;
case 4:
space = VSpace(VSpace::VFILL);
break;
case 5:
Glib::ustring const valueunit =
(*valueunitscombo_->get_active())[stringcol_];
space = VSpace(LyXGlueLength(valuespin_->get_text() + valueunit));
break;
}
space.setKeep(protectcheck_->get_active());
controller().params() = space;
}
void GVSpace::onSpacingComboChanged()
{
bool const custom = spacingcombo_->get_active_row_number() == 5;
valueunitscombo_->set_sensitive(custom);
valuespin_->set_sensitive(custom);
}
} // namespace frontend
} // namespace lyx

View File

@ -0,0 +1,49 @@
// -*- C++ -*-
/**
* \file GVSpace.h
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author John Spray
*
* Full author contact details are available in file CREDITS.
*/
#ifndef GVSPACE_H
#define GVSPACE_H
#include "GViewBase.h"
namespace lyx {
namespace frontend {
class ControlVSpace;
/** This class provides a GTK+ implementation of the VSpace Dialog.
*/
class GVSpace : public GViewCB<ControlVSpace, GViewGladeB> {
public:
GVSpace(Dialog & parent);
private:
virtual void apply();
virtual void doBuild();
virtual void update();
void PopulateComboBox(Gtk::ComboBox * combo,
std::vector<std::string> const & strings);
void onSpacingComboChanged();
Gtk::TreeModelColumn<Glib::ustring> stringcol_;
Gtk::TreeModel::ColumnRecord cols_;
Gtk::ComboBox * spacingcombo_;
Gtk::SpinButton * valuespin_;
Gtk::ComboBox * valueunitscombo_;
Gtk::CheckButton * protectcheck_;
};
} // namespace frontend
} // namespace lyx
#endif // GVSPACE_H

View File

@ -86,6 +86,8 @@ libgtk_la_SOURCES = \
GView.h \
GViewBase.C \
GViewBase.h \
GVSpace.C \
GVSpace.h \
GWorkArea.C \
GWorkArea.h \
GXpmBtnTbl.C \
@ -136,7 +138,6 @@ xforms_objects = \
../xforms/FormTabular.lo \
../xforms/FormText.lo \
../xforms/FormThesaurus.lo \
../xforms/FormVSpace.lo \
../xforms/FormWrap.lo \
../xforms/freebrowser.lo \
../xforms/input_validators.lo \

View File

@ -112,6 +112,19 @@ vector<string> const buildLengthUnitList()
}
vector<string> const buildLengthNoRelUnitList()
{
vector<string> data;
for (int i = 0; i < num_units; ++i) {
string str(unit_name_gui[i]);
if (str.find("%") == -1)
data.push_back(unit_name_gui[i]);
}
return data;
}
string const findGladeFile(string const & name)
{
// First, search in the installation directories.

View File

@ -37,6 +37,8 @@ void unitsComboFromLength(Gtk::ComboBox * combo,
std::vector<std::string> const buildLengthUnitList();
std::vector<std::string> const buildLengthNoRelUnitList();
/** name is the name of the glade file, without path or extension.
* Eg, "aboutlyx", "tableCreate".
*/

View File

@ -0,0 +1,279 @@
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<glade-interface>
<widget class="GtkDialog" id="dialog">
<property name="visible">True</property>
<property name="title" translatable="yes">dialog1</property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">False</property>
<property name="resizable">False</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area1">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="Cancel">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="Insert">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
<child>
<widget class="GtkAlignment" id="alignment1">
<property name="visible">True</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xscale">0</property>
<property name="yscale">0</property>
<property name="top_padding">0</property>
<property name="bottom_padding">0</property>
<property name="left_padding">0</property>
<property name="right_padding">0</property>
<child>
<widget class="GtkHBox" id="hbox2">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">2</property>
<child>
<widget class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="stock">gtk-ok</property>
<property name="icon_size">4</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="label" translatable="yes">_Insert</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
</widget>
</child>
</widget>
</child>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkTable" id="table1">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="n_rows">3</property>
<property name="n_columns">2</property>
<property name="homogeneous">False</property>
<property name="row_spacing">6</property>
<property name="column_spacing">6</property>
<child>
<widget class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">_Spacing:</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="label" translatable="yes">_Value:</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkComboBox" id="Spacing">
<property name="visible">True</property>
<property name="items" translatable="yes">DefSkip
SmallSkip
MedSkip
BigSkip
VFill
Custom</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="y_options">fill</property>
</packing>
</child>
<child>
<widget class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkSpinButton" id="Value">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="climb_rate">1</property>
<property name="digits">0</property>
<property name="numeric">False</property>
<property name="update_policy">GTK_UPDATE_ALWAYS</property>
<property name="snap_to_ticks">False</property>
<property name="wrap">False</property>
<property name="adjustment">1 0 10000 1 10 10</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
<child>
<widget class="GtkComboBox" id="ValueUnits">
<property name="visible">True</property>
</widget>
<packing>
<property name="padding">4</property>
<property name="expand">False</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<property name="y_options">fill</property>
</packing>
</child>
<child>
<widget class="GtkCheckButton" id="Protect">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">_Protect</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>