DnD fixes

Image fixes
  Clipboard API


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@952 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1998-11-02 14:12:29 +00:00
parent 8c65b36ad7
commit dc86cb34c3
17 changed files with 453 additions and 174 deletions

View File

@@ -22,6 +22,7 @@
#include "wx/debug.h"
#include "wx/log.h"
#include "../png/png.h"
#include "wx/filefn.h"
//-----------------------------------------------------------------------------
// wxImage
@@ -191,6 +192,13 @@ int wxImage::GetHeight() const
bool wxImage::LoadFile( const wxString& filename, long type )
{
UnRef();
if (!wxFileExists(filename))
{
wxLogWarning( "Image file does not exist." );
return FALSE;
}
m_refData = new wxImageRefData;

View File

@@ -74,6 +74,7 @@ LIB_CPP_SRC=\
gtk/button.cpp \
gtk/checkbox.cpp \
gtk/choice.cpp \
gtk/clipbrd.cpp \
gtk/colour.cpp \
gtk/control.cpp \
gtk/combobox.cpp \

View File

@@ -513,8 +513,12 @@ wxImage wxBitmap::ConvertToImage() const
image.Create( M_BMPDATA->m_width, M_BMPDATA->m_height );
char unsigned *data = image.GetData();
GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap );
if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
int bpp = visual->depth;
int bpp = gdk_image->bpp;
GdkColormap *cmap = gtk_widget_get_default_colormap();
long pos = 0;
@@ -525,6 +529,11 @@ wxImage wxBitmap::ConvertToImage() const
int pixel = gdk_image_get_pixel( gdk_image, i, j );
if (bpp <= 8)
{
/*
int r = cmap->colors[pixel].red; // debug code
int g = cmap->colors[pixel].green;
int b = cmap->colors[pixel].blue;
*/
data[pos] = cmap->colors[pixel].red >> 8;
data[pos+1] = cmap->colors[pixel].green >> 8;
data[pos+2] = cmap->colors[pixel].blue >> 8;

86
src/gtk/clipbrd.cpp Normal file
View File

@@ -0,0 +1,86 @@
/////////////////////////////////////////////////////////////////////////////
// Name: clipbrd.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "clipbrd.h"
#endif
#include "wx/clipbrd.h"
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
wxClipboard *wxTheClipboard = (wxClipboard*) NULL;
//-----------------------------------------------------------------------------
// functions
//-----------------------------------------------------------------------------
void wxInitClipboard()
{
if (wxTheClipboard) delete wxTheClipboard;
wxTheClipboard = new wxClipboard();
}
void wxDoneClipboard()
{
if (wxTheClipboard) delete wxTheClipboard;
wxTheClipboard = (wxClipboard*) NULL;
}
//-----------------------------------------------------------------------------
// "selection_received"
//-----------------------------------------------------------------------------
/*
static void selection_received( GtkWidget *widget, GtkSelectionData *selection_data, gpointer data )
{
}
*/
//-----------------------------------------------------------------------------
// wxClipboard
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject)
wxClipboard::wxClipboard()
{
m_data = (wxDataObject*)NULL;
m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
gtk_widget_realize( m_clipboardWidget );
}
wxClipboard::~wxClipboard()
{
if (m_data) delete m_data;
if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
}
void wxClipboard::SetData( wxDataObject *data )
{
if (m_data) delete m_data;
m_data = data;
}
void *wxClipboard::GetData( wxDataFormat format, size_t *length )
{
if (!IsAvailable(format))
{
if (length) *length = 0;
return NULL;
}
return NULL;
}
bool wxClipboard::IsAvailable( wxDataFormat WXUNUSED(format) )
{
return FALSE;
}

View File

