drag'n'drop sample application

2011-09-07 Thread John Emmas
Using gtk-win32, I'm porting a GTK+ application (originally written for Linux 
and OS-X) to the Windows platform and have been pleasantly surprised at how 
well it's all worked.  However, part of the app's functionality includes a 
drag'n'drop feature to move items from one part of the GUI to another part.  
This feature works fine on the other platforms but doesn't work in Windows.  I 
see a drag icon when moving the item but when I let go of it, it remains in its 
original position instead of moving to the new position.

I've established that the individual elements of the drag'n'drop operation seem 
to be working.  e.g. if I grab an item and drag it, all the various 
'drag_source()' functions get called, just like they do on the other platforms. 
 Likewise, if I drag an item from outside the app, I can successfully drop it 
onto a drop destination within the GUI.  So both parts of the operation work 
individually but they don't seem to work with each other.  My theory is that 
when I drag an internal item and let go of it, something must be preventing it 
from realising it's above a valid drop target.

Unfortunately, the app itself is very large and complicated so it's pretty 
difficult to figure out what's supposed to be happening.  Does anyone know of a 
handy example that I could use to study GTK+ drag'n'drop at a simpler level 
(with source code, obviously) ?

John
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Can g_file_monitor_file () report events from before it was created?

2011-09-07 Thread Peter Clifton
On Wed, 2011-09-07 at 03:18 +0100, Peter Clifton wrote:
 --=-RBhkyZn6RRXPH6Tyg7fR
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: quoted-printable
 
 On Tue, 2011-09-06 at 01:42 +0100, Peter Clifton wrote:
  --=3D-1PQvPQuhjpa09GLvybFI
  Content-Type: text/plain; charset=3DUTF-8
  Content-Transfer-Encoding: quoted-printable
 =20
  Hi,
 =20
  I'm working on some code to monitor for file changes in our application,
  and ran into a bit of a problem today with the Save-As case.
 =20
  The order of operations is something like:
 =20
  1. File monitor exists on the document file which was loaded last
  2. User hits File-Save as.. (and enters a filename)
 
 ^__ Just as an interesting (and probably critical note), I don't see
 this bug if I hard-code a Save-as filename.
 
 I only get unexpected file-monitor events if I use a
 gtk_file_chooser_dialog to select the new filename to save into.

Futhermore - it only breaks if the dialog is set to an initial location
with something like:

gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), *path);

(Or left to pick the current working directory, where the file is).

If I set the current folder to /, e.g.:

  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), /);

Then navigate to the directory I'm going to save into from within the
GUI, the problem does not occur.

-- 
Peter Clifton

Electrical Engineering Division,
Engineering Department,
University of Cambridge,
9, JJ Thomson Avenue,
Cambridge
CB3 0FA

Tel: +44 (0)7729 980173 - (No signal in the lab!)
Tel: +44 (0)1223 748328 - (Shared lab phone, ask for me)
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: drag'n'drop sample application

2011-09-07 Thread Allin Cottrell

On Wed, 7 Sep 2011, John Emmas wrote:

Using gtk-win32, I'm porting a GTK+ application (originally 
written for Linux and OS-X) to the Windows platform and have 
been pleasantly surprised at how well it's all worked. 
However, part of the app's functionality includes a 
drag'n'drop feature to move items from one part of the GUI 
to another part. [not working on Windows]


Unfortunately, the app itself is very large and complicated 
so it's pretty difficult to figure out what's supposed to be 
happening.  Does anyone know of a handy example that I could 
use to study GTK+ drag'n'drop at a simpler level (with 
source code, obviously) ?


I'm attaching a little test program that I once used for 
diagnosing GTK dnd problems on Windows.


Allin Cottrell

/*

  Test program for drag and drop with two sorts of targets available.

  Allin Cottrell (cottr...@wfu.edu), March 2003.

*/

#include gtk/gtk.h

enum {
DRAG_FILENAME,
DRAG_POINTER
};

GtkTargetEntry test_drag_targets[] = {
{ text/uri-list, 0, DRAG_FILENAME },
{ pointer, GTK_TARGET_SAME_APP, DRAG_POINTER }
};

void app_exit (GtkWidget *w, gpointer p)
{
gtk_main_quit();
}

static void msgbox (const char *msg)
{
GtkWidget *dialog;

dialog = gtk_message_dialog_new (NULL, 
 GTK_DIALOG_DESTROY_WITH_PARENT,
 GTK_MESSAGE_INFO,
 GTK_BUTTONS_CLOSE,
 msg);
gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_destroy(dialog);
}

static void 
get_drag_pointer (GtkWidget *w, GdkDragContext *context,
  GtkSelectionData *sel, guint info, guint t,
  gpointer ptr)
{
gtk_selection_data_set(sel, GDK_SELECTION_TYPE_INTEGER, 8, 
   (const guchar *) ptr, sizeof ptr);
}

static void 
pointer_window_drag_connect (GtkWidget *widget, gpointer ptr)
{
gtk_drag_source_set(widget, GDK_BUTTON1_MASK,
test_drag_targets[DRAG_POINTER],
1, GDK_ACTION_COPY);

g_signal_connect(G_OBJECT(widget), drag_data_get,
 G_CALLBACK(get_drag_pointer),
 ptr);
}

