summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2023-12-07 09:54:31 +0000
committerVincent Sanders <vince@kyllikki.org>2024-02-25 10:00:56 +0000
commit653ebf7228297adaae01969a53d4393c9752e357 (patch)
tree3167f3fe0e84add96ddb9a18b9654d6b9f7a8f09
parent9bc717498c8a8219c23aa75c24b943759749f81c (diff)
downloadnetsurf-653ebf7228297adaae01969a53d4393c9752e357.tar.gz
netsurf-653ebf7228297adaae01969a53d4393c9752e357.tar.bz2
split out widget and urlbar method implementations
-rw-r--r--frontends/qt/Makefile12
-rw-r--r--frontends/qt/urlbar.cpp117
-rw-r--r--frontends/qt/widget.cpp182
-rw-r--r--frontends/qt/window.cpp255
4 files changed, 309 insertions, 257 deletions
diff --git a/frontends/qt/Makefile b/frontends/qt/Makefile
index f3afee15d..91e29fea7 100644
--- a/frontends/qt/Makefile
+++ b/frontends/qt/Makefile
@@ -42,8 +42,16 @@ S_RESOURCE :=
# ----------------------------------------------------------------------------
# S_FRONTEND are sources purely for the QT frontend
-S_FRONTEND := main.cpp misc.cpp window.cpp fetch.cpp bitmap.cpp layout.cpp \
- plotters.cpp resources.cpp \
+S_FRONTEND := main.cpp \
+ misc.cpp \
+ window.cpp \
+ widget.cpp \
+ urlbar.cpp \
+ fetch.cpp \
+ bitmap.cpp \
+ layout.cpp \
+ plotters.cpp \
+ resources.cpp \
window.cls.moc.cpp widget.cls.moc.cpp urlbar.cls.moc.cpp
# This is the final source build list
diff --git a/frontends/qt/urlbar.cpp b/frontends/qt/urlbar.cpp
new file mode 100644
index 000000000..a54f5d797
--- /dev/null
+++ b/frontends/qt/urlbar.cpp
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2023 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf 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; version 2 of the License.
+ *
+ * NetSurf 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Widget methods for browsing context display.
+ */
+
+#include <QLineEdit>
+
+#include "qt/urlbar.cls.h"
+
+/**
+ * urlbar constructor
+ */
+NS_URLBar::NS_URLBar(QWidget* parent, struct browser_window *bw)
+ : QToolBar(parent), m_bw(bw)
+{
+ addAction(QIcon(":/icons/back.png"), "Back");
+ addAction(QIcon(":/icons/forward.png"), "Forward");
+ QLineEdit *input=new QLineEdit();
+ addWidget(input);
+}
+
+#if 0
+/**
+ * widget representing url bar
+ */
+class NS_URLBar : public Fl_Pack
+{
+private:
+ struct browser_window *m_bw;
+ Fl_Button *m_back_button;
+ Fl_Button *m_forward_button;
+ Fl_Input *m_input;
+
+ void back_callback(Fl_Button *button);
+ void forward_callback(Fl_Button *button);
+public:
+ NS_URLBar(int X,int Y,int W,int H, struct browser_window *bw);
+ nserror set_url(struct nsurl *url);
+
+ /* static wrapper for qt callbacks */
+ static void static_back_callback(Fl_Widget *w, void *f);
+ static void static_forward_callback(Fl_Widget *w, void *f);
+
+};
+
+NS_URLBar::NS_URLBar(int X,int Y,int W,int H, struct browser_window *bw)
+ : Fl_Pack(X,Y,W,H), m_bw(bw)
+{
+ type(Fl_Pack::HORIZONTAL);
+ spacing(4);
+
+ m_back_button = new Fl_Button(0,0,H,H, "B");
+ m_back_button->callback(static_back_callback, (void *)this);
+
+ m_forward_button = new Fl_Button(0,0,H,H, "F");
+ m_forward_button->callback(static_forward_callback, (void *)this);
+
+ m_input = new Fl_Input(0,0,W,H);
+
+ end();
+
+ resizable(m_input);
+}
+
+nserror NS_URLBar::set_url(struct nsurl *url)
+{
+ size_t idn_url_l;
+ char *idn_url_s = NULL;
+ if (nsurl_get_utf8(url, &idn_url_s, &idn_url_l) == NSERROR_OK) {
+ m_input->value(idn_url_s, idn_url_l-1);
+ free(idn_url_s);
+ } else {
+ m_input->value(nsurl_access(url));
+ }
+ return NSERROR_OK;
+}
+
+void NS_URLBar::back_callback(Fl_Button *button)
+{
+ browser_window_history_back(m_bw, false);
+}
+
+void NS_URLBar::forward_callback(Fl_Button *button)
+{
+ browser_window_history_forward(m_bw, false);
+}
+
+
+void NS_URLBar::static_back_callback(Fl_Widget *w, void *f)
+{
+ ((NS_URLBar *)f)->back_callback((Fl_Button *)w);
+}
+
+void NS_URLBar::static_forward_callback(Fl_Widget *w, void *f)
+{
+ ((NS_URLBar *)f)->forward_callback((Fl_Button *)w);
+}
+
+#endif
diff --git a/frontends/qt/widget.cpp b/frontends/qt/widget.cpp
new file mode 100644
index 000000000..e69d79970
--- /dev/null
+++ b/frontends/qt/widget.cpp
@@ -0,0 +1,182 @@
+/*
+ * Copyright 2023 Vincent Sanders <vince@netsurf-browser.org>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf 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; version 2 of the License.
+ *
+ * NetSurf 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * \file
+ * Widget methods for browsing context display.
+ */
+
+#include <QPaintEvent>
+#include <QPainter>
+
+extern "C" {
+#include "utils/errors.h"
+#include "netsurf/plotters.h"
+}
+
+#include "qt/widget.cls.h"
+
+#include "qt/plotters.h"
+
+/**
+ * widget has been resized
+ */
+void NS_Widget::resizeEvent(QResizeEvent *event)
+{
+ browser_window_schedule_reformat(m_bw);
+}
+
+/**
+ * redraw the netsurf browsing widget
+ */
+void NS_Widget::paintEvent(QPaintEvent *event)
+{
+ struct rect clip;
+ QPainter *painter;
+ struct redraw_context ctx = {
+ .interactive = true,
+ .background_images = true,
+ .plot = &nsqt_plotters,
+ .priv = NULL,
+ };
+
+ /* netsurf render clip region coordinates */
+ clip.x0 = event->rect().left();
+ clip.y0 = event->rect().top();
+ clip.x1 = clip.x0 + event->rect().width();
+ clip.y1 = clip.y0 + event->rect().height();
+
+ painter = new QPainter(this);
+ ctx.priv = painter;
+
+ browser_window_redraw(m_bw,
+ - m_xoffset,
+ - m_yoffset,
+ &clip,
+ &ctx);
+
+ delete painter;
+}
+
+/**
+ * get the current scroll offsets
+ */
+bool NS_Widget::get_scroll(int *sx, int *sy)
+{
+ *sx = m_xoffset;
+ *sy = m_yoffset;
+
+ return true;
+}
+
+
+/**
+ * get the viewable dimensions of browsing context
+ */
+nserror NS_Widget::get_dimensions(int *width, int *height)
+{
+ *width = size().width();
+ *height = size().height();
+
+ return NSERROR_OK;
+}
+
+
+/**
+ * mark an area of the browsing context as invalid
+ */
+nserror NS_Widget::invalidate(const struct rect *rect)
+{
+
+ if (rect == NULL) {
+ update();
+ } else {
+ update(rect->x0,
+ rect->y0,
+ rect->x1 - rect->x0,
+ rect->y1 - rect->y0);
+ }
+ return NSERROR_OK;
+
+}
+
+
+#if 0
+/**
+ * handle events on the netsurf browsing widget
+ */
+int NS_Widget::handle(int event)
+{
+ int state = BROWSER_MOUSE_HOVER;
+ int button;
+
+ switch (event) {
+
+ case FL_PUSH:
+ button = Fl::event_button();
+ if (button == FL_LEFT_MOUSE) {
+ state |= BROWSER_MOUSE_PRESS_1;
+ }
+ browser_window_mouse_click(m_bw,
+ (browser_mouse_state)state,
+ Fl::event_x() - x() + m_xoffset,
+ Fl::event_y() - y() + m_yoffset);
+ return 1;
+
+ case FL_RELEASE:
+ button = Fl::event_button();
+ if (button == FL_LEFT_MOUSE) {
+ state |= BROWSER_MOUSE_CLICK_1;
+
+ }
+ browser_window_mouse_click(m_bw,
+ (browser_mouse_state)state,
+ Fl::event_x() - x() + m_xoffset,
+ Fl::event_y() - y() + m_yoffset);
+
+ return 1;
+ default:
+ return Fl_Widget::handle(event);
+
+ }
+
+}
+#endif
+
+
+
+#if 0
+/**
+ * vertical scrollbar position has been changed
+ */
+void NS_Widget::vscroll_callback(Fl_Scrollbar *sb)
+{
+ m_yoffset = sb->value();
+ //damage(FL_DAMAGE_SCROLL);
+}
+
+
+/**
+ * horizontal scrollbar position has been changed
+ */
+void NS_Widget::hscroll_callback(Fl_Scrollbar *sb)
+{
+ m_xoffset = sb->value();
+ //damage(FL_DAMAGE_SCROLL);
+}
+#endif
diff --git a/frontends/qt/window.cpp b/frontends/qt/window.cpp
index 7c577ca5e..039516c7b 100644
--- a/frontends/qt/window.cpp
+++ b/frontends/qt/window.cpp
@@ -23,8 +23,6 @@
#include <stddef.h>
#include <QWidget>
-#include <QPaintEvent>
-#include <QPainter>
#include <QGridLayout>
#include <QHBoxLayout>
#include <QPushButton>
@@ -52,7 +50,6 @@ extern "C" {
#include "qt/urlbar.cls.h"
#include "qt/window.h"
-#include "qt/plotters.h"
extern bool nsqt_done;
@@ -61,242 +58,6 @@ struct gui_window {
};
-#if 0
-/**
- * handle events on the netsurf browsing widget
- */
-int NS_Widget::handle(int event)
-{
- int state = BROWSER_MOUSE_HOVER;
- int button;
-
- switch (event) {
-
- case FL_PUSH:
- button = Fl::event_button();
- if (button == FL_LEFT_MOUSE) {
- state |= BROWSER_MOUSE_PRESS_1;
- }
- browser_window_mouse_click(m_bw,
- (browser_mouse_state)state,
- Fl::event_x() - x() + m_xoffset,
- Fl::event_y() - y() + m_yoffset);
- return 1;
-
- case FL_RELEASE:
- button = Fl::event_button();
- if (button == FL_LEFT_MOUSE) {
- state |= BROWSER_MOUSE_CLICK_1;
-
- }
- browser_window_mouse_click(m_bw,
- (browser_mouse_state)state,
- Fl::event_x() - x() + m_xoffset,
- Fl::event_y() - y() + m_yoffset);
-
- return 1;
- default:
- return Fl_Widget::handle(event);
-
- }
-
-}
-#endif
-
-/**
- * widget has been resized
- */
-void NS_Widget::resizeEvent(QResizeEvent *event)
-{
- browser_window_schedule_reformat(m_bw);
-}
-
-/**
- * redraw the netsurf browsing widget
- */
-void NS_Widget::paintEvent(QPaintEvent *event)
-{
- struct rect clip;
- QPainter *painter;
- struct redraw_context ctx = {
- .interactive = true,
- .background_images = true,
- .plot = &nsqt_plotters,
- .priv = NULL,
- };
-
- /* netsurf render clip region coordinates */
- clip.x0 = event->rect().left();
- clip.y0 = event->rect().top();
- clip.x1 = clip.x0 + event->rect().width();
- clip.y1 = clip.y0 + event->rect().height();
-
- painter = new QPainter(this);
- ctx.priv = painter;
-
- //NSLOG(netsurf, WARNING, "redrawing");
- browser_window_redraw(m_bw,
- - m_xoffset,
- - m_yoffset,
- &clip,
- &ctx);
-
- delete painter;
-
-}
-
-#if 0
-/**
- * vertical scrollbar position has been changed
- */
-void NS_Widget::vscroll_callback(Fl_Scrollbar *sb)
-{
- m_yoffset = sb->value();
- //damage(FL_DAMAGE_SCROLL);
-}
-
-
-/**
- * horizontal scrollbar position has been changed
- */
-void NS_Widget::hscroll_callback(Fl_Scrollbar *sb)
-{
- m_xoffset = sb->value();
- //damage(FL_DAMAGE_SCROLL);
-}
-#endif
-/**
- * get the current scroll offsets
- */
-bool NS_Widget::get_scroll(int *sx, int *sy)
-{
- *sx = m_xoffset;
- *sy = m_yoffset;
-
- return true;
-}
-
-
-/**
- * get the viewable dimensions of browsing context
- */
-nserror NS_Widget::get_dimensions(int *width, int *height)
-{
- *width = size().width();
- *height = size().height();
-
- return NSERROR_OK;
-}
-
-
-/**
- * mark an area of the browsing context as invalid
- */
-nserror NS_Widget::invalidate(const struct rect *rect)
-{
-
- if (rect == NULL) {
- update();
- } else {
- update(rect->x0,
- rect->y0,
- rect->x1 - rect->x0,
- rect->y1 - rect->y0);
- }
- return NSERROR_OK;
-
-}
-#include <QLineEdit>
-
-NS_URLBar::NS_URLBar(QWidget* parent, struct browser_window *bw)
- : QToolBar(parent), m_bw(bw)
-{
- addAction(QIcon(":/icons/back.png"), "Back");
- addAction(QIcon(":/icons/forward.png"), "Forward");
- QLineEdit *input=new QLineEdit();
- addWidget(input);
-}
-
-#if 0
-/**
- * widget representing url bar
- */
-class NS_URLBar : public Fl_Pack
-{
-private:
- struct browser_window *m_bw;
- Fl_Button *m_back_button;
- Fl_Button *m_forward_button;
- Fl_Input *m_input;
-
- void back_callback(Fl_Button *button);
- void forward_callback(Fl_Button *button);
-public:
- NS_URLBar(int X,int Y,int W,int H, struct browser_window *bw);
- nserror set_url(struct nsurl *url);
-
- /* static wrapper for qt callbacks */
- static void static_back_callback(Fl_Widget *w, void *f);
- static void static_forward_callback(Fl_Widget *w, void *f);
-
-};
-
-NS_URLBar::NS_URLBar(int X,int Y,int W,int H, struct browser_window *bw)
- : Fl_Pack(X,Y,W,H), m_bw(bw)
-{
- type(Fl_Pack::HORIZONTAL);
- spacing(4);
-
- m_back_button = new Fl_Button(0,0,H,H, "B");
- m_back_button->callback(static_back_callback, (void *)this);
-
- m_forward_button = new Fl_Button(0,0,H,H, "F");
- m_forward_button->callback(static_forward_callback, (void *)this);
-
- m_input = new Fl_Input(0,0,W,H);
-
- end();
-
- resizable(m_input);
-}
-
-nserror NS_URLBar::set_url(struct nsurl *url)
-{
- size_t idn_url_l;
- char *idn_url_s = NULL;
- if (nsurl_get_utf8(url, &idn_url_s, &idn_url_l) == NSERROR_OK) {
- m_input->value(idn_url_s, idn_url_l-1);
- free(idn_url_s);
- } else {
- m_input->value(nsurl_access(url));
- }
- return NSERROR_OK;
-}
-
-void NS_URLBar::back_callback(Fl_Button *button)
-{
- browser_window_history_back(m_bw, false);
-}
-
-void NS_URLBar::forward_callback(Fl_Button *button)
-{
- browser_window_history_forward(m_bw, false);
-}
-
-
-void NS_URLBar::static_back_callback(Fl_Widget *w, void *f)
-{
- ((NS_URLBar *)f)->back_callback((Fl_Button *)w);
-}
-
-void NS_URLBar::static_forward_callback(Fl_Widget *w, void *f)
-{
- ((NS_URLBar *)f)->forward_callback((Fl_Button *)w);
-}
-
-#endif
-
-
/**
* netsurf window class constructor
*/
@@ -360,15 +121,6 @@ void NS_Window::closeEvent(QCloseEvent *event)
browser_window_destroy(m_bw);
}
-#if 0
-/**
- * qt window has been closed
- */
-void NS_Window::close_callback(Fl_Widget *w)
-{
- browser_window_destroy(m_bw);
-}
-#endif
/**
* set the status text
@@ -417,13 +169,6 @@ nserror NS_Window::set_extent(int ew, int eh)
/* static methods */
#if 0
-/**
- * static window close qt callback which calls the instance
- */
-void NS_Window::static_close_callback(Fl_Widget *w, void *f)
-{
- ((NS_Window *)f)->close_callback(w);
-}
/**
* static vertical scrollbar qt callback which calls the instance