fixes for utils.cc in gtk2_ardour and gtkmm2ext, including switch to Pango::FontDescription rather than string

git-svn-id: svn://localhost/trunk/ardour2@53 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
Paul Davis 2005-10-09 12:51:04 +00:00
parent c38fdbc64c
commit 8e591b0587
8 changed files with 112 additions and 81 deletions

View file

@ -830,14 +830,14 @@ Editor::initialize_canvas ()
/* stuff for the verbose canvas cursor */
string fontname = get_font_for_style (N_("VerboseCanvasCursor"));
Pango::FontDescription font = get_font_for_style (N_("VerboseCanvasCursor"));
verbose_canvas_cursor = gnome_canvas_item_new (gnome_canvas_root(GNOME_CANVAS(track_gnome_canvas)),
gnome_canvas_text_get_type(),
"font", fontname.c_str(),
"anchor", GTK_ANCHOR_NW,
"fill_color_rgba", color_map[cVerboseCanvasCursor],
NULL);
gnome_canvas_text_get_type(),
"font-desc", fontname,
"anchor", GTK_ANCHOR_NW,
"fill_color_rgba", color_map[cVerboseCanvasCursor],
NULL);
verbose_cursor_visible = false;
/* a group to hold time (measure) lines */
@ -1389,7 +1389,7 @@ Editor::track_canvas_allocate (GtkAllocation *alloc)
if (session == 0 && !ARDOUR_UI::instance()->will_create_new_session_automatically()) {
string fontname = get_font_for_style (N_("FirstActionMessage"));
Pango::FontDescription font = get_font_for_style (N_("FirstActionMessage"));
const char *txt1 = _("Start a new session\n");
const char *txt2 = _("via Session menu");
@ -1400,27 +1400,21 @@ Editor::track_canvas_allocate (GtkAllocation *alloc)
compute width, and multiply the height by 2.
*/
gint width;
gint lbearing;
gint rbearing;
gint ascent;
gint descent;
int pixel_height;
int pixel_width;
/* this is a dummy widget that exists so that we can get the
style from the RC file.
*/
Label foo (_(txt2));
Glib::RefPtr<Pango::Layout> layout;
foo.set_name ("NoSessionMessage");
foo.ensure_style ();
gdk_string_extents (foo.get_style()->get_font(),
_(txt2),
&lbearing,
&rbearing,
&width,
&ascent,
&descent);
layout = foo.create_pango_layout (_(txt2));
layout->set_font_description (font);
layout->get_pixel_size (pixel_width, pixel_height);
if (first_action_message == 0) {
@ -1432,22 +1426,22 @@ Editor::track_canvas_allocate (GtkAllocation *alloc)
strcat (txt, _(txt2));
first_action_message = gnome_canvas_item_new (gnome_canvas_root(GNOME_CANVAS(track_gnome_canvas)),
gnome_canvas_text_get_type(),
"font", fontname.c_str(),
"fill_color_rgba", color_map[cFirstActionMessage],
"x", (gdouble) (canvas_width - width) / 2.0,
"y", (gdouble) (canvas_height/2.0) - (2.0 * (ascent+descent)),
"anchor", GTK_ANCHOR_NORTH_WEST,
"text", txt,
NULL);
gnome_canvas_text_get_type(),
"fontdesc", font,
"fill_color_rgba", color_map[cFirstActionMessage],
"x", (gdouble) (canvas_width - pixel_width) / 2.0,
"y", (gdouble) (canvas_height/2.0) - (2.0 * (pixel_height)),
"anchor", GTK_ANCHOR_NORTH_WEST,
"text", txt,
NULL);
} else {
/* center it */
gnome_canvas_item_set (first_action_message,
"x", (gdouble) (canvas_width - width) / 2.0,
"y", (gdouble) (canvas_height/2.0) - (2.0 * (ascent+descent)),
"x", (gdouble) (canvas_width - pixel_width) / 2.0,
"y", (gdouble) (canvas_height/2.0) - (2.0 * (pixel_height)),
NULL);
}
}

View file

