[PATCH] GTK: Use gtk vseparator instead of native one for the toolbar
Lucas Baudin
xapantu at gmail.com
Sat Jan 29 12:20:45 PST 2011
---
vcl/inc/vcl/salnativewidgets.hxx | 33 ++++----
vcl/inc/vcl/toolbox.hxx | 1 +
vcl/source/window/toolbox.cxx | 125 ++++++++++++++++++------------
vcl/unx/gtk/gdi/salnativewidgets-gtk.cxx | 20 +++++
4 files changed, 114 insertions(+), 65 deletions(-)
diff --git a/vcl/inc/vcl/salnativewidgets.hxx b/vcl/inc/vcl/salnativewidgets.hxx
index be3eeb6..78cdfb7 100644
--- a/vcl/inc/vcl/salnativewidgets.hxx
+++ b/vcl/inc/vcl/salnativewidgets.hxx
@@ -157,22 +157,23 @@ typedef sal_uInt32 ControlType;
typedef sal_uInt32 ControlPart;
-#define PART_ENTIRE_CONTROL 1
-#define PART_WINDOW 5 // the static listbox window containing the list
-#define PART_BUTTON 100
-#define PART_BUTTON_UP 101
-#define PART_BUTTON_DOWN 102 // Also for ComboBoxes/ListBoxes
-#define PART_BUTTON_LEFT 103
-#define PART_BUTTON_RIGHT 104
-#define PART_ALL_BUTTONS 105
-#define PART_TRACK_HORZ_LEFT 200
-#define PART_TRACK_VERT_UPPER 201
-#define PART_TRACK_HORZ_RIGHT 202
-#define PART_TRACK_VERT_LOWER 203
-#define PART_TRACK_HORZ_AREA 204
-#define PART_TRACK_VERT_AREA 205
-#define PART_THUMB_HORZ 210 // Also used as toolbar grip
-#define PART_THUMB_VERT 211 // Also used as toolbar grip
+#define PART_ENTIRE_CONTROL 1
+#define PART_WINDOW 5 // the static listbox window containing the list
+#define PART_BUTTON 100
+#define PART_BUTTON_UP 101
+#define PART_BUTTON_DOWN 102 // Also for ComboBoxes/ListBoxes
+#define PART_BUTTON_LEFT 103
+#define PART_BUTTON_RIGHT 104
+#define PART_ALL_BUTTONS 105
+#define PART_SEPARATOR 106
+#define PART_TRACK_HORZ_LEFT 200
+#define PART_TRACK_VERT_UPPER 201
+#define PART_TRACK_HORZ_RIGHT 202
+#define PART_TRACK_VERT_LOWER 203
+#define PART_TRACK_HORZ_AREA 204
+#define PART_TRACK_VERT_AREA 205
+#define PART_THUMB_HORZ 210 // Also used as toolbar grip
+#define PART_THUMB_VERT 211 // Also used as toolbar grip
#define PART_MENU_ITEM 250
#define PART_MENU_ITEM_CHECK_MARK 251
#define PART_MENU_ITEM_RADIO_MARK 252
diff --git a/vcl/inc/vcl/toolbox.hxx b/vcl/inc/vcl/toolbox.hxx
index 8196642..eb4f36a 100644
--- a/vcl/inc/vcl/toolbox.hxx
+++ b/vcl/inc/vcl/toolbox.hxx
@@ -260,6 +260,7 @@ private:
SAL_DLLPRIVATE void ImplFormat( BOOL bResize = FALSE );
SAL_DLLPRIVATE void ImplDrawSpin( BOOL bUpperIn, BOOL bLowerIn );
SAL_DLLPRIVATE void ImplDrawNext( BOOL bIn );
+ SAL_DLLPRIVATE void ImplDrawSeparator( USHORT nPos, Rectangle rRect );
SAL_DLLPRIVATE void ImplDrawItem( USHORT nPos, BOOL bHighlight = FALSE, BOOL bPaint = FALSE, BOOL bLayout = FALSE );
using Window::ImplInvalidate;
SAL_DLLPRIVATE void ImplInvalidate( BOOL bNewCalc = FALSE, BOOL bFullPaint = FALSE );
diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx
index b931585..ecd6505 100644
--- a/vcl/source/window/toolbox.cxx
+++ b/vcl/source/window/toolbox.cxx
@@ -3403,6 +3403,54 @@ void ToolBox::ImplDrawNext( BOOL bIn )
// -----------------------------------------------------------------------
+void ToolBox::ImplDrawSeparator( USHORT nPos, Rectangle rRect )
+{
+ BOOL bNativeOk = FALSE;
+ ImplToolItem* pItem = &mpData->m_aItems[nPos];
+
+ if( IsNativeControlSupported( CTRL_TOOLBAR, PART_SEPARATOR ) )
+ {
+ ImplControlValue aControlValue;
+ ControlState nState = 0;
+ bNativeOk = DrawNativeControl( CTRL_TOOLBAR, PART_SEPARATOR,
+ rRect, nState, aControlValue, rtl::OUString() );
+ }
+
+ /* Draw the widget only if it can't be drawn natively. */
+ if( !bNativeOk )
+ {
+ const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+ ImplToolItem* pTempItem = &mpData->m_aItems[nPos-1];
+
+ // no separator before or after windows or at breaks
+ if ( pTempItem && !pTempItem->mbShowWindow && nPos < mpData->m_aItems.size()-1 )
+ {
+ pTempItem = &mpData->m_aItems[nPos+1];
+ if ( !pTempItem->mbShowWindow && !pTempItem->mbBreak )
+ {
+ long nCenterPos, nSlim;
+ SetLineColor( rStyleSettings.GetSeparatorColor() );
+ if ( IsHorizontal() )
+ {
+ nSlim = (pItem->maRect.Bottom() - pItem->maRect.Top ()) / 4;
+ nCenterPos = pItem->maRect.Center().X();
+ DrawLine( Point( nCenterPos, pItem->maRect.Top() + nSlim ),
+ Point( nCenterPos, pItem->maRect.Bottom() - nSlim ) );
+ }
+ else
+ {
+ nSlim = (pItem->maRect.Right() - pItem->maRect.Left ()) / 4;
+ nCenterPos = pItem->maRect.Center().Y();
+ DrawLine( Point( pItem->maRect.Left() + nSlim, nCenterPos ),
+ Point( pItem->maRect.Right() - nSlim, nCenterPos ) );
+ }
+ }
+ }
+ }
+}
+
+// -----------------------------------------------------------------------
+
static void ImplDrawButton( ToolBox* pThis, const Rectangle &rRect, USHORT highlight, BOOL bChecked, BOOL bEnabled, BOOL bIsWindow )
{
// draws toolbar button background either native or using a coloured selection
@@ -3462,6 +3510,33 @@ void ToolBox::ImplDrawItem( USHORT nPos, BOOL bHighlight, BOOL bPaint, BOOL bLay
if( rStyleSettings.GetFaceColor() == Color( COL_WHITE ) )
bHighContrastWhite = TRUE;
+ // Compute buttons area.
+ Size aBtnSize = pItem->maRect.GetSize();
+ if( ImplGetSVData()->maNWFData.mbToolboxDropDownSeparate )
+ {
+ // separate button not for dropdown only where the whole button is painted
+ if ( pItem->mnBits & TIB_DROPDOWN &&
+ ((pItem->mnBits & TIB_DROPDOWNONLY) != TIB_DROPDOWNONLY) )
+ {
+ Rectangle aArrowRect = pItem->GetDropDownRect( mbHorz );
+ if( aArrowRect.Top() == pItem->maRect.Top() ) // dropdown arrow on right side
+ aBtnSize.Width() -= aArrowRect.GetWidth();
+ else // dropdown arrow on bottom side
+ aBtnSize.Height() -= aArrowRect.GetHeight();
+ }
+ }
+
+ /* Compute the button/separator rectangle here, we'll need it for
+ * both the buttons and the separators. */
+ Rectangle aButtonRect( pItem->maRect.TopLeft(), aBtnSize );
+ long nOffX = SMALLBUTTON_OFF_NORMAL_X;
+ long nOffY = SMALLBUTTON_OFF_NORMAL_Y;
+ long nImageOffX = 0;
+ long nImageOffY = 0;
+ long nTextOffX = 0;
+ long nTextOffY = 0;
+ USHORT nStyle = 0;
+
// draw separators in flat style only
if ( !bLayout &&
(mnOutStyle & TOOLBOX_STYLE_FLAT) &&
@@ -3469,31 +3544,7 @@ void ToolBox::ImplDrawItem( USHORT nPos, BOOL bHighlight, BOOL bPaint, BOOL bLay
nPos > 0
)
{
- // no separator before or after windows or at breaks
- ImplToolItem* pTempItem = &mpData->m_aItems[nPos-1];
- if ( pTempItem && !pTempItem->mbShowWindow && nPos < mpData->m_aItems.size()-1 )
- {
- pTempItem = &mpData->m_aItems[nPos+1];
- if ( !pTempItem->mbShowWindow && !pTempItem->mbBreak )
- {
- long nCenterPos, nSlim;
- SetLineColor( rStyleSettings.GetSeparatorColor() );
- if ( IsHorizontal() )
- {
- nSlim = (pItem->maRect.Bottom() - pItem->maRect.Top ()) / 4;
- nCenterPos = pItem->maRect.Center().X();
- DrawLine( Point( nCenterPos, pItem->maRect.Top() + nSlim ),
- Point( nCenterPos, pItem->maRect.Bottom() - nSlim ) );
- }
- else
- {
- nSlim = (pItem->maRect.Right() - pItem->maRect.Left ()) / 4;
- nCenterPos = pItem->maRect.Center().Y();
- DrawLine( Point( pItem->maRect.Left() + nSlim, nCenterPos ),
- Point( pItem->maRect.Right() - nSlim, nCenterPos ) );
- }
- }
- }
+ ImplDrawSeparator( nPos, aButtonRect );
}
// do nothing if item is no button or will be displayed as window
@@ -3557,30 +3608,6 @@ void ToolBox::ImplDrawItem( USHORT nPos, BOOL bHighlight, BOOL bPaint, BOOL bLay
return;
}
- // draw button
- Size aBtnSize = pItem->maRect.GetSize();
- if( ImplGetSVData()->maNWFData.mbToolboxDropDownSeparate )
- {
- // separate button not for dropdown only where the whole button is painted
- if ( pItem->mnBits & TIB_DROPDOWN &&
- ((pItem->mnBits & TIB_DROPDOWNONLY) != TIB_DROPDOWNONLY) )
- {
- Rectangle aArrowRect = pItem->GetDropDownRect( mbHorz );
- if( aArrowRect.Top() == pItem->maRect.Top() ) // dropdown arrow on right side
- aBtnSize.Width() -= aArrowRect.GetWidth();
- else // dropdown arrow on bottom side
- aBtnSize.Height() -= aArrowRect.GetHeight();
- }
- }
- Rectangle aButtonRect( pItem->maRect.TopLeft(), aBtnSize );
- long nOffX = SMALLBUTTON_OFF_NORMAL_X;
- long nOffY = SMALLBUTTON_OFF_NORMAL_Y;
- long nImageOffX=0;
- long nImageOffY=0;
- long nTextOffX=0;
- long nTextOffY=0;
- USHORT nStyle = 0;
-
if ( pItem->meState == STATE_CHECK )
{
nStyle |= BUTTON_DRAW_CHECKED;
diff --git a/vcl/unx/gtk/gdi/salnativewidgets-gtk.cxx b/vcl/unx/gtk/gdi/salnativewidgets-gtk.cxx
index f94a9e3..0dbfefb 100644
--- a/vcl/unx/gtk/gdi/salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk/gdi/salnativewidgets-gtk.cxx
@@ -102,6 +102,7 @@ struct NWFWidgetData
GtkWidget * gTreeView;
GtkWidget * gHScale;
GtkWidget * gVScale;
+ GtkWidget * gVSeparator;
NWPixmapCacheList* gNWPixmapCacheList;
NWPixmapCache* gCacheTabItems;
@@ -140,6 +141,7 @@ struct NWFWidgetData
gTreeView( NULL ),
gHScale( NULL ),
gVScale( NULL ),
+ gVSeparator ( NULL ),
gNWPixmapCacheList( NULL ),
gCacheTabItems( NULL ),
gCacheTabPages( NULL )
@@ -583,6 +585,7 @@ BOOL GtkSalGraphics::IsNativeControlSupported( ControlType nType, ControlPart nP
|| (nPart==PART_THUMB_HORZ)
|| (nPart==PART_THUMB_VERT)
|| (nPart==PART_BUTTON)
+ || (nPart==PART_SEPARATOR)
)
) ||
((nType == CTRL_MENUBAR) &&
@@ -2640,6 +2643,21 @@ BOOL GtkSalGraphics::NWPaintGTKToolbar(
pButtonWidget, "button", x, y, w, h );
}
}
+ else if(nPart == PART_SEPARATOR )
+ {
+ gtk_paint_vline( gWidgetData[m_nScreen].gVSeparator->style,
+ gdkDrawable,
+ GTK_STATE_NORMAL,
+ &clipRect,
+ gWidgetData[m_nScreen].gVSeparator,
+ "vseparator",
+ y + 4, y + h - 8 /* -2 and -4 is a dirty
+ * hack, to fit most gtk
+ * style, but it must be
+ * fixed, FIXME */,
+ x
+ );
+ }
}
return( TRUE );
@@ -3945,6 +3963,8 @@ static void NWEnsureGTKToolbar( int nScreen )
NWAddWidgetToCacheWindow( gWidgetData[nScreen].gToolbarWidget, nScreen );
gWidgetData[nScreen].gToolbarButtonWidget = gtk_button_new();
gWidgetData[nScreen].gToolbarToggleWidget = gtk_toggle_button_new();
+ gWidgetData[nScreen].gVSeparator = gtk_vseparator_new();
+ NWAddWidgetToCacheWindow( gWidgetData[nScreen].gVSeparator, nScreen );
GtkReliefStyle aRelief = GTK_RELIEF_NORMAL;
gtk_widget_ensure_style( gWidgetData[nScreen].gToolbarWidget );
--
1.7.1
--=-u30bTd2lTqwgyaazZIAY--
More information about the LibreOffice
mailing list