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: 558
Joined: Jun 11, 2009 20:15

Post by MOD »

D.J.Peters wrote:But trust me EXTENDS isn't the secret wappon to handle all none C++ RTTI of the wxPackage.
You're right, but it would be a first step and although its not part of FB yet, it would be good thing. Until then we have to use the wxWindow-Methods.
MOD
Posts: 558
Joined: Jun 11, 2009 20:15

Post by MOD »

Here another example done with the designer and adjusted manually to the new wrapper:

Code: Select all

#Include "inc/wx.bi"

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

Declare Sub bmpbutton0_cb( )

Dim Shared As _wxApp Ptr wx_app
Dim Shared As _wxFrame Ptr wx_frame
Dim Shared As _wxPanel Ptr wx_panel

Dim Shared As _wxBitmapButton Ptr bmpbuttons( 1 )

Function App_OnInit APICALL ( ) As wxBool
    
    wx_frame = wxFrame_ctor( )
    wxImage_InitAllHandlers( )
    
    wxFrame_Create( wx_frame, WX_NULL, -1, wxString("testfile"), 483, 184, 337, 441, 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 )
    
    ''' Application Icon
    Dim As _wxIcon Ptr appIcon
    Dim As _wxBitmap Ptr iconImage
    appIcon = wxIcon_ctor( )
    iconImage = wxBitmap_ctor( )
    wxBitmap_LoadFile( iconImage, wxString("images\icon.ico"), wxBITMAP_TYPE_ICO )
    wxIcon_CopyFromBitmap( appIcon, iconImage )
    wxFrame_SetIcon( wx_frame, appIcon )
    
    '''
    ''' create widget togglebutton0
    '''
    Dim As _wxToggleButton Ptr togglebutton0
    togglebutton0 = wxToggleButton_ctor( )
    wxToggleButton_Create( togglebutton0, wx_panel, -1, wxString("togglebutton0"), 10, 10, 90, 30, 0, 0, 0 )
    
    
    '''
    ''' create widget bmpbutton0
    '''
    Dim As _wxBitmap Ptr picbmpbutton0
    Dim As _wxBitmapButton Ptr bmpbutton0
    
    picbmpbutton0 = wxBitmap_ctor( )
    wxBitmap_LoadFile( picbmpbutton0, wxString("images\close.bmp"), wxBITMAP_TYPE_BMP )
    bmpbutton0 = wxBitmapButton_ctor( )
    
    wxBitmapButton_RegisterVirtual( bmpbutton0, Cast(Virtual_OnSetBitmap, @bmpbutton0_cb) )
    bmpbuttons( 0 ) = bmpbutton0
    
    wxBitmapButton_Create( bmpbutton0, wx_panel, -1, picbmpbutton0, 120, 10, -1, -1, 2 Or 4, 0, 0 )
    wxWindow_SetBackgroundColour( bmpbutton0, wxColour_ctorByParts( 255, 255, 255 ) )
    
    
    '''
    ''' create widget image0
    '''
    Dim As _wxBitmap Ptr picimage0
    Dim As _wxStaticBitmap Ptr image0
    
    picimage0 = wxBitmap_ctor( )
    image0 = wxStaticBitmap_ctor( )
    
    wxBitmap_LoadFile( picimage0, wxString("images\close.bmp"), wxBITMAP_TYPE_BMP )
    wxStaticBitmap_Create( image0, wx_panel, -1, picimage0, 20, 60, -1, -1, 0, 0 )
    
    
    '''
    ''' create widget choice0
    '''
    Dim As _wxArrayString Ptr choice0_str
    choice0_str = wxArrayString_ctor
    wxArrayString_Add( choice0_str, wxString("choice0") )
    wxArrayString_Add( choice0_str, wxString("choice1") )
    wxArrayString_Add( choice0_str, wxString("choice2") )
    Dim As _wxChoice Ptr choice0
    choice0 = wxChoice_ctor( )
    wxChoice_Create( choice0, wx_panel, -1, 20, 110, -1, -1, choice0_str, 0, 0, 0 )
    wxChoice_SetColumns( choice0, 0 )
    
    
    '''
    ''' create widget combo0
    '''
    Dim As _wxArrayString Ptr combo0_str
    combo0_str = wxArrayString_ctor
    wxArrayString_Add( combo0_str, wxString("choice0") )
    wxArrayString_Add( combo0_str, wxString("choice1") )
    Dim As _wxCombobox Ptr combo0
    combo0 = wxCombobox_ctor( )
    wxCombobox_Create( combo0, wx_panel, -1, wxString("combo0"), 130, 110, -1, -1, combo0_str, 0, 0, 0 )
    
    
    '''
    ''' create widget spinctrl0
    '''
    Dim As _wxSpinCtrl Ptr spinctrl0
    spinctrl0 = wxSpinCtrl_ctor( )
    wxSpinCtrl_Create( spinctrl0, wx_panel, -1, wxString("50"), 20, 160, -1, -1, SP_ARROW_KEYS, 0, 100, 0, 0 )
    
    
    '''
    ''' create widget richtext0
    '''
    Dim As _wxTextCtrl Ptr richtext0
    richtext0 = wxTextCtrl_ctor( )
    wxTextCtrl_Create( richtext0, wx_panel, -1, wxString("any richtext0"), 20, 210, 100, 90, TE_PROCESS_ENTER Or TE_MULTILINE Or TE_Rich Or TE_RICH2, 0, 0 )
    
    
    '''
    ''' create widget gauge0
    '''
    Dim As _wxGauge Ptr gauge0
    gauge0 = wxGauge_ctor( )
    wxGauge_Create( gauge0, wx_panel, -1, 100, 190, 30, -1, -1, 0, 0, 0 )
    wxGauge_SetValue( gauge0, 45 )
    
    
    '''
    ''' create widget radio0
    '''
    Dim As _wxArrayString Ptr radio0_str
    radio0_str = wxArrayString_ctor
    wxArrayString_Add( radio0_str, wxString("choice1") )
    wxArrayString_Add( radio0_str, wxString("choice2") )
    Dim As _wxRadiobox Ptr radio0
    radio0 = wxRadiobox_ctor( )
    wxRadiobox_Create( radio0, wx_panel, -1, wxString("radio0"), 180, 150, -1, -1, radio0_str, 0, 0, 0, 0 )
    wxRadiobox_SetSelection( radio0, 0 )
    
    
    '''
    ''' create widget list0
    '''
    Dim As _wxArrayString Ptr list0_str
    list0_str = wxArrayString_ctor
    wxArrayString_Add( list0_str, wxString("list0") )
    wxArrayString_Add( list0_str, wxString("list1") )
    wxArrayString_Add( list0_str, wxString("list2") )
    Dim As _wxListbox Ptr list0
    list0 = wxListbox_ctor( )
    wxListbox_Create( list0, wx_panel, -1, 180, 230, -1, -1, list0_str, 0, 0, 0 )
    wxListbox_SetSelection( list0, 0, WX_TRUE )
    
    
    '''
    ''' create widget slider0
    '''
    Dim As _wxSlider Ptr slider0
    slider0 = wxSlider_ctor( )
    wxSlider_Create( slider0, wx_panel, -1, 0, 0, 100, 20, 340, -1, -1, 0 Or SL_LABELS, 0, 0 )
    wxSlider_SetValue( slider0, 45 )
    
    
    '''
    ''' create widget button0
    '''
    Dim As _wxButton Ptr button0
    button0 = wxButton_ctor( )
    wxButton_Create( button0, wx_panel, -1, wxString("button0"), 160, 350, -1, 24, 0, 0, 0 )
    
    wxWindow_Show( wx_frame, 1 )
    wxApp_OnInit( wx_app )
    
    Return 1
    
End Function

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

Sub bmpbutton0_cb( )
    wxBitmapButton_OnSetBitmap( bmpbuttons( 0 ) )
End Sub



''main
wx_app = wxApp_ctor( )
wxApp_RegisterVirtual ( wx_app, @App_OnInit, @App_OnExit )
wxApp_Run(0, 0)
End
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

hello MOD
thank you for the example i put it in the next download.

if i draw 10,000 lines after a button click with different colors
it cost ~100KB for every click and you will run out of resources

now i add missing things to the wrapper there are no wxPen_dtor() !!!

Code: Select all

_DF(wxPen_ctorByBitmap(stipple as _wxBitmap, penWidth as wxInt=1) as _wxPen ptr
_DS(wxPen_dtor)(self as _wxPen ptr)
_DS(wxPen_SetStipple)(self as _wxPen ptr, stipple as _wxBitmap ptr)
There are so many missing things in the wrapper
wxTimer, wxTCPServer, wxTCPClient, wxSound, wxGLCanvas, ... and so on.

Let me know if you will see any missing wxWidgets feature in the wrapper i will put it on my own wishlist.

Joshy
MOD
Posts: 558
Joined: Jun 11, 2009 20:15

Post by MOD »

If a certain destructor is missing, you can always use 'wxObject_dtor()'.

I've noticed, that 'accel.bi' is missing and maybe some other files, not sure.

Another example (with menus):

Code: Select all

#Include "inc/wx.bi"
Declare Function App_OnInit APICALL ( ) As wxBool
Declare Function App_OnExit APICALL ( ) As wxInt

Declare Sub menuhandler APICALL ( ByVal event As _wxEvent Ptr, ByVal iListener As Long )

Dim Shared As _wxApp Ptr wx_app
Dim Shared As _wxFrame Ptr wx_frame
Dim Shared As _wxPanel Ptr wx_panel
Dim Shared As _wxCheckBox Ptr checkbox0

Function App_OnInit APICALL ( ) As wxBool
    
    wx_frame = wxFrame_ctor( )
    wxFrame_Create( wx_frame, WX_NULL, -1, wxString("Menutest"), 483, 184, 167, 124, 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 checkbox0
    ''
    checkbox0 = wxCheckBox_ctor( )
    wxCheckBox_Create( checkbox0, wx_panel, -1, wxString("checkbox0"), 40, 30, -1, -1, 0, 0, 0 )
    wxCheckBox_SetValue( checkbox0, 0 )
    
    
    '' create menues
    Dim As _wxMenuBar Ptr wx_menubar
    wx_menubar = wxMenuBar_ctor( )
    
    '' menu " + menu->name + "
    Dim As _wxMenu Ptr wx_menu0
    wx_menu0 = wxMenu_ctor( wxString(""), 0 )
    wxMenuBase_Append( wx_menu0, 1, wxString("Check it"), wxString("Check it"), 0 )
    wxMenuBase_AppendSeparator( wx_menu0 )
    wxMenuBase_Append( wx_menu0, 2, wxString("Exit"), wxString("Exit"), 0 )
    wxMenuBar_Append( wx_menubar, wx_menu0, wxString("&Do") )
    '' menu " + menu->name + "
    Dim As _wxMenu Ptr wx_menu1
    wx_menu1 = wxMenu_ctor( wxString(""), 0 )
    wxMenuBase_Append( wx_menu1, 3, wxString("Uncheck it"), wxString("Uncheck it"), 0 )
    wxMenuBar_Append( wx_menubar, wx_menu1, wxString("&Undo") )
    wxFrame_SetMenuBar(wx_frame, wx_menubar)
    
    wxEvtHandler_Proxy( wx_frame, Cast(EventListener, @menuhandler) )
    wxEvtHandler_Connect( wx_frame, wxEvent_EVT_COMMAND_MENU_SELECTED( ), -1, -1, 0 )
    
    wxWindow_Show( wx_frame, 1 )
    wxApp_OnInit( wx_app )
    Return 1
    
End Function

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

Sub menuhandler APICALL ( ByVal event As _wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetId( event )
        Case 1
            '' stuff for selecting item Check it from menu &Do goes here
            wxCheckBox_SetValue( checkbox0, WX_TRUE )
        Case 2
            '' stuff for selecting item Exit from menu &Do goes here
            End
        Case 3
            '' stuff for selecting item Uncheck it from menu &Undo goes here
            wxCheckBox_SetValue( checkbox0, WX_FALSE )
    End Select
    
End Sub


''main
wx_app = wxApp_ctor( )
wxApp_RegisterVirtual ( wx_app, @App_OnInit, @App_OnExit )
wxApp_Run(0, 0)
This is one of the first codes I don't had to adjust by hand. The designer now supports the new wrapper. I'll do some more testings and then I'll upload it. However, it supports it only for its output, the designer needs the old version of the dll. Next step will be to update the designer code, but this will take a while.
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

MOD wrote:If a certain destructor is missing, you can always use 'wxObject_dtor()'.
this solution is to simple :lol:
how ever i added wx_Pen_dtor()
MOD wrote:I've noticed, that 'accel.bi' is missing
and why you don't post it ;-)
Don't wory it's in the *.zip file now.
MOD wrote:and maybe some other files, not sure.
think positive
i wrote more than 150 files per hand and only one was missing
really good job :-)
MOD wrote:Another example (with menus)
cool
MOD wrote:the designer needs the old version of the dll. Next step will be to update the designer code, but this will take a while.
make it real.

You can add a new control to your designer.
I added the wxTimer class to the wrapper

Code: Select all

#include once "inc/wx.bi"

const BUTTON_START_ID = 1
const BUTTON_STOP_ID  = 2
const TIMER_ID        = 3

Declare Sub EventListener APICALL(event As _wxEvent Ptr,iListener As wxInt)

Dim Shared As _wxApp      Ptr App
Dim Shared As _wxFrame    Ptr Frame
Dim Shared As _wxTimer    Ptr Ticker
Dim Shared As _wxButton   Ptr ButtonStart
Dim Shared As _wxButton   Ptr ButtonStop
Dim Shared As _wxTextCtrl Ptr textctrl0

function App_OnInit APICALL( ) as wxBool
  Frame = wxFrame_ctor( )
  wxFrame_Create(Frame,,,wxString("wxTimer"), _
                 ,, 390, 390, _
                 wxFRAME_DEFAULT_STYLE Or  wxCLOSE_BOX _
                 Xor wxMAXIMIZE_BOX Xor wxRESIZE_BORDER)
                 
  Dim As _wxPanel Ptr Panel = wxPanel_ctor2(Frame)

  ButtonStart = wxButton_ctor()
  wxButton_Create(Buttonstart, Panel, BUTTON_START_ID, wxString("start"), 10, 10)
  wxEvtHandler_proxy(ButtonStart, @EventListener)
  wxEvtHandler_Connect(ButtonStart,wxEvent_EVT_COMMAND_BUTTON_CLICKED())

  ButtonStop = wxButton_ctor()
  wxButton_Create(ButtonStop, Panel, BUTTON_STOP_ID, wxString("stop"),  10, 40)
  wxEvtHandler_proxy(ButtonStop, @EventListener)
  wxEvtHandler_Connect(ButtonStop,wxEvent_EVT_COMMAND_BUTTON_CLICKED())
  wxWindow_Enable(ButtonStop,WX_FALSE)

  Ticker = wxTimer_ctor(Frame,TIMER_ID)
  wxEvtHandler_proxy(Frame, @EventListener)
  wxEvtHandler_Connect(Frame,wxEvent_EVT_TIMER())

  wxWindow_Show(Frame, 1 )
  return wxApp_OnInit(App)
End function

function App_OnExit APICALL as wxInt
  return wxApp_OnExit(App )
End function

Sub EventListener APICALL(event As _wxEvent Ptr, iListener As wxInt )
  static as wxInt nTicks = 0
  select case wxEvent_GetId(event)
  case BUTTON_START_ID
    wxWindow_Enable(ButtonStart,WX_FALSE)
    wxWindow_Enable(ButtonStop ,WX_TRUE)
    wxTimer_Start(Ticker,20)
  case BUTTON_STOP_ID
    wxTimer_Stop(Ticker)
    wxWindow_Enable(ButtonStop ,WX_FALSE)
    wxWindow_Enable(ButtonStart,WX_TRUE)
  case TIMER_ID
    nticks+=1
    wxWindow_SetTitle(Frame, wxString("number of ticks = " & nTicks))
  end select
End Sub



''main
App = wxApp_ctor()
wxApp_RegisterVirtual App, @App_OnInit, @App_OnExit
wxApp_Run()
You can see any widget can be a parent of the hidden wxTimer control.

Code: Select all

Ticker = wxTimer_ctor(Frame,TIMER_ID)
  wxEvtHandler_proxy(Frame, @EventListener)
  wxEvtHandler_Connect(Frame,wxEvent_EVT_TIMER())
If an user of your wxDesigner put the wxTimer on a wxFrame, wxPanel or where ever
you must add only few line of code.

Here are how you can break the message loop without the END command.

Code: Select all

Sub menuhandler APICALL ( ByVal event As _wxEvent Ptr, ByVal iListener As Long )
  Select Case wxEvent_GetId( event )
    Case 1: wxCheckBox_SetValue( checkbox0, WX_TRUE )
    Case 2: wxWindow_close(wx_frame,WX_TRUE) 
    Case 3: wxCheckBox_SetValue( checkbox0, WX_FALSE )
  End Select
End Sub
happy coding

wxJoshy
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

This night i try to add the missing wxGLCanvas to the wrapper.

wish me success i can need it.

Joshy
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

It's all so colorful here must be OpenGL, i got it :-)

This was the primary point why i began the hard work with the wxWidgets at all.

I need for my own tools OpenGL and a modern GUI.

wxJoshy ;-)
ike
Posts: 387
Joined: Jan 17, 2011 18:59

Colorful?

Post by ike »

What do you mean colorful???

Like this????




http://images.tradekool.com/12751900/Co ... ration.jpg
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

now in gray :-)

glcanvas01.bas

Code: Select all

#include once "inc/wx.bi"
#include once "GL/gl.bi"
#include once "GL/glu.bi"

const FRAME_WIDTH  = 640
const FRAME_HEIGHT = 480
const TIMER_ID     = 1
const FRAME_STYLE  = wxSYSTEM_MENU _
                  or wxMINIMIZE_BOX _
                  or wxCAPTION _
                  or wxCLIP_CHILDREN _
                  or wxCLOSE_BOX
                 
dim shared as _wxApp      ptr App
dim shared as _wxFrame    ptr Frame
Dim Shared As _wxTimer    Ptr Ticker
dim shared as _wxGLCanvas ptr GLCanvas

Sub EventHandler APICALL (event As _wxEvent Ptr, iListener As wxInt)
  static as wxInt nTicks = 0
  select case wxEvent_GetId(event)
  case TIMER_ID
    ' is it the first frame ?
    if (nTicks=0) then
      GLCanvas = SimpleGLCanvas(frame,,FRAME_WIDTH,FRAME_HEIGHT)
      wxGLCanvas_SetCurent(GLCanvas)
      glViewport(0, 0, FRAME_WIDTH,FRAME_HEIGHT)
      glMatrixMode(GL_PROJECTION)
      glLoadIdentity()
      gluPerspective(60,FRAME_WIDTH/FRAME_HEIGHT,0.1,1000.0)
      glMatrixMode(GL_MODELVIEW)
      glEnable(GL_DEPTH_TEST)
      glEnable(GL_LIGHTING)
      glEnable(GL_LIGHT0)
      glClearColor(0.0,0.5,0.5,1.0)
    end if
    nticks+=1
    glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    gluLookAt(2,2,-1, 0,0,0, 0,1,0)
    
    glRotatef(nTicks mod 360,1,1,1)
    
    glBegin(GL_QUADS)
      glNormal3f( 0.0, 0.0, 1.0)
      glVertex3f( 0.5, 0.5, 0.5): glVertex3f(-0.5, 0.5, 0.5)
      glVertex3f(-0.5,-0.5, 0.5): glVertex3f( 0.5,-0.5, 0.5)

      glNormal3f( 0.0, 0.0,-1.0)
      glVertex3f(-0.5,-0.5,-0.5): glVertex3f(-0.5, 0.5,-0.5)
      glVertex3f( 0.5, 0.5,-0.5): glVertex3f( 0.5,-0.5,-0.5)

      glNormal3f( 0.0, 1.0, 0.0)
      glVertex3f( 0.5, 0.5, 0.5): glVertex3f( 0.5, 0.5,-0.5)
      glVertex3f(-0.5, 0.5,-0.5): glVertex3f(-0.5, 0.5, 0.5)

      glNormal3f( 0.0,-1.0, 0.0)
      glVertex3f(-0.5,-0.5,-0.5): glVertex3f( 0.5,-0.5,-0.5)
      glVertex3f( 0.5,-0.5, 0.5): glVertex3f(-0.5,-0.5, 0.5)

      glNormal3f( 1.0, 0.0, 0.0)
      glVertex3f( 0.5, 0.5, 0.5): glVertex3f( 0.5,-0.5, 0.5)
      glVertex3f( 0.5,-0.5,-0.5): glVertex3f( 0.5, 0.5,-0.5)

      glNormal3f(-1.0, 0.0, 0.0)
      glVertex3f(-0.5,-0.5,-0.5): glVertex3f(-0.5,-0.5, 0.5)
      glVertex3f(-0.5, 0.5, 0.5): glVertex3f(-0.5, 0.5,-0.5)
    glEnd()

    wxWindow_SetTitle(Frame, wxString("number of ticks = " & nTicks))
    wxGLCanvas_SwapBuffers(GLCanvas)
  end select
end sub

function OnInit APICALL as wxBool
  ' create a wxFrame
  Frame = wxFrame_ctor()
  wxFrame_Create(Frame,,,wxString("GLCanvas"),,,_
                 FRAME_WIDTH,FRAME_HEIGHT, FRAME_STYLE)
  ' create wxtimer
  Ticker = wxTimer_ctor(Frame,TIMER_ID)
  wxEvtHandler_proxy(Frame, @EventHandler)
  wxEvtHandler_Connect(Frame,wxEvent_EVT_TIMER())
  ' show the wxFrame
  wxWindow_Show(frame,WX_TRUE)
  ' start your engine :-)
  wxTimer_Start(Ticker,20)
  return wxApp_OnInit(App)
end function  

function OnExit APICALL as wxInt
  return wxApp_OnExit(App)
end function

' create our wxApllication
App = wxApp_ctor()
wxApp_RegisterVirtual(App,@OnInit,@OnExit)
wxApp_Run()
Image
MOD
Posts: 558
Joined: Jun 11, 2009 20:15

Post by MOD »

Another example (toolbar):

Code: Select all

#Include "inc/wx.bi"
Declare Function App_OnInit APICALL ( ) As wxBool
Declare Function App_OnExit APICALL ( ) As wxInt

Declare Sub menuhandler APICALL ( ByVal event As _wxEvent Ptr, ByVal iListener As Long )

Dim Shared As _wxApp Ptr wx_app
Dim Shared As _wxFrame Ptr wx_frame
Dim Shared As _wxPanel Ptr wx_panel

Function App_OnInit APICALL ( ) As wxBool
    
    wx_frame = wxFrame_ctor( )
    wxFrame_Create( wx_frame, WX_NULL, -1, wxString("toolbar"), 483, 184, 218, 127, 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 )
    
    wxFrame_CreateToolbar( wx_frame, wxHORIZONTAL Or TB_TEXT Or TB_FLAT, -1, 0 )
    wxToolBar_AddTool2( wxFrame_GetToolbar( wx_frame ), 1, _
                        wxString("Close"), _
                        wxBitmap_ctorByName( wxString("./media/close.bmp"), wxBITMAP_TYPE_BMP ), _
                        wxString("Closes the window"), _
                        0 )
    wxToolBar_Realize( wxFrame_GetToolbar( wx_frame ) )
    wxEvtHandler_Proxy( wx_frame, Cast(EventListener, @menuhandler) )
    wxEvtHandler_Connect( wx_frame, wxEvent_EVT_COMMAND_MENU_SELECTED( ), -1, -1, 0 )
    
    wxWindow_Show( wx_frame, 1 )
    wxApp_OnInit( wx_app )
    Return 1
    
End Function

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

Sub menuhandler APICALL ( ByVal event As _wxEvent Ptr, ByVal iListener As Long )
    
    Select Case wxEvent_GetId( event )
        Case 1
            '' stuff for toolbar button #1
            End
    End Select
    
End Sub


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

Post by MOD »

I've just updated the examples provided with FB.

mdi.bas:

Code: Select all

''
'' wx-c MDI example, by dumbledore
''
 

#Include Once "inc/wx.bi" 

Const CHILDREN = 4

'' globals
	Dim Shared As _wxApp Ptr app 
	Dim Shared As _wxMDIParentFrame Ptr mdiparent


'' obligatory callback when creating parent MDI frames
Function mdiparent_OnCreateClient(  ) As _wxMDIClientWindow Ptr 
    
    Function = wxMDIParentFrame_OnCreateClient( mdiparent ) 

End Function

''
Sub init_frames( )

    '' create the parent MDI frame
    mdiparent = wxMDIParentFrame_ctor( ) 
    wxMDIParentFrame_RegisterVirtual( mdiparent, @mdiparent_OnCreateClient )
    wxMDIParentFrame_Create( mdiparent, 0, -1, wxString("parent"), -1, -1, 500, 500, _
    						 wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX Or wxVSCROLL Or wxHSCROLL, 0 ) 
    
    '' now the child ones
    Dim As _wxMDIChildFrame Ptr childframe
    Dim As Integer i
    For i = 1 To CHILDREN
    	childframe = wxMDIChildFrame_ctor( ) 
    	wxMDIChildFrame_Create( childframe, mdiparent, -1, wxString("child_" + Str(i)), _
    							10*i, 10*i, 120, 100, _
    							wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX, 0 ) 
	Next

End Sub

''
Sub init_menus( )

    '' add a menu bar
    Dim As _wxMenuBar Ptr mbar = wxMenuBar_ctor( ) 
    
    '' and the menus
    Dim As _wxMenu Ptr menu = wxMenu_ctor( wxString(""), 0 ) 
    wxMenuBase_Append( menu, -1, wxString("&Nothing"), wxString("This does squat."), 0 ) 
    wxMenuBar_Append( mbar, menu, wxString("&File") ) 
    wxFrame_SetMenuBar( mdiparent, mbar ) 

End Sub

''
Function App_OnInit APICALL ( ) As wxBool

    ''
    init_frames( )
    
    ''
    init_menus( )
    
    ''
    wxWindow_Show( mdiparent, WX_TRUE ) 
    
    Function = wxApp_OnInit( app )

End Function

''
Function App_OnExit APICALL ( ) As wxInt

    Function = wxApp_OnExit( app ) 

End Function

'' main	
	app = wxApp_ctor( ) 
	wxApp_RegisterVirtual( app, @App_OnInit, @App_OnExit ) 
	wxApp_Run( 0, 0 ) 
sizers.bas:

Code: Select all

''
'' wx-c sizers example, by dumbledore
''


#Include Once "inc/wx.bi" 

'' globals
	Dim Shared As _wxApp Ptr app
	Dim Shared As _wxSizer Ptr sizer 

''
Sub sizer_OnDispose( )

End Sub

''
Sub sizer_OnRecalcSizes( ) 
    
    wxBoxSizer_RecalcSizes( sizer ) 
    
End Sub 

''
Function App_OnInit APICALL ( ) As wxBool

    '' create the main window
    Dim As _wxFrame Ptr frame = wxFrame_ctor( ) 
    wxFrame_Create( frame, 0, 1, wxString("Welcome to WX-C"), -1, -1, -1, -1, _
    				wxFRAME_DEFAULT_STYLE Or wxCLOSE_BOX, WX_NULL ) 
    
    '' create a box sizer and set as the new layout
    sizer = wxBoxSizer_ctor( wxVERTICAL )  
    wxBoxSizer_RegisterVirtual( sizer, @sizer_OnRecalcSizes ) 
    wxBoxSizer_RegisterDisposable( sizer, @sizer_OnDispose )
    wxWindow_SetAutoLayout( frame, WX_TRUE ) 
    
    '' create button 1 and add to sizer
    Dim As _wxButton Ptr button1 = wxButton_ctor( ) 
    wxButton_Create( button1, frame, 1, wxString("Button1"), -1,-1, -1, -1, 0, 0, 0 ) 
    wxSizer_AddWindow( sizer, button1, -1, -1, -1, 0 ) 
    
    '' create button 2 and add to sizer
    Dim As _wxButton Ptr button2 = wxButton_ctor( ) 
    wxButton_Create( button2, frame, 2, wxString("Button2"), -1, -1, -1, -1, 0, 0, 0 ) 
    wxSizer_AddWindow( sizer, button2, -1, -1, -1, 0 ) 
    
    '' 
    wxWindow_SetSizerAndFit( frame, sizer, 0 ) 
    
    ''
    wxWindow_CenterOnScreen( frame, wxBOTH ) 
    
    wxWindow_Show( frame, 1 ) 
    
    Function = wxApp_OnInit( app ) 
    
End Function

''
Function App_OnExit APICALL ( ) As wxInt

    Function = wxApp_OnExit( app ) 

End Function

'' main
  app = wxApp_ctor( ) 
  wxApp_RegisterVirtual( app, @App_OnInit, @App_OnExit ) 
  wxApp_Run( 0, 0 )
wx-c_demo.bas:

Code: Select all

''
'' wxWindows-c example, by dumbledore
''


#Include Once "inc/wx.bi"

Const FRAME_W = 500
Const FRAME_H = 400

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

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

''
'' globals
''
	Dim Shared As _wxApp Ptr app
	Dim Shared As _wxFrame Ptr frame
   	Dim Shared As _wxDialog Ptr dialog

'':::::
''
'' main  
''
  	app = wxApp_ctor( )
  	wxApp_RegisterVirtual( app, @app_oninit_cb, @app_onexit_cb )
  	wxApp_Run( 0, 0 )
  	
	End 0

'':::::
''
'' dialog's exit button callback
''
Sub diag_exitbutton_cb(ByVal event As _wxEvent Ptr, ByVal iListener As Integer)

	wxDialog_EndModal( dialog, 0 )
	
End Sub

'':::::
''
'' panel's click-me button callback
''
Sub panel_clickmebutton_cb (ByVal event As _wxEvent Ptr, ByVal iListener As Integer)
   
	wxDialog_ShowModal( dialog )
   
End Sub

'':::::
''
'' panel's exit button callback
''
Sub panel_exitbutton_cb (ByVal event As _wxEvent Ptr, ByVal iListener As Integer)
   
	wxWindow_Close( frame, 0 )
   
End Sub

'':::::
''
'' on init callback
''
Function app_oninit_cb APICALL () As wxBool
	Dim As Integer ypos, size
   
	'' create the main window
   	frame = wxFrame_ctor( )
   	wxFrame_Create( frame, 0, ID_FRAME, wxString("Welcome to WX-C"), _
   				   	200, 200, FRAME_W, FRAME_H, _
   				   	wxFRAME_DEFAULT_STYLE, WX_NULL )
   
   	'' make a dialog
   	dialog = wxDialog_ctor( )
   	wxDialog_Create( dialog, frame, -1, wxString("Press Exit"),_
   					 10, 10, 500, 400, _
   				     wxFRAME_DEFAULT_STYLE, 0 )
   
   	'' add widgets to the dialog
   	size = 27
   	ypos=1

   	wxButton_Create( wxButton_ctor( ), dialog, -1, wxString("&Goto"), _
   					405, ypos, 85, -1, 0, 0, 0 )
   	ypos += size
   
   	wxButton_Create( wxButton_ctor( ), dialog, -1, wxString("&Select"), _
   					 405, ypos, 85, -1, 0, 0, 0 )
   	ypos += size
   
   	wxButton_Create( wxButton_ctor( ), dialog, -1, wxString("E&dit"), _
   					 405, ypos, 85, -1, 0, 0, 0 )
   	ypos += size
   
   	wxButton_Create( wxButton_ctor( ), dialog, -1, wxString("&Add"), _
   					 405, ypos, 85, -1, 0, 0, 0 )
   	ypos += size
   
   	Dim As _wxButton Ptr diag_exitbutton = wxButton_ctor( )
   	wxButton_Create( diag_exitbutton, dialog, ID_DIAG_EXITBUTTON, wxString("&Exit"), _
   					 405, ypos, 85, -1, 0, 0, 0 )
   
   	wxEvtHandler_proxy( diag_exitbutton, @diag_exitbutton_cb )
   	wxEvtHandler_Connect( diag_exitbutton, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), ID_DIAG_EXITBUTTON, -1, 0 )

   	Dim As _wxListBox Ptr selector = wxListBox_ctor( )
   	wxListBox_Create( selector, dialog, -1, _
   					  -1, -1, 400, 350, 0, _
   					  LB_SINGLE Or LB_NEED_SB Or LB_HSCROLL, 0, 0 )
   	
   	Dim As _wxFont Ptr font = wxFont_ctor( 10, wxMODERN, wxNORMAL, wxNORMAL, 0, 0, 0 )
   	wxWindow_SetFont( selector, font )
   	
   	Dim As Integer i
   	Dim As _wxArrayString Ptr tempString = wxArrayString_ctor( )
   	For i = 0 To 15
   		wxArrayString_Add( tempString, wxString("list item " + Str( i+1 )) )
   		wxListBox_InsertItems( selector, tempString, i )
   		wxArrayString_Clear( tempString )
   	Next i
   
   	'' create the main panel
   	Dim As _wxPanel Ptr panel = wxPanel_ctor( )
   	wxPanel_Create( panel, frame, ID_PANEL, 0, 0, 0, 0 )
   
   	'' create a text widget
   	'' we're not using this thing for any events so it gets an id of -1
   	Dim As _wxTextCtrl Ptr text = wxTextCtrl_ctor( )
   	wxTextCtrl_Create( text, panel, -1, wxString("Hello from wx-c in fb!"), _
   					   8, 8, FRAME_W - 24, FRAME_H - 200, _
   					   wxVSCROLL, 0, 0 )
   					   
   	wxTextCtrl_SetFont( text, font )
   
   	'' make a button (sending a wxsize(-1,-1) means take the default size - 
   	'' you can specify just x or y as -1 if you want the other one to be a fixed size
   	Dim As _wxButton Ptr panel_clickmebutton = wxButton_ctor( )
   	wxButton_Create( panel_clickmebutton, panel, ID_CLICKMEBUTTON, wxString("Click me!"), _
   					 FRAME_W\2 - 100, FRAME_H - 60, -1, -1, 0, 0, 0 )
   
   	'' connect the button to the button event handler sub
   	wxEvtHandler_proxy( panel_clickmebutton, @panel_clickmebutton_cb )
   	wxEvtHandler_Connect( panel_clickmebutton, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), ID_CLICKMEBUTTON, -1, 0 )

   	''
   	Dim As _wxButton Ptr panel_exitbutton = wxButton_ctor( )
   	wxButton_Create( panel_exitbutton, panel, ID_EXITBUTTON, wxString("Exit"), _
   					 FRAME_W\2 + 40, FRAME_H - 60, -1, -1, 0, 0, 0 )
   
   	'' connect the button to the button event handler sub
   	wxEvtHandler_proxy( panel_exitbutton, @panel_exitbutton_cb )
   	wxEvtHandler_Connect( panel_exitbutton, wxEvent_EVT_COMMAND_BUTTON_CLICKED( ), ID_EXITBUTTON, -1, 0 )
   
   	'' center it
   	wxWindow_CenterOnScreen( frame, wxBOTH )
   	
   	'' show window
   	wxWindow_Show( frame, 1 )

	Function = wxApp_OnInit( app )
	
End Function

'':::::
''
'' on exit callback
''
Function app_onexit_cb () As Integer

	wxMsgBox( 0, wxString("Bye Bye..."), wxString("Window Closed!"), 0, -1, -1 )

	Function = wxApp_OnExit( app )
	
End Function
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

@MOD
It's good to have some examples as starting point.

Does the glCanvas works on your boxes ?

I added missing but usefull things to the wxImage class.

Code: Select all

_DF(wxImage_ctorFromFile)(FileName as _wxString ptr, typ as wxInt, index as wxInt=-1) as _wxImage ptr

_DF(wxImage_ctorFromData)(w as wxInt, h as wxInt, pixels as wxChar ptr, isStatic as wxBool=WX_TRUE) as _wxImage ptr

_DF(wxImage_GetRGBData)  (self as _wxImage ptr) as any ptr

_DF(wxImage_GetAlphaData)(self as _wxImage ptr) as any ptr

_DF(wxImage_GetRGBAData) (self as _wxImage ptr, pixels as any ptr, nPixels as wxInt) as wxBool
ike
Posts: 387
Joined: Jan 17, 2011 18:59

glcanvas

Post by ike »

glcanvas examples works on my PC with XP

There is only one problem: when I try to close window program crashes and I get error:

program encounter a problem

Send report - Dont Send
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

@ike i will research whats going wrong

By the way I found out that the behavior on Linux differs totaly.

In your example buttonarray.bas i rewrote
the Array of Buttons() are created shared outside of function App.OnInit()
that means all wxButton_ctors are called from the wxButton_object constructors
and it's ok on windows and will crash on linux. :-(

Now all xxx_ctors() constructors must be created inside of wxXXX_object.Create().

It's not really a big deal but i must rewrite all wxXXX_object classes.

Last but not least i found out that the param "NameArg as _wxString ptr"
is often optional and i define it "NameArg as _wxString ptr=WX_NULL"
in some cases it isn't optional and it will crash with an NULL pointer.

Again not a big thing but i must rewrite it all :-(

How ever i like wxWidgets i build a X11 only verion on Linux without GTK+
that means all widgets are createt pixel by pixel and it works.
(i know how many work are behind it)

Joshy
edit:
@ike you are right i saw the message on the console

It isn't from the GLCanvas alone it's more from wxTimer.

change
wxTimer_Start(Ticker,10)
to
wxTimer_Start(Ticker,10,WX_TRUE)

this will shot the timer only once and if you close the window
the error message are gone.

May be we must register an WINDOW_CLOSE event and stop the timer if the event fired.

First i was thinking it's a missing wxTimer_Stop() in OnExit()
but if it crashed OnExit() will never be called.
I will see how to fix it i'm sure it isn't a big thing
D.J.Peters
Posts: 8588
Joined: May 28, 2005 3:28
Contact:

Post by D.J.Peters »

I was not really lucky with the wxNet version of the wxEvtHandler.
Today i wrote a new wxEvtHandler C++ class.
It's now 1:1 as the original wxEvtHandler class and complete.
(no stupid proxi and iListner stuff any more)

Code: Select all

#include once "common.bi"

type Virtual_EventHandler as sub APICALL (event as _wxEvent ptr)

' wx-c wxEvtHandler
_DS(wxEvtHandler_Connect)(self      as _wxEvtHandler ptr, _
                          typ       as  wxEventType, _
                          veh       as  Virtual_EventHandler, _
                          UserData  as _wxObject     ptr = WX_NULL, _
                          eventSink as _wxEvtHandler ptr = WX_NULL)

_DS(wxEvtHandler_ConnectById)(self      as _wxEvtHandler ptr, _
                              id        as  wxInt, _
                              typ       as  wxEventType, _
                              veh       as  Virtual_EventHandler, _
                              UserData  as _wxObject     ptr = WX_NULL, _
                              eventSink as _wxEvtHandler ptr = WX_NULL)

_DS(wxEvtHandler_ConnectByIds)(self      as _wxEvtHandler ptr, _
                               id        as  wxInt, _
                               lastId    as  wxInt, _
                               typ       as  wxEventType, _
                               eh        as  Virtual_EventHandler, _
                               UserData  as _wxObject     ptr = WX_NULL, _
                               eventSink as _wxEvtHandler ptr = WX_NULL)

_DS(wxEvtHandler_AddPendingEvent)(self as _wxEvtHandler ptr, event as _wxEvent ptr)
_DF(wxEvtHandler_ProcessEvent)(self as _wxEvtHandler ptr, event as _wxEvent ptr) as wxBool

_DS(wxEvtHandler_SetClientData)(self as _wxEvtHandler ptr,cd as any ptr)
_DF(wxEvtHandler_GetClientData)(self as _wxEvtHandler ptr) as any ptr

_DS(wxEvtHandler_SetClientObject)(self as _wxEvtHandler ptr, cdo as _wxClientData ptr)
_DF(wxEvtHandler_GetClientObject)(self as _wxEvtHandler ptr) as _wxClientData ptr

_DS(wxEvtHandler_SetEvtHandlerEnabled)(self as _wxEvtHandler ptr, enabled as wxBool)
_DF(wxEvtHandler_GetEvtHandlerEnabled)(self as _wxEvtHandler ptr) as wxBool

_DS(wxEvtHandler_SetNextHandler)(self as _wxEvtHandler ptr, handler as _wxEvtHandler ptr)
_DF(wxEvtHandler_GetNextHandler)(self as _wxEvtHandler ptr) as _wxEvtHandler ptr

_DS(wxEvtHandler_SetPreviousHandler)(self as _wxEvtHandler ptr, handler as _wxEvtHandler ptr)
_DF(wxEvtHandler_GetPeviousHandler)(self as _wxEvtHandler ptr) as _wxEvtHandler ptr
The wxEvent class is complete too now.

The Windows part is in the download Linux tomorror.
(i have curently no Linux at my office )

Sorry if you must change your exists code a litle bit.

@ike please try the glcanvas01.bas again thank you

Joshy
Post Reply