2004-12-09 13:30:44 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net>
|
2010-10-05 23:14:46 +04:00
|
|
|
* Copyright 2009 Paul Blokus <paul_pl@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* 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/>.
|
2004-12-09 13:30:44 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
* Generic tree handling (implementation).
|
|
|
|
*/
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
2010-12-16 23:30:10 +03:00
|
|
|
#include <limits.h>
|
2004-12-09 13:30:44 +03:00
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <gdk/gdkkeysyms.h>
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/tree.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "desktop/tree_url_node.h"
|
|
|
|
#include "desktop/plotters.h"
|
2012-05-16 23:57:43 +04:00
|
|
|
#include "gtk/compat.h"
|
2011-01-30 02:40:22 +03:00
|
|
|
#include "gtk/gui.h"
|
|
|
|
#include "gtk/plotters.h"
|
|
|
|
#include "gtk/treeview.h"
|
2010-10-05 23:14:46 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/utils.h"
|
2004-12-09 13:30:44 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
struct nsgtk_treeview {
|
|
|
|
GtkWindow *window;
|
|
|
|
GtkScrolledWindow *scrolled;
|
|
|
|
GtkDrawingArea *drawing_area;
|
2011-07-24 15:38:26 +04:00
|
|
|
bool mouse_pressed;
|
2010-10-05 23:14:46 +04:00
|
|
|
int mouse_pressed_x;
|
|
|
|
int mouse_pressed_y;
|
2010-12-16 23:30:10 +03:00
|
|
|
int last_x, last_y;
|
2010-10-05 23:14:46 +04:00
|
|
|
browser_mouse_state mouse_state;
|
|
|
|
struct tree *tree;
|
|
|
|
};
|
2004-12-09 13:30:44 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
const char tree_directory_icon_name[] = "directory.png";
|
|
|
|
const char tree_content_icon_name[] = "content.png";
|
2004-12-09 13:30:44 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
void nsgtk_treeview_destroy(struct nsgtk_treeview *tv)
|
|
|
|
{
|
|
|
|
tree_delete(tv->tree);
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(tv->window));
|
|
|
|
free(tv);
|
2004-12-09 13:30:44 +03:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
struct tree *nsgtk_treeview_get_tree(struct nsgtk_treeview *tv)
|
|
|
|
{
|
|
|
|
return tv->tree;
|
|
|
|
}
|
2004-12-09 13:30:44 +03:00
|
|
|
|
2010-12-14 03:18:24 +03:00
|
|
|
static void nsgtk_tree_redraw_request(int x, int y, int width, int height, void *data)
|
2010-10-05 23:14:46 +04:00
|
|
|
{
|
|
|
|
struct nsgtk_treeview *tw = data;
|
|
|
|
|
|
|
|
gtk_widget_queue_draw_area(GTK_WIDGET(tw->drawing_area),
|
|
|
|
x, y, width, height);
|
2004-12-09 13:30:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Updates the tree owner following a tree resize
|
2004-12-09 13:30:44 +03:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param tree the tree to update the owner of
|
2004-12-09 13:30:44 +03:00
|
|
|
*/
|
2010-12-14 03:18:24 +03:00
|
|
|
static void nsgtk_tree_resized(struct tree *tree, int width, int height, void *data)
|
2010-10-05 23:14:46 +04:00
|
|
|
{
|
|
|
|
struct nsgtk_treeview *tw = data;
|
|
|
|
|
|
|
|
gtk_widget_set_size_request(GTK_WIDGET(tw->drawing_area),
|
|
|
|
width, height);
|
|
|
|
return;
|
2004-12-09 13:30:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Translates a content_type to the name of a respective icon
|
2004-12-09 13:30:44 +03:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param content_type content type
|
|
|
|
* \param buffer buffer for the icon name
|
2004-12-09 13:30:44 +03:00
|
|
|
*/
|
2010-10-05 23:14:46 +04:00
|
|
|
void tree_icon_name_from_content_type(char *buffer, content_type type)
|
|
|
|
{
|
|
|
|
// TODO: design/acquire icons
|
|
|
|
switch (type) {
|
|
|
|
case CONTENT_HTML:
|
|
|
|
case CONTENT_TEXTPLAIN:
|
|
|
|
case CONTENT_CSS:
|
2011-05-07 00:40:09 +04:00
|
|
|
case CONTENT_IMAGE:
|
2010-10-05 23:14:46 +04:00
|
|
|
default:
|
|
|
|
sprintf(buffer, tree_content_icon_name);
|
|
|
|
break;
|
|
|
|
}
|
2004-12-09 13:30:44 +03:00
|
|
|
}
|
|
|
|
|
2006-07-13 21:32:11 +04:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Scrolls the tree to make an element visible
|
2006-07-13 21:32:11 +04:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param y Y coordinate of the element
|
|
|
|
* \param height height of the element
|
|
|
|
* \param data user data assigned to the tree on tree creation
|
2006-07-13 21:32:11 +04:00
|
|
|
*/
|
2010-12-14 03:18:24 +03:00
|
|
|
static void nsgtk_tree_scroll_visible(int y, int height, void *data)
|
2010-10-05 23:14:46 +04:00
|
|
|
{
|
|
|
|
int y0, y1;
|
|
|
|
gdouble page;
|
|
|
|
struct nsgtk_treeview *tw = data;
|
|
|
|
GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(tw->scrolled);
|
2006-07-13 21:32:11 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
assert(vadj);
|
|
|
|
|
|
|
|
g_object_get(vadj, "page-size", &page, NULL);
|
|
|
|
|
|
|
|
y0 = (int)(gtk_adjustment_get_value(vadj));
|
|
|
|
y1 = y0 + page;
|
|
|
|
|
|
|
|
if ((y >= y0) && (y + height <= y1))
|
|
|
|
return;
|
|
|
|
if (y + height > y1)
|
|
|
|
y0 = y0 + (y + height - y1);
|
|
|
|
if (y < y0)
|
|
|
|
y0 = y;
|
|
|
|
gtk_adjustment_set_value(vadj, y0);
|
2006-07-13 21:32:11 +04:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2006-07-13 21:32:11 +04:00
|
|
|
/**
|
2010-10-05 23:14:46 +04:00
|
|
|
* Retrieves the dimensions of the window with the tree
|
2006-07-13 21:32:11 +04:00
|
|
|
*
|
2010-10-05 23:14:46 +04:00
|
|
|
* \param data user data assigned to the tree on tree creation
|
|
|
|
* \param width will be updated to window width if not NULL
|
|
|
|
* \param height will be updated to window height if not NULL
|
2006-07-13 21:32:11 +04:00
|
|
|
*/
|
2010-12-14 03:18:24 +03:00
|
|
|
static void nsgtk_tree_get_window_dimensions(int *width, int *height, void *data)
|
2010-10-05 23:14:46 +04:00
|
|
|
{
|
|
|
|
struct nsgtk_treeview *tw = data;
|
|
|
|
GtkAdjustment *vadj;
|
|
|
|
GtkAdjustment *hadj;
|
|
|
|
gdouble page;
|
|
|
|
|
|
|
|
if (width != NULL) {
|
|
|
|
hadj = gtk_scrolled_window_get_hadjustment(tw->scrolled);
|
|
|
|
g_object_get(hadj, "page-size", &page, NULL);
|
|
|
|
*width = page;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height != NULL) {
|
|
|
|
vadj = gtk_scrolled_window_get_vadjustment(tw->scrolled);
|
|
|
|
g_object_get(vadj, "page-size", &page, NULL);
|
|
|
|
*height = page;
|
|
|
|
}
|
|
|
|
}
|
2006-07-13 21:32:11 +04:00
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
#if GTK_CHECK_VERSION(3,0,0)
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
nsgtk_tree_window_draw_event(GtkWidget *widget, cairo_t *cr, gpointer data)
|
|
|
|
{
|
|
|
|
struct tree *tree = (struct tree *)data;
|
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = true,
|
|
|
|
.background_images = true,
|
|
|
|
.plot = &nsgtk_plotters
|
|
|
|
};
|
|
|
|
double x1;
|
|
|
|
double y1;
|
|
|
|
double x2;
|
|
|
|
double y2;
|
|
|
|
|
|
|
|
current_widget = widget;
|
|
|
|
current_cr = cr;
|
|
|
|
|
|
|
|
cairo_clip_extents(cr, &x1, &y1, &x2, &y2);
|
|
|
|
|
|
|
|
tree_set_redraw(tree, true);
|
|
|
|
tree_draw(tree, 0, 0, x1, y1, x2 - x1, y2 - y1, &ctx);
|
|
|
|
|
|
|
|
current_widget = NULL;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* signal handler functions for a tree window */
|
2012-05-16 23:57:43 +04:00
|
|
|
static gboolean
|
|
|
|
nsgtk_tree_window_draw_event(GtkWidget *widget, GdkEventExpose *event, gpointer g)
|
2010-10-05 23:14:46 +04:00
|
|
|
{
|
|
|
|
struct tree *tree = (struct tree *) g;
|
2011-06-30 19:48:07 +04:00
|
|
|
struct redraw_context ctx = {
|
|
|
|
.interactive = true,
|
2011-12-24 02:39:25 +04:00
|
|
|
.background_images = true,
|
2011-06-30 19:48:07 +04:00
|
|
|
.plot = &nsgtk_plotters
|
|
|
|
};
|
2010-10-05 23:14:46 +04:00
|
|
|
int x, y, width, height;
|
|
|
|
|
|
|
|
x = event->area.x;
|
|
|
|
y = event->area.y;
|
|
|
|
width = event->area.width;
|
|
|
|
height = event->area.height;
|
|
|
|
|
|
|
|
current_widget = widget;
|
2012-05-17 20:48:20 +04:00
|
|
|
current_cr = gdk_cairo_create(nsgtk_widget_get_window(widget));
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
tree_set_redraw(tree, true);
|
2011-06-30 19:48:07 +04:00
|
|
|
tree_draw(tree, 0, 0, x, y, width, height, &ctx);
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
current_widget = NULL;
|
|
|
|
cairo_destroy(current_cr);
|
|
|
|
|
|
|
|
return FALSE;
|
2006-07-13 21:32:11 +04:00
|
|
|
}
|
2004-12-09 13:30:44 +03:00
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
#endif
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
void nsgtk_tree_window_hide(GtkWidget *widget, gpointer g)
|
|
|
|
{
|
|
|
|
struct nsgtk_treeview *tw = g;
|
|
|
|
struct tree *tree = tw->tree;
|
|
|
|
|
|
|
|
if (tree != NULL)
|
|
|
|
tree_set_redraw(tree, false);
|
2004-12-09 13:30:44 +03:00
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
gboolean nsgtk_tree_window_button_press_event(GtkWidget *widget,
|
|
|
|
GdkEventButton *event, gpointer g)
|
|
|
|
{
|
|
|
|
struct nsgtk_treeview *tw = g;
|
|
|
|
struct tree *tree = tw->tree;
|
|
|
|
|
|
|
|
gtk_widget_grab_focus(GTK_WIDGET(tw->drawing_area));
|
2011-07-24 15:38:26 +04:00
|
|
|
|
|
|
|
tw->mouse_pressed = true;
|
2010-10-05 23:14:46 +04:00
|
|
|
tw->mouse_pressed_x = event->x;
|
|
|
|
tw->mouse_pressed_y = event->y;
|
2004-12-09 13:30:44 +03:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
if (event->type == GDK_2BUTTON_PRESS)
|
|
|
|
tw->mouse_state = BROWSER_MOUSE_DOUBLE_CLICK;
|
|
|
|
|
|
|
|
switch (event->button) {
|
|
|
|
case 1: tw->mouse_state |= BROWSER_MOUSE_PRESS_1; break;
|
2013-01-16 15:54:30 +04:00
|
|
|
case 2: tw->mouse_state |= BROWSER_MOUSE_PRESS_2; break;
|
2010-10-05 23:14:46 +04:00
|
|
|
}
|
|
|
|
/* Handle the modifiers too */
|
|
|
|
if (event->state & GDK_SHIFT_MASK)
|
|
|
|
tw->mouse_state |= BROWSER_MOUSE_MOD_1;
|
|
|
|
if (event->state & GDK_CONTROL_MASK)
|
|
|
|
tw->mouse_state |= BROWSER_MOUSE_MOD_2;
|
|
|
|
if (event->state & GDK_MOD1_MASK)
|
2010-12-16 23:30:10 +03:00
|
|
|
tw->mouse_state |= BROWSER_MOUSE_MOD_3;
|
|
|
|
|
|
|
|
/* Record where we pressed, for use when determining whether to start
|
|
|
|
* a drag in motion notify events. */
|
|
|
|
tw->last_x = event->x;
|
|
|
|
tw->last_y = event->y;
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
tree_mouse_action(tree, tw->mouse_state, event->x, event->y);
|
|
|
|
|
|
|
|
return TRUE;
|
2004-12-09 13:30:44 +03:00
|
|
|
}
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
gboolean nsgtk_tree_window_button_release_event(GtkWidget *widget,
|
|
|
|
GdkEventButton *event, gpointer g)
|
|
|
|
{
|
|
|
|
bool shift = event->state & GDK_SHIFT_MASK;
|
|
|
|
bool ctrl = event->state & GDK_CONTROL_MASK;
|
|
|
|
bool alt = event->state & GDK_MOD1_MASK;
|
|
|
|
struct nsgtk_treeview *tw = (struct nsgtk_treeview *) g;
|
|
|
|
struct tree *tree = tw->tree;
|
|
|
|
|
|
|
|
/* We consider only button 1 clicks as double clicks.
|
|
|
|
* If the mouse state is PRESS then we are waiting for a release to emit
|
|
|
|
* a click event, otherwise just reset the state to nothing*/
|
|
|
|
if (tw->mouse_state & BROWSER_MOUSE_DOUBLE_CLICK) {
|
|
|
|
|
|
|
|
if (tw->mouse_state & BROWSER_MOUSE_PRESS_1)
|
2010-12-16 03:04:51 +03:00
|
|
|
tw->mouse_state ^= BROWSER_MOUSE_PRESS_1 |
|
|
|
|
BROWSER_MOUSE_CLICK_1;
|
2010-10-05 23:14:46 +04:00
|
|
|
else if (tw->mouse_state & BROWSER_MOUSE_PRESS_2)
|
|
|
|
tw->mouse_state ^= (BROWSER_MOUSE_PRESS_2 |
|
2010-12-16 03:04:51 +03:00
|
|
|
BROWSER_MOUSE_CLICK_2 |
|
2010-10-05 23:14:46 +04:00
|
|
|
BROWSER_MOUSE_DOUBLE_CLICK);
|
|
|
|
|
|
|
|
} else if (tw->mouse_state & BROWSER_MOUSE_PRESS_1)
|
|
|
|
tw->mouse_state ^=
|
|
|
|
(BROWSER_MOUSE_PRESS_1 | BROWSER_MOUSE_CLICK_1);
|
|
|
|
else if (tw->mouse_state & BROWSER_MOUSE_PRESS_2)
|
|
|
|
tw->mouse_state ^= (BROWSER_MOUSE_PRESS_2 |
|
|
|
|
BROWSER_MOUSE_CLICK_2);
|
|
|
|
|
2011-07-24 15:38:26 +04:00
|
|
|
/* Handle modifiers being removed */
|
|
|
|
if (tw->mouse_state & BROWSER_MOUSE_MOD_1 && !shift)
|
|
|
|
tw->mouse_state ^= BROWSER_MOUSE_MOD_1;
|
|
|
|
if (tw->mouse_state & BROWSER_MOUSE_MOD_2 && !ctrl)
|
|
|
|
tw->mouse_state ^= BROWSER_MOUSE_MOD_2;
|
|
|
|
if (tw->mouse_state & BROWSER_MOUSE_MOD_3 && !alt)
|
|
|
|
tw->mouse_state ^= BROWSER_MOUSE_MOD_3;
|
|
|
|
|
|
|
|
|
|
|
|
if (tw->mouse_state &
|
|
|
|
(BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2
|
|
|
|
| BROWSER_MOUSE_DOUBLE_CLICK))
|
|
|
|
tree_mouse_action(tree, tw->mouse_state,
|
|
|
|
event->x, event->y);
|
|
|
|
else
|
|
|
|
tree_drag_end(tree, tw->mouse_state,
|
|
|
|
tw->mouse_pressed_x,
|
|
|
|
tw->mouse_pressed_y,
|
|
|
|
event->x, event->y);
|
2010-10-05 23:14:46 +04:00
|
|
|
|
|
|
|
|
2011-07-24 15:38:26 +04:00
|
|
|
tw->mouse_state = 0;
|
|
|
|
tw->mouse_pressed = false;
|
2010-10-05 23:14:46 +04:00
|
|
|
|
2011-07-24 15:38:26 +04:00
|
|
|
return TRUE;
|
2010-10-05 23:14:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean nsgtk_tree_window_motion_notify_event(GtkWidget *widget,
|
2011-07-24 15:38:26 +04:00
|
|
|
GdkEventMotion *event, gpointer g)
|
2010-10-05 23:14:46 +04:00
|
|
|
{
|
|
|
|
bool shift = event->state & GDK_SHIFT_MASK;
|
|
|
|
bool ctrl = event->state & GDK_CONTROL_MASK;
|
|
|
|
bool alt = event->state & GDK_MOD1_MASK;
|
|
|
|
struct nsgtk_treeview *tw = (struct nsgtk_treeview *) g;
|
|
|
|
struct tree *tree = tw->tree;
|
2010-12-16 23:30:10 +03:00
|
|
|
|
2011-07-24 15:38:26 +04:00
|
|
|
if (tw->mouse_pressed == false)
|
|
|
|
return TRUE;
|
|
|
|
|
2010-12-16 23:30:10 +03:00
|
|
|
if ((abs(event->x - tw->last_x) < 5) &&
|
|
|
|
(abs(event->y - tw->last_y) < 5)) {
|
|
|
|
/* Mouse hasn't moved far enough from press coordinate for this
|
|
|
|
* to be considered a drag. */
|
|
|
|
return FALSE;
|
|
|
|
} else {
|
|
|
|
/* This is a drag, ensure it's always treated as such, even if
|
|
|
|
* we drag back over the press location */
|
|
|
|
tw->last_x = INT_MIN;
|
|
|
|
tw->last_y = INT_MIN;
|
|
|
|
}
|
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
/* Handle modifiers being removed */
|
|
|
|
if (tw->mouse_state & BROWSER_MOUSE_MOD_1 && !shift)
|
|
|
|
tw->mouse_state ^= BROWSER_MOUSE_MOD_1;
|
|
|
|
if (tw->mouse_state & BROWSER_MOUSE_MOD_2 && !ctrl)
|
|
|
|
tw->mouse_state ^= BROWSER_MOUSE_MOD_2;
|
|
|
|
if (tw->mouse_state & BROWSER_MOUSE_MOD_3 && !alt)
|
|
|
|
tw->mouse_state ^= BROWSER_MOUSE_MOD_3;
|
|
|
|
|
|
|
|
if (tw->mouse_state & BROWSER_MOUSE_PRESS_1) {
|
|
|
|
/* Start button 1 drag */
|
|
|
|
tree_mouse_action(tree, BROWSER_MOUSE_DRAG_1,
|
|
|
|
tw->mouse_pressed_x, tw->mouse_pressed_y);
|
|
|
|
/* Replace PRESS with HOLDING and declare drag in progress */
|
|
|
|
tw->mouse_state ^= (BROWSER_MOUSE_PRESS_1 |
|
|
|
|
BROWSER_MOUSE_HOLDING_1);
|
|
|
|
tw->mouse_state |= BROWSER_MOUSE_DRAG_ON;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else if (tw->mouse_state & BROWSER_MOUSE_PRESS_2){
|
|
|
|
/* Start button 2s drag */
|
|
|
|
tree_mouse_action(tree, BROWSER_MOUSE_DRAG_2,
|
|
|
|
tw->mouse_pressed_x, tw->mouse_pressed_y);
|
|
|
|
/* Replace PRESS with HOLDING and declare drag in progress */
|
|
|
|
tw->mouse_state ^= (BROWSER_MOUSE_PRESS_2 |
|
|
|
|
BROWSER_MOUSE_HOLDING_2);
|
|
|
|
tw->mouse_state |= BROWSER_MOUSE_DRAG_ON;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tw->mouse_state & (BROWSER_MOUSE_HOLDING_1 |
|
|
|
|
BROWSER_MOUSE_HOLDING_2))
|
|
|
|
tree_mouse_action(tree, tw->mouse_state, event->x,
|
|
|
|
event->y);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gboolean nsgtk_tree_window_keypress_event(GtkWidget *widget, GdkEventKey *event,
|
|
|
|
gpointer g)
|
|
|
|
{
|
|
|
|
struct nsgtk_treeview *tw = (struct nsgtk_treeview *) g;
|
|
|
|
struct tree *tree = tw->tree;
|
|
|
|
uint32_t nskey;
|
|
|
|
double value;
|
|
|
|
GtkAdjustment *vscroll;
|
|
|
|
GtkAdjustment *hscroll;
|
|
|
|
GtkAdjustment *scroll = NULL;
|
|
|
|
gdouble hpage, vpage;
|
|
|
|
bool edited;
|
|
|
|
|
|
|
|
nskey = gtk_gui_gdkkey_to_nskey(event);
|
|
|
|
|
|
|
|
|
|
|
|
vscroll = gtk_scrolled_window_get_vadjustment(tw->scrolled);
|
|
|
|
hscroll = gtk_scrolled_window_get_hadjustment(tw->scrolled);
|
|
|
|
g_object_get(vscroll, "page-size", &vpage, NULL);
|
|
|
|
g_object_get(hscroll, "page-size", &hpage, NULL);
|
|
|
|
|
|
|
|
|
|
|
|
edited = tree_is_edited(tree);
|
|
|
|
|
|
|
|
switch (event->keyval) {
|
2012-05-16 23:57:43 +04:00
|
|
|
case GDK_KEY(Home):
|
|
|
|
case GDK_KEY(KP_Home):
|
2010-10-05 23:14:46 +04:00
|
|
|
if (edited)
|
|
|
|
break;
|
|
|
|
scroll = vscroll;
|
2012-05-17 20:48:20 +04:00
|
|
|
value = nsgtk_adjustment_get_lower(scroll);
|
2010-10-05 23:14:46 +04:00
|
|
|
break;
|
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
case GDK_KEY(End):
|
|
|
|
case GDK_KEY(KP_End):
|
2010-10-05 23:14:46 +04:00
|
|
|
if (edited)
|
|
|
|
break;
|
|
|
|
scroll = vscroll;
|
2012-05-17 20:48:20 +04:00
|
|
|
value = nsgtk_adjustment_get_upper(scroll) - vpage;
|
|
|
|
if (value < nsgtk_adjustment_get_lower(scroll))
|
|
|
|
value = nsgtk_adjustment_get_lower(scroll);
|
2010-10-05 23:14:46 +04:00
|
|
|
break;
|
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
case GDK_KEY(Left):
|
|
|
|
case GDK_KEY(KP_Left):
|
2010-10-05 23:14:46 +04:00
|
|
|
if (edited)
|
|
|
|
break;
|
|
|
|
scroll = hscroll;
|
|
|
|
value = gtk_adjustment_get_value(scroll) -
|
2012-05-17 20:48:20 +04:00
|
|
|
nsgtk_adjustment_get_step_increment(scroll);
|
|
|
|
if (value < nsgtk_adjustment_get_lower(scroll))
|
|
|
|
value = nsgtk_adjustment_get_lower(scroll);
|
2010-10-05 23:14:46 +04:00
|
|
|
break;
|
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
case GDK_KEY(Up):
|
|
|
|
case GDK_KEY(KP_Up):
|
2010-10-05 23:14:46 +04:00
|
|
|
scroll = vscroll;
|
|
|
|
value = gtk_adjustment_get_value(scroll) -
|
2012-05-17 20:48:20 +04:00
|
|
|
nsgtk_adjustment_get_step_increment(scroll);
|
|
|
|
if (value < nsgtk_adjustment_get_lower(scroll))
|
|
|
|
value = nsgtk_adjustment_get_lower(scroll);
|
2010-10-05 23:14:46 +04:00
|
|
|
break;
|
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
case GDK_KEY(Right):
|
|
|
|
case GDK_KEY(KP_Right):
|
2010-10-05 23:14:46 +04:00
|
|
|
if (edited)
|
|
|
|
break;
|
|
|
|
scroll = hscroll;
|
|
|
|
value = gtk_adjustment_get_value(scroll) +
|
2012-05-17 20:48:20 +04:00
|
|
|
nsgtk_adjustment_get_step_increment(scroll);
|
|
|
|
if (value > nsgtk_adjustment_get_upper(scroll) - hpage)
|
|
|
|
value = nsgtk_adjustment_get_upper(scroll) - hpage;
|
2010-10-05 23:14:46 +04:00
|
|
|
break;
|
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
case GDK_KEY(Down):
|
|
|
|
case GDK_KEY(KP_Down):
|
2010-10-05 23:14:46 +04:00
|
|
|
scroll = vscroll;
|
|
|
|
value = gtk_adjustment_get_value(scroll) +
|
2012-05-17 20:48:20 +04:00
|
|
|
nsgtk_adjustment_get_step_increment(scroll);
|
|
|
|
if (value > nsgtk_adjustment_get_upper(scroll) - vpage)
|
|
|
|
value = nsgtk_adjustment_get_upper(scroll) - vpage;
|
2010-10-05 23:14:46 +04:00
|
|
|
break;
|
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
case GDK_KEY(Page_Up):
|
|
|
|
case GDK_KEY(KP_Page_Up):
|
2010-10-05 23:14:46 +04:00
|
|
|
scroll = vscroll;
|
|
|
|
value = gtk_adjustment_get_value(scroll) -
|
2012-05-17 20:48:20 +04:00
|
|
|
nsgtk_adjustment_get_page_increment(scroll);
|
2012-05-16 23:57:43 +04:00
|
|
|
|
2012-05-17 20:48:20 +04:00
|
|
|
if (value < nsgtk_adjustment_get_lower(scroll))
|
|
|
|
value = nsgtk_adjustment_get_lower(scroll);
|
2012-05-16 23:57:43 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
break;
|
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
case GDK_KEY(Page_Down):
|
|
|
|
case GDK_KEY(KP_Page_Down):
|
2010-10-05 23:14:46 +04:00
|
|
|
scroll = vscroll;
|
|
|
|
value = gtk_adjustment_get_value(scroll) +
|
2012-05-17 20:48:20 +04:00
|
|
|
nsgtk_adjustment_get_page_increment(scroll);
|
2012-05-16 23:57:43 +04:00
|
|
|
|
2012-05-17 20:48:20 +04:00
|
|
|
if (value > nsgtk_adjustment_get_upper(scroll) - vpage)
|
|
|
|
value = nsgtk_adjustment_get_upper(scroll) - vpage;
|
2010-10-05 23:14:46 +04:00
|
|
|
break;
|
2012-05-16 23:57:43 +04:00
|
|
|
|
2010-10-05 23:14:46 +04:00
|
|
|
default:
|
|
|
|
tree_keypress(tree, nskey);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (scroll != NULL)
|
|
|
|
gtk_adjustment_set_value(scroll, value);
|
|
|
|
|
|
|
|
tree_keypress(tree, nskey);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2010-12-14 03:18:24 +03:00
|
|
|
|
|
|
|
static const struct treeview_table nsgtk_tree_callbacks = {
|
|
|
|
.redraw_request = nsgtk_tree_redraw_request,
|
|
|
|
.resized = nsgtk_tree_resized,
|
|
|
|
.scroll_visible = nsgtk_tree_scroll_visible,
|
|
|
|
.get_window_dimensions = nsgtk_tree_get_window_dimensions
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nsgtk_treeview *nsgtk_treeview_create(unsigned int flags,
|
|
|
|
GtkWindow *window, GtkScrolledWindow *scrolled,
|
|
|
|
GtkDrawingArea *drawing_area)
|
|
|
|
{
|
|
|
|
struct nsgtk_treeview *tv;
|
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
assert(drawing_area != NULL);
|
|
|
|
|
2010-12-14 03:18:24 +03:00
|
|
|
tv = malloc(sizeof(struct nsgtk_treeview));
|
|
|
|
if (tv == NULL) {
|
|
|
|
LOG(("malloc failed"));
|
|
|
|
warn_user("NoMemory", 0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tv->window = window;
|
|
|
|
tv->scrolled = scrolled;
|
|
|
|
tv->drawing_area = drawing_area;
|
|
|
|
tv->tree = tree_create(flags, &nsgtk_tree_callbacks, tv);
|
|
|
|
tv->mouse_state = 0;
|
2011-07-24 15:38:26 +04:00
|
|
|
tv->mouse_pressed = false;
|
2010-12-14 03:18:24 +03:00
|
|
|
|
2012-05-16 23:57:43 +04:00
|
|
|
nsgtk_widget_override_background_color(GTK_WIDGET(drawing_area),
|
|
|
|
GTK_STATE_NORMAL,
|
|
|
|
0, 0xffff, 0xffff, 0xffff);
|
|
|
|
|
|
|
|
nsgtk_connect_draw_event(GTK_WIDGET(drawing_area), G_CALLBACK(nsgtk_tree_window_draw_event), tv->tree);
|
2010-12-14 03:18:24 +03:00
|
|
|
|
|
|
|
#define CONNECT(obj, sig, callback, ptr) \
|
|
|
|
g_signal_connect(G_OBJECT(obj), (sig), G_CALLBACK(callback), (ptr))
|
|
|
|
CONNECT(drawing_area, "button_press_event",
|
|
|
|
nsgtk_tree_window_button_press_event,
|
|
|
|
tv);
|
|
|
|
CONNECT(drawing_area, "button_release_event",
|
|
|
|
nsgtk_tree_window_button_release_event,
|
|
|
|
tv);
|
|
|
|
CONNECT(drawing_area, "motion_notify_event",
|
|
|
|
nsgtk_tree_window_motion_notify_event,
|
|
|
|
tv);
|
|
|
|
CONNECT(drawing_area, "key_press_event",
|
|
|
|
nsgtk_tree_window_keypress_event,
|
|
|
|
tv);
|
|
|
|
return tv;
|
|
|
|
}
|