3

I play with Eclipse + wxWidgets + wxFormBuilder

I use wxFormBuilder for GUI-design. It generates 2 classes: first is base class; second inherits first to implement functionality like button clicks. But both of this files are regenerated every time I have changes in wxFormBuilder.

I wonder how to add some code to inherited class. For example, I have listbox, button and menu item. I want to do same action (add some string to listbox) when user presses button or selects menu item. For this reason I want to implement common function 'action'. I'll call this functuion in button and menu item handlers. Where I should declare this function and its implementation to avoid erasing manual code?

Thanks.

fat
  • 6,435
  • 5
  • 44
  • 70

2 Answers2

4

wxFormbuilder has the ability to generate a derived class for you. Located under Tools->Generate Inherited Class.

This code is only generated when you invoke this tool, so most probably only once. It is derived from the automatically generated class. You use this class and can implement your stuff inside of it.

So, the usual workflow is like this:

  • build your frame/panel in formbuilder
  • generate inherited class
  • implement your handling code in inherited class
  • make changes to form/panel in wxFormbuilder -> will only affect generated class, not inherited class
LiMuBei
  • 2,868
  • 22
  • 27
  • Thanks for reply. You described exact way I use to work with wxFormBuilder. Unfortunately, every time I generate inherited class, it refresh its content. Handling code inside inherited class is untoched, **but** all manually added functions are gone. – fat Nov 24 '11 at 13:30
  • There's two different functionalities in wxFormBuilder: generate code and generate inherited class. The latter you only use once and implement your own handling code there. The first one is what you do when you made changes to the form. So what exactly are you doing? – LiMuBei Nov 24 '11 at 13:34
  • I fully agree with you. But what if I dicide to add button to form? I generate 'general' class. There is no my code, it's ok. But I want to write some code as a reaction on button press. I add handler name in wxFormBuilder. And now I need to regenerate files of inhereted class. This operation will clear all my manually added functions, includes, global variables from inhereted class. Main frame of program is quite big and I cannot design it at one iteration at beginning. – fat Nov 24 '11 at 14:07
  • Now I get what you mean. That scenario is indeed a bit suboptimal to solve. I think it comes down to adding the needed code bits to your modified inhereted class manually. At least, that's what I do. – LiMuBei Nov 24 '11 at 17:23
  • Finally, I decided to write my own genetator of inherited class. It's not very complitated after all. **step1** grab all virtual funtions in base header **step2** grab all functions from inherited class **step3** check if all functions of base class has ancestors in inherited class **step4** if some of base funcs does not have ansestors, appen it to header and source files. This operation works delicate to preserve manually entered code. – fat Nov 25 '11 at 11:51
0

There is my own code generator for wxFormBuilder inherited classes which preserves manual code wxFUp455

fat
  • 6,435
  • 5
  • 44
  • 70