Revision: 448 Author: ntrel Date: 2006-06-16 04:17:52 -0700 (Fri, 16 Jun 2006) ViewCVS: http://svn.sourceforge.net/geany/?rev=448&view=rev
Log Message: ----------- Added currently disabled drag reordering of notebook tabs
Modified Paths: -------------- trunk/ChangeLog trunk/src/Makefile.am trunk/src/main.c
Added Paths: ----------- trunk/src/notebook.c trunk/src/notebook.h Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-06-15 17:31:54 UTC (rev 447) +++ trunk/ChangeLog 2006-06-16 11:17:52 UTC (rev 448) @@ -1,3 +1,9 @@ +2006-06-16 Nick Treleaven nick.treleaven@btinternet.com + + * src/notebook.c, src/notebook.h, src/main.c, src/Makefile.am: + Added currently disabled drag reordering of notebook tabs. + + 2006-06-15 Enrico Troeger enrico.troeger@uvena.de
* src/utils.c: Fixed a bug at opening files when clicking on compiler
Modified: trunk/src/Makefile.am =================================================================== --- trunk/src/Makefile.am 2006-06-15 17:31:54 UTC (rev 447) +++ trunk/src/Makefile.am 2006-06-16 11:17:52 UTC (rev 448) @@ -14,6 +14,7 @@
geany_SOURCES = \ main.c geany.h \ + notebook.c notebook.h \ keybindings.c keybindings.h \ templates.c templates.h \ treeviews.c treeviews.h \
Modified: trunk/src/main.c =================================================================== --- trunk/src/main.c 2006-06-15 17:31:54 UTC (rev 447) +++ trunk/src/main.c 2006-06-16 11:17:52 UTC (rev 448) @@ -46,6 +46,7 @@ #include "templates.h" #include "encodings.h" #include "treeviews.h" +#include "notebook.h" #ifdef HAVE_VTE # include "vte.h" #endif @@ -478,6 +479,7 @@ gtk_window_set_default_size(GTK_WINDOW(app->window), GEANY_WINDOW_DEFAULT_WIDTH, GEANY_WINDOW_DEFAULT_HEIGHT); configuration_load(); keybindings_init(); + notebook_init(); templates_init(); encodings_init(); document_init_doclist();
Added: trunk/src/notebook.c =================================================================== --- trunk/src/notebook.c (rev 0) +++ trunk/src/notebook.c 2006-06-16 11:17:52 UTC (rev 448) @@ -0,0 +1,148 @@ +/* + * notebook.c - this file is part of Geany, a fast and lightweight IDE + * + * Copyright 2006 Nick Treleaven nick.treleaven@btinternet.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 of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + */ + +#include "geany.h" +#include "notebook.h" + +#define GEANY_DND_NOTEBOOK_TAB_TYPE "geany_dnd_notebook_tab" + +static const GtkTargetEntry drag_targets[] = +{ + {GEANY_DND_NOTEBOOK_TAB_TYPE, GTK_TARGET_SAME_APP | GTK_TARGET_SAME_WIDGET, 0} +}; + + +gboolean +notebook_drag_motion_cb(GtkWidget *notebook, GdkDragContext *dc, + gint x, gint y, guint time, gpointer user_data); + + +void notebook_init() +{ + GtkWidget *notebook = app->notebook; + + g_object_set(G_OBJECT(notebook), "can-focus", FALSE, NULL); + + /* There is a bug with drag reordering notebook tabs. + * Clicking on a notebook tab, then making a selection in the + * Scintilla widget will cause a strange selection bug. + * It seems there is a conflict; the drag cursor is shown, + * and the selection is blocked; however, when releasing the + * mouse button, the selection continues. + * Maybe a bug in Scintilla 1.68? - ntrel */ +#ifndef TEST_TAB_DND + return; +#endif + + // Set up drag movement callback + g_signal_connect(G_OBJECT(notebook), "drag-motion", + G_CALLBACK(notebook_drag_motion_cb), NULL); + + // set up drag motion for moving notebook pages + gtk_drag_source_set(notebook, GDK_BUTTON1_MASK, + drag_targets, G_N_ELEMENTS(drag_targets), GDK_ACTION_MOVE); + gtk_drag_dest_set(notebook, GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, + drag_targets, G_N_ELEMENTS(drag_targets), GDK_ACTION_MOVE); +} + + +gboolean +notebook_drag_motion_cb(GtkWidget *widget, GdkDragContext *dc, + gint x, gint y, guint time, gpointer user_data) +{ + GtkNotebook *notebook = GTK_NOTEBOOK(widget); + static gint oldx, oldy; // for determining direction of mouse drag + gint ndest = notebook_find_tab_num_at_pos(notebook, x, y); + gint ncurr = gtk_notebook_get_current_page(notebook); + + if (ndest >= 0) + if (ndest != ncurr) + { + gboolean ok = FALSE; + // prevent oscillation between non-homogeneous sized tabs + switch(gtk_notebook_get_tab_pos(notebook)) + { + case GTK_POS_LEFT: + case GTK_POS_RIGHT: + ok = ((ndest > ncurr) && (y > oldy)) || ((ndest < ncurr) && (y < oldy)); + break; + + case GTK_POS_TOP: + case GTK_POS_BOTTOM: + ok = ((ndest > ncurr) && (x > oldx)) || ((ndest < ncurr) && (x < oldx)); + break; + } + + if (ok) gtk_notebook_reorder_child(notebook, + gtk_notebook_get_nth_page(notebook, ncurr), ndest); + } + + oldx = x; oldy = y; + return FALSE; +} + + +/* x,y are co-ordinates local to the notebook, not including border padding + * adapted from Epiphany absolute version in ephy-notebook.c, thanks + * notebook tab label widgets must not be NULL */ +gint notebook_find_tab_num_at_pos(GtkNotebook *notebook, gint x, gint y) +{ + GtkPositionType tab_pos; + int page_num = 0; + GtkWidget *page; + + // deal with less than 2 pages + switch(gtk_notebook_get_n_pages(notebook)) + {case 0: return -1; case 1: return 0;} + + tab_pos = gtk_notebook_get_tab_pos(notebook); //which edge + + while ((page = gtk_notebook_get_nth_page(notebook, page_num))) + { + gint max_x, max_y; + GtkWidget *tab = gtk_notebook_get_tab_label(notebook, page); + + g_return_val_if_fail(tab != NULL, -1); + + if (!GTK_WIDGET_MAPPED(GTK_WIDGET(tab))) + { // skip hidden tabs, e.g. tabs scrolled out of view + page_num++; + continue; + } + + // subtract notebook pos to remove possible border padding + max_x = tab->allocation.x + tab->allocation.width - + GTK_WIDGET(notebook)->allocation.x; + max_y = tab->allocation.y + tab->allocation.height - + GTK_WIDGET(notebook)->allocation.y; + + if (((tab_pos == GTK_POS_TOP) + || (tab_pos == GTK_POS_BOTTOM)) + &&(x<=max_x)) return page_num; + else if (((tab_pos == GTK_POS_LEFT) + || (tab_pos == GTK_POS_RIGHT)) + && (y<=max_y)) return page_num; + + page_num++; + } + return -1; +}
Property changes on: trunk/src/notebook.c ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native
Added: trunk/src/notebook.h =================================================================== --- trunk/src/notebook.h (rev 0) +++ trunk/src/notebook.h 2006-06-16 11:17:52 UTC (rev 448) @@ -0,0 +1,30 @@ +/* + * notebook.h - this file is part of Geany, a fast and lightweight IDE + * + * Copyright 2006 Nick Treleaven nick.treleaven@btinternet.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 of the License, 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + */ + +#ifndef GEANY_NOTEBOOK_H +#define GEANY_NOTEBOOK_H 1 + +void notebook_init(); + +gint notebook_find_tab_num_at_pos(GtkNotebook *notebook, gint x, gint y); + +#endif
Property changes on: trunk/src/notebook.h ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.