forked from Mirrors/openclonk
C4AbstractApp: Remove StdStrBuf
parent
c5ed6e7dc8
commit
22f42123e8
|
@ -2330,7 +2330,7 @@ namespace C4GUI
|
|||
bool fHasOK;
|
||||
int32_t *piConfigDontShowAgainSetting;
|
||||
class C4KeyBinding *pKeyCopy;
|
||||
StdCopyStrBuf sCopyText; // text that goes into clipboard if user presses Ctrl+C on this window
|
||||
std::string sCopyText; // text that goes into clipboard if user presses Ctrl+C on this window
|
||||
public:
|
||||
enum Buttons { btnOK=1, btnAbort=2, btnYes=4, btnNo=8, btnRetry=16, btnReset=32,
|
||||
btnOKAbort=btnOK|btnAbort, btnYesNo=btnYes|btnNo, btnRetryAbort=btnRetry|btnAbort
|
||||
|
|
|
@ -946,7 +946,7 @@ namespace C4GUI
|
|||
// resize to actually needed size
|
||||
SetClientSize(GetClientRect().Wdt, GetClientRect().Hgt - caMain.GetHeight());
|
||||
// Control+C copies text to clipboard
|
||||
sCopyText.Format("[%s] %s", szCaption ? szCaption : "", szMessage ? szMessage : "");
|
||||
sCopyText = strprintf("[%s] %s", szCaption ? szCaption : "", szMessage ? szMessage : "");
|
||||
pKeyCopy = new C4KeyBinding(C4KeyCodeEx(K_C, KEYS_Control), "GUIEditCopy", KEYSCOPE_Gui,
|
||||
new DlgKeyCB<MessageDialog>(*this, &MessageDialog::KeyCopy), C4CustomKey::PRIO_CtrlOverride);
|
||||
}
|
||||
|
|
|
@ -291,11 +291,10 @@ namespace C4GUI
|
|||
// get selected range
|
||||
int32_t iSelBegin = std::min(iSelectionStart, iSelectionEnd), iSelEnd = std::max(iSelectionStart, iSelectionEnd);
|
||||
if (iSelBegin == iSelEnd) return false;
|
||||
StdStrBuf buf;
|
||||
// allocate a global memory object for the text.
|
||||
buf.Append(Text+iSelBegin, iSelEnd-iSelBegin);
|
||||
std::string buf(Text+iSelBegin, iSelEnd-iSelBegin);
|
||||
if (cPasswordMask)
|
||||
memset(buf.getMData(), cPasswordMask, buf.getLength());
|
||||
buf.assign(buf.size(), cPasswordMask);
|
||||
|
||||
return Application.Copy(buf);
|
||||
}
|
||||
|
@ -315,7 +314,7 @@ namespace C4GUI
|
|||
bool fSuccess = false;
|
||||
// check clipboard contents
|
||||
if(!Application.IsClipboardFull()) return false;
|
||||
StdStrBuf text(Application.Paste());
|
||||
StdCopyStrBuf text(Application.Paste().c_str());
|
||||
char * szText = text.getMData();
|
||||
if (text)
|
||||
{
|
||||
|
|
|
@ -81,9 +81,9 @@ public:
|
|||
bool fQuitMsgReceived; // if true, a quit message has been received and the application should terminate
|
||||
|
||||
// Copy the text to the clipboard or the primary selection
|
||||
bool Copy(const StdStrBuf & text, bool fClipboard = true);
|
||||
bool Copy(const std::string &text, bool fClipboard = true);
|
||||
// Paste the text from the clipboard or the primary selection
|
||||
StdStrBuf Paste(bool fClipboard = true);
|
||||
std::string Paste(bool fClipboard = true);
|
||||
// Is there something in the clipboard?
|
||||
bool IsClipboardFull(bool fClipboard = true);
|
||||
// a command from stdin
|
||||
|
@ -95,8 +95,8 @@ public:
|
|||
// notify user to get back to the program
|
||||
void NotifyUserIfInactive();
|
||||
void MessageDialog(const char * message);
|
||||
const char *GetLastError() { return sLastError.getData(); }
|
||||
void Error(const char * m) { sLastError.Copy(m); }
|
||||
const char *GetLastError() { return sLastError.c_str(); }
|
||||
void Error(const char * m) { sLastError = m; }
|
||||
|
||||
#ifdef _WIN32
|
||||
private:
|
||||
|
@ -139,7 +139,7 @@ protected:
|
|||
|
||||
#ifdef __APPLE__
|
||||
public:
|
||||
StdStrBuf GetGameDataPath();
|
||||
std::string GetGameDataPath();
|
||||
#endif
|
||||
|
||||
#ifdef USE_WIN32_WINDOWS
|
||||
|
@ -153,7 +153,7 @@ protected:
|
|||
#endif
|
||||
|
||||
protected:
|
||||
StdStrBuf sLastError;
|
||||
std::string sLastError;
|
||||
bool fDspModeSet; // true if display mode was changed
|
||||
virtual bool DoInit(int argc, char * argv[]) = 0;
|
||||
|
||||
|
|
|
@ -31,11 +31,11 @@
|
|||
#import "platform/C4WindowController.h"
|
||||
#import "graphics/C4DrawGLMac.h"
|
||||
|
||||
bool C4AbstractApp::Copy(const StdStrBuf & text, bool fClipboard)
|
||||
bool C4AbstractApp::Copy(const std::string &text, bool fClipboard)
|
||||
{
|
||||
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
||||
[pasteboard declareTypes:[NSArray arrayWithObject:NSStringPboardType] owner:nil];
|
||||
NSString* string = [NSString stringWithCString:text.getData() encoding:NSUTF8StringEncoding];
|
||||
NSString* string = [NSString stringWithCString:text.c_str() encoding:NSUTF8StringEncoding];
|
||||
if (![pasteboard setString:string forType:NSStringPboardType])
|
||||
{
|
||||
Log("Writing to Cocoa pasteboard failed");
|
||||
|
@ -44,15 +44,15 @@ bool C4AbstractApp::Copy(const StdStrBuf & text, bool fClipboard)
|
|||
return true;
|
||||
}
|
||||
|
||||
StdStrBuf C4AbstractApp::Paste(bool fClipboard)
|
||||
std::string C4AbstractApp::Paste(bool fClipboard)
|
||||
{
|
||||
if (fClipboard)
|
||||
{
|
||||
NSPasteboard* pasteboard = [NSPasteboard generalPasteboard];
|
||||
const char* chars = [[pasteboard stringForType:NSStringPboardType] cStringUsingEncoding:NSUTF8StringEncoding];
|
||||
return StdStrBuf(chars);
|
||||
return chars;
|
||||
}
|
||||
return StdStrBuf(0);
|
||||
return std::string();
|
||||
}
|
||||
|
||||
bool C4AbstractApp::IsClipboardFull(bool fClipboard)
|
||||
|
@ -214,7 +214,7 @@ bool EraseItemSafe(const char* szFilename)
|
|||
tag: 0];
|
||||
}
|
||||
|
||||
StdStrBuf C4AbstractApp::GetGameDataPath()
|
||||
std::string C4AbstractApp::GetGameDataPath()
|
||||
{
|
||||
return StdCopyStrBuf([[[NSBundle mainBundle] resourcePath] fileSystemRepresentation]);
|
||||
return [[[NSBundle mainBundle] resourcePath] fileSystemRepresentation];
|
||||
}
|
||||
|
|
|
@ -450,16 +450,15 @@ void C4AbstractApp::RestoreVideoMode()
|
|||
SDL_SetWindowFullscreen(pWindow->window, 0);
|
||||
}
|
||||
|
||||
bool C4AbstractApp::Copy(const StdStrBuf & text, bool fClipboard)
|
||||
bool C4AbstractApp::Copy(const std::string &text, bool fClipboard)
|
||||
{
|
||||
return SDL_SetClipboardText(text.getData()) == 0;
|
||||
return SDL_SetClipboardText(text.c_str()) == 0;
|
||||
}
|
||||
|
||||
StdStrBuf C4AbstractApp::Paste(bool fClipboard)
|
||||
std::string C4AbstractApp::Paste(bool fClipboard)
|
||||
{
|
||||
char * text = SDL_GetClipboardText();
|
||||
StdStrBuf buf;
|
||||
buf.Copy(text);
|
||||
std::string buf(text);
|
||||
SDL_free(text);
|
||||
return buf;
|
||||
}
|
||||
|
|
|
@ -71,15 +71,15 @@ bool C4AbstractApp::SetVideoMode(int, int, unsigned int, unsigned int, bool)
|
|||
}
|
||||
|
||||
// Copy the text to the clipboard or the primary selection
|
||||
bool C4AbstractApp::Copy(const StdStrBuf & text, bool fClipboard)
|
||||
bool C4AbstractApp::Copy(const std::string &text, bool fClipboard)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Paste the text from the clipboard or the primary selection
|
||||
StdStrBuf C4AbstractApp::Paste(bool fClipboard)
|
||||
std::string C4AbstractApp::Paste(bool fClipboard)
|
||||
{
|
||||
return StdStrBuf("");
|
||||
return std::string();
|
||||
}
|
||||
// Is there something in the clipboard?
|
||||
bool C4AbstractApp::IsClipboardFull(bool fClipboard)
|
||||
|
|
|
@ -893,7 +893,7 @@ void C4AbstractApp::SetLastErrorFromOS()
|
|||
LPWSTR buffer = 0;
|
||||
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
0, ::GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), reinterpret_cast<LPWSTR>(&buffer), 0, 0);
|
||||
sLastError.Take(StdStrBuf(buffer));
|
||||
sLastError = WStrToString(buffer);
|
||||
LocalFree(buffer);
|
||||
}
|
||||
|
||||
|
@ -1046,7 +1046,7 @@ void C4AbstractApp::MessageDialog(const char * message)
|
|||
}
|
||||
|
||||
// Clipboard functions
|
||||
bool C4AbstractApp::Copy(const StdStrBuf & text, bool fClipboard)
|
||||
bool C4AbstractApp::Copy(const std::string &text, bool fClipboard)
|
||||
{
|
||||
if (!fClipboard) return false;
|
||||
bool fSuccess = true;
|
||||
|
@ -1054,12 +1054,12 @@ bool C4AbstractApp::Copy(const StdStrBuf & text, bool fClipboard)
|
|||
if (!OpenClipboard(pWindow ? pWindow->hWindow : nullptr)) return false;
|
||||
// must empty the global clipboard, so the application clipboard equals the Windows clipboard
|
||||
EmptyClipboard();
|
||||
int size = MultiByteToWideChar(CP_UTF8, 0, text.getData(), text.getSize(), 0, 0);
|
||||
int size = MultiByteToWideChar(CP_UTF8, 0, text.c_str(), text.size() + 1, 0, 0);
|
||||
HANDLE hglbCopy = GlobalAlloc(GMEM_MOVEABLE, size * sizeof(wchar_t));
|
||||
if (hglbCopy == nullptr) { CloseClipboard(); return false; }
|
||||
// lock the handle and copy the text to the buffer.
|
||||
wchar_t *szCopyChar = (wchar_t *) GlobalLock(hglbCopy);
|
||||
fSuccess = !!MultiByteToWideChar(CP_UTF8, 0, text.getData(), text.getSize(), szCopyChar, size);
|
||||
fSuccess = !!MultiByteToWideChar(CP_UTF8, 0, text.c_str(), text.size() + 1, szCopyChar, size);
|
||||
GlobalUnlock(hglbCopy);
|
||||
// place the handle on the clipboard.
|
||||
fSuccess = fSuccess && !!SetClipboardData(CF_UNICODETEXT, hglbCopy);
|
||||
|
@ -1069,15 +1069,15 @@ bool C4AbstractApp::Copy(const StdStrBuf & text, bool fClipboard)
|
|||
return fSuccess;
|
||||
}
|
||||
|
||||
StdStrBuf C4AbstractApp::Paste(bool fClipboard)
|
||||
std::string C4AbstractApp::Paste(bool fClipboard)
|
||||
{
|
||||
if (!fClipboard) return StdStrBuf();
|
||||
if (!fClipboard) return std::string();
|
||||
// open clipboard
|
||||
if (!OpenClipboard(nullptr)) return StdStrBuf();
|
||||
if (!OpenClipboard(nullptr)) return std::string();
|
||||
// get text from clipboard
|
||||
HANDLE hglb = GetClipboardData(CF_UNICODETEXT);
|
||||
if (!hglb) return StdStrBuf();
|
||||
StdStrBuf text((LPCWSTR) GlobalLock(hglb));
|
||||
if (!hglb) return std::string();
|
||||
std::string text{ WStrToString((wchar_t*)GlobalLock(hglb)) };
|
||||
// unlock mem
|
||||
GlobalUnlock(hglb);
|
||||
// close clipboard
|
||||
|
|
Loading…
Reference in New Issue