lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] A validating schema for wxxrc?


From: Greg Chicares
Subject: [lmi] A validating schema for wxxrc?
Date: Fri, 08 Jun 2007 01:24:24 +0000
User-agent: Thunderbird 1.5.0.10 (Windows/20070221)

Recently, off the list, we were chatting about designing a schema
to validate wxxrc files; it seems good to continue the discussion
here. Apparently this isn't entirely simple because the format is
extensible--wxxrc files can refer to user-defined subclasses of
wx controls, e.g.

  <object class="MyClassDerivedFrom_wxButton" name="my_button">

but perhaps that could be accommodated well by making the schema
itself extensible. That idea leads me to wonder what other kinds
of extensibility might be valuable and appropriate.

When I make a mistake, I ask:

 - how could I have detected it before committing it?

 - how could I have detected it automatically, with little
     thought or effort?

Let me simulate one of the actual mistakes I've made more than
once, as though I were proposing a defective patch to a file in
wx-2.8.3 .

  wxWidgets-2.8.3/samples/xrc/rc/menu.xrc

25     <object class="wxMenu" name="basic_demos_menu">
26         <label>_Basic</label>
27         <help>Basic techniques with XRC</help>
28          <object class="wxMenuItem" 
name="non_derived_dialog_tool_or_menuitem">
29             <label>_Non-Derived Dialog Example</label>
30             <bitmap>basicdlg.xpm</bitmap>
31             <help>The basic instance of wxDialog loaded via XRC</help>
32         </object>

Consider this incorrect patch:

-          <object class="wxMenuItem" 
name="non_derived_dialog_tool_or_menuitem">
+          <object class="wxMenuItem" 
name="non_derived_dialog_tool_or_menu_item">

Now, because of the incorrect extra "_" between "menu" and "item",
it no longer matches this code:

myframe.cpp:    EVT_MENU(XRCID("non_derived_dialog_tool_or_menuitem"), 
MyFrame::OnNonDerivedDialogToolOrMenuCommand)

The damaged '.xrc' file is still well-formed xml. And it's still
well-formed wxxrc xml, too. A generic wxxrc validator can't
possibly find this mistake.

Yet it's incorrect in the context of the program it's used with.
And lmi has a list of names, which the C++ program could print
to some sort of schema-extension file. Even if feasible, a schema
may not be the best place for this: it may be better to do it
entirely in C++. I don't know; I'm just trying to understand the
range of possibilities.

Here's another example, using the same file:

-             <bitmap>basicdlg.xpm</bitmap>
+             <bitmap>basicdlg.XPM</bitmap>

Suppose that such an X pixmap exists, and its name is all lowercase.
Maybe it works under msw (just a guess), but won't under GNU/Linux.
Or suppose it were misspelled as, say, 'basicdlg.xmp': that's a typo
of which I know I'm capable.

Here's an example of a few things that I guess would be caught at
runtime, if someone actually loads this particular dialog, but which
might be better to catch in a schema:

  wxWidgets-2.8.3/samples/xrc/rc/derivdlg.xrc

37                 <object class="sizeritem">
38                     <flag>wxALIGN_CENTRE|wxALL</flag>
39                     <border>5</border>
40                     <object class="wxCheckBox" name="my_checkbox">
41                         <label>Enable listbox</label>
42                     </object>
43                 </object>

Let me mangle that:

                 <Objekt Klass="WxSizerItem">
                     <flag>WxALIGN_IN_THE_CENTRE|wxBCE</flag>
                     <border>cinq</border>
                     <objet classe="wxChequeBox" nom="my_checkbox">

I guess I don't often make mistakes like that, and I find them
soon enough; but a schema would probably find them sooner, if I
routinely used it before committing any wxxrc file.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]