diff --git a/comp/src/gb.form/.project b/comp/src/gb.form/.project index 89dd9e2c5..8d7b3726c 100644 --- a/comp/src/gb.form/.project +++ b/comp/src/gb.form/.project @@ -1,7 +1,7 @@ # Gambas Project File 3.0 # Compiled with Gambas 3.5.90 Title=More controls for graphical components -Startup=FTabPanel +Startup=Form5 Version=3.5.90 VersionFile=1 Component=gb.image diff --git a/comp/src/gb.form/.src/Button/ButtonBox.class b/comp/src/gb.form/.src/Button/ButtonBox.class index 70e4a2824..260ed3d21 100644 --- a/comp/src/gb.form/.src/Button/ButtonBox.class +++ b/comp/src/gb.form/.src/Button/ButtonBox.class @@ -129,21 +129,6 @@ Private Sub Border_Write(Value As Boolean) End -' Public Sub Background_Arrange() -' -' '$hBackground.Move(0, 0, $hPanel.W, $hPanel.H) -' Dim iPad As Integer = If($bBorder, 3, 0) -' -' If $hButton.Visible Then -' $hTextBox.Move(iPad, iPad, $hBackground.W - $hButton.W - iPad * 2, $hBackground.H - iPad * 2) -' $hButton.Move($hBackground.W - $hButton.W - iPad, iPad, $hButton.W, $hBackground.H - iPad * 2) -' Else -' $hTextBox.Move(iPad, iPad, $hBackground.W - iPad * 2, $hBackground.H - iPad * 2) -' Endif -' -' End - - Public Sub Background_Draw() 'Dim FW, FH As Integer @@ -151,12 +136,8 @@ Public Sub Background_Draw() If Me.Background <> Color.Default Then iBg = Me.Background - 'FW = If($bBorder, Style.FrameWidth, 0) - 'FH = If($bBorder, Style.FrameWidth, 0) - - 'Draw.FillRect(FW, FH, Me.W - FW * 2, Me.H - FH * 2, iBg) If $bBorder Then - Style.PaintBox(0, 0, Me.W, Me.H, Style.StateOf(Me), iBg) + Style.PaintBox(0, 0, Me.W, Me.H, Style.StateOf($hTextBox), iBg) Else Paint.FillRect(0, 0, Me.W, Me.H, iBg) Endif diff --git a/comp/src/gb.form/.src/Test/Form5.form b/comp/src/gb.form/.src/Test/Form5.form index 502c7c2ea..dd0fd1770 100644 --- a/comp/src/gb.form/.src/Test/Form5.form +++ b/comp/src/gb.form/.src/Test/Form5.form @@ -1,7 +1,8 @@ # Gambas Form File 3.0 { Form Form - MoveScaled(0,0,64,64) + MoveScaled(0,0,44,32) + Margin = True { Menu1 Menu { Menu2 Menu Text = ("Menu2") @@ -16,33 +17,13 @@ Text = ("Menu5") } } - { ColorButton1 ColorButton - MoveScaled(3,4,13,5) - } - { MenuButton1 MenuButton - MoveScaled(16,21,15,4) - Text = ("MenuButton1") - } - { MenuButton2 MenuButton - MoveScaled(16,28,15,4) - Enabled = False - Text = ("MenuButton2") - } - { Button1 Button - MoveScaled(35,29,16,4) - Enabled = False - Text = ("Button1") - } - { Button2 Button - MoveScaled(35,21,16,4) - Text = ("Button2") - } - { TextBox1 TextBox - MoveScaled(13,37,24,4) - Text = ("TextBox1") - } { ButtonBox1 ButtonBox - MoveScaled(13,43,24,4) + MoveScaled(1,1,29,5) Text = ("ButtonBox1") } + { ButtonBox2 ButtonBox + MoveScaled(2,8,29,5) + Text = ("ButtonBox1") + Border = False + } } diff --git a/gb.gtk/src/gapplication.cpp b/gb.gtk/src/gapplication.cpp index ff261ac9e..c0f82d2d7 100644 --- a/gb.gtk/src/gapplication.cpp +++ b/gb.gtk/src/gapplication.cpp @@ -1276,14 +1276,6 @@ int gApplication::getScrollbarSpacing() return v; } -int gApplication::getFrameWidth() -{ - if (strcmp(getStyleName(), "oxygen-gtk") == 0) - return 3; - else - return 2; -} - int gApplication::getInnerWidth() { if (strcmp(getStyleName(), "oxygen-gtk") == 0) @@ -1292,6 +1284,51 @@ int gApplication::getInnerWidth() return 0; } +int gApplication::getFrameWidth() +{ + int w; +#ifdef GTK3 + GtkStyleContext *context = gt_get_style(GTK_TYPE_ENTRY); + GtkBorder tmp; + GtkBorder border; + + gtk_style_context_get_padding(context, (GtkStateFlags)0, &tmp); + gtk_style_context_get_border(context, (GtkStateFlags)0, &border); + + tmp.top += border.top; + tmp.right += border.right; + tmp.bottom += border.bottom; + tmp.left += border.left; + + w = MIN(tmp.top, tmp.left); + w = MIN(w, tmp.bottom); + w = MIN(w, tmp.right); + w = MAX(0, w - 1); + +#else + GtkStyle *style; + gint focus_width; + gboolean interior_focus; + //int inner; + + style = gt_get_old_style(GTK_TYPE_ENTRY); + + gtk_style_get(style, GTK_TYPE_ENTRY, + "focus-line-width", &focus_width, + "interior-focus", &interior_focus, + (char *)NULL); + + w = MIN(style->xthickness, style->ythickness); + + if (!interior_focus) + w += focus_width; + + w += getInnerWidth(); +#endif + + return w; +} + void gApplication::getBoxFrame(int *w, int *h) { GtkStyle *style; diff --git a/gb.gtk/src/gcontrol.cpp b/gb.gtk/src/gcontrol.cpp index 729e84dfd..b81995f20 100644 --- a/gb.gtk/src/gcontrol.cpp +++ b/gb.gtk/src/gcontrol.cpp @@ -1273,7 +1273,7 @@ gColor gControl::getFrameColor() #ifdef GTK3 void gControl::drawBorder(cairo_t *cr) { - gt_draw_border(cr, gtk_widget_get_style_context(widget), GTK_STATE_FLAG_NORMAL, getFrameBorder(), getFrameColor(), 0, 0, width(), height()); + gt_draw_border(cr, gtk_widget_get_style_context(widget), GTK_STATE_FLAG_NORMAL, getFrameBorder(), getFrameColor(), 0, 0, width(), height(), use_base); } #else void gControl::drawBorder(GdkEventExpose *e) @@ -1330,7 +1330,10 @@ void gControl::drawBorder(GdkEventExpose *e) GdkRectangle clip; gdk_region_get_clipbox(e->region, &clip); GtkStyle *st = gtk_widget_get_style(widget); - gtk_paint_shadow(st, win, GTK_STATE_NORMAL, shadow, &clip, NULL, NULL, x, y, w, h); + if (use_base) + gtk_paint_box(st, win, GTK_STATE_NORMAL, shadow, &clip, NULL, "entry", x, y, w, h); + else + gtk_paint_shadow(st, win, GTK_STATE_NORMAL, shadow, &clip, NULL, NULL, x, y, w, h); } #endif @@ -1647,28 +1650,29 @@ void gControl::realizeScrolledWindow(GtkWidget *wid, bool doNotRealize) void gControl::updateBorder() { - int padding; + int pad; if (!frame) return; if (!GTK_IS_ALIGNMENT(frame)) { + fprintf(stderr, "updateBorder: !alignment\n"); refresh(); return; } switch (frame_border) { - case BORDER_NONE: padding = 0; break; - case BORDER_PLAIN: padding = 1; break; - default: padding = 2; break; // TODO: Use style + case BORDER_NONE: pad = 0; break; + case BORDER_PLAIN: pad = 1; break; + default: pad = gApplication::getFrameWidth(); break; } - if ((int)frame_padding > padding) - padding = frame_padding; + if ((int)frame_padding > pad) + pad = frame_padding; - gtk_alignment_set_padding(GTK_ALIGNMENT(frame), padding, padding, padding, padding); + gtk_alignment_set_padding(GTK_ALIGNMENT(frame), pad, pad, pad, pad); refresh(); //gtk_widget_queue_draw(frame); } diff --git a/gb.gtk/src/gtextarea.cpp b/gb.gtk/src/gtextarea.cpp index 4c4214db3..0beda3ea2 100644 --- a/gb.gtk/src/gtextarea.cpp +++ b/gb.gtk/src/gtextarea.cpp @@ -337,8 +337,8 @@ gTextArea::gTextArea(gContainer *parent) : gControl(parent) g_signal_connect(G_OBJECT(_buffer), "insert-text", G_CALLBACK(cb_insert_text), (gpointer)this); g_signal_connect(G_OBJECT(_buffer), "delete-range", G_CALLBACK(cb_delete_range), (gpointer)this); - gtk_text_view_set_left_margin(GTK_TEXT_VIEW(textview), 2); - gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textview), 2); + /*gtk_text_view_set_left_margin(GTK_TEXT_VIEW(textview), 2); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textview), 2);*/ setBorder(true); setWrap(false); diff --git a/gb.gtk/src/gtextbox.cpp b/gb.gtk/src/gtextbox.cpp index 11168f5d2..468df294d 100644 --- a/gb.gtk/src/gtextbox.cpp +++ b/gb.gtk/src/gtextbox.cpp @@ -22,6 +22,7 @@ ***************************************************************************/ #include "widgets.h" +#include "gapplication.h" #include "gtextbox.h" #ifdef GTK3 @@ -118,6 +119,10 @@ struct _GtkEntryPrivate }; #endif +#ifdef GTK3 +GtkCssProvider *gTextBox::_style_provider = NULL; +#endif + static void cb_change_insert(GtkEditable *editable, gchar *new_text, gint new_text_length, gint *position, gTextBox *data) { gtk_editable_set_position(editable, *position); @@ -138,6 +143,24 @@ static void cb_activate(GtkEntry *editable,gTextBox *data) gTextBox::gTextBox(gContainer *parent, bool combo) : gControl(parent) { +#ifdef GTK3 + if (!_style_provider) + { + const char *css; + + _style_provider = gtk_css_provider_new(); + + if (strcmp(gApplication::getStyleName(), "Clearlooks-Phenix") == 0) + css = "GtkEntry { border-width: 0; padding: 0; border-radius: 0; margin: 0; border-style: none; box-shadow: none; background-image: none; }"; + else + css = "GtkEntry { border-width: 0; padding: 0; border-radius: 0; margin: 0; border-style: none; box-shadow: none; }"; + + gtk_css_provider_load_from_data(_style_provider, css, -1, NULL); + } + + g_object_ref(_style_provider); +#endif + if (!combo) { g_typ=Type_gTextBox; @@ -155,6 +178,13 @@ gTextBox::gTextBox(gContainer *parent, bool combo) : gControl(parent) onActivate = NULL; } +gTextBox::~gTextBox() +{ +#ifdef GTK3 + g_object_unref(_style_provider); +#endif +} + void gTextBox::initEntry() { if (!entry) @@ -256,10 +286,23 @@ void gTextBox::setBorder(bool vl) gtk_entry_set_has_frame(GTK_ENTRY(entry), vl); -#ifndef GTK3 +#ifdef GTK3 + GtkStyleContext *style = gtk_widget_get_style_context(entry); + if (vl) + gtk_style_context_remove_provider(style, GTK_STYLE_PROVIDER(_style_provider)); + else + gtk_style_context_add_provider(style, GTK_STYLE_PROVIDER(_style_provider), GTK_STYLE_PROVIDER_PRIORITY_USER); + + gtk_style_context_invalidate(style); +#else + if (vl) + gtk_entry_set_inner_border(GTK_ENTRY(entry), NULL); + else + { GtkBorder *border = gtk_border_new(); gtk_entry_set_inner_border(GTK_ENTRY(entry), border); gtk_border_free(border); + } #endif } diff --git a/gb.gtk/src/gtextbox.h b/gb.gtk/src/gtextbox.h index 065eb4645..7ad48183a 100644 --- a/gb.gtk/src/gtextbox.h +++ b/gb.gtk/src/gtextbox.h @@ -28,6 +28,7 @@ class gTextBox : public gControl { public: gTextBox(gContainer *parent, bool combo = false); + ~gTextBox(); //"Properties" int alignment(); @@ -69,6 +70,10 @@ public: void initEntry(); GtkWidget *entry; virtual int minimumHeight(); + +#ifdef GTK3 + static GtkCssProvider *_style_provider; +#endif }; #endif diff --git a/gb.gtk/src/gtools.cpp b/gb.gtk/src/gtools.cpp index 36e5d51ea..dfa9d76d3 100644 --- a/gb.gtk/src/gtools.cpp +++ b/gb.gtk/src/gtools.cpp @@ -2053,7 +2053,7 @@ GtkStyle *gt_get_style(GType type) // Draw a styled border -void gt_draw_border(cairo_t *cr, GtkStyleContext *st, GtkStateFlags state, int border, gColor color, int x, int y, int w, int h) +void gt_draw_border(cairo_t *cr, GtkStyleContext *st, GtkStateFlags state, int border, gColor color, int x, int y, int w, int h, bool bg) { if (border == BORDER_NONE) return; @@ -2087,7 +2087,8 @@ void gt_draw_border(cairo_t *cr, GtkStyleContext *st, GtkStateFlags state, int b st = gt_get_style(GTK_TYPE_ENTRY); gtk_style_context_set_state(st, state); //gtk_style_context_add_class(st, GTK_STYLE_CLASS_ENTRY); - + if (bg) + gtk_render_background(st, cr, x, y, w, h); gtk_render_frame(st, cr, x, y, w, h); } else if (border == BORDER_ETCHED) diff --git a/gb.gtk/src/gtools.h b/gb.gtk/src/gtools.h index a9874ee68..c1074cd51 100644 --- a/gb.gtk/src/gtools.h +++ b/gb.gtk/src/gtools.h @@ -183,7 +183,7 @@ bool gt_style_lookup_color(GtkStyleContext *style, const char **names, const cha // Draw a control border #ifdef GTK3 -void gt_draw_border(cairo_t *cr, GtkStyleContext *st, GtkStateFlags state, int border, gColor color, int x, int y, int w, int h); +void gt_draw_border(cairo_t *cr, GtkStyleContext *st, GtkStateFlags state, int border, gColor color, int x, int y, int w, int h, bool bg = false); #endif // Style management