Merge pull request #717 from p12tic/use-std-string

lib/platform: Use std::string directly instead of String typedef
This commit is contained in:
Dom Rodriguez 2020-05-30 21:06:54 +01:00 committed by GitHub
commit dacbfc1ee2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 275 additions and 358 deletions

View File

@ -21,6 +21,7 @@
#include "net/ISocket.h" #include "net/ISocket.h"
#include "io/IStream.h" #include "io/IStream.h"
#include "base/EventTypes.h" #include "base/EventTypes.h"
#include <string>
//! Data stream socket interface //! Data stream socket interface
/*! /*!

View File

@ -98,7 +98,7 @@ MSWindowsClipboard::empty()
} }
void void
MSWindowsClipboard::add(EFormat format, const String& data) MSWindowsClipboard::add(EFormat format, const std::string& data)
{ {
LOG((CLOG_DEBUG "add %d bytes to clipboard format: %d", data.size(), format)); LOG((CLOG_DEBUG "add %d bytes to clipboard format: %d", data.size(), format));
@ -165,8 +165,7 @@ MSWindowsClipboard::has(EFormat format) const
return false; return false;
} }
String std::string MSWindowsClipboard::get(EFormat format) const
MSWindowsClipboard::get(EFormat format) const
{ {
// find the converter for the first clipboard format we can handle // find the converter for the first clipboard format we can handle
IMSWindowsClipboardConverter* converter = NULL; IMSWindowsClipboardConverter* converter = NULL;
@ -183,7 +182,7 @@ MSWindowsClipboard::get(EFormat format) const
// if no converter then we don't recognize any formats // if no converter then we don't recognize any formats
if (converter == NULL) { if (converter == NULL) {
LOG((CLOG_WARN "no converter for format %d", format)); LOG((CLOG_WARN "no converter for format %d", format));
return String(); return {};
} }
// get a handle to the clipboard data // get a handle to the clipboard data
@ -192,7 +191,7 @@ MSWindowsClipboard::get(EFormat format) const
// nb: can't cause this using integ tests; this is only caused when // nb: can't cause this using integ tests; this is only caused when
// the selected converter returns an invalid format -- which you // the selected converter returns an invalid format -- which you
// cannot cause using public functions. // cannot cause using public functions.
return String(); return {};
} }
// convert // convert

View File

@ -55,21 +55,21 @@ public:
// IClipboard overrides // IClipboard overrides
virtual bool empty(); virtual bool empty();
virtual void add(EFormat, const String& data); virtual void add(EFormat, const std::string& data);
virtual bool open(Time) const; virtual bool open(Time) const;
virtual void close() const; virtual void close() const;
virtual Time getTime() const; virtual Time getTime() const;
virtual bool has(EFormat) const; virtual bool has(EFormat) const;
virtual String get(EFormat) const; virtual std::string get(EFormat) const;
void setFacade(IMSWindowsClipboardFacade& facade); void setFacade(IMSWindowsClipboardFacade& facade);
private: private:
void clearConverters(); void clearConverters();
UINT convertFormatToWin32(EFormat) const; UINT convertFormatToWin32(EFormat) const;
HANDLE convertTextToWin32(const String& data) const; HANDLE convertTextToWin32(const std::string& data) const;
String convertTextFromWin32(HANDLE) const; std::string convertTextFromWin32(HANDLE) const;
static UINT getOwnershipFormat(); static UINT getOwnershipFormat();
@ -105,9 +105,9 @@ public:
// the input data must be in the IClipboard format returned by // the input data must be in the IClipboard format returned by
// getFormat(). the return data will be in the win32 clipboard // getFormat(). the return data will be in the win32 clipboard
// format returned by getWin32Format(), allocated by GlobalAlloc(). // format returned by getWin32Format(), allocated by GlobalAlloc().
virtual HANDLE fromIClipboard(const String&) const = 0; virtual HANDLE fromIClipboard(const std::string&) const = 0;
// convert from the win32 clipboard format to the IClipboard format // convert from the win32 clipboard format to the IClipboard format
// (i.e., the reverse of fromIClipboard()). // (i.e., the reverse of fromIClipboard()).
virtual String toIClipboard(HANDLE data) const = 0; virtual std::string toIClipboard(HANDLE data) const = 0;
}; };

View File

@ -38,11 +38,10 @@ MSWindowsClipboardAnyTextConverter::getFormat() const
return IClipboard::kText; return IClipboard::kText;
} }
HANDLE HANDLE MSWindowsClipboardAnyTextConverter::fromIClipboard(const std::string& data) const
MSWindowsClipboardAnyTextConverter::fromIClipboard(const String& data) const
{ {
// convert linefeeds and then convert to desired encoding // convert linefeeds and then convert to desired encoding
String text = doFromIClipboard(convertLinefeedToWin32(data)); std::string text = doFromIClipboard(convertLinefeedToWin32(data));
UInt32 size = (UInt32)text.size(); UInt32 size = (UInt32)text.size();
// copy to memory handle // copy to memory handle
@ -63,18 +62,17 @@ MSWindowsClipboardAnyTextConverter::fromIClipboard(const String& data) const
return gData; return gData;
} }
String std::string MSWindowsClipboardAnyTextConverter::toIClipboard(HANDLE data) const
MSWindowsClipboardAnyTextConverter::toIClipboard(HANDLE data) const
{ {
// get datator // get datator
const char* src = (const char*)GlobalLock(data); const char* src = (const char*)GlobalLock(data);
UInt32 srcSize = (UInt32)GlobalSize(data); UInt32 srcSize = (UInt32)GlobalSize(data);
if (src == NULL || srcSize <= 1) { if (src == NULL || srcSize <= 1) {
return String(); return {};
} }
// convert text // convert text
String text = doToIClipboard(String(src, srcSize)); std::string text = doToIClipboard(std::string(src, srcSize));
// release handle // release handle
GlobalUnlock(data); GlobalUnlock(data);
@ -83,9 +81,7 @@ MSWindowsClipboardAnyTextConverter::toIClipboard(HANDLE data) const
return convertLinefeedToUnix(text); return convertLinefeedToUnix(text);
} }
String std::string MSWindowsClipboardAnyTextConverter::convertLinefeedToWin32(const std::string& src) const
MSWindowsClipboardAnyTextConverter::convertLinefeedToWin32(
const String& src) const
{ {
// note -- we assume src is a valid UTF-8 string // note -- we assume src is a valid UTF-8 string
@ -102,7 +98,7 @@ MSWindowsClipboardAnyTextConverter::convertLinefeedToWin32(
} }
// allocate new string // allocate new string
String dst; std::string dst;
dst.reserve(src.size() + numNewlines); dst.reserve(src.size() + numNewlines);
// copy string, converting newlines // copy string, converting newlines
@ -117,9 +113,7 @@ MSWindowsClipboardAnyTextConverter::convertLinefeedToWin32(
return dst; return dst;
} }
String std::string MSWindowsClipboardAnyTextConverter::convertLinefeedToUnix(const std::string& src) const
MSWindowsClipboardAnyTextConverter::convertLinefeedToUnix(
const String& src) const
{ {
// count newlines in string // count newlines in string
UInt32 numNewlines = 0; UInt32 numNewlines = 0;
@ -134,7 +128,7 @@ MSWindowsClipboardAnyTextConverter::convertLinefeedToUnix(
} }
// allocate new string // allocate new string
String dst; std::string dst;
dst.reserve(src.size()); dst.reserve(src.size());
// copy string, converting newlines // copy string, converting newlines

View File

@ -31,8 +31,8 @@ public:
virtual IClipboard::EFormat virtual IClipboard::EFormat
getFormat() const; getFormat() const;
virtual UINT getWin32Format() const = 0; virtual UINT getWin32Format() const = 0;
virtual HANDLE fromIClipboard(const String&) const; virtual HANDLE fromIClipboard(const std::string&) const;
virtual String toIClipboard(HANDLE) const; virtual std::string toIClipboard(HANDLE) const;
protected: protected:
//! Convert from IClipboard format //! Convert from IClipboard format
@ -40,18 +40,18 @@ protected:
Do UTF-8 conversion only. Memory handle allocation and Do UTF-8 conversion only. Memory handle allocation and
linefeed conversion is done by this class. doFromIClipboard() linefeed conversion is done by this class. doFromIClipboard()
must include the nul terminator in the returned string (not must include the nul terminator in the returned string (not
including the String's nul terminator). including the std::string's nul terminator).
*/ */
virtual String doFromIClipboard(const String&) const = 0; virtual std::string doFromIClipboard(const std::string&) const = 0;
//! Convert to IClipboard format //! Convert to IClipboard format
/*! /*!
Do UTF-8 conversion only. Memory handle allocation and Do UTF-8 conversion only. Memory handle allocation and
linefeed conversion is done by this class. linefeed conversion is done by this class.
*/ */
virtual String doToIClipboard(const String&) const = 0; virtual std::string doToIClipboard(const std::string&) const = 0;
private: private:
String convertLinefeedToWin32(const String&) const; std::string convertLinefeedToWin32(const std::string&) const;
String convertLinefeedToUnix(const String&) const; std::string convertLinefeedToUnix(const std::string&) const;
}; };

View File

@ -46,8 +46,7 @@ MSWindowsClipboardBitmapConverter::getWin32Format() const
return CF_DIB; return CF_DIB;
} }
HANDLE HANDLE MSWindowsClipboardBitmapConverter::fromIClipboard(const std::string& data) const
MSWindowsClipboardBitmapConverter::fromIClipboard(const String& data) const
{ {
// copy to memory handle // copy to memory handle
HGLOBAL gData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, data.size()); HGLOBAL gData = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, data.size());
@ -67,13 +66,12 @@ MSWindowsClipboardBitmapConverter::fromIClipboard(const String& data) const
return gData; return gData;
} }
String std::string MSWindowsClipboardBitmapConverter::toIClipboard(HANDLE data) const
MSWindowsClipboardBitmapConverter::toIClipboard(HANDLE data) const
{ {
// get datator // get datator
LPVOID src = GlobalLock(data); LPVOID src = GlobalLock(data);
if (src == NULL) { if (src == NULL) {
return String(); return {};
} }
UInt32 srcSize = (UInt32)GlobalSize(data); UInt32 srcSize = (UInt32)GlobalSize(data);
@ -85,7 +83,7 @@ MSWindowsClipboardBitmapConverter::toIClipboard(HANDLE data) const
bitmap->bmiHeader.biBitCount == 32) && bitmap->bmiHeader.biBitCount == 32) &&
bitmap->bmiHeader.biCompression == BI_RGB) { bitmap->bmiHeader.biCompression == BI_RGB) {
// already in canonical form // already in canonical form
String image(static_cast<char const*>(src), srcSize); std::string image(static_cast<char const*>(src), srcSize);
GlobalUnlock(data); GlobalUnlock(data);
return image; return image;
} }
@ -138,7 +136,7 @@ MSWindowsClipboardBitmapConverter::toIClipboard(HANDLE data) const
GdiFlush(); GdiFlush();
// extract data // extract data
String image((const char*)&info, info.biSize); std::string image((const char*)&info, info.biSize);
image.append((const char*)raw, 4 * w * h); image.append((const char*)raw, 4 * w * h);
// clean up GDI // clean up GDI