@@ -33,20 +33,12 @@ extern bool g_blockEventsOnDrag;
wxDropTarget::wxDropTarget()
{
m_size = 0;
}
wxDropTarget::~wxDropTarget()
{
}
void wxDropTarget::Drop( GdkEventDropDataAvailable *event, int x, int y )
{
printf( "Drop data is of type %s.\n", event->data_type );
OnDrop( x, y, (char *)event->data);
}
void wxDropTarget::UnregisterWidget( GtkWidget *widget )
{
if (!widget) return;
@@ -88,9 +80,9 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
// wxTextDropTarget
// ----------------------------------------------------------------------------
bool wxTextDropTarget::OnDrop( long x, long y, const void *pData )
bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) )
{
OnDropText( x, y, (const char*)pData );
OnDropText( x, y, (const char*)data );
return TRUE;
}
@@ -127,18 +119,18 @@ bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char *
return TRUE;
}
bool wxFileDropTarget::OnDrop(long x, long y, const void *pData )
bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size )
{
size_t number = 0;
char *text = (char*) pData;
for (int i = 0; i < m_size; i++)
char *text = (char*) data;
for (size_t i = 0; i < size; i++)
if (text[i] == 0) number++;
if (number == 0) return TRUE;
char **files = new char*[number];
text = (char*) pData;
text = (char*) data;
for (size_t i = 0; i < number; i++)
{
files[i] = text;
@@ -146,7 +138,7 @@ bool wxFileDropTarget::OnDrop(long x, long y, const void *pData )
text += len+1;
}
bool ret = OnDropFiles(x, y, 1, files );
bool ret = OnDropFiles( x, y, 1, files );
free( files );

View File

@@ -443,8 +443,10 @@ wxMenuItem *wxMenu::FindItem(int id) const
node = node->Next();
}
wxLogDebug( "wxMenu::FindItem: item %d not found.", id);
// Not finding anything here can be correct
// when search the entire menu system for
// an entry -> no error message.
return (wxMenuItem *) NULL;
}

View File

@@ -850,8 +850,10 @@ static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailab
int x = 0;
int y = 0;
gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL );
win->GetDropTarget()->m_size = event->data_numbytes;
win->GetDropTarget()->Drop( event, x, y );
printf( "Drop data is of type %s.\n", event->data_type );
win->GetDropTarget()->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes );
}
/*
@@ -1688,8 +1690,8 @@ void wxWindow::AddChild( wxWindow *child )
// wxFrame and wxDialog as children aren't placed into the parents
if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) &&
(!IS_KIND_OF(child,wxMDIChildFrame)))
if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) /*&&
(!IS_KIND_OF(child,wxMDIChildFrame))*/)
{
m_children.Append( child );
@@ -1714,7 +1716,7 @@ void wxWindow::AddChild( wxWindow *child )
}
}
}
// wxNotebook is very special, so it has a private AddChild()
if (IS_KIND_OF(this,wxNotebook))

View File

