Author Topic: Fix (or Feature?) wxSmith's identifier handler  (Read 11420 times)

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Fix (or Feature?) wxSmith's identifier handler
« on: April 07, 2010, 11:29:38 am »
Here's a video to explain this patch:http://portablecb.googlecode.com/files/wxsmith_fix_wxwidgets_id_prefix_set_failed.7z

1. You can use all the prefix is "wxID_" identifier. The wxs file like this:
Quote
<?xml version="1.0" encoding="utf-8" ?>
<wxsmith>
...
   <object class="wxFrame" name="MyWxFrame">
...
            <object class="wxButton" name="wxID_ANY" variable="Button1" member="yes">
...
            <object class="wxButton" name="wxID_ANY" variable="Button2" member="no">
...


2. If you do not select "Is member" option of choice, And use the default ID prefix, like "ID_BUTTON", it's auto set the ID to "wxID_ANY"
Code
+    if ( Item->GetPropertiesFlags() & flLocal )
+    {
+        wxString prefix = s_IdPrefix;
+        prefix << Item->GetInfo().DefaultVarName.Upper();
+        wxString curIdName = Item->GetIdName();
+        if (curIdName.Length() > prefix.Length() && curIdName.Left(prefix.Length()) == prefix)
+        {
+            Item->SetIdName(_T("wxID_ANY"));
+            if (m_Ids.find(curIdName) != m_Ids.end())
+            {
+                m_Ids.erase(curIdName);
+            }
+        }
+    }
+

EDIT:
fix a bug, the diff is show below.
Code
-        if ( m_Ids.empty() || (m_Ids.find(IdName) != m_Ids.end()) )
+        if (m_Ids.find(IdName) != m_Ids.end())
         {
             SetNewIdName(Item);
         }


[attachment deleted by admin]
« Last Edit: April 09, 2010, 12:16:14 pm by Loaden »

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: Fix (feature) wxSmith's identifier handler
« Reply #1 on: April 07, 2010, 02:53:45 pm »
Example, like this file: src\plugins\codecompletion\ccdebuginfo.h
Code
		//(*Identifiers(CCDebugInfo)
static const long ID_STATICTEXT29;
static const long ID_TEXTCTRL1;
static const long ID_BUTTON1;
static const long ID_STATICLINE1;
static const long ID_STATICTEXT17;
static const long ID_STATICTEXT18;
static const long ID_STATICTEXT1;
static const long ID_STATICTEXT2;
static const long ID_STATICTEXT9;
static const long ID_STATICTEXT10;
static const long ID_STATICTEXT11;
static const long ID_STATICTEXT12;
static const long ID_STATICTEXT3;
static const long ID_STATICTEXT4;
static const long ID_STATICTEXT5;
static const long ID_STATICTEXT6;
static const long ID_STATICTEXT7;
static const long ID_STATICTEXT8;
static const long ID_STATICTEXT36;
static const long ID_STATICTEXT37;
static const long ID_STATICTEXT40;
static const long ID_STATICTEXT41;
static const long ID_STATICTEXT13;
static const long ID_STATICTEXT14;
static const long ID_STATICTEXT15;
static const long ID_STATICTEXT16;
static const long ID_STATICTEXT32;
static const long ID_STATICTEXT33;
static const long ID_STATICTEXT38;
static const long ID_STATICTEXT39;
static const long ID_STATICTEXT19;
static const long ID_STATICTEXT20;
static const long ID_STATICTEXT22;
static const long ID_STATICTEXT24;
static const long ID_BUTTON4;
static const long ID_STATICTEXT30;
static const long ID_COMBOBOX3;
static const long ID_BUTTON5;
static const long ID_STATICTEXT21;
static const long ID_COMBOBOX2;
static const long ID_BUTTON3;
static const long ID_STATICTEXT23;
static const long ID_COMBOBOX1;
static const long ID_BUTTON2;
static const long ID_STATICTEXT25;
static const long ID_STATICTEXT26;
static const long ID_STATICTEXT27;
static const long ID_STATICTEXT28;
static const long ID_STATICTEXT34;
static const long ID_STATICTEXT35;
static const long ID_PANEL1;
static const long ID_LISTBOX1;
static const long ID_PANEL2;
static const long ID_LISTBOX2;
static const long ID_PANEL3;
static const long ID_NOTEBOOK1;
static const long ID_STATICTEXT31;
static const long ID_BUTTON6;
static const long ID_STATICLINE2;
//*)
After apply this patch, and set all control's ID to wxID_ANY, it's changed to:
Code
		//(*Identifiers(CCDebugInfo)
static const long ID_NOTEBOOK1;
//*)
And the init is:
Code
//(*IdInit(CCDebugInfo)
const long CCDebugInfo::ID_NOTEBOOK1 = wxNewId();
//*)


[attachment deleted by admin]

