FLTK 1.3.x C Wrapper (obsolete)

User contributed sources that have become inactive, deprecated, or generally unusable. But ... we don't really want to throw them away either.
Post Reply
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by D.J.Peters »

@nimdays post a "short" working example with the problem, please.

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

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by D.J.Peters »

Ok I see what you are trying.

The Help_View widget is an kind of "offline" web browser.

A online URL like http://doman.xyz/index.html are redirected to your default browser.

change it to a local URL file://index.html

Joshy

Code: Select all

#include once "fltk-c.bi"

function LinkCB cdecl (byval self as Fl_Widget ptr,byval uri as const zstring ptr) as const zstring ptr
  print "LinkCB: uri  " & *uri
  print "LinkCB: file " & *flFilenameName(uri)
  return flFilenameName(uri)
end function

Fl_Register_Images()
var win = Fl_Double_WindowNew(640,480, "Fl_Help_View04")
var hv  = Fl_Help_ViewNew(10,10,620,460)
Fl_Help_ViewLink hv,@LinkCB
Fl_Help_ViewLoad hv,"file://www.freebasic.net/forum/index.php"
Fl_GroupSetResizable win,hv
Fl_WindowShow win
Fl_Run
Last edited by D.J.Peters on Aug 01, 2015 20:57, edited 2 times in total.
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by nimdays »

This is based from your example

Code: Select all

#include once "fltk-c.bi"
dim as string html = "http://www.freebasic.net/forum"
var win = Fl_WindowNew(640,480)
var hv  = Fl_Help_ViewNew(10,10,620,460)
Fl_Help_ViewLoad hv,html
Fl_GroupSetResizable win,hv
Fl_WindowShow win
Fl_Run
Thanks for the info , is there any way for online browser ?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by D.J.Peters »

nimdays wrote:... is there any way for online browser ?
you have to download the pages to view it as local files.

Use the command line tool wget or simple network connection

Or you create a web browser widget by extending the Fl_Help_View widget with download function.

Joshy
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by nimdays »

Thanks Man , i'll try that :)
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by nimdays »

Hello again , i have a problem with png and switched to syslib
and then this message "ld: cannot find -lzlib"
Solved after changed "#inclib "zlib" to "z"
Btw can you upload fltk-c.tar.gz , can't find it from your site
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by D.J.Peters »

D.J.Peters wrote:FreeBASIC libraries and tests: fltk-c-1.3.3.zip Mon Jul 27, 2015 10:45 pm
Looks like your fltk-c isn't up to date syslib is the default mode for Linux.

Joshy

Code: Select all

#ifdef __FB_WIN32__
 #ifndef __FB_64BIT__
  #inclib "fltk-c-1.3.3-32" ' Windows 32-bit
 #else
  #inclib "fltk-c-1.3.3-64" ' Windows 64-bit
 #endif
#else
 #ifndef NOSYSLIB
  #ifndef __FB_64BIT__
   #inclib "fltk-c-1.3.3-32-syslib" ' Linux 32-bit will use syslib's libjpeg,libpng,libz from your distro
  #else
   #inclib "fltk-c-1.3.3-64-syslib" ' Linux 64-bit with use syslib's libjpeg,libpng,libz from your distro
  #endif
  #inclib "png"
  #inclib "jpeg"
  #inclib "z"
 #else
  #ifndef __FB_64BIT__
   #inclib "fltk-c-1.3.3-32" ' Linux 32-bit
  #else
   #inclib "fltk-c-1.3.3-64" ' Linux 64-bit
  #endif
 #endif
 ' #inclib "Xcursor" ' if you get open references to color icon support on linux
#endif
Last edited by D.J.Peters on Oct 03, 2017 4:10, edited 1 time in total.
angros47
Posts: 2324
Joined: Jun 21, 2005 19:04

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by angros47 »

Sorry for the OT, but I was wondering... on January, you said you were working on a 3d engine: how is it going? Is there already any preview?
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by D.J.Peters »

angros47 wrote:Sorry for the OT, but I was wondering... on January, you said you were working on a 3d engine: how is it going? Is there already any preview?
Sorry I don't work on a 3D engine.
If I need a modern engine I can use Irrlicht with C++.

Joshy
nimdays
Posts: 236
Joined: May 29, 2014 22:01
Location: West Java, Indonesia

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by nimdays »

D.J.Peters wrote:
D.J.Peters wrote:FreeBASIC libraries and tests: fltk-c-1.3.3.zip Mon Jul 27, 2015 10:45 pm
Looks like your fltk-c isn't up to date syslib is the default mode for Linux.

Thanks i missed that , sorry for my late reply , i have this small project MInux
Png give me a headache , i you have spare time ,can you test png with tiny core ?
I have to use custom png loader to load the image
I have another issue with flInput under linux (windows is ok)

Code: Select all

flmessage "test" 'i must put this or segmentation fault
?*flInput ("test","")
Thanks
WQ1980
Posts: 48
Joined: Sep 25, 2015 12:04
Location: Russia

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by WQ1980 »

Hi!
Need a example functions
Fl_Copy and Fl_Paste in Linux

This code:

Code: Select all

#Include Once "fltk-c.bi"

Dim as String sClipboard = "FLTK"

Fl_Copy(sClipboard, Len(sClipboard), 1)
In Ubuntu 12.04 and FreeBasic 1.00 -->

Segmentation fault (core dumped)
------------------
(program exited with code: 139)
Last edited by WQ1980 on Sep 30, 2015 13:00, edited 1 time in total.
WQ1980
Posts: 48
Joined: Sep 25, 2015 12:04
Location: Russia

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by WQ1980 »

Up
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by D.J.Peters »

Where is your GUI ?

On Linux the clipboard is a part of the running desktop-manager (XLib).
Without a GUI do not have a connection to the XServer.
If you create a FLTK widget it opens a connection via XOpen().

bla bla bla :-)

Joshy

Code: Select all

