Author Topic: wxSmith question Window styles  (Read 1421 times)

Offline tigerbeard

  • Almost regular
  • **
  • Posts: 189
wxSmith question Window styles
« on: February 03, 2024, 09:25:46 am »
I have a wxSmith managed wxFrame with a constructor like this
Code
MyFrame::MyFrame( wxWindow* parent, bool bNoBorder )
{
 ...
 //(*Initialze(Myframe)
 Create( parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE|wxBORDER_NONE );
 ...
}

wxSmith hardcodes the window styles  from the wxSmith property page checkbox where I can select or unselect wxBORDER_NONE. Above its selected. The selection is at compile time. The variable can only be set during window create, so i can not set it later.

How can I still use wxSmith and control the wxBORDER_NONE style by my variable "bNoBorder"?


Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: wxSmith question Window styles
« Reply #1 on: February 03, 2024, 08:30:50 pm »
How can I still use wxSmith and control the wxBORDER_NONE style by my variable "bNoBorder"?

Go to the "Resources" tab in the C::B management pane. Navigate to your frame class and click it. Scroll down, find and expand the "Style" setting. wxBORDER_NONE is one of many you can enable/disable.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5913
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: wxSmith question Window styles
« Reply #2 on: February 04, 2024, 04:39:01 am »
How can I still use wxSmith and control the wxBORDER_NONE style by my variable "bNoBorder"?

Go to the "Resources" tab in the C::B management pane. Navigate to your frame class and click it. Scroll down, find and expand the "Style" setting. wxBORDER_NONE is one of many you can enable/disable.

Hi, I think this method is "manually configure the option", and the style value is fixed(constant) after you tweak the wxSmith setting.

What tigerbeard want is a flexiable way, which means the "bool bNoBorder" should be passed to the "Create()" function call.

I don't find a better way to do that inside the wxSmith. But you can use a hack.

For example,

Code
MyFrame::MyFrame( wxWindow* parent, bool bNoBorder )
{

#define wxDEFAULT_FRAME_STYLE bNoBorder // change the wxDEFAULT_FRAME_STYLE to bNoBorder

 ...
 //(*Initialze(Myframe)
 Create( parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE );
 ...
}


Hopefully you don't use any wxDEFAULT_FRAME_STYLE in the following code in the same cpp file.

Or, you can use a better way, you can just restore the macro definition later, see this post: Temporarily overwrite a macro in C preprocessor - Stack Overflow

Hope that helps.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline cacb

  • Lives here!
  • ****
  • Posts: 536
Re: wxSmith question Window styles
« Reply #3 on: February 04, 2024, 10:15:14 am »
Another possibility is to change the style after frame creation, I don't know if it works for all styles, but here is an event handler that changes the frame style at runtime. It workes on both Windows and Linux

Code
void Uview2dFrame::OnStayOnTopCheckBoxClick(wxCommandEvent& event)
{
   int style = GetWindowStyle();
   if(event.IsChecked())SetWindowStyle(style | wxSTAY_ON_TOP);
   else                 SetWindowStyle(style & ~wxSTAY_ON_TOP);
   Refresh();
}
It could well be this is not universally working for all styles though.

Offline tigerbeard

  • Almost regular
  • **
  • Posts: 189
Re: wxSmith question Window styles
« Reply #4 on: February 04, 2024, 01:22:32 pm »
Another possibility is to change the style after frame creation, I don't know if it works for all styles,

thats why i wrote
Quote
The variable can only be set during window create, so i can not set it later.

Offline tigerbeard

  • Almost regular
  • **
  • Posts: 189
Re: wxSmith question Window styles
« Reply #5 on: February 04, 2024, 01:25:08 pm »
I don't find a better way to do that inside the wxSmith. But you can use a hack.
Code
#define wxDEFAULT_FRAME_STYLE bNoBorder // change the wxDEFAULT_FRAME_STYLE to bNoBorder
 ...
 //(*Initialze(Myframe)
 Create( parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE );

Or, you can use a better way, you can just restore the macro definition later, see this post: Temporarily overwrite a macro in C preprocessor - Stack Overflow

That is a pretty nice idea, very helpful. A you say its qute a mess but when used in rare cases and when its documented well in the code that should be fine.!
Thanks a lot