GitLab Commit is coming up on August 3-4. Learn how to innovate together using GitLab, the DevOps platform. Register for free: gitlabcommitvirtual2021.com

Commit e93a455f authored by Benoît Minisini's avatar Benoît Minisini
Browse files

Define the minimum size of controls better, so that less GTK+ spurious warnings are emitted.

[GB.GTK3]
* BUG: Define the minimum size of controls better, so that less GTK+ spurious warnings are emitted.
parent d2349cdb
Pipeline #243497031 passed with stage
in 25 minutes and 22 seconds
......@@ -930,6 +930,7 @@ GdkEvent *gApplication::_event = NULL;
bool gApplication::_fix_breeze = false;
bool gApplication::_fix_oxygen = false;
int gApplication::_scrollbar_size = 0;
int gApplication::_scrollbar_big_size = 0;
void gApplication::grabPopup()
{
......@@ -1464,6 +1465,7 @@ int gApplication::getScrollbarSize()
#endif
gtk_widget_show(widget);
gtk_widget_get_preferred_width(widget, NULL, &_scrollbar_size); //, &minimum_size, &natural_size);
gtk_widget_get_preferred_height(widget, NULL, &_scrollbar_big_size); //, &minimum_size, &natural_size);
gtk_widget_destroy(widget);
if (_fix_breeze)
......@@ -1486,6 +1488,16 @@ int gApplication::getScrollbarSize()
#endif
}
int gApplication::getScrollbarBigSize()
{
#ifdef GTK3
getScrollbarSize();
return _scrollbar_big_size;
#else
return getScrollbarSize();
#endif
}
int gApplication::getScrollbarSpacing()
{
gint v;
......
......@@ -84,6 +84,7 @@ public:
static bool (*onKeyEvent)(int type);
static int getScrollbarSize();
static int getScrollbarBigSize();
static int getScrollbarSpacing();
static int getFrameWidth();
static int getInnerWidth();
......@@ -109,6 +110,7 @@ public:
static bool _fix_breeze;
static bool _fix_oxygen;
static int _scrollbar_size;
static int _scrollbar_big_size;
//"Private"
static bool _init;
......
......@@ -574,7 +574,7 @@ void gButton::animateClick(bool on)
}
}
int gButton::minimumHeight() const
int gButton::autoHeight() const
{
int mh = 0;
......@@ -589,12 +589,7 @@ int gButton::minimumHeight() const
if (pic && (pic->height() > mh))
mh = pic->height();
return mh < 16 ? 16 : mh;
}
int gButton::minimumWidth() const
{
return 20;
return mh;
}
void gButton::setRadio(bool vl)
......@@ -703,7 +698,7 @@ void gButton::updateSize()
if (!_autoresize)
return;
mh = minimumHeight();
mh = autoHeight();
mw = 0;
if (hasText())
......
......@@ -91,8 +91,7 @@ public:
bool hasShortcut() const;
void unsetOtherRadioButtons();
virtual int minimumWidth() const;
virtual int minimumHeight() const;
int autoHeight() const;
virtual void updateSize();
};
......
......@@ -317,6 +317,8 @@ void gControl::initAll(gContainer *parent)
bufX = -16;
bufY = -16;
_min_w = 1;
_min_h = 1;
curs = NULL;
_font = NULL;
_resolved_font = NULL;
......@@ -1696,13 +1698,15 @@ static gboolean cb_clip_by_parent(GtkWidget *wid, GdkEventExpose *e, gControl *d
//#define must_patch(_widget) (gt_get_control(_widget) != NULL)
static bool _do_not_patch = false;
static bool must_patch(GtkWidget *widget)
{
GtkWidget *parent;
gControl *parent_control;
/*if (GTK_IS_ENTRY(widget)) // || GTK_IS_FIXED(widget))
return true;*/
if (_do_not_patch)
return false;
if (gt_get_control(widget))
{
......@@ -1789,6 +1793,29 @@ void gt_patch_control(GtkWidget *border, GtkWidget *widget)
#endif
void gControl::setMinimumSize()
{
#ifdef GTK3
GtkRequisition minimum_size, natural_size;
_do_not_patch = true;
gtk_widget_get_preferred_size(widget, &minimum_size, &natural_size);
_do_not_patch = false;
/*fprintf(stderr, "gtk_widget_get_preferred_size: %s: min = %d %d / nat = %d %d\n", GB.GetClassName(hFree), minimum_size.width, minimum_size.height, natural_size.width, natural_size.height);*/
_min_w = minimum_size.width;
_min_h = minimum_size.height;
#else
_min_w = _min_h = 1;
#endif
}
void gControl::realize(bool make_frame)
{
if (!_scroll)
......@@ -1835,8 +1862,10 @@ void gControl::realize(bool make_frame)
#endif
connectParent();
setMinimumSize();
resize(8, 8);
//updateGeometry(true);
initSignals();
//#ifndef GTK3
......@@ -2438,16 +2467,6 @@ void gControl::updateScrollBar()
}
}
int gControl::minimumHeight() const
{
return 1;
}
int gControl::minimumWidth() const
{
return 1;
}
bool gControl::isTracking() const
{
if (_proxy)
......
......@@ -236,6 +236,7 @@ public:
// "Private"
gint bufW,bufH,bufX,bufY;
int _min_w, _min_h;
gCursor *curs;
gFont *_font;
gFont *_resolved_font;
......@@ -340,8 +341,9 @@ public:
virtual void createBorder(GtkWidget *new_border, bool keep_widget = false);
void createWidget();
virtual int minimumWidth() const;
virtual int minimumHeight() const;
int minimumWidth() const { return _min_w; }
int minimumHeight() const { return _min_h; }
virtual void setMinimumSize();
void resolveFont();
......
......@@ -31,8 +31,6 @@ class gScrollBar : public gSlider
public:
gScrollBar(gContainer *parent);
virtual bool resize(int w, int h);
virtual int minimumWidth() const;
virtual int minimumHeight() const;
};
#endif
......@@ -271,11 +271,22 @@ bool gSlider::resize(int w, int h)
bool gScrollBar::resize(int w, int h)
{
if (gControl::resize(w, h))
return true;
GtkOrientation orientation, new_orientation;
int swap;
gtk_orientable_set_orientation(GTK_ORIENTABLE(widget), (width() < height()) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL);
return false;
orientation = gtk_orientable_get_orientation(GTK_ORIENTABLE(widget));
new_orientation = (w < h) ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL;
if (orientation != new_orientation)
{
gtk_orientable_set_orientation(GTK_ORIENTABLE(widget), new_orientation);
swap = _min_w;
_min_w = _min_h;
_min_h = swap;
}
return gControl::resize(w, h);
}
int gSlider::getDefaultSize()
......@@ -303,23 +314,3 @@ void gSlider::checkInverted()
{
gtk_range_set_inverted(GTK_RANGE(widget), !isVertical() && gDesktop::rightToLeft());
}
int gScrollBar::minimumWidth() const
{
return gApplication::getScrollbarSize() + gApplication::getScrollbarSpacing();
}
int gScrollBar::minimumHeight() const
{
return gApplication::getScrollbarSize() + gApplication::getScrollbarSpacing();
}
int gSlider::minimumWidth() const
{
return 28;
}
int gSlider::minimumHeight() const
{
return 28;
}
......@@ -55,8 +55,6 @@ public:
bool isVertical() const;
virtual bool resize(int w, int h);
virtual int minimumWidth() const;
virtual int minimumHeight() const;
//"Signals"
void (*onChange)(gSlider *sender);
......
......@@ -1088,21 +1088,6 @@ void gTextArea::customStyleSheet(GString *)
updateFixSpacing();
}
int gTextArea::minimumWidth() const
{
if (scrollBar())
return gDesktop::scale() * 4;
else
return 0;
}
int gTextArea::minimumHeight() const
{
if (scrollBar())
return gDesktop::scale() * 4;
else
return 0;
}
#endif
void gTextArea::getCursorPos(int *x, int *y, int pos)
......@@ -1142,3 +1127,9 @@ void gTextArea::onLeaveEvent()
gdk_window_hide(TEXT_AREA(textview));
}
#endif
void gTextArea::setMinimumSize()
{
_min_h = gApplication::getScrollbarBigSize(); // + font()->height() + (hasBorder() ? 4 : 0);
_min_w = _min_h;
}
......@@ -95,12 +95,11 @@ public:
//"Private"
virtual void updateCursor(GdkCursor *cursor);
virtual void setMinimumSize();
#ifdef GTK3
virtual GtkWidget *getStyleSheetWidget();
virtual const char *getStyleSheetColorNode();
virtual void customStyleSheet(GString *css);
virtual int minimumWidth() const;
virtual int minimumHeight() const;
virtual void onEnterEvent();
virtual void onLeaveEvent();
#endif
......
......@@ -453,14 +453,18 @@ void gTextBox::clear()
}
int gTextBox::minimumHeight() const
void gTextBox::setMinimumSize()
{
return font()->height() + hasBorder() ? 4 : 2;
_min_h = font()->height() + (hasBorder() ? 4 : 0);
_min_w = _min_h;
//fprintf(stderr, "setMinimumSize: TextBox: %d %d / %d\n", _min_w, _min_h, font()->height());
}
int gTextBox::minimumWidth() const
void gTextBox::setFont(gFont *ft)
{
return hasBorder() ? 12 : 8;
gControl::setFont(ft);
setMinimumSize();
}
GtkIMContext *gTextBox::getInputMethod()
......
......@@ -77,9 +77,11 @@ public:
//"Private"
virtual void updateCursor(GdkCursor *cursor);
void initEntry();
virtual int minimumHeight() const;
virtual int minimumWidth() const;
virtual GtkIMContext *getInputMethod();
virtual void setMinimumSize();
virtual void setFont(gFont *ft);
#ifdef GTK3
virtual void onEnterEvent();
virtual void onLeaveEvent();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment