Ignore:
Timestamp:
Feb 11, 2007, 4:52:34 PM (19 years ago)
Author:
cinc
Message:

Started drag and drop implementation. Some dox additions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/desktop/class_c/wpfolderwindow.c

    r224 r237  
    166166}
    167167
     168static gboolean fldrWindowHandleDragDrop(GtkWidget * widget, GdkDragContext* dragContext, gint x, gint y,
     169                         guint t, gpointer ptrUserData)
     170{
     171  DosBeep(2500, 10);
     172  DosBeep(500, 10);
     173  DosBeep(2500, 10);
     174  g_message("%s", __FUNCTION__);
     175  return FALSE;
     176}
     177
     178#if 0
     179static void fldrDragLeave(GtkWidget * widget, GdkDragContext* dragContext,
     180                          guint t, gpointer ptrUserData)
     181{
     182  GdkPixmap *pixMapDrag;
     183 
     184  gdk_pixbuf_render_pixmap_and_mask(pixBufStop, &pixMapDrag, NULL, 128);
     185  gdk_window_set_back_pixmap(wgtDrag->window, pixMapDrag, FALSE);
     186  g_object_unref(pixMapDrag);
     187  gtk_widget_queue_draw(wgtDrag);
     188
     189  g_message("%s", __FUNCTION__);
     190
     191  return;
     192}
     193#endif
     194
     195static GtkWidget *wgtDrag=NULL;
     196
     197static GdkPixmap *pixMapDrag=NULL;
     198static GdkPixmap *pixMapStop=NULL;
     199
     200/*
     201  Callback which loads a pixmap into the drag widget as soon as it#s realized.
     202 */
     203static void fldrWidgetRealize(GtkWidget * wgtDrag, gpointer ptrUserData)
     204{
     205  gdk_window_set_back_pixmap(wgtDrag->window, pixMapDrag, FALSE);
     206
     207  g_message("%s", __FUNCTION__);
     208  return;
     209}
     210
     211static void fldrWindowHandleDragBegin(GtkWidget * widget, GdkDragContext* dragContext,
     212                    gpointer ptrUserData)
     213{
     214  if(NULLHANDLE==wgtDrag)
     215    {
     216      GdkPixbuf *pixBufDrag;
     217      GdkPixbuf *pixBufStop;
     218
     219      wgtDrag=gtk_window_new(GTK_WINDOW_POPUP);
     220
     221      /*
     222        FIXME:
     223        In GTK 2.8 use *_HINT_DND instead.
     224       */
     225#warning move this somewhere else. Maybe into WPClassMgr
     226      gtk_window_set_type_hint(GTK_WINDOW(wgtDrag), GDK_WINDOW_TYPE_HINT_MENU);
     227      gtk_widget_set_app_paintable(GTK_WIDGET(wgtDrag), TRUE);
     228
     229      pixBufDrag=gtk_widget_render_icon(wgtDrag, GTK_STOCK_DND, GTK_ICON_SIZE_DND, NULL);
     230      gdk_pixbuf_render_pixmap_and_mask(pixBufDrag, &pixMapDrag, NULL, 128);
     231
     232      gtk_widget_set_size_request(wgtDrag, gdk_pixbuf_get_width(pixBufDrag), gdk_pixbuf_get_height(pixBufDrag));
     233
     234      g_object_unref(pixBufDrag);
     235
     236      pixBufStop=gtk_widget_render_icon(wgtDrag, GTK_STOCK_STOP, GTK_ICON_SIZE_DND, NULL);
     237      gdk_pixbuf_render_pixmap_and_mask(pixBufStop, &pixMapStop, NULL, 128);
     238      g_object_unref(pixBufStop);
     239
     240      if(!pixMapDrag)
     241        g_warning("Cannot load pixbuf");
     242      if(!pixMapStop)
     243        g_warning("Cannot load stop pixbuf");
     244
     245      //      gdk_pixbuf_render_pixmap_and_mask(pixBufDrag, &pixMapDrag, NULL, 128);
     246      //    gdk_window_set_back_pixmap(wgtDrag->window, pixMapDrag, FALSE);
     247      //      g_object_unref(pixMapDrag);
     248      g_signal_connect_after(GTK_WIDGET(wgtDrag), "realize", G_CALLBACK(fldrWidgetRealize), NULL);
     249    }
     250  DosBeep(1000, 10);
     251  g_message("%s", __FUNCTION__);
     252  //  if(wgtDrag->window)
     253  //gdk_window_set_back_pixmap(wgtDrag->window, pixMapDrag, FALSE);
     254
     255  gtk_drag_set_icon_widget(dragContext, wgtDrag, 0, 0);
     256
     257  return;
     258}
     259
     260static gboolean fldrWindowHandleDragMotion(GtkWidget * wgtThis, GdkDragContext* dragContext, int x, int y, guint t,
     261                    gpointer ptrUserData)
     262{
     263  GtkWidget *wgtSource;
     264  GtkTreePath* treePath;
     265  PWPFolderWindow pWindow;
     266  gulong rc=0;
     267  static gulong oldRc=0;
     268
     269  if(dragContext==NULL)
     270    return FALSE;
     271
     272  if((wgtSource=gtk_drag_get_source_widget(dragContext))==NULLHANDLE)
     273    return FALSE;
     274
     275#if 0
     276  if(wgtSource==wgtThis){
     277    gdk_drag_status(dragContext, GDK_ACTION_MOVE, t);
     278    //    gdk_drag_status(dragContext, 0, t);
     279    gtk_drag_highlight(wgtThis);
     280  }
     281  else{
     282    gdk_drag_status(dragContext, GDK_ACTION_COPY, t);
     283    gtk_drag_unhighlight(wgtSource);
     284  }
     285#endif
     286
     287  treePath=gtk_icon_view_get_path_at_pos(GTK_ICON_VIEW(wgtThis), x, y );
     288
     289  if(NULL==treePath)
     290    {     
     291      PWPFolder wpFolder;
     292      /* White space */
     293
     294      pWindow=(WPFolderWindow*)ptrUserData;
     295      if(!nomIsObj(pWindow))
     296        return FALSE;
     297
     298      wpFolder=(WPFolder*)WPFolderWindow_wpQueryWPObject(pWindow, NULLHANDLE);     
     299
     300      if(!nomIsObj(wpFolder))
     301        return FALSE;
     302
     303      rc=WPObject_wpDragOver((WPObject*)wpFolder, wgtThis, dragContext, NULL);
     304    }
     305  else
     306    {
     307      GtkTreeIter iter;
     308      GtkTreeModel* model;
     309      WPObject *wpObject;
     310      /* Over an icon */
     311     
     312      //   g_message("%s: %s", __FUNCTION__, gtk_tree_path_to_string(treePath));
     313      //    gtk_icon_view_item_activated(GTK_ICON_VIEW(wgtThis), treePath);
     314
     315      model=gtk_icon_view_get_model(GTK_ICON_VIEW(wgtThis));
     316           
     317      gtk_tree_model_get_iter(model , &iter, treePath);           
     318      gtk_tree_model_get(model, &iter, 0, &wpObject, -1);
     319
     320      //TST_OBJECT(wpObject);
     321
     322      //if(nomIsObj(wpObject))
     323      rc=WPObject_wpDragOver((WPObject*)wpObject, wgtThis, dragContext, NULL);
     324    }
     325
     326  if(oldRc!=rc)
     327    {
     328      /* drag icon */
     329      switch(rc)
     330        {
     331        case 0:
     332          {
     333            /* Don't drop */   
     334            gdk_window_set_back_pixmap(wgtDrag->window, pixMapStop, FALSE);
     335            break;
     336          }
     337        default:
     338          {
     339            gdk_window_set_back_pixmap(wgtDrag->window, pixMapDrag, FALSE);
     340            break;
     341          }
     342        }
     343      gtk_widget_queue_draw(wgtDrag);
     344    }
     345  oldRc=rc;
     346
     347  return FALSE;
     348}
     349
     350
    168351NOM_Scope void NOMLINK impl_WPFolderWindow_nomInit(WPFolderWindow* nomSelf, CORBA_Environment *ev)
    169352{
     
    255438                    G_CALLBACK (fldr_handleButtonEvent), nomSelf);
    256439
     440  /* Handle folder DnD */
     441  g_signal_connect(GTK_WIDGET(icon_view),"drag-begin",
     442                   G_CALLBACK(fldrWindowHandleDragBegin), nomSelf);
     443  g_signal_connect(GTK_WIDGET(icon_view),"drag-motion",
     444                   G_CALLBACK(fldrWindowHandleDragMotion), nomSelf);
     445  g_signal_connect(GTK_WIDGET(icon_view),"drag-drop",
     446                   G_CALLBACK(fldrWindowHandleDragDrop), nomSelf);
     447
     448
    257449#if 0
    258450  /* Connect to the "clicked" signal of the "Up" tool button */
Note: See TracChangeset for help on using the changeset viewer.