#include once "fltk-c.bi"
var msg = "message"
var win = Fl_WindowNew(640,480,"clipboard")
Fl_WindowShow win
Fl_Copy msg,len(msg),1
Fl_Run
Run this short test from your favorite linux IDE / editor and press [ctrl]+[v] (paste)
the "message" will be copied from clipboard to your source code.
WQ1980
Posts: 48
Joined: Sep 25, 2015 12:04
Location: Russia

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by WQ1980 »

D.J.Peters wrote:Where is your GUI ?

On Linux the clipboard is a part of the running desktop-manager (XLib).
Without a GUI do not have a connection to the XServer.
If you create a FLTK widget it opens a connection via XOpen().

bla bla bla :-)

Joshy

Code: Select all

#include once "fltk-c.bi"
var msg = "message"
var win = Fl_WindowNew(640,480,"clipboard")
Fl_WindowShow win
Fl_Copy msg,len(msg),1
Fl_Run
Run this short test from your favorite linux IDE / editor and press [ctrl]+[v] (paste)
the "message" will be copied from clipboard to your source code.
Thanks!

Yes, I have a GUI :)
Below my "little" code InpExBox -> my extended input widget (no optimization)

Problem -> Copy and Paste to\from clipboard in Windows\Linux with hotkeys and menu

Right now:

ctrl+c -> work
ctrl+x -> work

ctrl+v -> not work
Line 683

Code: Select all

Fl_Paste(pThis->m_Widget, 1)
Next -> handling FL_EVENT_PASTE ?
not work -> exit code

And how to make popup menu in extended widget:
Cut
Copy
Paste
and etc.?

Code:

Code: Select all

''InpExBox -> extended input FLTK widget (no optimization) by WQ1980, 2015

#Include "crt.bi"
#Include Once "fltk-c.bi"

Dim Shared win As Fl_Double_Window Ptr

Type InpExBox
	Declare Constructor (ByVal x As Long, _
	ByVal y As Long, _
	ByVal w As Long, _
	ByVal h As Long, _
	ByVal InpExStr As ZString Ptr=0)
	'Declare Operator Cast As Fl_Widget Ptr

	Declare Function getText Cdecl () As String
	Declare Sub setText Cdecl (ByVal InpExStr As ZString Ptr)

	Declare Function Update Cdecl(ByVal xX As Integer   = 0) As Integer
	Declare Function Arr Cdecl () As Integer
	Declare Function StoUTF Cdecl(Liste As ZString Ptr, arutf() As Integer) As Integer
	Declare Sub GetUtf Cdecl ()
	Declare Sub GetTextW Cdecl ()
	Declare Sub DelDiap Cdecl (ByVal index As Integer = 0)


	Declare Static Function DrawCB Cdecl (ByVal me As Any Ptr) As Long
	Declare Static Function ResizeCB Cdecl (ByVal me As Any Ptr, _
	ByVal x As Long, _
	ByVal y As Long, _
	ByVal w As Long, _
	ByVal h As Long) As Long
	Declare Static Function HandleCB Cdecl (ByVal me As Any Ptr, _
	ByVal event As FL_EVENT) As Long
	As Fl_WidgetEx Ptr m_Widget

	As String       m_Label
	As Long         m_Enter
	As Long         m_Down
	As Long         m_Up
	As Long         m_Down_PUSH
	As Long         m_Up_PUSH
	As Long         m_Click
	As Long         m_PUSH
	As Long         m_DablClick
	As Long         m_Drag
	As Long         m_MoveCursor
	As Long         m_SW
	As Double       dabl_timer
	As Integer ux, uy, uw, uh, dx, dy, dw, dh, cx, cx0, textw, aCX1(Any), _
	uu1, uu0, tx0, tx1, ind0, ind1, w0cl, le0
	As String ts, tsv
End Type

Constructor InpExBox(ByVal x As Long, _
	ByVal y As Long, _
	ByVal w As Long, _
	ByVal h As Long, _
	ByVal InpExStr As ZString Ptr)
	m_Widget = Fl_WidgetExNew(x,y,w,h, "")
	Fl_WidgetSetLabelColor m_Widget, FL_WHITE

	ts = *InpExStr

	Fl_WidgetSetUserData    m_Widget, @This
	Fl_WidgetExSetDrawCB    m_Widget, @DrawCB
	Fl_WidgetExSetHandleCB  m_Widget, @HandleCB
	Fl_WidgetExSetResizeCB  m_Widget, @ResizeCB
	m_DablClick=0
	m_Enter=0
	m_Down=0
	m_Up=0
	m_Click=0

	m_PUSH=0
	m_Drag=0
	m_MoveCursor = 0
	m_Down_PUSH=0
	m_Up_PUSH=0

	uw=w/4.5
	uh= h/2-2
	ux = x+w-uw-2
	uy=y+2
	dw=w/4.5
	dh=h/2-2
	dx = x+w-dw-2
	dy=y+h/2
	w0cl=10

	tx0= x+50

	ind0=0
	ind1=0
	m_SW=0
End Constructor

Function InpExBox.ResizeCB Cdecl (ByVal me As Any Ptr, _
	ByVal x As Long, _
	ByVal y As Long, _
	ByVal w As Long, _
	ByVal h As Long) As Long
	Dim As InpExBox Ptr pThis = Fl_WidgetGetUserData(me)

	pThis->uw=w/4.5
	pThis->uh= h/2-1
	pThis->ux = x+w-pThis->uw-2
	pThis->uy=y+2
	pThis->dw=w/4.5
	pThis->dh=h/2-2
	pThis->dx = x+w-pThis->dw-2
	pThis->dy=y+h/2
	Fl_WidgetRedraw me
	Return 1
End Function

Function InpExBox.getText Cdecl () As String
	Return ts
End Function

Sub InpExBox.setText Cdecl (ByVal InpExStr As ZString Ptr)
	Dim As InpExBox Ptr pThis = Fl_WidgetGetUserData(m_Widget)

	pThis->ts = *InpExStr
	pThis->Arr()
	m_SW=0
	Fl_WidgetRedraw m_Widget
End Sub

