From be93e360947f9dac215f8084c94bf33cd4cb4571 Mon Sep 17 00:00:00 2001 From: "bryner%netscape.com" Date: Sat, 20 Aug 2005 07:12:30 +0000 Subject: [PATCH] adding support for native tab widgets. not part of the build. --- widget/src/gtk/gtkdrawing.c | 20 +++++++++++ widget/src/gtk/gtkdrawing.h | 11 ++++++ widget/src/gtk/nsNativeThemeGTK.cpp | 54 ++++++++++++++++++++++++---- widget/src/gtk/nsNativeThemeGTK.h | 1 + widget/src/gtk2/gtkdrawing.h | 11 ++++++ widget/src/gtk2/nsNativeThemeGTK.cpp | 54 ++++++++++++++++++++++++---- widget/src/gtk2/nsNativeThemeGTK.h | 1 + 7 files changed, 138 insertions(+), 14 deletions(-) diff --git a/widget/src/gtk/gtkdrawing.c b/widget/src/gtk/gtkdrawing.c index df1a85942786..0691d5278d7a 100644 --- a/widget/src/gtk/gtkdrawing.c +++ b/widget/src/gtk/gtkdrawing.c @@ -57,6 +57,7 @@ extern GtkWidget* gHandleBoxWidget; extern GtkWidget* gFrameWidget; extern GtkWidget* gProtoWindow; extern GtkWidget* gProgressWidget; +extern GtkWidget* gTabWidget; extern GtkTooltips* gTooltipWidget; GtkStateType @@ -410,3 +411,22 @@ moz_gtk_progress_chunk_paint(GdkWindow* window, GtkStyle* style, rect->width, rect->height); } +void +moz_gtk_tab_paint(GdkWindow* window, GtkStyle* style, GdkRectangle* rect, + GdkRectangle* cliprect, GtkTabType type) +{ + gtk_paint_extension(style, window, + (type == kTabSelected ? GTK_STATE_NORMAL : GTK_STATE_ACTIVE), + GTK_SHADOW_OUT, cliprect, gTabWidget, "tab", rect->x, + rect->y, rect->width, rect->height, GTK_POS_BOTTOM); + + /* Here is the sleazy hack for before/after selected tab */ + if (type == kTabBeforeSelected) + gtk_paint_extension(style, window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, + cliprect, gTabWidget, "tab", rect->x + rect->width, + rect->y, rect->width, rect->height, GTK_POS_BOTTOM); + else if (type == kTabAfterSelected) + gtk_paint_extension(style, window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, + cliprect, gTabWidget, "tab", rect->x - rect->width, + rect->y, rect->width, rect->height, GTK_POS_BOTTOM); +} diff --git a/widget/src/gtk/gtkdrawing.h b/widget/src/gtk/gtkdrawing.h index a27f42709094..72718ff2f5f2 100644 --- a/widget/src/gtk/gtkdrawing.h +++ b/widget/src/gtk/gtkdrawing.h @@ -56,6 +56,13 @@ typedef struct { PRPackedBool canDefault; } GtkWidgetState; +typedef enum { + kTabNormal, + kTabBeforeSelected, + kTabSelected, + kTabAfterSelected +} GtkTabType; + void moz_gtk_button_paint(GdkWindow* window, GtkStyle* style, GdkRectangle* rect, GdkRectangle* cliprect, GtkWidgetState* state, @@ -123,6 +130,10 @@ void moz_gtk_progress_chunk_paint(GdkWindow* window, GtkStyle* style, GdkRectangle* rect, GdkRectangle* cliprect); +void +moz_gtk_tab_paint(GdkWindow* window, GtkStyle* style, GdkRectangle* rect, + GdkRectangle* cliprect, GtkTabType type); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/widget/src/gtk/nsNativeThemeGTK.cpp b/widget/src/gtk/nsNativeThemeGTK.cpp index 791cf386f924..a68c8e715422 100644 --- a/widget/src/gtk/nsNativeThemeGTK.cpp +++ b/widget/src/gtk/nsNativeThemeGTK.cpp @@ -67,6 +67,7 @@ GtkWidget* gHandleBoxWidget; GtkWidget* gFrameWidget; GtkWidget* gProtoWindow; GtkWidget* gProgressWidget; +GtkWidget* gTabWidget; GtkTooltips* gTooltipWidget; nsNativeThemeGTK::nsNativeThemeGTK() @@ -352,6 +353,36 @@ nsNativeThemeGTK::DrawWidgetBackground(nsIRenderingContext* aContext, moz_gtk_progress_chunk_paint(window, gProgressWidget->style, &gdk_rect, &gdk_clip); break; + +// case NS_THEME_TAB_PANELS: +// EnsureTabWidget(); +// break; + + case NS_THEME_TAB: + case NS_THEME_TAB_LEFT_EDGE: + case NS_THEME_TAB_RIGHT_EDGE: + { + EnsureTabWidget(); + GtkTabType tab_type; + switch (aWidgetType) { + case NS_THEME_TAB: + { + PRBool isSelected = CheckBooleanAttr(aFrame, mSelectedAtom); + tab_type = (isSelected ? kTabSelected : kTabNormal); + } + break; + case NS_THEME_TAB_LEFT_EDGE: + tab_type = kTabBeforeSelected; + break; + case NS_THEME_TAB_RIGHT_EDGE: + tab_type = kTabAfterSelected; + break; + } + + moz_gtk_tab_paint(window, gTabWidget->style, &gdk_rect, &gdk_clip, + tab_type); + break; + } } return NS_OK; @@ -555,7 +586,7 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsIPresContext* aPresContext, case NS_THEME_TOOLBAR_GRIPPER: case NS_THEME_STATUSBAR: case NS_THEME_STATUSBAR_PANEL: - // case NS_THEME_RESIZER: + // case NS_THEME_RESIZER: (n/a for gtk) // case NS_THEME_LISTBOX: // case NS_THEME_LISTBOX_LISTITEM: // case NS_THEME_TREEVIEW: @@ -570,16 +601,16 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsIPresContext* aPresContext, case NS_THEME_PROGRESSBAR_CHUNK: case NS_THEME_PROGRESSBAR_VERTICAL: case NS_THEME_PROGRESSBAR_CHUNK_VERTICAL: - // case NS_THEME_TAB: + case NS_THEME_TAB: // case NS_THEME_TAB_PANEL: - // case NS_THEME_TAB_LEFT_EDGE: - // case NS_THEME_TAB_RIGHT_EDGE: + case NS_THEME_TAB_LEFT_EDGE: + case NS_THEME_TAB_RIGHT_EDGE: // case NS_THEME_TAB_PANELS: case NS_THEME_TOOLTIP: // case NS_THEME_SPINNER: // case NS_THEME_SPINNER_UP_BUTTON: // case NS_THEME_SPINNER_DOWN_BUTTON: - // case NS_THEME_SCROLLBAR: + // case NS_THEME_SCROLLBAR: (n/a for gtk) case NS_THEME_SCROLLBAR_BUTTON_UP: case NS_THEME_SCROLLBAR_BUTTON_DOWN: case NS_THEME_SCROLLBAR_BUTTON_LEFT: @@ -588,8 +619,8 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsIPresContext* aPresContext, case NS_THEME_SCROLLBAR_TRACK_VERTICAL: case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: case NS_THEME_SCROLLBAR_THUMB_VERTICAL: - // case NS_THEME_SCROLLBAR_GRIPPER_HORIZONTAL: - // case NS_THEME_SCROLLBAR_GRIPPER_VERTICAL: + // case NS_THEME_SCROLLBAR_GRIPPER_HORIZONTAL: (n/a for gtk) + // case NS_THEME_SCROLLBAR_GRIPPER_VERTICAL: (n/a for gtk) case NS_THEME_TEXTFIELD: // case NS_THEME_TEXTFIELD_CARET: // case NS_THEME_DROPDOWN: @@ -734,3 +765,12 @@ nsNativeThemeGTK::EnsureProgressBarWidget() } } +void +nsNativeThemeGTK::EnsureTabWidget() +{ + if (!gTabWidget) { + gTabWidget = gtk_notebook_new(); + SetupWidgetPrototype(gTabWidget); + } +} + diff --git a/widget/src/gtk/nsNativeThemeGTK.h b/widget/src/gtk/nsNativeThemeGTK.h index 975f1e4d1997..785f3147ea67 100644 --- a/widget/src/gtk/nsNativeThemeGTK.h +++ b/widget/src/gtk/nsNativeThemeGTK.h @@ -99,6 +99,7 @@ protected: void EnsureTooltipWidget(); void EnsureFrameWidget(); void EnsureProgressBarWidget(); + void EnsureTabWidget(); private: nsCOMPtr mCheckedAtom; diff --git a/widget/src/gtk2/gtkdrawing.h b/widget/src/gtk2/gtkdrawing.h index a27f42709094..72718ff2f5f2 100644 --- a/widget/src/gtk2/gtkdrawing.h +++ b/widget/src/gtk2/gtkdrawing.h @@ -56,6 +56,13 @@ typedef struct { PRPackedBool canDefault; } GtkWidgetState; +typedef enum { + kTabNormal, + kTabBeforeSelected, + kTabSelected, + kTabAfterSelected +} GtkTabType; + void moz_gtk_button_paint(GdkWindow* window, GtkStyle* style, GdkRectangle* rect, GdkRectangle* cliprect, GtkWidgetState* state, @@ -123,6 +130,10 @@ void moz_gtk_progress_chunk_paint(GdkWindow* window, GtkStyle* style, GdkRectangle* rect, GdkRectangle* cliprect); +void +moz_gtk_tab_paint(GdkWindow* window, GtkStyle* style, GdkRectangle* rect, + GdkRectangle* cliprect, GtkTabType type); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/widget/src/gtk2/nsNativeThemeGTK.cpp b/widget/src/gtk2/nsNativeThemeGTK.cpp index 791cf386f924..a68c8e715422 100644 --- a/widget/src/gtk2/nsNativeThemeGTK.cpp +++ b/widget/src/gtk2/nsNativeThemeGTK.cpp @@ -67,6 +67,7 @@ GtkWidget* gHandleBoxWidget; GtkWidget* gFrameWidget; GtkWidget* gProtoWindow; GtkWidget* gProgressWidget; +GtkWidget* gTabWidget; GtkTooltips* gTooltipWidget; nsNativeThemeGTK::nsNativeThemeGTK() @@ -352,6 +353,36 @@ nsNativeThemeGTK::DrawWidgetBackground(nsIRenderingContext* aContext, moz_gtk_progress_chunk_paint(window, gProgressWidget->style, &gdk_rect, &gdk_clip); break; + +// case NS_THEME_TAB_PANELS: +// EnsureTabWidget(); +// break; + + case NS_THEME_TAB: + case NS_THEME_TAB_LEFT_EDGE: + case NS_THEME_TAB_RIGHT_EDGE: + { + EnsureTabWidget(); + GtkTabType tab_type; + switch (aWidgetType) { + case NS_THEME_TAB: + { + PRBool isSelected = CheckBooleanAttr(aFrame, mSelectedAtom); + tab_type = (isSelected ? kTabSelected : kTabNormal); + } + break; + case NS_THEME_TAB_LEFT_EDGE: + tab_type = kTabBeforeSelected; + break; + case NS_THEME_TAB_RIGHT_EDGE: + tab_type = kTabAfterSelected; + break; + } + + moz_gtk_tab_paint(window, gTabWidget->style, &gdk_rect, &gdk_clip, + tab_type); + break; + } } return NS_OK; @@ -555,7 +586,7 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsIPresContext* aPresContext, case NS_THEME_TOOLBAR_GRIPPER: case NS_THEME_STATUSBAR: case NS_THEME_STATUSBAR_PANEL: - // case NS_THEME_RESIZER: + // case NS_THEME_RESIZER: (n/a for gtk) // case NS_THEME_LISTBOX: // case NS_THEME_LISTBOX_LISTITEM: // case NS_THEME_TREEVIEW: @@ -570,16 +601,16 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsIPresContext* aPresContext, case NS_THEME_PROGRESSBAR_CHUNK: case NS_THEME_PROGRESSBAR_VERTICAL: case NS_THEME_PROGRESSBAR_CHUNK_VERTICAL: - // case NS_THEME_TAB: + case NS_THEME_TAB: // case NS_THEME_TAB_PANEL: - // case NS_THEME_TAB_LEFT_EDGE: - // case NS_THEME_TAB_RIGHT_EDGE: + case NS_THEME_TAB_LEFT_EDGE: + case NS_THEME_TAB_RIGHT_EDGE: // case NS_THEME_TAB_PANELS: case NS_THEME_TOOLTIP: // case NS_THEME_SPINNER: // case NS_THEME_SPINNER_UP_BUTTON: // case NS_THEME_SPINNER_DOWN_BUTTON: - // case NS_THEME_SCROLLBAR: + // case NS_THEME_SCROLLBAR: (n/a for gtk) case NS_THEME_SCROLLBAR_BUTTON_UP: case NS_THEME_SCROLLBAR_BUTTON_DOWN: case NS_THEME_SCROLLBAR_BUTTON_LEFT: @@ -588,8 +619,8 @@ nsNativeThemeGTK::ThemeSupportsWidget(nsIPresContext* aPresContext, case NS_THEME_SCROLLBAR_TRACK_VERTICAL: case NS_THEME_SCROLLBAR_THUMB_HORIZONTAL: case NS_THEME_SCROLLBAR_THUMB_VERTICAL: - // case NS_THEME_SCROLLBAR_GRIPPER_HORIZONTAL: - // case NS_THEME_SCROLLBAR_GRIPPER_VERTICAL: + // case NS_THEME_SCROLLBAR_GRIPPER_HORIZONTAL: (n/a for gtk) + // case NS_THEME_SCROLLBAR_GRIPPER_VERTICAL: (n/a for gtk) case NS_THEME_TEXTFIELD: // case NS_THEME_TEXTFIELD_CARET: // case NS_THEME_DROPDOWN: @@ -734,3 +765,12 @@ nsNativeThemeGTK::EnsureProgressBarWidget() } } +void +nsNativeThemeGTK::EnsureTabWidget() +{ + if (!gTabWidget) { + gTabWidget = gtk_notebook_new(); + SetupWidgetPrototype(gTabWidget); + } +} + diff --git a/widget/src/gtk2/nsNativeThemeGTK.h b/widget/src/gtk2/nsNativeThemeGTK.h index 975f1e4d1997..785f3147ea67 100644 --- a/widget/src/gtk2/nsNativeThemeGTK.h +++ b/widget/src/gtk2/nsNativeThemeGTK.h @@ -99,6 +99,7 @@ protected: void EnsureTooltipWidget(); void EnsureFrameWidget(); void EnsureProgressBarWidget(); + void EnsureTabWidget(); private: nsCOMPtr mCheckedAtom;