From: Robert Roebling Date: Wed, 27 Jan 1999 17:15:34 +0000 (+0000) Subject: wxToolTip part II X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/b11708106f93d28dbb47218b18e02674ad6c0cdb wxToolTip part II small change in tab traversal makefile corrections wxGLCanvas moved git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1498 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/image.tex b/docs/latex/wx/image.tex index a7808cd051..02cca80629 100644 --- a/docs/latex/wx/image.tex +++ b/docs/latex/wx/image.tex @@ -369,9 +369,9 @@ Depending on how wxWindows has been configured, not all formats may be available Returns a scaled version of the image. This is also useful for scaling bitmaps in general as the only other way to scale bitmaps -is do blit a wxMemoryDC into another wxMemoryDC. Windows can such scaling -itself, but on GTK scaling bitmaps is done using this routine -internally. +is to blit a wxMemoryDC into another wxMemoryDC. Windows can do such +scaling itself but in the GTK port, scaling bitmaps is done using +this routine internally. \membersection{wxImage::SetData}\label{wximagesetdata} @@ -391,7 +391,7 @@ Specifies whether there is a mask or not. The area of the mask is determined by \func{void}{SetMaskColour}{\param{unsigned char }{red}, \param{unsigned char }{blue}, \param{unsigned char }{green}} -Sets the mask colour for this image. +Sets the mask colour for this image (and tells the image to use the mask). \membersection{wxImage::SetRGB}\label{wximagesetrgb} diff --git a/include/wx/defs.h b/include/wx/defs.h index 2c3b71ec0c..55a54645ef 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1030,6 +1030,7 @@ typedef struct _GtkStyle GtkStyle; typedef struct _GtkAdjustment GtkAdjustment; typedef struct _GtkList GtkList; typedef struct _GtkToolbar GtkToolbar; +typedef struct _GtkTooltips GtkTooltips; typedef struct _GtkNotebook GtkNotebook; typedef struct _GtkNotebookPage GtkNotebookPage; diff --git a/include/wx/gtk/listbox.h b/include/wx/gtk/listbox.h index 1b24d42c25..9d6cafe665 100644 --- a/include/wx/gtk/listbox.h +++ b/include/wx/gtk/listbox.h @@ -94,6 +94,9 @@ public: #if wxUSE_DRAG_AND_DROP void SetDropTarget( wxDropTarget *dropTarget ); #endif + void SetToolTip( wxToolTip *tip ); + void SetToolTip( const wxString &tip ); + // implementation diff --git a/include/wx/gtk/tooltip.h b/include/wx/gtk/tooltip.h index d8f7c0b8e3..a724074f56 100644 --- a/include/wx/gtk/tooltip.h +++ b/include/wx/gtk/tooltip.h @@ -32,13 +32,24 @@ class wxToolTip: public wxObject { public: - wxToolTip() {} + wxToolTip( const wxString &tip ); + ~wxToolTip(); - static void Add( wxWindow *tool, const wxString &tip ); - static void Enable( bool flag ); - static void SetDelay( long msecs ); + wxString GetTip(); + + void Enable( bool flag ); + void SetDelay( long msecs ); + bool Ok(); + // implementation + + wxString m_text; + + GtkTooltips *m_tooltips; + GdkColor *m_bg; + GdkColor *m_fg; + void Create( GtkWidget *tool ); }; #endif // __GTKTOOLTIPH__ diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 046a6d6219..0031aa27a1 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -55,6 +55,7 @@ class wxItemResource; #if wxUSE_DRAG_AND_DROP class wxDropTarget; #endif +class wxToolTip; //----------------------------------------------------------------------------- // callback definition for inserting a window (internal) @@ -207,8 +208,8 @@ public: void PushEventHandler( wxEvtHandler *handler ); wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE ); - virtual wxValidator *GetValidator(); virtual void SetValidator( const wxValidator &validator ); + virtual wxValidator *GetValidator(); virtual void SetClientObject( wxClientData *data ); virtual wxClientData *GetClientObject(); @@ -225,9 +226,13 @@ public: wxWindowID GetId() const; void SetCursor( const wxCursor &cursor ); - + void WarpPointer(int x, int y); + virtual void SetToolTip( const wxString &tip ); + virtual void SetToolTip( wxToolTip *tip ); + virtual wxToolTip& GetToolTip(); + virtual void Refresh( bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL ); virtual void Clear(); @@ -359,6 +364,7 @@ public: wxAcceleratorTable m_acceleratorTable; wxClientData *m_clientObject; void *m_clientData; + wxToolTip *m_toolTip; GtkWidget *m_widget; GtkWidget *m_wxwindow; diff --git a/include/wx/gtk1/listbox.h b/include/wx/gtk1/listbox.h index 1b24d42c25..9d6cafe665 100644 --- a/include/wx/gtk1/listbox.h +++ b/include/wx/gtk1/listbox.h @@ -94,6 +94,9 @@ public: #if wxUSE_DRAG_AND_DROP void SetDropTarget( wxDropTarget *dropTarget ); #endif + void SetToolTip( wxToolTip *tip ); + void SetToolTip( const wxString &tip ); + // implementation diff --git a/include/wx/gtk1/tooltip.h b/include/wx/gtk1/tooltip.h index d8f7c0b8e3..a724074f56 100644 --- a/include/wx/gtk1/tooltip.h +++ b/include/wx/gtk1/tooltip.h @@ -32,13 +32,24 @@ class wxToolTip: public wxObject { public: - wxToolTip() {} + wxToolTip( const wxString &tip ); + ~wxToolTip(); - static void Add( wxWindow *tool, const wxString &tip ); - static void Enable( bool flag ); - static void SetDelay( long msecs ); + wxString GetTip(); + + void Enable( bool flag ); + void SetDelay( long msecs ); + bool Ok(); + // implementation + + wxString m_text; + + GtkTooltips *m_tooltips; + GdkColor *m_bg; + GdkColor *m_fg; + void Create( GtkWidget *tool ); }; #endif // __GTKTOOLTIPH__ diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index 046a6d6219..0031aa27a1 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -55,6 +55,7 @@ class wxItemResource; #if wxUSE_DRAG_AND_DROP class wxDropTarget; #endif +class wxToolTip; //----------------------------------------------------------------------------- // callback definition for inserting a window (internal) @@ -207,8 +208,8 @@ public: void PushEventHandler( wxEvtHandler *handler ); wxEvtHandler *PopEventHandler( bool deleteHandler = FALSE ); - virtual wxValidator *GetValidator(); virtual void SetValidator( const wxValidator &validator ); + virtual wxValidator *GetValidator(); virtual void SetClientObject( wxClientData *data ); virtual wxClientData *GetClientObject(); @@ -225,9 +226,13 @@ public: wxWindowID GetId() const; void SetCursor( const wxCursor &cursor ); - + void WarpPointer(int x, int y); + virtual void SetToolTip( const wxString &tip ); + virtual void SetToolTip( wxToolTip *tip ); + virtual wxToolTip& GetToolTip(); + virtual void Refresh( bool eraseBackground = TRUE, const wxRect *rect = (const wxRect *) NULL ); virtual void Clear(); @@ -359,6 +364,7 @@ public: wxAcceleratorTable m_acceleratorTable; wxClientData *m_clientObject; void *m_clientData; + wxToolTip *m_toolTip; GtkWidget *m_widget; GtkWidget *m_wxwindow; diff --git a/samples/controls/controls.cpp b/samples/controls/controls.cpp index d0f9bbb2d5..fe99c4266e 100644 --- a/samples/controls/controls.cpp +++ b/samples/controls/controls.cpp @@ -230,7 +230,7 @@ BEGIN_EVENT_TABLE(MyPanel, wxPanel) EVT_BUTTON (ID_CHOICE_DELETE, MyPanel::OnChoiceButtons) EVT_BUTTON (ID_CHOICE_FONT, MyPanel::OnChoiceButtons) EVT_CHECKBOX (ID_CHOICE_ENABLE, MyPanel::OnChoiceButtons) - EVT_CHOICE (ID_COMBO, MyPanel::OnCombo) + EVT_COMBOBOX (ID_COMBO, MyPanel::OnCombo) EVT_BUTTON (ID_COMBO_SEL_NUM, MyPanel::OnComboButtons) EVT_BUTTON (ID_COMBO_SEL_STR, MyPanel::OnComboButtons) EVT_BUTTON (ID_COMBO_CLEAR, MyPanel::OnComboButtons) @@ -333,6 +333,9 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : // panel->SetBackgroundColour("cadet blue"); // panel->SetForegroundColour("blue"); m_listbox = new wxListBox( panel, ID_LISTBOX, wxPoint(10,10), wxSize(120,70), 5, choices ); +#ifdef __WXGTK__ + m_listbox->SetToolTip( "This is a list box" ); +#endif // m_listbox->SetBackgroundColour("wheat"); (void)new wxButton( panel, ID_LISTBOX_SEL_NUM, "Select #2", wxPoint(180,30), wxSize(140,30) ); (void)new wxButton( panel, ID_LISTBOX_SEL_STR, "Select 'This'", wxPoint(340,30), wxSize(140,30) ); @@ -340,13 +343,16 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : (void)new wxButton( panel, ID_LISTBOX_APPEND, "Append 'Hi!'", wxPoint(340,80), wxSize(140,30) ); (void)new wxButton( panel, ID_LISTBOX_DELETE, "Delete selected item", wxPoint(180,130), wxSize(140,30) ); button = new wxButton( panel, ID_LISTBOX_FONT, "Set Italic font", wxPoint(340,130), wxSize(140,30) ); - #ifdef __WXGTK__ - wxToolTip::Add( button, "Press here to set italic font" ); + button->SetToolTip( "Press here to set italic font" ); #endif + // button->SetForegroundColour( "red" ); m_checkbox = new wxCheckBox( panel, ID_LISTBOX_ENABLE, "Disable", wxPoint(20,130), wxSize(140,30) ); m_checkbox->SetValue(FALSE); +#ifdef __WXGTK__ + m_checkbox->SetToolTip( "Click here to disable the listbox" ); +#endif m_notebook->AddPage(panel, "wxList", TRUE, Image_List); panel = new wxPanel(m_notebook); @@ -385,7 +391,7 @@ MyPanel::MyPanel( wxFrame *frame, int x, int y, int w, int h ) : // tc->SetBackgroundColour("wheat"); m_multitext = new wxTextCtrl( panel, ID_TEXT, "And here.", wxPoint(10,50), wxSize(320,160), wxTE_MULTILINE ); (*m_multitext) << " More text."; - m_multitext->SetBackgroundColour("wheat"); +// m_multitext->SetBackgroundColour("wheat"); (void)new wxStaticBox( panel, -1, "wxClipboard", wxPoint(345,50), wxSize(160,145) ); (void)new wxButton( panel, ID_COPY_TEXT, "Copy line 1", wxPoint(370,80), wxSize(110,30) ); (void)new wxButton( panel, ID_PASTE_TEXT, "Paste text", wxPoint(370,140), wxSize(110,30) ); diff --git a/samples/dde/ddesetup.h b/samples/dde/ddesetup.h index 7b674ecf54..00c6cc3b23 100644 --- a/samples/dde/ddesetup.h +++ b/samples/dde/ddesetup.h @@ -15,7 +15,7 @@ */ // If 1, use real DDE. If 0, use TCP/IP -#define wxUSE_DDE_FOR_SAMPLE 1 +#define wxUSE_DDE_FOR_SAMPLE 0 #if wxUSE_DDE_FOR_SAMPLE diff --git a/src/gtk/listbox.cpp b/src/gtk/listbox.cpp index 32cf66671e..6d6208d779 100644 --- a/src/gtk/listbox.cpp +++ b/src/gtk/listbox.cpp @@ -17,6 +17,7 @@ #include "wx/utils.h" #include "wx/intl.h" #include "wx/checklst.h" +#include "wx/tooltip.h" #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" @@ -345,6 +346,8 @@ void wxListBox::AppendCommon( const wxString &item ) if (m_dropTarget) m_dropTarget->RegisterWidget( list_item ); #endif #endif + + if (m_toolTip) m_toolTip->Create( list_item ); } void wxListBox::Append( const wxString &item ) @@ -673,6 +676,29 @@ int wxListBox::GetIndex( GtkWidget *item ) const return -1; } +void wxListBox::SetToolTip( const wxString &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 ) ); + child = child->next; + } +} + #if wxUSE_DRAG_AND_DROP void wxListBox::SetDropTarget( wxDropTarget *dropTarget ) { @@ -750,3 +776,4 @@ void wxListBox::ApplyWidgetStyle() child = child->next; } } + diff --git a/src/gtk/tooltip.cpp b/src/gtk/tooltip.cpp index bc5df460c6..f3e3acb598 100644 --- a/src/gtk/tooltip.cpp +++ b/src/gtk/tooltip.cpp @@ -17,53 +17,68 @@ #include "gdk/gdk.h" //----------------------------------------------------------------------------- -// global data +// wxToolTip //----------------------------------------------------------------------------- -GtkTooltips *gs_tooltips = (GtkTooltips*) NULL; -GdkColor gs_tooltip_bg; -GdkColor gs_tooltip_fg; +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; +} -//----------------------------------------------------------------------------- -// wxToolTip -//----------------------------------------------------------------------------- +wxToolTip::~wxToolTip() +{ + gtk_object_unref( GTK_OBJECT(m_tooltips) ); + + delete m_fg; + delete m_bg; +} -void wxToolTip::Add( wxWindow *tool, const wxString &tip ) +bool wxToolTip::Ok() { - if (!gs_tooltips) + return (m_tooltips); +} + +void wxToolTip::Create( GtkWidget *tool ) +{ + if (!m_tooltips) { - gs_tooltips = gtk_tooltips_new(); - - gs_tooltip_fg.red = 0; - gs_tooltip_fg.green = 0; - gs_tooltip_fg.blue = 0; - gdk_color_alloc( gtk_widget_get_colormap( tool->GetConnectWidget() ), &gs_tooltip_fg ); + m_tooltips = gtk_tooltips_new(); - gs_tooltip_bg.red = 65535; - gs_tooltip_bg.green = 65535; - gs_tooltip_bg.blue = 50000; - gdk_color_alloc( gtk_widget_get_colormap( tool->GetConnectWidget() ), &gs_tooltip_bg ); + gdk_color_alloc( gtk_widget_get_colormap( tool ), m_fg ); + gdk_color_alloc( gtk_widget_get_colormap( tool ), m_bg ); - gtk_tooltips_set_colors( gs_tooltips, &gs_tooltip_bg, &gs_tooltip_fg ); + gtk_tooltips_set_colors( m_tooltips, m_bg, m_fg ); } - gtk_tooltips_set_tip( gs_tooltips, tool->GetConnectWidget(), tip, (gchar*) NULL ); + gtk_tooltips_set_tip( m_tooltips, tool, m_text, (gchar*) NULL ); } void wxToolTip::Enable( bool flag ) { - if (!gs_tooltips) gs_tooltips = gtk_tooltips_new(); + if (!Ok()) return; if (flag) - gtk_tooltips_enable( gs_tooltips ); + gtk_tooltips_enable( m_tooltips ); else - gtk_tooltips_disable( gs_tooltips ); + gtk_tooltips_disable( m_tooltips ); } void wxToolTip::SetDelay( long msecs ) { - if (!gs_tooltips) gs_tooltips = gtk_tooltips_new(); + if (!Ok()) return; - gtk_tooltips_set_delay( gs_tooltips, msecs ); + gtk_tooltips_set_delay( m_tooltips, msecs ); } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 54cc477208..3f46517907 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -24,6 +24,7 @@ #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" #endif +#include "wx/tooltip.h" #include "wx/menu.h" #include "wx/statusbr.h" #include "wx/intl.h" @@ -1234,12 +1235,12 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, // InsertChild for wxWindow. //----------------------------------------------------------------------------- -// Callback for wxWindow. This very strange beast has to be used because -// C++ has no virtual methods in a constructor. We have to emulate a -// virtual function here as wxNotebook requires a different way to insert -// a child in it. I had opted for creating a wxNotebookPage window class -// which would have made this superfluous (such in the MDI window system), -// but no-one was listening to me... +/* Callback for wxWindow. This very strange beast has to be used because + * C++ has no virtual methods in a constructor. We have to emulate a + * virtual function here as wxNotebook requires a different way to insert + * a child in it. I had opted for creating a wxNotebookPage window class + * which would have made this superfluous (such in the MDI window system), + * but no-one was listening to me... */ static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child ) { @@ -1342,6 +1343,8 @@ wxWindow::wxWindow() m_isStaticBox = FALSE; m_acceptsFocus = FALSE; + + m_toolTip = (wxToolTip*) NULL; } wxWindow::wxWindow( wxWindow *parent, wxWindowID id, @@ -1420,7 +1423,7 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, if ((m_windowStyle & wxTAB_TRAVERSAL) != 0) { - GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); + GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); /* changed from UNSET */ m_acceptsFocus = FALSE; } else @@ -1500,6 +1503,8 @@ wxWindow::~wxWindow() if (m_dropTarget) delete m_dropTarget; #endif + if (m_toolTip) delete m_toolTip; + if (m_parent) m_parent->RemoveChild( this ); if (m_widget) Show( FALSE ); @@ -1629,6 +1634,7 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, m_clientData = NULL; m_isStaticBox = FALSE; + m_toolTip = (wxToolTip*) NULL; } void wxWindow::PostCreation() @@ -2458,6 +2464,28 @@ void wxWindow::Clear() if (m_wxwindow && m_wxwindow->window) gdk_window_clear( m_wxwindow->window ); } +void wxWindow::SetToolTip( const wxString &tip ) +{ + SetToolTip( new wxToolTip( tip ) ); +} + +void wxWindow::SetToolTip( wxToolTip *tip ) +{ + if (m_toolTip) delete m_toolTip; + + m_toolTip = tip; + + if (m_toolTip) m_toolTip->Create( GetConnectWidget() ); +} + +wxToolTip& wxWindow::GetToolTip() +{ + if (!m_toolTip) + wxLogError( "No tooltip set." ); + + return *m_toolTip; +} + wxColour wxWindow::GetBackgroundColour() const { return m_backgroundColour; diff --git a/src/gtk1/listbox.cpp b/src/gtk1/listbox.cpp index 32cf66671e..6d6208d779 100644 --- a/src/gtk1/listbox.cpp +++ b/src/gtk1/listbox.cpp @@ -17,6 +17,7 @@ #include "wx/utils.h" #include "wx/intl.h" #include "wx/checklst.h" +#include "wx/tooltip.h" #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" @@ -345,6 +346,8 @@ void wxListBox::AppendCommon( const wxString &item ) if (m_dropTarget) m_dropTarget->RegisterWidget( list_item ); #endif #endif + + if (m_toolTip) m_toolTip->Create( list_item ); } void wxListBox::Append( const wxString &item ) @@ -673,6 +676,29 @@ int wxListBox::GetIndex( GtkWidget *item ) const return -1; } +void wxListBox::SetToolTip( const wxString &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 ) ); + child = child->next; + } +} + #if wxUSE_DRAG_AND_DROP void wxListBox::SetDropTarget( wxDropTarget *dropTarget ) { @@ -750,3 +776,4 @@ void wxListBox::ApplyWidgetStyle() child = child->next; } } + diff --git a/src/gtk1/tooltip.cpp b/src/gtk1/tooltip.cpp index bc5df460c6..f3e3acb598 100644 --- a/src/gtk1/tooltip.cpp +++ b/src/gtk1/tooltip.cpp @@ -17,53 +17,68 @@ #include "gdk/gdk.h" //----------------------------------------------------------------------------- -// global data +// wxToolTip //----------------------------------------------------------------------------- -GtkTooltips *gs_tooltips = (GtkTooltips*) NULL; -GdkColor gs_tooltip_bg; -GdkColor gs_tooltip_fg; +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; +} -//----------------------------------------------------------------------------- -// wxToolTip -//----------------------------------------------------------------------------- +wxToolTip::~wxToolTip() +{ + gtk_object_unref( GTK_OBJECT(m_tooltips) ); + + delete m_fg; + delete m_bg; +} -void wxToolTip::Add( wxWindow *tool, const wxString &tip ) +bool wxToolTip::Ok() { - if (!gs_tooltips) + return (m_tooltips); +} + +void wxToolTip::Create( GtkWidget *tool ) +{ + if (!m_tooltips) { - gs_tooltips = gtk_tooltips_new(); - - gs_tooltip_fg.red = 0; - gs_tooltip_fg.green = 0; - gs_tooltip_fg.blue = 0; - gdk_color_alloc( gtk_widget_get_colormap( tool->GetConnectWidget() ), &gs_tooltip_fg ); + m_tooltips = gtk_tooltips_new(); - gs_tooltip_bg.red = 65535; - gs_tooltip_bg.green = 65535; - gs_tooltip_bg.blue = 50000; - gdk_color_alloc( gtk_widget_get_colormap( tool->GetConnectWidget() ), &gs_tooltip_bg ); + gdk_color_alloc( gtk_widget_get_colormap( tool ), m_fg ); + gdk_color_alloc( gtk_widget_get_colormap( tool ), m_bg ); - gtk_tooltips_set_colors( gs_tooltips, &gs_tooltip_bg, &gs_tooltip_fg ); + gtk_tooltips_set_colors( m_tooltips, m_bg, m_fg ); } - gtk_tooltips_set_tip( gs_tooltips, tool->GetConnectWidget(), tip, (gchar*) NULL ); + gtk_tooltips_set_tip( m_tooltips, tool, m_text, (gchar*) NULL ); } void wxToolTip::Enable( bool flag ) { - if (!gs_tooltips) gs_tooltips = gtk_tooltips_new(); + if (!Ok()) return; if (flag) - gtk_tooltips_enable( gs_tooltips ); + gtk_tooltips_enable( m_tooltips ); else - gtk_tooltips_disable( gs_tooltips ); + gtk_tooltips_disable( m_tooltips ); } void wxToolTip::SetDelay( long msecs ) { - if (!gs_tooltips) gs_tooltips = gtk_tooltips_new(); + if (!Ok()) return; - gtk_tooltips_set_delay( gs_tooltips, msecs ); + gtk_tooltips_set_delay( m_tooltips, msecs ); } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 54cc477208..3f46517907 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -24,6 +24,7 @@ #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" #endif +#include "wx/tooltip.h" #include "wx/menu.h" #include "wx/statusbr.h" #include "wx/intl.h" @@ -1234,12 +1235,12 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, // InsertChild for wxWindow. //----------------------------------------------------------------------------- -// Callback for wxWindow. This very strange beast has to be used because -// C++ has no virtual methods in a constructor. We have to emulate a -// virtual function here as wxNotebook requires a different way to insert -// a child in it. I had opted for creating a wxNotebookPage window class -// which would have made this superfluous (such in the MDI window system), -// but no-one was listening to me... +/* Callback for wxWindow. This very strange beast has to be used because + * C++ has no virtual methods in a constructor. We have to emulate a + * virtual function here as wxNotebook requires a different way to insert + * a child in it. I had opted for creating a wxNotebookPage window class + * which would have made this superfluous (such in the MDI window system), + * but no-one was listening to me... */ static void wxInsertChildInWindow( wxWindow* parent, wxWindow* child ) { @@ -1342,6 +1343,8 @@ wxWindow::wxWindow() m_isStaticBox = FALSE; m_acceptsFocus = FALSE; + + m_toolTip = (wxToolTip*) NULL; } wxWindow::wxWindow( wxWindow *parent, wxWindowID id, @@ -1420,7 +1423,7 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id, if ((m_windowStyle & wxTAB_TRAVERSAL) != 0) { - GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); + GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS ); /* changed from UNSET */ m_acceptsFocus = FALSE; } else @@ -1500,6 +1503,8 @@ wxWindow::~wxWindow() if (m_dropTarget) delete m_dropTarget; #endif + if (m_toolTip) delete m_toolTip; + if (m_parent) m_parent->RemoveChild( this ); if (m_widget) Show( FALSE ); @@ -1629,6 +1634,7 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id, m_clientData = NULL; m_isStaticBox = FALSE; + m_toolTip = (wxToolTip*) NULL; } void wxWindow::PostCreation() @@ -2458,6 +2464,28 @@ void wxWindow::Clear() if (m_wxwindow && m_wxwindow->window) gdk_window_clear( m_wxwindow->window ); } +void wxWindow::SetToolTip( const wxString &tip ) +{ + SetToolTip( new wxToolTip( tip ) ); +} + +void wxWindow::SetToolTip( wxToolTip *tip ) +{ + if (m_toolTip) delete m_toolTip; + + m_toolTip = tip; + + if (m_toolTip) m_toolTip->Create( GetConnectWidget() ); +} + +wxToolTip& wxWindow::GetToolTip() +{ + if (!m_toolTip) + wxLogError( "No tooltip set." ); + + return *m_toolTip; +} + wxColour wxWindow::GetBackgroundColour() const { return m_backgroundColour; diff --git a/utils/dialoged/src/Makefile b/utils/dialoged/src/Makefile index 05ad82cc43..d754615f73 100644 --- a/utils/dialoged/src/Makefile +++ b/utils/dialoged/src/Makefile @@ -1,3 +1,16 @@ +# +# File: Makefile +# Author: Robert Roebling +# Created: 1999 +# Updated: +# Copyright: (c) 1998 Robert Roebling +# +# Makefile for Dialog Editor (GTK version) +# +# This makefile requires wxWindows/GTK to be +# installed (possibly using "make install") +# on your system. +# CC = g++ diff --git a/utils/glcanvas/distrib/glcanvas.rsp b/utils/glcanvas/distrib/glcanvas.rsp index 045fa083bd..1c238e484d 100644 --- a/utils/glcanvas/distrib/glcanvas.rsp +++ b/utils/glcanvas/distrib/glcanvas.rsp @@ -2,15 +2,20 @@ docs/*.* win/*.cpp win/*.h win/make*.* -src/*.cpp -src/*.h -src/make*.* +gtk/*.cpp +gtk/*.h +gtk/make*.* +motif/*.cpp +motif/*.h +motif/*.txt +motif/make*.* samples/cube/*.cpp samples/cube/*.h samples/cube/*.rc samples/cube/*.ico samples/cube/*.xbm samples/cube/make*.* +samples/cube/Makefile samples/isosurf/*.cpp samples/isosurf/*.h samples/isosurf/*.rc @@ -19,6 +24,7 @@ samples/isosurf/*.xbm samples/isosurf/*.dat samples/isosurf/*.dat.gz samples/isosurf/make*.* +samples/isosurf/Makefile samples/penguin/*.cpp samples/penguin/*.c samples/penguin/*.h @@ -28,6 +34,7 @@ samples/penguin/*.xbm samples/penguin/*.xpm samples/penguin/make*.* samples/penguin/penguin.lwo +samples/penguin/Makefile diff --git a/utils/glcanvas/gtk/.cvsignore b/utils/glcanvas/gtk/.cvsignore new file mode 100644 index 0000000000..4646a42c35 --- /dev/null +++ b/utils/glcanvas/gtk/.cvsignore @@ -0,0 +1,3 @@ +Linux +linux-gnu +linux diff --git a/utils/glcanvas/gtk/glcanvas.cpp b/utils/glcanvas/gtk/glcanvas.cpp new file mode 100644 index 0000000000..9e16370d1e --- /dev/null +++ b/utils/glcanvas/gtk/glcanvas.cpp @@ -0,0 +1,312 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: glcanvas.cpp +// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWindows and GTK +// Author: Robert Roebling +// Modified by: +// Created: 17/08/98 +// RCS-ID: $Id$ +// Copyright: (c) Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma implementation "glcanvas.h" +#endif + +#include "glcanvas.h" + +#include "wx/frame.h" +#include "wx/colour.h" +#include "wx/module.h" +#include "wx/app.h" + +extern "C" { +#include "gtk/gtk.h" +#include "gdk/gdk.h" +#include "gdk/gdkx.h" +} + +#include "wx/gtk/win_gtk.h" + +//--------------------------------------------------------------------------- +// global data +//--------------------------------------------------------------------------- + +XVisualInfo *g_vi = (XVisualInfo*) NULL; + +//--------------------------------------------------------------------------- +// wxGLContext +//--------------------------------------------------------------------------- + +IMPLEMENT_CLASS(wxGLContext,wxObject) + +wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette& WXUNUSED(palette) ) +{ + m_window = win; + m_widget = ((wxGLCanvas*)win)->m_glWidget; + + wxCHECK_RET( g_vi, "invalid visual for OpenGl" ); + + m_glContext = glXCreateContext( GDK_DISPLAY(), g_vi, None, GL_TRUE ); + + wxCHECK_RET( m_glContext, "Couldn't create OpenGl context" ); +} + +wxGLContext::~wxGLContext() +{ + if (!m_glContext) return; + + if (m_glContext == glXGetCurrentContext()) + { + glXMakeCurrent( GDK_DISPLAY(), None, NULL); + } + + glXDestroyContext( GDK_DISPLAY(), m_glContext ); +} + +void wxGLContext::SwapBuffers() +{ + if (m_glContext) + { + glXSwapBuffers( GDK_DISPLAY(), GDK_WINDOW_XWINDOW( m_widget->window ) ); + } +} + +void wxGLContext::SetCurrent() +{ + if (m_glContext) + { + glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(m_widget->window), m_glContext ); + } +} + +void wxGLContext::SetColour(const char *colour) +{ + float r = 0.0; + float g = 0.0; + float b = 0.0; + wxColour *col = wxTheColourDatabase->FindColour(colour); + if (col) + { + r = (float)(col->Red()/256.0); + g = (float)(col->Green()/256.0); + b = (float)(col->Blue()/256.0); + glColor3f( r, g, b); + } +} + +void wxGLContext::SetupPixelFormat() +{ +} + +void wxGLContext::SetupPalette( const wxPalette& WXUNUSED(palette) ) +{ +} + +wxPalette wxGLContext::CreateDefaultPalette() +{ + return wxNullPalette; +} + +//--------------------------------------------------------------------------- +// wxGlCanvas +//--------------------------------------------------------------------------- + +IMPLEMENT_CLASS(wxGLCanvas, wxScrolledWindow) + +BEGIN_EVENT_TABLE(wxGLCanvas, wxScrolledWindow) + EVT_SIZE(wxGLCanvas::OnSize) +END_EVENT_TABLE() + +wxGLCanvas::wxGLCanvas( wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name, + int *attribList, + const wxPalette& palette ) +{ + Create( parent, id, pos, size, style, name, attribList, palette ); +} + +bool wxGLCanvas::Create( wxWindow *parent, wxWindowID id, + const wxPoint& pos, const wxSize& size, + long style, const wxString& name, + int *attribList, + const wxPalette& palette ) +{ + if (!attribList) + { + int data[] = { GLX_RGBA, + GLX_DOUBLEBUFFER, + GLX_DEPTH_SIZE, 1, + None }; + attribList = (int*) data; + } + + Display *dpy = GDK_DISPLAY(); + + g_vi = glXChooseVisual( dpy, DefaultScreen(dpy), attribList ); + + GdkVisual *visual = gdkx_visual_get( g_vi->visualid ); + GdkColormap *colormap = gdk_colormap_new( gdkx_visual_get(g_vi->visualid), TRUE ); + + gtk_widget_push_colormap( colormap ); + gtk_widget_push_visual( visual ); + + m_glWidget = gtk_drawing_area_new(); + gtk_widget_set_events( m_glWidget, + GDK_EXPOSURE_MASK | + GDK_POINTER_MOTION_HINT_MASK | + GDK_POINTER_MOTION_MASK | + GDK_BUTTON_MOTION_MASK | + GDK_BUTTON1_MOTION_MASK | + GDK_BUTTON2_MOTION_MASK | + GDK_BUTTON3_MOTION_MASK | + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_KEY_PRESS_MASK | + GDK_KEY_RELEASE_MASK | + GDK_ENTER_NOTIFY_MASK | + GDK_LEAVE_NOTIFY_MASK ); + + gtk_widget_pop_visual(); + gtk_widget_pop_colormap(); + + wxScrolledWindow::Create( parent, id, pos, size, style, name ); + + gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), m_glWidget, 0, 0 ); + + gtk_widget_show( m_glWidget ); + + m_glContext = new wxGLContext( TRUE, this, palette ); + + XFree( g_vi ); + g_vi = (XVisualInfo*) NULL; + + return TRUE; +} + +wxGLCanvas::~wxGLCanvas() +{ + if (m_glContext) delete m_glContext; +} + +void wxGLCanvas::SwapBuffers() +{ + if (m_glContext) m_glContext->SwapBuffers(); +} + +void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event)) +{ + int width, height; + GetClientSize( &width, &height ); + if (m_glContext && GTK_WIDGET_REALIZED(m_glWidget) ) + { + SetCurrent(); + + glViewport(0, 0, (GLint)width, (GLint)height ); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 ); + glMatrixMode(GL_MODELVIEW); + } +} + +void wxGLCanvas::SetCurrent() +{ + if (m_glContext) m_glContext->SetCurrent(); +} + +void wxGLCanvas::SetColour( const char *colour ) +{ + if (m_glContext) m_glContext->SetColour( colour ); +} + +void wxGLCanvas::SetSize( int x, int y, int width, int height, int sizeFlags ) +{ + if (m_resizing) return; // I don't like recursions + m_resizing = TRUE; + + if (m_parent->m_wxwindow == NULL) // i.e. wxNotebook + { + // don't set the size for children of wxNotebook, just take the values. + m_x = x; + m_y = y; + m_width = width; + m_height = height; + } + else + { + int old_width = m_width; + int old_height = m_height; + + if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING) + { + if (x != -1) m_x = x; + if (y != -1) m_y = y; + if (width != -1) m_width = width; + if (height != -1) m_height = height; + } + else + { + m_x = x; + m_y = y; + m_width = width; + m_height = height; + } + + if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) + { + if (width == -1) m_width = 80; + } + + if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) + { + if (height == -1) m_height = 26; + } + + if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; + if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; + if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; + if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; + + wxPoint pt( m_parent->GetClientAreaOrigin() ); + gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x+pt.x, m_y+pt.y ); + + if ((old_width != m_width) || (old_height != m_height)) + { + gtk_widget_set_usize( m_widget, m_width, m_height ); + + gtk_drawing_area_size( GTK_DRAWING_AREA(m_glWidget), m_width, m_height ); + + GtkAllocation allo; + allo.x = 0; + allo.y = 0; + allo.width = m_width; + allo.height = m_height; + gtk_widget_size_allocate( m_glWidget, &allo ); + } + } + + m_sizeSet = TRUE; + + wxSizeEvent event( wxSize(m_width,m_height), GetId() ); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent( event ); + + m_resizing = FALSE; +} + +void wxGLCanvas::SetSize( int width, int height ) +{ + SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); +} + +GtkWidget *wxGLCanvas::GetConnectWidget() +{ + return m_glWidget; +} + +bool wxGLCanvas::IsOwnGtkWindow( GdkWindow *window ) +{ + return (window == m_glWidget->window); +} diff --git a/utils/glcanvas/gtk/glcanvas.h b/utils/glcanvas/gtk/glcanvas.h new file mode 100644 index 0000000000..c32e176a61 --- /dev/null +++ b/utils/glcanvas/gtk/glcanvas.h @@ -0,0 +1,119 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: glcanvas.h +// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWindows and GTK +// Author: Robert Roebling +// Modified by: +// Created: 17/8/98 +// RCS-ID: $Id$ +// Copyright: (c) Robert Roebling +// Licence: wxWindows licence +///////////////////////////////////////////////////////////////////////////// + +#ifdef __GNUG__ +#pragma interface "glcanvas.h" +#endif + +#ifndef _WX_GLCANVAS_H_ +#define _WX_GLCANVAS_H_ + +#include "wx/defs.h" +#include "wx/scrolwin.h" + +extern "C" { +#include "GL/gl.h" +#include "GL/glx.h" +#include "GL/glu.h" +} + +//--------------------------------------------------------------------------- +// classes +//--------------------------------------------------------------------------- + +class wxGLContext; +class wxGLCanvas; + +//--------------------------------------------------------------------------- +// wxGLContext +//--------------------------------------------------------------------------- + + +class wxGLContext: public wxObject +{ + DECLARE_CLASS(wxGLContext) + + public: + + wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette ); + ~wxGLContext(); + + void SetCurrent(); + void SetColour(const char *colour); + void SwapBuffers(); + + void SetupPixelFormat(); + void SetupPalette(const wxPalette& palette); + wxPalette CreateDefaultPalette(); + + inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; } + inline wxWindow* GetWindow() const { return m_window; } + inline GtkWidget* GetWidget() const { return m_widget; } + inline GLXContext GetContext() const { return m_glContext; } + + public: + + GLXContext m_glContext; + + GtkWidget *m_widget; + wxPalette m_palette; + wxWindow* m_window; +}; + +//--------------------------------------------------------------------------- +// wxGLContext +//--------------------------------------------------------------------------- + +class wxGLCanvas: public wxScrolledWindow +{ + DECLARE_CLASS(wxGLCanvas) + + public: + wxGLCanvas( wxWindow *parent, wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, const wxString& name = "GLCanvas", + int *attribList = (int*) NULL, + const wxPalette& palette = wxNullPalette ); + + bool Create( wxWindow *parent, wxWindowID id = -1, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = 0, const wxString& name = "GLCanvas", + int *attribList = (int*) NULL, + const wxPalette& palette = wxNullPalette ); + + ~wxGLCanvas(); + + void SetCurrent(); + void SetColour(const char *colour); + void SwapBuffers(); + + void OnSize(wxSizeEvent& event); + + inline wxGLContext* GetContext() const { return m_glContext; } + + // implementation + + virtual void SetSize( int x, int y, int width, int height, + int sizeFlags = wxSIZE_AUTO ); + virtual void SetSize( int width, int height ); + + virtual GtkWidget *GetConnectWidget(); + bool IsOwnGtkWindow( GdkWindow *window ); + + wxGLContext *m_glContext; + GtkWidget *m_glWidget; + + DECLARE_EVENT_TABLE() +}; + +#endif diff --git a/utils/glcanvas/samples/cube/Makefile b/utils/glcanvas/samples/cube/Makefile index f24f7eb8ef..6e852b2dd4 100644 --- a/utils/glcanvas/samples/cube/Makefile +++ b/utils/glcanvas/samples/cube/Makefile @@ -1,3 +1,16 @@ +# +# File: Makefile +# Author: Robert Roebling +# Created: 1999 +# Updated: +# Copyright: (c) 1998 Robert Roebling +# +# Makefile for OpenGl demo (GTK version) +# +# This makefile requires wxWindows/GTK to be +# installed (possibly using "make install") +# on your system. +# CC = g++ @@ -7,10 +20,10 @@ cube: cube.o glcanvas.o `wx-config --libs` -lMesaGL -lMesaGLU cube.o: cube.cpp - $(CC) `wx-config --cflags` -I../../src -c cube.cpp + $(CC) `wx-config --cflags` -I../../gtk -c cube.cpp -glcanvas.o: ../../src/glcanvas.cpp - $(CC) `wx-config --cflags` `gtk-config --cflags` -I../../src -c ../../src/glcanvas.cpp +glcanvas.o: ../../gtk/glcanvas.cpp + $(CC) `wx-config --cflags` `gtk-config --cflags` -I../../gtk -c ../../gtk/glcanvas.cpp clean: rm -f *.o cube diff --git a/utils/glcanvas/samples/isosurf/Makefile b/utils/glcanvas/samples/isosurf/Makefile index 7722db17b0..e004da7555 100644 --- a/utils/glcanvas/samples/isosurf/Makefile +++ b/utils/glcanvas/samples/isosurf/Makefile @@ -1,3 +1,16 @@ +# +# File: Makefile +# Author: Robert Roebling +# Created: 1999 +# Updated: +# Copyright: (c) 1998 Robert Roebling +# +# Makefile for OpenGl demo (GTK version) +# +# This makefile requires wxWindows/GTK to be +# installed (possibly using "make install") +# on your system. +# CC = g++ @@ -7,10 +20,10 @@ isosurf: isosurf.o glcanvas.o `wx-config --libs` -lMesaGL -lMesaGLU isosurf.o: isosurf.cpp - $(CC) `wx-config --cflags` -I../../src -c isosurf.cpp + $(CC) `wx-config --cflags` -I../../gtk -c isosurf.cpp -glcanvas.o: ../../src/glcanvas.cpp - $(CC) `wx-config --cflags` `gtk-config --cflags` -I../../src -c ../../src/glcanvas.cpp +glcanvas.o: ../..gtk/glcanvas.cpp + $(CC) `wx-config --cflags` `gtk-config --cflags` -I../../gtk -c ../../gtk/glcanvas.cpp clean: rm -f *.o cube diff --git a/utils/glcanvas/samples/penguin/Makefile b/utils/glcanvas/samples/penguin/Makefile index 013c6f0884..f874de9287 100644 --- a/utils/glcanvas/samples/penguin/Makefile +++ b/utils/glcanvas/samples/penguin/Makefile @@ -1,3 +1,16 @@ +# +# File: Makefile +# Author: Robert Roebling +# Created: 1999 +# Updated: +# Copyright: (c) 1998 Robert Roebling +# +# Makefile for OpenGL demo (GTK version) +# +# This makefile requires wxWindows/GTK to be +# installed (possibly using "make install") +# on your system. +# CPP = g++ CC = gcc diff --git a/utils/glcanvas/src/.cvsignore b/utils/glcanvas/src/.cvsignore deleted file mode 100644 index 4646a42c35..0000000000 --- a/utils/glcanvas/src/.cvsignore +++ /dev/null @@ -1,3 +0,0 @@ -Linux -linux-gnu -linux diff --git a/utils/glcanvas/src/glcanvas.cpp b/utils/glcanvas/src/glcanvas.cpp deleted file mode 100644 index 9e16370d1e..0000000000 --- a/utils/glcanvas/src/glcanvas.cpp +++ /dev/null @@ -1,312 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: glcanvas.cpp -// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWindows and GTK -// Author: Robert Roebling -// Modified by: -// Created: 17/08/98 -// RCS-ID: $Id$ -// Copyright: (c) Robert Roebling -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma implementation "glcanvas.h" -#endif - -#include "glcanvas.h" - -#include "wx/frame.h" -#include "wx/colour.h" -#include "wx/module.h" -#include "wx/app.h" - -extern "C" { -#include "gtk/gtk.h" -#include "gdk/gdk.h" -#include "gdk/gdkx.h" -} - -#include "wx/gtk/win_gtk.h" - -//--------------------------------------------------------------------------- -// global data -//--------------------------------------------------------------------------- - -XVisualInfo *g_vi = (XVisualInfo*) NULL; - -//--------------------------------------------------------------------------- -// wxGLContext -//--------------------------------------------------------------------------- - -IMPLEMENT_CLASS(wxGLContext,wxObject) - -wxGLContext::wxGLContext( bool WXUNUSED(isRGB), wxWindow *win, const wxPalette& WXUNUSED(palette) ) -{ - m_window = win; - m_widget = ((wxGLCanvas*)win)->m_glWidget; - - wxCHECK_RET( g_vi, "invalid visual for OpenGl" ); - - m_glContext = glXCreateContext( GDK_DISPLAY(), g_vi, None, GL_TRUE ); - - wxCHECK_RET( m_glContext, "Couldn't create OpenGl context" ); -} - -wxGLContext::~wxGLContext() -{ - if (!m_glContext) return; - - if (m_glContext == glXGetCurrentContext()) - { - glXMakeCurrent( GDK_DISPLAY(), None, NULL); - } - - glXDestroyContext( GDK_DISPLAY(), m_glContext ); -} - -void wxGLContext::SwapBuffers() -{ - if (m_glContext) - { - glXSwapBuffers( GDK_DISPLAY(), GDK_WINDOW_XWINDOW( m_widget->window ) ); - } -} - -void wxGLContext::SetCurrent() -{ - if (m_glContext) - { - glXMakeCurrent( GDK_DISPLAY(), GDK_WINDOW_XWINDOW(m_widget->window), m_glContext ); - } -} - -void wxGLContext::SetColour(const char *colour) -{ - float r = 0.0; - float g = 0.0; - float b = 0.0; - wxColour *col = wxTheColourDatabase->FindColour(colour); - if (col) - { - r = (float)(col->Red()/256.0); - g = (float)(col->Green()/256.0); - b = (float)(col->Blue()/256.0); - glColor3f( r, g, b); - } -} - -void wxGLContext::SetupPixelFormat() -{ -} - -void wxGLContext::SetupPalette( const wxPalette& WXUNUSED(palette) ) -{ -} - -wxPalette wxGLContext::CreateDefaultPalette() -{ - return wxNullPalette; -} - -//--------------------------------------------------------------------------- -// wxGlCanvas -//--------------------------------------------------------------------------- - -IMPLEMENT_CLASS(wxGLCanvas, wxScrolledWindow) - -BEGIN_EVENT_TABLE(wxGLCanvas, wxScrolledWindow) - EVT_SIZE(wxGLCanvas::OnSize) -END_EVENT_TABLE() - -wxGLCanvas::wxGLCanvas( wxWindow *parent, wxWindowID id, - const wxPoint& pos, const wxSize& size, - long style, const wxString& name, - int *attribList, - const wxPalette& palette ) -{ - Create( parent, id, pos, size, style, name, attribList, palette ); -} - -bool wxGLCanvas::Create( wxWindow *parent, wxWindowID id, - const wxPoint& pos, const wxSize& size, - long style, const wxString& name, - int *attribList, - const wxPalette& palette ) -{ - if (!attribList) - { - int data[] = { GLX_RGBA, - GLX_DOUBLEBUFFER, - GLX_DEPTH_SIZE, 1, - None }; - attribList = (int*) data; - } - - Display *dpy = GDK_DISPLAY(); - - g_vi = glXChooseVisual( dpy, DefaultScreen(dpy), attribList ); - - GdkVisual *visual = gdkx_visual_get( g_vi->visualid ); - GdkColormap *colormap = gdk_colormap_new( gdkx_visual_get(g_vi->visualid), TRUE ); - - gtk_widget_push_colormap( colormap ); - gtk_widget_push_visual( visual ); - - m_glWidget = gtk_drawing_area_new(); - gtk_widget_set_events( m_glWidget, - GDK_EXPOSURE_MASK | - GDK_POINTER_MOTION_HINT_MASK | - GDK_POINTER_MOTION_MASK | - GDK_BUTTON_MOTION_MASK | - GDK_BUTTON1_MOTION_MASK | - GDK_BUTTON2_MOTION_MASK | - GDK_BUTTON3_MOTION_MASK | - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_KEY_PRESS_MASK | - GDK_KEY_RELEASE_MASK | - GDK_ENTER_NOTIFY_MASK | - GDK_LEAVE_NOTIFY_MASK ); - - gtk_widget_pop_visual(); - gtk_widget_pop_colormap(); - - wxScrolledWindow::Create( parent, id, pos, size, style, name ); - - gtk_myfixed_put( GTK_MYFIXED(m_wxwindow), m_glWidget, 0, 0 ); - - gtk_widget_show( m_glWidget ); - - m_glContext = new wxGLContext( TRUE, this, palette ); - - XFree( g_vi ); - g_vi = (XVisualInfo*) NULL; - - return TRUE; -} - -wxGLCanvas::~wxGLCanvas() -{ - if (m_glContext) delete m_glContext; -} - -void wxGLCanvas::SwapBuffers() -{ - if (m_glContext) m_glContext->SwapBuffers(); -} - -void wxGLCanvas::OnSize(wxSizeEvent& WXUNUSED(event)) -{ - int width, height; - GetClientSize( &width, &height ); - if (m_glContext && GTK_WIDGET_REALIZED(m_glWidget) ) - { - SetCurrent(); - - glViewport(0, 0, (GLint)width, (GLint)height ); - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 15.0 ); - glMatrixMode(GL_MODELVIEW); - } -} - -void wxGLCanvas::SetCurrent() -{ - if (m_glContext) m_glContext->SetCurrent(); -} - -void wxGLCanvas::SetColour( const char *colour ) -{ - if (m_glContext) m_glContext->SetColour( colour ); -} - -void wxGLCanvas::SetSize( int x, int y, int width, int height, int sizeFlags ) -{ - if (m_resizing) return; // I don't like recursions - m_resizing = TRUE; - - if (m_parent->m_wxwindow == NULL) // i.e. wxNotebook - { - // don't set the size for children of wxNotebook, just take the values. - m_x = x; - m_y = y; - m_width = width; - m_height = height; - } - else - { - int old_width = m_width; - int old_height = m_height; - - if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING) - { - if (x != -1) m_x = x; - if (y != -1) m_y = y; - if (width != -1) m_width = width; - if (height != -1) m_height = height; - } - else - { - m_x = x; - m_y = y; - m_width = width; - m_height = height; - } - - if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) - { - if (width == -1) m_width = 80; - } - - if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT) - { - if (height == -1) m_height = 26; - } - - if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth; - if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight; - if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_maxWidth; - if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_maxHeight; - - wxPoint pt( m_parent->GetClientAreaOrigin() ); - gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x+pt.x, m_y+pt.y ); - - if ((old_width != m_width) || (old_height != m_height)) - { - gtk_widget_set_usize( m_widget, m_width, m_height ); - - gtk_drawing_area_size( GTK_DRAWING_AREA(m_glWidget), m_width, m_height ); - - GtkAllocation allo; - allo.x = 0; - allo.y = 0; - allo.width = m_width; - allo.height = m_height; - gtk_widget_size_allocate( m_glWidget, &allo ); - } - } - - m_sizeSet = TRUE; - - wxSizeEvent event( wxSize(m_width,m_height), GetId() ); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent( event ); - - m_resizing = FALSE; -} - -void wxGLCanvas::SetSize( int width, int height ) -{ - SetSize( -1, -1, width, height, wxSIZE_USE_EXISTING ); -} - -GtkWidget *wxGLCanvas::GetConnectWidget() -{ - return m_glWidget; -} - -bool wxGLCanvas::IsOwnGtkWindow( GdkWindow *window ) -{ - return (window == m_glWidget->window); -} diff --git a/utils/glcanvas/src/glcanvas.h b/utils/glcanvas/src/glcanvas.h deleted file mode 100644 index c32e176a61..0000000000 --- a/utils/glcanvas/src/glcanvas.h +++ /dev/null @@ -1,119 +0,0 @@ -///////////////////////////////////////////////////////////////////////////// -// Name: glcanvas.h -// Purpose: wxGLCanvas, for using OpenGL/Mesa with wxWindows and GTK -// Author: Robert Roebling -// Modified by: -// Created: 17/8/98 -// RCS-ID: $Id$ -// Copyright: (c) Robert Roebling -// Licence: wxWindows licence -///////////////////////////////////////////////////////////////////////////// - -#ifdef __GNUG__ -#pragma interface "glcanvas.h" -#endif - -#ifndef _WX_GLCANVAS_H_ -#define _WX_GLCANVAS_H_ - -#include "wx/defs.h" -#include "wx/scrolwin.h" - -extern "C" { -#include "GL/gl.h" -#include "GL/glx.h" -#include "GL/glu.h" -} - -//--------------------------------------------------------------------------- -// classes -//--------------------------------------------------------------------------- - -class wxGLContext; -class wxGLCanvas; - -//--------------------------------------------------------------------------- -// wxGLContext -//--------------------------------------------------------------------------- - - -class wxGLContext: public wxObject -{ - DECLARE_CLASS(wxGLContext) - - public: - - wxGLContext( bool isRGB, wxWindow *win, const wxPalette& palette = wxNullPalette ); - ~wxGLContext(); - - void SetCurrent(); - void SetColour(const char *colour); - void SwapBuffers(); - - void SetupPixelFormat(); - void SetupPalette(const wxPalette& palette); - wxPalette CreateDefaultPalette(); - - inline wxPalette* GetPalette() const { return (wxPalette*) & m_palette; } - inline wxWindow* GetWindow() const { return m_window; } - inline GtkWidget* GetWidget() const { return m_widget; } - inline GLXContext GetContext() const { return m_glContext; } - - public: - - GLXContext m_glContext; - - GtkWidget *m_widget; - wxPalette m_palette; - wxWindow* m_window; -}; - -//--------------------------------------------------------------------------- -// wxGLContext -//--------------------------------------------------------------------------- - -class wxGLCanvas: public wxScrolledWindow -{ - DECLARE_CLASS(wxGLCanvas) - - public: - wxGLCanvas( wxWindow *parent, wxWindowID id = -1, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, const wxString& name = "GLCanvas", - int *attribList = (int*) NULL, - const wxPalette& palette = wxNullPalette ); - - bool Create( wxWindow *parent, wxWindowID id = -1, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = 0, const wxString& name = "GLCanvas", - int *attribList = (int*) NULL, - const wxPalette& palette = wxNullPalette ); - - ~wxGLCanvas(); - - void SetCurrent(); - void SetColour(const char *colour); - void SwapBuffers(); - - void OnSize(wxSizeEvent& event); - - inline wxGLContext* GetContext() const { return m_glContext; } - - // implementation - - virtual void SetSize( int x, int y, int width, int height, - int sizeFlags = wxSIZE_AUTO ); - virtual void SetSize( int width, int height ); - - virtual GtkWidget *GetConnectWidget(); - bool IsOwnGtkWindow( GdkWindow *window ); - - wxGLContext *m_glContext; - GtkWidget *m_glWidget; - - DECLARE_EVENT_TABLE() -}; - -#endif