Separator is now a Gambas-made control.

[GB.GTK]
* NEW: Remove Separator control.
* BUG: Fix minimum size computation.

[GB.GTK3]
* NEW: Remove Separator control.
* BUG: Fix minimum size computation.

[GB.GUI.BASE]
* NEW: Separator is now a Gambas-made control.

[GB.QT4]
* NEW: Remove Separator control.

[GB.QT5]
* NEW: Remove Separator control.
This commit is contained in:
gambas 2021-01-22 23:53:27 +01:00
parent 01a666387f
commit b4ab1027d8
19 changed files with 70 additions and 343 deletions

View file

@ -0,0 +1,47 @@
' Gambas class file
Export
Inherits DrawingArea
Public Const _Properties As String = "*,-Arrangement,-Spacing,-Margin,-Indent,-Invert,-NoBackground,-Tablet,-Cached,-Focus"
Public Const _DefaultEvent As String = "MouseDown"
Public Const _DefaultSize As String = "16,16"
Public Const _IsContainer As Boolean = False
Public Const _Group As String = "Form"
Private $hObs As Observer
Public Sub _new()
$hObs = New Observer(Me) As "DrawingArea"
End
Public Sub DrawingArea_Draw()
Dim iCol As Integer
Dim D As Integer
If Me.Foreground = Color.Default Then
iCol = Color.LightForeground
Else
iCol = Me.Foreground
Endif
If Paint.W = 1 Or If Paint.H = 1 Then
Paint.FillRect(Paint.X, Paint.Y, Paint.W, Paint.H, iCol)
Else
D = 2 + Desktop.Scale \ 2
If Paint.W > Paint.H Then
If Paint.W > D Then
Paint.FillRect(Paint.X + D \ 2, Paint.Y + CInt(Paint.H) \ 2, Paint.W - D, 1, iCol)
Endif
Else
If Paint.H > D Then
Paint.FillRect(Paint.X + CInt(Paint.W) \ 2, Paint.Y + D \ 2, 1, Paint.H - D, iCol)
Endif
Endif
Endif
End

View file

@ -1,51 +0,0 @@
/***************************************************************************
CSeparator.cpp
(c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#define __CSEPARATOR_CPP
#include "CSeparator.h"
#include "CContainer.h"
BEGIN_METHOD(CSEPARATOR_new, GB_OBJECT parent)
InitControl(new gSeparator(CONTAINER(VARG(parent))), (CWIDGET*)THIS);
END_METHOD
GB_DESC CSeparatorDesc[] =
{
GB_DECLARE("Separator", sizeof(CSEPARATOR)), GB_INHERITS("Control"),
GB_METHOD("_new", 0, CSEPARATOR_new, "(Parent)Container;"),
SEPARATOR_DESCRIPTION,
GB_END_DECLARE
};

View file

@ -1,47 +0,0 @@
/***************************************************************************
CSeparator.h
(c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#ifndef __CSEPARATOR_H
#define __CSEPARATOR_H
#include "main.h"
#include "CWidget.h"
#include "gseparator.h"
#ifndef __CSEPARATOR_CPP
extern GB_DESC CSeparatorDesc[];
#else
#define THIS ((CSEPARATOR *)_object)
#define SEPARATOR ((gSeparator*)THIS->ob.widget)
#endif
typedef
struct
{
CWIDGET ob;
}
CSEPARATOR;
#endif

View file

@ -15,7 +15,7 @@ gb_gtk_la_SOURCES = \
gtools.cpp gcolor.h \
gfont.cpp gpicture.cpp \
gdesktop.cpp gdialog.cpp \
gcontrol.cpp gcontainer.cpp gseparator.cpp \
gcontrol.cpp gcontainer.cpp \
gbutton.cpp gslider.cpp glabel.cpp gsignals.cpp \
gcombobox.cpp gtextbox.cpp gtextarea.cpp \
gframe.cpp gtabstrip.cpp \
@ -37,7 +37,6 @@ gb_gtk_la_SOURCES = \
CMouse.h CMouse.cpp \
CWatcher.h CWatcher.cpp \
CWidget.h CWidget.cpp CContainer.h CContainer.cpp \
CSeparator.h CSeparator.cpp \
CDrawingArea.h CDrawingArea.cpp \
CLabel.h CLabel.cpp \
CSlider.h CSlider.cpp \

View file

@ -317,8 +317,8 @@ void gControl::initAll(gContainer *parent)
bufX = -16;
bufY = -16;
_min_w = 1;
_min_h = 1;
_min_w = _min_h = 1;
_minimum_size_set = FALSE;
curs = NULL;
_font = NULL;
_resolved_font = NULL;
@ -686,6 +686,12 @@ bool gControl::resize(int w, int h)
if (w < 0 && h < 0)
return true;
if (!_minimum_size_set)
{
setMinimumSize();
_minimum_size_set = true;
}
if (pr && pr->isArrangementEnabled())
{
pr->decide(this, &decide_w, &decide_h);
@ -1828,20 +1834,27 @@ void gControl::setMinimumSize()
{
#ifdef GTK3
if (isContainer())
{
_min_w = _min_h = 1;
}
else
{
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);*/
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;
_min_w = _min_h = 1;
#endif
}
@ -1893,8 +1906,6 @@ void gControl::realize(bool make_frame)
#endif
connectParent();
setMinimumSize();
resize(8, 8);
initSignals();

View file

@ -297,6 +297,7 @@ public:
unsigned _has_native_popup : 1; // I have a native popup menu
unsigned _eat_return_key : 1; // If the control eats the return key
unsigned _style_dirty : 1; // If the style must be refreshed
unsigned _minimum_size_set : 1; // If minimum size has been computed
void removeParent() { pr = NULL; }
void initSignals();

View file

@ -1,109 +0,0 @@
/***************************************************************************
gseparator.cpp
(c) 2004-2006 - Daniel Campos Fernández <dcamposf@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#include "widgets.h"
#include "gdesktop.h"
#include "gseparator.h"
#ifdef GTK3
static gboolean cb_draw(GtkWidget *wid, cairo_t *cr, gSeparator *data)
{
gint x, y, w, h;
gColor color;
x = y = 0;
w = data->width();
h = data->height();
color = data->foreground();
if (color == COLOR_DEFAULT)
color = gDesktop::getColor(gDesktop::LIGHT_FOREGROUND);
gt_cairo_set_source_color(cr, color);
if (w == 1 || h == 1)
cairo_paint(cr);
else
{
int d = 2 + gDesktop::scale() / 2;
if (h >= w && h > d)
{
cairo_rectangle(cr, x + w / 2, y + d / 2, 1, h - d);
cairo_fill(cr);
}
else if (w > h && w > d)
{
cairo_rectangle(cr, x + d / 2, y + h / 2, w - d, 1);
cairo_fill(cr);
}
}
return false;
}
#else
static gboolean cb_expose(GtkWidget *wid, GdkEventExpose *e, gSeparator *data)
{
gint x, y, w, h;
gColor color;
x = wid->allocation.x;
y = wid->allocation.y;
w = data->width();
h = data->height();
if (w == 1 || h == 1)
{
cairo_t *cr;
cr = gdk_cairo_create(wid->window);
color = data->foreground();
if (color == COLOR_DEFAULT)
color = gDesktop::getColor(gDesktop::LIGHT_FOREGROUND);
gt_cairo_set_source_color(cr, color);
cairo_rectangle(cr, e->area.x, e->area.y, e->area.width, e->area.height);
cairo_fill(cr);
cairo_destroy(cr);
}
else if (w>=h)
gtk_paint_hline(wid->style, wid->window, GTK_STATE_NORMAL, &e->area, wid, NULL, x, x + w, y + h / 2);
else
gtk_paint_vline(wid->style, wid->window, GTK_STATE_NORMAL, &e->area, wid, NULL, y, y + h, x + w / 2);
return false;
}
#endif
gSeparator::gSeparator(gContainer *parent) : gControl(parent)
{
border = widget = gtk_fixed_new();
realize(false);
ON_DRAW(widget, this, cb_expose, cb_draw);
}

View file

@ -1,33 +0,0 @@
/***************************************************************************
gseparator.h
(c) 2000-2017 Benoît Minisini <g4mba5@gmail.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA.
***************************************************************************/
#ifndef __GSEPARATOR_H
#define __GSEPARATOR_H
class gSeparator : public gControl
{
public:
gSeparator(gContainer *parent);
};
#endif

View file

@ -60,7 +60,6 @@
#include "CSlider.h"
#include "CTabStrip.h"
#include "CTrayIcon.h"
#include "CSeparator.h"
#include "cprinter.h"
#include "csvgimage.h"
#include "canimation.h"
@ -238,7 +237,6 @@ GB_DESC *GB_CLASSES[] EXPORT =
CTabStripContainerDesc,
CTabStripContainerChildrenDesc,
CPluginDesc,
CSeparatorDesc,
PrinterDesc,
SvgImageDesc,
NULL

View file

@ -1 +0,0 @@
../../gb.gtk/src/CSeparator.cpp

View file

@ -1 +0,0 @@
../../gb.gtk/src/CSeparator.h

View file

