mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-06 03:39:51 +00:00
Move copy/paste of clipboard text from "ui" to "she" library
This commit is contained in:
parent
c1e26d0ac0
commit
896fb27fd5
@ -47,6 +47,7 @@
|
|||||||
#include "base/shared_ptr.h"
|
#include "base/shared_ptr.h"
|
||||||
#include "base/unique_ptr.h"
|
#include "base/unique_ptr.h"
|
||||||
#include "raster/sprite.h"
|
#include "raster/sprite.h"
|
||||||
|
#include "she/clipboard.h"
|
||||||
#include "she/display.h"
|
#include "she/display.h"
|
||||||
#include "she/surface.h"
|
#include "she/surface.h"
|
||||||
#include "she/system.h"
|
#include "she/system.h"
|
||||||
@ -61,6 +62,7 @@
|
|||||||
|
|
||||||
#ifdef ALLEGRO_WINDOWS
|
#ifdef ALLEGRO_WINDOWS
|
||||||
#include <winalleg.h>
|
#include <winalleg.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SPRITEDITOR_ACTION_COPYSELECTION "CopySelection"
|
#define SPRITEDITOR_ACTION_COPYSELECTION "CopySelection"
|
||||||
@ -134,6 +136,7 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
static she::Display* main_display = NULL;
|
static she::Display* main_display = NULL;
|
||||||
|
static she::Clipboard* main_clipboard = NULL;
|
||||||
static CustomizedGuiManager* manager = NULL;
|
static CustomizedGuiManager* manager = NULL;
|
||||||
static Theme* ase_theme = NULL;
|
static Theme* ase_theme = NULL;
|
||||||
|
|
||||||
@ -191,9 +194,12 @@ int init_module_gui()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
main_clipboard = she::Instance()->createClipboard();
|
||||||
|
|
||||||
// Create the default-manager
|
// Create the default-manager
|
||||||
manager = new CustomizedGuiManager();
|
manager = new CustomizedGuiManager();
|
||||||
manager->setDisplay(main_display);
|
manager->setDisplay(main_display);
|
||||||
|
manager->setClipboard(main_clipboard);
|
||||||
|
|
||||||
// Setup the GUI theme for all widgets
|
// Setup the GUI theme for all widgets
|
||||||
CurrentTheme::set(ase_theme = new SkinTheme());
|
CurrentTheme::set(ase_theme = new SkinTheme());
|
||||||
@ -236,6 +242,7 @@ void exit_module_gui()
|
|||||||
remove_keyboard();
|
remove_keyboard();
|
||||||
remove_mouse();
|
remove_mouse();
|
||||||
|
|
||||||
|
main_clipboard->dispose();
|
||||||
main_display->dispose();
|
main_display->dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
src/she/clipboard.h
Normal file
25
src/she/clipboard.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
// SHE library
|
||||||
|
// Copyright (C) 2012-2014 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 <string>
|
||||||
|
|
||||||
|
namespace she {
|
||||||
|
|
||||||
|
class Clipboard {
|
||||||
|
public:
|
||||||
|
virtual ~Clipboard() { }
|
||||||
|
virtual void dispose() = 0;
|
||||||
|
virtual std::string getText() = 0;
|
||||||
|
virtual void setText(const std::string& text) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace she
|
||||||
|
|
||||||
|
#endif
|
38
src/she/clipboard_simple.h
Normal file
38
src/she/clipboard_simple.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
// SHE library
|
||||||
|
// Copyright (C) 2012-2014 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() OVERRIDE {
|
||||||
|
return m_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setText(const std::string& text) {
|
||||||
|
m_text = text;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_text;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace she
|
||||||
|
|
||||||
|
#endif
|
76
src/she/clipboard_win.h
Normal file
76
src/she/clipboard_win.h
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
// SHE library
|
||||||
|
// Copyright (C) 2012-2014 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 "base/string.h"
|
||||||
|
#include "she/clipboard.h"
|
||||||
|
|
||||||
|
#pragma warning(disable:4996) // To void MSVC warning about std::copy() with unsafe arguments
|
||||||
|
|
||||||
|
namespace she {
|
||||||
|
|
||||||
|
class ClipboardImpl : public Clipboard {
|
||||||
|
public:
|
||||||
|
~ClipboardImpl() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispose() OVERRIDE {
|
||||||
|
delete this;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getText() OVERRIDE {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setText(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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string m_text;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace she
|
||||||
|
|
||||||
|
#endif
|
@ -1,5 +1,5 @@
|
|||||||
// SHE library
|
// SHE library
|
||||||
// Copyright (C) 2012-2013 David Capello
|
// Copyright (C) 2012-2014 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -8,6 +8,7 @@
|
|||||||
#define SHE_H_INCLUDED
|
#define SHE_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "she/clipboard.h"
|
||||||
#include "she/display.h"
|
#include "she/display.h"
|
||||||
#include "she/event.h"
|
#include "she/event.h"
|
||||||
#include "she/event_queue.h"
|
#include "she/event_queue.h"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// SHE library
|
// SHE library
|
||||||
// Copyright (C) 2012-2013 David Capello
|
// Copyright (C) 2012-2014 David Capello
|
||||||
//
|
//
|
||||||
// This file is released under the terms of the MIT license.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -26,6 +26,12 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#include "she/clipboard_win.h"
|
||||||
|
#else
|
||||||
|
#include "she/clipboard_simple.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "loadpng.h"
|
#include "loadpng.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@ -413,6 +419,10 @@ public:
|
|||||||
Alleg4Surface::AutoDestroy);
|
Alleg4Surface::AutoDestroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Clipboard* createClipboard() {
|
||||||
|
return new ClipboardImpl();
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static System* g_instance;
|
static System* g_instance;
|
||||||
|
@ -13,9 +13,10 @@
|
|||||||
|
|
||||||
namespace she {
|
namespace she {
|
||||||
|
|
||||||
class Surface;
|
class Clipboard;
|
||||||
class Display;
|
class Display;
|
||||||
class EventLoop;
|
class EventLoop;
|
||||||
|
class Surface;
|
||||||
|
|
||||||
class DisplayCreationException : std::runtime_error {
|
class DisplayCreationException : std::runtime_error {
|
||||||
public:
|
public:
|
||||||
@ -31,6 +32,7 @@ namespace she {
|
|||||||
virtual Display* createDisplay(int width, int height, int scale) = 0;
|
virtual Display* createDisplay(int width, int height, int scale) = 0;
|
||||||
virtual Surface* createSurface(int width, int height) = 0;
|
virtual Surface* createSurface(int width, int height) = 0;
|
||||||
virtual Surface* createSurfaceFromNativeHandle(void* nativeHandle) = 0;
|
virtual Surface* createSurfaceFromNativeHandle(void* nativeHandle) = 0;
|
||||||
|
virtual Clipboard* createClipboard() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
System* CreateSystem();
|
System* CreateSystem();
|
||||||
|
@ -10,22 +10,27 @@
|
|||||||
|
|
||||||
#include "ui/clipboard.h"
|
#include "ui/clipboard.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#include "she/clipboard.h"
|
||||||
#include "ui/clipboard_win.h"
|
#include "ui/manager.h"
|
||||||
#else
|
|
||||||
#include "ui/clipboard_none.h"
|
#include <string>
|
||||||
#endif
|
|
||||||
|
|
||||||
static std::string clipboard_text;
|
static std::string clipboard_text;
|
||||||
|
|
||||||
|
namespace ui {
|
||||||
|
namespace clipboard {
|
||||||
|
|
||||||
const char* ui::clipboard::get_text()
|
const char* ui::clipboard::get_text()
|
||||||
{
|
{
|
||||||
get_system_clipboard_text(clipboard_text);
|
clipboard_text = Manager::getDefault()->getClipboard()->getText();
|
||||||
return clipboard_text.c_str();
|
return clipboard_text.c_str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui::clipboard::set_text(const char* text)
|
void ui::clipboard::set_text(const char* text)
|
||||||
{
|
{
|
||||||
clipboard_text = text ? text: "";
|
clipboard_text = text ? text: "";
|
||||||
set_system_clipboard_text(clipboard_text);
|
Manager::getDefault()->getClipboard()->setText(clipboard_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace clipboard
|
||||||
|
} // namespace ui
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
// Aseprite UI Library
|
|
||||||
// Copyright (C) 2001-2014 David Capello
|
|
||||||
//
|
|
||||||
// This file is released under the terms of the MIT license.
|
|
||||||
// Read LICENSE.txt for more information.
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
void get_system_clipboard_text(std::string& text)
|
|
||||||
{
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
void set_system_clipboard_text(const std::string& text)
|
|
||||||
{
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -110,6 +110,7 @@ static void allegro_window_close_hook()
|
|||||||
Manager::Manager()
|
Manager::Manager()
|
||||||
: Widget(kManagerWidget)
|
: Widget(kManagerWidget)
|
||||||
, m_display(NULL)
|
, m_display(NULL)
|
||||||
|
, m_clipboard(NULL)
|
||||||
, m_eventQueue(NULL)
|
, m_eventQueue(NULL)
|
||||||
{
|
{
|
||||||
if (!m_defaultManager) {
|
if (!m_defaultManager) {
|
||||||
@ -184,6 +185,11 @@ void Manager::setDisplay(she::Display* display)
|
|||||||
m_eventQueue = m_display->getEventQueue();
|
m_eventQueue = m_display->getEventQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Manager::setClipboard(she::Clipboard* clipboard)
|
||||||
|
{
|
||||||
|
m_clipboard = clipboard;
|
||||||
|
}
|
||||||
|
|
||||||
void Manager::run()
|
void Manager::run()
|
||||||
{
|
{
|
||||||
MessageLoop loop(this);
|
MessageLoop loop(this);
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "ui/widget.h"
|
#include "ui/widget.h"
|
||||||
|
|
||||||
namespace she {
|
namespace she {
|
||||||
|
class Clipboard;
|
||||||
class Display;
|
class Display;
|
||||||
class EventQueue;
|
class EventQueue;
|
||||||
}
|
}
|
||||||
@ -35,7 +36,10 @@ namespace ui {
|
|||||||
~Manager();
|
~Manager();
|
||||||
|
|
||||||
she::Display* getDisplay() { return m_display; }
|
she::Display* getDisplay() { return m_display; }
|
||||||
|
she::Clipboard* getClipboard() { return m_clipboard; }
|
||||||
|
|
||||||
void setDisplay(she::Display* display);
|
void setDisplay(she::Display* display);
|
||||||
|
void setClipboard(she::Clipboard* clipboard);
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
|
||||||
@ -103,6 +107,7 @@ namespace ui {
|
|||||||
|
|
||||||
WidgetsList m_garbage;
|
WidgetsList m_garbage;
|
||||||
she::Display* m_display;
|
she::Display* m_display;
|
||||||
|
she::Clipboard* m_clipboard;
|
||||||
she::EventQueue* m_eventQueue;
|
she::EventQueue* m_eventQueue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ui/base.h"
|
#include "ui/base.h"
|
||||||
#include "ui/clipboard.h"
|
|
||||||
#include "ui/overlay_manager.h"
|
#include "ui/overlay_manager.h"
|
||||||
#include "ui/theme.h"
|
#include "ui/theme.h"
|
||||||
|
|
||||||
@ -39,9 +38,6 @@ GuiSystem::~GuiSystem()
|
|||||||
// finish theme
|
// finish theme
|
||||||
CurrentTheme::set(NULL);
|
CurrentTheme::set(NULL);
|
||||||
|
|
||||||
// destroy clipboard
|
|
||||||
clipboard::set_text(NULL);
|
|
||||||
|
|
||||||
// shutdown system
|
// shutdown system
|
||||||
_ji_widgets_exit();
|
_ji_widgets_exit();
|
||||||
_ji_font_exit();
|
_ji_font_exit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user