/[svn]/gigedit/trunk/src/gigedit/compat.h
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/compat.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3365 by schoenebeck, Wed Nov 15 16:01:48 2017 UTC revision 3735 by schoenebeck, Sat Feb 1 19:28:43 2020 UTC
# Line 1  Line 1 
1  /*                                                         -*- c++ -*-  /*                                                         -*- c++ -*-
2   * Copyright (C) 2011-2017 Andreas Persson   * Copyright (C) 2011-2019 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 40  Line 40 
40    
41  #ifdef CAIROMM_HEADER_FILE  #ifdef CAIROMM_HEADER_FILE
42  # include CAIROMM_HEADER_FILE(cairommconfig.h)  # include CAIROMM_HEADER_FILE(cairommconfig.h)
43  #else  #elif HAVE_CAIROMMCONFIG_H
44  # include <cairommconfig.h>  # include <cairommconfig.h>
45  #endif  #endif
46    
# Line 50  Line 50 
50  # include <gtkmmconfig.h>  # include <gtkmmconfig.h>
51  #endif  #endif
52    
53  #ifndef HAS_PANGOMM_CPP11_ENUMS // pangomm > 2.40 : <- just a "guess"  #ifndef HAS_PANGOMM_CPP11_ENUMS
54  # if PANGOMM_MAJOR_VERSION > 2 || (PANGOMM_MAJOR_VERSION == 2 && PANGOMM_MINOR_VERSION > 40)     // new enums introduced in unstable pangomm 2.41.3, but not in stable 2.42
55    # if PANGOMM_MAJOR_VERSION > 2 || (PANGOMM_MAJOR_VERSION == 2 && ((PANGOMM_MINOR_VERSION == 41 && PANGOMM_MICRO_VERSION >= 3) || PANGOMM_MINOR_VERSION > 42))
56  #  define HAS_PANGOMM_CPP11_ENUMS 1  #  define HAS_PANGOMM_CPP11_ENUMS 1
57  # else  # else
58  #  define HAS_PANGOMM_CPP11_ENUMS 0  #  define HAS_PANGOMM_CPP11_ENUMS 0
# Line 61  Line 62 
62  // Gtk::UIManager had been replaced by Gtk::Builder in GTKMM 3 and removed in GTKMM 4  // Gtk::UIManager had been replaced by Gtk::Builder in GTKMM 3 and removed in GTKMM 4
63  // Gtk::ActionGroup had been replaced by Gio::ActionGroup in GTKMM 3 and removed in GTKMM 4  // Gtk::ActionGroup had been replaced by Gio::ActionGroup in GTKMM 3 and removed in GTKMM 4
64  #if !defined(USE_GTKMM_BUILDER) || !defined(USE_GLIB_ACTION) // gtkmm > 3.22 :  #if !defined(USE_GTKMM_BUILDER) || !defined(USE_GLIB_ACTION) // gtkmm > 3.22 :
65  # if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  # if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
66  #  define USE_GTKMM_BUILDER 1  #  define USE_GTKMM_BUILDER 1
67  #  define USE_GLIB_ACTION 1  #  define USE_GLIB_ACTION 1
68  # else  # else
# Line 79  Line 80 
80  #endif  #endif
81    
82  #ifndef HAS_GTKMM_CPP11_ENUMS // gtkmm > 3.22  #ifndef HAS_GTKMM_CPP11_ENUMS // gtkmm > 3.22
83  # if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  # if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
84  #  define HAS_GTKMM_CPP11_ENUMS 1  #  define HAS_GTKMM_CPP11_ENUMS 1
85  # else  # else
86  #  define HAS_GTKMM_CPP11_ENUMS 0  #  define HAS_GTKMM_CPP11_ENUMS 0
# Line 88  Line 89 
89    
90  // alignment.h had been removed in GTKMM 4  // alignment.h had been removed in GTKMM 4
91  #ifndef HAS_GTKMM_ALIGNMENT // gtkmm > 3.22 :  #ifndef HAS_GTKMM_ALIGNMENT // gtkmm > 3.22 :
92  # if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  # if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
93  #  define HAS_GTKMM_ALIGNMENT 0  #  define HAS_GTKMM_ALIGNMENT 0
94  # else  # else
95  #  define HAS_GTKMM_ALIGNMENT 1  #  define HAS_GTKMM_ALIGNMENT 1
# Line 99  Line 100 
100  // stock.h had been removed in GTKMM 4  // stock.h had been removed in GTKMM 4
101  // Gtk::VBox, Gtk::HBox and Gtk::HButtonBox had been replaced by Gtk::Box in GTKMM 3 and removed in GTKMM 4  // Gtk::VBox, Gtk::HBox and Gtk::HButtonBox had been replaced by Gtk::Box in GTKMM 3 and removed in GTKMM 4
102  #if !defined(USE_GTKMM_GRID) || !defined(HAS_GTKMM_STOCK) || !defined(USE_GTKMM_BOX) || !defined(USE_GTKMM_PANED) // gtkmm > 3.22 :  #if !defined(USE_GTKMM_GRID) || !defined(HAS_GTKMM_STOCK) || !defined(USE_GTKMM_BOX) || !defined(USE_GTKMM_PANED) // gtkmm > 3.22 :
103  # if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  # if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
104  #  define USE_GTKMM_GRID 1  #  define USE_GTKMM_GRID 1
105  #  define HAS_GTKMM_STOCK 0  #  define HAS_GTKMM_STOCK 0
106  #  define USE_GTKMM_BOX 1  #  define USE_GTKMM_BOX 1
# Line 422  namespace Glib { Line 423  namespace Glib {
423    
424  #endif // glibmm 2.31.2  #endif // glibmm 2.31.2
425    
426    
427    // glibmm 2.47.3
428    
429    #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION == 47 && GLIBMM_MICRO_VERSION < 3) || \
430        (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 47) || GLIBMM_MAJOR_VERSION < 2
431    
432    #define GLIB_THREADS
433    
434    #endif
435    
436    #include <gtkmm/label.h>
437    
438    /** @brief Auto wrapped (multi-line) text, auto shrank to min. dimensions.
439     *
440     * This widgets is intended for large text blocks which are expected to require
441     * the text to be automatically wrapped (i.e. auto inserted line breaks) such
442     * that it would not exceed the label's maximum allowed width according to its
443     * parent container.
444     *
445     * This class overrides get_preferred_height_for_width_vfunc() to fix the
446     * default behaviour of Gtk::Label, which by default calculates a height under
447     * the assumption that EVERY word of the text had a line break, which would
448     * cause the label to claim much more vertical space than actually required for
449     * the text.
450     */
451    class MultiLineLabel : public Gtk::Label {
452    public:
453        MultiLineLabel() : Gtk::Label() {
454            #if GTKMM_MAJOR_VERSION >= 3
455            set_line_wrap();
456            #endif
457        }
458    
459        void set_markup(const Glib::ustring& s) {
460            Gtk::Label::set_markup(s);
461            m_markup = s;
462        }
463    
464        void get_preferred_height_for_width_vfunc(int width, int& minimum_height, int& natural_height) const {
465            Gtk::Label::get_preferred_height_for_width_vfunc(width, minimum_height, natural_height);
466            //printf("super suggests minimum_height=%d natural_height=%d\n", minimum_height, natural_height);
467    
468            Pango::Layout* origLayout = const_cast<Pango::Layout*>(get_layout().operator->());
469            Glib::RefPtr<Pango::Layout> layout = origLayout->copy();
470            Glib::ustring s = (!m_markup.empty()) ? m_markup : get_text();
471            layout->set_markup(s);
472            int w, h;
473            layout->get_pixel_size(w, h);
474            h += get_margin_top() + get_margin_bottom();
475            //printf("calculated w=%d h=%d\n", w, h);
476    
477            minimum_height = h;
478            if (natural_height < h)
479                natural_height = h;
480        }
481    
482    private:
483        Glib::ustring m_markup;
484    };
485    
486  #endif // GIGEDIT_COMPAT_H  #endif // GIGEDIT_COMPAT_H

Legend:
Removed from v.3365  
changed lines
  Added in v.3735

  ViewVC Help
Powered by ViewVC