Author Topic: wxGenericStaticBitmap  (Read 11231 times)

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
wxGenericStaticBitmap
« on: October 10, 2017, 01:57:18 am »
I see in the documentation for wxStaticBitmap in the wxWidgets Manual that there are operating systems where this can only be used for 64x64 pixel icons. It is a much larger image I seek to display. So to avoid potential trouble I seek to use wxGenericStaticBitmap as is recommended in that documentation. In Code::Blocks I see in the Standard tab the icon for wxStaticBitmap. I am not able to find a similar icon for wxGenericStaticBitmap in any of the tabs.

What is the best way to get wxGenericStaticBitmap on a form?

Will this have to be manually coded?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: wxGenericStaticBitmap
« Reply #1 on: October 10, 2017, 07:07:05 am »
There is button for custom controls. It could be used for controls we've not added to wxsmith. Otherwise you could try to add this control to the plugin and provide a patch.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: wxGenericStaticBitmap
« Reply #2 on: October 10, 2017, 09:42:22 pm »
I found a custom icon with the silhouette of a head, and a question mark on its chest. When I drag into the wxStaticBoxSizer I see a dark field with three question marks in it.

I would very much appreciate links to any information on how to use this.
« Last Edit: October 11, 2017, 09:50:14 pm by spflanze »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: wxGenericStaticBitmap
« Reply #3 on: October 11, 2017, 01:11:47 am »
You insert this custom control. Then you set the "class name" property from the left side to your class (wxStaticBitmap).  Then you can use this element like a normal wxSmith element. You can search for youtube videos how to use them...


Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: wxGenericStaticBitmap
« Reply #4 on: October 11, 2017, 11:09:18 pm »
I inserted the custom control. But instead of setting the "Class name" property to wxStaticBitmap I set it to wxGenericStaticBitmap as the use of this class is the reason for the custom control. The "Var name" property was set to img_Schem_Cascode_Boost, and the Identifier property was set to ID_IMG_SCHEM_CASCODE_BOOST.

In the Code::Blocks generated code the compiler indicated an error line 91:
Code
TIAFrame::TIAFrame(wxWindow* parent,wxWindowID id)
{
  ...
     img_Schem_Cascode_Boost = new wxGenericStaticBitmap(Panel1,ID_IMG_SCHEM_CASCODE_BOOST,wxPoint(0,0),wxDefaultSize,0,wxDefaultValidator,_T("ID_IMG_SCHEM_CASCODE_BOOST"));  // Line 91
 ...
}

The errors:
Quote
||=== Build: Debug in TIA (compiler: GNU GCC Compiler) ===|
C:\Engineering Software\TIA\TIAMain.cpp||In constructor 'TIAFrame::TIAFrame(wxWindow*, wxWindowID)':|
C:\Engineering Software\TIA\TIAMain.cpp|91|error: no matching function for call to 'wxGenericStaticBitmap::wxGenericStaticBitmap(wxPanel*&, const long int&, wxPoint, const wxSize&, int, const wxValidator&, const wchar_t [27])'|
C:\Engineering Software\TIA\TIAMain.cpp|91|note: candidates are:|
C:\wxWidgets-3.0.3\include\wx\generic\statbmpg.h|19|note: wxGenericStaticBitmap::wxGenericStaticBitmap(wxWindow*, wxWindowID, const wxBitmap&, const wxPoint&, const wxSize&, long int, const wxString&)|
C:\wxWidgets-3.0.3\include\wx\generic\statbmpg.h|19|note:   no known conversion for argument 3 from 'wxPoint' to 'const wxBitmap&'|
C:\wxWidgets-3.0.3\include\wx\generic\statbmpg.h|18|note: wxGenericStaticBitmap::wxGenericStaticBitmap()|
C:\wxWidgets-3.0.3\include\wx\generic\statbmpg.h|18|note:   candidate expects 0 arguments, 7 provided|
C:\wxWidgets-3.0.3\include\wx\generic\statbmpg.h|15|note: wxGenericStaticBitmap::wxGenericStaticBitmap(const wxGenericStaticBitmap&)|
C:\wxWidgets-3.0.3\include\wx\generic\statbmpg.h|15|note:   candidate expects 1 argument, 7 provided|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Missing in the Code::Blocks created constructor call in that line 91's instantiation is a parameter of type wxBitmap. Is this a bug in Code::Blocks? What can be done get this working?

I know how to create a wxBitmap type object and I have written the code to create it to pass to wxGenericStaticBitmap::SetBitmap()  .

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: wxGenericStaticBitmap
« Reply #5 on: October 12, 2017, 12:51:12 am »
It appears that in my circumstance default "Creating code" property for the custom element cannot be counted on to be correct. I changed this element to the string:
Code
$(THIS) = new $(CLASS)($(PARENT),$(ID),SchematicCascodeBoostBitmap,$(POS),$(SIZE),$(STYLE),$(NAME));

Then I defined  and insantiated SchematicCascodeBoostBitmap in the constructor as shown in this excerpt:

Code
TIAFrame::TIAFrame(wxWindow* parent,wxWindowID id)
{
    const wxString Filename("Images//TIA Cascode & Bootstrap cropped.sch.png");
    const wxBitmap SchematicCascodeBoostBitmap( Filename, wxBITMAP_TYPE_PNG );

    //(*Initialize(TIAFrame)
 
    ...

    img_Schem_Cascode_Boost = new wxGenericStaticBitmap(Panel1,ID_IMG_SCHEM_CASCODE_BOOST,SchematicCascodeBoostBitmap,wxPoint(0,0),wxDefaultSize,,_T("ID_IMG_SCHEM_CASCODE_BOOST"));

   ...

   //*)

}