View File

@ -31,6 +31,6 @@ public:
virtual IClipboard::EFormat virtual IClipboard::EFormat
getFormat() const; getFormat() const;
virtual UINT getWin32Format() const; virtual UINT getWin32Format() const;
virtual HANDLE fromIClipboard(const String&) const; virtual HANDLE fromIClipboard(const std::string&) const;
virtual String toIClipboard(HANDLE) const; virtual std::string toIClipboard(HANDLE) const;
}; };

View File

@ -46,15 +46,14 @@ MSWindowsClipboardHTMLConverter::getWin32Format() const
return m_format; return m_format;
} }
String std::string MSWindowsClipboardHTMLConverter::doFromIClipboard(const std::string& data) const
MSWindowsClipboardHTMLConverter::doFromIClipboard(const String& data) const
{ {
// prepare to CF_HTML format prefix and suffix // prepare to CF_HTML format prefix and suffix
String prefix("Version:0.9\r\nStartHTML:0000000105\r\n" std::string prefix("Version:0.9\r\nStartHTML:0000000105\r\n"
"EndHTML:ZZZZZZZZZZ\r\n" "EndHTML:ZZZZZZZZZZ\r\n"
"StartFragment:XXXXXXXXXX\r\nEndFragment:YYYYYYYYYY\r\n" "StartFragment:XXXXXXXXXX\r\nEndFragment:YYYYYYYYYY\r\n"
"<!DOCTYPE><HTML><BODY><!--StartFragment-->"); "<!DOCTYPE><HTML><BODY><!--StartFragment-->");
String suffix("<!--EndFragment--></BODY></HTML>\r\n"); std::string suffix("<!--EndFragment--></BODY></HTML>\r\n");
// Get byte offsets for header // Get byte offsets for header
UInt32 StartFragment = (UInt32)prefix.size(); UInt32 StartFragment = (UInt32)prefix.size();
@ -75,45 +74,43 @@ MSWindowsClipboardHTMLConverter::doFromIClipboard(const String& data) const
return prefix; return prefix;
} }
String std::string MSWindowsClipboardHTMLConverter::doToIClipboard(const std::string& data) const
MSWindowsClipboardHTMLConverter::doToIClipboard(const String& data) const
{ {
// get fragment start/end args // get fragment start/end args
String startArg = findArg(data, "StartFragment"); std::string startArg = findArg(data, "StartFragment");
String endArg = findArg(data, "EndFragment"); std::string endArg = findArg(data, "EndFragment");
if (startArg.empty() || endArg.empty()) { if (startArg.empty() || endArg.empty()) {
return String(); return std::string();
} }
// convert args to integers // convert args to integers
SInt32 start = (SInt32)atoi(startArg.c_str()); SInt32 start = (SInt32)atoi(startArg.c_str());
SInt32 end = (SInt32)atoi(endArg.c_str()); SInt32 end = (SInt32)atoi(endArg.c_str());
if (start <= 0 || end <= 0 || start >= end) { if (start <= 0 || end <= 0 || start >= end) {
return String(); return std::string();
} }
// extract the fragment // extract the fragment
return data.substr(start, end - start); return data.substr(start, end - start);
} }
String std::string MSWindowsClipboardHTMLConverter::findArg(const std::string& data,
MSWindowsClipboardHTMLConverter::findArg( const std::string& name) const
const String& data, const String& name) const
{ {
String::size_type i = data.find(name); std::string::size_type i = data.find(name);
if (i == String::npos) { if (i == std::string::npos) {
return String(); return std::string();
} }
i = data.find_first_of(":\r\n", i); i = data.find_first_of(":\r\n", i);
if (i == String::npos || data[i] != ':') { if (i == std::string::npos || data[i] != ':') {
return String(); return std::string();
} }
i = data.find_first_of("0123456789\r\n", i + 1); i = data.find_first_of("0123456789\r\n", i + 1);
if (i == String::npos || data[i] == '\r' || data[i] == '\n') { if (i == std::string::npos || data[i] == '\r' || data[i] == '\n') {
return String(); return std::string();
} }
String::size_type j = data.find_first_not_of("0123456789", i); std::string::size_type j = data.find_first_not_of("0123456789", i);
if (j == String::npos) { if (j == std::string::npos) {
j = data.size(); j = data.size();
} }
return data.substr(i, j - i); return data.substr(i, j - i);

View File

@ -34,11 +34,11 @@ public:
protected: protected:
// MSWindowsClipboardAnyTextConverter overrides // MSWindowsClipboardAnyTextConverter overrides
virtual String doFromIClipboard(const String&) const; virtual std::string doFromIClipboard(const std::string&) const;
virtual String doToIClipboard(const String&) const; virtual std::string doToIClipboard(const std::string&) const;
private: private:
String findArg(const String& data, const String& name) const; std::string findArg(const std::string& data, const std::string& name) const;
private: private:
UINT m_format; UINT m_format;

View File

@ -40,20 +40,18 @@ MSWindowsClipboardTextConverter::getWin32Format() const
return CF_TEXT; return CF_TEXT;
} }
String std::string MSWindowsClipboardTextConverter::doFromIClipboard(const std::string& data) const
MSWindowsClipboardTextConverter::doFromIClipboard(const String& data) const
{ {
// convert and add nul terminator // convert and add nul terminator
return Unicode::UTF8ToText(data) += '\0'; return Unicode::UTF8ToText(data) += '\0';
} }
String std::string MSWindowsClipboardTextConverter::doToIClipboard(const std::string& data) const
MSWindowsClipboardTextConverter::doToIClipboard(const String& data) const
{ {
// convert and truncate at first nul terminator // convert and truncate at first nul terminator
String dst = Unicode::textToUTF8(data); std::string dst = Unicode::textToUTF8(data);
String::size_type n = dst.find('\0'); std::string::size_type n = dst.find('\0');
if (n != String::npos) { if (n != std::string::npos) {
dst.erase(n); dst.erase(n);
} }
return dst; return dst;

View File

@ -32,6 +32,6 @@ public:
protected: protected:
// MSWindowsClipboardAnyTextConverter overrides // MSWindowsClipboardAnyTextConverter overrides
virtual String doFromIClipboard(const String&) const; virtual std::string doFromIClipboard(const std::string&) const;
virtual String doToIClipboard(const String&) const; virtual std::string doToIClipboard(const std::string&) const;
}; };

View File

@ -40,20 +40,18 @@ MSWindowsClipboardUTF16Converter::getWin32Format() const
return CF_UNICODETEXT; return CF_UNICODETEXT;
} }
String std::string MSWindowsClipboardUTF16Converter::doFromIClipboard(const std::string& data) const
MSWindowsClipboardUTF16Converter::doFromIClipboard(const String& data) const
{ {
// convert and add nul terminator // convert and add nul terminator
return Unicode::UTF8ToUTF16(data).append(sizeof(wchar_t), 0); return Unicode::UTF8ToUTF16(data).append(sizeof(wchar_t), 0);
} }
String std::string MSWindowsClipboardUTF16Converter::doToIClipboard(const std::string& data) const
MSWindowsClipboardUTF16Converter::doToIClipboard(const String& data) const
{ {
// convert and strip nul terminator // convert and strip nul terminator
String dst = Unicode::UTF16ToUTF8(data); std::string dst = Unicode::UTF16ToUTF8(data);
String::size_type n = dst.find('\0'); std::string::size_type n = dst.find('\0');
if (n != String::npos) { if (n != std::string::npos) {
dst.erase(n); dst.erase(n);
} }
return dst; return dst;

View File

@ -32,6 +32,6 @@ public:
protected: protected:
// MSWindowsClipboardAnyTextConverter overrides // MSWindowsClipboardAnyTextConverter overrides
virtual String doFromIClipboard(const String&) const; virtual std::string doFromIClipboard(const std::string&) const;
virtual String doToIClipboard(const String&) const; virtual std::string doToIClipboard(const std::string&) const;
}; };

View File

@ -746,8 +746,7 @@ MSWindowsDesks::deskThread(void* vdesk)
} }
} }
MSWindowsDesks::Desk* MSWindowsDesks::Desk* MSWindowsDesks::addDesk(const std::string& name, HDESK hdesk)
MSWindowsDesks::addDesk(const String& name, HDESK hdesk)
{ {
Desk* desk = new Desk; Desk* desk = new Desk;
desk->m_name = name; desk->m_name = name;
@ -782,7 +781,7 @@ MSWindowsDesks::checkDesk()
// get current desktop. if we already know about it then return. // get current desktop. if we already know about it then return.
Desk* desk; Desk* desk;
HDESK hdesk = openInputDesktop(); HDESK hdesk = openInputDesktop();
String name = getDesktopName(hdesk); std::string name = getDesktopName(hdesk);
Desks::const_iterator index = m_desks.find(name); Desks::const_iterator index = m_desks.find(name);
if (index == m_desks.end()) { if (index == m_desks.end()) {
desk = addDesk(name, hdesk); desk = addDesk(name, hdesk);
@ -900,18 +899,17 @@ MSWindowsDesks::closeDesktop(HDESK desk)
} }
} }
String std::string MSWindowsDesks::getDesktopName(HDESK desk)
MSWindowsDesks::getDesktopName(HDESK desk)
{ {
if (desk == NULL) { if (desk == NULL) {
return String(); return {}
} }
else { else {
DWORD size; DWORD size;
GetUserObjectInformation(desk, UOI_NAME, NULL, 0, &size); GetUserObjectInformation(desk, UOI_NAME, NULL, 0, &size);
TCHAR* name = (TCHAR*)alloca(size + sizeof(TCHAR)); TCHAR* name = (TCHAR*)alloca(size + sizeof(TCHAR));
GetUserObjectInformation(desk, UOI_NAME, name, size, &size); GetUserObjectInformation(desk, UOI_NAME, name, size, &size);
String result(name); std::string result(name);
return result; return result;
} }
} }

View File

@ -25,8 +25,8 @@
#include "barrier/option_types.h" #include "barrier/option_types.h"
#include "mt/CondVar.h" #include "mt/CondVar.h"
#include "mt/Mutex.h" #include "mt/Mutex.h"
#include "base/String.h"
#include "common/stdmap.h" #include "common/stdmap.h"
#include <string>
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
@ -195,7 +195,7 @@ public:
private: private:
class Desk { class Desk {
public: public:
String m_name; std::string m_name;
Thread* m_thread; Thread* m_thread;
DWORD m_threadID; DWORD m_threadID;
DWORD m_targetID; DWORD m_targetID;
@ -204,7 +204,7 @@ private:
HWND m_foregroundWindow; HWND m_foregroundWindow;
bool m_lowLevel; bool m_lowLevel;
}; };
typedef std::map<String, Desk*> Desks; typedef std::map<std::string, Desk*> Desks;
// initialization and shutdown operations // initialization and shutdown operations
HCURSOR createBlankCursor() const; HCURSOR createBlankCursor() const;
@ -222,7 +222,7 @@ private:
void deskThread(void* vdesk); void deskThread(void* vdesk);
// desk switch checking and handling // desk switch checking and handling
Desk* addDesk(const String& name, HDESK hdesk); Desk* addDesk(const std::string& name, HDESK hdesk);
void removeDesks(); void removeDesks();
void checkDesk(); void checkDesk();
bool isDeskAccessible(const Desk* desk) const; bool isDeskAccessible(const Desk* desk) const;
@ -238,7 +238,7 @@ private:
// desk API wrappers // desk API wrappers
HDESK openInputDesktop(); HDESK openInputDesktop();
void closeDesktop(HDESK); void closeDesktop(HDESK);
String getDesktopName(HDESK); std::string getDesktopName(HDESK);
// our desk window procs // our desk window procs
static LRESULT CALLBACK primaryDeskProc(HWND, UINT, WPARAM, LPARAM); static LRESULT CALLBACK primaryDeskProc(HWND, UINT, WPARAM, LPARAM);
@ -276,7 +276,7 @@ private:
// the current desk and it's name // the current desk and it's name
Desk* m_activeDesk; Desk* m_activeDesk;
String m_activeDeskName; std::string m_activeDeskName;
// one desk per desktop and a cond var to communicate with it // one desk per desktop and a cond var to communicate with it
Mutex m_mutex; Mutex m_mutex;

