]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxPGCell::SetFont() and GetFont(); Documented wxPGCell class.
authorJaakko Salli <jaakko.salli@dnainternet.net>
Thu, 15 Oct 2009 14:41:00 +0000 (14:41 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Thu, 15 Oct 2009 14:41:00 +0000 (14:41 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62412 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/property.h
interface/wx/propgrid/property.h
samples/propgrid/propgrid.cpp
src/propgrid/editors.cpp
src/propgrid/property.cpp

index ca40fb77658ffe5ba0a99948e6ef1a83e0effb42..b585a68823778e0a194477af6cb1f14e15f89e4d 100644 (file)
@@ -137,14 +137,28 @@ public:
                           wxPGProperty* property,
                           const wxPGEditor* editor ) const;
 
-    /** Utility to render cell bitmap and set text colour plus bg brush colour.
+    /** Utility to render cell bitmap and set text colour plus bg brush
+        colour.
 
-        Returns image width that, for instance, can be passed to DrawText.
+        @return Returns image width, which, for instance, can be passed to
+                DrawText.
     */
     int PreDrawCell( wxDC& dc,
                      const wxRect& rect,
                      const wxPGCell& cell,
                      int flags ) const;
+
+    /**
+        Utility to be called after drawing is done, to revert whatever
+        changes PreDrawCell() did.
+
+        @param flags
+            Same as those passed to PreDrawCell().
+    */
+    void PostDrawCell( wxDC& dc,
+                       const wxPropertyGrid* propGrid,
+                       const wxPGCell& cell,
+                       int flags ) const;
 };
 
 
@@ -162,6 +176,7 @@ public:
     void SetBitmap( const wxBitmap& bitmap ) { m_bitmap = bitmap; }
     void SetFgCol( const wxColour& col ) { m_fgCol = col; }
     void SetBgCol( const wxColour& col ) { m_bgCol = col; }
+    void SetFont( const wxFont& font ) { m_font = font; }
 
 protected:
     virtual ~wxPGCellData() { }
@@ -170,14 +185,16 @@ protected:
     wxBitmap    m_bitmap;
     wxColour    m_fgCol;
     wxColour    m_bgCol;
+    wxFont      m_font;
 
     // True if m_text is valid and specified
     bool        m_hasValidText;
 };
 
-/** @class wxPGCell
+/**
+    @class wxPGCell
 
-    Base class for simple wxPropertyGrid cell information.
+    Base class for wxPropertyGrid cell information.
 */
 class WXDLLIMPEXP_PROPGRID wxPGCell : public wxObject
 {
@@ -218,11 +235,32 @@ public:
     void SetText( const wxString& text );
     void SetBitmap( const wxBitmap& bitmap );
     void SetFgCol( const wxColour& col );
+
+    /**
+        Sets font of the cell.
+
+        @remarks Because wxPropertyGrid does not support rows of
+                 different height, it makes little sense to change
+                 size of the font. Therefore it is recommended
+                 to use return value of wxPropertyGrid::GetFont()
+                 or wxPropertyGrid::GetCaptionFont() as a basis
+                 for the font that, after modifications, is passed
+                 to this member function.
+    */
+    void SetFont( const wxFont& font );
+
     void SetBgCol( const wxColour& col );
 
     const wxString& GetText() const { return GetData()->m_text; }
     const wxBitmap& GetBitmap() const { return GetData()->m_bitmap; }
     const wxColour& GetFgCol() const { return GetData()->m_fgCol; }
+
+    /**
+        Returns font of the cell. If no specific font is set for this
+        cell, then the font will be invalid.
+    */
+    const wxFont& GetFont() const { return GetData()->m_font; }
+
     const wxColour& GetBgCol() const { return GetData()->m_bgCol; }
 
     wxPGCell& operator=( const wxPGCell& other )
index fb4c7bb7b843138f17a9e2df1f093dea7b20c49e..25a8b394968549b39cfcfe22969d41d0239030dd 100644 (file)
@@ -1505,6 +1505,73 @@ public:
 };
 
 
+/**
+    @class wxPGCell
+
+    Base class for wxPropertyGrid cell information.
+
+    @library{wxpropgrid}
+    @category{propgrid}
+*/
+class wxPGCell : public wxObject
+{
+public:
+    wxPGCell();
+    wxPGCell(const wxPGCell& other);
+    wxPGCell( const wxString& text,
+              const wxBitmap& bitmap = wxNullBitmap,
+              const wxColour& fgCol = wxNullColour,
+              const wxColour& bgCol = wxNullColour );
+
+    virtual ~wxPGCell();
+
+    const wxPGCellData* GetData() const;
+
+    /**
+        Returns @true if this cell has custom text stored within.
+    */
+    bool HasText() const;
+
+    /**
+        Merges valid data from srcCell into this.
+    */
+    void MergeFrom( const wxPGCell& srcCell );
+
+    void SetText( const wxString& text );
+    void SetBitmap( const wxBitmap& bitmap );
+    void SetFgCol( const wxColour& col );
+
+    /**
+        Sets font of the cell.
+
+        @remarks Because wxPropertyGrid does not support rows of
+                 different height, it makes little sense to change
+                 size of the font. Therefore it is recommended
+                 to use return value of wxPropertyGrid::GetFont()
+                 or wxPropertyGrid::GetCaptionFont() as a basis
+                 for the font that, after modifications, is passed
+                 to this member function.
+    */
+    void SetFont( const wxFont& font );
+
+    void SetBgCol( const wxColour& col );
+
+    const wxString& GetText() const;
+    const wxBitmap& GetBitmap() const;
+    const wxColour& GetFgCol() const;
+
+    /**
+        Returns font of the cell. If no specific font is set for this
+        cell, then the font will be invalid.
+    */
+    const wxFont& GetFont() const;
+
+    const wxColour& GetBgCol() const;
+
+    wxPGCell& operator=( const wxPGCell& other );
+};
+
+
 /**
     @class wxPGChoices
 
@@ -1522,7 +1589,7 @@ public:
     @library{wxpropgrid}
     @category{propgrid}
 */