@ -15,7 +15,7 @@ gb_gtk3_la_SOURCES = \
gtools.cpp gcolor.h \
gfont.cpp gpicture.cpp \
gdesktop.cpp gdialog.cpp \
gcontrol.cpp gcontainer.cpp gseparator.cpp \
gcontrol.cpp gcontainer.cpp \
gbutton.cpp gslider.cpp glabel.cpp gsignals.cpp \
gcombobox.cpp gtextbox.cpp gtextarea.cpp \
gframe.cpp gtabstrip.cpp \
@ -37,7 +37,6 @@ gb_gtk3_la_SOURCES = \
CMouse.h CMouse.cpp \
CWatcher.h CWatcher.cpp \
CWidget.h CWidget.cpp CContainer.h CContainer.cpp \
CSeparator.h CSeparator.cpp \
CDrawingArea.h CDrawingArea.cpp \
CLabel.h CLabel.cpp \
CSlider.h CSlider.cpp \

View file

@ -1 +0,0 @@
../../gb.gtk/src/gseparator.cpp

View file

@ -1 +0,0 @@
../../gb.gtk/src/gseparator.h

View file

@ -60,7 +60,6 @@
#include "CSlider.h"
#include "CTabStrip.h"
#include "CTrayIcon.h"
#include "CSeparator.h"
#include "cprinter.h"
#include "csvgimage.h"
#include "canimation.h"
@ -249,7 +248,6 @@ GB_DESC *GB_CLASSES[] EXPORT =
CTabStripDesc,
CTabStripContainerDesc,
CTabStripContainerChildrenDesc,
CSeparatorDesc,
PrinterDesc,
SvgImageDesc,
NULL

View file

@ -207,28 +207,6 @@ GB_DESC CTextLabelDesc[] =
};
/***************************************************************************/
BEGIN_METHOD(CSEPARATOR_new, GB_OBJECT parent)
MySeparator *wid = new MySeparator(QCONTAINER(VARG(parent)));
CWIDGET_new(wid, (void *)_object);
END_METHOD
GB_DESC CSeparatorDesc[] =
{
GB_DECLARE("Separator", sizeof(CSEPARATOR)), GB_INHERITS("Control"),
GB_METHOD("_new", NULL, CSEPARATOR_new, "(Parent)Container;"),
SEPARATOR_DESCRIPTION,
GB_END_DECLARE
};
/** MyLabel *****************************************************************/
MyLabel::MyLabel(QWidget *parent) : QLabel(parent)
@ -406,50 +384,3 @@ void MyLabel::paintEvent(QPaintEvent *e)
QLabel::paintEvent(e);
}
/** class MySeparator ******************************************************/
MySeparator::MySeparator(QWidget *parent)
: QWidget(parent)
{
}
void MySeparator::paintEvent( QPaintEvent * )
{
void *_object = CWidget::getReal(this);
QPainter p(this);
uint color = CWIDGET_get_foreground(&THIS->widget);
QColor pen = (color == COLOR_DEFAULT) ? CCOLOR_light_foreground() : TO_QCOLOR(color);
if (width() == 1 || height() == 1)
{
p.fillRect(0, 0, width(), height(), pen);
}
else
{
/*QStyleOption opt;
opt.rect = rect();
opt.palette = palette();
opt.state |= QStyle::State_Enabled;
if (width() < height())
opt.state |= QStyle::State_Horizontal;
style()->drawPrimitive(QStyle::PE_IndicatorToolBarSeparator, &opt, &p);*/
int d = 2 + MAIN_scale / 2;
if (height() >= width())
{
if (height() > d)
p.fillRect(width() / 2, d / 2, 1, height() - d, pen);
}
else if (width() > d)
{
p.fillRect(d / 2, height() / 2, width() - d, 1, pen);
}
}
}

View file

@ -90,17 +90,4 @@ private:
char _border;
};
class MySeparator : public QWidget
{
Q_OBJECT
public:
MySeparator(QWidget *);
protected:
void paintEvent(QPaintEvent *);
};
#endif

View file

@ -1350,7 +1350,7 @@ GB_DESC *GB_CLASSES[] EXPORT =
CControlDesc, ContainerChildrenDesc, ContainerDesc,
UserControlDesc, UserContainerDesc,
CMenuChildrenDesc, CMenuDesc,
CLabelDesc, CTextLabelDesc, CSeparatorDesc,
CLabelDesc, CTextLabelDesc,
CButtonDesc, CToggleButtonDesc, CToolButtonDesc,
CCheckBoxDesc, CRadioButtonDesc,
CTextBoxSelectionDesc, CTextBoxDesc, CComboBoxItemDesc, CComboBoxDesc,

View file

@ -1102,7 +1102,7 @@ GB_DESC *GB_CLASSES[] EXPORT =
CControlDesc, ContainerChildrenDesc, ContainerDesc,
UserControlDesc, UserContainerDesc,
CMenuChildrenDesc, CMenuDesc,
CLabelDesc, CTextLabelDesc, CSeparatorDesc,
CLabelDesc, CTextLabelDesc,
CButtonDesc, CToggleButtonDesc, CToolButtonDesc,
CCheckBoxDesc, CRadioButtonDesc,
CTextBoxSelectionDesc, CTextBoxDesc, CComboBoxItemDesc, CComboBoxDesc,