wxWidgets Toolbar Sample folder (+new user questions)

If you are using wxDev-C++ for your wxWidgets design, please ask your questions here instead of in IDE Related.
Post Reply
softport
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sat Jan 28, 2012 3:55 pm
Location: Houston TX
Contact:

wxWidgets Toolbar Sample folder (+new user questions)

Post by softport »

Hello, I just started using wxDev-C yesterday, and am working through Malcolm Nealon's Minimal Example.

In the section 'Adding a toolbar' it says:
"copy the bitmaps folder from the wxWidgets Toolbar Sample folder to your project folder".

I don't seem to have this sample folder in my Dev-Cpp directory. There is an Icons folder,
but it only has .ico images. Am I looking in the wrong place, or do I need to download
the Toolbar sample folder from somewhere?

thanks!


Windows XP, wxDevC++ build 7.4.1.13
Last edited by softport on Mon Jan 30, 2012 3:54 am, edited 1 time in total.
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: wxWidgets Toolbar Sample folder

Post by jgrzybowski »

I have got previous version of wxDevC++ (7.3.1.3) yet and I have found bitmaps in following folder:
C:\Program Files\Dev-Cpp\examples\wxWidgets\toolbar\bitmaps
There are some BMP and XPM files.

Any time you can use differnt bitmaps for your toolbuttons, for example PNG files like this:
http://www.famfamfam.com/lab/icons/silk

Regards
Jarek
softport
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sat Jan 28, 2012 3:55 pm
Location: Houston TX
Contact:

Re: wxWidgets Toolbar Sample folder

Post by softport »

Thanks Jarek, I guess my version does not have the \toolbar\bitmaps folder. Maybe
it was an installation option that I left unchecked.
I downloaded the 'silk' icons from your link, 100's of them in a zip file, all 16x16.

regards,
Walter
softport
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sat Jan 28, 2012 3:55 pm
Location: Houston TX
Contact:

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by softport »

Hello, today I changed the name of a button control (from the properties panel), and found
that wxDevC++ did not change the name in the project files. On compiling I got a bunch of
errors, and it took about an hour to fix them :P . Is there a proper way of changing a
control's name, so the control's name is updated automatically in all the project files?

Also found a minor quirk. If I place only one control in my frame, then compile and execute,
the single control re-sizes to fill the whole frame.


wxWidgets frame project
Windows XP, wxDev-C++ 7.4.2.259, wxWidgets 2.8.12, MingW
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by jgrzybowski »

wxDev C++ is going to change the name of control automatically only inside of code which was created also automatically (for example: void YourFrameFrm:: CreateGUIControls() and events functions like OnClick). Inside of code created manually you have to change the names manually or you can try to use Replace (Ctrl+H).

First control putted on the frame (except toolbar, status bar, menu bar) is fulfilled inside of frame. That is why many users advise to put as a first control always boxsizer. Boxsizer is used to arrange other controls inside of frame and panels (More completed info you can find on this forum looking for “sizers”).

regards
Jarek
softport
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sat Jan 28, 2012 3:55 pm
Location: Houston TX
Contact:

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by softport »

Thanks Jarek.

Today I found that, like you say, a button name change is handled automatically.
Had no problems changing the name to anything at all, and it would compile fine.
I think yesterday I was also changing the name of the button's event, to be the
same as the name of the button (with 'Click' appended at the end). I found that
wxDev-C was not automatically changing the name of the event function.

So, if I also change the name of the button's OnClick event, then whatever name
I put there will be the name of the handler function. This name must be changed
manually in both ProjectForm.h and ProjectForm.cpp. Do I have that correct, or
am missing a shortcut?

Thanks for the tip on the 'sizers'.

regards, Walter
Windows XP, wxDev-C++ 7.4.2.259, wxWidgets 2.8.12, MingW
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by jgrzybowski »

Yes, you have right, event function still have the same old name of button. But it still should by fine, because after name has been changed, ID value of button should stay the same (see in properties window), like:
Name: MyNewNameOfButton
ID: ID_MYOLDNAMEOFBUTTON

