mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-26 12:35:33 +00:00
Use clip library to copy/paste text
In this way we can remove all the code related to handle clipboard text from she and ui libraries.
This commit is contained in:
parent
174d31a12a
commit
924c2ac86a
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -27,3 +27,6 @@
|
||||
[submodule "third_party/libpng"]
|
||||
path = third_party/libpng
|
||||
url = https://github.com/aseprite/libpng.git
|
||||
[submodule "src/clip"]
|
||||
path = src/clip
|
||||
url = https://github.com/aseprite/clip.git
|
||||
|
@ -86,6 +86,7 @@ add_subdirectory(base)
|
||||
include_directories(${BASE_INCLUDE_DIR})
|
||||
|
||||
add_subdirectory(cfg)
|
||||
add_subdirectory(clip)
|
||||
add_subdirectory(css)
|
||||
add_subdirectory(doc)
|
||||
add_subdirectory(filters)
|
||||
|
@ -439,6 +439,7 @@ add_library(app-lib
|
||||
target_link_libraries(app-lib
|
||||
base-lib
|
||||
cfg-lib
|
||||
clip
|
||||
css-lib
|
||||
doc-lib
|
||||
filters-lib
|
||||
|
@ -37,7 +37,6 @@
|
||||
#include "base/shared_ptr.h"
|
||||
#include "base/unique_ptr.h"
|
||||
#include "doc/sprite.h"
|
||||
#include "she/clipboard.h"
|
||||
#include "she/display.h"
|
||||
#include "she/error.h"
|
||||
#include "she/surface.h"
|
||||
@ -82,7 +81,6 @@ protected:
|
||||
};
|
||||
|
||||
static she::Display* main_display = NULL;
|
||||
static she::Clipboard* main_clipboard = NULL;
|
||||
static CustomizedGuiManager* manager = NULL;
|
||||
static Theme* gui_theme = NULL;
|
||||
|
||||
@ -176,12 +174,9 @@ int init_module_gui()
|
||||
return -1;
|
||||
}
|
||||
|
||||
main_clipboard = she::instance()->createClipboard();
|
||||
|
||||
// Create the default-manager
|
||||
manager = new CustomizedGuiManager();
|
||||
manager->setDisplay(main_display);
|
||||
manager->setClipboard(main_clipboard);
|
||||
|
||||
// Setup the GUI theme for all widgets
|
||||
gui_theme = new SkinTheme();
|
||||
@ -208,7 +203,6 @@ void exit_module_gui()
|
||||
CurrentTheme::set(NULL);
|
||||
delete gui_theme;
|
||||
|
||||
main_clipboard->dispose();
|
||||
main_display->dispose();
|
||||
}
|
||||
|
||||
|
1
src/clip
Submodule
1
src/clip
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit e57130a56659d001d7bc33081c7cb3abe0621be2
|
@ -211,13 +211,11 @@ endif()
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND SHE_SOURCES
|
||||
win/clipboard.cpp
|
||||
win/native_dialogs.cpp)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
list(APPEND SHE_SOURCES
|
||||
osx/clipboard.mm
|
||||
osx/logger.mm
|
||||
osx/native_dialogs.mm)
|
||||
endif()
|
||||
|
@ -1,27 +0,0 @@
|
||||
// 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_CLIPBOARD_H_INCLUDED
|
||||
#define SHE_CLIPBOARD_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "she/display_handle.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace she {
|
||||
|
||||
class Clipboard {
|
||||
public:
|
||||
virtual ~Clipboard() { }
|
||||
virtual void dispose() = 0;
|
||||
virtual std::string getText(DisplayHandle hwnd) = 0;
|
||||
virtual void setText(DisplayHandle hwnd, const std::string& text) = 0;
|
||||
};
|
||||
|
||||
} // namespace she
|
||||
|
||||
#endif
|
@ -1,38 +0,0 @@
|
||||
// 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_CLIPBOARD_IMPL_H_INCLUDED
|
||||
#define SHE_CLIPBOARD_IMPL_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "she/clipboard.h"
|
||||
|
||||
namespace she {
|
||||
|
||||
class ClipboardImpl : public Clipboard {
|
||||
public:
|
||||
~ClipboardImpl() {
|
||||
}
|
||||
|
||||
void dispose() override {
|
||||
delete this;
|
||||
}
|
||||
|
||||
std::string getText(DisplayHandle) override {
|
||||
return m_text;
|
||||
}
|
||||
|
||||
void setText(DisplayHandle, const std::string& text) override {
|
||||
m_text = text;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_text;
|
||||
};
|
||||
|
||||
} // namespace she
|
||||
|
||||
#endif
|
@ -9,16 +9,12 @@
|
||||
#pragma once
|
||||
|
||||
#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"
|
||||
#elif defined(ASEPRITE_WITH_GTK_FILE_DIALOG_SUPPORT) && defined(__linux__)
|
||||
#include "she/clipboard_simple.h"
|
||||
#include "she/gtk/native_dialogs.h"
|
||||
#else
|
||||
#include "she/clipboard_simple.h"
|
||||
#include "she/native_dialogs.h"
|
||||
#endif
|
||||
|
||||
@ -68,16 +64,6 @@ public:
|
||||
return m_nativeDialogs;
|
||||
}
|
||||
|
||||
Clipboard* createClipboard() override {
|
||||
#ifdef _WIN32
|
||||
return new ClipboardWin32();
|
||||
#elif defined(__APPLE__)
|
||||
return new ClipboardOSX();
|
||||
#else
|
||||
return new ClipboardImpl();
|
||||
#endif
|
||||
}
|
||||
|
||||
Font* loadSpriteSheetFont(const char* filename, int scale) override {
|
||||
Surface* sheet = loadRgbaSurface(filename);
|
||||
Font* font = nullptr;
|
||||
|
@ -1,28 +0,0 @@
|
||||
// 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
|
@ -1,36 +0,0 @@
|
||||
// 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 <Cocoa/Cocoa.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
|
@ -8,7 +8,6 @@
|
||||
#define SHE_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "she/clipboard.h"
|
||||
#include "she/display.h"
|
||||
#include "she/error.h"
|
||||
#include "she/event.h"
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
namespace she {
|
||||
|
||||
class Clipboard;
|
||||
class Display;
|
||||
class EventQueue;
|
||||
class Font;
|
||||
@ -49,7 +48,6 @@ namespace she {
|
||||
virtual Surface* loadRgbaSurface(const char* filename) = 0;
|
||||
virtual Font* loadSpriteSheetFont(const char* filename, int scale = 1) = 0;
|
||||
virtual Font* loadTrueTypeFont(const char* filename, int height) = 0;
|
||||
virtual Clipboard* createClipboard() = 0;
|
||||
};
|
||||
|
||||
System* create_system();
|
||||
|
@ -1,94 +0,0 @@
|
||||
// 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.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "base/string.h"
|
||||
#include "she/win/clipboard.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace {
|
||||
|
||||
bool open_clipboard(HWND hwnd)
|
||||
{
|
||||
for (int i=0; i<5; ++i) {
|
||||
if (OpenClipboard(hwnd))
|
||||
return true;
|
||||
|
||||
Sleep(100);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace she {
|
||||
|
||||
void ClipboardWin32::dispose()
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
|
||||
std::string ClipboardWin32::getText(DisplayHandle hwnd)
|
||||
{
|
||||
std::string text;
|
||||
|
||||
if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
|
||||
if (open_clipboard((HWND)hwnd)) {
|
||||
HGLOBAL hglobal = GetClipboardData(CF_UNICODETEXT);
|
||||
if (hglobal) {
|
||||
LPWSTR lpstr = static_cast<LPWSTR>(GlobalLock(hglobal));
|
||||
if (lpstr) {
|
||||
text = base::to_utf8(lpstr).c_str();
|
||||
GlobalUnlock(hglobal);
|
||||
}
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
}
|
||||
else if (IsClipboardFormatAvailable(CF_TEXT)) {
|
||||
if (open_clipboard((HWND)hwnd)) {
|
||||
HGLOBAL hglobal = GetClipboardData(CF_TEXT);
|
||||
if (hglobal) {
|
||||
LPSTR lpstr = static_cast<LPSTR>(GlobalLock(hglobal));
|
||||
if (lpstr) {
|
||||
text = lpstr;
|
||||
GlobalUnlock(hglobal);
|
||||
}
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
void ClipboardWin32::setText(DisplayHandle hwnd, const std::string& text)
|
||||
{
|
||||
if (open_clipboard((HWND)hwnd)) {
|
||||
EmptyClipboard();
|
||||
|
||||
if (!text.empty()) {
|
||||
std::wstring wstr = base::from_utf8(text);
|
||||
int len = wstr.size();
|
||||
|
||||
HGLOBAL hglobal = GlobalAlloc(GMEM_MOVEABLE |
|
||||
GMEM_ZEROINIT, sizeof(WCHAR)*(len+1));
|
||||
|
||||
LPWSTR lpstr = static_cast<LPWSTR>(GlobalLock(hglobal));
|
||||
std::copy(wstr.begin(), wstr.end(), lpstr);
|
||||
GlobalUnlock(hglobal);
|
||||
|
||||
SetClipboardData(CF_UNICODETEXT, hglobal);
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace she
|
@ -1,28 +0,0 @@
|
||||
// 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_WIN_CLIPBOARD_H_INCLUDED
|
||||
#define SHE_WIN_CLIPBOARD_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "base/string.h"
|
||||
#include "she/clipboard.h"
|
||||
|
||||
namespace she {
|
||||
|
||||
class ClipboardWin32 : public Clipboard {
|
||||
public:
|
||||
void dispose() override;
|
||||
std::string getText(DisplayHandle hwnd) override;
|
||||
void setText(DisplayHandle hwnd, const std::string& text) override;
|
||||
|
||||
private:
|
||||
std::string m_text;
|
||||
};
|
||||
|
||||
} // namespace she
|
||||
|
||||
#endif
|
@ -10,7 +10,6 @@ add_library(ui-lib
|
||||
alert.cpp
|
||||
box.cpp
|
||||
button.cpp
|
||||
clipboard.cpp
|
||||
combobox.cpp
|
||||
component.cpp
|
||||
cursor.cpp
|
||||
|
@ -1,42 +0,0 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "ui/clipboard.h"
|
||||
|
||||
#include "she/clipboard.h"
|
||||
#include "she/display.h"
|
||||
#include "ui/manager.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
static std::string clipboard_text;
|
||||
|
||||
namespace ui {
|
||||
namespace clipboard {
|
||||
|
||||
const char* get_text()
|
||||
{
|
||||
Manager* manager = Manager::getDefault();
|
||||
clipboard_text = manager->getClipboard()->getText(
|
||||
manager->getDisplay()->nativeHandle());
|
||||
return clipboard_text.c_str();
|
||||
}
|
||||
|
||||
void set_text(const char* text)
|
||||
{
|
||||
Manager* manager = Manager::getDefault();
|
||||
clipboard_text = (text ? text: "");
|
||||
manager->getClipboard()->setText(
|
||||
manager->getDisplay()->nativeHandle(),
|
||||
clipboard_text);
|
||||
}
|
||||
|
||||
} // namespace clipboard
|
||||
} // namespace ui
|
@ -1,22 +0,0 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2013 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#ifndef UI_CLIPBOARD_H_INCLUDED
|
||||
#define UI_CLIPBOARD_H_INCLUDED
|
||||
#pragma once
|
||||
|
||||
#include "ui/base.h"
|
||||
|
||||
namespace ui {
|
||||
namespace clipboard {
|
||||
|
||||
const char* get_text();
|
||||
void set_text(const char* text);
|
||||
|
||||
} // namespace clipboard
|
||||
} // namespace ui
|
||||
|
||||
#endif
|
@ -1,55 +0,0 @@
|
||||
// Aseprite UI Library
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
//
|
||||
// This file is released under the terms of the MIT license.
|
||||
// Read LICENSE.txt for more information.
|
||||
|
||||
#include "base/string.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <windows.h>
|
||||
|
||||
namespace {
|
||||
|
||||
void get_system_clipboard_text(std::string& text)
|
||||
{
|
||||
if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
|
||||
if (OpenClipboard(win_get_window())) {
|
||||
HGLOBAL hglobal = GetClipboardData(CF_UNICODETEXT);
|
||||
if (hglobal != NULL) {
|
||||
LPWSTR lpstr = static_cast<LPWSTR>(GlobalLock(hglobal));
|
||||
if (lpstr != NULL) {
|
||||
text = base::to_utf8(lpstr).c_str();
|
||||
GlobalUnlock(hglobal);
|
||||
}
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void set_system_clipboard_text(const std::string& text)
|
||||
{
|
||||
if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
|
||||
if (OpenClipboard(win_get_window())) {
|
||||
EmptyClipboard();
|
||||
|
||||
if (!text.empty()) {
|
||||
std::wstring wstr = base::from_utf8(text);
|
||||
int len = wstr.size();
|
||||
|
||||
HGLOBAL hglobal = GlobalAlloc(GMEM_MOVEABLE |
|
||||
GMEM_ZEROINIT, sizeof(WCHAR)*(len+1));
|
||||
|
||||
LPWSTR lpstr = static_cast<LPWSTR>(GlobalLock(hglobal));
|
||||
std::copy(wstr.begin(), wstr.end(), lpstr);
|
||||
GlobalUnlock(hglobal);
|
||||
|
||||
SetClipboardData(CF_UNICODETEXT, hglobal);
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,8 +12,8 @@
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/string.h"
|
||||
#include "clip/clip.h"
|
||||
#include "she/font.h"
|
||||
#include "ui/clipboard.h"
|
||||
#include "ui/manager.h"
|
||||
#include "ui/menu.h"
|
||||
#include "ui/message.h"
|
||||
@ -611,7 +611,7 @@ void Entry::executeCmd(EntryCmd cmd, int unicodeChar, bool shift_pressed)
|
||||
// *cut* text!
|
||||
if (cmd == EntryCmd::Cut) {
|
||||
std::wstring selected = text.substr(selbeg, selend - selbeg + 1);
|
||||
clipboard::set_text(base::to_utf8(selected).c_str());
|
||||
clip::set_text(base::to_utf8(selected));
|
||||
}
|
||||
|
||||
// remove text
|
||||
@ -629,11 +629,8 @@ void Entry::executeCmd(EntryCmd cmd, int unicodeChar, bool shift_pressed)
|
||||
break;
|
||||
|
||||
case EntryCmd::Paste: {
|
||||
const char* clipboard_str;
|
||||
|
||||
if ((clipboard_str = clipboard::get_text())) {
|
||||
std::string clipboard(clipboard_str);
|
||||
|
||||
std::string clipboard;
|
||||
if (clip::get_text(clipboard)) {
|
||||
// delete the entire selection
|
||||
if (selbeg >= 0) {
|
||||
text.erase(selbeg, selend-selbeg+1);
|
||||
@ -659,7 +656,7 @@ void Entry::executeCmd(EntryCmd cmd, int unicodeChar, bool shift_pressed)
|
||||
case EntryCmd::Copy:
|
||||
if (selbeg >= 0) {
|
||||
std::wstring selected = text.substr(selbeg, selend - selbeg + 1);
|
||||
clipboard::set_text(base::to_utf8(selected).c_str());
|
||||
clip::set_text(base::to_utf8(selected));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -87,7 +87,6 @@ static int cmp_down(Widget* widget, int x, int y);
|
||||
Manager::Manager()
|
||||
: Widget(kManagerWidget)
|
||||
, m_display(NULL)
|
||||
, m_clipboard(NULL)
|
||||
, m_eventQueue(NULL)
|
||||
, m_lockedWindow(NULL)
|
||||
, m_mouseButtons(kButtonNone)
|
||||
@ -154,11 +153,6 @@ void Manager::setDisplay(she::Display* display)
|
||||
onNewDisplayConfiguration();
|
||||
}
|
||||
|
||||
void Manager::setClipboard(she::Clipboard* clipboard)
|
||||
{
|
||||
m_clipboard = clipboard;
|
||||
}
|
||||
|
||||
void Manager::run()
|
||||
{
|
||||
MessageLoop loop(this);
|
||||
|
@ -16,7 +16,6 @@
|
||||
#include "ui/widget.h"
|
||||
|
||||
namespace she {
|
||||
class Clipboard;
|
||||
class Display;
|
||||
class EventQueue;
|
||||
}
|
||||
@ -37,10 +36,8 @@ namespace ui {
|
||||
~Manager();
|
||||
|
||||
she::Display* getDisplay() { return m_display; }
|
||||
she::Clipboard* getClipboard() { return m_clipboard; }
|
||||
|
||||
void setDisplay(she::Display* display);
|
||||
void setClipboard(she::Clipboard* clipboard);
|
||||
|
||||
// Executes the main message loop.
|
||||
void run();
|
||||
@ -166,7 +163,6 @@ namespace ui {
|
||||
|
||||
WidgetsList m_garbage;
|
||||
she::Display* m_display;
|
||||
she::Clipboard* m_clipboard;
|
||||
she::EventQueue* m_eventQueue;
|
||||
gfx::Region m_invalidRegion; // Invalid region (we didn't receive paint messages yet for this).
|
||||
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include "ui/base.h"
|
||||
#include "ui/box.h"
|
||||
#include "ui/button.h"
|
||||
#include "ui/clipboard.h"
|
||||
#include "ui/combobox.h"
|
||||
#include "ui/component.h"
|
||||
#include "ui/cursor.h"
|
||||
|
Loading…
x
Reference in New Issue
Block a user