From e5403d7c573d45fcfef73959c41fda93aea1d07f Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 28 Oct 1998 11:44:41 +0000 Subject: [PATCH] DnD RadioBox layout git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@927 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/gtk/todo.txt | 17 +++---- include/wx/gtk/dnd.h | 10 ++-- include/wx/gtk1/dnd.h | 10 ++-- samples/controls/controls.cpp | 12 ++++- src/gtk/dnd.cpp | 39 +++++++++++--- src/gtk/radiobox.cpp | 95 ++++++++++++++++++++++++++++++----- src/gtk/window.cpp | 3 +- src/gtk1/dnd.cpp | 39 +++++++++++--- src/gtk1/radiobox.cpp | 95 ++++++++++++++++++++++++++++++----- src/gtk1/window.cpp | 3 +- 10 files changed, 259 insertions(+), 64 deletions(-) diff --git a/docs/gtk/todo.txt b/docs/gtk/todo.txt index 5f78721806..415cbcb0d4 100644 --- a/docs/gtk/todo.txt +++ b/docs/gtk/todo.txt @@ -2,23 +2,17 @@ -------------------- High priority --------------------- wxTreeCtrl - -> Keyboard handling, icon support. + -> Make it compile. Keyboard handling, icon support. wxListCtrl - -> Icon support in list mode. + -> Icon support in list mode. Backgroundcolour, font? -Finish DnD - -> Only decoding filelist and visual feedback missing - wxClipboard - -> Urg. + -> Urgh. wxHelpController -> Karsten ? -Implement wxRadioBox layout - -> I'm so lazy. - Fix printing of bitmaps -> No idea. @@ -27,7 +21,10 @@ Add support SetForegroundColour in GTK widgets wxBitmapCheckBox -> Interface same as checkbox? - + +wxImage + -> 24-bit support + -------------------- Low priority --------------------- wxDebugContext <-> wxLogXXX functions diff --git a/include/wx/gtk/dnd.h b/include/wx/gtk/dnd.h index 962161ea94..7f72906e47 100644 --- a/include/wx/gtk/dnd.h +++ b/include/wx/gtk/dnd.h @@ -123,7 +123,7 @@ public: wxFileDataObject(void) { } void AddFile( const wxString &file ) - { m_files += file; m_files += ";"; } + { m_files += file; m_files += '\0'; } // implement base class pure virtuals virtual wxDataFormat GetPreferredFormat() const @@ -131,7 +131,7 @@ public: virtual bool IsSupportedFormat(wxDataFormat format) const { return format == wxDF_FILENAME; } virtual size_t GetDataSize() const - { return m_files.Len() + 1; } // +1 for trailing '\0'of course + { return m_files.Len(); } // no trailing '\0' virtual void GetDataHere(void *pBuf) const { memcpy(pBuf, m_files.c_str(), GetDataSize()); } @@ -154,16 +154,16 @@ class wxDropTarget: public wxObject virtual void OnLeave() { } virtual bool OnDrop( long x, long y, const void *pData ) = 0; -// protected: + // implementation - friend wxWindow; + int m_size; // Override these to indicate what kind of data you support: virtual size_t GetFormatCount() const = 0; virtual wxDataFormat GetFormat(size_t n) const = 0; - void Drop( GdkEvent *event, int x, int y ); + void Drop( GdkEventDropDataAvailable *event, int x, int y ); void RegisterWidget( GtkWidget *widget ); void UnregisterWidget( GtkWidget *widget ); }; diff --git a/include/wx/gtk1/dnd.h b/include/wx/gtk1/dnd.h index 962161ea94..7f72906e47 100644 --- a/include/wx/gtk1/dnd.h +++ b/include/wx/gtk1/dnd.h @@ -123,7 +123,7 @@ public: wxFileDataObject(void) { } void AddFile( const wxString &file ) - { m_files += file; m_files += ";"; } + { m_files += file; m_files += '\0'; } // implement base class pure virtuals virtual wxDataFormat GetPreferredFormat() const @@ -131,7 +131,7 @@ public: virtual bool IsSupportedFormat(wxDataFormat format) const { return format == wxDF_FILENAME; } virtual size_t GetDataSize() const - { return m_files.Len() + 1; } // +1 for trailing '\0'of course + { return m_files.Len(); } // no trailing '\0' virtual void GetDataHere(void *pBuf) const { memcpy(pBuf, m_files.c_str(), GetDataSize()); } @@ -154,16 +154,16 @@ class wxDropTarget: public wxObject virtual void OnLeave() { } virtual bool OnDrop( long x, long y, const void *pData ) = 0; -// protected: + // implementation - friend wxWindow; + int m_size; // Override these to indicate what kind of data you support: virtual size_t GetFormatCount() const = 0; virtual wxDataFormat GetFormat(size_t n) const = 0; - void Drop( GdkEvent *event, int x, int y ); + void Drop( GdkEventDropDataAvailable *event, int x, int y ); void RegisterWidget( GtkWidget *widget ); void UnregisterWidget( GtkWidget *widget ); }; diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index ac2be534d5..ab5a9e5770 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -316,14 +316,22 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : tc->SetBackgroundColour("wheat"); m_notebook->AddPage(panel, "wxTextCtrl" , FALSE, Image_Text); + wxString choices2[] = + { + "Wonderful", + "examples.", + }; + panel = new wxPanel(m_notebook); panel->SetBackgroundColour("cadet blue"); - m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices ); + m_radio = new wxRadioBox( panel, ID_RADIOBOX, "That", wxPoint(10,160), wxSize(-1,-1), 2, choices2, 1, wxRA_HORIZONTAL ); + m_radio->SetBackgroundColour("wheat"); + m_radio = new wxRadioBox( panel, ID_RADIOBOX, "This", wxPoint(10,10), wxSize(-1,-1), 5, choices, 1, wxRA_VERTICAL ); m_radio->SetBackgroundColour("wheat"); (void)new wxButton( panel, ID_RADIOBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); (void)new wxButton( panel, ID_RADIOBOX_SEL_STR, "Select 'This'", wxPoint(180,80), wxSize(140,30) ); (void)new wxButton( panel, ID_RADIOBOX_FONT, "Set Italic font", wxPoint(180,130), wxSize(140,30) ); - (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); + (void)new wxCheckBox( panel, ID_RADIOBOX_ENABLE, "Disable", wxPoint(340,130), wxSize(140,30) ); m_fontButton = new wxButton( panel, ID_SET_FONT, "Set more Italic font", wxPoint(340,30), wxSize(160,30) ); m_notebook->AddPage(panel, "wxRadioBox", FALSE, Image_Radio); diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index acf9b6c80b..b55ca705f1 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -33,17 +33,18 @@ extern bool g_blockEventsOnDrag; wxDropTarget::wxDropTarget() { + m_size = 0; } wxDropTarget::~wxDropTarget() { } -void wxDropTarget::Drop( GdkEvent *event, int x, int y ) +void wxDropTarget::Drop( GdkEventDropDataAvailable *event, int x, int y ) { - printf( "Drop data is of type %s.\n", event->dropdataavailable.data_type ); + printf( "Drop data is of type %s.\n", event->data_type ); - OnDrop( x, y, (char *)event->dropdataavailable.data); + OnDrop( x, y, (char *)event->data); } void wxDropTarget::UnregisterWidget( GtkWidget *widget ) @@ -114,18 +115,42 @@ wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const // wxFileDropTarget // ---------------------------------------------------------------------------- -bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const WXUNUSED(aszFiles)[] ) +bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] ) { printf( "Got %d dropped files.\n", (int)nFiles ); printf( "At x: %d, y: %d.\n", (int)x, (int)y ); + for (size_t i = 0; i < nFiles; i++) + { + printf( aszFiles[i] ); + printf( "\n" ); + } return TRUE; } -bool wxFileDropTarget::OnDrop(long x, long y, const void *WXUNUSED(pData) ) +bool wxFileDropTarget::OnDrop(long x, long y, const void *pData ) { - char *str = "/this/is/a/path.txt"; + size_t number = 0; + char *text = (char*) pData; + for (int i = 0; i < m_size; i++) + if (text[i] == 0) number++; - return OnDropFiles(x, y, 1, &str ); + if (number == 0) return TRUE; + + char **files = new char*[number]; + + text = (char*) pData; + for (size_t i = 0; i < number; i++) + { + files[i] = text; + int len = strlen( text ); + text += len+1; + } + + bool ret = OnDropFiles(x, y, 1, files ); + + free( files ); + + return ret; } size_t wxFileDropTarget::GetFormatCount() const diff --git a/src/gtk/radiobox.cpp b/src/gtk/radiobox.cpp index badc40018e..2d00f6d3e8 100644 --- a/src/gtk/radiobox.cpp +++ b/src/gtk/radiobox.cpp @@ -80,11 +80,11 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, int y = m_y+15; int maxLen = 0; int height = 20; + int width = 0; GtkRadioButton *m_radio = (GtkRadioButton*) NULL; -// if (((m_style & wxRA_VERTICAL) == wxRA_VERTICAL) && (n > 0)) - if (n > 0) + if (m_windowStyle & wxRA_VERTICAL) { GSList *radio_button_group = (GSList *) NULL; for (int i = 0; i < n; i++) @@ -107,7 +107,7 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, int tmp = 22+gdk_string_measure( GTK_WIDGET(m_radio)->style->font, choices[i] ); if (tmp > maxLen) maxLen = tmp; - int width = m_width-10; + width = m_width-10; if (size.x == -1) width = tmp; gtk_widget_set_usize( GTK_WIDGET(m_radio), width, 20 ); @@ -115,10 +115,47 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, height += 20; } + width = maxLen + 10; + } + else + { + int max = 0; + for (int i = 0; i < n; i++) + { + GdkFont *font = m_widget->style->font; + int len = 27+gdk_string_measure( font, choices[i] ); + if (len > max) max = len; + } + + GSList *radio_button_group = (GSList *) NULL; + for (int i = 0; i < n; i++) + { + if (i) radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) ); + + m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, choices[i] ) ); + + m_boxes.Append( (wxObject*) m_radio ); + + ConnectWidget( GTK_WIDGET(m_radio) ); + + if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); + + gtk_signal_connect( GTK_OBJECT(m_radio), "clicked", + GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); + + gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), GTK_WIDGET(m_radio), x, y ); + + gtk_widget_set_usize( GTK_WIDGET(m_radio), max, 20 ); + + x += max; + } + + width = max*n + 10; + height = 40; } wxSize newSize = size; - if (newSize.x == -1) newSize.x = maxLen+10; + if (newSize.x == -1) newSize.x = width; if (newSize.y == -1) newSize.y = height; SetSize( newSize.x, newSize.y ); @@ -151,19 +188,51 @@ void wxRadioBox::OnSize( wxSizeEvent &event ) int x = m_x+5; int y = m_y+15; - wxNode *node = m_boxes.First(); - while (node) + if (m_windowStyle & wxRA_VERTICAL) { - GtkWidget *button = GTK_WIDGET( node->Data() ); + wxNode *node = m_boxes.First(); + while (node) + { + GtkWidget *button = GTK_WIDGET( node->Data() ); - gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), button, x, y ); - y += 20; + gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), button, x, y ); + y += 20; - int w = m_width-10; - if (w < 15) w = 15; - gtk_widget_set_usize( button, w, 20 ); + int w = m_width-10; + if (w < 15) w = 15; + gtk_widget_set_usize( button, w, 20 ); - node = node->Next(); + node = node->Next(); + } + } + else + { + int max = 0; + + wxNode *node = m_boxes.First(); + while (node) + { + GtkButton *button = GTK_BUTTON( node->Data() ); + GtkLabel *label = GTK_LABEL( button->child ); + + GdkFont *font = m_widget->style->font; + int len = 27+gdk_string_measure( font, label->label ); + if (len > max) max = len; + + node = node->Next(); + } + + node = m_boxes.First(); + while (node) + { + GtkWidget *button = GTK_WIDGET( node->Data() ); + + gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), button, x, y ); + x += max; + gtk_widget_set_usize( button, max, 20 ); + + node = node->Next(); + } } } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 0b0179b5a2..707a1682ec 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -841,7 +841,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventBut // "drop_data_available_event" //----------------------------------------------------------------------------- -static void gtk_window_drop_callback( GtkWidget *widget, GdkEvent *event, wxWindow *win ) +static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailable *event, wxWindow *win ) { if (!win->HasVMT()) return; @@ -850,6 +850,7 @@ static void gtk_window_drop_callback( GtkWidget *widget, GdkEvent *event, wxWind 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 ); } diff --git a/src/gtk1/dnd.cpp b/src/gtk1/dnd.cpp index acf9b6c80b..b55ca705f1 100644 --- a/src/gtk1/dnd.cpp +++ b/src/gtk1/dnd.cpp @@ -33,17 +33,18 @@ extern bool g_blockEventsOnDrag; wxDropTarget::wxDropTarget() { + m_size = 0; } wxDropTarget::~wxDropTarget() { } -void wxDropTarget::Drop( GdkEvent *event, int x, int y ) +void wxDropTarget::Drop( GdkEventDropDataAvailable *event, int x, int y ) { - printf( "Drop data is of type %s.\n", event->dropdataavailable.data_type ); + printf( "Drop data is of type %s.\n", event->data_type ); - OnDrop( x, y, (char *)event->dropdataavailable.data); + OnDrop( x, y, (char *)event->data); } void wxDropTarget::UnregisterWidget( GtkWidget *widget ) @@ -114,18 +115,42 @@ wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const // wxFileDropTarget // ---------------------------------------------------------------------------- -bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const WXUNUSED(aszFiles)[] ) +bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] ) { printf( "Got %d dropped files.\n", (int)nFiles ); printf( "At x: %d, y: %d.\n", (int)x, (int)y ); + for (size_t i = 0; i < nFiles; i++) + { + printf( aszFiles[i] ); + printf( "\n" ); + } return TRUE; } -bool wxFileDropTarget::OnDrop(long x, long y, const void *WXUNUSED(pData) ) +bool wxFileDropTarget::OnDrop(long x, long y, const void *pData ) { - char *str = "/this/is/a/path.txt"; + size_t number = 0; + char *text = (char*) pData; + for (int i = 0; i < m_size; i++) + if (text[i] == 0) number++; - return OnDropFiles(x, y, 1, &str ); + if (number == 0) return TRUE; + + char **files = new char*[number]; + + text = (char*) pData; + for (size_t i = 0; i < number; i++) + { + files[i] = text; + int len = strlen( text ); + text += len+1; + } + + bool ret = OnDropFiles(x, y, 1, files ); + + free( files ); + + return ret; } size_t wxFileDropTarget::GetFormatCount() const diff --git a/src/gtk1/radiobox.cpp b/src/gtk1/radiobox.cpp index badc40018e..2d00f6d3e8 100644 --- a/src/gtk1/radiobox.cpp +++ b/src/gtk1/radiobox.cpp @@ -80,11 +80,11 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, int y = m_y+15; int maxLen = 0; int height = 20; + int width = 0; GtkRadioButton *m_radio = (GtkRadioButton*) NULL; -// if (((m_style & wxRA_VERTICAL) == wxRA_VERTICAL) && (n > 0)) - if (n > 0) + if (m_windowStyle & wxRA_VERTICAL) { GSList *radio_button_group = (GSList *) NULL; for (int i = 0; i < n; i++) @@ -107,7 +107,7 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, int tmp = 22+gdk_string_measure( GTK_WIDGET(m_radio)->style->font, choices[i] ); if (tmp > maxLen) maxLen = tmp; - int width = m_width-10; + width = m_width-10; if (size.x == -1) width = tmp; gtk_widget_set_usize( GTK_WIDGET(m_radio), width, 20 ); @@ -115,10 +115,47 @@ bool wxRadioBox::Create( wxWindow *parent, wxWindowID id, const wxString& title, height += 20; } + width = maxLen + 10; + } + else + { + int max = 0; + for (int i = 0; i < n; i++) + { + GdkFont *font = m_widget->style->font; + int len = 27+gdk_string_measure( font, choices[i] ); + if (len > max) max = len; + } + + GSList *radio_button_group = (GSList *) NULL; + for (int i = 0; i < n; i++) + { + if (i) radio_button_group = gtk_radio_button_group( GTK_RADIO_BUTTON(m_radio) ); + + m_radio = GTK_RADIO_BUTTON( gtk_radio_button_new_with_label( radio_button_group, choices[i] ) ); + + m_boxes.Append( (wxObject*) m_radio ); + + ConnectWidget( GTK_WIDGET(m_radio) ); + + if (!i) gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(m_radio), TRUE ); + + gtk_signal_connect( GTK_OBJECT(m_radio), "clicked", + GTK_SIGNAL_FUNC(gtk_radiobutton_clicked_callback), (gpointer*)this ); + + gtk_myfixed_put( GTK_MYFIXED(m_parent->m_wxwindow), GTK_WIDGET(m_radio), x, y ); + + gtk_widget_set_usize( GTK_WIDGET(m_radio), max, 20 ); + + x += max; + } + + width = max*n + 10; + height = 40; } wxSize newSize = size; - if (newSize.x == -1) newSize.x = maxLen+10; + if (newSize.x == -1) newSize.x = width; if (newSize.y == -1) newSize.y = height; SetSize( newSize.x, newSize.y ); @@ -151,19 +188,51 @@ void wxRadioBox::OnSize( wxSizeEvent &event ) int x = m_x+5; int y = m_y+15; - wxNode *node = m_boxes.First(); - while (node) + if (m_windowStyle & wxRA_VERTICAL) { - GtkWidget *button = GTK_WIDGET( node->Data() ); + wxNode *node = m_boxes.First(); + while (node) + { + GtkWidget *button = GTK_WIDGET( node->Data() ); - gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), button, x, y ); - y += 20; + gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), button, x, y ); + y += 20; - int w = m_width-10; - if (w < 15) w = 15; - gtk_widget_set_usize( button, w, 20 ); + int w = m_width-10; + if (w < 15) w = 15; + gtk_widget_set_usize( button, w, 20 ); - node = node->Next(); + node = node->Next(); + } + } + else + { + int max = 0; + + wxNode *node = m_boxes.First(); + while (node) + { + GtkButton *button = GTK_BUTTON( node->Data() ); + GtkLabel *label = GTK_LABEL( button->child ); + + GdkFont *font = m_widget->style->font; + int len = 27+gdk_string_measure( font, label->label ); + if (len > max) max = len; + + node = node->Next(); + } + + node = m_boxes.First(); + while (node) + { + GtkWidget *button = GTK_WIDGET( node->Data() ); + + gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), button, x, y ); + x += max; + gtk_widget_set_usize( button, max, 20 ); + + node = node->Next(); + } } } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 0b0179b5a2..707a1682ec 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -841,7 +841,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventBut // "drop_data_available_event" //----------------------------------------------------------------------------- -static void gtk_window_drop_callback( GtkWidget *widget, GdkEvent *event, wxWindow *win ) +static void gtk_window_drop_callback( GtkWidget *widget, GdkEventDropDataAvailable *event, wxWindow *win ) { if (!win->HasVMT()) return; @@ -850,6 +850,7 @@ static void gtk_window_drop_callback( GtkWidget *widget, GdkEvent *event, wxWind 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 ); } -- 2.45.2