Events are defined by macros like this:
EVT_BUTTON(ID_MYOLDNAMEOFBUTTON, ProjectForm::MyOldNameOfButtonClick)

That is why your button with new name "MyNewNameOfButton" and old ID value "ID_MYOLDNAMEOFBUTTON" will generate the same event and the same event function with old name will be called. So I believe you do not have to change it manually (but you can) and we can say wxDev is handled this area automatically also.

Regards
Jarek
softport
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sat Jan 28, 2012 3:55 pm
Location: Houston TX
Contact:

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by softport »

Jarek, thanks very much for your input.

I have been trying to make a display that can be icremented/decremented
by 0.01. It looked like wxSpinCtrl would do the job, but it only seems
to increment/decrement by 1. I also had trouble formatting the text:
it would not center, and changing background and text colors would work while
editing, but it reverted to black text on white background when compiled.

So.. I am using separate wxMemo and wxSpinBtn. I am learning C++ and
wxWidgets together, so it took a while to finally get some code to do what I
needed:

void ControlsFrm::WxSpinButton1Up(wxSpinEvent& event)
{
double value;

// Convert wxMemo text to double, and store in 'value'.
(WxMemo1->GetValue()).ToDouble(&value);

// Add desired increment to 'value'
value = value + 0.01;

// Convert 'value' to string, and update display
WxMemo1->SetValue(wxString::Format(wxT("%3.2f"), value));
}

Is there a better way to do this? On this site I found 'wxSpinCtrlDouble' which
looks like just what I need, but I don't seem to have this in my controls.

regards, Walter
Windows XP, wxDev-C++ 7.4.2.259, wxWidgets 2.8.12, MingW
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by jgrzybowski »

wxDevC++ does not have any possible control from wxWidget library available in RAD (designer), but you can still use this wxSpinCtrlDouble in your project in wxDev. You need to write whole code responsible of creation wxSpinCtrlDouble manually (this time wxDev is like in typical IDE without RAD). I believe it is not so complicated, take a look inside of void YourFrameFrm:: CreateGUIControls() where is code responsible for creation other controls is your project.
Regards
Jarek
softport
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sat Jan 28, 2012 3:55 pm
Location: Houston TX
Contact:

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by softport »

Hello Jerek, here is what I tried, but it's not working yet.
In MyForm.h there is an #include <wx/spinctrl.h>. I looked in this file and didn't
see any mention of wxSpinCtrlDouble. Could this be the problem?

regards, Walter


From: http://docs.wxwidgets.org/trunk/classwx ... ouble.html,
"Constructor, creating and showing a spin control" :

wxSpinCtrlDouble (wxWindow *parent, wxWindowID id=-1, const wxString &value=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxSP_ARROW_KEYS, double min=0, double max=100, double initial=0, double inc=1, const wxString &name=wxT("wxSpinCtrlDouble"))

I put this (in Line 60) under void MySpinCtrlFrm::CreateGUIControls() :

MyWxSpinCtrlDouble = new wxSpinCtrlDouble (this, ID_MYWXSPINCTRLDOUBLE, wxT(""), wxPoint(93, 100) , wxSize(121, 22), wxSP_ARROW_KEYS, 0, 100, 0, 0.01, wxT("wxSpinCtrlDouble"));

Result 2 Errors:
(Line 60) `MyWxSpinCtrlDouble' was not declared in this scope
(Line 60) `wxSpinCtrlDouble' has not been declared


Then in MyForm.h ;
1) Added this under the control declarations (line 53): wxSpinCtrlDouble *MyWxSpinCtrlDouble;
2) In the 'enum' control ID section I added: ID_MYWXSPINCTRLDOUBLE = 1050
3) Commented out: ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values

