diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-08-14 20:05:06 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-08-17 12:17:08 +0200 |
commit | a59f45d5808ed4d4767608246f0b9cf49e6b5276 (patch) | |
tree | 296f7ed917e6eed3e282d76de6ad5a39f1769c70 /vcl/unx | |
parent | 4d7bf28b2c09984cad88ee6760cbdbb6886b1545 (diff) |
Related: tdf#135743 position combobox dropdowns correctly for RTL
Change-Id: I4f8e70e128fd8506e7f95291226fc52599f15896
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100758
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index ade418e30d01..3c2032970376 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -1700,7 +1700,6 @@ static MouseEventModifiers ImplGetMouseMoveMode(sal_uInt16 nCode) namespace { -#if GTK_CHECK_VERSION(3,22,0) bool SwapForRTL(GtkWidget* pWidget) { GtkTextDirection eDir = gtk_widget_get_direction(pWidget); @@ -1710,7 +1709,6 @@ namespace return false; return AllSettings::GetLayoutRTL(); } -#endif void replaceWidget(GtkWidget* pWidget, GtkWidget* pReplacement) { @@ -1968,12 +1966,7 @@ protected: bool SwapForRTL() const { - GtkTextDirection eDir = gtk_widget_get_direction(m_pWidget); - if (eDir == GTK_TEXT_DIR_RTL) - return true; - if (eDir == GTK_TEXT_DIR_LTR) - return false; - return AllSettings::GetLayoutRTL(); + return ::SwapForRTL(m_pWidget); } void do_enable_drag_source(rtl::Reference<TransferDataContainer>& rHelper, sal_uInt8 eDNDConstants) @@ -7028,10 +7021,26 @@ GtkPositionType show_menu_older_gtk(GtkWidget* pMenuButton, GtkWindow* pMenu) gtk_window_group_add_window(gtk_window_get_group(GTK_WINDOW(pToplevel)), pMenu); gtk_window_set_transient_for(pMenu, GTK_WINDOW(pToplevel)); - GtkRequisition req; - gtk_widget_get_preferred_size(GTK_WIDGET(pMenu), nullptr, &req); - gint nMenuWidth = req.width; - gint nMenuHeight = req.height; + gint nMenuWidth, nMenuHeight; + gtk_widget_get_size_request(GTK_WIDGET(pMenu), &nMenuWidth, &nMenuHeight); + + if (nMenuWidth == -1 || nMenuHeight == -1) + { + GtkRequisition req; + gtk_widget_get_preferred_size(GTK_WIDGET(pMenu), nullptr, &req); + if (nMenuWidth == -1) + nMenuWidth = req.width; + if (nMenuHeight == -1) + nMenuHeight = req.height; + } + + bool bSwapForRTL = SwapForRTL(pMenuButton); + if (bSwapForRTL) + { + gint nButtonWidth = gtk_widget_get_allocated_width(pMenuButton); + x += nButtonWidth; + x -= nMenuWidth; + } tools::Rectangle aWorkArea(::get_monitor_workarea(pMenuButton)); @@ -7041,11 +7050,9 @@ GtkPositionType show_menu_older_gtk(GtkWidget* pMenuButton, GtkWindow* pMenu) aWorkArea.AdjustBottom(-8); gint endx = x + nMenuWidth; if (endx > aWorkArea.Right()) - { x -= endx - aWorkArea.Right(); - if (x < 0) - x = 0; - } + if (x < 0) + x = 0; GtkPositionType ePosUsed = GTK_POS_BOTTOM; @@ -7104,17 +7111,14 @@ bool show_menu_newer_gtk(GtkWidget* pComboBox, GtkWindow* pMenu) gtk_window_group_add_window(gtk_window_get_group(GTK_WINDOW(pToplevel)), pMenu); gtk_window_set_transient_for(pMenu, GTK_WINDOW(pToplevel)); - GtkRequisition req; - gtk_widget_get_preferred_size(GTK_WIDGET(pMenu), nullptr, &req); - gint nMenuWidth = req.width; + gint nComboWidth = gtk_widget_get_allocated_width(pComboBox); + gint nComboHeight = gtk_widget_get_allocated_height(pComboBox); - gint nButtonHeight = gtk_widget_get_allocated_height(pComboBox); + bool bSwapForRTL = SwapForRTL(GTK_WIDGET(pComboBox)); - GdkGravity rect_anchor = GDK_GRAVITY_SOUTH, menu_anchor = GDK_GRAVITY_NORTH; - GdkRectangle rect {static_cast<int>(x), - static_cast<int>(y), - static_cast<int>(nMenuWidth), - static_cast<int>(nButtonHeight) }; + GdkGravity rect_anchor = !bSwapForRTL ? GDK_GRAVITY_SOUTH_WEST : GDK_GRAVITY_SOUTH_EAST; + GdkGravity menu_anchor = !bSwapForRTL ? GDK_GRAVITY_NORTH_WEST : GDK_GRAVITY_NORTH_EAST; + GdkRectangle rect {x, y, nComboWidth, nComboHeight }; GdkWindow* toplevel = gtk_widget_get_window(GTK_WIDGET(pMenu)); window_move_to_rect(toplevel, &rect, rect_anchor, menu_anchor, |