1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
/*
* PatternClipboard.h
* ------------------
* Purpose: Implementation of the pattern clipboard mechanism
* Notes : (currently none)
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#pragma once
#include "openmpt/all/BuildSettings.hpp"
#include "ResizableDialog.h"
#include "../soundlib/Snd_defs.h"
OPENMPT_NAMESPACE_BEGIN
struct PatternEditPos;
class PatternRect;
class CSoundFile;
struct PatternClipboardElement
{
std::string content;
CString description;
};
class PatternClipboard
{
friend class PatternClipboardDialog;
public:
enum PasteModes
{
pmOverwrite,
pmMixPaste,
pmMixPasteIT,
pmPasteFlood,
pmPushForward,
};
// Clipboard index type
using clipindex_t = size_t;
protected:
// The one and only pattern clipboard object
static PatternClipboard instance;
// Active internal clipboard index
clipindex_t m_activeClipboard = 0;
// Internal clipboard collection
std::vector<PatternClipboardElement> m_clipboards;
PatternClipboardElement m_channelClipboard;
PatternClipboardElement m_patternClipboard;
public:
// Copy a range of patterns to both the system clipboard and the internal clipboard.
static bool Copy(const CSoundFile &sndFile, ORDERINDEX first, ORDERINDEX last, bool onlyOrders);
// Copy a pattern selection to both the system clipboard and the internal clipboard.
static bool Copy(const CSoundFile &sndFile, PATTERNINDEX pattern, PatternRect selection);
// Copy a pattern or pattern channel to the internal pattern or channel clipboard.
static bool Copy(const CSoundFile &sndFile, PATTERNINDEX pattern, CHANNELINDEX channel = CHANNELINDEX_INVALID);
// Try pasting a pattern selection from the system clipboard.
static bool Paste(CSoundFile &sndFile, PatternEditPos &pastePos, PasteModes mode, PatternRect &pasteRect, bool &orderChanged);
// Try pasting a pattern selection from an internal clipboard.
static bool Paste(CSoundFile &sndFile, PatternEditPos &pastePos, PasteModes mode, PatternRect &pasteRect, clipindex_t internalClipboard, bool &orderChanged);
// Paste from pattern or channel clipboard.
static bool Paste(CSoundFile &sndFile, PATTERNINDEX pattern, CHANNELINDEX channel = CHANNELINDEX_INVALID);
// Copy one of the internal clipboards to the system clipboard.
static bool SelectClipboard(clipindex_t which);
// Switch to the next internal clipboard.
static bool CycleForward();
// Switch to the previous internal clipboard.
static bool CycleBackward();
// Set the maximum number of internal clipboards.
static void SetClipboardSize(clipindex_t maxEntries);
// Return the current number of clipboards.
static clipindex_t GetClipboardSize() { return instance.m_clipboards.size(); };
// Check whether patterns can be pasted from clipboard
static bool CanPaste();
protected:
PatternClipboard() { SetClipboardSize(1); };
static std::string GetFileExtension(const char *ext, bool addPadding);
static std::string FormatClipboardHeader(const CSoundFile &sndFile);
// Create the clipboard text for a pattern selection
static std::string CreateClipboardString(const CSoundFile &sndFile, PATTERNINDEX pattern, PatternRect selection);
// Parse clipboard string and perform the pasting operation.
static bool HandlePaste(CSoundFile &sndFile, PatternEditPos &pastePos, PasteModes mode, const std::string &data, PatternRect &pasteRect, bool &orderChanged);
// System-specific clipboard functions
static bool ToSystemClipboard(const PatternClipboardElement &clipboard) { return ToSystemClipboard(clipboard.content); };
static bool ToSystemClipboard(const std::string_view &data);
static bool FromSystemClipboard(std::string &data);
};
class PatternClipboardDialog : public ResizableDialog
{
protected:
// The one and only pattern clipboard dialog object
static PatternClipboardDialog instance;
// Edit class for clipboard name editing
class CInlineEdit : public CEdit
{
protected:
PatternClipboardDialog &parent;
public:
CInlineEdit(PatternClipboardDialog &dlg);
DECLARE_MESSAGE_MAP();
afx_msg void OnKillFocus(CWnd *newWnd);
};
CSpinButtonCtrl m_numClipboardsSpin;
CListBox m_clipList;
CInlineEdit m_editNameBox;
int m_posX = -1, m_posY = -1;
bool m_isLocked = true, m_isCreated = false;
public:
static void UpdateList();
static void Show();
static void Toggle()
{
if(instance.m_isCreated)
instance.OnCancel();
else
instance.Show();
}
protected:
PatternClipboardDialog();
void DoDataExchange(CDataExchange *pDX) override;
void OnOK() override;
void OnCancel() override;
afx_msg void OnNumClipboardsChanged();
afx_msg void OnSelectClipboard();
// Edit clipboard name
afx_msg void OnEditName();
void OnEndEdit(bool apply = true);
DECLARE_MESSAGE_MAP();
};
OPENMPT_NAMESPACE_END
|