Sub InpExBox.GetUtf Cdecl ()
	Dim As InpExBox Ptr pThis = Fl_WidgetGetUserData(m_Widget)
	pThis->ts=""
	pThis->textw=0
	Dim As ZString*10 zz
	Dim As Integer  l
	For j As Integer = 0 To UBound(pThis->aCX1)
		l=Fl_utf8encode(pThis->aCX1(j),@zz)
		If l=1 Then
			pThis->ts &=Chr(pThis->aCX1(j))
		Else
			pThis->ts &=zz
		EndIf
		pThis->textw +=DrawGetCharWidth(pThis->aCX1(j))
	Next
End Sub

Sub InpExBox.GetTextW Cdecl ()
	Dim As InpExBox Ptr pThis = Fl_WidgetGetUserData(m_Widget)
	pThis->textw=0
	For j As Integer = 0 To UBound(pThis->aCX1)
		pThis->textw += DrawGetCharWidth(pThis->aCX1(j))
	Next
	If pThis->textw=0 Then pThis->m_DablClick=0
End Sub

Sub InpExBox.DelDiap Cdecl (ByVal index As Integer  = 0 )
	Dim As InpExBox Ptr pThis = Fl_WidgetGetUserData(m_Widget)
	Var w = Fl_WidgetGetW(m_Widget)-50
	Dim As Integer uu0, uu1

	If pThis->uu1 >= pThis->uu0 Then
		uu0=pThis->uu0
		uu1=pThis->uu1
	Else
		uu1=pThis->uu0
		uu0=pThis->uu1
	EndIf
	Dim As Integer l
	Dim As ZString*10 zz
	Dim As String msg

	If index > 0 Then
		For j As Integer = uu0 To uu1
			l=Fl_utf8encode(pThis->aCX1(j),@zz)
			If l=1 Then
				msg &=Chr(pThis->aCX1(j))
			Else
				msg &=zz
			EndIf
		Next
		Fl_Copy (msg, Len(msg), 1)
	EndIf

	If index = 2 Then Exit Sub

	If (uu1 = UBound(pThis->aCX1) And uu0 = 0) Then
		pThis->ts=""
		pThis->uu1= -1
		pThis->cx = 0
		ReDim pThis->aCX1(-1)
		pThis->GetTextW()
	Else

		For j As Integer =  uu0 To uu1

			Dim As Integer r
			r=pThis->aCX1(pThis->uu1)
			For i As Integer = uu0 To UBound(pThis->aCX1)-1
				Swap pThis->aCX1(i), pThis->aCX1(i+1)
			Next
			ReDim Preserve pThis->aCX1(UBound(pThis->aCX1)-1)

			If pThis->uu1 >= pThis->uu0 Then
				pThis->uu1 -= 1
				If pThis->uu1 < 0 Then
					pThis->uu1= -1
					pThis->cx=0
				EndIf
			EndIf

			If pThis->uu1 < pThis->ind0 Then
				pThis->ind0 -= 1
				If pThis->ind0 < 0 Then
					pThis->ind0 = 0
				EndIf
			EndIf

			pThis->GetUtf()
			If pThis->ind1>UBound(pThis->aCX1)Then pThis->ind1=UBound(pThis->aCX1)
		Next

		If pThis->cx > 0 Then
			Dim As Integer tttw
			For i As Integer = pThis->ind0 To uu0-1
				tttw += DrawGetCharWidth(pThis->aCX1(i))
			Next
			pThis->cx=tttw
			pThis->GetTextW()
			If pThis->textw <= w - pThis->tx0 Then
				pThis->ind0=0
				pThis->ind1=UBound(pThis->aCX1)
			EndIf
		EndIf
	EndIf
	pThis->m_DablClick=0
	pThis->m_Drag=0
End Sub

