Author Topic: Adding extracode like members to Classes  (Read 3722 times)

Offline coeps

  • Single posting newcomer
  • *
  • Posts: 6
Adding extracode like members to Classes
« on: July 14, 2008, 10:28:33 pm »
hello everybody,

in order to implement designpatterns like MVC with code::blocks, I was trying to add some extra members to a standard headerfile. The members are a few pointers I need. For example to add a View Object.
I can not find a way to to that with wxsmith. The "extra code" goes into the cpp-file. So I can do e.g. view = new View(...);, but I can not declare the member in the header.

By the way, is there a possibility to derive a panel from wxpanel and a custom class, using the "AddPanel" dialog??

 Can someone help me please?


Thank you,

coeps

Offline byo

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 837
Re: Adding extracode like members to Classes
« Reply #1 on: July 14, 2008, 10:46:33 pm »
After you create new resource with header and source file, you can freely modify everything that's not inside wxSmith's code marks. Blocks of code which will be changed by wxSmith always start from //(* commend and always end with nearest //*) one.

Any extra code you modify outside such blocks will remain untouched - so for example if you want class other than wxPanel to be the base class, you can simply edit header file and change it to anything you want.

The only drawback is that resources generated by wxSmith are always initialized through Create() function instead of passing arguments to base class directly. This require that your new base class also offer such function and empty constructor. There's workaround for this limitation (I've used it inside HexEdit plugin which you can find somewhere on these forums) which generally works by commenting the line of code where Create function is called but it's only a workaround.

Regards
   BYO

Offline coeps

  • Single posting newcomer
  • *
  • Posts: 6
Re: Adding extracode like members to Classes
« Reply #2 on: July 15, 2008, 09:07:26 am »
Thanks,

In case someone else needs it:

1. Add wxPanel, derive it from wxPanel (do not add other classes here)
1.5 add custom argument: Xyz* xyz  (unfortunally you have to add a default value ( =0), so be careful to add the xyz when creating the object... )
1.75 Hit the OK button
2. Add other baseclasses manually in newPanel.cpp / .h
3. Comment (or better remove) the create()-call in BuildContent(...), it will come back again.... so you will do it many times...
3. Add the constructor like:   
:wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("id")), XYZ(xyz)
4. To link the new panel, create a custom widget, use the newPanel as "classname", check the "Use ""for include", add the Header in "Include file", adapt the "Creating Code" to the needed constructor, in my case: $(THIS) = new $(CLASS)($(PARENT),$(ID),$(POS),$(SIZE),my_xyz);

and finally have a nice day!!!

coeps
« Last Edit: July 15, 2008, 01:16:05 pm by coeps »

Offline byo

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 837
Re: Adding extracode like members to Classes
« Reply #3 on: July 16, 2008, 07:26:21 pm »
3. Comment (or better remove) the create()-call in BuildContent(...), it will come back again.... so you will do it many times...
3. Add the constructor like:   
:wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _T("id")), XYZ(xyz)

Hmm, If I understood your method correctly, this commenting-out is not needed,
leave that Create() - call uncommented and add the initializer list to constructor like this:
Code
  : XYZ(xyz)

Anyway if you really need to comment that Connect() function and do not want to re-comment it every change in wxSmith, here's how it can be done:

1. In the "Extra code" property of main resource item (the one for example with window's title) add code containing closing comment tag:

Code
 ... Closing comment to prevent Create() call ..
*/

Now go to place where the Create function is located and find the first wxSmith-block mark (comment starting with //(* ) over it and put opening comment tag just before it:

Code
/*
.. Comment preventing Create() call ...

Now if you don't use XRC file, make sure that all items in the resource have "Is Member" selected - that's the only drawback. And voila - the Create() call will always remain commented.

Regards
   BYO

Offline coeps

  • Single posting newcomer
  • *
  • Posts: 6
Re: Adding extracode like members to Classes
« Reply #4 on: July 16, 2008, 07:36:12 pm »
Thanks,

works

Regards,
coeps
« Last Edit: July 18, 2008, 01:34:40 pm by coeps »