Doubt about button_press_event and drag and drop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



To GTK Team,

 

    I am new into GTK programmer language and I´ve been develop one application that needs treeview to operate a SQL data base to linux and windows.

    I developed one interface with glade_3 to use gtk 2.12 for windows and mingw c compiler with a treeview that will control database. Inside treeview I need to use some GDKEVENTS that they are:

    Button press, button release,  button release (double click), Button release (right click) to call popup menu, and drag and drop operation to organize the structure.

 

    I´ve been worded hard this 2 last weeks to understand why drag and drop doesn´t work when I define button_press_event or button_release_event.

 

    I made some tests and I see when I don´t  define any button press or release  event drag and drop work fine but when I define them, drag and drop doesn´t  work.

    I read some tutorials that I looked for into internet and the documentation of GTK, GDK, GLIB and see something about drag and drop that explain drag starts with button_press and drop ends with button releases but my doubt go on yet. Main question is:

 

    Is it possible to use button_press ou release events with drag and drop with high level api?

 

    If not,  do I need to detect this events separately? And manually (low level api) starts drag and drop with combination between button_press_event and motion_event?

 

    I will appreciate yours help.

   

    Ubirajara Marques da Cruz

    

    Email: biracruz@xxxxxxxxxxxx

 

To make glade interface i used a window with a treeview only.

 

Program is below

 

#include <gtk/gtk.h>

#include <gdk/gdk.h>

#include <glib.h>

#include <glade/glade.h>

#include <stdio.h>

 

GladeXML *xml;

GtkWidget *varwid;

GtkCellRenderer *renderer;

GtkTreeModel  *model;

GtkTreeStore *store;

GtkTreeIter iter, child, iaux;

GtkTreeViewColumn *coluna;

GtkTreePath *path;

gint i;

 

enum

{

COL_NAME = 0,

COL_AGE,

COL_TESTE,

NUM_COLS,

COLOR_COLUMN

};

void sair(void)

{

      gtk_main_quit();

}

static void messbox(gchar *mensagem)

{

 GtkWidget *dialogo;

 if (mensagem=="")

    mensagem="VAZIO";

 varwid==glade_xml_get_widget(xml,"window");

 dialogo = gtk_message_dialog_new (GTK_WINDOW (varwid),

                           GTK_DIALOG_MODAL /*| GTK_DIALOG_DESTROY_WITH_PARENT*/,

                           GTK_MESSAGE_INFO,

                           GTK_BUTTONS_OK,

                           mensagem);

  gtk_dialog_run (GTK_DIALOG (dialogo));

  gtk_widget_destroy (dialogo);

};

void tv1_release(GtkWidget *tv, GdkEventButton *evento, gpointer usdata)

      {

      if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(tv),evento->x,evento->y,&path,NULL,NULL,NULL))

            gtk_tree_view_set_cursor(GTK_TREE_VIEW(tv),path,coluna,0);

      else

            messbox("path doesn't exist");

      if(evento->button==3 && evento->type==GDK_BUTTON_RELEASE)

            {

            g_print("Left Click!\n");

            }

      if (evento->button==1 && evento->type==GDK_BUTTON_RELEASE)

            {

            g_print("Right Click!\n");

            }

      };

int main (int argc, char **argv)

