Change cursor type when hoover over link
authorMichael Rasmussen <mir@datanom.net>
Fri, 9 Nov 2018 16:00:50 +0000 (17:00 +0100)
committerAndrej Kacian <ticho@claws-mail.org>
Tue, 12 Feb 2019 18:38:09 +0000 (19:38 +0100)
Signed-off-by: Michael Rasmussen <mir@datanom.net>
src/plugins/litehtml_viewer/lh_widget.cpp
src/plugins/litehtml_viewer/lh_widget.h

index f92cd3d2d2f10502c3d1b82c2fc45bb748e8ee35..0b0839b1087dd0206b36d63dc20b6e2f292f2189 100644 (file)
@@ -123,13 +123,6 @@ void lh_widget::on_anchor_click(const litehtml::tchar_t* url, const litehtml::el
        return;
 }
 
-void lh_widget::set_cursor(const litehtml::tchar_t* cursor)
-{
-       g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget set_cursor");
-       if (cursor == NULL)
-               return;
-}
-
 void lh_widget::import_css(litehtml::tstring& text, const litehtml::tstring& url, litehtml::tstring& baseurl)
 {
        g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget import_css");
@@ -286,6 +279,36 @@ void lh_widget::clear()
        m_rendered_width = 0;
 }
 
+void lh_widget::set_cursor(const litehtml::tchar_t* cursor)
+{
+    g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget set_cursor %s:%s", m_cursor, cursor);
+    if (cursor)
+    {
+       if (m_cursor != cursor)
+       {
+           m_cursor = cursor;
+           update_cursor();
+       }
+    }
+}
+
+void lh_widget::update_cursor()
+{
+    g_log(NULL, G_LOG_LEVEL_MESSAGE, "lh_widget update_cursor %s", m_cursor);
+    GdkCursorType cursType = GDK_ARROW;
+    if(m_cursor == _t("pointer"))
+    {
+        cursType = GDK_HAND1;
+    }
+    if(cursType == GDK_ARROW)
+    {
+        gdk_window_set_cursor(gtk_widget_get_window(m_drawing_area), NULL);
+    } else
+    {
+        gdk_window_set_cursor(gtk_widget_get_window(m_drawing_area), gdk_cursor_new(cursType));
+    }
+}
+
 static gboolean expose_event_cb(GtkWidget *widget, GdkEvent *event,
                gpointer user_data)
 {
@@ -320,6 +343,7 @@ static gboolean button_press_event(GtkWidget *widget, GdkEventButton *event,
         {
             for(auto& pos : redraw_boxes)
             {
+               g_log(NULL, G_LOG_LEVEL_MESSAGE, "x: %d y:%d w: %d h: %d", pos.x, pos.y, pos.width, pos.height);
                 gtk_widget_queue_draw_area(widget, pos.x, pos.y, pos.width, pos.height);
             }
         }
@@ -342,6 +366,7 @@ static gboolean motion_notify_event(GtkWidget *widget, GdkEventButton *event,
         {
             for (auto& pos : redraw_boxes)
             {
+               g_log(NULL, G_LOG_LEVEL_MESSAGE, "x: %d y:%d w: %d h: %d", pos.x, pos.y, pos.width, pos.height);
                 gtk_widget_queue_draw_area(widget, pos.x, pos.y, pos.width, pos.height);
             }
         }
@@ -366,6 +391,7 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
         {
             for (auto& pos : redraw_boxes)
             {
+               g_log(NULL, G_LOG_LEVEL_MESSAGE, "x: %d y:%d w: %d h: %d", pos.x, pos.y, pos.width, pos.height);
                 gtk_widget_queue_draw_area(widget, pos.x, pos.y, pos.width, pos.height);
             }
         }
@@ -373,7 +399,9 @@ static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
         if (!w->m_clicked_url.empty())
         {
                 g_log(NULL, G_LOG_LEVEL_MESSAGE, "Open in browser: %s", w->m_clicked_url.c_str());
-                gtk_show_uri(NULL, w->m_clicked_url.c_str(), GDK_CURRENT_TIME, &error);
+               gtk_show_uri(gdk_screen_get_default(),
+                            w->m_clicked_url.c_str(),
+                            GDK_CURRENT_TIME, &error);
                 if (error) {
                     g_log(NULL, G_LOG_LEVEL_ERROR, "Failed opening url(%s): %s", w->m_clicked_url, error->message);
                     g_clear_error(&error);
index 32d751c4c4e0515d0e570ad1ab4ea073bb059234..2f4eb11a23d02998ba7cec604c8e4ea5f0ca2cdc 100644 (file)
@@ -28,8 +28,9 @@ class lh_widget : public container_linux
                void redraw();
                void open_html(const gchar *contents);
                void clear();
+               void update_cursor();
 
-        litehtml::document::ptr m_html;
+               litehtml::document::ptr m_html;
                litehtml::tstring m_clicked_url;
 
        private: