Corrected byte swapping macros.

Added test for them to typetest.
  Removed debug code from wxClipboard.
  Added empty compat. call to wxMSW's clipboard.
  Added for primary selection to sample/text.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2753 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1999-06-10 22:29:46 +00:00
parent 85833f5c6c
commit 7e2c43b855
8 changed files with 88 additions and 51 deletions

View File

@@ -441,8 +441,8 @@ typedef wxUint16 wxWord;
#define wxINT16_SWAP_ALWAYS(val) \
((wxInt16) ( \
(((wxInt16) (val) & (wxInt16) 0x00ffU) << 8) | \
(((wxInt16) (val) & (wxInt16) 0xff00U) >> 8)))
(((wxUint16) (val) & (wxUint16) 0x00ffU) << 8) | \
(((wxUint16) (val) & (wxUint16) 0xff00U) >> 8)))
#define wxUINT32_SWAP_ALWAYS(val) \
((wxUint32) ( \
@@ -453,31 +453,31 @@ typedef wxUint16 wxWord;
#define wxINT32_SWAP_ALWAYS(val) \
((wxInt32) ( \
(((wxInt32) (val) & (wxInt32) 0x000000ffU) << 24) | \
(((wxInt32) (val) & (wxInt32) 0x0000ff00U) << 8) | \
(((wxInt32) (val) & (wxInt32) 0x00ff0000U) >> 8) | \
(((wxInt32) (val) & (wxInt32) 0xff000000U) >> 24)))
(((wxUint32) (val) & (wxUint32) 0x000000ffU) << 24) | \
(((wxUint32) (val) & (wxUint32) 0x0000ff00U) << 8) | \
(((wxUint32) (val) & (wxUint32) 0x00ff0000U) >> 8) | \
(((wxUint32) (val) & (wxUint32) 0xff000000U) >> 24)))
// machine specific byte swapping
#ifdef WORDS_BIGENDIAN
#define wxUINT16_SWAP_FROM_LE(val) wxUINT16_SWAP_ALWAYS(val)
#define wxINT16_SWAP_FROM_LE(val) wxINT16_SWAP_ALWAYS(val)
#define wxUINT16_SWAP_FROM_BE(val) (val)
#define wxINT16_SWAP_FROM_BE(val) (val)
#define wxUINT32_SWAP_FROM_LE(val) wxUINT32_SWAP_ALWAYS(val)
#define wxINT32_SWAP_FROM_LE(val) wxINT32_SWAP_ALWAYS(val)
#define wxUINT32_SWAP_FROM_BE(val) (val)
#define wxINT32_SWAP_FROM_BE(val) (val)
#define wxUINT16_SWAP_ON_BE(val) wxUINT16_SWAP_ALWAYS(val)
#define wxINT16_SWAP_ON_BE(val) wxINT16_SWAP_ALWAYS(val)
#define wxUINT16_SWAP_ON_LE(val) (val)
#define wxINT16_SWAP_ON_LE(val) (val)
#define wxUINT32_SWAP_ON_BE(val) wxUINT32_SWAP_ALWAYS(val)
#define wxINT32_SWAP_ON_BE(val) wxINT32_SWAP_ALWAYS(val)
#define wxUINT32_SWAP_ON_LE(val) (val)
#define wxINT32_SWAP_ON_LE(val) (val)
#else
#define wxUINT16_SWAP_FROM_BE(val) wxUINT16_SWAP_ALWAYS(val)
#define wxINT16_SWAP_FROM_BE(val) wxINT16_SWAP_ALWAYS(val)
#define wxUINT16_SWAP_FROM_LE(val) (val)
#define wxINT16_SWAP_FROM_LE(val) (val)
#define wxUINT32_SWAP_FROM_BE(val) wxUINT32_SWAP_ALWAYS(val)
#define wxINT32_SWAP_FROM_BE(val) wxINT32_SWAP_ALWAYS(val)
#define wxUINT32_SWAP_FROM_LE(val) (val)
#define wxINT32_SWAP_FROM_LE(val) (val)
#define wxUINT16_SWAP_ON_LE(val) wxUINT16_SWAP_ALWAYS(val)
#define wxINT16_SWAP_ON_LE(val) wxINT16_SWAP_ALWAYS(val)
#define wxUINT16_SWAP_ON_BE(val) (val)
#define wxINT16_SWAP_ON_BE(val) (val)
#define wxUINT32_SWAP_ON_LE(val) wxUINT32_SWAP_ALWAYS(val)
#define wxINT32_SWAP_ON_LE(val) wxINT32_SWAP_ALWAYS(val)
#define wxUINT32_SWAP_ON_BE(val) (val)
#define wxINT32_SWAP_ON_BE(val) (val)
#endif
// ----------------------------------------------------------------------------

