2017-08-05 20:42:48 +02:00
|
|
|
#include <QtGui>
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QClipboard>
|
|
|
|
|
2021-07-19 19:35:16 +02:00
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
2017-08-05 20:42:48 +02:00
|
|
|
// DECLARATIONS SPLIT TO AVOID CONFLICT OF TYPES
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
uint32_t *getrplstackobject(int level, int *size);
|
|
|
|
char *getdecompiledrplobject(int level, int *strsize);
|
|
|
|
void pushobject(char *data, int sizebytes);
|
|
|
|
void pushtext(char *data, int sizebytes);
|
|
|
|
void removestackobject(int level, int nitems);
|
|
|
|
int compileobject();
|
2021-07-19 19:35:16 +02:00
|
|
|
void fullscreenupdate();
|
|
|
|
void palette2list(uint32_t *buffer,int *size);
|
|
|
|
void list2palette(uint32_t *buffer);
|
|
|
|
int getrplobjsize(uint32_t *object);
|
|
|
|
int palettesize();
|
2017-08-05 20:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// COPY OBJECT FROM THE STACK INTO THE HOST CLIPBOARD
|
2020-01-22 00:34:44 +01:00
|
|
|
void Stack2Clipboard(int level, int dropit)
|
2017-08-05 20:42:48 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
uint32_t *obj;
|
|
|
|
int size;
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
obj = getrplstackobject(level, &size);
|
2017-08-05 20:42:48 +02:00
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
if(!obj)
|
|
|
|
return;
|
2017-08-05 20:42:48 +02:00
|
|
|
|
|
|
|
QClipboard *clip = qApp->clipboard();
|
2020-01-22 00:34:44 +01:00
|
|
|
QMimeData *data = new QMimeData;
|
2017-08-05 20:42:48 +02:00
|
|
|
QByteArray buffer;
|
2020-01-22 00:34:44 +01:00
|
|
|
buffer.append((const char *)obj, size * sizeof(int32_t));
|
2017-08-05 20:42:48 +02:00
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
data->setData(QString("application/newrpl-object"), buffer);
|
2017-08-05 20:42:48 +02:00
|
|
|
|
|
|
|
char *text;
|
|
|
|
int strsize;
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
text = getdecompiledrplobject(level, &strsize);
|
2017-08-05 20:42:48 +02:00
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
if(!text)
|
|
|
|
return;
|
2017-08-05 20:42:48 +02:00
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
QByteArray decomptext((const char *)text, strsize);
|
2017-08-05 20:42:48 +02:00
|
|
|
QString utf8string(decomptext);
|
2020-12-28 23:43:29 +01:00
|
|
|
data->setText(utf8string); // PLAIN TEXT
|
|
|
|
//data->setData(QString("text/plain;charset=utf-8"),decomptext); // UTF-8 ENCODED TEXT
|
|
|
|
//data->setHtml(utf8string);
|
2020-01-22 00:34:44 +01:00
|
|
|
clip->setMimeData(data, QClipboard::Clipboard);
|
2017-08-05 20:42:48 +02:00
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
if(dropit)
|
|
|
|
removestackobject(level, 1);
|
2017-08-05 20:42:48 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// PUSH THE CLIPBOARD IN THE STACK
|
|
|
|
void Clipboard2Stack()
|
|
|
|
{
|
|
|
|
QClipboard *clip = qApp->clipboard();
|
2020-01-22 00:34:44 +01:00
|
|
|
const QMimeData *data = clip->mimeData();
|
2017-08-05 20:42:48 +02:00
|
|
|
|
2020-02-01 00:18:15 +01:00
|
|
|
// DEBUG ONLY
|
|
|
|
for(QString& formatName: data->formats()) {
|
|
|
|
std::string s;
|
|
|
|
s = formatName.toStdString();
|
|
|
|
|
|
|
|
QByteArray arr = clip->mimeData()->data(formatName);
|
|
|
|
qDebug() << "name=" << s.c_str() << ", size=" << arr.size();
|
|
|
|
qDebug() << "\nContents:\n";
|
|
|
|
qDebug() << QString::fromUtf8(arr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
qDebug() << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-08-05 20:42:48 +02:00
|
|
|
if(data->hasFormat(QString("application/newrpl-object"))) {
|
|
|
|
QByteArray mydata(data->data(QString("application/newrpl-object")));
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
pushobject(mydata.data(), mydata.size());
|
2017-08-05 20:42:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data->hasText()) {
|
|
|
|
QByteArray mydata(data->text().toUtf8());
|
2020-01-22 00:34:44 +01:00
|
|
|
pushtext(mydata.data(), mydata.size());
|
2017-08-05 20:42:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-07 19:14:55 +01:00
|
|
|
void Clipboard2StackCompile()
|
|
|
|
{
|
|
|
|
QClipboard *clip = qApp->clipboard();
|
2020-01-22 00:34:44 +01:00
|
|
|
const QMimeData *data = clip->mimeData();
|
2019-03-07 19:14:55 +01:00
|
|
|
|
|
|
|
if(data->hasFormat(QString("application/newrpl-object"))) {
|
|
|
|
QByteArray mydata(data->data(QString("application/newrpl-object")));
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
pushobject(mydata.data(), mydata.size());
|
2019-03-07 19:14:55 +01:00
|
|
|
compileobject();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(data->hasText()) {
|
|
|
|
QByteArray mydata(data->text().toUtf8());
|
2020-01-22 00:34:44 +01:00
|
|
|
pushtext(mydata.data(), mydata.size());
|
2019-03-07 19:14:55 +01:00
|
|
|
compileobject();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
int SaveRPLObject(QString & filename, int level)
|
2017-08-05 20:42:48 +02:00
|
|
|
{
|
|
|
|
uint32_t *obj;
|
|
|
|
int size;
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
obj = getrplstackobject(level, &size);
|
2017-08-05 20:42:48 +02:00
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
if(!obj)
|
|
|
|
return 0;
|
2017-08-05 20:42:48 +02:00
|
|
|
|
|
|
|
QFile f(filename);
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
if(!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
2017-08-05 20:42:48 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
const char *fileprolog = "NRPL";
|
|
|
|
f.write(fileprolog, 4);
|
|
|
|
f.write((const char *)obj, size * 4);
|
2017-08-05 20:42:48 +02:00
|
|
|
f.close();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-07-19 19:35:16 +02:00
|
|
|
int SaveRPLObjectbyPointer(QString & filename, uint32_t * obj)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
|
|
|
|
if(!obj)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
size=getrplobjsize(obj);
|
|
|
|
|
|
|
|
QFile f(filename);
|
|
|
|
|
|
|
|
if(!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *fileprolog = "NRPL";
|
|
|
|
f.write(fileprolog, 4);
|
|
|
|
f.write((const char *)obj, size * 4);
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
int LoadRPLObject(QString & filename)
|
2017-08-05 20:42:48 +02:00
|
|
|
{
|
2020-01-16 19:12:43 +01:00
|
|
|
|
2017-08-05 20:42:48 +02:00
|
|
|
int size;
|
|
|
|
|
|
|
|
QFile f(filename);
|
|
|
|
|
|
|
|
if(!f.open(QIODevice::ReadOnly)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
size = f.size();
|
|
|
|
if(size & 3)
|
|
|
|
return 0;
|
|
|
|
QByteArray data = f.read(f.size());
|
2017-08-05 20:42:48 +02:00
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
if((data.at(0) != 'N') || (data.at(1) != 'R') || (data.at(2) != 'P')
|
|
|
|
|| (data.at(3) != 'L'))
|
2017-08-05 20:42:48 +02:00
|
|
|
return 0;
|
|
|
|
|
2020-01-22 00:34:44 +01:00
|
|
|
pushobject(data.data() + 4, data.size() - 4);
|
2017-08-05 20:42:48 +02:00
|
|
|
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
}
|
2021-07-19 19:35:16 +02:00
|
|
|
|
|
|
|
void FullScreenUpdate()
|
|
|
|
{
|
|
|
|
fullscreenupdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
int SaveColorTheme(QString & filename)
|
|
|
|
{
|
|
|
|
int palette_size = palettesize();
|
|
|
|
uint32_t buffer[palette_size*3+2];
|
|
|
|
int size=palette_size*3+2;
|
|
|
|
palette2list(buffer,&size);
|
|
|
|
if(size) return SaveRPLObjectbyPointer(filename,buffer);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int LoadColorTheme(QString & filename)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
QFile f(filename);
|
|
|
|
|
|
|
|
if(!f.open(QIODevice::ReadOnly)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = f.size();
|
|
|
|
if(size & 3)
|
|
|
|
return 0;
|
|
|
|
QByteArray data = f.read(f.size());
|
|
|
|
|
|
|
|
if((data.at(0) != 'N') || (data.at(1) != 'R') || (data.at(2) != 'P')
|
|
|
|
|| (data.at(3) != 'L'))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
list2palette(((uint32_t *)data.constData())+1);
|
|
|
|
|
|
|
|
f.close();
|
|
|
|
|
|
|
|
FullScreenUpdate();
|
|
|
|
return 1;
|
|
|
|
}
|