Skip to content

Commit

Permalink
Added currently disabled drag reordering of notebook tabs
Browse files Browse the repository at this point in the history
git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@448 ea778897-0a13-0410-b9d1-a72fbfd435f5
  • Loading branch information
ntrel committed Jun 16, 2006
1 parent 26d1a9c commit 14e6966
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 0 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Expand Up @@ -14,6 +14,7 @@ bin_PROGRAMS = geany

geany_SOURCES = \
main.c geany.h \
notebook.c notebook.h \
keybindings.c keybindings.h \
templates.c templates.h \
treeviews.c treeviews.h \
Expand Down
2 changes: 2 additions & 0 deletions src/main.c
Expand Up @@ -46,6 +46,7 @@
#include "templates.h"
#include "encodings.h"
#include "treeviews.h"
#include "notebook.h"
#ifdef HAVE_VTE
# include "vte.h"
#endif
Expand Down Expand Up @@ -478,6 +479,7 @@ gint main(gint argc, gchar **argv)
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();
Expand Down
148 changes: 148 additions & 0 deletions src/notebook.c
@@ -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;
}
30 changes: 30 additions & 0 deletions src/notebook.h
@@ -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

0 comments on commit 14e6966

Please sign in to comment.