Added some tentative wxMotif clipboard code; did some file formatting

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1408 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
1999-01-14 15:15:39 +00:00
parent 8de2e39c17
commit 2d120f8391
46 changed files with 9903 additions and 9564 deletions

View File

@@ -20,218 +20,508 @@
#include "wx/utils.h"
#include "wx/metafile.h"
#include "wx/clipbrd.h"
#include "wx/dataobj.h"
#include <Xm/Xm.h>
#include <Xm/CutPaste.h>
#include <string.h>
#if !USE_SHARED_LIBRARY
IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject)
IMPLEMENT_ABSTRACT_CLASS(wxClipboardClient, wxObject)
// IMPLEMENT_DYNAMIC_CLASS(wxClipboard, wxObject)
// IMPLEMENT_ABSTRACT_CLASS(wxClipboardClient, wxObject)
#endif
static bool gs_clipboardIsOpen = FALSE;
bool wxOpenClipboard()
{
// TODO
return FALSE;
if (!gs_clipboardIsOpen)
{
gs_clipboardIsOpen = TRUE;
return TRUE;
}
else
return FALSE;
}
bool wxCloseClipboard()
{
// TODO
return FALSE;
if (gs_clipboardIsOpen)
{
gs_clipboardIsOpen = FALSE;
return TRUE;
}
else
return FALSE;
}
bool wxEmptyClipboard()
{
// TODO
return FALSE;
// No equivalent in Motif
return TRUE;
}
bool wxClipboardOpen()
{
// TODO
return FALSE;
return gs_clipboardIsOpen;
}
bool wxIsClipboardFormatAvailable(int dataFormat)
bool wxIsClipboardFormatAvailable(wxDataFormat dataFormat)
{
// TODO
return FALSE;
// Only text is supported.
if (dataFormat != wxDF_TEXT)
return FALSE;
unsigned long numBytes = 0;
long privateId = 0;
Window window = (Window) 0;
if (wxTheApp->GetTopWindow())
window = XtWindow( (Widget) wxTheApp->GetTopWindow()->GetTopWidget() );
int success = XmClipboardRetrieve((Display*) wxGetDisplay(),
window, "TEXT", (XtPointer) 0, 0, & numBytes, & privateId) ;
// Assume only text is supported. If we have anything at all,
// or the clipboard is locked so we're not sure, we say we support it.
if (success == ClipboardNoData)
return FALSE;
else
return TRUE;
}
bool wxSetClipboardData(int dataFormat, wxObject *obj, int width, int height)
bool wxSetClipboardData(wxDataFormat dataFormat, wxObject *obj, int width, int height)
{
// TODO
return FALSE;
if (dataFormat != wxDF_TEXT)
return FALSE;
char* data = (char*) obj;
XmString text = XmStringCreateSimple ("CLIPBOARD");
Window window = (Window) 0;
if (wxTheApp->GetTopWindow())
window = XtWindow( (Widget) wxTheApp->GetTopWindow()->GetTopWidget() );
long itemId = 0;
int result = 0;
while ((result =
XmClipboardStartCopy((Display*) wxGetDisplay(),
window,
text,
XtLastTimestampProcessed((Display*) wxGetDisplay()),
(Widget) 0,
(XmCutPasteProc) 0,
& itemId)) != ClipboardSuccess)
;
XmStringFree (text);
long dataId = 0;
while ((result =
XmClipboardCopy((Display*) wxGetDisplay(),
window,
itemId,
"TEXT",
(XtPointer) data,
strlen(data) + 1,
0,
& dataId)) != ClipboardSuccess)
;
while (( result =
XmClipboardEndCopy((Display*) wxGetDisplay(),
window, itemId) ) != ClipboardSuccess)
;
return TRUE;
}
wxObject *wxGetClipboardData(int dataFormat, long *len)
wxObject *wxGetClipboardData(wxDataFormat dataFormat, long *len)
{
// TODO
if (dataFormat != wxDF_TEXT)
return (wxObject*) NULL;
bool done = FALSE;
long id = 0;
unsigned long numBytes = 0;
int result = 0;
Window window = (Window) 0;
if (wxTheApp->GetTopWindow())
window = XtWindow( (Widget) wxTheApp->GetTopWindow()->GetTopWidget() );
int currentDataSize = 256;
char* data = new char[currentDataSize];
while (!done)
{
if (result == ClipboardTruncate)
{
delete[] data;
currentDataSize = 2*currentDataSize;
data = new char[currentDataSize];
}
result = XmClipboardRetrieve((Display*) wxGetDisplay(),
window,
"TEXT",
(XtPointer) data,
currentDataSize,
&numBytes,
&id);
switch (result)
{
case ClipboardSuccess:
{
if (len)
*len = strlen(data) + 1;
return (wxObject*) data;
break;
}
case ClipboardTruncate:
case ClipboardLocked:
{
break;
}
default:
case ClipboardNoData:
{
return (wxObject*) NULL;
break;
}
}
}
return NULL;
}
int wxEnumClipboardFormats(int dataFormat)
wxDataFormat wxEnumClipboardFormats(wxDataFormat dataFormat)
{
// TODO
return 0;
// Only wxDF_TEXT supported
if (dataFormat == (wxDataFormat) 0)
return wxDF_TEXT;
else
return (wxDataFormat) 0;
}
int wxRegisterClipboardFormat(char *formatName)
wxDataFormat wxRegisterClipboardFormat(char *formatName)
{
// TODO
return 0;
// Not supported
return (wxDataFormat) 0;
}
bool wxGetClipboardFormatName(int dataFormat, char *formatName, int maxCount)
bool wxGetClipboardFormatName(wxDataFormat dataFormat, char *formatName, int maxCount)
{
// TODO
// Only wxDF_TEXT supported
if (dataFormat == wxDF_TEXT)
{
strcpy(formatName, "TEXT");
return TRUE;
}
else
return FALSE;
}
//-----------------------------------------------------------------------------
// wxClipboard
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject)
wxClipboard* wxTheClipboard = (wxClipboard*) NULL;
wxClipboard::wxClipboard()
{
m_open = FALSE;
}
wxClipboard::~wxClipboard()
{
Clear();
}
void wxClipboard::Clear()
{
wxNode* node = m_data.First();
while (node)
{
wxDataObject* data = (wxDataObject*) node->Data();
delete data;
node = node->Next();
}
m_data.Clear();
}
bool wxClipboard::Open()
{
wxCHECK_MSG( !m_open, FALSE, "clipboard already open" );
m_open = TRUE;
return wxOpenClipboard();
}
bool wxClipboard::SetData( wxDataObject *data )
{
wxCHECK_MSG( data, FALSE, "data is invalid" );
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
switch (data->GetFormat())
{
case wxDF_TEXT:
case wxDF_OEMTEXT:
{
wxTextDataObject* textDataObject = (wxTextDataObject*) data;
wxString str(textDataObject->GetText());
return wxSetClipboardData(data->GetFormat(), (wxObject*) (const char*) str);
break;
}
case wxDF_BITMAP:
case wxDF_DIB:
{
wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data;
wxBitmap bitmap(bitmapDataObject->GetBitmap());
return wxSetClipboardData(data->GetFormat(), & bitmap);
break;
}
default:
{
return FALSE;
}
}
return FALSE;
}
void wxClipboard::Close()
{
wxCHECK_RET( m_open, "clipboard not open" );
m_open = FALSE;
wxCloseClipboard();
}
bool wxClipboard::IsSupportedFormat( wxDataFormat format, const wxString& WXUNUSED(id) )
{
return wxIsClipboardFormatAvailable(format);
}
bool wxClipboard::GetData( wxDataObject *data )
{
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
switch (data->GetFormat())
{
case wxDF_TEXT:
case wxDF_OEMTEXT:
{
wxTextDataObject* textDataObject = (wxTextDataObject*) data;
char* s = (char*) wxGetClipboardData(data->GetFormat());
if (s)
{
textDataObject->SetText(s);
delete[] s;
return TRUE;
}
else
return FALSE;
break;
}
case wxDF_BITMAP:
case wxDF_DIB:
{
wxBitmapDataObject* bitmapDataObject = (wxBitmapDataObject*) data;
wxBitmap* bitmap = (wxBitmap*) wxGetClipboardData(data->GetFormat());
if (bitmap)
{
bitmapDataObject->SetBitmap(* bitmap);
delete bitmap;
return TRUE;
}
else
return FALSE;
break;
}
default:
{
return FALSE;
}
}
return FALSE;
}
//-----------------------------------------------------------------------------
// wxClipboardModule
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule)
bool wxClipboardModule::OnInit()
{
wxTheClipboard = new wxClipboard();
return TRUE;
}
void wxClipboardModule::OnExit()
{
if (wxTheClipboard) delete wxTheClipboard;
wxTheClipboard = (wxClipboard*) NULL;
}
#if 0
/*
* Generalized clipboard implementation by Matthew Flatt
*/
* Old clipboard implementation by Matthew Flatt
*/
wxClipboard *wxTheClipboard = NULL;
void wxInitClipboard()
{
if (!wxTheClipboard)
wxTheClipboard = new wxClipboard;
if (!wxTheClipboard)
wxTheClipboard = new wxClipboard;
}
wxClipboard::wxClipboard()
{
clipOwner = NULL;
cbString = NULL;
clipOwner = NULL;
cbString = NULL;
}
wxClipboard::~wxClipboard()
{
if (clipOwner)
clipOwner->BeingReplaced();
if (cbString)
delete[] cbString;
if (clipOwner)
clipOwner->BeingReplaced();
if (cbString)
delete[] cbString;
}
static int FormatStringToID(char *str)
{
if (!strcmp(str, "TEXT"))
return wxDF_TEXT;
return wxRegisterClipboardFormat(str);
if (!strcmp(str, "TEXT"))
return wxDF_TEXT;
return wxRegisterClipboardFormat(str);
}
void wxClipboard::SetClipboardClient(wxClipboardClient *client, long time)
{
bool got_selection;
if (clipOwner)
clipOwner->BeingReplaced();
clipOwner = client;
if (cbString) {
delete[] cbString;
cbString = NULL;
}
if (wxOpenClipboard()) {
char **formats, *data;
int i;
int ftype;
long size;
formats = clipOwner->formats.ListToArray(FALSE);
for (i = clipOwner->formats.Number(); i--; ) {
ftype = FormatStringToID(formats[i]);
data = clipOwner->GetData(formats[i], &size);
if (!wxSetClipboardData(ftype, (wxObject *)data, size, 1)) {
got_selection = FALSE;
break;
}
bool got_selection;
if (clipOwner)
clipOwner->BeingReplaced();
clipOwner = client;
if (cbString) {
delete[] cbString;
cbString = NULL;
}
if (wxOpenClipboard()) {
char **formats, *data;
int i;
int ftype;
long size;
formats = clipOwner->formats.ListToArray(FALSE);
for (i = clipOwner->formats.Number(); i--; ) {
ftype = FormatStringToID(formats[i]);
data = clipOwner->GetData(formats[i], &size);
if (!wxSetClipboardData(ftype, (wxObject *)data, size, 1)) {
got_selection = FALSE;
break;
}
}
if (i < 0)
got_selection = wxCloseClipboard();
} else
got_selection = FALSE;
got_selection = FALSE; // Assume another process takes over
if (!got_selection) {
clipOwner->BeingReplaced();
clipOwner = NULL;
}
if (i < 0)
got_selection = wxCloseClipboard();
} else
got_selection = FALSE;
got_selection = FALSE; // Assume another process takes over
if (!got_selection) {
clipOwner->BeingReplaced();
clipOwner = NULL;
}
}
wxClipboardClient *wxClipboard::GetClipboardClient()
{
return clipOwner;
return clipOwner;
}
void wxClipboard::SetClipboardString(char *str, long time)
{
bool got_selection;
if (clipOwner) {
clipOwner->BeingReplaced();
clipOwner = NULL;
}
if (cbString)
delete[] cbString;
cbString = str;
if (wxOpenClipboard()) {
if (!wxSetClipboardData(wxDF_TEXT, (wxObject *)str))
got_selection = FALSE;
else
got_selection = wxCloseClipboard();
} else
got_selection = FALSE;
got_selection = FALSE; // Assume another process takes over
if (!got_selection) {
delete[] cbString;
cbString = NULL;
}
bool got_selection;
if (clipOwner) {
clipOwner->BeingReplaced();
clipOwner = NULL;
}
if (cbString)
delete[] cbString;
cbString = str;
if (wxOpenClipboard()) {
if (!wxSetClipboardData(wxDF_TEXT, (wxObject *)str))
got_selection = FALSE;
else
got_selection = wxCloseClipboard();
} else
got_selection = FALSE;
got_selection = FALSE; // Assume another process takes over
if (!got_selection) {
delete[] cbString;
cbString = NULL;
}
}
char *wxClipboard::GetClipboardString(long time)
{
char *str;
long length;
str = GetClipboardData("TEXT", &length, time);
if (!str) {
str = new char[1];
*str = 0;
}
return str;
char *str;
long length;
str = GetClipboardData("TEXT", &length, time);
if (!str) {
str = new char[1];
*str = 0;
}
return str;
}
char *wxClipboard::GetClipboardData(char *format, long *length, long time)
{
if (clipOwner) {
if (clipOwner->formats.Member(format))
return clipOwner->GetData(format, length);
else
return NULL;
} else if (cbString) {
if (!strcmp(format, "TEXT"))
return copystring(cbString);
else
return NULL;
} else {
if (wxOpenClipboard()) {
receivedString = (char *)wxGetClipboardData(FormatStringToID(format),
length);
wxCloseClipboard();
} else
receivedString = NULL;
return receivedString;
}
if (clipOwner) {
if (clipOwner->formats.Member(format))
return clipOwner->GetData(format, length);
else
return NULL;
} else if (cbString) {
if (!strcmp(format, "TEXT"))
return copystring(cbString);
else
return NULL;
} else {
if (wxOpenClipboard()) {
receivedString = (char *)wxGetClipboardData(FormatStringToID(format),
length);
wxCloseClipboard();
} else
receivedString = NULL;
return receivedString;
}
}
#endif