fixes for utils.cc in gtk2_ardour and gtkmm2ext, including switch to Pango::FontDescr...
authorPaul Davis <paul@linuxaudiosystems.com>
Sun, 9 Oct 2005 12:51:04 +0000 (12:51 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Sun, 9 Oct 2005 12:51:04 +0000 (12:51 +0000)
git-svn-id: svn://localhost/trunk/ardour2@53 d708f5d6-7413-0410-9779-e7cbd77b26cf

gtk2_ardour/editor.cc
gtk2_ardour/marker.cc
gtk2_ardour/time_axis_view_item.cc
gtk2_ardour/time_axis_view_item.h
gtk2_ardour/utils.cc
gtk2_ardour/utils.h
libs/gtkmm2ext/gtkmm2ext/utils.h
libs/gtkmm2ext/utils.cc

index 928b3bd13776f01180d01b54d9113b92c93f1ef3..601eda77335bfc69096090dd4d53ab2f4bb4425d 100644 (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);
                }
        }
index 262110286571fbc2e5d63a88f284d6c2a383a9e9..0d124f556c46a497671d8ee84fa579dc36df75d7 100644 (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);
index 7f1bfc53e58c9499ac0c9849c3514039e2df0b4a..62a1e7d9e68afba15f41085b61c94615cac29bbf 100644 (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 ;
index d4e852461ad06ca93a1e83edebdf0b465c1bd430..ff651b96490267131a955c637aab6083fe5846cb 100644 (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 ;
index 21a8233d4410d9d263598e45ab2a9acb83d1c680..e0a31e584443e8573ac507eed92780411fcf3a07 100644 (file)
 #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;
 }
index b844e0eb30af354b65e01a592fe4cb59872bff1e..1b33db7a4ae05f5e0149ab7bd283739839e1613a 100644 (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__ */
index 57cbe7dda511beff10e195c4a38dafc5c5c32ed5..f9d4569e44959a458cab9b3d0665ab65ca623f86 100644 (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);
        }
-};
 
-gint do_not_propagate (GdkEventButton*);
+       GdkWindow* get_paned_handle (Gtk::Paned& paned);
+};
 
 #endif /*  __gtkmm2ext_utils_h__ */
index df4e510df8d38bd08d174aa219f276481a8a734c..2f0bf3a98eda8c44d4f29a72ac1563c505c0e986 100644 (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;
+}