]> git.saurik.com Git - wxWidgets.git/commitdiff
Add "inherit" to <font> XRC tag.
authorVadim Zeitlin <vadim@wxwidgets.org>
Fri, 28 Sep 2012 23:48:34 +0000 (23:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Fri, 28 Sep 2012 23:48:34 +0000 (23:48 +0000)
This allows to construct a font based on the parent window font instead of
either fully specifying all font parameters or basing it on a standard font.

Closes #14632.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72572 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
docs/doxygen/overviews/xrc_format.h
include/wx/xrc/xmlres.h
samples/xrc/rc/controls.xrc
src/xrc/xh_listc.cpp
src/xrc/xmlres.cpp

index 1c45e52d1d72651a0e9a1c98187a855f149a4ba9..c2ed7071b705ce63f357938611f9391305be915c 100644 (file)
@@ -557,6 +557,7 @@ All (GUI):
 - Fix text origin and extent computations in wxSVGFileDC (Neil Chittenden).
 - Show tooltips for the too long items in generic wxTreeCtrl (Steven Houchins).
 - Add wxStyledTextCtrl::AnnotationClearLine() (sentieshar).
+- Add "inherit" to <font> XRC tag (Steffen Olszewski, Gero Meßsysteme GmbH).
 
 wxGTK:
 
index eb9f73e49b6400aa0c29ad0862e7bfaad759d03e..84e60f92fbf03161741d13804c1b03b94f2e2df5 100644 (file)
@@ -402,7 +402,8 @@ Examples:
 
 XRC uses similar, but more flexible, abstract description of fonts to that
 used by wxFont class. A font can be described either in terms of its elementary
-properties, or it can be derived from one of system fonts.
+properties, or it can be derived from one of system fonts or the parent window
+font.
 
 The font property element is "composite" element: unlike majority of
 properties, it doesn't have text value but contains several child elements
@@ -413,7 +414,8 @@ and can be one of the following "sub-properties":
 @hdr3col{property, type, description}
 @row3col{size, unsigned integer,
     Pixel size of the font (default: wxNORMAL_FONT's size or @c sysfont's
-    size if the @c sysfont property is used.}
+    size if the @c sysfont property is used or the current size of the font
+    of the enclosing control if the @c inherit property is used.}
 @row3col{style, enum,
     One of "normal", "italic" or "slant" (default: normal).}
 @row3col{weight, enum,
@@ -431,14 +433,18 @@ and can be one of the following "sub-properties":
     (default: unspecified).}
 @row3col{sysfont, ,
     Symbolic name of system standard font(one of wxSYS_*_FONT constants).}
+@row3col{inherit, @ref overview_xrcformat_type_bool,
+    If true, the font of the enclosing control is used. If this property and the
+    @c sysfont property are specified the @c sysfont property takes precedence.}
 @row3col{relativesize, float,
-    Float, font size relative to chosen system font's size; can only be
-    used when 'sysfont' is used and when 'size' is not used.}
+    Float, font size relative to chosen system font's or inherited font's size;
+    can only be used when 'sysfont' or 'inherit' is used and when 'size' is not
+    used.}
 @endTable
 
 All of them are optional, if they are missing, appropriate wxFont default is
-used. If the @c sysfont property is used, then the defaults are taken from it
-instead.
+used. If the @c sysfont or @c inherit property is used, then the defaults are
+taken from it instead.
 
 Examples:
 @code
@@ -456,6 +462,10 @@ Examples:
 </font>
 @endcode
 
+@note You cannot use @c inherit for a font that gets used before the enclosing
+      control is created, e.g. if the control gets the font passed as parameter
+      for its constructor, or if the control is not derived from wxWindow.
+
 
 @section overview_xrcformat_windows Controls and Windows
 
index 1d226c11afa5c99f6e5ece5171813b8dfed99a28..07a5b90251f3979e6a110986de1deb60fa74e7ef 100644 (file)
@@ -594,7 +594,7 @@ protected:
 #endif
 
     // Gets a font.
-    wxFont GetFont(const wxString& param = wxT("font"));
+    wxFont GetFont(const wxString& param = wxT("font"), wxWindow* parent = NULL);
 
     // Gets the value of a boolean attribute (only "0" and "1" are valid values)
     bool GetBoolAttr(const wxString& attr, bool defaultv);
index 0a7306146e692be680351fe5429488a80dd4709d..b14bade14eb656050c7bc9713775867e3a6ba23a 100644 (file)
@@ -934,18 +934,63 @@ lay them out using wxSizers, absolute positioning, everything you like!
                 <object class="choicebookpage">
                     <label>wxStaticText</label>
                     <object class="wxPanel" name="statictext">
+                        <font>
+                            <size>12</size>
+                        </font>
                         <object class="wxFlexGridSizer">
