Sunday, August 15, 2010

Playing with the UI

Again, before doing anything on the UI side, I highly recommend adding this to your .gdbinit :
This GDB macro prints all size & position of a window and all its children.
Making a UI component without a SRC file is quite tricky - there's just too many things to be careful about. How does a src file actually look like?
It's basically a lot of text with the IDs of the UI components in it, and also the positions/sizes and hierarchy in it. You can open any .src file to get a feel of it, or look the one made here for the AnimationTabPage and the StyleSheetEffectPane:
Once this is correctly written, making your UI components should only contain of giving the actual code these IDs.
- Take a notepad (actual papir + pen)
- Sketch how you'd like the UI to look
- Invent the coordinates in which ever way so they are rounded to integers
- Put that sizes, positions and hierarchy into the src file
- Make sure you give the root component the size of your sketch, cause all the other ones will be stretched according to that one, and the root one will be dependent on the container size
- Add the constants used in the src file, to a hrc file
- Include the hrc file in your cxx file
- *Very important*: don't forget to add your .src file to the makefile. No error will be detected (everything's in the hrc!) , but the UI will not work. At all.
- Put all the UI control variables as a private members of your class, e.g. PushButton a, ListBox b, etc.
- in the ctor of your UI class, initialize all of those variables, only with a parent and a ResId. Be careful which ResId you use - if the hrc/src are in the SD code, use SdResId. If they are in SVX code, you have to use SvxResId or nothing will work, and no errors will be detected.
- Add a delete for each of these variables in the destructor

If you make everything nicely and nothing is displayed, try this:
- override a Paint() method from the Window class, and put a breakpoint there, or at the end of ctor (anywhere inside the UI class might work as well)
- call the printWindow script on the UI component (this)
- If all the sizes/positions are (0,0), it is very likely that your ResId isn't found and the control are just given default (zero) sizes & positions. Check where your ResIds are and use the appropriate resource manager. Check for double instances of the IDs.

Some components have to be displayed by explicitly calling Show() on them.
Dialogs have to be Execute() -ed so they would show. One handy thing about dialogs is that they are not deleted once a user closes them, so you can still gather the data from the dialog.

Making the UI is definitely the most painful point of the OOo...except for the build system, of course.
Good luck!

No comments:

Post a Comment