{

      gtk_init(&argc,&argv);

      glade_init();

      xml = glade_xml_new("treeview.glade","window",NULL);

      varwid=glade_xml_get_widget(xml,"view");

      renderer = gtk_cell_renderer_text_new();

      varwid=glade_xml_get_widget(xml,"view");

      coluna = gtk_tree_view_column_new_with_attributes("Linha",renderer,"text",COL_NAME,"editable",

                  TRUE,"editable-set",TRUE, NULL);

      gtk_tree_view_append_column(GTK_TREE_VIEW(varwid),coluna);

      coluna = gtk_tree_view_column_new_with_attributes("Idade",renderer,"text",COL_AGE, NULL);

      gtk_tree_view_append_column(GTK_TREE_VIEW(varwid),coluna);

      coluna = gtk_tree_view_column_new_with_attributes("Teste",renderer,"text",COL_TESTE,NULL);

      gtk_tree_view_append_column(GTK_TREE_VIEW(varwid),coluna);

      gtk_tree_view_set_grid_lines        (GTK_TREE_VIEW (varwid),

            GTK_TREE_VIEW_GRID_LINES_BOTH);

    store = gtk_tree_store_new (NUM_COLS ,G_TYPE_STRING,G_TYPE_ULONG,G_TYPE_STRING);

    model=GTK_TREE_MODEL(store);

    gtk_tree_view_set_model(GTK_TREE_VIEW(varwid), model);

    gchar *a,buf[5],*pth;

    a="1";

    gdouble c[15];

    /*

     * To fill tree view i assembly an array that show parents and child to understant

     * tree. if you see 0 is first level 1 is second level and so on.

     */

    c[0]=0 ;c[1]=1 ;c[2]=2 ;c[3]=3 ;c[4]=3 ;c[5]=2 ;c[6]=2 ;c[7]=3 ;c[8]=3 ;c[9]=4 ;

    c[10]=0 ;c[11]=1 ;c[12]=0 ;c[13]=0 ;c[14]=1 ;c[15]=0 ;

    gtk_tree_store_append(store,&iter,NULL);

    a=g_ascii_dtostr(buf,2,c[0]);

    pth=gtk_tree_model_get_string_from_iter(model,&iter);

    gtk_tree_store_set(store,&iter,COL_NAME,a,COL_AGE,0,COL_TESTE,pth,-1);

    iaux=iter;

    gint i,k;

    for (i=1;i<16;i++)

    {

    if (c[i]-c[i-1]>0) //son

            {

      gtk_tree_store_append(store,&child,&iaux);

      a=g_ascii_dtostr(buf,2,c[i]);

      pth=gtk_tree_model_get_string_from_iter(model,&child);

      gtk_tree_store_set(store,&child,COL_NAME,a,COL_AGE,i,COL_TESTE,pth,-1);

      iaux=child;

            }

    else

            {

      if (c[i]-c[i-1]==0) //brother

                  {

            if (gtk_tree_model_iter_parent(model,&iaux,&child)) //brother with father

                        {

                  gtk_tree_store_append(store,&child,&iaux);

                  a=g_ascii_dtostr(buf,2,c[i]);

                  pth=gtk_tree_model_get_string_from_iter(model,&child);

                  gtk_tree_store_set(store,&child,COL_NAME,a,COL_AGE,i,COL_TESTE,pth,-1);

                  iaux=child;

                        }

            else

                        {     //brother without father

                  iaux=child;

                  if(gtk_tree_store_iter_depth(store,&iaux)==0)

                             {

                        gtk_tree_store_append(store,&child,NULL);

                        a=g_ascii_dtostr(buf,2,c[i]);

                        pth=gtk_tree_model_get_string_from_iter(model,&child);

                        gtk_tree_store_set(store,&child,COL_NAME,a,COL_AGE,i,COL_TESTE,pth,-1);

                        iaux=child;

                             }

                        }

                  }

      else

                  {     //Level grand father

            k=c[i-1]-c[i];

            while (k>0)

                        {

                  if (gtk_tree_model_iter_parent(model,&iaux,&child)==1)

                             {

                        k=k-1;

                        child=iaux;

                             }

                  else

                        iaux=child;

                        } //end while

            if (gtk_tree_model_iter_parent(model,&iaux,&child)==1) //brother with father

                  {

                  gtk_tree_store_append(store,&child,&iaux);

                a=g_ascii_dtostr(buf,2,c[i]);

                pth=gtk_tree_model_get_string_from_iter(model,&child);

                gtk_tree_store_set(store,&child,COL_NAME,a,COL_AGE,i,COL_TESTE,pth,-1);

                iaux=child;

                  }

            else

                        {     //brother without father

                  iaux=child;

                if(gtk_tree_store_iter_depth(store,&iaux)==0)

                  {

                  gtk_tree_store_append(store,&child,NULL);

                  a=g_ascii_dtostr(buf,2,c[i]);

                  pth=gtk_tree_model_get_string_from_iter(model,&child);

                  gtk_tree_store_set(store,&child,COL_NAME,a,COL_AGE,i,COL_TESTE,pth,-1);

                  iaux=child;

                  }

                  }

                  } //end 2nd if

            }//end 1st if

 

    }// end for

    g_object_unref(model);

      glade_xml_signal_connect(xml,"tv1_release",G_CALLBACK(tv1_release));

      varwid=glade_xml_get_widget(xml,"window");

      gtk_widget_show_all (varwid);

      gtk_main();

    return 0;

}

 

As informacoes contidas nesta mensagem e nos arquivos anexados sao para uso
exclusivo do destinatario aqui indicado e podem conter assuntos comerciais, de 
propriedade intelectual ou outras informacoes confidenciais, protegidas pelas leis 
aplicaveis.
Caso nao seja o destinatario correto, por favor, notifique o remetente 
imediatamente e elimine esta mensagem, uma vez que qualquer revisao, leitura, 
copia e, ou divulgacao do conteudo desta mensagem sao estritamente proibidas 
e nao autorizadas.
Obrigado por sua cooperacao.
The information contained in this message and the attached files are restricted to 
the addressee, and may contain commercial information, copyright, or other 
confidential information protected by law.
If you are not the recipient, please notify the sender immediately and delete it 
from you system, since any change, reading, copy and, or dissemination of this 
e-mail is strictly prohibited by and not authorized.
Thank you.
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux