Xojo Developer Conference
25/27th April 2018 in Denver.
MBS Xojo Conference
6/7th September 2018 in Munich, Germany.

Platforms to show: All Mac Windows Linux Cross-Platform

/MacControls/Custom NSView Drop
Function:
Required plugins for this example: MBS MacBase Plugin, MBS MacCocoa Plugin, MBS MacControls Plugin, MBS MacFrameworks Plugin, MBS Main Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacControls/Custom NSView Drop
This example is the version from Thu, 6th Apr 2016.
Project "Custom NSView Drop.rbp"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits Window
Control CocoaControlMBS1 Inherits CocoaControlMBS
ControlInstance CocoaControlMBS1 Inherits CocoaControlMBS
EventHandler Function GetView() As NSViewMBS n=new CustomNSView(0,0,me.Width,me.Height) n.list = list dim types() as string types.Append NSPasteboardMBS.NSFilenamesPboardType 'types.Append NSPasteboardMBS.NSURLPboardType 'types.Append "public.data" n.registerForDraggedTypes(types) Return n End EventHandler
End Control
Control List Inherits Listbox
ControlInstance List Inherits Listbox
End Control
EventHandler Sub Open() if not CocoaControlMBS1.Available then MsgBox "This example requires Mac OS X 10.5." quit end if End EventHandler
Property n As CustomNSView
End Class
MenuBar MenuBar1
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
Class CustomNSView Inherits CustomNSViewMBS
EventHandler Sub DrawRect(g as NSGraphicsMBS, left as double, top as double, width as double, height as double) g.SetColorRGB 1.0,0.0,0.0,1.0 g.fillRect left,top,width,height End EventHandler
EventHandler Function acceptsFirstMouse(e as NSEventMBS) As boolean Return true End EventHandler
EventHandler Function acceptsFirstResponder() As boolean Return true End EventHandler
EventHandler Function becomeFirstResponder() As boolean Return true End EventHandler
EventHandler Function canBecomeKeyView() As boolean Return true End EventHandler
EventHandler Sub concludeDragOperation(sender as NSDraggingInfoMBS) // DraggingDestination log CurrentMethodName End EventHandler
EventHandler Sub draggingEnded(sender as NSDraggingInfoMBS) // DraggingDestination log CurrentMethodName End EventHandler
EventHandler Function draggingEntered(sender as NSDraggingInfoMBS) As integer // DraggingDestination log CurrentMethodName Return NSDraggingInfoMBS.NSDragOperationCopy End EventHandler
EventHandler Sub draggingExited(sender as NSDraggingInfoMBS) // DraggingDestination log CurrentMethodName End EventHandler
EventHandler Function draggingUpdated(sender as NSDraggingInfoMBS) As integer // DraggingDestination log CurrentMethodName Return NSDraggingInfoMBS.NSDragOperationCopy End EventHandler
EventHandler Function ignoreModifierKeysForDraggingSession(session as NSDraggingSessionMBS) As boolean log CurrentMethodName End EventHandler
EventHandler Function mouseDown(e as NSEventMBS, x as double, y as double) As boolean Return true End EventHandler
EventHandler Function performDragOperation(sender as NSDraggingInfoMBS) As boolean // DraggingDestination log CurrentMethodName dim p as NSPasteboardMBS = sender.draggingPasteboard dim types() as string = p.types log "Types: "+Join(types,", ") dim url as string = p.URLFromPasteboard log "URL: "+URL dim file as FolderItem = GetFolderItem(url, FolderItem.PathTypeURL) log "File: "+file.AbsolutePath Return true End EventHandler
EventHandler Function prepareForDragOperation(sender as NSDraggingInfoMBS) As boolean // DraggingDestination log CurrentMethodName Return true End EventHandler
EventHandler Sub updateDraggingItemsForDrag(sender as NSDraggingInfoMBS) // DraggingDestination log CurrentMethodName End EventHandler
EventHandler Function wantsPeriodicDraggingUpdates() As boolean log CurrentMethodName End EventHandler
Sub log(s as string) list.AddRow s list.ScrollPosition = list.ListCount End Sub
Property list As listbox
End Class
End Project

See also:

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacControls Plugin.




Links
MBS Xojo Chart Plugins