Function InpExBox.HandleCB Cdecl (ByVal me As Any Ptr,ByVal event As FL_EVENT) As Long
	Dim As InpExBox Ptr pThis = Fl_WidgetGetUserData(me)

	Var x = Fl_WidgetGetX(me)
	Var y = Fl_WidgetGetY(me)
	Var w = Fl_WidgetGetW(me)-50
	Var h = Fl_WidgetGetH(me)

	Var tx=x+4

	Select Case As Const event
		Case FL_EVENT_UNFOCUS, FL_EVENT_DRAG
			pThis->m_DablClick=0
			'pThis->m_Drag=0
		Case FL_EVENT_PUSH
			If Fl_EventButton1()>0 Or Fl_EventButton1()>0 Then
				pThis->m_Drag=0
				pThis->m_DablClick=0
			EndIf
		Case FL_EVENT_KEYDOWN
			Select Case Fl_EventKey()
				Case FL_Home, FL_Left, FL_Right, FL_End
					pThis->m_DablClick=0
					pThis->m_Drag=0
			End Select
	End Select

	Static As Integer ActiveDND = 0

	Select Case As Const event
		Case FL_EVENT_UNFOCUS
			pThis->m_Click=0
			Fl_WindowCursor(me,FL_CURSOR_DEFAULT)
			Fl_WidgetRedraw me

		Case FL_EVENT_RELEASE

			pThis->dabl_timer=Timer

			If pThis->m_PUSH=1 Then
				pThis->m_Click=1
				pThis->cx=Fl_EventX
				pThis->Update(Fl_EventX)
				pThis->m_PUSH=0

				If pThis->m_Drag=1 Then
					If pThis->uu0 > pThis->uu1 Then
						pThis->uu0 -=1
						pThis->uu1 +=1
						Swap pThis->uu0, pThis->uu1
					EndIf
				EndIf
				Fl_WidgetRedraw me
			EndIf

		Case FL_EVENT_PUSH

			pThis->le0=Fl_EventX

			If (Timer-pThis->dabl_timer) < 0.20 And Fl_EventButton1()>0 Then
				pThis->dabl_timer=Timer
				pThis->GetTextW()

				If pThis->textw>0 Then
					pThis->m_DablClick = 1

					Var ind=0
					For j As Integer = pThis->uu1-1 To 0 Step -1
						If pThis->aCX1(j)=32 Then
							pThis->uu0=j+1
							ind=1
							Exit For
						EndIf
					Next

					If ind=0 Then pThis->uu0 = 0
					ind=0

					Dim As Integer uu1 = pThis->uu1

					For j As Integer = uu1 To UBound(pThis->aCX1)
						If pThis->aCX1(j)=32 Then
							pThis->uu1=j-1
							ind=1
							Exit For
						EndIf
					Next
					If ind=0 Then pThis->uu1 = UBound(pThis->aCX1)
					Fl_WidgetRedraw me
				EndIf

				Return Fl_WidgetExHandleBase(pThis->m_Widget,event)

			EndIf

			Fl_WindowCursor(me,FL_CURSOR_INSERT)

			If Fl_EventButton1()>0 Then
				Fl_SetFocus(me)
				pThis->m_PUSH=1
				'Fl_WidgetRedraw me
			ElseIf Fl_EventButton2()>0 Then
				Fl_SetFocus(me)
				pThis->ts = ""
				pThis->uu1 = -1
				pThis->cx = 0
				ReDim pThis->aCX1(-1)
				pThis->GetTextW()
				pThis->ind1=0
				Fl_WidgetRedraw me
			EndIf
		Case FL_EVENT_DRAG

			pThis->GetTextW()

			If pThis->textw>0 And Fl_EventButton1() > 0 Then

				pThis->Update(Fl_EventX)
				If pThis->m_Drag=0 Then
					pThis->uu0 = pThis->uu1+1
					pThis->cx0 = pThis->cx

					pThis->m_Drag=1
				EndIf

				If pThis->uu1 <= UBound(pThis->aCX1) And Fl_EventX - x  + pThis->w0cl >= w  Then
					pThis->uu1 +=1
					If pThis->uu1 > -1 Then
						pThis->ind0 += 1
						pThis->ind1 += 1
					EndIf
				EndIf

				If Fl_EventX - x  + pThis->w0cl <= pThis->tx0 Then
					If pThis->uu1 < pThis->ind0 Then

						pThis->ind0 -= 1

						If pThis->ind0 < 0 Then
							pThis->ind0 = 0
						Else
							Dim As Integer tttw
							For j As Integer = pThis->ind0 To pThis->ind1
								tttw += DrawGetCharWidth(pThis->aCX1(j))
								If tttw >= w - pThis->tx0 Then
									pThis->ind1=j
									pThis->cx0=tttw
									Exit For
								EndIf
							Next
						EndIf
					EndIf
				EndIf

				If pThis->uu1 >= UBound(pThis->aCX1) Then
					Dim As Integer tttw
					If pThis->textw >= w - pThis->tx0  Then
						For j As Integer = UBound(pThis->aCX1) To 0 Step -1
							tttw += DrawGetCharWidth(pThis->aCX1(j))
							If tttw >= w - pThis->tx0  Then
								pThis->ind0 = j
								pThis->ind1 = UBound(pThis->aCX1)
								Exit For
							EndIf
						Next
					EndIf
					pThis->uu1=UBound(pThis->aCX1)
				EndIf

				If pThis->ind0 > pThis->uu0 Then pThis->cx0=0

				If Abs(Fl_EventX-pThis->le0) < DrawGetStrWidth(":") Then pThis->m_Drag=0

				Fl_WidgetRedraw me
			Else

			EndIf


		Case FL_EVENT_KEYDOWN

			Select Case Fl_EventKey()
				Case FL_Left

					pThis->cx -= DrawGetCharWidth(pThis->aCX1(pThis->uu1))

					If pThis->cx < 0 Then
						pThis->cx=0
					EndIf

					pThis->uu1 -=1

					If pThis->cx=0 Then
						pThis->uu1 = -1
					EndIf

					If pThis->uu1 < pThis->ind0 Then

						pThis->ind0 -= 1

						If pThis->ind0 < 0 Then
							pThis->ind0 = 0
						Else
							Dim As Integer tttw
							For j As Integer = pThis->ind0 To pThis->ind1
								tttw += DrawGetCharWidth(pThis->aCX1(j))
								If tttw >= w - pThis->tx0 Then
									pThis->ind1=j
									Exit For
								EndIf
							Next
						EndIf
					EndIf

				Case FL_Right
					pThis->Arr()

					pThis->uu1 +=1
					pThis->cx += DrawGetCharWidth(pThis->aCX1(pThis->uu1))

					If pThis->uu1 <= UBound(pThis->aCX1) And pThis->cx >= w - pThis->tx0 Then

						If pThis->uu1 > -1 Then
							pThis->ind0 += 1
							pThis->ind1 += 1
						EndIf

					EndIf

					If pThis->cx >= w - pThis->tx0 Then
						Dim As Integer tttw
						For j As Integer = pThis->ind1 To 0 Step -1
							tttw += DrawGetCharWidth(pThis->aCX1(j))
							If tttw >= w - pThis->tx0  Then
								pThis->ind0 = j
								pThis->cx=tttw
								Exit For
							EndIf
						Next
					EndIf

					If pThis->uu1 >= UBound(pThis->aCX1) Then
						Dim As Integer tttw
						If pThis->textw > w - pThis->tx0  Then
							For j As Integer = UBound(pThis->aCX1) To 0 Step -1
								tttw += DrawGetCharWidth(pThis->aCX1(j))
								If tttw >= w - pThis->tx0  Then
									pThis->ind0 = j
									pThis->ind1 = UBound(pThis->aCX1)
									Exit For
								EndIf
							Next
							pThis->cx = tttw
						Else
							pThis->cx = pThis->textw
						EndIf

						pThis->uu1=UBound(pThis->aCX1)
					EndIf

				Case FL_End

					pThis->Arr()
					Dim As Integer tttw
					If pThis->textw > w - pThis->tx0 Then
						For j As Integer = UBound(pThis->aCX1) To 0 Step -1
							tttw += DrawGetCharWidth(pThis->aCX1(j))
							If tttw >= w - pThis->tx0  Then
								pThis->ind0 = j
								pThis->ind1 = UBound(pThis->aCX1)
								Exit For
							EndIf
						Next
						pThis->cx = tttw
					Else
						pThis->cx = pThis->textw
						pThis->ind0=0
						pThis->ind1=UBound(pThis->aCX1)
					EndIf
					pThis->uu1 = UBound(pThis->aCX1)
				Case FL_Home
					pThis->GetTextW()
					Dim As Integer tttw
					If pThis->textw > w - pThis->tx0 Then
						For j As Integer = 0 To UBound(pThis->aCX1)
							tttw += DrawGetCharWidth(pThis->aCX1(j))
							If tttw >= w - pThis->tx0 Then
								pThis->ind0 = 0
								pThis->ind1= j
								Exit For
							EndIf
						Next
					Else
						pThis->ind0=0
						pThis->ind1=UBound(pThis->aCX1)
					EndIf

					pThis->uu1 = -1
					pThis->cx = 0

				Case FL_BackSpace

					If pThis->m_DablClick=1 Or pThis->m_Drag=1 Then

						pThis->DelDiap()

						Fl_WidgetRedraw me
						Return Fl_WidgetExHandleBase(pThis->m_Widget,event)
					EndIf

					Select Case pThis->uu1
						Case -1
							Return Fl_WidgetExHandleBase(pThis->m_Widget,event)
						Case UBound(pThis->aCX1)

							If UBound(pThis->aCX1)> 0 Then
								Dim As Integer r
								r=pThis->aCX1(UBound(pThis->aCX1))
								ReDim Preserve pThis->aCX1(UBound(pThis->aCX1)-1)
								pThis->GetUtf()
								pThis->cx -= DrawGetCharWidth(r)

								pThis->uu1 = UBound(pThis->aCX1)
								pThis->ind1 = pThis->uu1
								If pThis->ind1 > UBound(pThis->aCX1) Then pThis->ind1=UBound(pThis->aCX1)

								If pThis->uu1 < pThis->ind0 Then
									pThis->ind0 -= 1
									If pThis->ind0 < 0 Then
										pThis->ind0 = 0
									EndIf
									pThis->cx = DrawGetCharWidth(pThis->aCX1(pThis->ind0))
								EndIf
							Else
								pThis->ts=""
								pThis->uu1= -1
								pThis->cx = 0
								ReDim pThis->aCX1(-1)
								pThis->GetTextW()
							EndIf

						Case Else

							Dim As Integer r
							r=pThis->aCX1(pThis->uu1)
							For i As Integer =  pThis->uu1 To UBound(pThis->aCX1)-1
								Swap pThis->aCX1(i), pThis->aCX1(i+1)
							Next
							ReDim Preserve pThis->aCX1(UBound(pThis->aCX1)-1)

							pThis->cx -= DrawGetCharWidth(r)
							pThis->uu1 -= 1

							If pThis->uu1 < 0 Then
								pThis->uu1= -1
							EndIf

							If pThis->uu1 < pThis->ind0 Then
								pThis->ind0 -= 1
								If pThis->ind0 < 0 Then
									pThis->ind0 = 0
								EndIf
								pThis->cx = DrawGetCharWidth(pThis->aCX1(pThis->ind0))
							EndIf

							pThis->GetUtf()
							If pThis->ind1>UBound(pThis->aCX1) Then pThis->ind1=UBound(pThis->aCX1)

							If pThis->uu1=-1 Then pThis->cx=0
					End Select

					pThis->Arr()

				Case FL_Delete

					If pThis->m_DablClick=1 Or pThis->m_Drag=1 Then
						pThis->DelDiap()
						Fl_WidgetRedraw me
						Return Fl_WidgetExHandleBase(pThis->m_Widget,event)
					EndIf

					Select Case pThis->uu1

						Case UBound(pThis->aCX1)
							Return Fl_WidgetExHandleBase(pThis->m_Widget,event)
						Case -1
							If UBound(pThis->aCX1)>0 Then
								For i As Integer = 0 To UBound(pThis->aCX1)-1
									Swap pThis->aCX1(i), pThis->aCX1(i+1)
								Next
								ReDim Preserve pThis->aCX1(UBound(pThis->aCX1)-1)
								pThis->GetUtf()
							Else
								pThis->ts=""
							EndIf
							ReDim pThis->aCX1(-1)
							pThis->Arr()
							pThis->uu1 = -1
							Dim As Integer tttw
							If pThis->textw >= w - pThis->tx0  Then
								For j As Integer = 0 To UBound(pThis->aCX1)
									tttw += DrawGetCharWidth(pThis->aCX1(j))
									If tttw >= w - pThis->tx0  Then
										pThis->ind0 = 0
										pThis->ind1 = j
										Exit For
									EndIf
								Next
							EndIf
							pThis->cx = 0
						Case Else
							For i As Integer = pThis->uu1+1 To UBound(pThis->aCX1)-1
								Swap pThis->aCX1(i), pThis->aCX1(i+1)
							Next
							ReDim Preserve pThis->aCX1(UBound(pThis->aCX1)-1)
							pThis->GetUtf()

							Dim As Integer tttw
							If pThis->textw >= w - pThis->tx0  Then
								For j As Integer = pThis->ind0 To UBound(pThis->aCX1)
									tttw += DrawGetCharWidth(pThis->aCX1(j))
									If tttw >= w - pThis->tx0 Then
										pThis->ind1 = j
										Exit For
									EndIf
								Next
							EndIf
					End Select
				Case FL_SHIFT, FL_Shift_L, FL_Shift_R, FL_Alt_R, FL_Alt_L, FL_Control_L, FL_Control_R, FL_Meta_L, FL_Meta_R, _
					FL_Volume_Down, FL_Volume_Mute, FL_Volume_Up, FL_Media_Play,FL_Media_Stop, FL_Media_Prev,FL_Media_Next,FL_Home_Page, _
					FL_Mail, FL_Search, FL_Back, FL_Forward, FL_Stop, FL_Refresh,FL_Sleep, FL_Favorites,FL_Tab_KEY, FL_Iso_Key, FL_Enter_Key, _
					FL_Pause,FL_ScrollLock,	FL_Escape,FL_Up, FL_Down,FL_Page_Up, FL_Page_Down,	FL_Print, FL_Insert, _
					FL_Menu, FL_Help,FL_NumLock,FL_KP,FL_KP_Enter,FL_KP_Last,FL_F, FL_F_Last,FL_CapsLock, 65470 To 65481

					Return Fl_WidgetExHandleBase(pThis->m_Widget,event)
				Case Else

					pThis->GetTextW()

					Dim As String SText = *Fl_EventText()

					If Fl_EventCtrl > 0 Then
						Select Case Fl_EventKey()
							Case 118 'ctrl+v


								Fl_Paste(pThis->m_Widget, 1) ' not work


							Case 99  'ctrl+c
								If pThis->m_DablClick = 1 Or pThis->m_Drag=1 Then
									pThis->DelDiap(2)
									Fl_WidgetRedraw me
								EndIf
								Return Fl_WidgetExHandleBase(pThis->m_Widget,event)
							Case 120 'ctrl+x
								If pThis->m_DablClick = 1 Or pThis->m_Drag=1 Then
									pThis->DelDiap(1)
									Fl_WidgetRedraw me
								EndIf
								Return Fl_WidgetExHandleBase(pThis->m_Widget,event)
							Case 97
								pThis->uu0=0
								pThis->uu1=UBound(pThis->aCX1)
								pThis->m_DablClick = 1
								Fl_WidgetRedraw me

								Return Fl_WidgetExHandleBase(pThis->m_Widget,event)
							Case Else
								Return Fl_WidgetExHandleBase(pThis->m_Widget,event)
						End Select
					EndIf

					If pThis->m_DablClick=1 Or pThis->m_Drag=1 Then
						pThis->DelDiap()
						pThis->Arr()
					EndIf

					Dim arutf() As Integer
					pThis->StoUTF(SText, arutf())

					For ii As Integer = 0 To UBound(arutf)

						Select Case pThis->uu1
							Case -1
								pThis->cx +=DrawGetCharWidth(arutf(ii))

								ReDim Preserve pThis->aCX1(UBound(pThis->aCX1)+1)

								For i As Integer = UBound(pThis->aCX1) To 1 Step -1
									pThis->aCX1(i) = pThis->aCX1(i-1)
								Next
								pThis->uu1 +=1
								pThis->aCX1(0) = arutf(ii)

								pThis->GetUtf()
								Dim As Integer tttw

								If pThis->textw > w - pThis->tx0 + pThis->w0cl Then
									For j As Integer = 0 To UBound(pThis->aCX1)
										tttw += DrawGetCharWidth(pThis->aCX1(j))
										If tttw >= w - pThis->tx0 + pThis->w0cl Then
											pThis->ind0 = 0
											pThis->ind1 = j
											Exit For
										EndIf
									Next
								Else
									pThis->ind1 = UBound(pThis->aCX1)
								EndIf

							Case UBound(pThis->aCX1)

								ReDim Preserve pThis->aCX1(UBound(pThis->aCX1)+1)
								pThis->aCX1(UBound(pThis->aCX1)) = arutf(ii)

								pThis->uu1 +=1
								pThis->GetUtf()

								If pThis->textw > w - pThis->tx0 Then

									pThis->ind0 += 1
									Dim As Integer tttw

									For j As Integer = UBound(pThis->aCX1) To 0 Step -1
										tttw += DrawGetCharWidth(pThis->aCX1(j))
										If tttw >= w - pThis->tx0  Then
											pThis->ind0 = j
											pThis->ind1 = UBound(pThis->aCX1)
											Exit For
										EndIf
									Next
									pThis->cx = tttw
								Else
									pThis->ind1 = pThis->uu1
									pThis->cx=pThis->textw
								EndIf
							Case Else

								ReDim Preserve pThis->aCX1(UBound(pThis->aCX1)+1)
								Dim As Integer ggg
								For i As Integer = UBound(pThis->aCX1) To pThis->uu1+2 Step -1
									pThis->aCX1(i) = pThis->aCX1(i-1)
									ggg=i
								Next
								pThis->aCX1(pThis->uu1+1) = arutf(ii)

								pThis->GetUtf()
								pThis->Arr()
								pThis->uu1 +=1

								Dim As Integer tttw0=0, tttw1=0, tttw2

								For j As Integer = pThis->ind0 To pThis->uu1
									tttw0 += DrawGetCharWidth(pThis->aCX1(j))
								Next

								If tttw0 > w - pThis->tx0 Then
									pThis->ind1 +=1
									Dim As Integer tttw
									For j As Integer = pThis->uu1 To 0 Step -1
										tttw += DrawGetCharWidth(pThis->aCX1(j))
										If tttw >= w - pThis->tx0  Then
											pThis->ind0 = j
											pThis->cx=tttw
											Exit For
										EndIf
									Next
								Else
									If pThis->textw < w - pThis->tx0 Then
										pThis->ind0=0
										pThis->ind1=UBound(pThis->aCX1)
										pThis->cx += DrawGetCharWidth(arutf(ii))
									Else

										For j As Integer = pThis->ind0 To pThis->ind1
											tttw1 += DrawGetCharWidth(pThis->aCX1(j))
										Next

										If tttw1 >= w - pThis->tx0 Then
											pThis->ind0 +=1
										EndIf

										For j As Integer = pThis->ind0 To ggg-1
											tttw2 += DrawGetCharWidth(pThis->aCX1(j))
										Next
										pThis->cx =tttw2
									EndIf
								EndIf


						End Select
					Next
			End Select
			Fl_WidgetRedraw me
		Case FL_EVENT_DND_ENTER   : ActiveDND=1 : Return 1
		Case FL_EVENT_DND_LEAVE   : ActiveDND=0 : Return 1
		Case FL_EVENT_DND_DRAG, FL_EVENT_DND_RELEASE : Return 1

		Case FL_EVENT_PASTE
			?*Fl_EventText()

			If ActiveDND Then
				Dim As String sf=*Fl_EventText()

				Fl_SetFocus(me)
				ActiveDND=0
				pThis->ts = *Fl_EventText()
				pThis->Arr()
				printf(*Fl_EventText())
				Dim As Integer tttw
				If pThis->textw > w - pThis->tx0  Then
					For j As Integer = UBound(pThis->aCX1) To 0 Step -1
						tttw += DrawGetCharWidth(pThis->aCX1(j))
						If tttw >= w - pThis->tx0  Then
							pThis->ind0 = j
							pThis->ind1 = UBound(pThis->aCX1)
							Exit For
						EndIf
					Next
					pThis->cx = tttw
				Else
					pThis->cx = pThis->textw
					pThis->ind0 = 0
					pThis->ind1 = UBound(pThis->aCX1)

				EndIf
				pThis->uu1 = UBound(pThis->aCX1)
				pThis->m_Click=1
				Fl_WidgetRedraw me
			EndIf
		Case FL_EVENT_LEAVE
			pThis->m_Enter=0
			Fl_WindowCursor(me,FL_CURSOR_DEFAULT)
			'Fl_WidgetRedraw me
		Case FL_EVENT_ENTER
			pThis->m_Enter=1
			Fl_WindowCursor(me,FL_CURSOR_INSERT)
			'Fl_WidgetRedraw me
		Case FL_EVENT_MOVE

			If  Fl_EventInside2(pThis->ux,pThis->uy,pThis->uw,pThis->uh) Then
				Fl_WindowCursor(me,FL_CURSOR_DEFAULT)
			EndIf

			If pThis->m_MoveCursor=0 Then
				pThis->m_MoveCursor=1
				Fl_WindowCursor(me,FL_CURSOR_INSERT)
			EndIf
		Case Else
			Return Fl_WidgetExHandleBase(pThis->m_Widget,event)
	End Select
	Return 1
