Skip to content

Commit

Permalink
Merge pull request #546 from a740g/clipboard-fixes
Browse files Browse the repository at this point in the history
Fix #541 and update clip library
  • Loading branch information
a740g authored Sep 25, 2024
2 parents a699674 + ce56ee6 commit 8a5d77f
Show file tree
Hide file tree
Showing 17 changed files with 1,201 additions and 652 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ ifeq ($(OS),lnx)
endif

ifeq ($(OS),win)
CXXLIBS += -static-libgcc -static-libstdc++ -lcomdlg32 -lole32 -lshlwapi -lwindowscodecs
CXXLIBS += -static-libgcc -static-libstdc++ -lcomdlg32 -lole32 -luuid -lshlwapi -lwindowscodecs
CXXFLAGS += -DGLEW_STATIC -DFREEGLUT_STATIC
endif

Expand Down
5 changes: 4 additions & 1 deletion internal/c/parts/os/clipboard/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ ifeq ($(OS),lnx)
endif

ifeq ($(OS),win)
CLIP_SRCS += clip_win.cpp
CLIP_SRCS += \
clip_win.cpp \
clip_win_bmp.cpp \
clip_win_wic.cpp
endif

ifeq ($(OS),osx)
Expand Down
10 changes: 9 additions & 1 deletion internal/c/parts/os/clipboard/clip/clip.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Clip Library
// Copyright (c) 2015-2018 David Capello
// Copyright (c) 2015-2024 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand Down Expand Up @@ -72,6 +72,14 @@ bool lock::get_image_spec(image_spec& spec) const {

#endif // CLIP_ENABLE_IMAGE

#if CLIP_ENABLE_LIST_FORMATS

std::vector<format_info> lock::list_formats() const {
return p->list_formats();
}

#endif // CLIP_ENABLE_LIST_FORMATS

format empty_format() { return 0; }
format text_format() { return 1; }
#if CLIP_ENABLE_IMAGE
Expand Down
21 changes: 21 additions & 0 deletions internal/c/parts/os/clipboard/clip/clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <cassert>
#include <memory>
#include <string>
#include <vector>

namespace clip {

Expand All @@ -21,8 +22,22 @@ namespace clip {
// Clipboard format identifier.
typedef size_t format;

#if CLIP_ENABLE_IMAGE
class image;
struct image_spec;
#endif // CLIP_ENABLE_IMAGE

#if CLIP_ENABLE_LIST_FORMATS
struct format_info {
format id = 0;
std::string name;
format_info(const format id,
const std::string& name)
: id(id),
name(name) {
}
};
#endif // CLIP_ENABLE_LIST_FORMATS

class lock {
public:
Expand Down Expand Up @@ -58,6 +73,12 @@ namespace clip {
bool get_image_spec(image_spec& spec) const;
#endif // CLIP_ENABLE_IMAGE

#if CLIP_ENABLE_LIST_FORMATS
// Returns the list of available formats (by name) in the
// clipboard.
std::vector<format_info> list_formats() const;
#endif // CLIP_ENABLE_LIST_FORMATS

private:
class impl;
std::unique_ptr<impl> p;
Expand Down
2 changes: 2 additions & 0 deletions internal/c/parts/os/clipboard/clip/clip_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#define CLIP_COMMON_H_INCLUDED
#pragma once

#include "clip.h"

namespace clip {
namespace details {

Expand Down
9 changes: 8 additions & 1 deletion internal/c/parts/os/clipboard/clip/clip_lock_impl.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Clip Library
// Copyright (c) 2015-2018 David Capello
// Copyright (c) 2015-2024 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
Expand All @@ -20,9 +20,16 @@ class lock::impl {
bool set_data(format f, const char* buf, size_t len);
bool get_data(format f, char* buf, size_t len) const;
size_t get_data_length(format f) const;

#if CLIP_ENABLE_IMAGE
bool set_image(const image& image);
bool get_image(image& image) const;
bool get_image_spec(image_spec& spec) const;
#endif // CLIP_ENABLE_IMAGE

#if CLIP_ENABLE_LIST_FORMATS
std::vector<format_info> list_formats() const;
#endif // CLIP_ENABLE_LIST_FORMATS

private:
bool m_locked;
Expand Down
35 changes: 35 additions & 0 deletions internal/c/parts/os/clipboard/clip/clip_osx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Clip Library
// Copyright (c) 2024 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.

#ifndef CLIP_OSX_H_INCLUDED
#define CLIP_OSX_H_INCLUDED
#pragma once

#ifdef __OBJC__

#include <Cocoa/Cocoa.h>

namespace clip {

class image;
struct image_spec;

namespace osx {

#if CLIP_ENABLE_IMAGE

bool get_image_from_clipboard(NSPasteboard* pasteboard,
image* output_img,
image_spec* output_spec);

#endif // CLIP_ENABLE_IMAGE

} // namespace osx
} // namespace clip

#endif

#endif
16 changes: 11 additions & 5 deletions internal/c/parts/os/clipboard/clip/clip_osx.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@
std::map<std::string, format> g_name_to_format;
std::map<format, std::string> g_format_to_name;

}

namespace osx {

#if CLIP_ENABLE_IMAGE

bool get_image_from_clipboard(image* output_img,
bool get_image_from_clipboard(NSPasteboard* pasteboard,
image* output_img,
image_spec* output_spec)
{
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
NSString* result = [pasteboard availableTypeFromArray:
[NSArray arrayWithObjects:NSPasteboardTypeTIFF,NSPasteboardTypePNG,nil]];

Expand Down Expand Up @@ -137,7 +141,7 @@ bool get_image_from_clipboard(image* output_img,

#endif // CLIP_ENABLE_IMAGE

}
} // namespace osx

lock::impl::impl(void*) : m_locked(true) {
}
Expand Down Expand Up @@ -347,11 +351,13 @@ bool get_image_from_clipboard(image* output_img,
}

bool lock::impl::get_image(image& img) const {
return get_image_from_clipboard(&img, nullptr);
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
return osx::get_image_from_clipboard(pasteboard, &img, nullptr);
}

bool lock::impl::get_image_spec(image_spec& spec) const {
return get_image_from_clipboard(nullptr, &spec);
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
return osx::get_image_from_clipboard(pasteboard, nullptr, &spec);
}

#endif // CLIP_ENABLE_IMAGE
Expand Down
Loading

0 comments on commit 8a5d77f

Please sign in to comment.