@ -351,17 +351,17 @@ Marker::Marker (PublicEditor& ed, GnomeCanvasGroup *parent, guint32 rgba, const
"outline_color", "black",
NULL);
string fontname = get_font_for_style (N_("MarkerText"));
Pango::FontDescription font = get_font_for_style (N_("MarkerText"));
text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(group),
gnome_canvas_text_get_type (),
"text", annotation.c_str(),
"x", label_offset,
"y", 0.0,
"font", fontname.c_str(),
"anchor", GTK_ANCHOR_NW,
"fill_color", "black",
NULL);
gnome_canvas_text_get_type (),
"text", annotation.c_str(),
"x", label_offset,
"y", 0.0,
"fontdesc", font,
"anchor", GTK_ANCHOR_NW,
"fill_color", "black",
NULL);
gtk_object_set_data (GTK_OBJECT(group), "marker", this);
gtk_signal_connect (GTK_OBJECT(group), "event", (GtkSignalFunc) callback, &editor);

View file

@ -38,7 +38,8 @@ using namespace Editing;
//------------------------------------------------------------------------------
/** Initialize static memeber data */
std::string TimeAxisViewItem::NAME_FONT;
Pango::FontDescription TimeAxisViewItem::NAME_FONT;
bool TimeAxisViewItem::have_name_font = false;
const double TimeAxisViewItem::NAME_X_OFFSET = 15.0;
const double TimeAxisViewItem::NAME_Y_OFFSET = 15.0 ; /* XXX depends a lot on the font size, sigh. */
const double TimeAxisViewItem::NAME_HIGHLIGHT_SIZE = 15.0 ; /* ditto */
@ -65,8 +66,9 @@ TimeAxisViewItem::TimeAxisViewItem(std::string it_name, GnomeCanvasGroup* parent
Visibility visibility)
: trackview (tv)
{
if (NAME_FONT.empty()) {
if (!have_name_font) {
NAME_FONT = get_font_for_style (N_("TimeAxisViewItemName"));
have_name_font = true;
}
item_name = it_name ;

View file

@ -264,7 +264,8 @@ class TimeAxisViewItem : public sigc::trackable, public Selectable
bool name_active() const { return name_connected; }
// Default sizes, font and spacing
static std::string NAME_FONT ;
static Pango::FontDescription NAME_FONT ;
static bool have_name_font;
static const double NAME_X_OFFSET ;
static const double NAME_Y_OFFSET ;
static const double NAME_HIGHLIGHT_SIZE ;

View file

@ -25,6 +25,10 @@
#include <gtkmm/combo.h>
#include <gtkmm/label.h>
#include <gtkmm/paned.h>
#include <gtkmm/action.h>
#include <gtkmm/actiongroup.h>
#include <gtkmm/accelgroup.h>
#include <gtkmm/accelmap.h>
#include <gtk/gtkpaned.h>
#include <gtkmm2ext/utils.h>
@ -36,6 +40,7 @@
using namespace std;
using namespace Gtk;
using namespace sigc;
string
short_version (string orig, string::size_type target_length)
@ -102,27 +107,22 @@ short_version (string orig, string::size_type target_length)
}
string
fit_to_pixels (string str, int32_t pixel_width, Gdk_Font& font)
fit_to_pixels (string str, int pixel_width, string font)
{
gint width;
gint lbearing;
gint rbearing;
gint ascent;
gint descent;
Label foo;
int width;
int height;
Pango::FontDescription fontdesc (font);
int namelen = str.length();
char cstr[namelen+1];
strcpy (cstr, str.c_str());
while (namelen) {
gdk_string_extents (font,
cstr,
&lbearing,
&rbearing,
&width,
&ascent,
&descent);
Glib::RefPtr<Pango::Layout> layout = foo.create_pango_layout (cstr);
layout->set_font_description (fontdesc);
layout->get_pixel_size (width, height);
if (width < (pixel_width)) {
break;
@ -415,26 +415,19 @@ url_decode (string& url)
}
}
string
Pango::FontDescription
get_font_for_style (string widgetname)
{
Gtk::Label foobar;
Glib::RefPtr<Style> style;
foobar.set_name (widgetname);
foobar.ensure_style();
if (foobar.get_style() == 0 || foobar.get_style()->gobj()->rc_style == 0 || foobar.get_style()->gobj()->rc_style->font_name == 0) {
return "fixed";
}
string str = foobar.get_style()->gobj()->rc_style->font_name;
if (str.empty()) {
return "fixed"; // standard X Window fallback font
} else {
return str;
}
style = foobar.get_style ();
return style->get_font();
}
gint
pane_handler (GdkEventButton* ev, Gtk::Paned* pane)
{
@ -446,8 +439,8 @@ pane_handler (GdkEventButton* ev, Gtk::Paned* pane)
gint pos;
gint cmp;
pos = Gtkmm2ext::gtk_paned_get_position (pane->gobj());
pos = pane->get_position ();
if (dynamic_cast<VPaned*>(pane)) {
cmp = pane->get_height();
@ -522,5 +515,39 @@ rgba_from_style (string style, uint32_t r, uint32_t g, uint32_t b, uint32_t a)
void
decorate (Gtk::Window& w, Gdk::WMDecoration d)
{
w.get_window().set_decorations (d);
w.get_window()->set_decorations (d);
}
Glib::RefPtr<Action>
register_action (Glib::RefPtr<ActionGroup> group, string name, string label, slot<void> sl, guint key, Gdk::ModifierType mods)
{
Glib::RefPtr<Action> act;
act = Action::create (name, label);
group->add (act, sl);
AccelMap::add_entry (act->get_accel_path(), key, mods);
return act;
}
Glib::RefPtr<Action>
register_action (Glib::RefPtr<ActionGroup> group, string name, string label, slot<void> sl)
{
Glib::RefPtr<Action> act;
act = Action::create (name, label);
group->add (act, sl);
return act;
}
Glib::RefPtr<Action>
register_action (Glib::RefPtr<ActionGroup> group, string name, string label)
{
Glib::RefPtr<Action> act;
act = Action::create (name, label);
group->add (act);
return act;
}

View file

@ -51,7 +51,7 @@ slider_position_to_gain (double pos)
}
std::string short_version (std::string, std::string::size_type target_length);
std::string fit_to_pixels (std::string, int32_t pixel_width, Gdk::Font&);
std::string fit_to_pixels (std::string, int pixel_width, std::string font);
int atoi (const std::string&);
double atof (const std::string&);
@ -66,9 +66,14 @@ unsigned char* xpm2rgba (const char** xpm, uint32_t& w, uint32_t& h);
GnomeCanvasPoints* get_canvas_points (std::string who, uint32_t npoints);
int channel_combo_get_channel_count (Gtk::ComboBoxText& combo);
std::string get_font_for_style (std::string widgetname);
Pango::FontDescription get_font_for_style (std::string widgetname);
gint pane_handler (GdkEventButton*, Gtk::Paned*);
uint32_t rgba_from_style (std::string style, uint32_t, uint32_t, uint32_t, uint32_t);
Glib::RefPtr<Gtk::Action> register_action (Glib::RefPtr<Gtk::ActionGroup> group, string name, string label, sigc::slot<void> sl, guint key, Gdk::ModifierType mods);
Glib::RefPtr<Gtk::Action> register_action (Glib::RefPtr<Gtk::ActionGroup> group, string name, string label, sigc::slot<void> sl);
Glib::RefPtr<Gtk::Action> register_action (Glib::RefPtr<Gtk::ActionGroup> group, string name, string label);
#endif /* __ardour_gtk_utils_h__ */

View file

@ -24,6 +24,7 @@
#include <vector>
#include <string>
#include <gtkmm/widget.h>
#include <gtkmm/paned.h>
#include <gtkmm/comboboxtext.h>
namespace Gtkmm2ext {
@ -39,8 +40,8 @@ namespace Gtkmm2ext {
template<class T> void deferred_delete (void *ptr) {
delete static_cast<T *> (ptr);
}
GdkWindow* get_paned_handle (Gtk::Paned& paned);
};
gint do_not_propagate (GdkEventButton*);
#endif /* __gtkmm2ext_utils_h__ */

View file

@ -18,6 +18,7 @@
$Id$
*/
#include <gtk/gtkpaned.h>
#include <gtkmm2ext/utils.h>
#include <gtkmm2ext/gtkutils.h>
#include <gtkmm/comboboxtext.h>
@ -35,12 +36,6 @@ Gtkmm2ext::set_size_request_to_display_given_text (Gtk::Widget &w, const gchar *
set_size_request_to_display_given_text(w, text, hpadding, vpadding);
}
gint
do_not_propagate (GdkEventButton *ev)
{
return TRUE;
}
void
Gtkmm2ext::init ()
{
@ -57,3 +52,9 @@ Gtkmm2ext::set_popdown_strings (Gtk::ComboBoxText& cr, vector<string>& strings)
cr.append_text (*i);
}
}
GdkWindow*
Gtkmm2ext::get_paned_handle (Gtk::Paned& paned)
{
return GTK_PANED(paned.gobj())->handle;
}