End Function

Function InpExBox.StoUTF Cdecl(Liste As ZString Ptr, arutf() As Integer) As Integer
	Dim As Integer l, r, t, uu=0
	ReDim arutf(-1)
	For i As Integer = 0 To Len(*Liste)
		If l>1 Then
			t=l
		EndIf
		r=Fl_utf8decode(Liste[i], 0, @l)
		If t>1 Then
			t-=1
			r=0
		EndIf
		If r>0 Then
			ReDim Preserve arutf(uu)
			arutf(uu)=r
			uu += 1
		EndIf
	Next
	Return 1
End Function

Function InpExBox.Arr Cdecl () As Integer
	Dim As InpExBox Ptr pThis = Fl_WidgetGetUserData(m_Widget)
	Dim As Integer l, r, t, uu=0
	ReDim pThis->aCX1(-1)
	If Len(pThis->ts) = 0 Then Return 0
	pThis->textw=0
	For i As Integer = 0 To Len(pThis->ts)
		If l>1 Then
			t=l
		EndIf
		r=Fl_utf8decode(@pThis->ts[i], 0, @l)
		If t>1 Then
			t-=1
			r=0
		EndIf
		If r>0 Then
			pThis->textw += DrawGetCharWidth(r)
			ReDim Preserve pThis->aCX1(uu)
			pThis->aCX1(uu)=r
			uu += 1
		EndIf
	Next

	Return pThis->textw
