From f2b7492a88eef36f26668cefff8d3f8b91e5f50e Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 8 Apr 2008 10:39:57 +0000 Subject: [PATCH] By default, align renderers as column header under GTK+, too. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53087 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dataview.h | 5 ++- include/wx/gtk/dataview.h | 2 + interface/dataview.h | 74 +++++++++++++++++------------------ samples/dataview/dataview.cpp | 4 +- src/common/datavcmn.cpp | 51 ++++++++++++------------ src/gtk/dataview.cpp | 56 ++++++++++++-------------- 6 files changed, 95 insertions(+), 97 deletions(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 4a59a5b39e..e2dec89538 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -60,8 +60,9 @@ extern WXDLLIMPEXP_DATA_ADV(const wxChar) wxDataViewCtrlNameStr[]; // the default minimal width of the columns: #define wxDVC_DEFAULT_MINWIDTH 30 -// the default alignment of wxDataViewRenderers: -#define wxDVR_DEFAULT_ALIGNMENT (wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL) +// The default alignment of wxDataViewRenderers is to take +// the alignment from the column it owns. +#define wxDVR_DEFAULT_ALIGNMENT -1 // --------------------------------------------------------- diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 4859f9dea3..52f89899c4 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -41,9 +41,11 @@ public: GtkCellRenderer* GetGtkHandle() { return m_renderer; } void GtkInitHandlers(); virtual bool GtkHasAttributes() { return false; } + void GtkUpdateAlignment(); protected: GtkCellRenderer *m_renderer; + int m_alignment; protected: DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer) diff --git a/interface/dataview.h b/interface/dataview.h index 5d651b1737..1ed5ed5829 100644 --- a/interface/dataview.h +++ b/interface/dataview.h @@ -126,35 +126,6 @@ public: */ void SetValue(const wxVariant& value); }; - - - -/** - @class wxDataViewIconTextRenderer - @wxheader{dataview.h} - - The wxDataViewIconTextRenderer class is used to display text with - a small icon next to it as it is typically done in a file manager. - This classes uses the wxDataViewIconText - helper class to store its data. wxDataViewIonText can be converted - to a from a wxVariant using the left shift - operator. - - @library{wxadv} - @category{FIXME} -*/ -class wxDataViewIconTextRenderer : public wxDataViewRenderer -{ -public: - /** - - */ - wxDataViewIconTextRenderer(const wxString& varianttype = "wxDataViewIconText", - wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT); -}; - - - /** @class wxDataViewModel @wxheader{dataview.h} @@ -1125,11 +1096,6 @@ public: wxDataViewDateRenderer. wxDataViewSpinRenderer. - Note that the @e alignment parameter is ignored under OS X and - the alignment is controlled by wxDataViewColumn::GetAlignment() - so that under OS X, column header alignment and column content - alignment are always the same and cannot be set independently. - Additionally, the user can write own renderers by deriving from wxDataViewCustomRenderer. @@ -1178,10 +1144,10 @@ public: */ wxDataViewRenderer(const wxString& varianttype, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, - int align = wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL); + int align = wxDVR_DEFAULT_ALIGNMENT ); /** - Returns the alignment. + Returns the alignment. See SetAlignment() */ virtual int GetAlignment() const; @@ -1209,7 +1175,12 @@ public: virtual wxString GetVariantType(); /** - Sets the alignment. + Sets the alignment of the renderer's content. The default value + of wxDVR_DEFAULT_ALIGMENT indicates that the content should + have the same alignment as the column header. The method is + not implemented under OS X and the renderer always aligns its + contents as the column header on that platform. The other platforms + support both vertical and horizontal alignment. */ virtual void SetAlignment( int align ); /** @@ -1263,6 +1234,35 @@ public: +/** + @class wxDataViewIconTextRenderer + @wxheader{dataview.h} + + The wxDataViewIconTextRenderer class is used to display text with + a small icon next to it as it is typically done in a file manager. + This classes uses the wxDataViewIconText + helper class to store its data. wxDataViewIonText can be converted + to a from a wxVariant using the left shift + operator. + + @library{wxadv} + @category{FIXME} +*/ +class wxDataViewIconTextRenderer : public wxDataViewRenderer +{ +public: + /** + + */ + wxDataViewIconTextRenderer(const wxString& varianttype = "wxDataViewIconText", + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, + int align = wxDVR_DEFAULT_ALIGNMENT ); +}; + + + + + /** @class wxDataViewProgressRenderer @wxheader{dataview.h} diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index c0989cca9b..8e216d8ea6 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -797,8 +797,8 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int column0->SetSortOrder( true ); #endif - tr = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE, wxALIGN_RIGHT ); - wxDataViewColumn *column1 = new wxDataViewColumn( wxT("artist"), tr, 1, 150, wxALIGN_LEFT, + tr = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE ); + wxDataViewColumn *column1 = new wxDataViewColumn( wxT("artist"), tr, 1, 150, wxALIGN_RIGHT, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE | wxDATAVIEW_COL_RESIZABLE ); m_musicCtrl->AppendColumn( column1 ); diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 63a9036656..645aa4ed0e 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -659,6 +659,7 @@ wxDataViewRendererBase::wxDataViewRendererBase( const wxString &varianttype, { m_variantType = varianttype; m_editorCtrl = NULL; + m_owner = NULL; } const wxDataViewCtrl* wxDataViewRendererBase::GetView() const @@ -771,6 +772,7 @@ void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event ) switch ( event.m_keyCode ) { case WXK_RETURN: + wxPrintf( "OnChar RETURN\n" ); m_finished = true; m_owner->FinishEditing(); break; @@ -789,6 +791,7 @@ void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event ) { if (!m_finished) { + wxPrintf( "OnKillFocus\n" ); m_finished = true; m_owner->FinishEditing(); } @@ -914,7 +917,7 @@ wxDataViewCtrlBase::AppendTextColumn( const wxString &label, unsigned int model_ wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), + new wxDataViewTextRenderer( wxT("string"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -925,7 +928,7 @@ wxDataViewCtrlBase::AppendIconTextColumn( const wxString &label, unsigned int mo wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), + new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -937,7 +940,7 @@ wxDataViewCtrlBase::AppendToggleColumn( const wxString &label, unsigned int mode { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), + new wxDataViewToggleRenderer( wxT("bool"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -948,7 +951,7 @@ wxDataViewCtrlBase::AppendProgressColumn( const wxString &label, unsigned int mo wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), + new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -959,7 +962,7 @@ wxDataViewCtrlBase::AppendDateColumn( const wxString &label, unsigned int model_ wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), + new wxDataViewDateRenderer( wxT("datetime"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -970,7 +973,7 @@ wxDataViewCtrlBase::AppendBitmapColumn( const wxString &label, unsigned int mode wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), + new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -981,7 +984,7 @@ wxDataViewCtrlBase::AppendTextColumn( const wxBitmap &label, unsigned int model_ wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), + new wxDataViewTextRenderer( wxT("string"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -992,7 +995,7 @@ wxDataViewCtrlBase::AppendIconTextColumn( const wxBitmap &label, unsigned int mo wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), + new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -1003,7 +1006,7 @@ wxDataViewCtrlBase::AppendToggleColumn( const wxBitmap &label, unsigned int mode wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), + new wxDataViewToggleRenderer( wxT("bool"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -1014,7 +1017,7 @@ wxDataViewCtrlBase::AppendProgressColumn( const wxBitmap &label, unsigned int mo wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), + new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -1025,7 +1028,7 @@ wxDataViewCtrlBase::AppendDateColumn( const wxBitmap &label, unsigned int model_ wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), + new wxDataViewDateRenderer( wxT("datetime"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -1036,7 +1039,7 @@ wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int mode wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), + new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ), model_column, width, align, flags ); AppendColumn( ret ); return ret; @@ -1047,7 +1050,7 @@ wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), + new wxDataViewTextRenderer( wxT("string"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1058,7 +1061,7 @@ wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int m wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), + new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1070,7 +1073,7 @@ wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int mod { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), + new wxDataViewToggleRenderer( wxT("bool"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1081,7 +1084,7 @@ wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int m wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), + new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1092,7 +1095,7 @@ wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), + new wxDataViewDateRenderer( wxT("datetime"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1103,7 +1106,7 @@ wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int mod wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), + new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1114,7 +1117,7 @@ wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), + new wxDataViewTextRenderer( wxT("string"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1125,7 +1128,7 @@ wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int m wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), + new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1136,7 +1139,7 @@ wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int mod wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), + new wxDataViewToggleRenderer( wxT("bool"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1147,7 +1150,7 @@ wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int m wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), + new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1158,7 +1161,7 @@ wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), + new wxDataViewDateRenderer( wxT("datetime"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; @@ -1169,7 +1172,7 @@ wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int mod wxDataViewCellMode mode, int width, wxAlignment align, int flags ) { wxDataViewColumn *ret = new wxDataViewColumn( label, - new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), + new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode ), model_column, width, align, flags ); PrependColumn( ret ); return ret; diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index d725ee6746..0ecca2c7f1 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -1468,8 +1468,21 @@ wxDataViewCellMode wxDataViewRenderer::GetMode() const return ret; } -void wxDataViewRenderer::SetAlignment( int align ) +void wxDataViewRenderer::GtkUpdateAlignment() { + int align = m_alignment; + + // query alignment from column ? + if (align == -1) + { + // None there yet + if (GetOwner() == NULL) + return; + + align = GetOwner()->GetAlignment(); + align |= wxALIGN_CENTRE_VERTICAL; + } + // horizontal alignment: gfloat xalign = 0.0; @@ -1499,40 +1512,16 @@ void wxDataViewRenderer::SetAlignment( int align ) g_value_unset( &gvalue2 ); } -int wxDataViewRenderer::GetAlignment() const +void wxDataViewRenderer::SetAlignment( int align ) { - int ret = 0; - GValue gvalue; - - // horizontal alignment: - - g_object_get( G_OBJECT(m_renderer), "xalign", &gvalue, NULL ); - float xalign = g_value_get_float( &gvalue ); - if (xalign < 0.5) - ret |= wxALIGN_LEFT; - else if (xalign == 0.5) - ret |= wxALIGN_CENTER_HORIZONTAL; - else - ret |= wxALIGN_RIGHT; - g_value_unset( &gvalue ); - - - // vertical alignment: - - g_object_get( G_OBJECT(m_renderer), "yalign", &gvalue, NULL ); - float yalign = g_value_get_float( &gvalue ); - if (yalign < 0.5) - ret |= wxALIGN_TOP; - else if (yalign == 0.5) - ret |= wxALIGN_CENTER_VERTICAL; - else - ret |= wxALIGN_BOTTOM; - g_value_unset( &gvalue ); - - return ret; + m_alignment = align; + GtkUpdateAlignment(); } - +int wxDataViewRenderer::GetAlignment() const +{ + return m_alignment; +} // --------------------------------------------------------- // wxDataViewTextRenderer @@ -2564,6 +2553,9 @@ void wxDataViewColumn::SetAlignment( wxAlignment align ) xalign = 0.5; gtk_tree_view_column_set_alignment( column, xalign ); + + if (m_renderer && m_renderer->GetAlignment() == -1) + m_renderer->GtkUpdateAlignment(); } wxAlignment wxDataViewColumn::GetAlignment() const