From 7e2c43b8551c394d790e416ae52a4476c759683e Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 10 Jun 1999 22:29:46 +0000 Subject: [PATCH] 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 --- include/wx/defs.h | 44 +++++++++++++++++------------------ include/wx/msw/clipbrd.h | 4 ++++ samples/text/controls.cpp | 7 +++++- samples/typetest/typetest.cpp | 36 +++++++++++++++++++++++++++- samples/typetest/typetest.h | 2 ++ src/common/image.cpp | 26 ++++++++++----------- src/gtk/clipbrd.cpp | 10 +++----- src/gtk1/clipbrd.cpp | 10 +++----- 8 files changed, 88 insertions(+), 51 deletions(-) diff --git a/include/wx/defs.h b/include/wx/defs.h index 2df71e010d..9bdeb7b0f6 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -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 // ---------------------------------------------------------------------------- diff --git a/include/wx/msw/clipbrd.h b/include/wx/msw/clipbrd.h index 9ca52afad1..223801a6a6 100644 --- a/include/wx/msw/clipbrd.h +++ b/include/wx/msw/clipbrd.h @@ -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 diff --git a/samples/text/controls.cpp b/samples/text/controls.cpp index cff2e79bea..b9e3bf4777 100644 --- a/samples/text/controls.cpp +++ b/samples/text/controls.cpp @@ -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 diff --git a/samples/typetest/typetest.cpp b/samples/typetest/typetest.cpp index 59bc12f3db..3a7545896f 100644 --- a/samples/typetest/typetest.cpp +++ b/samples/typetest/typetest.cpp @@ -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"; } diff --git a/samples/typetest/typetest.h b/samples/typetest/typetest.h index aa78a80bd5..dde4128437 100644 --- a/samples/typetest/typetest.h +++ b/samples/typetest/typetest.h @@ -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_ diff --git a/src/common/image.cpp b/src/common/image.cpp index 69b1f52036..50a037f7e3 100644 --- a/src/common/image.cpp +++ b/src/common/image.cpp @@ -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; diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 966eb2d3ca..f4ed88753f 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -91,7 +91,7 @@ targets_selection_received( GtkWidget *WXUNUSED(widget), for (unsigned int i=0; ilength/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 )) diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp index 966eb2d3ca..f4ed88753f 100644 --- a/src/gtk1/clipbrd.cpp +++ b/src/gtk1/clipbrd.cpp @@ -91,7 +91,7 @@ targets_selection_received( GtkWidget *WXUNUSED(widget), for (unsigned int i=0; ilength/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 )) -- 2.45.2