End Function

Function InpExBox.Update Cdecl (ByVal xX As Integer = 0) As Integer
	Dim As InpExBox Ptr pThis = Fl_WidgetGetUserData(m_Widget)
	pThis->textw=0
	Var x = Fl_WidgetGetX(m_Widget)

	Dim As Integer i, l, r, t, cx1=0, cx2=0, cx3=0, dcx, uu=0
	Dim As String s1, s2, s0

	pThis->textw=pThis->Arr()

	If pThis->textw = 0 Then
		pThis->uu1 = -1
		Return 0
	EndIf

	pThis->uu1= 0

	For i = pThis->ind0 To pThis->ind1

		If i> pThis->ind0 Then cx1 += DrawGetCharWidth(pThis->aCX1(i-1))
		cx2 += DrawGetCharWidth(pThis->aCX1(i))
		dcx=cx2-cx1
		If xX - pThis->tx0 + pThis->w0cl >= cx1 And xX-pThis->tx0 < round(cx2-dcx/2) Then
			If pThis->tx0 - pThis->w0cl < xX And round(DrawGetCharWidth(pThis->aCX1(pThis->ind0))/2)+pThis->tx0 >= xX Then
				pThis->cx = 0
				pThis->uu1= -1
			Else
				pThis->cx = cx1
			EndIf
			Exit For
		ElseIf xX-pThis->tx0 > round(cx2-dcx/2) And xX-pThis->tx0 <= cx2 Then
			pThis->cx = cx2
			Exit For
		Else
			pThis->uu1+= 1
		EndIf
	Next

	pThis->uu1 += pThis->ind0

	For j As Integer = pThis->ind0 To pThis->ind1
		cx3 += DrawGetCharWidth(pThis->aCX1(j))
		If pThis->cx=cx3 Then
			pThis->uu1=j
			Exit For
		EndIf
	Next

	If pThis->uu1 > UBound(pThis->aCX1) Then
		pThis->uu1 = UBound(pThis->aCX1)
	EndIf

	If pThis->textw=0 Then pThis->m_DablClick=0

	If pThis->uu1 > UBound(pThis->aCX1)-pThis->uu1 Then
		pThis->cx=cx3
	EndIf

	Return 1
