#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/app.h>
#include "wxSmith1App.h"
//(*Headers(wxSmith1Dialog)
#include <wx/button.h>
#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/statline.h>
#include <wx/stattext.h>
//*)
class wxSmith1Dialog: public wxDialog
{
public:
wxSmith1Dialog(wxWindow* parent,wxWindowID id = -1);
virtual ~wxSmith1Dialog();
private:
//(*Handlers(wxSmith1Dialog)
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
//*)
//(*Identifiers(wxSmith1Dialog)
static const long ID_STATICTEXT1;
static const long ID_BUTTON1;
static const long ID_STATICLINE1;
static const long ID_BUTTON2;
//*)
//(*Declarations(wxSmith1Dialog)
wxBoxSizer* BoxSizer1;
wxStaticText* StaticText1;
wxBoxSizer* BoxSizer2;
wxButton* Button1;
wxStaticLine* StaticLine1;
wxButton* Button2;
//*)
DECLARE_EVENT_TABLE()
};
#include "wxSmith1App.h"
//(*Headers(wxSmith1Dialog)
#include <wx/dialog.h>
class wxButton;
class wxBoxSizer;
class wxStaticText;
class wxStaticLine;
class wxCommandEvent;
//*)
class wxSmith1Dialog: public wxDialog
{
public:
wxSmith1Dialog(wxWindow* parent,wxWindowID id = -1);
virtual ~wxSmith1Dialog();
private:
//(*Handlers(wxSmith1Dialog)
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
//*)
//(*Identifiers(wxSmith1Dialog)
static const long ID_STATICTEXT1;
static const long ID_BUTTON1;
static const long ID_STATICLINE1;
static const long ID_BUTTON2;
//*)
//(*Declarations(wxSmith1Dialog)
wxBoxSizer* BoxSizer1;
wxStaticText* StaticText1;
wxBoxSizer* BoxSizer2;
wxButton* Button1;
wxStaticLine* StaticLine1;
wxButton* Button2;
//*)
DECLARE_EVENT_TABLE()
};
#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif
#ifdef __BORLANDC__
#pragma hdrstop
#endif //__BORLANDC__
#include "wxSmith1Main.h"
//helper functions
enum wxbuildinfoformat {
short_f, long_f };
wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);
if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif
#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}
return wxbuild;
}
//(*InternalHeaders(wxSmith1Dialog)
#include <wx/bitmap.h>
#include <wx/font.h>
#include <wx/fontenum.h>
#include <wx/fontmap.h>
#include <wx/image.h>
#include <wx/intl.h>
#include <wx/settings.h>
//*)
//(*IdInit(wxSmith1Dialog)
const long wxSmith1Dialog::ID_STATICTEXT1 = wxNewId();
const long wxSmith1Dialog::ID_BUTTON1 = wxNewId();
const long wxSmith1Dialog::ID_STATICLINE1 = wxNewId();
const long wxSmith1Dialog::ID_BUTTON2 = wxNewId();
//*)
BEGIN_EVENT_TABLE(wxSmith1Dialog,wxDialog)
//(*EventTable(wxSmith1Dialog)
//*)
END_EVENT_TABLE()
wxSmith1Dialog::wxSmith1Dialog(wxWindow* parent,wxWindowID id)
{
//(*Initialize(wxSmith1Dialog)
Create(parent,id,_("wxWidgets app"),wxDefaultPosition,wxDefaultSize,wxDEFAULT_DIALOG_STYLE,_T("wxDialog"));
BoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
StaticText1 = new wxStaticText(this,ID_STATICTEXT1,_("Welcome to\nwxWidgets"),wxDefaultPosition,wxDefaultSize,0,_T("ID_STATICTEXT1"));
wxFont StaticText1Font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
if ( !StaticText1Font.Ok() ) StaticText1Font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
StaticText1Font.SetPointSize(20);
StaticText1->SetFont(StaticText1Font);
BoxSizer1->Add(StaticText1,1,wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL,10);
BoxSizer2 = new wxBoxSizer(wxVERTICAL);
Button1 = new wxButton(this,ID_BUTTON1,_("About"),wxDefaultPosition,wxDefaultSize,0,wxDefaultValidator,_T("ID_BUTTON1"));
BoxSizer2->Add(Button1,1,wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL,4);
StaticLine1 = new wxStaticLine(this,ID_STATICLINE1,wxDefaultPosition,wxSize(10,-1),wxLI_HORIZONTAL,_T("ID_STATICLINE1"));
BoxSizer2->Add(StaticLine1,0,wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL,4);
Button2 = new wxButton(this,ID_BUTTON2,_("Quit"),wxDefaultPosition,wxDefaultSize,0,wxDefaultValidator,_T("ID_BUTTON2"));
BoxSizer2->Add(Button2,1,wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL,4);
BoxSizer1->Add(BoxSizer2,0,wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL,4);
SetSizer(BoxSizer1);
BoxSizer1->Fit(this);
BoxSizer1->SetSizeHints(this);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxSmith1Dialog::OnAbout);
Connect(ID_BUTTON2,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&wxSmith1Dialog::OnQuit);
//*)
}
wxSmith1Dialog::~wxSmith1Dialog()
{
//(*Destroy(wxSmith1Dialog)
//*)
}
void wxSmith1Dialog::OnQuit(wxCommandEvent& event)
{
Close();
}
void wxSmith1Dialog::OnAbout(wxCommandEvent& event)
{
wxString msg = wxbuildinfo(long_f);
wxMessageBox(msg, _("Welcome to..."));
}
Remark : I never got the choice to say in I want pch or not !!!
Question : is that _BORLANDC_ pragma really needed. I just looks and feels plain ugly ?
- do NOT use NULL, that's not standard C/C++ ==> the correct value is : 0
This is something where wxSmith also is not doing the best it could do: I nthe header file it is including a bunch of headers which are not needed at that point, forward declaration are sufficient. Those headers are only needed at the cpp.
- first of all all headers should be included at the top, not first some code and then some headers.
Finally bringing in wx/intl.h (_T()), but still no wxString. So in this example not all needed headers are included !!!
#ifdef WX_PRECOMP
#include "wx_pch.h"
#else
// include here all headers you need and that in the pch case would be brought in by the wx_pch.h (and hope this never changes in the future (extension is ok, but reduction not)
#endif
// include here all other wx headers needed but that are not delivered by wx_pch.h [so they get included always: pch and non-pch]
- I didn't check the rest of the code, but 1 thing I already noticed was no header included for wxMessageBox, so the include of <wx/utils.h> should be added otherwise wcode
As said, the name of my project was wxSmith1, all previous 4 generated files are CamelCase, only this one is NOT.Not a problem. It followed previous scheme used for class wizard (all file names lower case).
Once again I would like to stress : please use headers and there includes correctly. You get less dependencies and better portable code [most of the tie for example if the linux build is broken in CB it is due to incorrect header inclusions]. So this is extremely important.
Aside of that : wxSmith rules !!!
Correct, my mistake.
Quote
- I didn't check the rest of the code, but 1 thing I already noticed was no header included for wxMessageBox, so the include of <wx/utils.h> should be added otherwise wcode
Actually, here it would be <wx/msgdlg.h> Wink
I just created a new wxWidgets project and choose wxSmith as the gui builder. I choose the dialog based app.
On linux !
Unfortunately it doesn't compile, probably doesn't know where the headers are, seems this is not dealed with by the wizard ??
[Edit] : fixed : I can build now my build options needed to be changed to `wx-config-2.8 --cflags` --> append of -2.8
Remark : I never got the choice to say in I want pch or not !!!
Question : is that _BORLANDC_ pragma really needed. I just looks and feels plain ugly ?
EDIT : I would suggest to get rid of that _BORLANDC_ thing, since CB code is purely targeted for GCC. And I really wonder if Borland still needs such an ugly beast.
EDIT : I would suggest to get rid of that _BORLANDC_ thing, since CB code is purely targeted for GCC. And I really wonder if Borland still needs such an ugly beast.
Is it written anywhere? Or am I missing anything?
If you are talking about compiling C::B's code with Borland C++ 5.5 compiler, then you may remove that pragma. BCC 5.5 can't compile Squirrel.
It'll work with wxSmith. But NOT when you'll be using it without wxSmith.
Edit 1: @Byo, Thanks for the update. :) But the problem is wxSmith adds the necessary headers whereas without wxSmith the wizard generated codes become blind.
@Biplab : don't get me wrong, I am not putting anything or anyone down.
I had tried the wizard on windows, where I get a lot of choices (like #wx). So in linux I did similar. Now I didn't get that choice although I had set up that global variable correctly. So nothing compiled.
By looking into the project options I saw the wx-config and then with some help of other people we saw that in the wx284 package we installed on OpenSuse it's called wx-config-2.8. Did you notice the
- don't include pch headers in a header file, which was what happened !!!
- other includes were missing (never depend on a.h including b.h, be clear, if you use wxString --> include wxString.h, I don't think a user should start checking if wx/intl.h includes wxstring.h).
You know our wizards work, wxSmith does splendid things, and if then the code that comes out of it is clean and good C++, then we have something very beautiful.
Sorry for that :oops:. I don't know what I've done wrong but I also tested all three options for GUI designer and it compiled and run fine, I must have committed wrong script. Again sorry for the inconvenience.
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
as said, I would suggest to be explicit and not just wx.h.
Things are clearer to the user also, he knows which headers are in play, and no need to search wx.h for which header it could be. Less surprises if certainly a header get's kicked out of wx.h. Hopefully this won't happen but you never know with these wx guys.
And secondly if you don't use pch, wx.h is bringing way to many things into play and will slow down compilation.
The problem is you've removed the following linesQuote#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
Now wx.h includes a number of commonly used headers. So if it's not there, we've to include <wx/frame.h>, <wx/button.h>, etc for all the classes we want to use. There lies the problem. :)
Another point. It seems that you've removed _BORLANDC_ preprocessor directive and the associated pragma.
#ifndef WX_PCH_H_INCLUDED
#define WX_PCH_H_INCLUDED
// basic wxWidgets headers
#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#ifdef WX_PRECOMP
// put here all your rarely-changing header files
#endif // WX_PRECOMP
#endif // WX_PCH_H_INCLUDED
Hmm, I was just wondering - there's this _BORLANDC_ stuff inside wx_pch.h file:
So it should work correctly. And it really cleans the source. Maybe with one exception: the "// put here all your rarely-changing header files" content should be placed before _BORLANDC_ stuff to cache rarely-changing project headers too. The only problem with wxSmith is that this "wx_pch.h" is not included for newly created resources but I'll probably try to detect such file and add it automatically.
#include "the pch header"
#ifndef CB_PRECOMP
blablabla
#endif
more blablabla
But AFAIK, newer BCC (Turbo C++ Explorer 2006's compiler) supports PCH creation using a Header file. So that bad hack is necessary only for BCC 5.5.
So, support BorlandC : yes or no. CB sources itself *only* support gcc, so in CB sources that Borland stuff is ready to go out of the door.
Bye bye BCC5.5 ;-)
When a user is creating a bigger project starting from the wizards code, it can happen he wants to to pch stuff with his code, well that's the users choice, I feel that the code generated from our wizards should NOT take that into account. We can not, and should not, predict all possible uses or ideas a user might have in mind.
Turbo package is full of S**t. You've to install the whole IDE + .NET SDK 1.1 to get the compiler working for you.
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "wx_pch.h"
#ifndef WX_PRECOMP
// Include headers that are inside pch, may be even #include <wx/wx.h>
#endif
// Include headers that are not inside pch
#ifndef WX_PCH_H_INCLUDED
#define WX_PCH_H_INCLUDED
// basic wxWidgets headers
#include <wx/wxprec.h>
#ifdef WX_PRECOMP
// put here all your rarely-changing header files
#endif // WX_PRECOMP
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#endif // WX_PCH_H_INCLUDED
#ifdef WX_PRECOMP
#include "wx_pch.h"
#endif
That would be a nice change. :)
I'll update the Non-wxSmith generated sources without <wx/wx.h> header. I believe that would make the PCH file smaller and the build be faster, too.
#include "wx/wxprec.h"and then it compiles again.
I think we have a little problem.
On linux there's no wx_pch.h, or I am not finding it.
I replace it by :Quote#include "wx/wxprec.h"and then it compiles again.
I think we have a little problem.
On linux there's no wx_pch.h, or I am not finding it.
I replace it by :Quote#include "wx/wxprec.h"and then it compiles again.
We need to check the wizard in Linux, too. :)
Including "wx/wxprec.h" would kill the benefits and cleanliness that you and Byo have proposed. But for a temporary fix, it can be used. :D
For unix-based wizard there's "wxWidgets Library Settings" with two options:
- Use default wxWidgets configuration
- Use Advanced Options
In the first mode all extra options (including pch) are disabled. But "Create Empty Project" and "Create and use precompiled header (PCH)" should also be enabled since it should be possible to create both empty and pch-enabled project even when default wx settings are used.
are you saying linux builds have to use pch ?