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: push:
branches: branches:
- "master" - "master"
- "2.0"
jobs: jobs:
"sonarcloud": "sonarcloud":

View File

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

View File

@ -149,11 +149,12 @@ bool E2wxApp::OnInit() {
// wxLogWarning("%s", "a warning has occurred"); // wxLogWarning("%s", "a warning has occurred");
// wxLogInfo("%s", "informational"); // wxLogInfo("%s", "informational");
// wxLogVerbose("%s", "verbose"); // wxLogVerbose("%s", "verbose");
// wxFile().Open("foobar.txt"); // wxFile().Open("foobar.txt"); // <-- example of generating wx log message
// TODO wx log file window? // TODO wx log file window?
// TODO remove all logging from stdout/err to log file // 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 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 ID: " << this->GetID();
BOOST_LOG_TRIVIAL(info) << "Application version: " << this->GetVersion(); 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("btnDelete"), PreferencesDialog::OnDelete)
EVT_BUTTON(XRCID("btnRename"), PreferencesDialog::OnRename) EVT_BUTTON(XRCID("btnRename"), PreferencesDialog::OnRename)
wxEND_EVENT_TABLE() wxEND_EVENT_TABLE()
// TODO import external config file

View File

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

View File

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

View File

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

View File

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