End Function

Function InpExBox.DrawCB Cdecl (ByVal me As Any Ptr) As Long

	Var x = Fl_WidgetGetX(me)
	Var y = Fl_WidgetGetY(me)
	Var w = Fl_WidgetGetW(me)-50
	Var h = Fl_WidgetGetH(me)

	Dim As InpExBox Ptr pThis = Fl_WidgetGetUserData(me)

	If DrawGetFont() <> Fl_WidgetGetLabelFont(me) Or _
		DrawGetFontSize() <> Fl_WidgetGetLabelSize(me) Then
		DrawSetFont(Fl_WidgetGetLabelFont(me),Fl_WidgetGetLabelSize(me))
	EndIf

	DrawBox(BoxType(FL_DOWN_BOX),x,y,w+50,h,FL_RGB_Color(255,255,255))

	Var tH=DrawGetFontHeight()

	DrawSetColor FL_RGB_Color(0,0,0)

	Dim As ZString*10 zz
	Dim As Integer cx1, cx2, dcx, r, l=0, t, tttw=0
	pThis->tsv=""

	If pThis->m_SW=0 Then
		pThis->Arr()

		If pThis->textw > w - pThis->tx0 + pThis->w0cl Then
			For j As Integer = 0 To UBound(pThis->aCX1)
				l=Fl_utf8encode(pThis->aCX1(j),@zz)
				tttw += DrawGetCharWidth(pThis->aCX1(j))
				If l=1 Then
					pThis->tsv &= Chr(pThis->aCX1(j))
				Else
					pThis->tsv &= zz
				EndIf

				If tttw >= w - pThis->tx0 Then
					pThis->ind1=j
					Exit For
				EndIf
			Next
		Else
			pThis->tsv=pThis->ts
			pThis->ind0 = 0
			pThis->ind1 = UBound(pThis->aCX1)
		EndIf
		pThis->m_SW=1
	Else
		If UBound(pThis->aCX1)>-1 Then
			If pThis->ind0 < 0 Then pThis->ind0 = 0
			If pThis->ind1 > UBound(pThis->aCX1) Then pThis->ind1 = UBound(pThis->aCX1)
			For j As Integer = pThis->ind0 To pThis->ind1
				l=Fl_utf8encode(pThis->aCX1(j),@zz)
				If l=1 Then
					pThis->tsv &= Chr(pThis->aCX1(j))
				Else
					pThis->tsv &= zz
				EndIf
			Next
		EndIf
	EndIf

	If pThis->m_DablClick=1 Then
		Dim As Integer dabltextw=0, dabltextx, uu0

		If pThis->ind0 < = pThis->uu0-1 Then
			For j As Integer = pThis->ind0 To pThis->uu0-1
				dabltextx += DrawGetCharWidth(pThis->aCX1(j))
			Next
			uu0=pThis->uu0
		Else
			dabltextx=0
			uu0=pThis->ind0
		EndIf
		If pThis->uu1<=pThis->ind1 Then
			For j As Integer = uu0 To pThis->uu1
				dabltextw += DrawGetCharWidth(pThis->aCX1(j))
			Next
		Else
			For j As Integer = uu0 To pThis->ind1
				dabltextw += DrawGetCharWidth(pThis->aCX1(j))
			Next
		EndIf
		DrawRectFillColor(pThis->tx0+dabltextx, y+h/2-th/2, dabltextw, tH,FL_RGB_Color(50,152,254))
	EndIf

	If pThis->m_Drag=1 Then
		Var sx=IIf(pThis->cx0 < pThis->cx, pThis->cx0, pThis->cx)
		DrawRectFillColor(pThis->tx0+sx, y+h/2-th/2, Abs(pThis->cx-pThis->cx0), tH,FL_RGB_Color(50,152,254))
	EndIf

	DrawSetColor(FL_RGB_Color(0,0,0))
	DrawStrBox(pThis->tsv, pThis->tx0, y, w, h, Fl_ALIGN_LEFT Or Fl_ALIGN_INSIDE)

	If (pThis->m_Click=1 And pThis->m_DablClick=0 And pThis->m_Drag=0 ) Then
		If  pThis->cx > pThis->textw And pThis->textw < w - pThis->tx0 Then
			pThis->cx=pThis->textw
		EndIf
		DrawRectFillColor(pThis->cx + pThis->tx0, y+h/2-th/2, 2 ,tH,FL_RGB_Color(42,42,42))
	EndIf

	Return 0
