use wx for clipboard handling; slight refactor

This commit is contained in:
Christopher A. Mosher 2022-12-14 21:05:04 -05:00
parent 1438999790
commit 513e27e64a
8 changed files with 35 additions and 33 deletions

View File

@ -3,6 +3,7 @@ on:
push:
branches:
- "master"
- "2.0"
jobs:
"sonarcloud":

View File

@ -1,7 +1,7 @@
/*
/*
* File: Cpu6502.cpp
* Author: Christopher
*
*
* Created on December 12, 2013, 10:14 PM
*/
@ -33,6 +33,7 @@ void Cpu6502::clock(bool phase) {
setPins(PinSettings{std::make_pair(common.CLK0,phase)});
rw();
// TODO turn these into trace log settings
#ifdef TRACEREG
this->trace.dumpRegisters();
#endif

View File

@ -149,11 +149,12 @@ bool E2wxApp::OnInit() {
// wxLogWarning("%s", "a warning has occurred");
// wxLogInfo("%s", "informational");
// wxLogVerbose("%s", "verbose");
// wxFile().Open("foobar.txt");
// wxFile().Open("foobar.txt"); // <-- example of generating wx log message
// TODO wx log file window?
// TODO remove all logging from stdout/err to log file
// TODO define components to turn on/off for trace level logging (disk, cassette, woz, keyboard, ram, lss, audio, etc.)
// TODO why are log messages getting buffered? (It ruins the timestamp.)
BOOST_LOG_TRIVIAL(info) << "Application ID: " << this->GetID();
BOOST_LOG_TRIVIAL(info) << "Application version: " << this->GetVersion();

View File

@ -33,7 +33,7 @@ wxBEGIN_EVENT_TABLE(PreferencesDialog, wxDialog)
EVT_BUTTON(XRCID("btnDelete"), PreferencesDialog::OnDelete)
EVT_BUTTON(XRCID("btnRename"), PreferencesDialog::OnRename)
wxEND_EVENT_TABLE()
// TODO import external config file

View File

@ -17,22 +17,25 @@
*/
#include "clipboardhandler.h"
#include <SDL.h>
#include <limits.h>
#include <wx/clipbrd.h>
ClipboardHandler::ClipboardHandler()
{
ClipboardHandler::ClipboardHandler() {
}
ClipboardHandler::~ClipboardHandler()
{
ClipboardHandler::~ClipboardHandler() {
}
std::string ClipboardHandler::getText()
{
std::string ret;
char* sdlAllocatedText = SDL_GetClipboardText();
ret.assign(sdlAllocatedText);
SDL_free(sdlAllocatedText);
wxString ClipboardHandler::getText() {
wxString ret;
if (wxTheClipboard->Open())
{
if (wxTheClipboard->IsSupported(wxDF_TEXT)) {
wxTextDataObject data;
wxTheClipboard->GetData(data);
ret = data.GetText();
}
wxTheClipboard->Close();
}
return ret;
}

View File

@ -18,16 +18,14 @@
#ifndef CLIPBOARDHANDLER_H
#define CLIPBOARDHANDLER_H
#include <string>
#include <wx/string.h>
class ClipboardHandler
{
class ClipboardHandler {
public:
ClipboardHandler();
~ClipboardHandler();
std::string getText();
wxString getText();
};
#endif

View File

@ -22,6 +22,7 @@
#include "e2const.h"
#include <wx/msgdlg.h>
#include <wx/string.h>
#include <SDL.h>
@ -363,16 +364,13 @@ void Emulator::powerOffComputer() {
void Emulator::paste() {
// Feed input from the clipboard to the Apple keyboard
std::string s = this->clip.getText();
for (unsigned int i = 0; i < s.length(); ++i) {
unsigned char key = s[i];
// TODO fix pasting line-endings
if (key == '\n')
key = '\r';
if ('a' <= key && key <= 'z') {
key -= 32;
}
this->keypresses.push(key);
wxString s = this->clip.getText();
s.Replace("\n\r", "\r\n");
s.Replace("\r\n", "\r");
s.Replace("\n", "\r");
s.MakeUpper();
for (auto c : s) {
this->keypresses.push(c);
}
}

View File

@ -18,8 +18,8 @@
#ifndef KEYBOARD_H
#define KEYBOARD_H
#include <SDL.h>
#include <queue>
#include <cstdint>
typedef std::queue<unsigned char> KeypressQueue;
@ -31,7 +31,7 @@ class Keyboard {
unsigned char latch;
unsigned char cGet;
Uint32 lastGet;
uint32_t lastGet;
public:
Keyboard(KeypressQueue& q, KeyboardBufferMode& buffered);