View File

@ -19,7 +19,6 @@
#pragma once #pragma once
#include "barrier/KeyState.h" #include "barrier/KeyState.h"
#include "base/String.h"
#include "common/stdvector.h" #include "common/stdvector.h"
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN

View File

@ -38,7 +38,6 @@
#include "arch/Arch.h" #include "arch/Arch.h"
#include "base/FunctionJob.h" #include "base/FunctionJob.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/String.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"
#include "base/TMethodJob.h" #include "base/TMethodJob.h"
@ -150,7 +149,7 @@ MSWindowsScreen::MSWindowsScreen(
// SHGetFolderPath is deprecated in vista, but use it for xp support. // SHGetFolderPath is deprecated in vista, but use it for xp support.
char desktopPath[MAX_PATH]; char desktopPath[MAX_PATH];
if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, desktopPath))) { if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, desktopPath))) {
m_desktopPath = String(desktopPath); m_desktopPath = std::string(desktopPath);
LOG((CLOG_DEBUG "using desktop for drop target: %s", m_desktopPath.c_str())); LOG((CLOG_DEBUG "using desktop for drop target: %s", m_desktopPath.c_str()));
} }
else { else {
@ -378,7 +377,7 @@ MSWindowsScreen::leave()
void void
MSWindowsScreen::sendDragThread(void*) MSWindowsScreen::sendDragThread(void*)
{ {
String& draggingFilename = getDraggingFilename(); std::string& draggingFilename = getDraggingFilename();
size_t size = draggingFilename.size(); size_t size = draggingFilename.size();
if (draggingFilename.empty() == false) { if (draggingFilename.empty() == false) {
@ -1867,8 +1866,7 @@ MSWindowsScreen::fakeDraggingFiles(DragFileList fileList)
// exception from being thrown. // exception from being thrown.
} }
String& std::string& MSWindowsScreen::getDraggingFilename()
MSWindowsScreen::getDraggingFilename()
{ {
if (m_draggingStarted) { if (m_draggingStarted) {
m_dropTarget->clearDraggingFilename(); m_dropTarget->clearDraggingFilename();
@ -1894,7 +1892,7 @@ MSWindowsScreen::getDraggingFilename()
fakeKeyUp(1); fakeKeyUp(1);
fakeMouseButton(kButtonLeft, false); fakeMouseButton(kButtonLeft, false);
String filename; std::string filename;
DOUBLE timeout = ARCH->time() + .5f; DOUBLE timeout = ARCH->time() + .5f;
while (ARCH->time() < timeout) { while (ARCH->time() < timeout) {
ARCH->sleep(.05f); ARCH->sleep(.05f);
@ -1923,8 +1921,7 @@ MSWindowsScreen::getDraggingFilename()
return m_draggingFilename; return m_draggingFilename;
} }
const String& const std::string& MSWindowsScreen::getDropTarget() const
MSWindowsScreen::getDropTarget() const
{ {
return m_desktopPath; return m_desktopPath;
} }

View File

@ -25,7 +25,7 @@
#include "platform/synwinhk.h" #include "platform/synwinhk.h"
#include "mt/CondVar.h" #include "mt/CondVar.h"
#include "mt/Mutex.h" #include "mt/Mutex.h"
#include "base/String.h" #include <string>
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
@ -118,9 +118,8 @@ public:
virtual void setSequenceNumber(UInt32); virtual void setSequenceNumber(UInt32);
virtual bool isPrimary() const; virtual bool isPrimary() const;
virtual void fakeDraggingFiles(DragFileList fileList); virtual void fakeDraggingFiles(DragFileList fileList);
virtual String& getDraggingFilename(); virtual std::string& getDraggingFilename();
virtual const String& virtual const std::string& getDropTarget() const;
getDropTarget() const;
protected: protected:
// IPlatformScreen overrides // IPlatformScreen overrides
@ -333,7 +332,7 @@ private:
IEventQueue* m_events; IEventQueue* m_events;
String m_desktopPath; std::string m_desktopPath;
MSWindowsDropTarget* MSWindowsDropTarget*
m_dropTarget; m_dropTarget;

View File

@ -19,7 +19,6 @@
#pragma once #pragma once
#include "barrier/IScreenSaver.h" #include "barrier/IScreenSaver.h"
#include "base/String.h"
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>

View File

@ -172,10 +172,9 @@ MSWindowsSession::nextProcessEntry(HANDLE snapshot, LPPROCESSENTRY32 entry)
return gotEntry; return gotEntry;
} }
String std::string MSWindowsSession::getActiveDesktopName()
MSWindowsSession::getActiveDesktopName()
{ {
String result; std::string result;
try { try {
HDESK hd = OpenInputDesktop(0, TRUE, GENERIC_READ); HDESK hd = OpenInputDesktop(0, TRUE, GENERIC_READ);
if (hd != NULL) { if (hd != NULL) {

View File

@ -17,7 +17,7 @@
#pragma once #pragma once
#include "base/String.h" #include <string>
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
@ -42,7 +42,7 @@ public:
void updateActiveSession(); void updateActiveSession();
String getActiveDesktopName(); std::string getActiveDesktopName();
private: private:
BOOL nextProcessEntry(HANDLE snapshot, LPPROCESSENTRY32 entry); BOOL nextProcessEntry(HANDLE snapshot, LPPROCESSENTRY32 entry);

View File

@ -18,29 +18,25 @@
#include "platform/MSWindowsUtil.h" #include "platform/MSWindowsUtil.h"
#include "base/String.h"
#include <stdio.h> #include <stdio.h>
// //
// MSWindowsUtil // MSWindowsUtil
// //
String std::string MSWindowsUtil::getString(HINSTANCE instance, DWORD id)
MSWindowsUtil::getString(HINSTANCE instance, DWORD id)
{ {
char* msg = NULL; char* msg = NULL;
int n = LoadString(instance, id, reinterpret_cast<LPSTR>(&msg), 0); int n = LoadString(instance, id, reinterpret_cast<LPSTR>(&msg), 0);
if (n <= 0) { if (n <= 0) {
return String(); return {};
} }
return String (msg, n); return std::string (msg, n);
} }
String std::string MSWindowsUtil::getErrorString(HINSTANCE hinstance, DWORD error, DWORD id)
MSWindowsUtil::getErrorString(HINSTANCE hinstance, DWORD error, DWORD id)
{ {
char* buffer; char* buffer;
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
@ -52,12 +48,12 @@ MSWindowsUtil::getErrorString(HINSTANCE hinstance, DWORD error, DWORD id)
(LPTSTR)&buffer, (LPTSTR)&buffer,
0, 0,
NULL) == 0) { NULL) == 0) {
String errorString = barrier::string::sprintf("%d", error); std::string errorString = barrier::string::sprintf("%d", error);
return barrier::string::format(getString(hinstance, id).c_str(), return barrier::string::format(getString(hinstance, id).c_str(),
errorString.c_str()); errorString.c_str());
} }
else { else {
String result(buffer); std::string result(buffer);
LocalFree(buffer); LocalFree(buffer);
return result; return result;
} }

View File

@ -18,7 +18,7 @@
#pragma once #pragma once
#include "base/String.h" #include <string>
#define WINDOWS_LEAN_AND_MEAN #define WINDOWS_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
@ -29,14 +29,14 @@ public:
/*! /*!
Gets a string for \p id from the string table of \p instance. Gets a string for \p id from the string table of \p instance.
*/ */
static String getString(HINSTANCE instance, DWORD id); static std::string getString(HINSTANCE instance, DWORD id);
//! Get error string //! Get error string
/*! /*!
Gets a system error message for \p error. If the error cannot be Gets a system error message for \p error. If the error cannot be
found return the string for \p id, replacing ${1} with \p error. found return the string for \p id, replacing ${1} with \p error.
*/ */
static String getErrorString(HINSTANCE, DWORD error, DWORD id); static std::string getErrorString(HINSTANCE, DWORD error, DWORD id);
//! Create directory //! Create directory
/*! /*!

View File

@ -327,8 +327,7 @@ MSWindowsWatchdog::startProcess()
} }
} }
BOOL BOOL MSWindowsWatchdog::doStartProcessAsSelf(std::string& command)
MSWindowsWatchdog::doStartProcessAsSelf(String& command)
{ {
DWORD creationFlags = DWORD creationFlags =
NORMAL_PRIORITY_CLASS | NORMAL_PRIORITY_CLASS |
@ -347,8 +346,8 @@ MSWindowsWatchdog::doStartProcessAsSelf(String& command)
return CreateProcess(NULL, LPSTR(command.c_str()), NULL, NULL, FALSE, creationFlags, NULL, NULL, &si, &m_processInfo); return CreateProcess(NULL, LPSTR(command.c_str()), NULL, NULL, FALSE, creationFlags, NULL, NULL, &si, &m_processInfo);
} }
BOOL BOOL MSWindowsWatchdog::doStartProcessAsUser(std::string& command, HANDLE userToken,
MSWindowsWatchdog::doStartProcessAsUser(String& command, HANDLE userToken, LPSECURITY_ATTRIBUTES sa) LPSECURITY_ATTRIBUTES sa)
{ {
// clear, as we're reusing process info struct // clear, as we're reusing process info struct
ZeroMemory(&m_processInfo, sizeof(PROCESS_INFORMATION)); ZeroMemory(&m_processInfo, sizeof(PROCESS_INFORMATION));

View File

@ -55,8 +55,8 @@ private:
HANDLE duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTES security); HANDLE duplicateProcessToken(HANDLE process, LPSECURITY_ATTRIBUTES security);
HANDLE getUserToken(LPSECURITY_ATTRIBUTES security); HANDLE getUserToken(LPSECURITY_ATTRIBUTES security);
void startProcess(); void startProcess();
BOOL doStartProcessAsUser(String& command, HANDLE userToken, LPSECURITY_ATTRIBUTES sa); BOOL doStartProcessAsUser(std::string& command, HANDLE userToken, LPSECURITY_ATTRIBUTES sa);
BOOL doStartProcessAsSelf(String& command); BOOL doStartProcessAsSelf(std::string& command);
private: private:
Thread* m_thread; Thread* m_thread;
@ -85,8 +85,8 @@ An error occured in the process watchdog.
*/ */
class XMSWindowsWatchdogError : public XBarrier { class XMSWindowsWatchdogError : public XBarrier {
public: public:
XMSWindowsWatchdogError(const String& msg) : XBarrier(msg) { } XMSWindowsWatchdogError(const std::string& msg) : XBarrier(msg) { }
// XBase overrides // XBase overrides
virtual String getWhat() const throw() { return what(); } virtual std::string getWhat() const throw() { return what(); }
}; };

View File

@ -92,8 +92,7 @@ OSXClipboard::synchronize()
return false; return false;
} }
void void OSXClipboard::add(EFormat format, const std::string& data)
OSXClipboard::add(EFormat format, const String & data)
{ {
if (m_pboard == NULL) if (m_pboard == NULL)
return; return;
@ -116,7 +115,7 @@ OSXClipboard::add(EFormat format, const String & data)
// skip converters for other formats // skip converters for other formats
if (converter->getFormat() == format) { if (converter->getFormat() == format) {
String osXData = converter->fromIClipboard(data); std::string osXData = converter->fromIClipboard(data);
CFStringRef flavorType = converter->getOSXFormat(); CFStringRef flavorType = converter->getOSXFormat();
CFDataRef dataRef = CFDataCreate(kCFAllocatorDefault, (UInt8 *)osXData.data(), osXData.size()); CFDataRef dataRef = CFDataCreate(kCFAllocatorDefault, (UInt8 *)osXData.data(), osXData.size());
PasteboardItemID itemID = 0; PasteboardItemID itemID = 0;
@ -185,12 +184,11 @@ OSXClipboard::has(EFormat format) const
return false; return false;
} }
String std::string OSXClipboard::get(EFormat format) const
OSXClipboard::get(EFormat format) const
{ {
CFStringRef type; CFStringRef type;
PasteboardItemID item; PasteboardItemID item;
String result; std::string result;
if (m_pboard == NULL) if (m_pboard == NULL)
return result; return result;
@ -229,7 +227,7 @@ OSXClipboard::get(EFormat format) const
throw err; throw err;
} }
result = String((char *) CFDataGetBytePtr(buffer), CFDataGetLength(buffer)); result = std::string((char *) CFDataGetBytePtr(buffer), CFDataGetLength(buffer));
} }
catch (OSStatus err) { catch (OSStatus err) {
LOG((CLOG_DEBUG "exception thrown in OSXClipboard::get MacError (%d)", err)); LOG((CLOG_DEBUG "exception thrown in OSXClipboard::get MacError (%d)", err));

View File

@ -21,6 +21,7 @@
#include "barrier/IClipboard.h" #include "barrier/IClipboard.h"
#include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
#include <string>
#include <vector> #include <vector>
class IOSXClipboardConverter; class IOSXClipboardConverter;
@ -36,12 +37,12 @@ public:
// IClipboard overrides // IClipboard overrides
virtual bool empty(); virtual bool empty();
virtual void add(EFormat, const String& data); virtual void add(EFormat, const std::string& data);
virtual bool open(Time) const; virtual bool open(Time) const;
virtual void close() const; virtual void close() const;
virtual Time getTime() const; virtual Time getTime() const;
virtual bool has(EFormat) const; virtual bool has(EFormat) const;
virtual String get(EFormat) const; virtual std::string get(EFormat) const;
bool synchronize(); bool synchronize();
private: private:
@ -72,8 +73,7 @@ public:
getFormat() const = 0; getFormat() const = 0;
//! returns the scrap flavor type that this object converts from/to //! returns the scrap flavor type that this object converts from/to
virtual CFStringRef virtual CFStringRef getOSXFormat() const = 0;
getOSXFormat() const = 0;
//! Convert from IClipboard format //! Convert from IClipboard format
/*! /*!
@ -82,14 +82,14 @@ public:
getFormat(). The return data will be in the scrap getFormat(). The return data will be in the scrap
format returned by getOSXFormat(). format returned by getOSXFormat().
*/ */
virtual String fromIClipboard(const String&) const = 0; virtual std::string fromIClipboard(const std::string&) const = 0;
//! Convert to IClipboard format //! Convert to IClipboard format
/*! /*!
Convert from the carbon scrap format to the IClipboard format Convert from the carbon scrap format to the IClipboard format
(i.e., the reverse of fromIClipboard()). (i.e., the reverse of fromIClipboard()).
*/ */
virtual String toIClipboard(const String&) const = 0; virtual std::string toIClipboard(const std::string&) const = 0;
//@} //@}
}; };

View File

@ -35,14 +35,12 @@ OSXClipboardAnyBitmapConverter::getFormat() const
return IClipboard::kBitmap; return IClipboard::kBitmap;
} }
String std::string OSXClipboardAnyBitmapConverter::fromIClipboard(const std::string& data) const
OSXClipboardAnyBitmapConverter::fromIClipboard(const String& data) const
{ {
return doFromIClipboard(data); return doFromIClipboard(data);
} }
String std::string OSXClipboardAnyBitmapConverter::toIClipboard(const std::string& data) const
OSXClipboardAnyBitmapConverter::toIClipboard(const String& data) const
{ {
return doToIClipboard(data); return doToIClipboard(data);
} }

View File

@ -30,19 +30,19 @@ public:
virtual IClipboard::EFormat virtual IClipboard::EFormat
getFormat() const; getFormat() const;
virtual CFStringRef getOSXFormat() const = 0; virtual CFStringRef getOSXFormat() const = 0;
virtual String fromIClipboard(const String &) const; virtual std::string fromIClipboard(const std::string &) const;
virtual String toIClipboard(const String &) const; virtual std::string toIClipboard(const std::string &) const;
protected: protected:
//! Convert from IClipboard format //! Convert from IClipboard format
/*! /*!
Do UTF-8 conversion and linefeed conversion. Do UTF-8 conversion and linefeed conversion.
*/ */
virtual String doFromIClipboard(const String&) const = 0; virtual std::string doFromIClipboard(const std::string&) const = 0;
//! Convert to IClipboard format //! Convert to IClipboard format
/*! /*!
Do UTF-8 conversion and Linefeed conversion. Do UTF-8 conversion and Linefeed conversion.
*/ */
virtual String doToIClipboard(const String&) const = 0; virtual std::string doToIClipboard(const std::string&) const = 0;
}; };

View File

@ -40,15 +40,13 @@ OSXClipboardAnyTextConverter::getFormat() const
return IClipboard::kText; return IClipboard::kText;
} }
String std::string OSXClipboardAnyTextConverter::fromIClipboard(const std::string& data) const
OSXClipboardAnyTextConverter::fromIClipboard(const String& data) const
{ {
// convert linefeeds and then convert to desired encoding // convert linefeeds and then convert to desired encoding
return doFromIClipboard(convertLinefeedToMacOS(data)); return doFromIClipboard(convertLinefeedToMacOS(data));
} }
String std::string OSXClipboardAnyTextConverter::toIClipboard(const std::string& data) const
OSXClipboardAnyTextConverter::toIClipboard(const String& data) const
{ {
// convert text then newlines // convert text then newlines
return convertLinefeedToUnix(doToIClipboard(data)); return convertLinefeedToUnix(doToIClipboard(data));
@ -68,21 +66,19 @@ isCR(char ch)
return (ch == '\r'); return (ch == '\r');
} }
String std::string OSXClipboardAnyTextConverter::convertLinefeedToMacOS(const std::string& src)
OSXClipboardAnyTextConverter::convertLinefeedToMacOS(const String& src)
{ {
// note -- we assume src is a valid UTF-8 string // note -- we assume src is a valid UTF-8 string
String copy = src; std::string copy = src;
std::replace_if(copy.begin(), copy.end(), isLF, '\r'); std::replace_if(copy.begin(), copy.end(), isLF, '\r');
return copy; return copy;
} }
String std::string OSXClipboardAnyTextConverter::convertLinefeedToUnix(const std::string& src)
OSXClipboardAnyTextConverter::convertLinefeedToUnix(const String& src)
{ {
String copy = src; std::string copy = src;
std::replace_if(copy.begin(), copy.end(), isCR, '\n'); std::replace_if(copy.begin(), copy.end(), isCR, '\n');

View File

@ -29,25 +29,24 @@ public:
// IOSXClipboardConverter overrides // IOSXClipboardConverter overrides
virtual IClipboard::EFormat virtual IClipboard::EFormat
getFormat() const; getFormat() const;
virtual CFStringRef virtual CFStringRef getOSXFormat() const = 0;
getOSXFormat() const = 0; virtual std::string fromIClipboard(const std::string &) const;
virtual String fromIClipboard(const String &) const; virtual std::string toIClipboard(const std::string &) const;
virtual String toIClipboard(const String &) const;
protected: protected:
//! Convert from IClipboard format //! Convert from IClipboard format
/*! /*!
Do UTF-8 conversion and linefeed conversion. Do UTF-8 conversion and linefeed conversion.
*/ */
virtual String doFromIClipboard(const String&) const = 0; virtual std::string doFromIClipboard(const std::string&) const = 0;
//! Convert to IClipboard format //! Convert to IClipboard format
/*! /*!
Do UTF-8 conversion and Linefeed conversion. Do UTF-8 conversion and Linefeed conversion.
*/ */
virtual String doToIClipboard(const String&) const = 0; virtual std::string doToIClipboard(const std::string&) const = 0;
private: private:
static String convertLinefeedToMacOS(const String&); static std::string convertLinefeedToMacOS(const std::string&);
static String convertLinefeedToUnix(const String&); static std::string convertLinefeedToUnix(const std::string&);
}; };

View File

@ -91,8 +91,7 @@ OSXClipboardBMPConverter::getOSXFormat() const
return CFSTR("com.microsoft.bmp"); return CFSTR("com.microsoft.bmp");
} }
String std::string OSXClipboardBMPConverter::fromIClipboard(const std::string& bmp) const
OSXClipboardBMPConverter::fromIClipboard(const String& bmp) const
{ {
LOG((CLOG_DEBUG1 "ENTER OSXClipboardBMPConverter::doFromIClipboard()")); LOG((CLOG_DEBUG1 "ENTER OSXClipboardBMPConverter::doFromIClipboard()"));
// create BMP image // create BMP image
@ -104,21 +103,20 @@ OSXClipboardBMPConverter::fromIClipboard(const String& bmp) const
toLE(dst, static_cast<UInt16>(0)); toLE(dst, static_cast<UInt16>(0));
toLE(dst, static_cast<UInt16>(0)); toLE(dst, static_cast<UInt16>(0));
toLE(dst, static_cast<UInt32>(14 + 40)); toLE(dst, static_cast<UInt32>(14 + 40));
return String(reinterpret_cast<const char*>(header), 14) + bmp; return std::string(reinterpret_cast<const char*>(header), 14) + bmp;
} }
String std::string OSXClipboardBMPConverter::toIClipboard(const std::string& bmp) const
OSXClipboardBMPConverter::toIClipboard(const String& bmp) const
{ {
// make sure data is big enough for a BMP file // make sure data is big enough for a BMP file
if (bmp.size() <= 14 + 40) { if (bmp.size() <= 14 + 40) {
return String(); return {};
} }
// check BMP file header // check BMP file header
const UInt8* rawBMPHeader = reinterpret_cast<const UInt8*>(bmp.data()); const UInt8* rawBMPHeader = reinterpret_cast<const UInt8*>(bmp.data());
if (rawBMPHeader[0] != 'B' || rawBMPHeader[1] != 'M') { if (rawBMPHeader[0] != 'B' || rawBMPHeader[1] != 'M') {
return String(); return {};
} }
// get offset to image data // get offset to image data

View File

@ -34,11 +34,10 @@ public:
getOSXFormat() const; getOSXFormat() const;
// OSXClipboardAnyBMPConverter overrides // OSXClipboardAnyBMPConverter overrides
virtual String fromIClipboard(const String&) const; virtual std::string fromIClipboard(const std::string&) const;
virtual String toIClipboard(const String&) const; virtual std::string toIClipboard(const std::string&) const;
// generic encoding converter // generic encoding converter
static String convertString(const String& data, static std::string convertString(const std::string& data, CFStringEncoding fromEncoding,
CFStringEncoding fromEncoding, CFStringEncoding toEncoding);
CFStringEncoding toEncoding);
}; };

