Implemented run-time checks for the GTK version

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30870 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2004-12-05 23:03:09 +00:00
parent d7b995a497
commit 77f706726c
8 changed files with 420 additions and 334 deletions

View File

@@ -202,7 +202,7 @@ static GdkPixbuf *CreateStockIcon(const char *stockid, GtkIconSize size)
GTK_STATE_NORMAL, size, NULL, NULL);
}
#if GTK_CHECK_VERSION(2,4,0)
#ifdef __WXGTK24__
static GdkPixbuf *CreateThemeIcon(const char *iconname,
GtkIconSize iconsize, const wxSize& sz)
{
@@ -218,7 +218,7 @@ static GdkPixbuf *CreateThemeIcon(const char *iconname,
size.x,
(GtkIconLookupFlags)0, NULL);
}
#endif // GTK+ >= 2.4.0
#endif
wxBitmap wxGTK2ArtProvider::CreateBitmap(const wxArtID& id,
const wxArtClient& client,
@@ -235,9 +235,12 @@ wxBitmap wxGTK2ArtProvider::CreateBitmap(const wxArtID& id,
GdkPixbuf *pixbuf = CreateStockIcon(stockid, stocksize);
#if GTK_CHECK_VERSION(2,4,0)
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
if (!pixbuf)
pixbuf = CreateThemeIcon(stockid, stocksize, size);
}
#endif
if (pixbuf && size != wxDefaultSize &&

View File

@@ -127,13 +127,18 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
else if (HasFlag(wxBU_BOTTOM))
y_alignment = 1.0;
#if GTK_CHECK_VERSION(2,4,0)
#if __WXGTK24__
if (!gtk_check_version(2,4,0))
{
gtk_button_set_alignment(GTK_BUTTON(m_widget), x_alignment, y_alignment);
#else
}
else
#endif
{
if (GTK_IS_MISC(BUTTON_CHILD(m_widget)))
gtk_misc_set_alignment (GTK_MISC (BUTTON_CHILD (m_widget)),
x_alignment, y_alignment);
#endif
}
SetLabel(label);

View File

@@ -141,6 +141,8 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
wildCard, style, pos, true )
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
m_needParent = FALSE;
m_destroyed_by_delete = FALSE;
@@ -192,49 +194,58 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
SetWildcard(wildCard);
SetFilterIndex(0);
#else
wxGenericFileDialog::Create( parent, message, defaultDir, defaultFileName, wildCard, style, pos );
}
else
#endif
wxGenericFileDialog::Create( parent, message, defaultDir, defaultFileName, wildCard, style, pos );
}
wxFileDialog::~wxFileDialog()
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
if (m_destroyed_by_delete)
m_widget = NULL;
}
#endif
}
void wxFileDialog::OnFakeOk( wxCommandEvent &event )
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
wxDialog::OnOK( event );
#else
wxGenericFileDialog::OnListOk( event );
else
#endif
wxGenericFileDialog::OnListOk( event );
}
int wxFileDialog::ShowModal()
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
return wxDialog::ShowModal();
#else
return wxGenericFileDialog::ShowModal();
else
#endif
return wxGenericFileDialog::ShowModal();
}
bool wxFileDialog::Show( bool show )
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
return wxDialog::Show( show );
#else
return wxGenericFileDialog::Show( show );
else
#endif
return wxGenericFileDialog::Show( show );
}
void wxFileDialog::GetFilenames(wxArrayString& files) const
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
GetPaths(files);
for (size_t n = 0; n < files.GetCount(); n++ )
{
@@ -247,14 +258,17 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const
}
files[n] = name;
}
#else
wxGenericFileDialog::GetFilenames( files );
}
else
#endif
wxGenericFileDialog::GetFilenames( files );
}
void wxFileDialog::GetPaths(wxArrayString& paths) const
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
paths.Empty();
if (GetWindowStyle() & wxMULTIPLE)
{
@@ -275,24 +289,30 @@ void wxFileDialog::GetPaths(wxArrayString& paths) const
{
paths.Add(m_fileName);
}
#else
wxGenericFileDialog::GetPaths( paths );
}
else
#endif
wxGenericFileDialog::GetPaths( paths );
}
void wxFileDialog::SetMessage(const wxString& message)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
m_message = message;
SetTitle(message);
#else
wxGenericFileDialog::SetMessage( message );
}
else
#endif
wxGenericFileDialog::SetMessage( message );
}
void wxFileDialog::SetPath(const wxString& path)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
if (path.empty()) return;
wxFileName fn(path);
@@ -300,41 +320,49 @@ void wxFileDialog::SetPath(const wxString& path)
m_dir = fn.GetPath();
m_fileName = fn.GetFullName();
UpdateDialog();
#else
wxGenericFileDialog::SetPath( path );
}
else
#endif
wxGenericFileDialog::SetPath( path );
}
void wxFileDialog::SetDirectory(const wxString& dir)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
if (wxDirExists(dir))
{
m_dir = dir;
m_path = wxFileName(m_dir, m_fileName).GetFullPath();
UpdateDialog();
}
#else
wxGenericFileDialog::SetDirectory( dir );
}
else
#endif
wxGenericFileDialog::SetDirectory( dir );
}
void wxFileDialog::SetFilename(const wxString& name)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
m_fileName = name;
m_path = wxFileName(m_dir, m_fileName).GetFullPath();
UpdateDialog();
#else
wxGenericFileDialog::SetFilename( name );
}
else
#endif
wxGenericFileDialog::SetFilename( name );
}
void wxFileDialog::SetWildcard(const wxString& wildCard)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
m_wildCard = wildCard;
GtkFileChooser* chooser = GTK_FILE_CHOOSER(m_widget);
// empty current filter list:
@@ -374,14 +402,17 @@ void wxFileDialog::SetWildcard(const wxString& wildCard)
gtk_file_chooser_add_filter(chooser, filter);
}
}
#else
wxGenericFileDialog::SetWildcard( wildCard );
}
else
#endif
wxGenericFileDialog::SetWildcard( wildCard );
}
void wxFileDialog::SetFilterIndex(int filterIndex)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
m_filterIndex = filterIndex;
GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget);
@@ -400,9 +431,10 @@ void wxFileDialog::SetFilterIndex(int filterIndex)
fnode = fnode->next;
}
g_slist_free(filters);
#else
wxGenericFileDialog::SetFilterIndex( filterIndex );
}
else
#endif
wxGenericFileDialog::SetFilterIndex( filterIndex );
}
void wxFileDialog::UpdateDialog()

View File

@@ -487,16 +487,19 @@ bool wxTextCtrl::Create( wxWindow *parent,
gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text), GTK_JUSTIFY_CENTER );
// Left justify (alignment) is the default and we don't need to apply GTK_JUSTIFY_LEFT
}
// gtk_entry_set_alignment was introduced in gtk+-2.3.5
#if GTK_CHECK_VERSION(2, 3, 5)
else
{
#ifdef __WXGTK24__
// gtk_entry_set_alignment was introduced in gtk+-2.3.5
if (!gtk_check_version(2,4,0))
{
if (style & wxTE_RIGHT)
gtk_entry_set_alignment( GTK_ENTRY(m_text), 1.0 );
else if (style & wxTE_CENTRE)
gtk_entry_set_alignment( GTK_ENTRY(m_text), 0.5 );
}
#endif // gtk+-2.3.5
#endif
}
#endif // __WXGTK20__
// We want to be notified about text changes.

View File

@@ -202,7 +202,7 @@ static GdkPixbuf *CreateStockIcon(const char *stockid, GtkIconSize size)
GTK_STATE_NORMAL, size, NULL, NULL);
}
#if GTK_CHECK_VERSION(2,4,0)
#ifdef __WXGTK24__
static GdkPixbuf *CreateThemeIcon(const char *iconname,
GtkIconSize iconsize, const wxSize& sz)
{
@@ -218,7 +218,7 @@ static GdkPixbuf *CreateThemeIcon(const char *iconname,
size.x,
(GtkIconLookupFlags)0, NULL);
}
#endif // GTK+ >= 2.4.0
#endif
wxBitmap wxGTK2ArtProvider::CreateBitmap(const wxArtID& id,
const wxArtClient& client,
@@ -235,9 +235,12 @@ wxBitmap wxGTK2ArtProvider::CreateBitmap(const wxArtID& id,
GdkPixbuf *pixbuf = CreateStockIcon(stockid, stocksize);
#if GTK_CHECK_VERSION(2,4,0)
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
if (!pixbuf)
pixbuf = CreateThemeIcon(stockid, stocksize, size);
}
#endif
if (pixbuf && size != wxDefaultSize &&

View File

@@ -127,13 +127,18 @@ bool wxButton::Create( wxWindow *parent, wxWindowID id, const wxString &label,
else if (HasFlag(wxBU_BOTTOM))
y_alignment = 1.0;
#if GTK_CHECK_VERSION(2,4,0)
#if __WXGTK24__
if (!gtk_check_version(2,4,0))
{
gtk_button_set_alignment(GTK_BUTTON(m_widget), x_alignment, y_alignment);
#else
}
else
#endif
{
if (GTK_IS_MISC(BUTTON_CHILD(m_widget)))
gtk_misc_set_alignment (GTK_MISC (BUTTON_CHILD (m_widget)),
x_alignment, y_alignment);
#endif
}
SetLabel(label);

View File

@@ -141,6 +141,8 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
wildCard, style, pos, true )
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
m_needParent = FALSE;
m_destroyed_by_delete = FALSE;
@@ -192,49 +194,58 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
SetWildcard(wildCard);
SetFilterIndex(0);
#else
wxGenericFileDialog::Create( parent, message, defaultDir, defaultFileName, wildCard, style, pos );
}
else
#endif
wxGenericFileDialog::Create( parent, message, defaultDir, defaultFileName, wildCard, style, pos );
}
wxFileDialog::~wxFileDialog()
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
if (m_destroyed_by_delete)
m_widget = NULL;
}
#endif
}
void wxFileDialog::OnFakeOk( wxCommandEvent &event )
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
wxDialog::OnOK( event );
#else
wxGenericFileDialog::OnListOk( event );
else
#endif
wxGenericFileDialog::OnListOk( event );
}
int wxFileDialog::ShowModal()
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
return wxDialog::ShowModal();
#else
return wxGenericFileDialog::ShowModal();
else
#endif
return wxGenericFileDialog::ShowModal();
}
bool wxFileDialog::Show( bool show )
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
return wxDialog::Show( show );
#else
return wxGenericFileDialog::Show( show );
else
#endif
return wxGenericFileDialog::Show( show );
}
void wxFileDialog::GetFilenames(wxArrayString& files) const
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
GetPaths(files);
for (size_t n = 0; n < files.GetCount(); n++ )
{
@@ -247,14 +258,17 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const
}
files[n] = name;
}
#else
wxGenericFileDialog::GetFilenames( files );
}
else
#endif
wxGenericFileDialog::GetFilenames( files );
}
void wxFileDialog::GetPaths(wxArrayString& paths) const
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
paths.Empty();
if (GetWindowStyle() & wxMULTIPLE)
{
@@ -275,24 +289,30 @@ void wxFileDialog::GetPaths(wxArrayString& paths) const
{
paths.Add(m_fileName);
}
#else
wxGenericFileDialog::GetPaths( paths );
}
else
#endif
wxGenericFileDialog::GetPaths( paths );
}
void wxFileDialog::SetMessage(const wxString& message)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
m_message = message;
SetTitle(message);
#else
wxGenericFileDialog::SetMessage( message );
}
else
#endif
wxGenericFileDialog::SetMessage( message );
}
void wxFileDialog::SetPath(const wxString& path)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
if (path.empty()) return;
wxFileName fn(path);
@@ -300,41 +320,49 @@ void wxFileDialog::SetPath(const wxString& path)
m_dir = fn.GetPath();
m_fileName = fn.GetFullName();
UpdateDialog();
#else
wxGenericFileDialog::SetPath( path );
}
else
#endif
wxGenericFileDialog::SetPath( path );
}
void wxFileDialog::SetDirectory(const wxString& dir)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
if (wxDirExists(dir))
{
m_dir = dir;
m_path = wxFileName(m_dir, m_fileName).GetFullPath();
UpdateDialog();
}
#else
wxGenericFileDialog::SetDirectory( dir );
}
else
#endif
wxGenericFileDialog::SetDirectory( dir );
}
void wxFileDialog::SetFilename(const wxString& name)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
m_fileName = name;
m_path = wxFileName(m_dir, m_fileName).GetFullPath();
UpdateDialog();
#else
wxGenericFileDialog::SetFilename( name );
}
else
#endif
wxGenericFileDialog::SetFilename( name );
}
void wxFileDialog::SetWildcard(const wxString& wildCard)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
m_wildCard = wildCard;
GtkFileChooser* chooser = GTK_FILE_CHOOSER(m_widget);
// empty current filter list:
@@ -374,14 +402,17 @@ void wxFileDialog::SetWildcard(const wxString& wildCard)
gtk_file_chooser_add_filter(chooser, filter);
}
}
#else
wxGenericFileDialog::SetWildcard( wildCard );
}
else
#endif
wxGenericFileDialog::SetWildcard( wildCard );
}
void wxFileDialog::SetFilterIndex(int filterIndex)
{
#ifdef __WXGTK24__
if (!gtk_check_version(2,4,0))
{
m_filterIndex = filterIndex;
GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget);
@@ -400,9 +431,10 @@ void wxFileDialog::SetFilterIndex(int filterIndex)
fnode = fnode->next;
}
g_slist_free(filters);
#else
wxGenericFileDialog::SetFilterIndex( filterIndex );
}
else
#endif
wxGenericFileDialog::SetFilterIndex( filterIndex );
}
void wxFileDialog::UpdateDialog()

View File

@@ -487,16 +487,19 @@ bool wxTextCtrl::Create( wxWindow *parent,
gtk_text_view_set_justification( GTK_TEXT_VIEW(m_text), GTK_JUSTIFY_CENTER );
// Left justify (alignment) is the default and we don't need to apply GTK_JUSTIFY_LEFT
}
// gtk_entry_set_alignment was introduced in gtk+-2.3.5
#if GTK_CHECK_VERSION(2, 3, 5)
else
{
#ifdef __WXGTK24__
// gtk_entry_set_alignment was introduced in gtk+-2.3.5
if (!gtk_check_version(2,4,0))
{
if (style & wxTE_RIGHT)
gtk_entry_set_alignment( GTK_ENTRY(m_text), 1.0 );
else if (style & wxTE_CENTRE)
gtk_entry_set_alignment( GTK_ENTRY(m_text), 0.5 );
}
#endif // gtk+-2.3.5
#endif
}
#endif // __WXGTK20__
// We want to be notified about text changes.