mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-05-12 12:00:13 +00:00
Implement internal clipboard support
This commit is contained in:
parent
6bcb68b74c
commit
f5a32ef466
|
@ -25,18 +25,29 @@ extern const int32_t nextimg; // used by sub__clipboardimage()
|
|||
extern const uint8_t charset8x8[256][8][8]; // used by sub__clipboardimage()
|
||||
extern const uint8_t charset8x16[256][16][8]; // used by sub__clipboardimage()
|
||||
|
||||
// This is used as a fallback internal clipboard should any text clipboard functions below fail
|
||||
static std::string g_InternalClipboard;
|
||||
|
||||
/// @brief Gets text (if present) in the OS clipboard.
|
||||
/// @return A qbs string.
|
||||
qbs *func__clipboard() {
|
||||
std::string text;
|
||||
qbs *qbsText;
|
||||
|
||||
IMAGE_DEBUG_PRINT("Attempting to get OS clipboard text");
|
||||
|
||||
if (clip::has(clip::text_format()) && clip::get_text(text)) {
|
||||
IMAGE_DEBUG_PRINT("Getting OS clipboard text");
|
||||
|
||||
qbsText = qbs_new(text.length(), 1);
|
||||
if (qbsText->len)
|
||||
memcpy(qbsText->chr, text.data(), qbsText->len);
|
||||
} else {
|
||||
qbsText = qbs_new(0, 1);
|
||||
IMAGE_DEBUG_PRINT("Falling back to internal clipboard");
|
||||
|
||||
qbsText = qbs_new(g_InternalClipboard.length(), 1);
|
||||
if (qbsText->len)
|
||||
memcpy(qbsText->chr, g_InternalClipboard.data(), qbsText->len);
|
||||
}
|
||||
|
||||
return qbsText;
|
||||
|
@ -47,8 +58,10 @@ qbs *func__clipboard() {
|
|||
void sub__clipboard(const qbs *qbsText) {
|
||||
std::string text(reinterpret_cast<const char *>(qbsText->chr), qbsText->len);
|
||||
|
||||
if (qbsText->len)
|
||||
if (qbsText->len) {
|
||||
clip::set_text(text);
|
||||
g_InternalClipboard = text;
|
||||
}
|
||||
}
|
||||
|
||||
static constexpr inline int clipboard_scale_5bits_to_8bits(const int v) { return (v << 3) | (v >> 2); }
|
||||
|
|
Loading…
Reference in a new issue