-                            <cols>1</cols>
+                            <cols>2</cols>
                             <rows>0</rows>
                             <vgap>0</vgap>
                             <hgap>0</hgap>
-                            <growablecols>0</growablecols>
-                            <growablerows>0</growablerows>
+                            <growablecols>0,1</growablecols>
+                            <growablerows>0,1,2</growablerows>
                             <object class="sizeritem">
-                                <flag>wxALIGN_CENTRE|wxALL</flag>
+                                <flag>wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxALL</flag>
+                                <border>5</border>
+                                <object class="wxStaticText" name="wxID_STATIC">
+                                    <label>Default font:</label>
+                                </object>
+                            </object>
+                            <object class="sizeritem">
+                                <flag>wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL</flag>
+                                <border>5</border>
+                                <object class="wxStaticText" name="controls_statictext">
+                                    <label>It was a dark and stormy night.</label>
+                                </object>
+                            </object>
+                            <object class="sizeritem">
+                                <flag>wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxALL</flag>
+                                <border>5</border>
+                                <object class="wxStaticText" name="wxID_STATIC">
+                                    <label>Default constructed bold font:</label>
+                                </object>
+                            </object>
+                            <object class="sizeritem">
+                                <flag>wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL</flag>
+                                <border>5</border>
+                                <object class="wxStaticText" name="controls_statictext">
+                                    <label>It was a dark and stormy night.</label>
+                                    <font>
+                                      <weight>bold</weight>
+                                    </font>
+                                </object>
+                            </object>
+                            <object class="sizeritem">
+                                <flag>wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxALL</flag>
+                                <border>5</border>
+                                <object class="wxStaticText" name="wxID_STATIC">
+                                    <label>Inheritance constructed bold font:</label>
+                                </object>
+                            </object>
+                            <object class="sizeritem">
+                                <flag>wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL</flag>
                                 <border>5</border>
                                 <object class="wxStaticText" name="controls_statictext">
                                     <label>It was a dark and stormy night.</label>
+                                    <font>
+                                      <inherit>1</inherit>
+                                      <weight>bold</weight>
+                                    </font>
                                 </object>
                             </object>
                         </object>
index acce070d341d53ab3ebd7335f355ebd242bbc909..b9a9c2d059770f14566770cf307fab173ba12cb9 100644 (file)
@@ -150,7 +150,7 @@ void wxListCtrlXmlHandler::HandleListItem()
     if (HasParam(wxT("data")))
         item.SetData(GetLong(wxT("data")));
     if (HasParam(wxT("font")))
-        item.SetFont(GetFont());
+        item.SetFont(GetFont(wxT("font"), list));
     if (HasParam(wxT("state")))
         item.SetState(GetStyle(wxT("state")));
     if (HasParam(wxT("textcolour")))
index f39611943ba5a22b655ab71c436695283281c60f..8e41d39e5eaa7594ca18981e60e9e3b1bc28b216 100644 (file)
@@ -2201,7 +2201,7 @@ static wxFont GetSystemFont(const wxString& name)
     return wxNullFont;
 }
 
-wxFont wxXmlResourceHandler::GetFont(const wxString& param)
+wxFont wxXmlResourceHandler::GetFont(const wxString& param, wxWindow* parent)
 {
     wxXmlNode *font_node = GetParamNode(param);
     if (font_node == NULL)
@@ -2304,8 +2304,21 @@ wxFont wxXmlResourceHandler::GetFont(const wxString& param)
     }
 #endif // wxUSE_FONTMAP
 
+    wxFont font;
+
     // is this font based on a system font?
-    wxFont font = GetSystemFont(GetParamValue(wxT("sysfont")));
+    if (HasParam(wxT("sysfont")))
+    {
+        font = GetSystemFont(GetParamValue(wxT("sysfont")));
+    }
+    // or should the font of the widget be used?
+    else if (GetBool(wxT("inherit"), false))
+    {
+        if (parent)
+            font = parent->GetFont();
+        else
+            ReportError("no parent window specified to derive the font from");
+    }
 
     if (font.IsOk())
     {
@@ -2368,9 +2381,9 @@ void wxXmlResourceHandler::SetupWindow(wxWindow *wnd)
         wnd->SetToolTip(GetText(wxT("tooltip")));
 #endif
     if (HasParam(wxT("font")))
-        wnd->SetFont(GetFont(wxT("font")));
+        wnd->SetFont(GetFont(wxT("font"), wnd));
     if (HasParam(wxT("ownfont")))
-        wnd->SetOwnFont(GetFont(wxT("ownfont")));
+        wnd->SetOwnFont(GetFont(wxT("ownfont"), wnd));
     if (HasParam(wxT("help")))
         wnd->SetHelpText(GetText(wxT("help")));
 }