load notebook pages from dlls Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Grom
Earned a small fee
Earned a small fee
Posts: 13
Joined: Tue Feb 27, 2007 4:23 am

load notebook pages from dlls

Post by Grom » Wed Mar 14, 2007 7:26 pm

I'm making an editor type of program that has a panel on the right with a notebook on it. I want to load the different pages at runtime, preferably from DLL files (so that they can be entirely independant of the main program)

How would I go about implementing something like this?

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4170
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Wed Mar 14, 2007 8:29 pm

Do you know how to make a dynamic link library under different platform?

If yes, all you need is to create a DLL project with one exported function that will create a (note)book, and give this function some "int" parameter.
Then crteate the code for all of your panels inside the DLL, and depending on your flag parameter add the needed panels to the (note)book.

That's how I do that.

Thank you.

Grom
Earned a small fee
Earned a small fee
Posts: 13
Joined: Tue Feb 27, 2007 4:23 am

Post by Grom » Thu Mar 15, 2007 12:29 pm

how do I do an event table with a setup like this? I've extracted an entire page out to a class, and it displays fine, but I can't figure out how to get the buttons working and whatnot.

I have a function that uses a virtual create function as a basis for my pages, but it isn't a wxFrame. I like the BEGIN_EVENT_TABLE format of attaching events, but if something else will get the buttons/sliders active I'll gladly use that.

tim.ebenezer
Earned a small fee
Earned a small fee
Posts: 19
Joined: Sun Feb 18, 2007 11:45 pm

Post by tim.ebenezer » Thu Mar 15, 2007 1:56 pm

The best way I've found to do this is to have each page as a class of wxWindow and declare the event table within that (exported through the DLL).
Hope this helps,
Tim
--
iBook G4 - OS X 10.4 - wxMac 2.8.0 - Compiling for Universal - g++

Toshiba Portege - 1.4 Ghz Centrino - Windows XP - wxMSW 2.8.0 - mingw

Grom
Earned a small fee
Earned a small fee
Posts: 13
Joined: Tue Feb 27, 2007 4:23 am

Post by Grom » Thu Mar 15, 2007 4:25 pm

can anyone share some example code? I'm trying to do it but it doesn't seem to work, where do I declare the event table? Right now I have a separate .h & .cpp of a class (not exported to DLL yet) that builds the notebook page succesfully but doesnt register events.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4170
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Post by ONEEYEMAN » Thu Mar 15, 2007 6:46 pm

Grom,
What event are you trying to catch in your page?
You can probably create your own class derived from wxPanel, and catch you event there, or just use a Connect() function to assign the event to the page.

Just look at the "event" sample....

Thank you.

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Fri Mar 16, 2007 1:33 pm

Hi!
If I understood you correctly you want to create a GUI with a wxNotebook in it. The notebook content, namely the panels for the pages, should be created in plugin DLLs, as well as the "action handling".

Doing something like that can be a bit troublesome...
The first problem you'll run into is RTTI. When linking both, application and DLL, statically with wxWidgets, you can't "share" RTTI classinfos. Using a DLL build of wxWidgets might be the easiest way to circumvent this.

However, it can be done. I created a small example app that does something like you want it. It's not perfect, but it should do the job. There is one "bug", or better, problem though: When using a wxButton in the plugin in Debug mode you will get a debug message from wxWidgets complaining about the button not having a wxTopLevelWindow parent when wxButton::UnsetTmpdefault() (losing focus is guess) is called. The problem here is in fact RTTI as I mentioned before. The button does have a proper parent. In release builds this warning does not show up. Anyway, I'll attach the sources and a compiled binary to try.

Check the Wiki pages. There are some references on creating plugins, but unfortunately some don't work with newer wxWidgets versions.

Hope this helps a bit.
Attachments
wxPlugin.zip
Small example of how to implement a plugin system with wxWidgets (static linking)
(2.07 MiB) Downloaded 316 times
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

Grom
Earned a small fee
Earned a small fee
Posts: 13
Joined: Tue Feb 27, 2007 4:23 am

Post by Grom » Fri Mar 16, 2007 4:20 pm

wow thank you very much!

Grom
Earned a small fee
Earned a small fee
Posts: 13
Joined: Tue Feb 27, 2007 4:23 am

Post by Grom » Sat Mar 17, 2007 1:11 am

it works well except for two slight issues. 1: the background of the panel doesn't get drawn for some reason. 2: I can't for the life of me get events to connect and work.

Grom
Earned a small fee
Earned a small fee
Posts: 13
Joined: Tue Feb 27, 2007 4:23 am

Post by Grom » Sun Mar 18, 2007 11:39 am

nothing I try seems to work. I tried to set the background color of the panel, it still isn't getting drawn (dragging windows over it leaves a trail). The events from within the panel just will not connect! I've tried every possible combination of things to connect it to and all that, it will not do it! ARGH!

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Mon Mar 19, 2007 8:08 am

Hi!
Hmm... for me this works nicely, but I would have expected that there may be problems.
What is you setup? wxVersion?

I tried this using 2.8.0, multi-lib release/debug build, statically linked C-runtime. Both, host and plugin, are linked statically with the wxWidgets libs.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

User avatar
T-Rex
Moderator
Moderator
Posts: 1195
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex » Mon Mar 19, 2007 8:21 am

upCASE, I already noticed this problem here:
http://forums.wxwidgets.org/viewtopic.p ... sc&start=0
and we got no solution

Screenshot (after resizing the window):
http://rapidshare.com/files/21745807/wx ... r.jpg.html

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Mon Mar 19, 2007 9:53 am

Confirmed, you're right...
Sorry for neglecting the obvious. Maybe I was too keen and focusing on presenting a solution. As it turns out this obviously doesn't work properly...

But, damn, I'm not willing to give up on this. There has to be a way. :)
Right now I'm trying a different approach. I'll keep you posted.
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Mon Mar 19, 2007 2:36 pm

Hi!
Well, my "other" solution seems not to work either. Guess I'll have to try something different...
Meanwhile I tried the old solution and removed the notebook. When adding the panel directly into a box sizer on the frame, it seems to work and redraws are correct.

I guess using a DLL build and dynamic linking to the c-runtime would really be the easiest solution. But then again I like the challenge :)
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

User avatar
T-Rex
Moderator
Moderator
Posts: 1195
Joined: Sat Oct 23, 2004 9:58 am
Location: Zaporizhzhya, Ukraine
Contact:

Post by T-Rex » Mon Mar 19, 2007 2:51 pm

It would be nice to make it work with wxAUI because my previous test project which uses wxAUI has the same problem.
When adding the panel directly into a box sizer on the frame, it seems to work and redraws are correct
Does it work with wxFlatNotebook? It seems that wxFlatNotebook uses sizer for displaying tabs and it is possible that controls loaded from DLL and placed into wxFlatNotebook will work correctly.

Also, as far as I remember, your sample (as well as my project), does not work when compiling with MinGW.

Post Reply