End Function

Dim Shared As Integer Ptr chk1

Sub ButtonCB Cdecl (ByVal button As FL_WIDGET Ptr)
	Dim As InpExBox Ptr pThis = Fl_WidgetGetUserData(*chk1)
	?pThis->getText()
	pThis->setText("")
End Sub


win = Fl_Double_WindowExNew2(500,300,534,190,"InpExBox")
Fl_Background(112,121,134)

Var Btn = Fl_ButtonNew(15,60,200,25,"Get/set text InpExBox")
Fl_WidgetSetCallback0 Btn,@ButtonCB
Fl_WidgetSetColor win,12

chk1 = New InpExBox(15,10,430,27,"FreeBASIC is a multiplatform, free/open source BASIC compiler for Windows and Linux")

Fl_WindowShow win
Fl_Run
Last edited by WQ1980 on Oct 02, 2015 9:39, edited 1 time in total.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: FLTK 1.3.3 C Wrapper Windows/Linux 32/64-bit.

Post by D.J.Peters »

Good find it was an typo byref/byval both in FreeBASIC and the C++ wrapper.

Is fixed now.

Joshy

Code: Select all

#include once "fltk-c.bi"

namespace Widgets
  dim as Fl_Window ptr _Window
  dim as Fl_Input  ptr _Source
  dim as Fl_Input  ptr _Target
  dim as Fl_Button ptr _Copy
  dim as Fl_Button ptr _Paste
end namespace 

using Widgets

sub CopyCB cdecl(self as Fl_Widget ptr)
  var nChars =  Fl_Input_GetSize(_source)
  ' no text disable paste button
  if nChars=0 then Fl_WidgetDeactivate _Paste : return
  ' copy text to clipboard
  Fl_Copy Fl_Input_GetValue(_Source),nChars,1
  ' enable paste button
  Fl_WidgetActivate _Paste
end sub

sub PasteCB cdecl(self as Fl_Widget ptr)
  ' paste text from clipboard to target widget
  Fl_Paste _Target, 1
end sub

'
' main
'
_Window = Fl_WindowNew(620,78,        "clipboard")
_Source = Fl_InputNew ( 80,10,320,24, "source:"  )
_Target = Fl_InputNew ( 80,44,320,24, "target:"  )
_Copy   = Fl_ButtonNew(410,10,160,24, "copy to clipboard")
_Paste  = Fl_ButtonNew(410,44,160,24, "paste from clipboard")
Fl_WidgetSetCallback0 _Copy,@CopyCB
Fl_WidgetSetCallback0 _Paste,@PasteCB
Fl_WidgetDeactivate   _Paste
Fl_WidgetDeactivate   _Target
Fl_WindowShow         _Window
Fl_Run


Post Reply