The code compiles but the image does not show in the sizer. I know I have defined and instantiated SchematicCascodeBoostBitmap correctly because before I used the Custom element I used SchematicCascodeBoostBitma to add the image in the form in code I created outside of what Code::Blocks creates. I used the code automatically generated code as an example. The image displayed, but not inside the sizer.

What is missing here regarding the use of the Custom element?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: wxGenericStaticBitmap
« Reply #6 on: October 12, 2017, 11:53:45 am »
as you have found out, the "generic" control is generic. It uses the most common constructor of window classes in wxWidgets but they do not fit all needs.

Quote
The code compiles but the image does not show in the sizer
From here on it is no codeblocks problem anymore, and you will need to search for help in a wx forum. We can not support this kind of questions.

Code
const wxString Filename("Images//TIA Cascode & Bootstrap cropped.sch.png");
    const wxBitmap SchematicCascodeBoostBitmap( Filename, wxBITMAP_TYPE_PNG );
you do not make any sanity check if the bitmap is loaded. This seems to be a bad idea for me. Here it can fail.

You can try to debug...

Code
The image displayed, but not inside the sizer
So the image gets displayed but is not inside the sizer, or does not scale properly? Have you checked if the generated code is correct? Is the custom control added to your sizer? Have you set the expand flag? This is all wild guessing without code, image or video...


Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: wxGenericStaticBitmap
« Reply #7 on: October 13, 2017, 01:03:58 am »
The project that shows the image outside the sizer:
http://www.mediafire.com/file/rz9prvd1ex8bcs8/TIA_Added_Schematic.zip
In this project I added that image in a  wxGenericStaticBitmap object manually using as an example the code generated for the wxStaticBitmap object. This project demonstrates the code I wrote to create the wxBitmap object is working. I suspect image is outside the sizer because the wxs file needs to be edited. I hoped the Custom element would result in doing this for me.

The project that attempts to use the Custom element to add the image:
http://www.mediafire.com/file/f4ggwjkmckyq77y/TIA_Custom_Element.zip
The image does not display in the form.

I appreciate your assistance :)

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: wxGenericStaticBitmap
« Reply #8 on: October 13, 2017, 11:01:25 am »
You have a custom Paint event handler activated for your generic bitmap. Remove the handler, or call the base class paint handler and the image will get displayed...

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: wxGenericStaticBitmap
« Reply #9 on: October 13, 2017, 11:04:46 pm »
I found in the code where the paint event handler is activated. I commented out the line with the result that the image did appear as expected in the form.

But the line I commented out is between     //(*Initialize(TIAFrame and //*) which means it is Code::Blocks managed code and so that line will be repeatedly restored when Code::Blocks overwrites it as I continue to develop the application. I need to know where to tell Code::Blocks not to include this handler. I do not see a way to do it in the Custom element's Properties tab. In its Events tab the EVT_PAINT event has --None-- for a handler. It is the same for all other events in this tab.

How do I tell Code:Blocks to exclude this handler?

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: wxGenericStaticBitmap
« Reply #10 on: October 13, 2017, 11:07:15 pm »
For me it was a klick on the custom control so that the properties are shown, then top of this property grid you can select the event tab and there was a EVT_PAINT handler. After selecting there "none" all worked for me....

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: wxGenericStaticBitmap
« Reply #11 on: October 14, 2017, 11:45:25 pm »
I already had none for an event handler there. To test if something was out of synch I attempted to add an event handler that would be subsequently removed. But I got an error message box that said "Can't add event handler".

I added a new element to the form to be subsequently removed just to get Code::Blocks to refresh the managed code. This did not make a difference. And I found that I am not able to add event handlers for any new element I add to the form. I get the same error message.

Changes made to the form are not reflected in what I see when the program is run. It is as if it compiles from the wrong wxs file. I do not know where to look for which wxs file it uses. I know for sure the one I edit is the one attached to the project in the Management window.
« Last Edit: October 15, 2017, 12:17:45 am by spflanze »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: wxGenericStaticBitmap
« Reply #12 on: October 15, 2017, 02:41:30 am »
can you zip and upload the broken project?

Offline spflanze

  • Almost regular
  • **
  • Posts: 134
Re: wxGenericStaticBitmap
« Reply #13 on: October 16, 2017, 09:18:26 pm »
Can be downloaded here:
http://www.mediafire.com/file/ba11q041m4cz6l5/TIA_Designer_Form_Synch.zip

I removed an empty wxStaticBitmap object above the schematic on the left side. But when I compile and run it that removed and empty wxStaticBitmap object is still there in the executable.
« Last Edit: October 16, 2017, 09:21:54 pm by spflanze »

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: wxGenericStaticBitmap
« Reply #14 on: October 16, 2017, 10:47:37 pm »
you have completrly messed up your project file...
Do you have moved and or renamed source files?

wxSmith can not find the source and header files it has to work with. To fix this open the TIADesigner.cbp file with a text editor (notepad++ for example). Search for the part
Code
			<wxsmith version="1">
<gui name="wxWidgets" src="TIAApp.cpp" main="TIAFrame" init_handlers="necessary" language="CPP" />
<resources>
<wxFrame wxs="wxsmith/TIAframe.wxs" src="TIAMain.cpp" hdr="TIAMain.h" fwddecl="0" i18n="1" name="TIAFrame" language="CPP" />
</resources>
</wxsmith>
here you have to set all src and hdr attributes to valid source files. The attributes in the gui node is you application and the attributes in the wxFrame node is your frame. Save the file and open it in codeblocks. Add a button to the frame and remove it again, so that the code gets re generated...