-class WXDLLIMPEXP_PROPGRID wxPGChoices
+class wxPGChoices
 {
 public:
     typedef long ValArrItem;
index 98286772bb91a028e8f17643938277625480fb9f..251e2e5b65d09fb216664a54e76e2451605d8ef9 100644 (file)
@@ -1793,9 +1793,19 @@ void FormMain::PopulateWithLibraryConfig ()
 
     wxPGProperty* pid;
 
+    wxFont italicFont = pgman->GetGrid()->GetCaptionFont();
+    italicFont.SetStyle(wxFONTSTYLE_ITALIC);
+
+    wxString italicFontHelp = "Font of this property's wxPGCell has "
+                              "been modified. Obtain property's cell "
+                              "with wxPGProperty::"
+                              "GetOrCreateCell(column).";
+
 #define ADD_WX_LIB_CONF_GROUP(A) \
     cat = pg->AppendIn( pid, new wxPropertyCategory(A) ); \
-    pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp );
+    pg->SetPropertyCell( cat, 0, wxPG_LABEL, bmp ); \
+    cat->GetCell(0).SetFont(italicFont); \
+    cat->SetHelpString(italicFontHelp);
 
 #define ADD_WX_LIB_CONF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)((A>0)?true:false)));
 #define ADD_WX_LIB_CONF_NODEF(A) pg->Append( new wxBoolProperty(wxT(#A),wxPG_LABEL,(bool)false) ); \
index 100209eed2292de7cc3d1b63fbae66c52e7b9f79..9f6d5a5a3d892ea670959b8b90426824b65e2b84 100644 (file)
@@ -682,6 +682,9 @@ void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox* pCb,
     if ( pDc )
         pDc->SetBrush(*wxWHITE_BRUSH);
 
+    wxPGCellRenderer* renderer = NULL;
+    const wxPGChoiceEntry* cell = NULL;
+
     if ( rect.x >= 0 )
     {
         //
@@ -750,11 +753,13 @@ void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox* pCb,
 
             if ( choices.IsOk() && item >= 0 && comValIndex < 0 )
             {
-                const wxPGChoiceEntry& cell = choices.Item(item);
-                wxPGCellRenderer* renderer = wxPGGlobalVars->m_defaultRenderer;
-                int imageOffset = renderer->PreDrawCell( dc, rect, cell, renderFlags );
+                cell = &choices.Item(item);
+                renderer = wxPGGlobalVars->m_defaultRenderer;
+                int imageOffset = renderer->PreDrawCell(dc, rect, *cell,
+                                                        renderFlags );
                 if ( imageOffset )
-                    imageOffset += wxCC_CUSTOM_IMAGE_MARGIN1 + wxCC_CUSTOM_IMAGE_MARGIN2;
+                    imageOffset += wxCC_CUSTOM_IMAGE_MARGIN1 +
+                                   wxCC_CUSTOM_IMAGE_MARGIN2;
                 pt.x += imageOffset;
             }
         }
@@ -768,6 +773,9 @@ void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox* pCb,
         pt.x += 1;
 
         dc.DrawText( text, pt.x + wxPG_XBEFORETEXT, pt.y );
+
+        if ( renderer )
+            renderer->PostDrawCell(dc, this, *cell, renderFlags);
     }
     else
     {
index 5c789adc78596d73b081b058d88d608caec3675a..6f1dc5408effc54038fb1b7b355c89e78cd7afa8 100644 (file)
@@ -149,6 +149,11 @@ int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell&
     if ( !(flags & (Control|ChoicePopup)) )
         dc.DrawRectangle(rect);
 
+    // Use cell font, if provided
+    const wxFont& font = cell.GetFont();
+    if ( font.IsOk() )
+        dc.SetFont(font);
+
     const wxBitmap& bmp = cell.GetBitmap();
     if ( bmp.Ok() &&
         // Do not draw oversized bitmap outside choice popup
@@ -165,6 +170,17 @@ int wxPGCellRenderer::PreDrawCell( wxDC& dc, const wxRect& rect, const wxPGCell&
     return imageWidth;
 }
 
+void wxPGCellRenderer::PostDrawCell( wxDC& dc,
+                                     const wxPropertyGrid* propGrid,
+                                     const wxPGCell& cell,
+                                     int WXUNUSED(flags) ) const
+{
+    // Revert font
+    const wxFont& font = cell.GetFont();
+    if ( font.IsOk() )
+        dc.SetFont(propGrid->GetFont());
+}
+
 // -----------------------------------------------------------------------
 // wxPGDefaultRenderer
 // -----------------------------------------------------------------------
@@ -276,6 +292,8 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
                                       propertyGrid->GetFontHeight()+(wxPG_CAPRECTYMARGIN*2) );
         }
     }
+
+    PostDrawCell(dc, propertyGrid, *cell, preDrawFlags);
 }
 
 wxSize wxPGDefaultRenderer::GetImageSize( const wxPGProperty* property,
@@ -362,6 +380,13 @@ void wxPGCell::SetFgCol( const wxColour& col )
     GetData()->SetFgCol(col);
 }
 
+void wxPGCell::SetFont( const wxFont& font )
+{
+    AllocExclusive();
+
+    GetData()->SetFont(font);
+}
+
 void wxPGCell::SetBgCol( const wxColour& col )
 {
     AllocExclusive();