B4J Question BCTextEngine/BBCodeView on Modal Form

madru

Active Member
Licensed User
Longtime User
Hi,

does anyone have an idea how to use BCTextEngine/BBCodeView on a ModalForm?
 
Last edited:

madru

Active Member
Licensed User
Longtime User
I have no idea how and where to initialise the modules.....using your BBCodeDesigner sample.....

B4X:
    Dim mfE As TestEditor
    mfE.Initialize(frm,(frm.WindowLeft+15),(frm.windowTop+ 50),(800),(700),"Editor",tfTN.Text)
    mfE.Show


B4X:
Sub Class_Globals
    Private fx As JFX
    Private xui As XUI
    Private frm As Form
    Private SplitPane1 As SplitPane
    Private TextArea1 As TextArea
    Private BBCodeView1 As BBCodeView
    Private TextEngine As BCTextEngine

End Sub

Public Sub Initialize (Parent As Form,left As String,top As String,width As String,height As String,titel As String,text As String)

    If frm.IsInitialized = False Then
        frm.Initialize("frm", 800, 600)
        frm.RootPane.LoadLayout("frmEditor")
        SplitPane1.LoadLayout("Top")
        SplitPane1.LoadLayout("Bottom")
   
    End If
         
    Dim ps As Screen = fx.PrimaryScreen
    frm.WindowWidth = width
    frm.WindowHeight = height
    frm.WindowTop = ps.MinY +  (ps.MaxY - frm.WindowHeight) / 2
    frm.WindowLeft = ps.MinX + (ps.MaxX - frm.WindowWidth) / 2
   
    frm.Title=titel
    frm.SetFormStyle("DECORATED")
    frm.Resizable = True

End Sub

Public Sub Show As String
    'TextEngine.Initialize(frm.RootPane) ' to early here
    frm.ShowAndWait
    TextEngine.Initialize(frm.RootPane) ' to late here
    Return TextArea1.Text
End Sub

Sub btnUpdate_Click
    Try
        AddViews(TextArea1.Text)
        BBCodeView1.Text = TextArea1.Text
    Catch
        TextEngine.TagParser.ErrorString.Append(CRLF).Append(LastException.Message)
        Log(LastException)
    End Try
    If TextEngine.TagParser.ErrorString.Length > 0 Then
        xui.MsgboxAsync(TextEngine.TagParser.ErrorString, "Error")
    End If
End Sub

Sub AddViews (s As String)
    Dim m As Matcher = Regex.Matcher2("\[view=(\w+)", Regex.CASE_INSENSITIVE, s)
    Do While m.Find
        Dim key As String = m.Group(1)
        If BBCodeView1.Views.ContainsKey(key) = False Then
            Dim p As B4XView = xui.CreatePanel("")
            p.SetLayoutAnimated(0, 0, 0, 100dip, 100dip)
            p.Color = Rnd(0xff000000, -1)
            BBCodeView1.Views.Put(key, p)
        End If
    Loop
End Sub
 
Last edited:
Upvote 0

madru

Active Member
Licensed User
Longtime User
That’s what I did in the end but I was wondering how to do it with a Modal FRM
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
I was wondering how to do it with a Modal FRM
You can turn any B4XPage into a modal form by the following routine. It is not necessary to hide other B4XPage(s).
B4XPage modal form open code:
Sub Button1_Click
'    --- Show modal form
    pgModal.ShowModal
End Sub
B4XPage modal form show modal form code:
Public Sub ShowModal
    Dim frm As Form = B4XPages.GetNativeParent(Me)
    frm.WindowLeft = 400
    frm.WindowTop = 100
    frm.ShowAndWait        ' --- This will block interactivity with other B4XPages
End Sub

Private Sub btnClick_Click
    Wait For (xui.Msgbox2Async("Close?", "Close modal form", "Yes", "Cancel", "No", Null)) Msgbox_Result (Result As Int)
    If Result = xui.DialogResponse_Positive Then
'        --- quit the calling object, returns to the Main object
        B4XPages.ClosePage(Me)
    End If
End Sub
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
not using B4XPages in the example
Everything starts with the first time ;);)
 
Upvote 0
Top