Add support for native OS X clipboard

This commit is contained in:
David Capello 2015-03-17 14:46:08 -03:00
parent 0350ac4bbe
commit 4421f4cb10
6 changed files with 123 additions and 1 deletions

View File

@ -90,7 +90,9 @@ endif()
if(APPLE)
list(APPEND SHE_SOURCES
osx/logger.mm)
osx/clipboard.mm
osx/logger.mm
osx/native_dialogs.mm)
endif()
add_library(she ${SHE_SOURCES})

View File

@ -7,6 +7,9 @@
#ifdef _WIN32
#include "she/win/clipboard.h"
#include "she/win/native_dialogs.h"
#elif defined(__APPLE__)
#include "she/osx/clipboard.h"
#include "she/osx/native_dialogs.h"
#else
#include "she/clipboard_simple.h"
#endif
@ -43,6 +46,9 @@ public:
#ifdef _WIN32
if (!m_nativeDialogs)
m_nativeDialogs = new NativeDialogsWin32();
#elif defined(__APPLE__)
if (!m_nativeDialogs)
m_nativeDialogs = new NativeDialogsOSX();
#endif
return m_nativeDialogs;
}
@ -50,6 +56,8 @@ public:
Clipboard* createClipboard() override {
#ifdef _WIN32
return new ClipboardWin32();
#elif defined(__APPLE__)
return new ClipboardOSX();
#else
return new ClipboardImpl();
#endif

28
src/she/osx/clipboard.h Normal file
View File

@ -0,0 +1,28 @@
// SHE library
// Copyright (C) 2012-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef SHE_OSX_CLIPBOARD_H_INCLUDED
#define SHE_OSX_CLIPBOARD_H_INCLUDED
#pragma once
#include "base/string.h"
#include "she/clipboard.h"
namespace she {
class ClipboardOSX : public Clipboard {
public:
void dispose() override;
std::string getText(DisplayHandle display) override;
void setText(DisplayHandle display, const std::string& text) override;
private:
std::string m_text;
};
} // namespace she
#endif

38
src/she/osx/clipboard.mm Normal file
View File

@ -0,0 +1,38 @@
// SHE library
// Copyright (C) 2012-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>
#include <AppKit/AppKit.h>
#include "she/osx/clipboard.h"
namespace she {
void ClipboardOSX::dispose()
{
delete this;
}
std::string ClipboardOSX::getText(DisplayHandle display)
{
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
NSString* string = [pasteboard stringForType:NSStringPboardType];
if (string)
return std::string([string UTF8String]);
else
return std::string();
}
void ClipboardOSX::setText(DisplayHandle display, const std::string& text)
{
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
[pasteboard clearContents];
[pasteboard setString:[NSString stringWithUTF8String:text.c_str()]
forType:NSStringPboardType];
}
} // namespace she

View File

@ -0,0 +1,23 @@
// SHE library
// Copyright (C) 2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef SHE_OSX_NATIVE_DIALOGS_H_INCLUDED
#define SHE_OSX_NATIVE_DIALOGS_H_INCLUDED
#pragma once
#include "she/native_dialogs.h"
namespace she {
class NativeDialogsOSX : public NativeDialogs {
public:
NativeDialogsOSX();
FileDialog* createFileDialog() override;
};
} // namespace she
#endif

View File

@ -0,0 +1,23 @@
// SHE library
// Copyright (C) 2012-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#include <CoreFoundation/CoreFoundation.h>
#include <Foundation/Foundation.h>
#include "she/osx/native_dialogs.h"
namespace she {
NativeDialogsOSX::NativeDialogsOSX()
{
}
FileDialog* NativeDialogsOSX::createFileDialog()
{
return nullptr;
}
} // namespace she