Changeset 448


Ignore:
Timestamp:
Jan 13, 2010, 9:14:29 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

gui: DnD: Drag party code in progress.

Location:
trunk/src/gui/kernel
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/kernel/qapplication_pm.cpp

    r447 r448  
    117117
    118118static HWND autoCaptureWnd = NULLHANDLE;
    119 static bool autoCaptureReleased = FALSE;
     119static bool autoCaptureReleased = ;
    120120static void setAutoCapture(HWND); // automatic capture
    121121static void releaseAutoCapture();
     
    21172117}
    21182118#endif
     2119
     2120
     2121
     2122
     2123
     2124
     2125
     2126
     2127
     2128
     2129
     2130
     2131
    21192132
    21202133//
  • trunk/src/gui/kernel/qdnd_pm.cpp

    r447 r448  
    5252#include "qcursor.h"
    5353#include "qdesktopwidget.h"
     54
    5455#include "qdnd_p.h"
    5556#include "qdebug.h"
     
    6869
    6970#if !defined(QT_NO_DRAGANDDROP) && !defined(QT_NO_CLIPBOARD)
     71
     72
     73
    7074
    7175/** \internal
     
    271275        return DO_MOVE;
    272276    return DO_UNKNOWN;
     277
     278
     279
     280
     281
     282
     283
     284
     285
     286
     287
     288
    273289}
    274290
     
    617633}
    618634
     635
     636
     637
     638
     639
     640
     641
     642
     643
     644
     645
     646
     647
     648
     649
     650
     651
     652
     653
     654
     655
     656
     657
     658
     659
     660
     661
     662
     663
     664
     665
     666
     667
     668
     669
     670
     671
     672
     673
     674
     675
     676
     677
     678
     679
     680
     681
     682
     683
     684
     685
     686
     687
     688
     689
     690
     691
     692
     693
     694
     695
     696
     697
     698
     699
     700
     701
     702
     703
     704
     705
     706
     707
     708
     709
     710
     711
     712
     713
     714
     715
     716
     717
     718
     719
     720
     721
     722
     723
     724
     725
     726
     727
     728
     729
     730
     731
     732
     733
     734
     735
     736
     737
     738
     739
     740
     741
     742
     743
     744
     745
     746
     747
     748
     749
     750
     751
     752
     753
     754
     755
     756
     757
     758
     759
     760
     761
     762
     763
     764
     765
     766
     767
     768
     769
     770
     771
     772
     773
     774
     775
     776
     777
     778
     779
     780
     781
     782
     783
     784
     785
     786
     787
     788
     789
     790
     791
     792
     793
     794
     795
     796
     797
     798
     799
     800
     801
     802
     803
     804
     805
     806
     807
     808
     809
     810
     811
     812
     813
     814
     815
     816
     817
     818
     819
     820
     821
     822
     823
     824
     825
     826
     827
     828
     829
     830
     831
     832
     833
     834
     835
     836
     837
     838
     839
     840
     841
     842
     843
     844
     845
     846
     847
     848
     849
     850
     851
     852
     853
     854
     855
     856
     857
     858
     859
     860
     861
     862
     863
     864
     865
     866
     867
     868
     869
     870
     871
     872
     873
     874
     875
     876
     877
     878
     879
     880
     881
     882
     883
     884
     885
     886
     887
     888
     889
     890
     891
     892
     893
     894
     895
     896
     897
     898
     899
     900
     901
     902
     903
     904
     905
     906
     907
     908
     909
     910
     911
     912
     913
     914
     915
     916
     917
     918
     919
     920
     921
     922
     923
     924
     925
     926
     927
     928
     929
     930
     931
     932
     933
     934
     935
     936
     937
     938
     939
     940
     941
     942
     943
     944
     945
     946
     947
     948
     949
     950
     951
     952
     953
     954
     955
     956
     957
     958
     959
     960
     961
     962
     963
     964
     965
     966
     967
     968
     969
     970
     971
     972
     973
     974
     975
     976
     977
     978
     979
     980
     981
     982
     983
     984
     985
     986
     987
     988
     989
     990
     991
     992
     993
     994
     995
     996
     997
     998
    619999Qt::DropAction QDragManager::drag(QDrag *o)
    6201000
     
    6221002    DEBUG(() << "QDragManager::drag");
    6231003
    624     // @todo implement
    625     return Qt::IgnoreAction;
    626 }
    627 
    628 void QDragManager::cancel(bool /* deleteSource */)
    629 {
    630     // @todo implement
     1004    if (object == o || !o || !o->d_func()->source)
     1005        return Qt::IgnoreAction;
     1006
     1007    if (object) {
     1008        cancel();
     1009        qApp->removeEventFilter(this);
     1010        beingCancelled = false;
     1011    }
     1012
     1013    // detect a mouse button to end dragging
     1014    LONG vkTerminate = 0;
     1015    {
     1016        ULONG msg = WinQuerySysValue(HWND_DESKTOP, SV_BEGINDRAG) & 0xFFFF;
     1017        switch(msg) {
     1018            case WM_BUTTON1MOTIONSTART: vkTerminate = VK_BUTTON1; break;
     1019            case WM_BUTTON2MOTIONSTART: vkTerminate = VK_BUTTON2; break;
     1020            case WM_BUTTON3MOTIONSTART: vkTerminate = VK_BUTTON3; break;
     1021        }
     1022
     1023        if (WinGetKeyState(HWND_DESKTOP, vkTerminate) & 0x8000) {
     1024            // prefer the default button if it is pressed
     1025        } else if (WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000) {
     1026            vkTerminate = VK_BUTTON2;
     1027        } else if (WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000) {
     1028            vkTerminate = VK_BUTTON1;
     1029        } else if (WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000) {
     1030            vkTerminate = VK_BUTTON3;
     1031        } else {
     1032            vkTerminate = 0;
     1033        }
     1034    }
     1035
     1036    if (!vkTerminate) {
     1037        DEBUG(() << "QDragManager::drag: No valid mouse button pressed, "
     1038                    "dragging cancelled!");
     1039        o->deleteLater();
     1040        return Qt::IgnoreAction;
     1041    }
     1042
     1043    USHORT supportedOps = toPmDragDropOps(dragPrivate()->possible_actions);
     1044
     1045    static QPMCoopDragWorker dragWorker;
     1046   
     1047    bool ok = dragWorker.collectWorkers(o);
     1048    Q_ASSERT(ok);
     1049    Q_ASSERT(dragWorker.hwnd());
     1050    if (!ok || !dragWorker.hwnd()) {
     1051        o->deleteLater();
     1052        return Qt::IgnoreAction;
     1053    }
     1054
     1055    dragWorker.src = o->mimeData();
     1056    dragWorker.init();
     1057    DRAGINFO *info = dragWorker.createDragInfo(o->objectName(), supportedOps);
     1058
     1059    Q_ASSERT(info);
     1060    if (!info) {
     1061        dragWorker.cleanup(true /* isCancelled */);
     1062        dragWorker.src = 0;
     1063        o->deleteLater();
     1064        return Qt::IgnoreAction;
     1065    }
     1066
     1067    object = o;
     1068
     1069    DEBUG(() << "QDragManager::drag: actions"
     1070             << dragActionsToString(dragPrivate()->possible_actions));
     1071
     1072    dragPrivate()->target = 0;
     1073
     1074#ifndef QT_NO_ACCESSIBILITY
     1075    QAccessible::updateAccessibility(this, 0, QAccessible::DragDropStart);
     1076#endif
     1077
     1078    // @todo custom drag pixmap?
     1079
     1080    DRAGIMAGE img;
     1081    img.cb = sizeof(DRAGIMAGE);
     1082    img.hImage = WinQuerySysPointer(HWND_DESKTOP, SPTR_FILE, FALSE);
     1083    img.fl = DRG_ICON;
     1084    img.cxOffset = 0;
     1085    img.cyOffset = 0;
     1086
     1087    // the mouse is most likely captured by Qt at this point, uncapture it
     1088    // or DrgDrag() will definitely fail
     1089    WinSetCapture(HWND_DESKTOP, 0);
     1090
     1091    HWND target = DrgDrag(dragWorker.hwnd(), info, &img, 1, vkTerminate,
     1092                          (PVOID)0x80000000L); // don't lock the desktop PS
     1093
     1094    DEBUG(("QDragManager::drag: DrgDrag() returned %08lX (error 0x%08lX)",
     1095            target, WinGetLastError(0)));
     1096
     1097    // we won't get any mouse release event, so manually adjust qApp state
     1098    qt_pmMouseButtonUp();
     1099
     1100    bool moveDisallowed = dragWorker.cleanup(beingCancelled || target == 0);
     1101    dragWorker.src = 0;
     1102   
     1103    moveDisallowed |= beingCancelled || target == 0 ||
     1104                      info->usOperation != DO_MOVE;
     1105
     1106    DEBUG(() << "QDragManager::drag: moveDisallowed" << moveDisallowed);
     1107
     1108    Qt::DropAction ret = Qt::IgnoreAction;
     1109    if (target != 0) {
     1110        ret = toQDragDropAction(info->usOperation);
     1111        if (moveDisallowed && info->usOperation == DO_MOVE)
     1112            ret = Qt::TargetMoveAction;
     1113    }
     1114
     1115    DEBUG(() << "QDragManager::drag: result" << dragActionsToString(ret));
     1116
     1117    if (target == 0)
     1118        DrgDeleteDraginfoStrHandles(info);
     1119    DrgFreeDraginfo(info);
     1120
     1121    if (!beingCancelled) {
     1122        dragPrivate()->target = QWidget::find(target);
     1123        cancel(); // this will delete o (object)
     1124    }
     1125
     1126    beingCancelled = false;
     1127
     1128#ifndef QT_NO_ACCESSIBILITY
     1129    QAccessible::updateAccessibility(this, 0, QAccessible::DragDropEnd);
     1130#endif
     1131
     1132    return ret;
     1133}
     1134
     1135void QDragManager::cancel(bool deleteSource)
     1136{
     1137    // Note: the only place where this function is called with
     1138    // deleteSource = false so far is QDrag::~QDrag()
     1139
     1140    Q_ASSERT(object && !beingCancelled);
     1141    if (!object || beingCancelled)
     1142        return;
     1143   
     1144    beingCancelled = true;
     1145
     1146    object->setMimeData(0);
     1147
     1148    if (deleteSource)
     1149        object->deleteLater();
     1150    object = 0;
     1151
     1152#ifndef QT_NO_CURSOR
     1153    // insert cancel code here ######## todo
     1154
     1155    if (restoreCursor) {
     1156        QApplication::restoreOverrideCursor();
     1157        restoreCursor = false;
     1158    }
     1159#endif
     1160#ifndef QT_NO_ACCESSIBILITY
     1161    QAccessible::updateAccessibility(this, 0, QAccessible::DragDropEnd);
     1162#endif
    6311163}
    6321164
  • trunk/src/gui/kernel/qmime.h

    r444 r448  
    322322    friend class QClipboard;
    323323    friend class QPMDragData;
     324
    324325
    325326    struct Match
Note: See TracChangeset for help on using the changeset viewer.