static void pointer_window (void)
 /* mock-up of a window which supplies a pointer to drop */
{
GtkWidget *pw, *plabel;

pw = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_print(Pointer window is at %p\n, (void *) pw);

plabel = gtk_label_new(\n Pointer window \n);
gtk_container_add(GTK_CONTAINER(pw), plabel);
pointer_window_drag_connect(pw, (gpointer) pw);

gtk_widget_show_all(pw);
}

static void  
handle_drag_data (GtkWidget *widget,
  GdkDragContext *context,
  gint x, gint y,
  GtkSelectionData *data,
  guint info, guint time,
  gpointer p)
{
gchar *input = NULL;

if (info == DRAG_FILENAME) {
input = g_strdup_printf(Got uri-list: %s, data-data);
} 
else if (info == DRAG_POINTER) {
input = g_strdup_printf(Got pointer (address of pointer window):\n
%p, *(void **) data-data);
} 
else {
input = g_strdup(Got unknown drag input);
}

msgbox(input);
g_free(input);
}

static void 
main_window_drag_connect (GtkWidget *widget)
{
gtk_drag_dest_set (widget,
   GTK_DEST_DEFAULT_ALL,
   test_drag_targets, 2,
   GDK_ACTION_COPY);

g_signal_connect (G_OBJECT(widget), drag_data_received,
  G_CALLBACK(handle_drag_data),
  NULL);
}

int main (int argc, char *argv[])
{
GtkWidget *w, *label;

gtk_init(argc, argv);

w = gtk_window_new(GTK_WINDOW_TOPLEVEL);

g_signal_connect(G_OBJECT(w), destroy,
 G_CALLBACK(app_exit), NULL);

label = gtk_label_new(\n Drag onto me, from a file icon \n
   or from the pointer window. \n);
gtk_container_add(GTK_CONTAINER(w), label);
main_window_drag_connect(label);

gtk_widget_show_all(w);

pointer_window();

gtk_main();

return 0;
}
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Open a file in a GTK application (over network)

2011-09-07 Thread Michal Suchanek
Obviously, all file choosers are broken in one way or another.

No way to open a file in GTK yet. Maybe it will be possible in GTK4 or
if you roll your own widget :-S
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


gtk_combo_box_new_with_model_and_entry with gtk_cell_layout_set_cell_data_func

2011-09-07 Thread Pierre-Louis Bonicoli
Hi !

I try to use gtk_cell_layout_set_cell_data_func with a combobox which
has an entry.
gtk_cell_layout_set_cell_data_func method allows to map an item in my
model with an entry in the combobox. How to map an index of an entry
with an item in the model ? It seems that using
gtk_combo_box_set_entry_text_column is the right way to do that but my
model doesn't contain a G_TYPE_STRING columns (entries in the combobox
are dynamically computed with a GtkCellLayoutDataFunc which modify
text property of the CellRenderer).

So when an entry in the combobox is clicked, entry doesn't become
selected and a warning message is displayed:
GLib-GObject-WARNING **: unable to set property `text' of type
`gchararray' from value of type `glong'

Here is complete test code (available here too:
http://pastebin.drouet.eu/pastebin.php?show=83 )

#include stdlib.h
#include gtk/gtk.h
 /*
Build with the following Makefile
all: test

test: test.c
gcc `pkg-config --libs --cflags gtk+-2.0` test.c -o test
*/
 typedef struct _wrapper {
char * text;
} Wrapper;
 static void
wrapper2text(GtkCellLayout *cell_layout, GtkCellRenderer *cell,
GtkTreeModel *model, GtkTreeIter *iter, gpointer data) {
Wrapper * w;
gtk_tree_model_get (model, iter, 0, w, -1);
g_object_set (cell, text, w-text, NULL);
}
 static void
add_text(GtkListStore *model, char *text) {
GtkTreeIter new_row;
Wrapper * w;
 w = g_new0(Wrapper, 1);
w-text = g_strdup(text);
gtk_list_store_append(model, new_row);
gtk_list_store_set(model, new_row, 0, w, -1);
}
 int main(int argc, char **argv)
{
GtkWidget * window = NULL;
GtkListStore * store;
GtkListStore * model;
GType *columns;
GtkWidget * combo;
GtkCellRenderer *renderer;;
gtk_init(argc, argv);
  columns = g_new0 (GType, 1);
columns[0] = G_TYPE_POINTER;
 model = gtk_list_store_newv(1, columns);
add_text(model, test1);
add_text(model, test2);
add_text(model, test3);
 g_free(columns);
combo = gtk_combo_box_new_with_model_and_entry(GTK_TREE_MODEL(model));
renderer = gtk_cell_renderer_text_new();
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(combo), renderer, NULL);
gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(combo), renderer,
wrapper2text, NULL, NULL);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_add(GTK_CONTAINER(window), combo);
gtk_widget_show_all(window);
gtk_main();
return EXIT_SUCCESS;
}



Is there a way to avoid calling gtk_combo_box_set_entry_text_column
(which implies having one useless column of type G_TYPE_STRING in the
model) ?


Using
gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(combo), renderer,
wrapper2text, combo, NULL);
and
g_object_set (gtk_bin_get_child(GTK_COMBO_BOX(data)), text, w-text,
NULL);
in wrapper2text function works but the warning remains.

Thanks,

Pierre-Louis
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list