Lothar Schirm wrote:Thank you and Rod very much for your help. I am on the way now.
As part of our conversion from PowerBasic/EZGUI to FreeBasic/FLTK, we decided to isolate all FLTK code in its own namespace. The main reason for doing this was that our PowerBasic code uses Strings, whereas FLTK uses ZStrings, which would add confusion to our code. Also, FLTK operates at a fairly low level, and we didn't want to clutter our application code with irrelevant details.
Here are some code snippets that show how we use FLTK. If you're interested in learning more about my macros, naming conventions, classes, program structure, etc, I'd be happy to go into more detail.
Warning we make heavy use of macros to simplify our code and make it easy to understand. Treat these samples as pseudo code.
The following code initializes the application and builds the main window:
Code: Select all
'
'-----------------------------------------------
'
BeginExternalSubroutine(subMain)
'
' package mainline procedure
'
modApp.exsPackageCode = sSYS_DD
modApp.exsPackageName = "DVS Data Dictionary"
modApp.exnMajor = 6
modApp.exnMinor = 1
modApp.exnBuildNumber = 1
modApp.exsVersionText = "6.1.1"
modApp.expCBStart = ProcPtr(subSignIn) ' 16773 : callback ptr: activate package startup operations
modApp.expCBNormal = ProcPtr(subNormalOperations) ' 16774 : callback ptr: activate normal package operations
modApp.expCBCrash = ProcPtr(subCrashRecovery) ' 16775 : callback ptr: activate package crash recovery operations
modApp.expCBInstall = ProcPtr(subPackageInstallation) ' 16776 : callback ptr: activate package installation operations
modApp.expCBRegister = ProcPtr(subPackageRegistration) ' 16789 : callback ptr: activate package registration
'
proAppWindow->exsCaption = "DVS Data Dictionary" ' 15328 : caption text
proAppWindow->exiBaseWidth = iWINDOW_BASE_WIDTH ' 16415 : nominal width of the gui object (pixels)
proAppWindow->exiBaseHeight = iWINDOW_BASE_HEIGHT ' 16416 : nominal height of the gui object (pixels)
proAppWindow->exlResizeAllowed = True ' 16405 : true = gui object can be resized
proAppWindow->expCBDesign = ProcPtr(subDesignWindow) ' 16080 : callback ptr: design an object
proAppWindow->subBuild()
'
modApp.subInitializePackage()
'
modGui.subEventLoop() ' process the event loop
'
EndExternalSubroutine
Here are the two include files that define the main window class, followed by selected procedures from the FLTK namespace:
Code: Select all
'===============================================
'
' file name : clsWindow-i.bi
' description : Window Class (Interface)
' reference : 6016
' date generated : 2015-06-16 14:53
' configuration : FB 1.02.1 (FLTK 1.3.3), 32bit, Linux & Windows
' copyright : 1977-2015, Rod Gobby
'
'===============================================
'
BeginClass(clsWindow)
'
BeginClassInterface BaseClass(clsGadget) ' extends the Gadget Class
'
'===============================================
'
ProtectedInterface
'
' Protected file handle control blocks
'
'
' Protected file records
'
'
' Protected file objects
'
'
' Protected variables
'
'
' Protected property variables: read/write
'
'
' Protected property variables: read only
'
'
' Protected property variables: write only
'
ProtectedPointer(prpCBDesign) ' 16080 : callback ptr: design an object
'
' Protected procedures
'
'
'===============================================
'
PublicInterface
'
' Public properties: read/write
'
'
' Public properties: read only
'
'
' Public properties: write only
'
DeclarePublicSetPointer(expCBDesign, prpCBDesign)
'
' Public procedures
'
DeclarePublicConstructor
DeclarePublicDestructor
DeclarePublicVirtualFunction(funEvents, typInt32) ' Virtual: process the gadget events
DeclarePublicVirtualSubroutine(subBuild) ' Virtual: build this object
'
'===============================================
'
EndClassInterface
'
EndClass
'
'===============================================
' end of : clsWindow-i.bi
'===============================================
'===============================================
'
' file name : clsWindow-p.bi
' description : Window Class (Procedures)
' reference : 6016
' date generated : 2015-06-16 14:53
' configuration : FB 1.02.1 (FLTK 1.3.3), 32bit, Linux & Windows
' copyright : 1977-2015, Rod Gobby
'
'===============================================
'
BeginClass(clsWindow)
'
BeginClassProcedures
'
'===============================================
'
' Public Properties
'
'-----------------------------------------------
'
' Public properties: read/write
'
'
'-----------------------------------------------
'
' Public properties: read only
'
'
'-----------------------------------------------
'
' Public properties: write only
'
PublicSetPointer(expCBDesign, prpCBDesign)
'
'===============================================
'
' Procedures
'
'-----------------------------------------------
'
BeginPublicConstructor
'
' Procedure 1 :
'
'
'
priReferenceNumber = iCLASS_TYPE_WINDOW ' 16447 : the entity number for the module, program, package, etc
EndPublicConstructor
'
'-----------------------------------------------
'
BeginPublicDestructor
'
' Procedure 2 :
'
'
EndPublicDestructor
'
'-----------------------------------------------
'
BeginPublicVirtualFunction(funEvents, typInt32)
'
' Procedure 3 : Virtual: process the gadget events
'
'
'
' not used -- placeholder only
'
EndPublicFunction
'
'-----------------------------------------------
'
BeginPublicVirtualSubroutine(subBuild)
'
' Procedure 4 : Virtual: build this object
'
'
subApplyExternalResizeRules()
prpWidgetRef = modGui.funWindowCreate(priActualLeft, priActualTop, priActualWidth, priActualHeight, prsCaption)
modGui.subWindowSetGadgetSelf(prpWidgetRef, prpSelf) ' link this window to its widget
modGui.subWindowSetTerminator(prpWidgetRef) ' link to the window terminator callback
If IsTrue(prlResizeAllowed) And IsFalse(prlShrinkAllowed) Then
modGui.subWindowBounds(prpWidgetRef, priBaseWidth, priBaseHeight) ' set the minimum window size
End If
modGui.subWindowBegin(prpWidgetRef) ' begin window design
PerformCallback(prpCBDesign) ' design the window
modGui.subWindowEnd(prpWidgetRef) ' end window design
modGui.subWindowShow(prpWidgetRef) ' show the application window
EndPublicSubroutine
'
'===============================================
'
EndClassProcedures
'
EndClass
'
'===============================================
' end of : clsWindow-p.bi
'===============================================
Here are FLTK procedures used by the above code, plus a few others:
Code: Select all
'===============================================
'
' file name : modGui-p.bi
' description : Gui Support (FLTK) (Procedures)
' reference : 6080
' date generated : 2015-06-16 14:59
' configuration : FB 1.02.1 (FLTK 1.3.3), 32bit, Linux & Windows
' copyright : 1977-2015, Rod Gobby
'
'===============================================
'
BeginNamespace(modGui)
'
BeginNamespaceProcedures
'
'===============================================
'
' Procedures
'
'-----------------------------------------------
'
BeginPrivateSubroutineCdecl(subWindowTerminator, BPtr(bvpWindowRef))
'
' Procedure 3 : Cdecl: window terminator callback
'
' bvpWindowRef 16400 : fltk window reference
'
If Fl_EventNumber = FL_EVENT_SHORTCUT And Fl_EventKey = FL_Escape Then
Return ' ignore an escape key
End If
Fl_WindowHide(bvpWindowRef) ' terminate the program if no escape key
EndPrivateSubroutine
'
'-----------------------------------------------
'
BeginPrivateFunctionCdecl(funWidgetEventRouter, typInt32, BPtr(bvpWidgetRef), BObj(broGenericGadget, objGadget))
'
' Procedure 4 : Cdecl: widget event router
'
' bvpWidgetRef 16882 : fltk widget reference
' broGenericGadget 16407 : generic gadget object
'
LocalField(iReturnCode, typInt32) ' 15050 : generic return code
iReturnCode = iGUI_EVENT_IGNORED ' assume the event is not processed
If IsObject(broGenericGadget) Then
If IsTrue(broGenericGadget->exlEventsBlocked) Then
iReturnCode = iGUI_EVENT_USED ' prevent further propogation of the event
Else
iReturnCode = broGenericGadget->funEvents() ' process the event
End If
End If
Return iReturnCode
EndPrivateFunction
'
'-----------------------------------------------
'
BeginExternalSubroutine(subEventLoop)
'
' Procedure 5 : process the event loop
'
'
Fl_Run
EndExternalSubroutine
'
'-----------------------------------------------
'
BeginExternalFunction(funWindowCreate, typPointer, BVal(bviBaseLeft, typInt32), BVal(bviBaseTop, typInt32), BVal(bviBaseWidth, typInt32), BVal(bviBaseHeight, typInt32), BRef(brsCaption, typString))
'
' Procedure 9 : create a window
'
' bviBaseLeft 16413 : nominal left position of the gui object (pixels)
' bviBaseTop 16414 : nominal top position of the gui object (pixels)
' bviBaseWidth 16415 : nominal width of the gui object (pixels)
' bviBaseHeight 16416 : nominal height of the gui object (pixels)
' bvsCaption 15328 : caption text
'
LocalPointer(pWindowRef) ' 16400 : fltk window reference
pWindowRef = Fl_Double_WindowNew2(bviBaseLeft, bviBaseTop, bviBaseWidth, bviBaseHeight, StrPtr(brsCaption))
Return pWindowRef
EndExternalFunction
'
'-----------------------------------------------
'
BeginExternalSubroutine(subWindowDestroy, BPtr(bvpWindowRef))
'
' Procedure 10 : destroy a window
'
' bvpWindowRef 16400 : fltk window reference
'
subWindowTerminator(bvpWindowRef)
EndExternalSubroutine
'
'-----------------------------------------------
'
BeginExternalSubroutine(subWindowBounds, BPtr(bvpWindowRef), BVal(bviBaseWidth, typInt32), BVal(bviBaseHeight, typInt32))
'
' Procedure 11 : set the minimum size of a window
'
' bvpWindowRef 16400 : fltk window reference
' bviBaseWidth 16415 : nominal width of the gui object (pixels)
' bviBaseHeight 16416 : nominal height of the gui object (pixels)
'
Fl_WindowSizeRange(bvpWindowRef, bviBaseWidth, bviBaseHeight, 0, 0)
EndExternalSubroutine
'
'-----------------------------------------------
'
BeginExternalSubroutine(subWindowShow, BPtr(bvpWindowRef))
'
' Procedure 12 : show a window
'
' bvpWindowRef 16400 : fltk window reference
'
Fl_WindowShow(bvpWindowRef)
EndExternalSubroutine
'
'-----------------------------------------------
'
BeginExternalSubroutine(subWindowBegin, BPtr(bvpWindowRef))
'
' Procedure 15 : begin the window design
'
' bvpWindowRef 16400 : fltk window reference
'
Fl_WindowBegin(bvpWindowRef)
EndExternalSubroutine
'
'-----------------------------------------------
'
BeginExternalSubroutine(subWindowEnd, BPtr(bvpWindowRef))
'
' Procedure 16 : end the window design
'
' bvpWindowRef 16400 : fltk window reference
'
Fl_WindowEnd(bvpWindowRef)
EndExternalSubroutine
'
'-----------------------------------------------
'
BeginExternalSubroutine(subWindowSetTerminator, BPtr(bvpWindowRef))
'
' Procedure 17 : link the window to the terminator callback
'
' bvpWindowRef 16400 : fltk window reference
'
Fl_WidgetSetCallback0(bvpWindowRef, ProcPtr(subWindowTerminator))
EndExternalSubroutine
'
'-----------------------------------------------
'
BeginExternalSubroutine(subWindowSetGadgetSelf, BPtr(bvpWindowRef), BPtr(bvpSelf))
'
' Procedure 18 : link a window to its gadget object instance
'
' bvpWindowRef 16400 : fltk window reference
' bvpSelf 16898 : reference to the current gui object
'
Fl_WidgetSetUserData(bvpWindowRef, bvpSelf)
EndExternalSubroutine
'
'-----------------------------------------------
'
BeginExternalFunction(funWindowGetGadgetSelf, typPointer, BPtr(bvpWindowRef))
'
' Procedure 19 : return the window`s gadget object reference
'
' bvpWindowRef 16400 : fltk window reference
'
LocalPointer(pSelf) ' 16898 : reference to the current gui object
pSelf = Fl_WidgetGetUserData(bvpWindowRef)
Return pSelf
EndExternalFunction
'
'-----------------------------------------------
'
BeginExternalSubroutine(subWindowSetToolTip, BPtr(bvpWindowRef), BRef(brsToolTip, typString))
'
' Procedure 20 : define a window tooltip
'
' bvpWindowRef 16400 : fltk window reference
' bvsToolTip 16421 : tooltip text: blank = no tooltip
'
If NotNull(brsToolTip) Then
Fl_WidgetSetTooltip(bvpWindowRef, StrPtr(brsToolTip))
End If
EndExternalSubroutine
'
'===============================================
'
EndNamespaceProcedures
'
EndNamespace
'
'===============================================
' end of : modGui-p.bi
'===============================================