Skip to content

Commit 838bafb

Browse files
[[ RawClipboard ]] OSX platform changes for the refactored clipboard code
1 parent c124b00 commit 838bafb

File tree

9 files changed

+72
-106
lines changed

9 files changed

+72
-106
lines changed

engine/src/desktop-dc.cpp

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,73 +1262,8 @@ static bool fetch_dragboard(MCPlatformPasteboardFlavor p_flavor, void*& r_data,
12621262
return fetch_pasteboard(s_local_dragboard, p_flavor, r_data, r_data_size);
12631263
}
12641264

1265-
MCDragAction MCScreenDC::dodragdrop(Window w, MCPasteboard *p_pasteboard, MCDragActionSet p_allowed_actions, MCImage *p_image, const MCPoint* p_image_offset)
1265+
MCDragAction MCScreenDC::dodragdrop(Window w, MCDragActionSet p_allowed_actions, MCImage *p_image, const MCPoint* p_image_offset)
12661266
{
1267-
/////////
1268-
1269-
MCPlatformPasteboardRef t_dragboard;
1270-
MCPlatformGetDragboard(t_dragboard);
1271-
1272-
MCPlatformPasteboardClear(t_dragboard);
1273-
1274-
// COCOA-TODO: Duplicate code - needs refactored along with code in setclipboard().
1275-
1276-
MCTransferType *t_types;
1277-
size_t t_type_count;
1278-
if (!p_pasteboard -> Query(t_types, t_type_count))
1279-
{
1280-
t_type_count = 0;
1281-
t_types = nil;
1282-
}
1283-
1284-
s_local_dragboard = p_pasteboard;
1285-
1286-
for(uindex_t i = 0; i < t_type_count; i++)
1287-
{
1288-
MCPlatformPasteboardFlavor t_flavors[2];
1289-
uindex_t t_flavor_count;
1290-
t_flavor_count = 0;
1291-
1292-
switch(t_types[i])
1293-
{
1294-
case TRANSFER_TYPE_TEXT:
1295-
case TRANSFER_TYPE_UNICODE_TEXT:
1296-
t_flavors[t_flavor_count++] = kMCPlatformPasteboardFlavorUTF8;
1297-
break;
1298-
case TRANSFER_TYPE_STYLED_TEXT:
1299-
t_flavors[t_flavor_count++] = kMCPlatformPasteboardFlavorRTF;
1300-
t_flavors[t_flavor_count++] = kMCPlatformPasteboardFlavorUTF8;
1301-
break;
1302-
case TRANSFER_TYPE_IMAGE:
1303-
{
1304-
MCAutoDataRef t_data;
1305-
if (p_pasteboard -> Fetch(TRANSFER_TYPE_IMAGE, &t_data))
1306-
{
1307-
if (MCImageDataIsPNG(*t_data))
1308-
t_flavors[t_flavor_count++] = kMCPlatformPasteboardFlavorPNG;
1309-
if (MCImageDataIsGIF(*t_data))
1310-
t_flavors[t_flavor_count++] = kMCPlatformPasteboardFlavorGIF;
1311-
if (MCImageDataIsJPEG(*t_data))
1312-
t_flavors[t_flavor_count++] = kMCPlatformPasteboardFlavorJPEG;
1313-
}
1314-
}
1315-
break;
1316-
case TRANSFER_TYPE_FILES:
1317-
t_flavors[t_flavor_count++] = kMCPlatformPasteboardFlavorFiles;
1318-
break;
1319-
case TRANSFER_TYPE_OBJECTS:
1320-
t_flavors[t_flavor_count++] = kMCPlatformPasteboardFlavorObjects;
1321-
break;
1322-
case TRANSFER_TYPE_PRIVATE:
1323-
break;
1324-
}
1325-
1326-
if (t_flavor_count != 0)
1327-
MCPlatformPasteboardStore(t_dragboard, t_flavors, t_flavor_count, (void *)fetch_dragboard);
1328-
}
1329-
1330-
/////////
1331-
13321267
MCPlatformAllowedDragOperations t_operations;
13331268
t_operations = kMCPlatformDragOperationNone;
13341269
if ((p_allowed_actions & DRAG_ACTION_COPY) != 0)
@@ -1353,10 +1288,6 @@ MCDragAction MCScreenDC::dodragdrop(Window w, MCPasteboard *p_pasteboard, MCDrag
13531288

13541289
MCImageFreeBitmap(t_image_bitmap);
13551290

1356-
MCPlatformPasteboardRelease(t_dragboard);
1357-
1358-
s_local_dragboard = nil;
1359-
13601291
MCDragAction t_action;
13611292
switch(t_op)
13621293
{

engine/src/desktop-dc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class MCScreenDC: public MCUIDC
155155
// Mismatching types - thus the 'unimplemented' MCUICDC::snapshot was called instead of the MCScreenDC one
156156
virtual MCImageBitmap *snapshot(MCRectangle &r, uint4 window, MCStringRef displayname, MCPoint *size);
157157

158-
virtual MCDragAction dodragdrop(Window w, MCPasteboard *p_pasteboard, MCDragActionSet p_allowed_actions, MCImage *p_image, const MCPoint* p_image_offset);
158+
virtual MCDragAction dodragdrop(Window w, MCDragActionSet p_allowed_actions, MCImage *p_image, const MCPoint* p_image_offset);
159159
// SN-2014-07-23: [[ Bug 12907 ]] File > Import as control > Snapshot from screen
160160
// Update as well MCSreenDC::createscriptenvironment (and callees)
161161
virtual MCScriptEnvironment *createscriptenvironment(MCStringRef p_language);

engine/src/desktop.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "player.h"
4141
#include "aclip.h"
4242
#include "stacklst.h"
43+
#include "clipboard.h"
4344

4445
#include "desktop-dc.h"
4546
#include "param.h"
@@ -361,7 +362,7 @@ void MCPlatformHandleMouseDown(MCPlatformWindowRef p_window, uint32_t p_button,
361362
MCdragimageid = 0;
362363
MCdragimageoffset . x = 0;
363364
MCdragimageoffset . y = 0;
364-
MCdragdata -> ResetSource();
365+
MCdragboard->Clear();
365366
}
366367

367368
t_target -> mdown(p_button + 1);
@@ -520,13 +521,16 @@ static MCPlatformDragOperation dragaction_to_dragoperation(MCDragAction p_action
520521
return kMCPlatformDragOperationNone;
521522
}
522523

523-
void MCPlatformHandleDragEnter(MCPlatformWindowRef p_window, MCPlatformPasteboardRef p_pasteboard, MCPlatformDragOperation& r_operation)
524+
void MCPlatformHandleDragEnter(MCPlatformWindowRef p_window, MCRawClipboard* p_dragboard, MCPlatformDragOperation& r_operation)
524525
{
525-
MCSystemPasteboard *t_pasteboard;
526-
t_pasteboard = new MCSystemPasteboard(p_pasteboard);
527-
MCdispatcher -> wmdragenter(p_window, t_pasteboard);
528-
t_pasteboard -> Release();
526+
// On some platforms (Mac and iOS), the drag board used for drag-and-drop
527+
// operations may not be the main drag board. If a non-NULL clipboard was
528+
// supplied for this operation, tell the engine drag board to re-bind to it.
529+
if (p_dragboard != NULL)
530+
MCdragboard->Rebind(p_dragboard);
529531

532+
MCdispatcher->wmdragenter(p_window);
533+
530534
r_operation = dragaction_to_dragoperation(MCdragaction);
531535
}
532536

@@ -539,7 +543,12 @@ void MCPlatformHandleDragMove(MCPlatformWindowRef p_window, MCPoint p_location,
539543

540544
void MCPlatformHandleDragLeave(MCPlatformWindowRef p_window)
541545
{
542-
MCdispatcher -> wmdragleave(p_window);
546+
// On some platforms (Mac and iOS), the drag board used for drag-and-drop
547+
// operations may not be the main drag board. Reset the drag board back to
548+
// the main one after the drag has left.
549+
MCdragboard->Rebind(MCRawClipboard::CreateSystemDragboard());
550+
551+
MCdispatcher -> wmdragleave(p_window);
543552
}
544553

545554
void MCPlatformHandleDragDrop(MCPlatformWindowRef p_window, bool& r_accepted)

engine/src/mac-clipboard.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ public MCRawClipboardItemRep
3333
public:
3434

3535
// Methods inherited from MCRawClipboardItem
36-
virtual MCStringRef GetTypeString() const;
37-
virtual MCDataRef GetData() const;
36+
virtual MCStringRef CopyTypeString() const;
37+
virtual MCDataRef CopyData() const;
3838

3939
private:
4040

engine/src/mac-clipboard.mm

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
NULL,
4242

4343
"com.runrev.livecode.objects-1",
44+
"com.runrev.livecode.text-styled-1",
4445

4546
NULL,
4647
NULL,
@@ -49,11 +50,22 @@
4950
};
5051

5152

52-
MCRawClipboard* MCRawClipboard::Create()
53+
MCRawClipboard* MCRawClipboard::CreateSystemClipboard()
5354
{
5455
return new MCMacRawClipboard([NSPasteboard generalPasteboard]);
5556
}
5657

58+
MCRawClipboard* MCRawClipboard::CreateSystemSelectionClipboard()
59+
{
60+
// Create a pasteboard internal to LiveCode
61+
return new MCMacRawClipboard([NSPasteboard pasteboardWithUniqueName]);
62+
}
63+
64+
MCRawClipboard* MCRawClipboard::CreateSystemDragboard()
65+
{
66+
return new MCMacRawClipboard([NSPasteboard pasteboardWithName:NSDragPboard]);
67+
}
68+
5769

5870
MCMacRawClipboard::MCMacRawClipboard(NSPasteboard* p_pasteboard) :
5971
MCRawClipboard(),
@@ -72,14 +84,7 @@
7284

7385
uindex_t MCMacRawClipboard::GetItemCount() const
7486
{
75-
NSArray* t_items = [m_pasteboard pasteboardItems];
76-
77-
// If an error occurred retrieving the clipboard items, we will have
78-
// received nil.
79-
if (t_items == nil)
80-
return 0;
81-
82-
return [t_items count];
87+
return [m_items count];
8388
}
8489

8590
const MCMacRawClipboardItem* MCMacRawClipboard::GetItemAtIndex(uindex_t p_index) const
@@ -184,7 +189,10 @@
184189

185190
MCStringRef MCMacRawClipboard::GetKnownTypeString(MCRawClipboardKnownType p_type) const
186191
{
187-
// TODO: implement
192+
// Index into the mapping table
193+
if (s_clipboard_types[p_type] != NULL)
194+
return MCSTR(s_clipboard_types[p_type]);
195+
188196
return NULL;
189197
}
190198

@@ -334,7 +342,7 @@
334342
// refernce for us.
335343
}
336344

337-
MCStringRef MCMacRawClipboardItemRep::GetTypeString() const
345+
MCStringRef MCMacRawClipboardItemRep::CopyTypeString() const
338346
{
339347
// If the type string has already been fetched, just return it
340348
if (*m_type != NULL)
@@ -421,7 +429,7 @@
421429
return t_type_string;
422430
}
423431

424-
MCDataRef MCMacRawClipboardItemRep::GetData() const
432+
MCDataRef MCMacRawClipboardItemRep::CopyData() const
425433
{
426434
// If the data has already been fetched, just return it
427435
if (*m_data != NULL)
@@ -433,8 +441,7 @@
433441
if ([m_item isKindOfClass:[NSPasteboardItem class]])
434442
{
435443
// Get the type string for this representation (as lookup is by type)
436-
MCAutoStringRef t_type_string;
437-
t_type_string = GetTypeString();
444+
MCAutoStringRef t_type_string(CopyTypeString());
438445
if (*t_type_string == NULL)
439446
return NULL;
440447

engine/src/mac-window.mm

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "platform.h"
2727
#include "platform-internal.h"
2828

29+
#include "mac-clipboard.h"
2930
#include "mac-internal.h"
3031

3132
#include <objc/objc-runtime.h>
@@ -1352,17 +1353,17 @@ - (BOOL)wantsPeriodicDraggingUpdates
13521353

13531354
- (NSDragOperation)draggingEntered: (id<NSDraggingInfo>)sender
13541355
{
1355-
MCPlatformPasteboardRef t_pasteboard;
1356-
MCMacPlatformPasteboardCreate([sender draggingPasteboard], t_pasteboard);
1357-
1356+
// Create a wrapper around the drag board for this operation
1357+
MCAutoRefcounted<MCMacRawClipboard> t_dragboard = new MCMacRawClipboard([sender draggingPasteboard]);
1358+
13581359
NSDragOperation t_ns_operation;
13591360

13601361
MCMacPlatformWindow *t_window;
13611362
t_window = [self platformWindow];
13621363
if (t_window != nil)
13631364
{
13641365
MCPlatformDragOperation t_operation;
1365-
t_window -> HandleDragEnter(t_pasteboard, t_operation);
1366+
t_window -> HandleDragEnter(t_dragboard, t_operation);
13661367
t_ns_operation = MCMacPlatformMapDragOperationToNSDragOperation(t_operation);
13671368
}
13681369
else

engine/src/platform-internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class MCPlatformWindow
125125
void HandleKeyDown(MCPlatformKeyCode key_code, codepoint_t mapped_codepoint, codepoint_t unmapped_codepoint);
126126
void HandleKeyUp(MCPlatformKeyCode key_code, codepoint_t mapped_codepoint, codepoint_t unmapped_codepoint);
127127

128-
void HandleDragEnter(MCPlatformPasteboardRef pasteboard, MCPlatformDragOperation& r_operation);
128+
void HandleDragEnter(class MCRawClipboard* p_dragboard, MCPlatformDragOperation& r_operation);
129129
void HandleDragMove(MCPoint location, MCPlatformDragOperation& r_operation);
130130
void HandleDragLeave(void);
131131
void HandleDragDrop(bool& r_accepted);
@@ -300,7 +300,7 @@ void MCPlatformCallbackSendMouseLeave(MCPlatformWindowRef window);
300300
void MCPlatformCallbackSendMouseMove(MCPlatformWindowRef window, MCPoint location);
301301
void MCPlatformCallbackSendMouseScroll(MCPlatformWindowRef window, int32_t dx, int32_t dy);
302302

303-
void MCPlatformCallbackSendDragEnter(MCPlatformWindowRef window, MCPlatformPasteboardRef pasteboard, MCPlatformDragOperation& r_operation);
303+
void MCPlatformCallbackSendDragEnter(MCPlatformWindowRef window, class MCRawClipboard* p_dragboard, MCPlatformDragOperation& r_operation);
304304
void MCPlatformCallbackSendDragLeave(MCPlatformWindowRef window);
305305
void MCPlatformCallbackSendDragMove(MCPlatformWindowRef window, MCPoint location, MCPlatformDragOperation& r_operation);
306306
void MCPlatformCallbackSendDragDrop(MCPlatformWindowRef window, bool& r_accepted);

engine/src/platform-window.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,9 @@ void MCPlatformWindow::HandleKeyUp(MCPlatformKeyCode p_key_code, codepoint_t p_m
563563
MCPlatformCallbackSendKeyUp(this, p_key_code, p_mapped_char, p_unmapped_char);
564564
}
565565

566-
void MCPlatformWindow::HandleDragEnter(MCPlatformPasteboardRef p_pasteboard, MCPlatformDragOperation& r_operation)
566+
void MCPlatformWindow::HandleDragEnter(MCRawClipboard* p_dragboard, MCPlatformDragOperation& r_operation)
567567
{
568-
MCPlatformCallbackSendDragEnter(this, p_pasteboard, r_operation);
568+
MCPlatformCallbackSendDragEnter(this, p_dragboard, r_operation);
569569
}
570570

571571
void MCPlatformWindow::HandleDragMove(MCPoint p_location, MCPlatformDragOperation& r_operation)

engine/src/platform.cpp

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1+
/* Copyright (C) 2003-2015 LiveCode Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
118
#include "platform.h"
219
#include "platform-internal.h"
320

21+
422
////////////////////////////////////////////////////////////////////////////////
523

624
void MCPlatformHandleApplicationStartup(int p_argc, MCStringRef *p_argv, MCStringRef *p_envp, int& r_error_code, MCStringRef& r_error_message);
@@ -45,7 +63,7 @@ void MCPlatformHandleMouseRelease(MCPlatformWindowRef window, uint32_t button, b
4563
void MCPlatformHandleMouseMove(MCPlatformWindowRef window, MCPoint location);
4664
void MCPlatformHandleMouseScroll(MCPlatformWindowRef window, int dx, int dy);
4765

48-
void MCPlatformHandleDragEnter(MCPlatformWindowRef window, MCPlatformPasteboardRef pasteboard, MCPlatformDragOperation& r_operation);
66+
void MCPlatformHandleDragEnter(MCPlatformWindowRef window, class MCRawClipboard* p_clipboard, MCPlatformDragOperation& r_operation);
4967
void MCPlatformHandleDragMove(MCPlatformWindowRef window, MCPoint location, MCPlatformDragOperation& r_operation);
5068
void MCPlatformHandleDragLeave(MCPlatformWindowRef window);
5169
void MCPlatformHandleDragDrop(MCPlatformWindowRef window, bool& r_accepted);
@@ -246,11 +264,11 @@ void MCPlatformCallbackSendMouseScroll(MCPlatformWindowRef p_window, int dx, int
246264

247265
//////////
248266

249-
void MCPlatformCallbackSendDragEnter(MCPlatformWindowRef p_window, MCPlatformPasteboardRef p_pasteboard, MCPlatformDragOperation& r_operation)
267+
void MCPlatformCallbackSendDragEnter(MCPlatformWindowRef p_window, MCRawClipboard* p_dragboard, MCPlatformDragOperation& r_operation)
250268
{
251-
MCLog("Window(%p) -> DragEnter(%p)", p_window, p_pasteboard);
269+
MCLog("Window(%p) -> DragEnter(%p)", p_window, p_dragboard);
252270
MCPlatformWindowDeathGrip(p_window);
253-
MCPlatformHandleDragEnter(p_window, p_pasteboard, r_operation);
271+
MCPlatformHandleDragEnter(p_window, p_dragboard, r_operation);
254272
}
255273

256274
void MCPlatformCallbackSendDragLeave(MCPlatformWindowRef p_window)

0 commit comments

Comments
 (0)