@@ -513,8 +513,12 @@ wxImage wxBitmap::ConvertToImage() const
image.Create( M_BMPDATA->m_width, M_BMPDATA->m_height );
char unsigned *data = image.GetData();
GdkVisual *visual = gdk_window_get_visual( M_BMPDATA->m_pixmap );
if (visual == NULL) visual = gdk_window_get_visual( (GdkWindow*) &gdk_root_parent );
int bpp = visual->depth;
int bpp = gdk_image->bpp;
GdkColormap *cmap = gtk_widget_get_default_colormap();
long pos = 0;
@@ -525,6 +529,11 @@ wxImage wxBitmap::ConvertToImage() const
int pixel = gdk_image_get_pixel( gdk_image, i, j );
if (bpp <= 8)
{
/*
int r = cmap->colors[pixel].red; // debug code
int g = cmap->colors[pixel].green;
int b = cmap->colors[pixel].blue;
*/
data[pos] = cmap->colors[pixel].red >> 8;
data[pos+1] = cmap->colors[pixel].green >> 8;
data[pos+2] = cmap->colors[pixel].blue >> 8;

86
src/gtk1/clipbrd.cpp Normal file
View File

@@ -0,0 +1,86 @@
/////////////////////////////////////////////////////////////////////////////
// Name: clipbrd.cpp
// Purpose:
// Author: Robert Roebling
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#ifdef __GNUG__
#pragma implementation "clipbrd.h"
#endif
#include "wx/clipbrd.h"
//-----------------------------------------------------------------------------
// data
//-----------------------------------------------------------------------------
wxClipboard *wxTheClipboard = (wxClipboard*) NULL;
//-----------------------------------------------------------------------------
// functions
//-----------------------------------------------------------------------------
void wxInitClipboard()
{
if (wxTheClipboard) delete wxTheClipboard;
wxTheClipboard = new wxClipboard();
}
void wxDoneClipboard()
{
if (wxTheClipboard) delete wxTheClipboard;
wxTheClipboard = (wxClipboard*) NULL;
}
//-----------------------------------------------------------------------------
// "selection_received"
//-----------------------------------------------------------------------------
/*
static void selection_received( GtkWidget *widget, GtkSelectionData *selection_data, gpointer data )
{
}
*/
//-----------------------------------------------------------------------------
// wxClipboard
//-----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject)
wxClipboard::wxClipboard()
{
m_data = (wxDataObject*)NULL;
m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
gtk_widget_realize( m_clipboardWidget );
}
wxClipboard::~wxClipboard()
{
if (m_data) delete m_data;
if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
}
void wxClipboard::SetData( wxDataObject *data )
{
if (m_data) delete m_data;
m_data = data;
}
void *wxClipboard::GetData( wxDataFormat format, size_t *length )
{
if (!IsAvailable(format))
{
if (length) *length = 0;
return NULL;
}
return NULL;
}
bool wxClipboard::IsAvailable( wxDataFormat WXUNUSED(format) )
{
return FALSE;
}

View File

@@ -33,20 +33,12 @@ extern bool g_blockEventsOnDrag;
wxDropTarget::wxDropTarget()
{
m_size = 0;
}
wxDropTarget::~wxDropTarget()
{
}
void wxDropTarget::Drop( GdkEventDropDataAvailable *event, int x, int y )
{
printf( "Drop data is of type %s.\n", event->data_type );
OnDrop( x, y, (char *)event->data);
}
void wxDropTarget::UnregisterWidget( GtkWidget *widget )
{
if (!widget) return;
@@ -88,9 +80,9 @@ void wxDropTarget::RegisterWidget( GtkWidget *widget )
// wxTextDropTarget
// ----------------------------------------------------------------------------
bool wxTextDropTarget::OnDrop( long x, long y, const void *pData )
bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) )
{
OnDropText( x, y, (const char*)pData );
OnDropText( x, y, (const char*)data );
return TRUE;
}
@@ -127,18 +119,18 @@ bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char *
return TRUE;
}
bool wxFileDropTarget::OnDrop(long x, long y, const void *pData )
bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size )
{
size_t number = 0;
char *text = (char*) pData;
for (int i = 0; i < m_size; i++)
char *text = (char*) data;
for (size_t i = 0; i < size; i++)
if (text[i] == 0) number++;
if (number == 0) return TRUE;
char **files = new char*[number];
text = (char*) pData;
text = (char*) data;
for (size_t i = 0; i < number; i++)
{
files[i] = text;
@@ -146,7 +138,7 @@ bool wxFileDropTarget::OnDrop(long x, long y, const void *pData )
text += len+1;
}
bool ret = OnDropFiles(x, y, 1, files );
bool ret = OnDropFiles( x, y, 1, files );
free( files );

View File

@@ -443,8 +443,10 @@ wxMenuItem *wxMenu::FindItem(int id) const
node = node->Next();
}
wxLogDebug( "wxMenu::FindItem: item %d not found.", id);
// Not finding anything here can be correct
// when search the entire menu system for
// an entry -> no error message.
return (wxMenuItem *) NULL;
}

View File

@@ -850,8 +850,10 @@ static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailab
int x = 0;
int y = 0;
gdk_window_get_pointer( widget->window, &x, &y, (GdkModifierType *) NULL );
win->GetDropTarget()->m_size = event->data_numbytes;
win->GetDropTarget()->Drop( event, x, y );
printf( "Drop data is of type %s.\n", event->data_type );
win->GetDropTarget()->OnDrop( x, y, (const void*)event->data, (size_t)event->data_numbytes );
}
/*
@@ -1688,8 +1690,8 @@ void wxWindow::AddChild( wxWindow *child )
// wxFrame and wxDialog as children aren't placed into the parents
if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) &&
(!IS_KIND_OF(child,wxMDIChildFrame)))
if (( IS_KIND_OF(child,wxFrame) || IS_KIND_OF(child,wxDialog) ) /*&&
(!IS_KIND_OF(child,wxMDIChildFrame))*/)
{
m_children.Append( child );
@@ -1714,7 +1716,7 @@ void wxWindow::AddChild( wxWindow *child )
}
}
}
// wxNotebook is very special, so it has a private AddChild()
if (IS_KIND_OF(this,wxNotebook))