Skip to content

Commit 8a5d77f

Browse files
authored
Merge pull request QB64-Phoenix-Edition#546 from a740g/clipboard-fixes
Fix QB64-Phoenix-Edition#541 and update clip library
2 parents a699674 + ce56ee6 commit 8a5d77f

17 files changed

+1201
-652
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ ifeq ($(OS),lnx)
150150
endif
151151

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

internal/c/parts/os/clipboard/build.mk

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ ifeq ($(OS),lnx)
1717
endif
1818

1919
ifeq ($(OS),win)
20-
CLIP_SRCS += clip_win.cpp
20+
CLIP_SRCS += \
21+
clip_win.cpp \
22+
clip_win_bmp.cpp \
23+
clip_win_wic.cpp
2124
endif
2225

2326
ifeq ($(OS),osx)

internal/c/parts/os/clipboard/clip/clip.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Clip Library
2-
// Copyright (c) 2015-2018 David Capello
2+
// Copyright (c) 2015-2024 David Capello
33
//
44
// This file is released under the terms of the MIT license.
55
// Read LICENSE.txt for more information.
@@ -72,6 +72,14 @@ bool lock::get_image_spec(image_spec& spec) const {
7272

7373
#endif // CLIP_ENABLE_IMAGE
7474

75+
#if CLIP_ENABLE_LIST_FORMATS
76+
77+
std::vector<format_info> lock::list_formats() const {
78+
return p->list_formats();
79+
}
80+
81+
#endif // CLIP_ENABLE_LIST_FORMATS
82+
7583
format empty_format() { return 0; }
7684
format text_format() { return 1; }
7785
#if CLIP_ENABLE_IMAGE

internal/c/parts/os/clipboard/clip/clip.h

+21
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <cassert>
1212
#include <memory>
1313
#include <string>
14+
#include <vector>
1415

1516
namespace clip {
1617

@@ -21,8 +22,22 @@ namespace clip {
2122
// Clipboard format identifier.
2223
typedef size_t format;
2324

25+
#if CLIP_ENABLE_IMAGE
2426
class image;
2527
struct image_spec;
28+
#endif // CLIP_ENABLE_IMAGE
29+
30+
#if CLIP_ENABLE_LIST_FORMATS
31+
struct format_info {
32+
format id = 0;
33+
std::string name;
34+
format_info(const format id,
35+
const std::string& name)
36+
: id(id),
37+
name(name) {
38+
}
39+
};
40+
#endif // CLIP_ENABLE_LIST_FORMATS
2641

2742
class lock {
2843
public:
@@ -58,6 +73,12 @@ namespace clip {
5873
bool get_image_spec(image_spec& spec) const;
5974
#endif // CLIP_ENABLE_IMAGE
6075

76+
#if CLIP_ENABLE_LIST_FORMATS
77+
// Returns the list of available formats (by name) in the
78+
// clipboard.
79+
std::vector<format_info> list_formats() const;
80+
#endif // CLIP_ENABLE_LIST_FORMATS
81+
6182
private:
6283
class impl;
6384
std::unique_ptr<impl> p;

internal/c/parts/os/clipboard/clip/clip_common.h

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define CLIP_COMMON_H_INCLUDED
99
#pragma once
1010

11+
#include "clip.h"
12+
1113
namespace clip {
1214
namespace details {
1315

internal/c/parts/os/clipboard/clip/clip_lock_impl.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Clip Library
2-
// Copyright (c) 2015-2018 David Capello
2+
// Copyright (c) 2015-2024 David Capello
33
//
44
// This file is released under the terms of the MIT license.
55
// Read LICENSE.txt for more information.
@@ -20,9 +20,16 @@ class lock::impl {
2020
bool set_data(format f, const char* buf, size_t len);
2121
bool get_data(format f, char* buf, size_t len) const;
2222
size_t get_data_length(format f) const;
23+
24+
#if CLIP_ENABLE_IMAGE
2325
bool set_image(const image& image);
2426
bool get_image(image& image) const;
2527
bool get_image_spec(image_spec& spec) const;
28+
#endif // CLIP_ENABLE_IMAGE
29+
30+
#if CLIP_ENABLE_LIST_FORMATS
31+
std::vector<format_info> list_formats() const;
32+
#endif // CLIP_ENABLE_LIST_FORMATS
2633

2734
private:
2835
bool m_locked;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Clip Library
2+
// Copyright (c) 2024 David Capello
3+
//
4+
// This file is released under the terms of the MIT license.
5+
// Read LICENSE.txt for more information.
6+
7+
#ifndef CLIP_OSX_H_INCLUDED
8+
#define CLIP_OSX_H_INCLUDED
9+
#pragma once
10+
11+
#ifdef __OBJC__
12+
13+
#include <Cocoa/Cocoa.h>
14+
15+
namespace clip {
16+
17+
class image;
18+
struct image_spec;
19+
20+
namespace osx {
21+
22+
#if CLIP_ENABLE_IMAGE
23+
24+
bool get_image_from_clipboard(NSPasteboard* pasteboard,
25+
image* output_img,
26+
image_spec* output_spec);
27+
28+
#endif // CLIP_ENABLE_IMAGE
29+
30+
} // namespace osx
31+
} // namespace clip
32+
33+
#endif
34+
35+
#endif

internal/c/parts/os/clipboard/clip/clip_osx.mm

+11-5
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@
2424
std::map<std::string, format> g_name_to_format;
2525
std::map<format, std::string> g_format_to_name;
2626

27+
}
28+
29+
namespace osx {
30+
2731
#if CLIP_ENABLE_IMAGE
2832

29-
bool get_image_from_clipboard(image* output_img,
33+
bool get_image_from_clipboard(NSPasteboard* pasteboard,
34+
image* output_img,
3035
image_spec* output_spec)
3136
{
32-
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
3337
NSString* result = [pasteboard availableTypeFromArray:
3438
[NSArray arrayWithObjects:NSPasteboardTypeTIFF,NSPasteboardTypePNG,nil]];
3539

@@ -137,7 +141,7 @@ bool get_image_from_clipboard(image* output_img,
137141

138142
#endif // CLIP_ENABLE_IMAGE
139143

140-
}
144+
} // namespace osx
141145

142146
lock::impl::impl(void*) : m_locked(true) {
143147
}
@@ -347,11 +351,13 @@ bool get_image_from_clipboard(image* output_img,
347351
}
348352

349353
bool lock::impl::get_image(image& img) const {
350-
return get_image_from_clipboard(&img, nullptr);
354+
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
355+
return osx::get_image_from_clipboard(pasteboard, &img, nullptr);
351356
}
352357

353358
bool lock::impl::get_image_spec(image_spec& spec) const {
354-
return get_image_from_clipboard(nullptr, &spec);
359+
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
360+
return osx::get_image_from_clipboard(pasteboard, nullptr, &spec);
355361
}
356362

357363
#endif // CLIP_ENABLE_IMAGE

0 commit comments

Comments
 (0)