Result 1 Error:
(Line 53) ISO C++ forbids declaration of `wxSpinCtrlDouble' with no type
Windows XP, wxDev-C++ 7.4.2.259, wxWidgets 2.8.12, MingW
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by jgrzybowski »

In general: you need to download your extra control from www and install according to the documentation and/or forum about this control. Right now your compiler is looking for declaration/definition of wxSpinCtrlDouble and can not find it in your project files. In the simplest controls you need to only add files (ExtraControl.h, ExtraControl.cpp) into your project and you need to give this information to the compiler (#include “ExtraControl.h”). Sometimes it is not enough.

But wxSpinCtrlDouble seems to be a part of wxWidget Version: 2.9.4 (it is not an extra control). I have got 2.8.9 (check your version: wxDev->Tools->Compiler Options->wxWidget) and I do not have any wxSpinCtrlDouble.

Regards
Jarek
softport
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sat Jan 28, 2012 3:55 pm
Location: Houston TX
Contact:

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by softport »

Hello Jarek,
my wxWidgets version is 2.8.12 .

I'm leaning towards not fighting this battle right now. I've spent a lot of time trying to figure
out how to add wxSinCtrlDouble, instead of learning C++. After your answer I realized
that just changing .h and cpp would probably not be enough, because the controls have
dependencies from classes higher up. I have attached a zip file I found that should include
everything necessary to have a wxSpinCtrlDouble. I was not confident enough to change
all the folders in wxCpp that it includes, so I only tried the .h and cpp. Of course it didn't
work :D .

Here is a screen shot of my first program that does something, with separate
text and spin controls:
Image

The green input controls use wxTextValidator(wxFILTER_NUMERIC, NULL) to filter
out non numeric characters. This still leaves 'commas' which I didn't want. and it
was also allowing numbers like: 332.3.5.6- with a plus/minus sign at the end.
So I added the lines below at the beginning of the user 'Enter' key event:

double bore;
// Convert text value to double, store in temp variable 'bore'
(Bore_Display->GetValue()).ToDouble(&bore);
// Convert temp variable to string, and update display
Bore_Display->SetValue(wxString::Format(wxT("%3.2f"), bore));

This filters out everything. Best would be to write my own Validator, but I'm
not quite at that level yet.

I do have a C++ question if that's ok to ask here. I made a class called 'ClassEngine',
but I was not sure where, in the project files, an object of this class should be
created. The program worked when I put the line: ClassEngine myEngine;
in MyForm.cpp just above CreateGUIControls(). Is this the correct place?
I watched some C++ videos on YouTube, where the class objects were declared
in the main() function, but we have FrmApp.cpp::OnInit() .

regards, Walter


PS I don't know if the 'zip' format is only for windows. Is there a preferred compression
program for all platforms?

Some nice videos to learn about C++ classes.
Videos 12-15, 42-49, 52-57, 60
Attachments
spinctrldouble.zip
(47.71 KiB) Downloaded 210 times
Windows XP, wxDev-C++ 7.4.2.259, wxWidgets 2.8.12, MingW
jgrzybowski
Earned some good credits
Earned some good credits
Posts: 113
Joined: Sat Sep 24, 2011 9:32 pm
Location: Poland

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by jgrzybowski »

For sure C++ issues are more complete described on other forums like C++ Development on wxWidget forum (there are several topics about wxSpinCtrlDouble:http://forums.wxwidgets.org/viewtopic.p ... CtrlDouble). I have learned from polish book (Symfonia C++), that the best solution is to create new header (NewClass.h) and definition (NewClass.cpp) file for each class. In wxDev-C++ : File->New->Source File.

I do not know is there any the most preferred compression format, zip is popular, on unix/linux can be founded tar/tar.gz formats.

Regards
Jarek
softport
Experienced Solver
Experienced Solver
Posts: 61
Joined: Sat Jan 28, 2012 3:55 pm
Location: Houston TX
Contact:

Re: wxWidgets Toolbar Sample folder (+new user questions)

Post by softport »

Jerek, thanks again for your input and patience, I'm jumping like a cricket from one
topic to another.

Just have to say that I wish I had discovered wxDevC++ years ago.

regards, Walter
Windows XP, wxDev-C++ 7.4.2.259, wxWidgets 2.8.12, MingW
Post Reply