View File

@ -42,18 +42,16 @@ OSXClipboardHTMLConverter::getOSXFormat() const
return CFSTR("public.html"); return CFSTR("public.html");
} }
String std::string OSXClipboardHTMLConverter::convertString(const std::string& data,
OSXClipboardHTMLConverter::convertString( CFStringEncoding fromEncoding,
const String& data, CFStringEncoding toEncoding)
CFStringEncoding fromEncoding,
CFStringEncoding toEncoding)
{ {
CFStringRef stringRef = CFStringCreateWithCString( CFStringRef stringRef = CFStringCreateWithCString(
kCFAllocatorDefault, kCFAllocatorDefault,
data.c_str(), fromEncoding); data.c_str(), fromEncoding);
if (stringRef == NULL) { if (stringRef == NULL) {
return String(); return {};
} }
CFIndex buffSize; CFIndex buffSize;
@ -66,13 +64,13 @@ OSXClipboardHTMLConverter::convertString(
if (buffer == NULL) { if (buffer == NULL) {
CFRelease(stringRef); CFRelease(stringRef);
return String(); return {};
} }
CFStringGetBytes(stringRef, entireString, toEncoding, CFStringGetBytes(stringRef, entireString, toEncoding,
0, false, (UInt8*)buffer, buffSize, NULL); 0, false, (UInt8*)buffer, buffSize, NULL);
String result(buffer, buffSize); std::string result(buffer, buffSize);
delete[] buffer; delete[] buffer;
CFRelease(stringRef); CFRelease(stringRef);
@ -80,15 +78,13 @@ OSXClipboardHTMLConverter::convertString(
return result; return result;
} }
String std::string OSXClipboardHTMLConverter::doFromIClipboard(const std::string& data) const
OSXClipboardHTMLConverter::doFromIClipboard(const String& data) const
{ {
return convertString(data, kCFStringEncodingUTF8, return convertString(data, kCFStringEncodingUTF8,
CFStringGetSystemEncoding()); CFStringGetSystemEncoding());
} }
String std::string OSXClipboardHTMLConverter::doToIClipboard(const std::string& data) const
OSXClipboardHTMLConverter::doToIClipboard(const String& data) const
{ {
return convertString(data, CFStringGetSystemEncoding(), return convertString(data, CFStringGetSystemEncoding(),
kCFStringEncodingUTF8); kCFStringEncodingUTF8);

View File

@ -34,11 +34,10 @@ public:
protected: protected:
// OSXClipboardAnyTextConverter overrides // OSXClipboardAnyTextConverter overrides
virtual String doFromIClipboard(const String&) const; virtual std::string doFromIClipboard(const std::string&) const;
virtual String doToIClipboard(const String&) const; virtual std::string doToIClipboard(const std::string&) const;
// generic encoding converter // generic encoding converter
static String convertString(const String& data, static std::string convertString(const std::string& data, CFStringEncoding fromEncoding,
CFStringEncoding fromEncoding, CFStringEncoding toEncoding);
CFStringEncoding toEncoding);
}; };

View File

@ -40,18 +40,16 @@ OSXClipboardTextConverter::getOSXFormat() const
return CFSTR("public.plain-text"); return CFSTR("public.plain-text");
} }
String std::string OSXClipboardTextConverter::convertString(const std::string& data,
OSXClipboardTextConverter::convertString( CFStringEncoding fromEncoding,
const String& data, CFStringEncoding toEncoding)
CFStringEncoding fromEncoding,
CFStringEncoding toEncoding)
{ {
CFStringRef stringRef = CFStringRef stringRef =
CFStringCreateWithCString(kCFAllocatorDefault, CFStringCreateWithCString(kCFAllocatorDefault,
data.c_str(), fromEncoding); data.c_str(), fromEncoding);
if (stringRef == NULL) { if (stringRef == NULL) {
return String(); return {};
} }
CFIndex buffSize; CFIndex buffSize;
@ -64,13 +62,13 @@ OSXClipboardTextConverter::convertString(
if (buffer == NULL) { if (buffer == NULL) {
CFRelease(stringRef); CFRelease(stringRef);
return String(); return {};
} }
CFStringGetBytes(stringRef, entireString, toEncoding, CFStringGetBytes(stringRef, entireString, toEncoding,
0, false, (UInt8*)buffer, buffSize, NULL); 0, false, (UInt8*)buffer, buffSize, NULL);
String result(buffer, buffSize); std::string result(buffer, buffSize);
delete[] buffer; delete[] buffer;
CFRelease(stringRef); CFRelease(stringRef);
@ -78,15 +76,13 @@ OSXClipboardTextConverter::convertString(
return result; return result;
} }
String std::string OSXClipboardTextConverter::doFromIClipboard(const std::string& data) const
OSXClipboardTextConverter::doFromIClipboard(const String& data) const
{ {
return convertString(data, kCFStringEncodingUTF8, return convertString(data, kCFStringEncodingUTF8,
CFStringGetSystemEncoding()); CFStringGetSystemEncoding());
} }
String std::string OSXClipboardTextConverter::doToIClipboard(const std::string& data) const
OSXClipboardTextConverter::doToIClipboard(const String& data) const
{ {
return convertString(data, CFStringGetSystemEncoding(), return convertString(data, CFStringGetSystemEncoding(),
kCFStringEncodingUTF8); kCFStringEncodingUTF8);

View File

@ -32,11 +32,10 @@ public:
protected: protected:
// OSXClipboardAnyTextConverter overrides // OSXClipboardAnyTextConverter overrides
virtual String doFromIClipboard(const String&) const; virtual std::string doFromIClipboard(const std::string&) const;
virtual String doToIClipboard(const String&) const; virtual std::string doToIClipboard(const std::string&) const;
// generic encoding converter // generic encoding converter
static String convertString(const String& data, static std::string convertString(const std::string& data, CFStringEncoding fromEncoding,
CFStringEncoding fromEncoding, CFStringEncoding toEncoding);
CFStringEncoding toEncoding);
}; };

View File

@ -40,15 +40,13 @@ OSXClipboardUTF16Converter::getOSXFormat() const
return CFSTR("public.utf16-plain-text"); return CFSTR("public.utf16-plain-text");
} }
String std::string OSXClipboardUTF16Converter::doFromIClipboard(const std::string& data) const
OSXClipboardUTF16Converter::doFromIClipboard(const String& data) const
{ {
// convert and add nul terminator // convert and add nul terminator
return Unicode::UTF8ToUTF16(data); return Unicode::UTF8ToUTF16(data);
} }
String std::string OSXClipboardUTF16Converter::doToIClipboard(const std::string& data) const
OSXClipboardUTF16Converter::doToIClipboard(const String& data) const
{ {
// convert and strip nul terminator // convert and strip nul terminator
return Unicode::UTF16ToUTF8(data); return Unicode::UTF16ToUTF8(data);

View File

@ -32,6 +32,6 @@ public:
protected: protected:
// OSXClipboardAnyTextConverter overrides // OSXClipboardAnyTextConverter overrides
virtual String doFromIClipboard(const String&) const; virtual std::string doFromIClipboard(const std::string&) const;
virtual String doToIClipboard(const String&) const; virtual std::string doToIClipboard(const std::string&) const;
}; };

