From 301cd871a221ca5c0f1c20df50c654a3e7a388fe Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 1 Feb 1999 06:44:35 +0000 Subject: [PATCH] wxToolTip git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1553 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- distrib/gtk/copy_src | 11 ++++- include/wx/gtk/listbox.h | 4 +- include/wx/gtk/tooltip.h | 18 ++++----- include/wx/gtk/window.h | 35 +++++++++++----- include/wx/gtk1/listbox.h | 4 +- include/wx/gtk1/tooltip.h | 18 ++++----- include/wx/gtk1/window.h | 35 +++++++++++----- samples/controls/controls.cpp | 7 ++++ src/gtk/listbox.cpp | 19 ++------- src/gtk/tooltip.cpp | 76 +++++++++++++++++++++-------------- src/gtk/window.cpp | 36 +++++++++++++---- src/gtk1/listbox.cpp | 19 ++------- src/gtk1/tooltip.cpp | 76 +++++++++++++++++++++-------------- src/gtk1/window.cpp | 36 +++++++++++++---- 14 files changed, 234 insertions(+), 160 deletions(-) diff --git a/distrib/gtk/copy_src b/distrib/gtk/copy_src index c3a0ac7720..0a532c00c8 100755 --- a/distrib/gtk/copy_src +++ b/distrib/gtk/copy_src @@ -3,7 +3,10 @@ # This script is creates a dir tree in ~/wxgtk_dist which # can then be packed into an archive -echo This script will copy the wxGTK release files into ~/wxgtk_dist +echo -------- +echo This script will copy the wxGTK release files into ~/wxgtk_dist +echo -------- +echo mkdir ~/wxgtk_dist mkdir ~/wxgtk_dist/wxGTK @@ -668,9 +671,13 @@ cp Makefile ~/wxgtk_dist/wxGTK/samples/wxsocket cp Makefile.in ~/wxgtk_dist/wxGTK/samples/wxsocket cp *.cpp ~/wxgtk_dist/wxGTK/samples/wxsocket cp *.xpm ~/wxgtk_dist/wxGTK/samples/wxsocket -cd .. +cd ../.. +echo LOCAL CORRECTCIONS +cd distrib/gtk +cp README.txt ~/wxgtk_dist/wxGTK/utils/wxPython +cp Setup ~/wxgtk_dist/wxGTK/utils/wxPython/src diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index 9d6cafe665..41b5e1b229 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -94,9 +94,6 @@ public: #if wxUSE_DRAG_AND_DROP void SetDropTarget( wxDropTarget *dropTarget ); #endif - void SetToolTip( wxToolTip *tip ); - void SetToolTip( const wxString &tip ); - // implementation @@ -105,6 +102,7 @@ public: GtkWidget *GetConnectWidget(); bool IsOwnGtkWindow( GdkWindow *window ); void ApplyWidgetStyle(); + void ApplyToolTip( GtkTooltips *tips, const char *tip ); GtkList *m_list; wxList m_clientDataList; diff --git a/include/wx/gtk/tooltip.h b/include/wx/gtk/tooltip.h index a724074f56..299f0945b2 100644 --- a/include/wx/gtk/tooltip.h +++ b/include/wx/gtk/tooltip.h @@ -33,23 +33,21 @@ class wxToolTip: public wxObject public: wxToolTip( const wxString &tip ); - ~wxToolTip(); - wxString GetTip(); + void SetTip( const wxString &tip ); + wxString GetTip() const; + wxWindow *GetWindow() const; + bool Ok() const; - void Enable( bool flag ); - void SetDelay( long msecs ); - bool Ok(); + static void Enable( bool flag ); + static void SetDelay( long msecs ); // implementation wxString m_text; + wxWindow *m_window; - GtkTooltips *m_tooltips; - GdkColor *m_bg; - GdkColor *m_fg; - - void Create( GtkWidget *tool ); + void Apply( wxWindow *win ); }; #endif // __GTKTOOLTIPH__ diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 0031aa27a1..4d8ae64bc5 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -231,16 +231,16 @@ public: virtual void SetToolTip( const wxString &tip ); virtual void SetToolTip( wxToolTip *tip ); - virtual wxToolTip& GetToolTip(); + virtual wxToolTip* GetToolTip(); virtual void Refresh( bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL ); virtual void Clear(); virtual wxRegion GetUpdateRegion() const; - virtual bool IsExposed(int x, int y) const; - virtual bool IsExposed(int x, int y, int w, int h) const; - virtual bool IsExposed(const wxPoint& pt) const; - virtual bool IsExposed(const wxRect& rect) const; + virtual bool IsExposed( int x, int y ) const; + virtual bool IsExposed( int x, int y, int w, int h ) const; + virtual bool IsExposed( const wxPoint& pt ) const; + virtual bool IsExposed( const wxRect& rect ) const; virtual wxColour GetBackgroundColour() const; virtual void SetBackgroundColour( const wxColour &colour ); @@ -320,24 +320,37 @@ public: // implementation + virtual wxPoint GetClientAreaOrigin() const; + virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags ); + + bool HasVMT(); + + virtual void OnInternalIdle(); + + /* used by all classes in the widget creation process */ + void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style, const wxString &name ); void PostCreation(); + /* the methods below are required because many native widgets + are composed of several subwidgets and setting a style for + the widget means setting it for all subwidgets as well. + also, it is nor clear, which native widget is the top + widget where (most of) the input goes. even tooltips have + to be applied to all subwidgets. */ + virtual GtkWidget* GetConnectWidget(); virtual bool IsOwnGtkWindow( GdkWindow *window ); void ConnectWidget( GtkWidget *widget ); - bool HasVMT(); - - virtual wxPoint GetClientAreaOrigin() const; - virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags ); - GtkStyle *GetWidgetStyle(); void SetWidgetStyle(); virtual void ApplyWidgetStyle(); - virtual void OnInternalIdle(); + virtual void ApplyToolTip( GtkTooltips *tips, const char *tip ); + + /* private member variables */ wxWindow *m_parent; wxList m_children; diff --git a/include/wx/gtk1/listbox.h b/include/wx/gtk1/listbox.h index 9d6cafe665..41b5e1b229 100644 --- a/include/wx/gtk1/listbox.h +++ b/include/wx/gtk1/listbox.h @@ -94,9 +94,6 @@ public: #if wxUSE_DRAG_AND_DROP void SetDropTarget( wxDropTarget *dropTarget ); #endif - void SetToolTip( wxToolTip *tip ); - void SetToolTip( const wxString &tip ); - // implementation @@ -105,6 +102,7 @@ public: GtkWidget *GetConnectWidget(); bool IsOwnGtkWindow( GdkWindow *window ); void ApplyWidgetStyle(); + void ApplyToolTip( GtkTooltips *tips, const char *tip ); GtkList *m_list; wxList m_clientDataList; diff --git a/include/wx/gtk1/tooltip.h b/include/wx/gtk1/tooltip.h index a724074f56..299f0945b2 100644 --- a/include/wx/gtk1/tooltip.h +++ b/include/wx/gtk1/tooltip.h @@ -33,23 +33,21 @@ class wxToolTip: public wxObject public: wxToolTip( const wxString &tip ); - ~wxToolTip(); - wxString GetTip(); + void SetTip( const wxString &tip ); + wxString GetTip() const; + wxWindow *GetWindow() const; + bool Ok() const; - void Enable( bool flag ); - void SetDelay( long msecs ); - bool Ok(); + static void Enable( bool flag ); + static void SetDelay( long msecs ); // implementation wxString m_text; + wxWindow *m_window; - GtkTooltips *m_tooltips; - GdkColor *m_bg; - GdkColor *m_fg; - - void Create( GtkWidget *tool ); + void Apply( wxWindow *win ); }; #endif // __GTKTOOLTIPH__ diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index 0031aa27a1..4d8ae64bc5 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -231,16 +231,16 @@ public: virtual void SetToolTip( const wxString &tip ); virtual void SetToolTip( wxToolTip *tip ); - virtual wxToolTip& GetToolTip(); + virtual wxToolTip* GetToolTip(); virtual void Refresh( bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL ); virtual void Clear(); virtual wxRegion GetUpdateRegion() const; - virtual bool IsExposed(int x, int y) const; - virtual bool IsExposed(int x, int y, int w, int h) const; - virtual bool IsExposed(const wxPoint& pt) const; - virtual bool IsExposed(const wxRect& rect) const; + virtual bool IsExposed( int x, int y ) const; + virtual bool IsExposed( int x, int y, int w, int h ) const; + virtual bool IsExposed( const wxPoint& pt ) const; + virtual bool IsExposed( const wxRect& rect ) const; virtual wxColour GetBackgroundColour() const; virtual void SetBackgroundColour( const wxColour &colour ); @@ -320,24 +320,37 @@ public: // implementation + virtual wxPoint GetClientAreaOrigin() const; + virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags ); + + bool HasVMT(); + + virtual void OnInternalIdle(); + + /* used by all classes in the widget creation process */ + void PreCreation( wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style, const wxString &name ); void PostCreation(); + /* the methods below are required because many native widgets + are composed of several subwidgets and setting a style for + the widget means setting it for all subwidgets as well. + also, it is nor clear, which native widget is the top + widget where (most of) the input goes. even tooltips have + to be applied to all subwidgets. */ + virtual GtkWidget* GetConnectWidget(); virtual bool IsOwnGtkWindow( GdkWindow *window ); void ConnectWidget( GtkWidget *widget ); - bool HasVMT(); - - virtual wxPoint GetClientAreaOrigin() const; - virtual void AdjustForParentClientOrigin( int& x, int& y, int sizeFlags ); - GtkStyle *GetWidgetStyle(); void SetWidgetStyle(); virtual void ApplyWidgetStyle(); - virtual void OnInternalIdle(); + virtual void ApplyToolTip( GtkTooltips *tips, const char *tip ); + + /* private member variables */ wxWindow *m_parent; wxList m_children; diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index a7965e72da..1aef2bffab 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -658,6 +658,13 @@ void MyPanel::OnListBoxButtons( wxCommandEvent &event ) case ID_LISTBOX_ENABLE: { m_text->WriteText("Checkbox clicked.\n"); +#ifdef __WXGTK__ + wxCheckBox *cb = (wxCheckBox*)event.GetEventObject(); + if (event.GetInt()) + cb->SetToolTip( "Click to enable listbox" ); + else + cb->SetToolTip( "Click to disable listbox" ); +#endif m_listbox->Enable( event.GetInt() == 0 ); break; } diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 6d6208d779..db10f19582 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -347,7 +347,7 @@ void wxListBox::AppendCommon( const wxString &item ) #endif #endif - if (m_toolTip) m_toolTip->Create( list_item ); + if (m_toolTip) m_toolTip->Apply( this ); } void wxListBox::Append( const wxString &item ) @@ -676,25 +676,12 @@ int wxListBox::GetIndex( GtkWidget *item ) const return -1; } -void wxListBox::SetToolTip( const wxString &tip ) +void wxListBox::ApplyToolTip( GtkTooltips *tips, const char *tip ) { - SetToolTip( new wxToolTip( tip ) ); -} - -void wxListBox::SetToolTip( wxToolTip *tip ) -{ - if (m_toolTip) delete m_toolTip; - - m_toolTip = tip; - - if (!tip) return; - - m_toolTip->Create( GTK_WIDGET(m_list) ); /* this has no effect */ - GList *child = m_list->children; while (child) { - m_toolTip->Create( GTK_WIDGET( child->data ) ); + gtk_tooltips_set_tip( tips, GTK_WIDGET( child->data ), tip, (gchar*) NULL ); child = child->next; } } diff --git a/src/gtk/tooltip.cpp b/src/gtk/tooltip.cpp index f3e3acb598..44759110bf 100644 --- a/src/gtk/tooltip.cpp +++ b/src/gtk/tooltip.cpp @@ -16,6 +16,14 @@ #include "gtk/gtk.h" #include "gdk/gdk.h" +//----------------------------------------------------------------------------- +// global data +//----------------------------------------------------------------------------- + +static GtkTooltips *ss_tooltips = (GtkTooltips*) NULL; +static GdkColor ss_bg; +static GdkColor ss_fg; + //----------------------------------------------------------------------------- // wxToolTip //----------------------------------------------------------------------------- @@ -23,62 +31,68 @@ wxToolTip::wxToolTip( const wxString &tip ) { m_text = tip; - - m_tooltips = (GtkTooltips*) NULL; - - m_fg = new GdkColor; - m_fg->red = 0; - m_fg->green = 0; - m_fg->blue = 0; - - m_bg = new GdkColor; - m_bg->red = 65535; - m_bg->green = 65535; - m_bg->blue = 50000; + m_window = (wxWindow*) NULL; } -wxToolTip::~wxToolTip() +bool wxToolTip::Ok() const { - gtk_object_unref( GTK_OBJECT(m_tooltips) ); - - delete m_fg; - delete m_bg; + return (m_window); } -bool wxToolTip::Ok() +wxString wxToolTip::GetTip() const { - return (m_tooltips); + return m_text; } -void wxToolTip::Create( GtkWidget *tool ) +void wxToolTip::SetTip( const wxString &tip ) { - if (!m_tooltips) + m_text = tip; + Apply( m_window ); +} + +void wxToolTip::Apply( wxWindow *win ) +{ + if (!win) return; + + if (!ss_tooltips) { - m_tooltips = gtk_tooltips_new(); + ss_tooltips = gtk_tooltips_new(); + + ss_fg.red = 0; + ss_fg.green = 0; + ss_fg.blue = 0; + gdk_color_alloc( gtk_widget_get_default_colormap(), &ss_fg ); - gdk_color_alloc( gtk_widget_get_colormap( tool ), m_fg ); - gdk_color_alloc( gtk_widget_get_colormap( tool ), m_bg ); + ss_bg.red = 65535; + ss_bg.green = 65535; + ss_bg.blue = 50000; + gdk_color_alloc( gtk_widget_get_default_colormap(), &ss_bg ); - gtk_tooltips_set_colors( m_tooltips, m_bg, m_fg ); + gtk_tooltips_set_colors( ss_tooltips, &ss_bg, &ss_fg ); } - gtk_tooltips_set_tip( m_tooltips, tool, m_text, (gchar*) NULL ); + m_window = win; + + if (m_text.IsEmpty()) + m_window->ApplyToolTip( ss_tooltips, (char*) NULL ); + else + m_window->ApplyToolTip( ss_tooltips, m_text ); } void wxToolTip::Enable( bool flag ) { - if (!Ok()) return; + if (!ss_tooltips) return; if (flag) - gtk_tooltips_enable( m_tooltips ); + gtk_tooltips_enable( ss_tooltips ); else - gtk_tooltips_disable( m_tooltips ); + gtk_tooltips_disable( ss_tooltips ); } void wxToolTip::SetDelay( long msecs ) { - if (!Ok()) return; + if (!ss_tooltips) return; - gtk_tooltips_set_delay( m_tooltips, msecs ); + gtk_tooltips_set_delay( ss_tooltips, msecs ); } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 9b1cb42717..69d0c5f2a9 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -2475,24 +2475,44 @@ void wxWindow::Clear() void wxWindow::SetToolTip( const wxString &tip ) { - SetToolTip( new wxToolTip( tip ) ); + if (m_toolTip) + { + m_toolTip->SetTip( tip ); + } + else + { + m_toolTip = new wxToolTip( tip ); + m_toolTip->Apply( this ); + } + + if (tip.IsEmpty()) + { + delete m_toolTip; + m_toolTip = (wxToolTip*) NULL; + } } void wxWindow::SetToolTip( wxToolTip *tip ) { - if (m_toolTip) delete m_toolTip; + if (m_toolTip) + { + m_toolTip->SetTip( (char*) NULL ); + delete m_toolTip; + } m_toolTip = tip; - if (m_toolTip) m_toolTip->Create( GetConnectWidget() ); + if (m_toolTip) m_toolTip->Apply( this ); } -wxToolTip& wxWindow::GetToolTip() +void wxWindow::ApplyToolTip( GtkTooltips *tips, const char *tip ) { - if (!m_toolTip) - wxLogError( "No tooltip set." ); - - return *m_toolTip; + gtk_tooltips_set_tip( tips, GetConnectWidget(), tip, (gchar*) NULL ); +} + +wxToolTip* wxWindow::GetToolTip() +{ + return m_toolTip; } wxColour wxWindow::GetBackgroundColour() const diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 6d6208d779..db10f19582 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -347,7 +347,7 @@ void wxListBox::AppendCommon( const wxString &item ) #endif #endif - if (m_toolTip) m_toolTip->Create( list_item ); + if (m_toolTip) m_toolTip->Apply( this ); } void wxListBox::Append( const wxString &item ) @@ -676,25 +676,12 @@ int wxListBox::GetIndex( GtkWidget *item ) const return -1; } -void wxListBox::SetToolTip( const wxString &tip ) +void wxListBox::ApplyToolTip( GtkTooltips *tips, const char *tip ) { - SetToolTip( new wxToolTip( tip ) ); -} - -void wxListBox::SetToolTip( wxToolTip *tip ) -{ - if (m_toolTip) delete m_toolTip; - - m_toolTip = tip; - - if (!tip) return; - - m_toolTip->Create( GTK_WIDGET(m_list) ); /* this has no effect */ - GList *child = m_list->children; while (child) { - m_toolTip->Create( GTK_WIDGET( child->data ) ); + gtk_tooltips_set_tip( tips, GTK_WIDGET( child->data ), tip, (gchar*) NULL ); child = child->next; } } diff --git a/src/gtk1/tooltip.cpp b/src/gtk1/tooltip.cpp index f3e3acb598..44759110bf 100644 --- a/src/gtk1/tooltip.cpp +++ b/src/gtk1/tooltip.cpp @@ -16,6 +16,14 @@ #include "gtk/gtk.h" #include "gdk/gdk.h" +//----------------------------------------------------------------------------- +// global data +//----------------------------------------------------------------------------- + +static GtkTooltips *ss_tooltips = (GtkTooltips*) NULL; +static GdkColor ss_bg; +static GdkColor ss_fg; + //----------------------------------------------------------------------------- // wxToolTip //----------------------------------------------------------------------------- @@ -23,62 +31,68 @@ wxToolTip::wxToolTip( const wxString &tip ) { m_text = tip; - - m_tooltips = (GtkTooltips*) NULL; - - m_fg = new GdkColor; - m_fg->red = 0; - m_fg->green = 0; - m_fg->blue = 0; - - m_bg = new GdkColor; - m_bg->red = 65535; - m_bg->green = 65535; - m_bg->blue = 50000; + m_window = (wxWindow*) NULL; } -wxToolTip::~wxToolTip() +bool wxToolTip::Ok() const { - gtk_object_unref( GTK_OBJECT(m_tooltips) ); - - delete m_fg; - delete m_bg; + return (m_window); } -bool wxToolTip::Ok() +wxString wxToolTip::GetTip() const { - return (m_tooltips); + return m_text; } -void wxToolTip::Create( GtkWidget *tool ) +void wxToolTip::SetTip( const wxString &tip ) { - if (!m_tooltips) + m_text = tip; + Apply( m_window ); +} + +void wxToolTip::Apply( wxWindow *win ) +{ + if (!win) return; + + if (!ss_tooltips) { - m_tooltips = gtk_tooltips_new(); + ss_tooltips = gtk_tooltips_new(); + + ss_fg.red = 0; + ss_fg.green = 0; + ss_fg.blue = 0; + gdk_color_alloc( gtk_widget_get_default_colormap(), &ss_fg ); - gdk_color_alloc( gtk_widget_get_colormap( tool ), m_fg ); - gdk_color_alloc( gtk_widget_get_colormap( tool ), m_bg ); + ss_bg.red = 65535; + ss_bg.green = 65535; + ss_bg.blue = 50000; + gdk_color_alloc( gtk_widget_get_default_colormap(), &ss_bg ); - gtk_tooltips_set_colors( m_tooltips, m_bg, m_fg ); + gtk_tooltips_set_colors( ss_tooltips, &ss_bg, &ss_fg ); } - gtk_tooltips_set_tip( m_tooltips, tool, m_text, (gchar*) NULL ); + m_window = win; + + if (m_text.IsEmpty()) + m_window->ApplyToolTip( ss_tooltips, (char*) NULL ); + else + m_window->ApplyToolTip( ss_tooltips, m_text ); } void wxToolTip::Enable( bool flag ) { - if (!Ok()) return; + if (!ss_tooltips) return; if (flag) - gtk_tooltips_enable( m_tooltips ); + gtk_tooltips_enable( ss_tooltips ); else - gtk_tooltips_disable( m_tooltips ); + gtk_tooltips_disable( ss_tooltips ); } void wxToolTip::SetDelay( long msecs ) { - if (!Ok()) return; + if (!ss_tooltips) return; - gtk_tooltips_set_delay( m_tooltips, msecs ); + gtk_tooltips_set_delay( ss_tooltips, msecs ); } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 9b1cb42717..69d0c5f2a9 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -2475,24 +2475,44 @@ void wxWindow::Clear() void wxWindow::SetToolTip( const wxString &tip ) { - SetToolTip( new wxToolTip( tip ) ); + if (m_toolTip) + { + m_toolTip->SetTip( tip ); + } + else + { + m_toolTip = new wxToolTip( tip ); + m_toolTip->Apply( this ); + } + + if (tip.IsEmpty()) + { + delete m_toolTip; + m_toolTip = (wxToolTip*) NULL; + } } void wxWindow::SetToolTip( wxToolTip *tip ) { - if (m_toolTip) delete m_toolTip; + if (m_toolTip) + { + m_toolTip->SetTip( (char*) NULL ); + delete m_toolTip; + } m_toolTip = tip; - if (m_toolTip) m_toolTip->Create( GetConnectWidget() ); + if (m_toolTip) m_toolTip->Apply( this ); } -wxToolTip& wxWindow::GetToolTip() +void wxWindow::ApplyToolTip( GtkTooltips *tips, const char *tip ) { - if (!m_toolTip) - wxLogError( "No tooltip set." ); - - return *m_toolTip; + gtk_tooltips_set_tip( tips, GetConnectWidget(), tip, (gchar*) NULL ); +} + +wxToolTip* wxWindow::GetToolTip() +{ + return m_toolTip; } wxColour wxWindow::GetBackgroundColour() const -- 2.45.2