View File

@@ -83,6 +83,10 @@ public:
// clears wxTheClipboard and the system's clipboard if possible
virtual void Clear();
/// X11 has two clipboards which get selected by this call. Empty on MSW.
inline void UsePrimarySelection( bool WXUNUSED(primary) ) { }
};
// The global clipboard object

View File

@@ -450,10 +450,15 @@ void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) )
// parts in wxUSE_DRAG_AND_DROP.
#if wxUSE_CLIPBOARD && wxUSE_DRAG_AND_DROP
// On X11, we want to get the data from the primary selection instead
// of the normal clipboard (which isn't normal under X11 at all). This
// call has no effect under MSW.
wxTheClipboard->UsePrimarySelection();
if (!wxTheClipboard->Open())
{
*m_log << "Error opening the clipboard.\n";
return;
}
else

View File

@@ -43,6 +43,7 @@ BEGIN_EVENT_TABLE(MyApp, wxApp)
EVT_MENU(TYPES_DATE, MyApp::DoDateDemo)
EVT_MENU(TYPES_TIME, MyApp::DoTimeDemo)
EVT_MENU(TYPES_VARIANT, MyApp::DoVariantDemo)
EVT_MENU(TYPES_BYTEORDER, MyApp::DoByteOrderDemo)
END_EVENT_TABLE()
bool MyApp::OnInit(void)
@@ -62,6 +63,7 @@ bool MyApp::OnInit(void)
file_menu->Append(TYPES_DATE, "&Date test");
file_menu->Append(TYPES_TIME, "&Time test");
file_menu->Append(TYPES_VARIANT, "&Variant test");
file_menu->Append(TYPES_BYTEORDER, "&Byteorder test");
file_menu->AppendSeparator();
file_menu->Append(TYPES_QUIT, "E&xit");
wxMenuBar *menu_bar = new wxMenuBar;
@@ -78,12 +80,44 @@ bool MyApp::OnInit(void)
return TRUE;
}
void MyApp::DoByteOrderDemo(wxCommandEvent& WXUNUSED(event))
{
wxTextCtrl& textCtrl = * GetTextCtrl();
textCtrl.Clear();
textCtrl << "\nTest byte order macros:\n\n";
if (wxBYTE_ORDER == wxLITTLE_ENDIAN)
textCtrl << "This is a little endian system.\n\n";
else
textCtrl << "This is a big endian system.\n\n";
wxString text;
wxInt32 var = 0xF1F2F3F4;
text = "";
text.Printf( "Value of wxInt32 is now: %#x.\n\n", var );
textCtrl.WriteText( text );
text = "";
text.Printf( "Value of swapped wxInt32 is: %#x.\n\n", wxINT32_SWAP_ALWAYS( var ) );
textCtrl.WriteText( text );
text = "";
text.Printf( "Value of wxInt32 swapped on little endian is: %#x.\n\n", wxINT32_SWAP_ON_LE( var ) );
textCtrl.WriteText( text );
text = "";
text.Printf( "Value of wxInt32 swapped on big endian is: %#x.\n\n", wxINT32_SWAP_ON_BE( var ) );
textCtrl.WriteText( text );
}
void MyApp::DoTimeDemo(wxCommandEvent& WXUNUSED(event))
{
wxTextCtrl& textCtrl = * GetTextCtrl();
textCtrl.Clear();
cout << "\nTest class wxTime" << endl;
textCtrl << "\nTest class wxTime:\n";
wxTime now;
textCtrl << "It is now " << (wxString) now << "\n";
}