View File

@ -97,9 +97,9 @@ public:
virtual void setSequenceNumber(UInt32); virtual void setSequenceNumber(UInt32);
virtual bool isPrimary() const; virtual bool isPrimary() const;
virtual void fakeDraggingFiles(DragFileList fileList); virtual void fakeDraggingFiles(DragFileList fileList);
virtual String& getDraggingFilename(); virtual std::string& getDraggingFilename();
const String& getDropTarget() const { return m_dropTarget; } const std::string& getDropTarget() const { return m_dropTarget; }
void waitForCarbonLoop() const; void waitForCarbonLoop() const;
protected: protected:
@ -338,7 +338,7 @@ private:
IEventQueue* m_events; IEventQueue* m_events;
Thread* m_getDropTargetThread; Thread* m_getDropTargetThread;
String m_dropTarget; std::string m_dropTarget;
#if defined(MAC_OS_X_VERSION_10_7) #if defined(MAC_OS_X_VERSION_10_7)
Mutex* m_carbonLoopMutex; Mutex* m_carbonLoopMutex;

View File

@ -170,7 +170,7 @@ XWindowsClipboard::addSimpleRequest(Window requestor,
} }
// handle targets // handle targets
String data; std::string data;
Atom type = None; Atom type = None;
int format = 0; int format = 0;
if (target == m_atomTargets) { if (target == m_atomTargets) {
@ -303,8 +303,7 @@ XWindowsClipboard::empty()
return true; return true;
} }
void void XWindowsClipboard::add(EFormat format, const std::string& data)
XWindowsClipboard::add(EFormat format, const String& data)
{ {
assert(m_open); assert(m_open);
assert(m_owner); assert(m_owner);
@ -387,8 +386,7 @@ XWindowsClipboard::has(EFormat format) const
return m_added[format]; return m_added[format];
} }
String std::string XWindowsClipboard::get(EFormat format) const
XWindowsClipboard::get(EFormat format) const
{ {
assert(m_open); assert(m_open);
@ -513,7 +511,7 @@ XWindowsClipboard::icccmFillCache()
// instead of the correct type ATOM; allow either. // instead of the correct type ATOM; allow either.
const Atom atomTargets = m_atomTargets; const Atom atomTargets = m_atomTargets;
Atom target; Atom target;
String data; std::string data;
if (!icccmGetSelection(atomTargets, &target, &data) || if (!icccmGetSelection(atomTargets, &target, &data) ||
(target != m_atomAtom && target != m_atomTargets)) { (target != m_atomAtom && target != m_atomTargets)) {
LOG((CLOG_DEBUG1 "selection doesn't support TARGETS")); LOG((CLOG_DEBUG1 "selection doesn't support TARGETS"));
@ -557,7 +555,7 @@ XWindowsClipboard::icccmFillCache()
// get the data // get the data
Atom actualTarget; Atom actualTarget;
String targetData; std::string targetData;
if (!icccmGetSelection(target, &actualTarget, &targetData)) { if (!icccmGetSelection(target, &actualTarget, &targetData)) {
LOG((CLOG_DEBUG1 " no data for target %s", XWindowsUtil::atomToString(m_display, target).c_str())); LOG((CLOG_DEBUG1 " no data for target %s", XWindowsUtil::atomToString(m_display, target).c_str()));
continue; continue;
@ -573,7 +571,7 @@ XWindowsClipboard::icccmFillCache()
bool bool
XWindowsClipboard::icccmGetSelection(Atom target, XWindowsClipboard::icccmGetSelection(Atom target,
Atom* actualTarget, String* data) const Atom* actualTarget, std::string* data) const
{ {
assert(actualTarget != NULL); assert(actualTarget != NULL);
assert(data != NULL); assert(data != NULL);
@ -597,7 +595,7 @@ IClipboard::Time
XWindowsClipboard::icccmGetTime() const XWindowsClipboard::icccmGetTime() const
{ {
Atom actualTarget; Atom actualTarget;
String data; std::string data;
if (icccmGetSelection(m_atomTimestamp, &actualTarget, &data) && if (icccmGetSelection(m_atomTimestamp, &actualTarget, &data) &&
actualTarget == m_atomInteger) { actualTarget == m_atomInteger) {
Time time = *reinterpret_cast<const Time*>(data.data()); Time time = *reinterpret_cast<const Time*>(data.data());
@ -668,7 +666,7 @@ XWindowsClipboard::motifOwnsClipboard() const
// get the Motif clipboard header property from the root window // get the Motif clipboard header property from the root window
Atom target; Atom target;
SInt32 format; SInt32 format;
String data; std::string data;
Window root = RootWindow(m_display, DefaultScreen(m_display)); Window root = RootWindow(m_display, DefaultScreen(m_display));
if (!XWindowsUtil::getWindowProperty(m_display, root, if (!XWindowsUtil::getWindowProperty(m_display, root,
m_atomMotifClipHeader, m_atomMotifClipHeader,
@ -697,7 +695,7 @@ XWindowsClipboard::motifFillCache()
// get the Motif clipboard header property from the root window // get the Motif clipboard header property from the root window
Atom target; Atom target;
SInt32 format; SInt32 format;
String data; std::string data;
Window root = RootWindow(m_display, DefaultScreen(m_display)); Window root = RootWindow(m_display, DefaultScreen(m_display));
if (!XWindowsUtil::getWindowProperty(m_display, root, if (!XWindowsUtil::getWindowProperty(m_display, root,
m_atomMotifClipHeader, m_atomMotifClipHeader,
@ -741,13 +739,13 @@ XWindowsClipboard::motifFillCache()
static_cast<const char*>(data.data())); static_cast<const char*>(data.data()));
// get the available formats // get the available formats
typedef std::map<Atom, String> MotifFormatMap; typedef std::map<Atom, std::string> MotifFormatMap;
MotifFormatMap motifFormats; MotifFormatMap motifFormats;
for (SInt32 i = 0; i < numFormats; ++i) { for (SInt32 i = 0; i < numFormats; ++i) {
// get Motif format property from the root window // get Motif format property from the root window
sprintf(name, "_MOTIF_CLIP_ITEM_%d", formats[i]); sprintf(name, "_MOTIF_CLIP_ITEM_%d", formats[i]);
Atom atomFormat = m_impl->XInternAtom(m_display, name, False); Atom atomFormat = m_impl->XInternAtom(m_display, name, False);
String data; std::string data;
if (!XWindowsUtil::getWindowProperty(m_display, root, if (!XWindowsUtil::getWindowProperty(m_display, root,
atomFormat, &data, atomFormat, &data,
&target, &format, False)) { &target, &format, False)) {
@ -797,7 +795,7 @@ XWindowsClipboard::motifFillCache()
// get the data (finally) // get the data (finally)
Atom actualTarget; Atom actualTarget;
String targetData; std::string targetData;
if (!motifGetSelection(&motifFormat, &actualTarget, &targetData)) { if (!motifGetSelection(&motifFormat, &actualTarget, &targetData)) {
LOG((CLOG_DEBUG1 " no data for target %s", XWindowsUtil::atomToString(m_display, target).c_str())); LOG((CLOG_DEBUG1 " no data for target %s", XWindowsUtil::atomToString(m_display, target).c_str()));
continue; continue;
@ -813,7 +811,7 @@ XWindowsClipboard::motifFillCache()
bool bool
XWindowsClipboard::motifGetSelection(const MotifClipFormat* format, XWindowsClipboard::motifGetSelection(const MotifClipFormat* format,
Atom* actualTarget, String* data) const Atom* actualTarget, std::string* data) const
{ {
// if the current clipboard owner and the owner indicated by the // if the current clipboard owner and the owner indicated by the
// motif clip header are the same then transfer via a property on // motif clip header are the same then transfer via a property on
@ -849,7 +847,7 @@ XWindowsClipboard::insertMultipleReply(Window requestor,
// get the requested targets // get the requested targets
Atom target; Atom target;
SInt32 format; SInt32 format;
String data; std::string data;
if (!XWindowsUtil::getWindowProperty(m_display, requestor, if (!XWindowsUtil::getWindowProperty(m_display, requestor,
property, &data, &target, &format, False)) { property, &data, &target, &format, False)) {
// can't get the requested targets // can't get the requested targets
@ -887,7 +885,7 @@ XWindowsClipboard::insertMultipleReply(Window requestor,
// add reply for MULTIPLE request // add reply for MULTIPLE request
insertReply(new Reply(requestor, m_atomMultiple, insertReply(new Reply(requestor, m_atomMultiple,
time, property, String(), None, 32)); time, property, std::string(), None, 32));
return true; return true;
} }
@ -1101,7 +1099,7 @@ XWindowsClipboard::sendReply(Reply* reply)
LOG((CLOG_DEBUG2 "properties of 0x%08x:", reply->m_requestor)); LOG((CLOG_DEBUG2 "properties of 0x%08x:", reply->m_requestor));
for (int i = 0; i < n; ++i) { for (int i = 0; i < n; ++i) {
Atom target; Atom target;
String data; std::string data;
char* name = m_impl->XGetAtomName(m_display, props[i]); char* name = m_impl->XGetAtomName(m_display, props[i]);
if (!XWindowsUtil::getWindowProperty(m_display, if (!XWindowsUtil::getWindowProperty(m_display,
reply->m_requestor, reply->m_requestor,
@ -1112,9 +1110,9 @@ XWindowsClipboard::sendReply(Reply* reply)
// if there are any non-ascii characters in string // if there are any non-ascii characters in string
// then print the binary data. // then print the binary data.
static const char* hex = "0123456789abcdef"; static const char* hex = "0123456789abcdef";
for (String::size_type j = 0; j < data.size(); ++j) { for (std::string::size_type j = 0; j < data.size(); ++j) {
if (data[j] < 32 || data[j] > 126) { if (data[j] < 32 || data[j] > 126) {
String tmp; std::string tmp;
tmp.reserve(data.size() * 3); tmp.reserve(data.size() * 3);
for (j = 0; j < data.size(); ++j) { for (j = 0; j < data.size(); ++j) {
unsigned char v = (unsigned char)data[j]; unsigned char v = (unsigned char)data[j];
@ -1221,8 +1219,7 @@ XWindowsClipboard::wasOwnedAtTime(::Time time) const
return (/*when >= 0 &&*/ when <= duration); return (/*when >= 0 &&*/ when <= duration);
} }
Atom Atom XWindowsClipboard::getTargetsData(std::string& data, int* format) const
XWindowsClipboard::getTargetsData(String& data, int* format) const
{ {
assert(format != NULL); assert(format != NULL);
@ -1246,8 +1243,7 @@ XWindowsClipboard::getTargetsData(String& data, int* format) const
return m_atomAtom; return m_atomAtom;
} }
Atom Atom XWindowsClipboard::getTimestampData(std::string& data, int* format) const
XWindowsClipboard::getTimestampData(String& data, int* format) const
{ {
assert(format != NULL); assert(format != NULL);
@ -1285,7 +1281,7 @@ XWindowsClipboard::CICCCMGetClipboard::~CICCCMGetClipboard()
bool bool
XWindowsClipboard::CICCCMGetClipboard::readClipboard(Display* display, XWindowsClipboard::CICCCMGetClipboard::readClipboard(Display* display,
Atom selection, Atom target, Atom* actualTarget, String* data) Atom selection, Atom target, Atom* actualTarget, std::string* data)
{ {
assert(actualTarget != NULL); assert(actualTarget != NULL);
assert(data != NULL); assert(data != NULL);
@ -1430,7 +1426,7 @@ XWindowsClipboard::CICCCMGetClipboard::processEvent(
// get the data from the property // get the data from the property
Atom target; Atom target;
const String::size_type oldSize = m_data->size(); const std::string::size_type oldSize = m_data->size();
if (!XWindowsUtil::getWindowProperty(display, m_requestor, if (!XWindowsUtil::getWindowProperty(display, m_requestor,
m_property, m_data, &target, NULL, True)) { m_property, m_data, &target, NULL, True)) {
// unable to read property // unable to read property
@ -1515,7 +1511,7 @@ XWindowsClipboard::Reply::Reply(Window requestor, Atom target, ::Time time) :
} }
XWindowsClipboard::Reply::Reply(Window requestor, Atom target, ::Time time, XWindowsClipboard::Reply::Reply(Window requestor, Atom target, ::Time time,
Atom property, const String& data, Atom type, int format) : Atom property, const std::string& data, Atom type, int format) :
m_requestor(requestor), m_requestor(requestor),
m_target(target), m_target(target),
m_time(time), m_time(time),

View File

@ -90,12 +90,12 @@ public:
// IClipboard overrides // IClipboard overrides
virtual bool empty(); virtual bool empty();
virtual void add(EFormat, const String& data); virtual void add(EFormat, const std::string& data);
virtual bool open(Time) const; virtual bool open(Time) const;
virtual void close() const; virtual void close() const;
virtual Time getTime() const; virtual Time getTime() const;
virtual bool has(EFormat) const; virtual bool has(EFormat) const;
virtual String get(EFormat) const; virtual std::string get(EFormat) const;
private: private:
// remove all converters from our list // remove all converters from our list
@ -148,7 +148,7 @@ private:
// cannot be performed (in which case *actualTarget == None). // cannot be performed (in which case *actualTarget == None).
bool readClipboard(Display* display, bool readClipboard(Display* display,
Atom selection, Atom target, Atom selection, Atom target,
Atom* actualTarget, String* data); Atom* actualTarget, std::string* data);
private: private:
bool processEvent(Display* display, XEvent* event); bool processEvent(Display* display, XEvent* event);
@ -169,7 +169,7 @@ private:
bool m_reading; bool m_reading;
// the converted selection data // the converted selection data
String* m_data; std::string* m_data;
// the actual type of the data. if this is None then the // the actual type of the data. if this is None then the
// selection owner cannot convert to the requested type. // selection owner cannot convert to the requested type.
@ -224,8 +224,8 @@ private:
class Reply { class Reply {
public: public:
Reply(Window, Atom target, ::Time); Reply(Window, Atom target, ::Time);
Reply(Window, Atom target, ::Time, Atom property, Reply(Window, Atom target, ::Time, Atom property, const std::string& data,
const String& data, Atom type, int format); Atom type, int format);
public: public:
// information about the request // information about the request
@ -241,7 +241,7 @@ private:
bool m_done; bool m_done;
// the data to send and its type and format // the data to send and its type and format
String m_data; std::string m_data;
Atom m_type; Atom m_type;
int m_format; int m_format;
@ -254,8 +254,7 @@ private:
// ICCCM interoperability methods // ICCCM interoperability methods
void icccmFillCache(); void icccmFillCache();
bool icccmGetSelection(Atom target, bool icccmGetSelection(Atom target, Atom* actualTarget, std::string* data) const;
Atom* actualTarget, String* data) const;
Time icccmGetTime() const; Time icccmGetTime() const;
// motif interoperability methods // motif interoperability methods
@ -263,8 +262,7 @@ private:
void motifUnlockClipboard() const; void motifUnlockClipboard() const;
bool motifOwnsClipboard() const; bool motifOwnsClipboard() const;
void motifFillCache(); void motifFillCache();
bool motifGetSelection(const MotifClipFormat*, bool motifGetSelection(const MotifClipFormat*, Atom* actualTarget, std::string* data) const;
Atom* actualTarget, String* data) const;
Time motifGetTime() const; Time motifGetTime() const;
// reply methods // reply methods
@ -281,8 +279,8 @@ private:
bool wasOwnedAtTime(::Time) const; bool wasOwnedAtTime(::Time) const;
// data conversion methods // data conversion methods
Atom getTargetsData(String&, int* format) const; Atom getTargetsData(std::string&, int* format) const;
Atom getTimestampData(String&, int* format) const; Atom getTimestampData(std::string&, int* format) const;
private: private:
typedef std::vector<IXWindowsClipboardConverter*> ConverterList; typedef std::vector<IXWindowsClipboardConverter*> ConverterList;
@ -306,7 +304,7 @@ private:
bool m_cached; bool m_cached;
Time m_cacheTime; Time m_cacheTime;
bool m_added[kNumFormats]; bool m_added[kNumFormats];
String m_data[kNumFormats]; std::string m_data[kNumFormats];
// conversion request replies // conversion request replies
ReplyMap m_replies; ReplyMap m_replies;
@ -368,14 +366,14 @@ public:
getFormat(). The return data will be in the X selection getFormat(). The return data will be in the X selection
format returned by getAtom(). format returned by getAtom().
*/ */
virtual String fromIClipboard(const String&) const = 0; virtual std::string fromIClipboard(const std::string&) const = 0;
//! Convert to IClipboard format //! Convert to IClipboard format
/*! /*!
Convert from the X selection format to the IClipboard format Convert from the X selection format to the IClipboard format
(i.e., the reverse of fromIClipboard()). (i.e., the reverse of fromIClipboard()).
*/ */
virtual String toIClipboard(const String&) const = 0; virtual std::string toIClipboard(const std::string&) const = 0;
//@} //@}
}; };

View File

@ -122,8 +122,7 @@ XWindowsClipboardAnyBitmapConverter::getDataSize() const
return 8; return 8;
} }
String std::string XWindowsClipboardAnyBitmapConverter::fromIClipboard(const std::string& bmp) const
XWindowsClipboardAnyBitmapConverter::fromIClipboard(const String& bmp) const
{ {
// fill BMP info header with native-endian data // fill BMP info header with native-endian data
CBMPInfoHeader infoHeader; CBMPInfoHeader infoHeader;
@ -145,7 +144,7 @@ XWindowsClipboardAnyBitmapConverter::fromIClipboard(const String& bmp) const
infoHeader.biWidth == 0 || infoHeader.biHeight == 0 || infoHeader.biWidth == 0 || infoHeader.biHeight == 0 ||
infoHeader.biPlanes != 0 || infoHeader.biCompression != 0 || infoHeader.biPlanes != 0 || infoHeader.biCompression != 0 ||
(infoHeader.biBitCount != 24 && infoHeader.biBitCount != 32)) { (infoHeader.biBitCount != 24 && infoHeader.biBitCount != 32)) {
return String(); return {};
} }
// convert to image format // convert to image format
@ -160,14 +159,13 @@ XWindowsClipboardAnyBitmapConverter::fromIClipboard(const String& bmp) const
} }
} }
String std::string XWindowsClipboardAnyBitmapConverter::toIClipboard(const std::string& image) const
XWindowsClipboardAnyBitmapConverter::toIClipboard(const String& image) const
{ {
// convert to raw BMP data // convert to raw BMP data
UInt32 w, h, depth; UInt32 w, h, depth;
String rawBMP = doToIClipboard(image, w, h, depth); std::string rawBMP = doToIClipboard(image, w, h, depth);
if (rawBMP.empty() || w == 0 || h == 0 || (depth != 24 && depth != 32)) { if (rawBMP.empty() || w == 0 || h == 0 || (depth != 24 && depth != 32)) {
return String(); return {};
} }
// fill BMP info header with little-endian data // fill BMP info header with little-endian data
@ -186,6 +184,6 @@ XWindowsClipboardAnyBitmapConverter::toIClipboard(const String& image) const
toLE(dst, static_cast<UInt32>(0)); toLE(dst, static_cast<UInt32>(0));
// construct image // construct image
return String(reinterpret_cast<const char*>(infoHeader), return std::string(reinterpret_cast<const char*>(infoHeader),
sizeof(infoHeader)) + rawBMP; sizeof(infoHeader)) + rawBMP;
} }

View File

@ -32,29 +32,27 @@ public:
getFormat() const; getFormat() const;
virtual Atom getAtom() const = 0; virtual Atom getAtom() const = 0;
virtual int getDataSize() const; virtual int getDataSize() const;
virtual String fromIClipboard(const String&) const; virtual std::string fromIClipboard(const std::string&) const;
virtual String toIClipboard(const String&) const; virtual std::string toIClipboard(const std::string&) const;
protected: protected:
//! Convert from IClipboard format //! Convert from IClipboard format
/*! /*!
Convert raw BGR pixel data to another image format. Convert raw BGR pixel data to another image format.
*/ */
virtual String doBGRFromIClipboard(const UInt8* bgrData, virtual std::string doBGRFromIClipboard(const UInt8* bgrData, UInt32 w, UInt32 h) const = 0;
UInt32 w, UInt32 h) const = 0;
//! Convert from IClipboard format //! Convert from IClipboard format
/*! /*!
Convert raw BGRA pixel data to another image format. Convert raw BGRA pixel data to another image format.
*/ */
virtual String doBGRAFromIClipboard(const UInt8* bgrData, virtual std::string doBGRAFromIClipboard(const UInt8* bgrData, UInt32 w, UInt32 h) const = 0;
UInt32 w, UInt32 h) const = 0;
//! Convert to IClipboard format //! Convert to IClipboard format
/*! /*!
Convert an image into raw BGR or BGRA image data and store the Convert an image into raw BGR or BGRA image data and store the
width, height, and image depth (24 or 32). width, height, and image depth (24 or 32).
*/ */
virtual String doToIClipboard(const String&, virtual std::string doToIClipboard(const std::string&, UInt32& w, UInt32& h,
UInt32& w, UInt32& h, UInt32& depth) const = 0; UInt32& depth) const = 0;
}; };

View File

@ -101,8 +101,7 @@ XWindowsClipboardBMPConverter::getDataSize() const
return 8; return 8;
} }
String std::string XWindowsClipboardBMPConverter::fromIClipboard(const std::string& bmp) const
XWindowsClipboardBMPConverter::fromIClipboard(const String& bmp) const
{ {
// create BMP image // create BMP image
UInt8 header[14]; UInt8 header[14];
@ -113,21 +112,20 @@ XWindowsClipboardBMPConverter::fromIClipboard(const String& bmp) const
toLE(dst, static_cast<UInt16>(0)); toLE(dst, static_cast<UInt16>(0));
toLE(dst, static_cast<UInt16>(0)); toLE(dst, static_cast<UInt16>(0));
toLE(dst, static_cast<UInt32>(14 + 40)); toLE(dst, static_cast<UInt32>(14 + 40));
return String(reinterpret_cast<const char*>(header), 14) + bmp; return std::string(reinterpret_cast<const char*>(header), 14) + bmp;
} }
String std::string XWindowsClipboardBMPConverter::toIClipboard(const std::string& bmp) const
XWindowsClipboardBMPConverter::toIClipboard(const String& bmp) const
{ {
// make sure data is big enough for a BMP file // make sure data is big enough for a BMP file
if (bmp.size() <= 14 + 40) { if (bmp.size() <= 14 + 40) {
return String(); return {};
} }
// check BMP file header // check BMP file header
const UInt8* rawBMPHeader = reinterpret_cast<const UInt8*>(bmp.data()); const UInt8* rawBMPHeader = reinterpret_cast<const UInt8*>(bmp.data());
if (rawBMPHeader[0] != 'B' || rawBMPHeader[1] != 'M') { if (rawBMPHeader[0] != 'B' || rawBMPHeader[1] != 'M') {
return String(); return {};
} }
// get offset to image data // get offset to image data

View File

@ -32,8 +32,8 @@ public:
getFormat() const; getFormat() const;
virtual Atom getAtom() const; virtual Atom getAtom() const;
virtual int getDataSize() const; virtual int getDataSize() const;
virtual String fromIClipboard(const String&) const; virtual std::string fromIClipboard(const std::string&) const;
virtual String toIClipboard(const String&) const; virtual std::string toIClipboard(const std::string&) const;
private: private:
Atom m_atom; Atom m_atom;

View File

@ -54,14 +54,12 @@ XWindowsClipboardHTMLConverter::getDataSize() const
return 8; return 8;
} }
String std::string XWindowsClipboardHTMLConverter::fromIClipboard(const std::string& data) const
XWindowsClipboardHTMLConverter::fromIClipboard(const String& data) const
{ {
return Unicode::UTF8ToUTF16(data); return Unicode::UTF8ToUTF16(data);
} }
String std::string XWindowsClipboardHTMLConverter::toIClipboard(const std::string& data) const
XWindowsClipboardHTMLConverter::toIClipboard(const String& data) const
{ {
return Unicode::UTF16ToUTF8(data); return Unicode::UTF16ToUTF8(data);
} }

View File

@ -34,8 +34,8 @@ public:
getFormat() const; getFormat() const;
virtual Atom getAtom() const; virtual Atom getAtom() const;
virtual int getDataSize() const; virtual int getDataSize() const;
virtual String fromIClipboard(const String&) const; virtual std::string fromIClipboard(const std::string&) const;
virtual String toIClipboard(const String&) const; virtual std::string toIClipboard(const std::string&) const;
private: private:
Atom m_atom; Atom m_atom;

View File

@ -54,18 +54,16 @@ XWindowsClipboardTextConverter::getDataSize() const
return 8; return 8;
} }
String std::string XWindowsClipboardTextConverter::fromIClipboard(const std::string& data) const
XWindowsClipboardTextConverter::fromIClipboard(const String& data) const
{ {
return Unicode::UTF8ToText(data); return Unicode::UTF8ToText(data);
} }
String std::string XWindowsClipboardTextConverter::toIClipboard(const std::string& data) const
XWindowsClipboardTextConverter::toIClipboard(const String& data) const
{ {
// convert to UTF-8 // convert to UTF-8
bool errors; bool errors;
String utf8 = Unicode::textToUTF8(data, &errors); std::string utf8 = Unicode::textToUTF8(data, &errors);
// if there were decoding errors then, to support old applications // if there were decoding errors then, to support old applications
// that don't understand UTF-8 but can report the exact binary // that don't understand UTF-8 but can report the exact binary

View File

@ -34,8 +34,8 @@ public:
getFormat() const; getFormat() const;
virtual Atom getAtom() const; virtual Atom getAtom() const;
virtual int getDataSize() const; virtual int getDataSize() const;
virtual String fromIClipboard(const String&) const; virtual std::string fromIClipboard(const std::string&) const;
virtual String toIClipboard(const String&) const; virtual std::string toIClipboard(const std::string&) const;
private: private:
Atom m_atom; Atom m_atom;

View File

@ -54,14 +54,12 @@ XWindowsClipboardUCS2Converter::getDataSize() const
return 16; return 16;
} }
String std::string XWindowsClipboardUCS2Converter::fromIClipboard(const std::string& data) const
XWindowsClipboardUCS2Converter::fromIClipboard(const String& data) const
{ {
return Unicode::UTF8ToUCS2(data); return Unicode::UTF8ToUCS2(data);
} }
String std::string XWindowsClipboardUCS2Converter::toIClipboard(const std::string& data) const
XWindowsClipboardUCS2Converter::toIClipboard(const String& data) const
{ {
return Unicode::UCS2ToUTF8(data); return Unicode::UCS2ToUTF8(data);
} }

View File

@ -34,8 +34,8 @@ public:
getFormat() const; getFormat() const;
virtual Atom getAtom() const; virtual Atom getAtom() const;
virtual int getDataSize() const; virtual int getDataSize() const;
virtual String fromIClipboard(const String&) const; virtual std::string fromIClipboard(const std::string&) const;
virtual String toIClipboard(const String&) const; virtual std::string toIClipboard(const std::string&) const;
private: private:
Atom m_atom; Atom m_atom;

View File

@ -52,14 +52,12 @@ XWindowsClipboardUTF8Converter::getDataSize() const
return 8; return 8;
} }
String std::string XWindowsClipboardUTF8Converter::fromIClipboard(const std::string& data) const
XWindowsClipboardUTF8Converter::fromIClipboard(const String& data) const
{ {
return data; return data;
} }
String std::string XWindowsClipboardUTF8Converter::toIClipboard(const std::string& data) const
XWindowsClipboardUTF8Converter::toIClipboard(const String& data) const
{ {
return data; return data;
} }

View File

@ -34,8 +34,8 @@ public:
getFormat() const; getFormat() const;
virtual Atom getAtom() const; virtual Atom getAtom() const;
virtual int getDataSize() const; virtual int getDataSize() const;
virtual String fromIClipboard(const String&) const; virtual std::string fromIClipboard(const std::string&) const;
virtual String toIClipboard(const String&) const; virtual std::string toIClipboard(const std::string&) const;
private: private:
Atom m_atom; Atom m_atom;

View File

@ -20,7 +20,6 @@
#include "platform/XWindowsUtil.h" #include "platform/XWindowsUtil.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/String.h"
#include "common/stdmap.h" #include "common/stdmap.h"
#include <cstddef> #include <cstddef>

View File

@ -30,7 +30,6 @@
#include "arch/Arch.h" #include "arch/Arch.h"
#include "base/Log.h" #include "base/Log.h"
#include "base/Stopwatch.h" #include "base/Stopwatch.h"
#include "base/String.h"
#include "base/IEventQueue.h" #include "base/IEventQueue.h"
#include "base/TMethodEventJob.h" #include "base/TMethodEventJob.h"

View File

@ -1294,7 +1294,7 @@ XWindowsUtil::KeySymMap XWindowsUtil::s_keySymToUCS4;
bool bool
XWindowsUtil::getWindowProperty(Display* display, Window window, XWindowsUtil::getWindowProperty(Display* display, Window window,
Atom property, String* data, Atom* type, Atom property, std::string* data, Atom* type,
SInt32* format, bool deleteProperty) SInt32* format, bool deleteProperty)
{ {
assert(display != NULL); assert(display != NULL);
@ -1608,8 +1608,7 @@ XWindowsUtil::getModifierBitForKeySym(KeySym keysym)
} }
} }
String std::string XWindowsUtil::atomToString(Display* display, Atom atom)
XWindowsUtil::atomToString(Display* display, Atom atom)
{ {
if (atom == 0) { if (atom == 0) {
return "None"; return "None";
@ -1622,20 +1621,19 @@ XWindowsUtil::atomToString(Display* display, Atom atom)
return barrier::string::sprintf("<UNKNOWN> (%d)", (int)atom); return barrier::string::sprintf("<UNKNOWN> (%d)", (int)atom);
} }
else { else {
String msg = barrier::string::sprintf("%s (%d)", name, (int)atom); std::string msg = barrier::string::sprintf("%s (%d)", name, (int)atom);
XFree(name); XFree(name);
return msg; return msg;
} }
} }
String std::string XWindowsUtil::atomsToString(Display* display, const Atom* atom, UInt32 num)
XWindowsUtil::atomsToString(Display* display, const Atom* atom, UInt32 num)
{ {
char** names = new char*[num]; char** names = new char*[num];
bool error = false; bool error = false;
XWindowsUtil::ErrorLock lock(display, &error); XWindowsUtil::ErrorLock lock(display, &error);
XGetAtomNames(display, const_cast<Atom*>(atom), (int)num, names); XGetAtomNames(display, const_cast<Atom*>(atom), (int)num, names);
String msg; std::string msg;
if (error) { if (error) {
for (UInt32 i = 0; i < num; ++i) { for (UInt32 i = 0; i < num; ++i) {
msg += barrier::string::sprintf("<UNKNOWN> (%d), ", (int)atom[i]); msg += barrier::string::sprintf("<UNKNOWN> (%d), ", (int)atom[i]);
@ -1654,8 +1652,7 @@ XWindowsUtil::atomsToString(Display* display, const Atom* atom, UInt32 num)
return msg; return msg;
} }
void void XWindowsUtil::convertAtomProperty(std::string& data)
XWindowsUtil::convertAtomProperty(String& data)
{ {
// as best i can tell, 64-bit systems don't pack Atoms into properties // as best i can tell, 64-bit systems don't pack Atoms into properties
// as 32-bit numbers but rather as the 64-bit numbers they are. that // as 32-bit numbers but rather as the 64-bit numbers they are. that
@ -1669,22 +1666,19 @@ XWindowsUtil::convertAtomProperty(String& data)
} }
} }
void void XWindowsUtil::appendAtomData(std::string& data, Atom atom)
XWindowsUtil::appendAtomData(String& data, Atom atom)
{ {
data.append(reinterpret_cast<char*>(&atom), sizeof(Atom)); data.append(reinterpret_cast<char*>(&atom), sizeof(Atom));
} }
void void XWindowsUtil::replaceAtomData(std::string& data, UInt32 index, Atom atom)
XWindowsUtil::replaceAtomData(String& data, UInt32 index, Atom atom)
{ {
data.replace(index * sizeof(Atom), sizeof(Atom), data.replace(index * sizeof(Atom), sizeof(Atom),
reinterpret_cast<const char*>(&atom), reinterpret_cast<const char*>(&atom),
sizeof(Atom)); sizeof(Atom));
} }
void void XWindowsUtil::appendTimeData(std::string& data, Time time)
XWindowsUtil::appendTimeData(String& data, Time time)
{ {
data.append(reinterpret_cast<char*>(&time), sizeof(Time)); data.append(reinterpret_cast<char*>(&time), sizeof(Time));
} }

View File

@ -18,7 +18,6 @@
#pragma once #pragma once
#include "base/String.h"
#include "base/EventTypes.h" #include "base/EventTypes.h"
#include "common/stdmap.h" #include "common/stdmap.h"
#include "common/stdvector.h" #include "common/stdvector.h"
@ -29,6 +28,8 @@
# include <X11/Xlib.h> # include <X11/Xlib.h>
#endif #endif
#include <string>
//! X11 utility functions //! X11 utility functions
class XWindowsUtil { class XWindowsUtil {
public: public:
@ -42,10 +43,9 @@ public:
if \c format is not NULL. If \c deleteProperty is true then the if \c format is not NULL. If \c deleteProperty is true then the
property is deleted after being read. property is deleted after being read.
*/ */
static bool getWindowProperty(Display*, static bool getWindowProperty(Display*, Window window, Atom property,
Window window, Atom property, std::string* data, Atom* type,
String* data, Atom* type, SInt32* format, bool deleteProperty);
SInt32* format, bool deleteProperty);
//! Set property //! Set property
/*! /*!
@ -81,44 +81,42 @@ public:
/*! /*!
Converts \p atom to its string representation. Converts \p atom to its string representation.
*/ */
static String atomToString(Display*, Atom atom); static std::string atomToString(Display*, Atom atom);
//! Convert several Atoms to a string //! Convert several Atoms to a string
/*! /*!
Converts each atom in \p atoms to its string representation and Converts each atom in \p atoms to its string representation and
concatenates the results. concatenates the results.
*/ */
static String atomsToString(Display* display, static std::string atomsToString(Display* display, const Atom* atom, UInt32 num);
const Atom* atom, UInt32 num);
//! Prepare a property of atoms for use //! Prepare a property of atoms for use
/*! /*!
64-bit systems may need to modify a property's data if it's a 64-bit systems may need to modify a property's data if it's a
list of Atoms before using it. list of Atoms before using it.
*/ */
static void convertAtomProperty(String& data); static void convertAtomProperty(std::string& data);
//! Append an Atom to property data //! Append an Atom to property data
/*! /*!
Converts \p atom to a 32-bit on-the-wire format and appends it to Converts \p atom to a 32-bit on-the-wire format and appends it to
\p data. \p data.
*/ */
static void appendAtomData(String& data, Atom atom); static void appendAtomData(std::string& data, Atom atom);
//! Replace an Atom in property data //! Replace an Atom in property data
/*! /*!
Converts \p atom to a 32-bit on-the-wire format and replaces the atom Converts \p atom to a 32-bit on-the-wire format and replaces the atom
at index \p index in \p data. at index \p index in \p data.
*/ */
static void replaceAtomData(String& data, static void replaceAtomData(std::string& data, UInt32 index, Atom atom);
UInt32 index, Atom atom);
//! Append an Time to property data //! Append an Time to property data
/*! /*!
Converts \p time to a 32-bit on-the-wire format and appends it to Converts \p time to a 32-bit on-the-wire format and appends it to
\p data. \p data.
*/ */
static void appendTimeData(String& data, Time time); static void appendTimeData(std::string& data, Time time);
//! X11 error handler //! X11 error handler
/*! /*!