Offline Loaden

  • Lives here!
  • ****
  • Posts: 1014
Re: Fix (feature) wxSmith's identifier handler
« Reply #2 on: April 07, 2010, 04:41:01 pm »
More explanation about my patch for wxSmith:

Then current wxSmith, we can't use the same ID in different Controls. Even this ID is "wxID_ANY", or the IDs pre-defined by wxWidgets library such as wxID_FILE or wxID_OPEN or wxID_ABOUT.

If the ID is not a class member, the value of the ID perhaps is useless for the programmer. But the code generated by wxSmith contains some snippets to declaration, definition and initialization of these IDs.

For example, in the CodeCompletion plugins source code, there are code statement like below:

In Header:
Code
        //(*Identifiers(CCDebugInfo)
        static const long ID_NOTEBOOK1;
        //*)
In Source:
Code
//(*IdInit(CCDebugInfo)
const long CCDebugInfo::ID_NOTEBOOK1 = wxNewId();
//*)

As you know, if you have many different IDs, then there are many different unused static const variables, all these variables will take the memory space in the final executable files.

For example, in the source file:  src\plugins\codecompletion\ccdebuginfo.h There are 61 different ununsed IDs.
Code
		//(*Identifiers(CCDebugInfo)
static const long ID_STATICTEXT29;
static const long ID_TEXTCTRL1;
static const long ID_BUTTON1;
static const long ID_STATICLINE1;
static const long ID_STATICTEXT17;
static const long ID_STATICTEXT18;
static const long ID_STATICTEXT1;
static const long ID_STATICTEXT2;
static const long ID_STATICTEXT9;
static const long ID_STATICTEXT10;
static const long ID_STATICTEXT11;
static const long ID_STATICTEXT12;
static const long ID_STATICTEXT3;
static const long ID_STATICTEXT4;
static const long ID_STATICTEXT5;
static const long ID_STATICTEXT6;
static const long ID_STATICTEXT7;
static const long ID_STATICTEXT8;
static const long ID_STATICTEXT36;
static const long ID_STATICTEXT37;
static const long ID_STATICTEXT40;
static const long ID_STATICTEXT41;
static const long ID_STATICTEXT13;
static const long ID_STATICTEXT14;
static const long ID_STATICTEXT15;
static const long ID_STATICTEXT16;
static const long ID_STATICTEXT32;
static const long ID_STATICTEXT33;
static const long ID_STATICTEXT38;
static const long ID_STATICTEXT39;
static const long ID_STATICTEXT19;
static const long ID_STATICTEXT20;
static const long ID_STATICTEXT22;
static const long ID_STATICTEXT24;
static const long ID_BUTTON4;
static const long ID_STATICTEXT30;
static const long ID_COMBOBOX3;
static const long ID_BUTTON5;
static const long ID_STATICTEXT21;
static const long ID_COMBOBOX2;
static const long ID_BUTTON3;
static const long ID_STATICTEXT23;
static const long ID_COMBOBOX1;
static const long ID_BUTTON2;
static const long ID_STATICTEXT25;
static const long ID_STATICTEXT26;
static const long ID_STATICTEXT27;
static const long ID_STATICTEXT28;
static const long ID_STATICTEXT34;
static const long ID_STATICTEXT35;
static const long ID_PANEL1;
static const long ID_LISTBOX1;
static const long ID_PANEL2;
static const long ID_LISTBOX2;
static const long ID_PANEL3;
static const long ID_NOTEBOOK1;
static const long ID_STATICTEXT31;
static const long ID_BUTTON6;
static const long ID_STATICLINE2;
//*)

When applied my patch, you can merge all the different IDs to only one wxID_ANY, and there are no side effect.
In my previous post, I have attached a CCDebugInfo.7z, and you can see the new generated ccdebuginfo.h and ccdebuginfo.cpp, they are more clean and beautiful.
Code
		//(*Identifiers(CCDebugInfo)
static const long ID_NOTEBOOK1;
//*)

the rebuild CC works as before.

[attachment deleted by admin]
« Last Edit: April 07, 2010, 04:46:12 pm by Loaden »

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Fix (or Feature?) wxSmith's identifier handler
« Reply #3 on: April 07, 2010, 05:00:47 pm »
Nice work Loaden.
@byo, can you consider this? Thanks.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Fix (or Feature?) wxSmith's identifier handler
« Reply #4 on: January 09, 2011, 01:42:49 am »
This patch leads to a bug.
See this thread for details and discussion: http://forums.codeblocks.org/index.php/topic,14003.msg94113.html#msg94113

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7255
Re: Fix (or Feature?) wxSmith's identifier handler
« Reply #5 on: January 11, 2011, 05:50:25 pm »
New thread started here: http://forums.codeblocks.org/index.php/topic,14028.0.html.

Any discussion should be made there.
« Last Edit: January 11, 2011, 05:52:42 pm by jens »