Skip to content

Commit

Permalink
Drag+drop now supported on text labels
Browse files Browse the repository at this point in the history
Relates to #549.

Images can now be drag+dropped onto the text labels in the "quick start" canvas screen
  • Loading branch information
tannerhelland committed Apr 2, 2024
1 parent c759668 commit 936ac55
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
12 changes: 11 additions & 1 deletion Controls/pdCanvas.ctl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Begin VB.UserControl pdCanvas
_ExtentX = 1508
_ExtentY = 873
Caption = "quick start"
CustomDragDropEnabled= -1 'True
FontSize = 18
End
Begin PhotoDemon.pdLabel lblTitle
Expand All @@ -52,6 +53,7 @@ Begin VB.UserControl pdCanvas
_ExtentX = 3413
_ExtentY = 873
Caption = "recent images"
CustomDragDropEnabled= -1 'True
FontSize = 18
End
Begin PhotoDemon.pdHyperlink hypRecentFiles
Expand Down Expand Up @@ -786,7 +788,7 @@ Private Sub cmdStart_Click(Index As Integer)
End Sub

Private Sub cmdStart_CustomDragDrop(Index As Integer, Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
Loading.LoadFromDragDrop Data, Effect, Button, Shift, x, y
Loading.LoadFromDragDrop Data, Effect, Button, Shift
End Sub

Private Sub cmdStart_CustomDragOver(Index As Integer, Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)
Expand Down Expand Up @@ -851,6 +853,14 @@ Private Sub hypRecentFiles_SetCustomTabTarget(ByVal shiftTabWasPressed As Boolea
End If
End Sub

Private Sub lblTitle_CustomDragDrop(Index As Integer, Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
Loading.LoadFromDragDrop Data, Effect, Button, Shift
End Sub

Private Sub lblTitle_CustomDragOver(Index As Integer, Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)
Loading.HelperForDragOver Data, Effect, Button, Shift, x, y, State
End Sub

Private Sub m_PopupMenu_MenuClicked(ByRef clickedMenuID As String, ByVal idxMenuTop As Long, ByVal idxMenuSub As Long)

Select Case idxMenuTop
Expand Down
33 changes: 29 additions & 4 deletions Controls/pdLabel.ctl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ Attribute VB_Exposed = False
'PhotoDemon Unicode Label control
'Copyright 2014-2024 by Tanner Helland
'Created: 28/October/14
'Last updated: 02/November/15
'Last update: convert to ucSupport. This control was a messy one, but it has the most to gain from program-level
' font caching (vs each control maintaining its own font copy).
'Last updated: 01/April/24
'Last update: raise custom drag/drop events (that the owner can respond to as they wish)
'
'In a surprise to precisely no one, PhotoDemon has some unique needs when it comes to user controls - needs that
' the intrinsic VB controls can't handle. These range from the obnoxious (lack of an "autosize" property for
Expand Down Expand Up @@ -62,7 +61,12 @@ Attribute VB_Exposed = False

Option Explicit

'This control raises no events, by design.
'In April 2024, I added DragDrop relays (to enable custom drag/drop behavior on individual buttons).
' (Despite the name, these relays are for the underlying OLE-prefixed events, which are the only drag/drop
' events PD uses.)
Public Event CustomDragDrop(ByRef Data As DataObject, ByRef Effect As Long, ByRef Button As Integer, ByRef Shift As Integer, ByRef x As Single, ByRef y As Single)
Public Event CustomDragOver(ByRef Data As DataObject, ByRef Effect As Long, ByRef Button As Integer, ByRef Shift As Integer, ByRef x As Single, ByRef y As Single, ByRef State As Integer)
Private m_CustomDragDropEnabled As Boolean

'Rather than handle autosize and wordwrap separately, this control combines them into a single "Layout" property.
' All four possible layout approaches are covered by this enum.
Expand Down Expand Up @@ -181,6 +185,15 @@ Public Property Let Caption(ByRef newCaption As String)

End Property

Public Property Get CustomDragDropEnabled() As Boolean
CustomDragDropEnabled = m_CustomDragDropEnabled
End Property

Public Property Let CustomDragDropEnabled(ByVal newValue As Boolean)
m_CustomDragDropEnabled = newValue
If newValue Then UserControl.OLEDropMode = 1 Else UserControl.OLEDropMode = 0
End Property

'The Enabled property is a bit unique; see http://msdn.microsoft.com/en-us/library/aa261357%28v=vs.60%29.aspx
Public Property Get Enabled() As Boolean
Attribute Enabled.VB_UserMemId = -514
Expand Down Expand Up @@ -361,6 +374,16 @@ Private Sub UserControl_InitProperties()
FontItalic = False
FontSize = 10

CustomDragDropEnabled = False

End Sub

Private Sub UserControl_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)
RaiseEvent CustomDragDrop(Data, Effect, Button, Shift, x, y)
End Sub

Private Sub UserControl_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)
RaiseEvent CustomDragOver(Data, Effect, Button, Shift, x, y, State)
End Sub

'At run-time, painting is handled by PD's pdWindowPainter class. In the IDE, however, we must rely on VB's internal paint event.
Expand All @@ -374,6 +397,7 @@ Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
Alignment = .ReadProperty("Alignment", vbLeftJustify)
m_BackColor = .ReadProperty("BackColor", vbWindowBackground)
Caption = .ReadProperty("Caption", "caption")
CustomDragDropEnabled = .ReadProperty("CustomDragDropEnabled", False)
FontBold = .ReadProperty("FontBold", False)
FontItalic = .ReadProperty("FontItalic", False)
FontSize = .ReadProperty("FontSize", 10)
Expand All @@ -396,6 +420,7 @@ Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
.WriteProperty "Alignment", Alignment, vbLeftJustify
.WriteProperty "BackColor", m_BackColor, vbWindowBackground
.WriteProperty "Caption", Caption, "caption"
.WriteProperty "CustomDragDropEnabled", Me.CustomDragDropEnabled, False
.WriteProperty "FontBold", FontBold, False
.WriteProperty "FontItalic", FontItalic, False
.WriteProperty "FontSize", FontSize, 10
Expand Down
21 changes: 2 additions & 19 deletions Forms/MainWindow.frm
Original file line number Diff line number Diff line change
Expand Up @@ -2138,28 +2138,11 @@ End Sub

'Allow the user to drag-and-drop files and URLs onto the main form
Private Sub Form_OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single)

'Make sure the form is available (e.g. a modal form hasn't stolen focus)
If (Not g_AllowDragAndDrop) Then Exit Sub

'Use the external function (in the clipboard handler, as the code is roughly identical to
' clipboard pasting) to load the OLE source.
Dim dropAsNewLayer As VbMsgBoxResult
dropAsNewLayer = Dialogs.PromptDropAsNewLayer()
If (dropAsNewLayer <> vbCancel) Then g_Clipboard.LoadImageFromDragDrop Data, Effect, (dropAsNewLayer = vbNo)

Loading.LoadFromDragDrop Data, Effect, Button, Shift
End Sub

Private Sub Form_OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, x As Single, y As Single, State As Integer)

'PD supports many different types of drop sources. These values are defined and addressed by
' the main clipboard handler, because Drag/Drop and clipboard actions use very similar code.
If g_Clipboard.IsObjectDragDroppable(Data) And g_AllowDragAndDrop Then
Effect = vbDropEffectCopy And Effect
Else
Effect = vbDropEffectNone
End If

Loading.HelperForDragOver Data, Effect, Button, Shift, x, y, State
End Sub

'If the user attempts to close the program, run some checks first. Specifically, we want to notify them
Expand Down

0 comments on commit 936ac55

Please sign in to comment.