wxWidgets 2.8.12 FreeBASIC C wrapper

Headers, Bindings, Libraries for use with FreeBASIC, Please include example of use to help ensure they are tested and usable.
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Post by MOD »

The problem is your type. wxWindow_FindWindowByName returns a wxWindow Ptr and even if you declare it as a wxTextCtrl it will stay a wxWindow. Btw, all types here are just declared as Any, that's why even casting does not help here.

You have to use the wxWindow methods.

If you want to use wx-c, provided with wx.Net project than the right header are here: wx-c header

And your code for this header:

Code: Select all

#Include Once "wx-c 0.9.2/wx.bi"

Const FRAME_W = 500
Const FRAME_H = 400

''
'' ids
''
Enum
  ID_FRAME=1
  ID_PANEL
  ID_CLICKMEBUTTON
  ID_EXITBUTTON
  ID_DIAG_EXITBUTTON
End Enum

Declare Function app_oninit_cb WXCALL () As wxBool
Declare Function app_onexit_cb WXCALL () As wxInt

''
'' globals
''
Dim Shared As wxApp Ptr app
Dim Shared As wxDialog Ptr dialog

'':::::
'''
'' main
''
'Dim apps As _wxApp Ptr
app = wxApp_ctor()
wxApp_RegisterVirtual(app, @app_oninit_cb, @app_onexit_cb)
wxApp_Run

'':::::
''
'' dialog's exit button callback
''
Sub diag_exitbutton_cb WXCALL (ByVal event As _wxEvent Ptr,iListener as wxInt)
        'wxMsgBox(,wxString_ctorUTF8("Bye Bye...1"), wxString_ctorUTF8("Window Closed!"))
          wxWindow_Destroy( dialog)
          app_onexit_cb(  )
End Sub

'':::::
''
'' on init callback
''
Function app_oninit_cb WXCALL () As wxBool
  Dim As Integer ypos, size
  Dim xrc As wxXmlResource Ptr
  '' create the main window

  xrc = wxXmlResource_ctorByFilemask(wxString_ctorUTF8("frmMayaMyAppsClient.xrc"), XRC_USE_LOCALE)
  wxXmlResource_InitAllHandlers(xrc)
  dialog = wxDialog_ctor( )
 
  wxDialog_Create(dialog,WX_NULL,-1, wxString_ctorUTF8("Press Exit"),_
      10, 10, 500, 400, _
            wxDIALOG_DEFAULT_STYLE, 0 ) ' Does not make any difference what type you set as they are overwritten by XRC
  wxXmlResource_LoadDialogDlg(xrc, dialog, 0, wxString_ctorUTF8("frmMain"))
  wxWindow_CenterOnScreen(dialog, wxBOTH )
 
  wxEvtHandler_proxy(dialog,@diag_exitbutton_cb)
  wxEvtHandler_Connect(dialog,wxEvent_EVT_CLOSE_WINDOW( ))

  Dim m_notebook1 As wxNotebook Ptr
  Dim m_clInstalled As wxCheckListBox Ptr
  Dim m_staticText2 As wxWindow Ptr

          m_clInstalled = wxWindow_FindWindowByName(wxString_ctorUTF8("m_hyperlink1"), dialog)
          m_staticText2 =  wxWindow_FindWindowByName(wxString_ctorUTF8("m_staticText2"), dialog)
       
        wxWindow_SetLabel(m_staticText2,  wxString_ctorUTF8("test"))
        wxWindow_Hide(m_clInstalled)
       
  wxWindow_Show(dialog)
 
  Function = wxApp_OnInit(app)
End Function

Function app_onexit_cb WXCALL () As wxInt
  Function = wxApp_OnExit( app )
  End
End Function
 
mayankjohri
Posts: 7
Joined: Jun 04, 2010 12:22

Post by mayankjohri »

so is there a way to get wxchecklistbox controls as wxwindows does not have options for wxchecklistbox.
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Post by MOD »

If you can't get it to work with wxWindow methods then, I think, it's not possible.

The mainproblem is casting. The wx-c types are not really types, just a unspecified memoryblock. You had to define all types as it's done in wxWidgets than just using 'Any Ptr' (and this isn't possible at the moment - maybe with the inheritance-branch). Even XRCCTRL is a macro that just casts the wxWindow to the given type.

At this state the capabilities of only wx-c are not enough for doing such things...
leodescal
Posts: 165
Joined: Oct 16, 2009 14:44
Location: Jodhpur, Rajputana, Empire of Aryavart
Contact:

Great

Post by leodescal »

It's super awesome!!!

Keep it up!
bonny
Posts: 75
Joined: Nov 22, 2007 10:23

How to control text color?!?

Post by bonny »

Hello...
I just making 1'st steps in wx.
I don't know how to change text in richedit. I make that example to show 2 colored text but cant find how to actualy set color.

Can someone help?

Code: Select all

#Include "wx-c 0.9.2/wx.bi"

Declare Function App_OnInit WXCALL ( ) As wxBool
Declare Function App_OnExit WXCALL ( ) As wxInt

Declare Sub button0_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As wxInt )

Dim Shared As wxApp Ptr wx_app
Dim Shared As wxFrame Ptr wx_frame
Dim Shared As wxPanel Ptr wx_panel

Dim Shared As wxTextCtrl Ptr richtext0

Function App_OnInit WXCALL ( ) As wxBool

	wx_frame = wxFrame_ctor( )
	wxFrame_Create( wx_frame, WX_NULL, -1, wxString_ctorUTF8("My WX-C Project"), 760, 400, 400, 400, wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER, WX_NULL )
	wx_panel = wxPanel_ctor2( wx_frame, -1, -1, -1, -1, -1, 0, WX_NULL )

	''
	'' create widget button0
	''
	Dim As wxButton Ptr button0
	button0 = wxButton_ctor( )
	wxButton_Create( button0, wx_panel, -1, wxString_ctorUTF8("Add text"), 10, 10, -1, 24, 0, 0, 0 )

	wxEvtHandler_Proxy( button0, Cast(EventListener, @button0_event) )
	wxEvtHandler_Connect( button0, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), -1, -1, 0 )

	''
	'' create widget richtext0
	''
'	Dim As wxTextCtrl Ptr richtext0
	richtext0 = wxTextCtrl_ctor( )
	wxTextCtrl_Create( richtext0, wx_panel, -1, wxString_ctorUTF8("richtext0"), 10, 70, 370, 280, wxTE_PROCESS_ENTER Or wxTE_MULTILINE Or wxTE_Rich Or wxTE_RICH2, 0, 0 )
	
	
	wxWindow_Show( wx_frame, 1 )
	wxApp_OnInit( wx_app )
	Return 1
	
End Function

Function App_OnExit WXCALL ( ) As wxInt
	
	Return wxApp_OnExit( wx_app )
	
End Function

Sub button0_event WXCALL ( ByVal event As wxEvent Ptr, ByVal iListener As wxInt )
	
	Select Case wxEvent_GetEventType( event )
		Case wxEvent_EVT_COMMAND_BUTTON_CLICKED
		
'                        wxTextCtrl_SetDefaultStyle(richtext0,????)
                        wxTextCtrl_AppendText(richtext0,wxString_ctorUTF8(" TEST_IN_RED "))

'                        wxTextCtrl_SetDefaultStyle(richtext0,????)
                        wxTextCtrl_AppendText(richtext0,wxString_ctorUTF8(" TEST_IN_BLUE "+chr(13)))


			''stuff
			
	End Select
	
End Sub


''main
wx_app = wxApp_ctor( )
wxApp_RegisterVirtual ( wx_app, @App_OnInit, @App_OnExit )
wxApp_Run(0, 0)
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Re: wxWidgets 2.8.12 FreeBASIC C wrapper

Post by MOD »

Something like this:

Code: Select all

wxTextCtrl_SetDefaultStyle(richtext0, wxTextAttr_ctor(wxColour_ctorByName(wxString_ctorUTF8("red")), wxColour_ctorByName(wxString_ctorUTF8("white")), wxFont_ctor(12, wxMODERN, wxNORMAL, wxNORMAL, 0, 0, 0), 1))
wxTextCtrl_AppendText(richtext0, wxString_ctorUTF8(" TEST_IN_RED "))

wxTextCtrl_SetDefaultStyle(richtext0, wxTextAttr_ctor(wxColour_ctorByName(wxString_ctorUTF8("blue")), wxColour_ctorByName(wxString_ctorUTF8("white")), wxFont_ctor(12, wxMODERN, wxNORMAL, wxNORMAL, 0, 0, 0), 1))
wxTextCtrl_AppendText(richtext0, wxString_ctorUTF8(" TEST_IN_BLUE " + Chr(13)))
bonny
Posts: 75
Joined: Nov 22, 2007 10:23

Re: wxWidgets 2.8.12 FreeBASIC C wrapper

Post by bonny »

Exactly.....

Is there some help file explaining all that parameters...
I found just wx.chm file. It is hughe but explain near nothing...
for example to use style is just:
wxTextCtrl::SetDefaultStyle
bool SetDefaultStyle(const wxTextAttr& style)
Changes the default style to use for the new text which is going to be added to the control using WriteText or AppendText.
If either of the font, foreground, or background colour is not set in style, the values of the previous default style are used for them. If the previous default style didn't set them neither, the global font or colours of the text control itself are used as fall back.
However if the style parameter is the default wxTextAttr, then the default style is just reset (instead of being combined with the new style which wouldn't change it at all).
Parameters
style
The style for the new text.
Return value
true on success, false if an error occurred - may also mean that the styles are not supported under this platform.

See also
GetDefaultStyle
....and in your example here are 5 parameters...
... and same is for other functions...
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Re: wxWidgets 2.8.12 FreeBASIC C wrapper

Post by MOD »

....and in your example here are 5 parameters...
No, 2 parameters, one more than in that helpfile. It's due to the fact that it's a wrapper and all the functions are not methods of a class, so everything needs a additional first parameter with the pointer to the variable.

wxTextCtrl::SetDefaultStyle(const wxTextAttr& style) in C++ will translate to wxTextCtrl_SetDefaultStyle(varptr as wxTextCtrl Ptr, style as wxTextAttr Ptr) in FB. What I did was to build the second parameter 'style' directly in the call with 'wxTextAttr_ctor'. Another Way to do the exact same thing:

Code: Select all

Dim As wxColour Ptr blue, white, red
blue = wxColour_ctorByName(wxString_ctorUTF8("blue"))
white = wxColour_ctorByName(wxString_ctorUTF8("white"))
red = wxColour_ctorByName(wxString_ctorUTF8("red"))

Dim As wxFont Ptr font = wxFont_ctor(12, wxMODERN, wxNORMAL, wxNORMAL, 0, 0, 0)

Dim As wxTextAttr Ptr textAttr_red, textAttr_blue

textAttr_red = wxTextAttr_ctor(red, white, font, 1)
textAttr_blue = wxTextAttr_ctor(blue, white, font, 1)

wxTextCtrl_SetDefaultStyle(richtext0, textAttr_red)
wxTextCtrl_AppendText(richtext0, wxString_ctorUTF8(" TEST_IN_RED "))

wxTextCtrl_SetDefaultStyle(richtext0, textAttr_blue)
wxTextCtrl_AppendText(richtext0, wxString_ctorUTF8(" TEST_IN_BLUE " + Chr(13)))
bonny
Posts: 75
Joined: Nov 22, 2007 10:23

Re: wxWidgets 2.8.12 FreeBASIC C wrapper

Post by bonny »

ok understand that...
..but got other problems.
For same example when I click to add text and the window is full, then window is cleared and only last line is showed. I need to all text be scrolled just one line up when box is full. I tried with wxTextCtrl_ShowPosition with no success. And the next one is how to save text with text formatting? (for example as rtf or similar) I have managed just to save plain text.

and least... Is it this right place to ask questions like this?
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Re: wxWidgets 2.8.12 FreeBASIC C wrapper

Post by MOD »

Add a 'wxWindow_ScrollLines(richtext0, 2)' at the and of the handler code, it will scroll the code permanently down.

If you want to save it as RTF, you will have to implement it yourself. AFAIK also wxWidgets can't do it.

You can ask here or simply start a new topic for new problems. It's easier for others to find a topic than a single post, so threads would be better.
leodescal
Posts: 165
Joined: Oct 16, 2009 14:44
Location: Jodhpur, Rajputana, Empire of Aryavart
Contact:

Re: wxWidgets 2.8.12 FreeBASIC C wrapper

Post by leodescal »

Hi! Do somebody know the C version of wx-c?
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Re: wxWidgets 2.8.12 FreeBASIC C wrapper

Post by MOD »

The C version of wx-c? wx-c is written in C so it is its own C version.
If you're asking for usage, then it's used same as in FreeBASIC.
If you're asking for C header, the project comes with a script to generate the header which you have to run.
leodescal
Posts: 165
Joined: Oct 16, 2009 14:44
Location: Jodhpur, Rajputana, Empire of Aryavart
Contact:

Re: wxWidgets 2.8.12 FreeBASIC C wrapper

Post by leodescal »

MOD wrote:The C version of wx-c? wx-c is written in C so it is its own C version.
If you're asking for usage, then it's used same as in FreeBASIC.
If you're asking for C header, the project comes with a script to generate the header which you have to run.
Ah.. I found it... Thanks :)

As you said that wx-c is just a sub set of wxWidgets... I have a question...

Do it support images in menu, combobox and list box?

I run quite a few tests but can't find them.... Are the absent in wx-c?
MOD
Posts: 555
Joined: Jun 11, 2009 20:15

Re: wxWidgets 2.8.12 FreeBASIC C wrapper

Post by MOD »

First of all, there is a visual designer for wx-c: Visual WX-C Designer

As you can see, wx-c has menus, comboboxes (you should now this as it's used in wxFBE) and listboxes. Menus can also have images (the designer uses this feature) but so far I can't make it work on linux too. So it looks like it's windows only.

The designer comes with some examples, feel free to play with them.
leodescal
Posts: 165
Joined: Oct 16, 2009 14:44
Location: Jodhpur, Rajputana, Empire of Aryavart
Contact:

Re: wxWidgets 2.8.12 FreeBASIC C wrapper

Post by leodescal »

MOD wrote:First of all, there is a visual designer for wx-c: Visual WX-C Designer

As you can see, wx-c has menus, comboboxes (you should now this as it's used in wxFBE) and listboxes. Menus can also have images (the designer uses this feature) but so far I can't make it work on linux too. So it looks like it's windows only.

The designer comes with some examples, feel free to play with them.
Ah.. I think than GTK is only tool currently accessible by FreeBASIC which gives professional level GUI support... It have only one flaw that it needs tons of dependencies.

VANAYA also did a good work but it is Windows only. Currently checking IUP, if it isn't satisfactory than I think I wouldn't have any other option but to submit to GTK :D
Post Reply