View File

@@ -25,6 +25,7 @@ public:
void DoDateDemo(wxCommandEvent& event);
void DoTimeDemo(wxCommandEvent& event);
void DoVariantDemo(wxCommandEvent& event);
void DoByteOrderDemo(wxCommandEvent& event);
wxTextCtrl* GetTextCtrl() const { return m_textCtrl; }
@@ -60,6 +61,7 @@ public:
#define TYPES_DATE 103
#define TYPES_TIME 104
#define TYPES_VARIANT 105
#define TYPES_BYTEORDER 106
#endif
// _WX_TYPETEST_H_

View File

@@ -621,12 +621,12 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream )
stream.Read( &bbuf, 2 );
stream.Read( dbuf, 4 * 4 );
wxInt32 size = wxINT32_SWAP_FROM_LE( dbuf[0] );
wxInt32 offset = wxINT32_SWAP_FROM_LE( dbuf[2] );
wxInt32 size = wxINT32_SWAP_ON_BE( dbuf[0] );
wxInt32 offset = wxINT32_SWAP_ON_BE( dbuf[2] );
stream.Read(dbuf, 4 * 2);
int width = (int)wxINT32_SWAP_FROM_LE( dbuf[0] );
int height = (int)wxINT32_SWAP_FROM_LE( dbuf[1] );
int width = (int)wxINT32_SWAP_ON_BE( dbuf[0] );
int height = (int)wxINT32_SWAP_ON_BE( dbuf[1] );
if (width > 32767)
{
wxLogError( _T("Image width > 32767 pixels for file.") );
@@ -641,10 +641,10 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream )
stream.Read( &aWord, 2 );
/*
TODO
int planes = (int)wxUINT16_SWAP_FROM_LE( aWord );
int planes = (int)wxUINT16_SWAP_ON_BE( aWord );
*/
stream.Read( &aWord, 2 );
int bpp = (int)wxUINT16_SWAP_FROM_LE( aWord );
int bpp = (int)wxUINT16_SWAP_ON_BE( aWord );
if (bpp != 1 && bpp != 4 && bpp != 8 && bpp != 16 && bpp != 24 && bpp != 32)
{
wxLogError( _T("unknown bitdepth in file.") );
@@ -652,7 +652,7 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream )
}
stream.Read( dbuf, 4 * 4 );
int comp = (int)wxINT32_SWAP_FROM_LE( dbuf[0] );
int comp = (int)wxINT32_SWAP_ON_BE( dbuf[0] );
if (comp != BI_RGB && comp != BI_RLE4 && comp != BI_RLE8 && comp != BI_BITFIELDS)
{
wxLogError( _T("unknown encoding in Windows BMP file.") );
@@ -660,7 +660,7 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream )
}
stream.Read( dbuf, 4 * 2 );
int ncolors = (int)wxINT32_SWAP_FROM_LE( dbuf[0] );
int ncolors = (int)wxINT32_SWAP_ON_BE( dbuf[0] );
if (ncolors == 0)
ncolors = 1 << bpp;
/* some more sanity checks */
@@ -712,9 +712,9 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream )
{
int bit = 0;
stream.Read( dbuf, 4 * 3 );
bmask = wxINT32_SWAP_FROM_LE( dbuf[0] );
gmask = wxINT32_SWAP_FROM_LE( dbuf[1] );
rmask = wxINT32_SWAP_FROM_LE( dbuf[2] );
bmask = wxINT32_SWAP_ON_BE( dbuf[0] );
gmask = wxINT32_SWAP_ON_BE( dbuf[1] );
rmask = wxINT32_SWAP_ON_BE( dbuf[2] );
/* find shift amount.. ugly, but i can't think of a better way */
for (bit = 0; bit < bpp; bit++)
{
@@ -892,7 +892,7 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream )
{
unsigned char temp;
stream.Read( &aWord, 2 );
aWord = wxUINT16_SWAP_FROM_LE( aWord );
aWord = wxUINT16_SWAP_ON_BE( aWord );
linepos += 2;
temp = (aWord & rmask) >> rshift;
ptr[poffset] = temp;
@@ -906,7 +906,7 @@ bool wxBMPHandler::LoadFile( wxImage *image, wxInputStream& stream )
{
unsigned char temp;
stream.Read( &aDword, 4 );
aDword = wxINT32_SWAP_FROM_LE( aDword );
aDword = wxINT32_SWAP_ON_BE( aDword );
linepos += 4;
temp = (aDword & rmask) >> rshift;
ptr[poffset] = temp;

View File

@@ -91,7 +91,7 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
{
/* char *name = gdk_atom_name (atoms[i]);
/* char *name = gdk_atom_name (atoms[i]);
if (name) printf( "Format available: %s.\n", name ); */
if (atoms[i] == clipboard->m_targetRequested)
@@ -370,6 +370,8 @@ wxClipboard::wxClipboard()
m_formatSupported = FALSE;
m_targetRequested = 0;
m_usePrimary = FALSE;
}
wxClipboard::~wxClipboard()
@@ -422,7 +424,6 @@ bool wxClipboard::Open()
wxCHECK_MSG( !m_open, FALSE, _T("clipboard already open") );
m_open = TRUE;
UsePrimarySelection(FALSE);
return TRUE;
}
@@ -493,7 +494,6 @@ bool wxClipboard::AddData( wxDataObject *data )
(gpointer) NULL );
#endif
// printf( "vorher.\n" );
/* Tell the world we offer clipboard data */
if (!gtk_selection_owner_set( m_clipboardWidget,
g_clipboardAtom,
@@ -503,10 +503,6 @@ bool wxClipboard::AddData( wxDataObject *data )
}
m_ownsClipboard = TRUE;
// printf( "nachher.\n" );
return TRUE;
if (!gtk_selection_owner_set( m_clipboardWidget,
GDK_SELECTION_PRIMARY,
GDK_CURRENT_TIME ))

View File

@@ -91,7 +91,7 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
{
/* char *name = gdk_atom_name (atoms[i]);
/* char *name = gdk_atom_name (atoms[i]);
if (name) printf( "Format available: %s.\n", name ); */
if (atoms[i] == clipboard->m_targetRequested)
@@ -370,6 +370,8 @@ wxClipboard::wxClipboard()
m_formatSupported = FALSE;
m_targetRequested = 0;
m_usePrimary = FALSE;
}
wxClipboard::~wxClipboard()
@@ -422,7 +424,6 @@ bool wxClipboard::Open()
wxCHECK_MSG( !m_open, FALSE, _T("clipboard already open") );
m_open = TRUE;
UsePrimarySelection(FALSE);
return TRUE;
}
@@ -493,7 +494,6 @@ bool wxClipboard::AddData( wxDataObject *data )
(gpointer) NULL );
#endif
// printf( "vorher.\n" );
/* Tell the world we offer clipboard data */
if (!gtk_selection_owner_set( m_clipboardWidget,
g_clipboardAtom,
@@ -503,10 +503,6 @@ bool wxClipboard::AddData( wxDataObject *data )
}
m_ownsClipboard = TRUE;
// printf( "nachher.\n" );
return TRUE;
if (!gtk_selection_owner_set( m_clipboardWidget,
GDK_SELECTION_PRIMARY,
GDK_CURRENT_TIME ))