Ignore:
Timestamp:
Mar 6, 2007, 8:47:20 PM (18 years ago)
Author:
cinc
Message:

WC2007 patches for drag and drop implementation.

File:
1 edited

Legend:

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

    r240 r241  
    6262#include "exception.h"
    6363
     64#include "nomdragwindow.h"
     65#include "nomdraginfo.h"
     66
    6467NOM_Scope PGtkWidget NOMLINK impl_WPFolderWindow_wpQueryContainerHandle(WPFolderWindow* nomSelf, CORBA_Environment *ev)
    6568{
     
    7073
    7174NOM_Scope void NOMLINK impl_WPFolderWindow_wpSetContainerHandle(WPFolderWindow* nomSelf, const PGtkWidget pgWidget,
    72                                                               CORBA_Environment *ev)
     75                                                                CORBA_Environment *ev)
    7376{
    7477  WPFolderWindowData* nomThis=WPFolderWindowGetData(nomSelf);
     
    116119        PWPFolderWindow pWindow;
    117120        GtkTreePath* treePath;
    118         //DosBeep(5000, 100);
     121
    119122        pWindow=(WPFolderWindow*)user_data;
    120123        //TST_OBJECT(pWindow);
     
    182185};
    183186
     187static NOMDragWindow *nomDragWindow=NULL;
     188static NOMDragInfo   *nomDragInfo=NULL;
    184189
    185190/*
    186191  This callback handles the drop of an item on an object.
    187192 */
    188 static gboolean fldrWindowHandleDragDrop(GtkWidget * wgtThis, GdkDragContext* dragContext, gint x, gint y,
     193static gboolean fldrWindowHandleDragDrop(GtkWidget * wgtThis, GdkDragContext* dragContext,
     194                                         gint x, gint y,
    189195                         guint t, gpointer ptrUserData)
    190196{
    191   DosBeep(500, 10);
    192   g_message("%s", __FUNCTION__);
    193   g_message("  action: %d", dragContext->action );
    194 
     197  GtkTreePath* treePath;
     198  PWPFolderWindow pWindow;
     199  gulong rc=0;
     200  WPObject *wpObject;
     201
     202  //g_message("   %s", __FUNCTION__);
     203  //g_message("   action: %d", dragContext->action );
     204
     205  /* Find the object beneath the pointer */
     206  treePath=gtk_icon_view_get_path_at_pos(GTK_ICON_VIEW(wgtThis), x, y );
     207  if(NULL==treePath)
     208    {     
     209
     210      /* White space, so ask the folder */
     211     
     212      pWindow=(WPFolderWindow*)ptrUserData;
     213      if(!nomIsObj(pWindow))
     214        return FALSE;
     215
     216      wpObject=WPFolderWindow_wpQueryWPObject(pWindow, NULLHANDLE);     
     217
     218      if(!nomIsObj(wpObject))
     219        return FALSE;
     220    }
     221  else
     222    {
     223      GtkTreeIter iter;
     224      GtkTreeModel* model;
     225
     226      /* Over an icon */
     227     
     228      model=gtk_icon_view_get_model(GTK_ICON_VIEW(wgtThis));           
     229      gtk_tree_model_get_iter(model , &iter, treePath);           
     230      gtk_tree_model_get(model, &iter, 0, &wpObject, -1);
     231
     232      //TST_OBJECT(wpObject);
     233
     234      if(!nomIsObj(wpObject))
     235        return FALSE;
     236    }
     237  rc=WPObject_wpDragOver(wpObject, wgtThis, nomDragInfo, NULL);
     238  g_message("rc: %d", rc);
    195239  if(dragContext->targets)
    196240    {
    197241      GdkAtom targetType;
    198242      targetType=GDK_POINTER_TO_ATOM(g_list_nth_data(dragContext->targets, WPOBJECT_TARGET_OBJECT));
    199       g_message("  calling gtk_drag_get_data()..." );
     243      //    g_message("  calling gtk_drag_get_data()..." );
    200244      gtk_drag_get_data(wgtThis, dragContext, targetType, t);
     245
     246      /* FIXME:
     247         We don't use the returned data for now but use our own draginfo stuff. This is
     248         broken.
     249         The following may be moved to dragDataReceived later. */
     250      if(rc) {
     251        //        g_message("Now call wpDrop() actions: %d action: %d sugg %d", dragContext->action,
     252        //        dragContext->action, dragContext->suggested_action);
     253
     254        WPObject_wpDrop( wpObject, wgtThis, nomDragInfo, NULLHANDLE);
     255       
     256        gtk_drag_finish(dragContext, TRUE, FALSE, t);
     257        return TRUE;
     258      }
     259
    201260    }
    202261  return FALSE;
     
    208267{
    209268  GdkPixmap *pixMapDrag;
    210  
    211269  gdk_pixbuf_render_pixmap_and_mask(pixBufStop, &pixMapDrag, NULL, 128);
    212270  gdk_window_set_back_pixmap(wgtDrag->window, pixMapDrag, FALSE);
    213271  g_object_unref(pixMapDrag);
    214272  gtk_widget_queue_draw(wgtDrag);
    215 
    216   g_message("%s", __FUNCTION__);
    217 
    218   return;
    219 }
    220 #endif
    221 
    222 static GtkWidget *wgtDrag=NULL;
    223 
    224 static GdkPixmap *pixMapDrag=NULL;
    225 static GdkPixmap *pixMapStop=NULL;
    226 
    227 /*
    228   Callback which loads a pixmap into the drag widget as soon as it's realized.
    229  */
    230 static void fldrWidgetRealize(GtkWidget * wgtDrag, gpointer ptrUserData)
    231 {
    232   gdk_window_set_back_pixmap(wgtDrag->window, pixMapDrag, FALSE);
    233 
    234273  g_message("%s", __FUNCTION__);
    235274  return;
    236275}
     276#endif
     277
    237278/**
    238279   Callback for the drag-begin signal.
    239280 */
    240281static void fldrWindowHandleDragBegin(GtkWidget * widget, GdkDragContext* dragContext,
    241                     gpointer ptrUserData)
    242 {
    243   if(NULLHANDLE==wgtDrag)
    244     {
    245       GdkPixbuf *pixBufDrag;
    246       GdkPixbuf *pixBufStop;
    247 
    248       wgtDrag=gtk_window_new(GTK_WINDOW_POPUP);
    249 
    250       /*
    251         FIXME:
    252         In GTK 2.8 use *_HINT_DND instead.
    253        */
    254 #warning move this somewhere else. Maybe into WPClassMgr
    255       gtk_window_set_type_hint(GTK_WINDOW(wgtDrag), GDK_WINDOW_TYPE_HINT_MENU);
    256       gtk_widget_set_app_paintable(GTK_WIDGET(wgtDrag), TRUE);
    257 
    258       pixBufDrag=gtk_widget_render_icon(wgtDrag, GTK_STOCK_DND, GTK_ICON_SIZE_DND, NULL);
    259       gdk_pixbuf_render_pixmap_and_mask(pixBufDrag, &pixMapDrag, NULL, 128);
    260 
    261       gtk_widget_set_size_request(wgtDrag, gdk_pixbuf_get_width(pixBufDrag), gdk_pixbuf_get_height(pixBufDrag));
    262 
    263       g_object_unref(pixBufDrag);
    264 
    265       pixBufStop=gtk_widget_render_icon(wgtDrag, GTK_STOCK_STOP, GTK_ICON_SIZE_DND, NULL);
    266       gdk_pixbuf_render_pixmap_and_mask(pixBufStop, &pixMapStop, NULL, 128);
    267       g_object_unref(pixBufStop);
    268 
    269       if(!pixMapDrag)
    270         g_warning("Cannot load pixbuf");
    271       if(!pixMapStop)
    272         g_warning("Cannot load stop pixbuf");
    273 
    274       //      gdk_pixbuf_render_pixmap_and_mask(pixBufDrag, &pixMapDrag, NULL, 128);
    275       //    gdk_window_set_back_pixmap(wgtDrag->window, pixMapDrag, FALSE);
    276       //      g_object_unref(pixMapDrag);
    277       g_signal_connect_after(GTK_WIDGET(wgtDrag), "realize", G_CALLBACK(fldrWidgetRealize), NULL);
    278     }
    279   DosBeep(1000, 10);
    280   g_message("%s", __FUNCTION__);
    281   //  if(wgtDrag->window)
    282   //gdk_window_set_back_pixmap(wgtDrag->window, pixMapDrag, FALSE);
    283 
    284   gtk_drag_set_icon_widget(dragContext, wgtDrag, 0, 0);
    285 
     282                                      gpointer ptrUserData)
     283{
     284  GtkTreePath* treePath;
     285  gint x, y;
     286
     287  /* Create the drag window displayed to the user */
     288  if(NULLHANDLE==nomDragWindow)
     289    {
     290      nomDragWindow=NOMDragWindowNew();
     291    }
     292
     293  if(NULLHANDLE==nomDragInfo)
     294    {
     295      nomDragInfo=NOMDragInfoNew();
     296    }
     297
     298  if(!dragContext)
     299    return;
     300
     301  /* Make sure we have no leftovers... */
     302  NOMDragInfo_deleteAllDragItems(nomDragInfo, NULLHANDLE);
     303  NOMDragInfo_setGdkDragContextPointer(nomDragInfo, dragContext, NULLHANDLE);
     304
     305  /* Get the object beneath the pointer if any */
     306  gtk_widget_get_pointer(widget, &x, &y);
     307  treePath=gtk_icon_view_get_path_at_pos(GTK_ICON_VIEW(widget), x, y );
     308
     309  if(NULL==treePath)
     310    {
     311      /* Click on white space */
     312      //    NOMDragWindow_hide(nomDragWindow, NULLHANDLE);
     313      g_message("%d %s: White space!", __LINE__, __FUNCTION__);
     314    }
     315  else
     316    {
     317      GtkTreeIter iter;
     318      GtkTreeModel* model;
     319      WPObject *wpObject;
     320      WPFolderWindow *wpFolderWindow=(WPFolderWindow*)ptrUserData;
     321
     322      /* Click on an icon occurred */
     323
     324      if(!nomIsObj(wpFolderWindow))
     325        return; //Oops...
     326     
     327      g_message("%s: %s", __FUNCTION__, gtk_tree_path_to_string(treePath));
     328     
     329      /* Get the object belonging to the tree path */
     330      model=gtk_icon_view_get_model(GTK_ICON_VIEW(widget));
     331      gtk_tree_model_get_iter(model , &iter, treePath);           
     332      gtk_tree_model_get(model, &iter, 0, &wpObject, -1);
     333     
     334      //  TST_OBJECT(wpObject);
     335     
     336      if(nomIsObj(wpObject)){
     337        g_message("%s: %s begin DnD", __FUNCTION__, wpObject->mtab->nomClassName);
     338
     339        /* Add the object to the list of items for this drag */
     340        NOMDragInfo_addWPObjectToItemList(nomDragInfo, wpObject,
     341                                       (PWPFolder)WPFolderWindow_wpQueryWPObject(wpFolderWindow, NULLHANDLE),
     342                                       widget, NULLHANDLE);
     343      }
     344      else
     345        g_message("%d %s: WPDataFile object not valid!", __LINE__, __FUNCTION__);
     346 
     347     NOMDragWindow_show(nomDragWindow, NULLHANDLE);
     348    }
     349
     350
     351  /* Tell GTK to use our drag window as an 'icon' while dragging. */
     352  gtk_drag_set_icon_widget(dragContext,
     353                           NOMDragWindow_queryWindowHandle(nomDragWindow, NULLHANDLE), 0, 0);   
     354
     355  // gdk_drag_status(dragContext, GDK_ACTION_MOVE, t);
     356  //NOMDragWindow_hide(nomDragWindow, NULLHANDLE);
    286357  return;
    287358}
     
    293364  GtkTreePath* treePath;
    294365  PWPFolderWindow pWindow;
     366  WPObject *wpObject;
    295367  gulong rc=0;
    296   static gulong oldRc=0;
     368  static gulong oldRc=0xff;/* Make sure we at last one time have an rc!=oldRc so the icon is
     369                              set properly below */
    297370
    298371  if(dragContext==NULL)
     
    303376
    304377  /* This does not work for some reason */
    305   gtk_drag_highlight(wgtThis);
    306   gtk_widget_queue_draw(wgtThis);
     378  //  gtk_drag_highlight(wgtThis);
     379  //gtk_widget_queue_draw(wgtThis);
     380
    307381
    308382  if(dragContext)
    309383    {
    310       g_message("  Actions: %x %x" , dragContext->actions, dragContext->suggested_action);
     384      //        g_message("  Actions: %x %x" , dragContext->actions, dragContext->suggested_action);
    311385    }
    312386
     
    323397#endif
    324398
     399  /* Find the object beneath the pointer */
    325400  treePath=gtk_icon_view_get_path_at_pos(GTK_ICON_VIEW(wgtThis), x, y );
    326 
    327401  if(NULL==treePath)
    328402    {     
    329       PWPFolder wpFolder;
    330       /* White space */
     403      /* White space, so ask the folder */
    331404
    332405      pWindow=(WPFolderWindow*)ptrUserData;
     
    334407        return FALSE;
    335408
    336       wpFolder=(WPFolder*)WPFolderWindow_wpQueryWPObject(pWindow, NULLHANDLE);     
    337 
    338       if(!nomIsObj(wpFolder))
     409      wpObject=WPFolderWindow_wpQueryWPObject(pWindow, NULLHANDLE);     
     410
     411      if(!nomIsObj(wpObject))
    339412        return FALSE;
    340 
    341       rc=WPObject_wpDragOver((WPObject*)wpFolder, wgtThis, dragContext, NULL);
    342413    }
    343414  else
     
    345416      GtkTreeIter iter;
    346417      GtkTreeModel* model;
    347       WPObject *wpObject;
     418
    348419      /* Over an icon */
    349420     
    350       //   g_message("%s: %s", __FUNCTION__, gtk_tree_path_to_string(treePath));
    351       //    gtk_icon_view_item_activated(GTK_ICON_VIEW(wgtThis), treePath);
    352 
    353421      model=gtk_icon_view_get_model(GTK_ICON_VIEW(wgtThis));
    354422           
     
    358426      //TST_OBJECT(wpObject);
    359427
    360       //if(nomIsObj(wpObject))
    361       rc=WPObject_wpDragOver((WPObject*)wpObject, wgtThis, dragContext, NULL);
    362     }
    363 
     428      if(!nomIsObj(wpObject))
     429        return FALSE;
     430      //g_message("Over an icon");
     431    }
     432  rc=WPObject_wpDragOver(wpObject, wgtThis, nomDragInfo, NULL);
     433  //g_message("rc: %d oldRc %d", rc, oldRc);
     434
     435  /* Change the drag icon if necesary. Note that this will not change the
     436     cursor. */
    364437  if(oldRc!=rc)
    365438    {
     
    367440      switch(rc)
    368441        {
    369         case 0:
     442        case DOR_NODROP:
    370443          {
    371444            /* Don't drop */   
    372             gdk_window_set_back_pixmap(wgtDrag->window, pixMapStop, FALSE);
     445            NOMDragWindow_displayStopImage(nomDragWindow, NULLHANDLE);
     446            //     gdk_drag_status(dragContext, 0, t);
    373447            break;
    374448          }
    375449        default:
    376450          {
    377             gdk_window_set_back_pixmap(wgtDrag->window, pixMapDrag, FALSE);
     451            NOMDragWindow_displayDragImage(nomDragWindow, NULLHANDLE);
     452            //  gdk_drag_status(dragContext, GDK_ACTION_MOVE, t);
     453           break;
     454          }
     455        }
     456      /* Tell GTK to redraw the drag window */
     457      gtk_widget_queue_draw(NOMDragWindow_queryWindowHandle(nomDragWindow, NULLHANDLE));
     458    }
     459  oldRc=rc;
     460
     461  switch(dragContext->actions)
     462    { 
     463    case GDK_ACTION_COPY:
     464      {
     465        gdk_drag_status(dragContext, GDK_ACTION_COPY, t);
     466        break;
     467      }
     468    case GDK_ACTION_MOVE:
     469      {
     470        gdk_drag_status(dragContext, GDK_ACTION_MOVE, t);
     471        break;
     472      }
     473    case GDK_ACTION_LINK:
     474      {
     475        gdk_drag_status(dragContext, GDK_ACTION_LINK, t);
     476        break;
     477      }
     478    default:
     479      {
     480        if(dragContext->actions & GDK_ACTION_MOVE) //FIXME
     481          gdk_drag_status(dragContext, GDK_ACTION_MOVE, t);       
     482        break;
     483      }
     484    }
     485#if 0
     486  /* Now change the cursor */
     487  switch(rc & DOR_ALLFLAGS)
     488    {
     489    case DOR_NODROP:
     490      {
     491        /* Don't drop */   
     492        gdk_drag_status(dragContext, 0, t);
     493        break;
     494      }
     495    default:
     496      {
     497        switch(rc & DO_ALLFLAGS)
     498          {
     499          case DO_MOVE:
     500            {
     501              gdk_drag_status(dragContext, GDK_ACTION_MOVE, t);
     502              break;
     503            }
     504          case DO_COPY:
     505            {
     506              gdk_drag_status(dragContext, GDK_ACTION_COPY, t);
     507              break;
     508            }
     509          case DO_LINK:
     510            {
     511              gdk_drag_status(dragContext, GDK_ACTION_LINK, t);
     512              break;
     513            }
     514
     515          default:
     516            if(dragContext->actions & GDK_ACTION_MOVE) //FIXME
     517              gdk_drag_status(dragContext, GDK_ACTION_MOVE, t);
    378518            break;
    379519          }
    380         }
    381       gtk_widget_queue_draw(wgtDrag);
    382     }
    383   oldRc=rc;
    384 
     520        break;
     521      }
     522    }/* switch() */
     523#endif
     524 
    385525  return FALSE;
    386526}
     
    390530                          guint info, guint uiTime, gpointer ptrUserData)
    391531{
    392   DosBeep(5000, 100);
    393532  g_message("%s", __FUNCTION__);
    394533  //  gdk_drag_status(dragContext, GDK_ACTION_COPY, uiTime);
     
    397536
    398537
    399 
    400538/*
    401539
     
    424562      break;
    425563    };
    426   // 
     564
    427565  return;
    428566}
     
    525663                   G_CALLBACK(fldrWindowHandleDragDrop), nomSelf);
    526664  g_signal_connect(GTK_WIDGET(icon_view), "drag_data_received",
    527                    G_CALLBACK(fldrWindowHandleDragDataReceived), NULL);
     665                   G_CALLBACK(fldrWindowHandleDragDataReceived), nomSelf);
    528666  g_signal_connect(GTK_WIDGET(icon_view), "drag_data_get",
    529                    G_CALLBACK(fldrWindowHandleDragDataGet), NULL);
     667                   G_CALLBACK(fldrWindowHandleDragDataGet), nomSelf);
    530668
    531669  /* Prepare drag and drop */
    532670  gtk_drag_source_set(GTK_WIDGET(icon_view), GDK_BUTTON3_MASK, targetEntries,
    533                       G_N_ELEMENTS(targetEntries) ,
    534                       GDK_ACTION_LINK|GDK_ACTION_COPY|GDK_ACTION_MOVE);
    535   gtk_drag_dest_set(GTK_WIDGET(icon_view), GTK_DEST_DEFAULT_ALL, targetEntries, 1 ,
    536                       GDK_ACTION_LINK|GDK_ACTION_COPY|GDK_ACTION_MOVE);
     671                      G_N_ELEMENTS(targetEntries),
     672                      GDK_ACTION_DEFAULT|GDK_ACTION_LINK|GDK_ACTION_COPY|GDK_ACTION_MOVE);
     673  gtk_drag_dest_set(GTK_WIDGET(icon_view), GTK_DEST_DEFAULT_ALL, targetEntries, 1,
     674                      GDK_ACTION_DEFAULT|GDK_ACTION_LINK|GDK_ACTION_COPY|GDK_ACTION_MOVE);
    537675
    538676#if 0
Note: See TracChangeset for help on using the changeset viewer.