This is an automated email from the git hooks/post-receive script. thansen pushed a commit to branch master in repository aseprite.
commit 924c2ac86ae2882b5e5a7fee8828bad220d615a8 Author: David Capello <[email protected]> Date: Thu Apr 28 23:26:20 2016 -0300 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. --- .gitmodules | 3 ++ src/CMakeLists.txt | 1 + src/app/CMakeLists.txt | 1 + src/app/modules/gui.cpp | 6 --- src/clip | 1 + src/she/CMakeLists.txt | 2 - src/she/clipboard.h | 27 ------------- src/she/clipboard_simple.h | 38 ------------------- src/she/common/system.h | 14 ------- src/she/osx/clipboard.h | 28 -------------- src/she/osx/clipboard.mm | 36 ------------------ src/she/she.h | 1 - src/she/system.h | 2 - src/she/win/clipboard.cpp | 94 ---------------------------------------------- src/she/win/clipboard.h | 28 -------------- src/ui/CMakeLists.txt | 1 - src/ui/clipboard.cpp | 42 --------------------- src/ui/clipboard.h | 22 ----------- src/ui/clipboard_win.h | 55 --------------------------- src/ui/entry.cpp | 13 +++---- src/ui/manager.cpp | 6 --- src/ui/manager.h | 4 -- src/ui/ui.h | 1 - 23 files changed, 11 insertions(+), 415 deletions(-) diff --git a/.gitmodules b/.gitmodules index 630ab02..a2126b7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8585516..ee97662 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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) diff --git a/src/app/CMakeLists.txt b/src/app/CMakeLists.txt index 2c0e402..04eea0a 100644 --- a/src/app/CMakeLists.txt +++ b/src/app/CMakeLists.txt @@ -439,6 +439,7 @@ add_library(app-lib target_link_libraries(app-lib base-lib cfg-lib + clip css-lib doc-lib filters-lib diff --git a/src/app/modules/gui.cpp b/src/app/modules/gui.cpp index 49eb8e6..6b4b1e6 100644 --- a/src/app/modules/gui.cpp +++ b/src/app/modules/gui.cpp @@ -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(); } diff --git a/src/clip b/src/clip new file mode 160000 index 0000000..e57130a --- /dev/null +++ b/src/clip @@ -0,0 +1 @@ +Subproject commit e57130a56659d001d7bc33081c7cb3abe0621be2 diff --git a/src/she/CMakeLists.txt b/src/she/CMakeLists.txt index 1841aa6..77b3090 100644 --- a/src/she/CMakeLists.txt +++ b/src/she/CMakeLists.txt @@ -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() diff --git a/src/she/clipboard.h b/src/she/clipboard.h deleted file mode 100644 index 01397b0..0000000 --- a/src/she/clipboard.h +++ /dev/null @@ -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 diff --git a/src/she/clipboard_simple.h b/src/she/clipboard_simple.h deleted file mode 100644 index 5e7fb9c..0000000 --- a/src/she/clipboard_simple.h +++ /dev/null @@ -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 diff --git a/src/she/common/system.h b/src/she/common/system.h index f03a0ce..54097eb 100644 --- a/src/she/common/system.h +++ b/src/she/common/system.h @@ -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; diff --git a/src/she/osx/clipboard.h b/src/she/osx/clipboard.h deleted file mode 100644 index 94f350f..0000000 --- a/src/she/osx/clipboard.h +++ /dev/null @@ -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 diff --git a/src/she/osx/clipboard.mm b/src/she/osx/clipboard.mm deleted file mode 100644 index 0acccd9..0000000 --- a/src/she/osx/clipboard.mm +++ /dev/null @@ -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 diff --git a/src/she/she.h b/src/she/she.h index 44d0bec..87c334b 100644 --- a/src/she/she.h +++ b/src/she/she.h @@ -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" diff --git a/src/she/system.h b/src/she/system.h index 2b1535b..9cf224b 100644 --- a/src/she/system.h +++ b/src/she/system.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(); diff --git a/src/she/win/clipboard.cpp b/src/she/win/clipboard.cpp deleted file mode 100644 index b2e5460..0000000 --- a/src/she/win/clipboard.cpp +++ /dev/null @@ -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 diff --git a/src/she/win/clipboard.h b/src/she/win/clipboard.h deleted file mode 100644 index 479459b..0000000 --- a/src/she/win/clipboard.h +++ /dev/null @@ -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 diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt index b787daf..72e1adc 100644 --- a/src/ui/CMakeLists.txt +++ b/src/ui/CMakeLists.txt @@ -10,7 +10,6 @@ add_library(ui-lib alert.cpp box.cpp button.cpp - clipboard.cpp combobox.cpp component.cpp cursor.cpp diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp deleted file mode 100644 index dc07b2f..0000000 --- a/src/ui/clipboard.cpp +++ /dev/null @@ -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 diff --git a/src/ui/clipboard.h b/src/ui/clipboard.h deleted file mode 100644 index abf43cf..0000000 --- a/src/ui/clipboard.h +++ /dev/null @@ -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 diff --git a/src/ui/clipboard_win.h b/src/ui/clipboard_win.h deleted file mode 100644 index 696f068..0000000 --- a/src/ui/clipboard_win.h +++ /dev/null @@ -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(); - } - } -} - -} diff --git a/src/ui/entry.cpp b/src/ui/entry.cpp index 647c82d..c382b09 100644 --- a/src/ui/entry.cpp +++ b/src/ui/entry.cpp @@ -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; diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index 7f3ea7a..1317f68 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -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); diff --git a/src/ui/manager.h b/src/ui/manager.h index cbc938d..520a3a8 100644 --- a/src/ui/manager.h +++ b/src/ui/manager.h @@ -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). diff --git a/src/ui/ui.h b/src/ui/ui.h index f5b4f99..039e6c3 100644 --- a/src/ui/ui.h +++ b/src/ui/ui.h @@ -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" -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git _______________________________________________ Pkg-games-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

