Option Strict Off
Option Explicit On
'------------------------------------ 2023/11/09 ------------------------------------
Public Class 四frmHelpWnd

#Region "宣言"
    Private Const cfontfamilyHED0 As String = "BODY{font-family:"   'BODY{font-family:メイリオ;}
    Private Const cfontfamilyHED1 As String = "TABLE{font-family:"  'TABLE{font-family:メイリオ;}
    Private Const cfontsizeHED0 As String = "BODY{font-size:"       'BODY{font-size:80%;}
    Private Const cfontsizeHED1 As String = "TABLE{font-size:"      'TABLE{font-size:80%;}
    Private Const cfontENDCOM As String = ";}"
    Private mLenfontfamilyHED0 As Integer = Len(cfontfamilyHED0)
    Private mLenfontfamilyHED1 As Integer = Len(cfontfamilyHED1)
    Private mLenfontsizeHED0 As Integer = Len(cfontsizeHED0)
    Private mLenfontsizeHED1 As Integer = Len(cfontsizeHED1)
    Private mLenfontENDCOM As Integer = Len(cfontENDCOM)
    Private mURL As String = ""
    Private mCSS As String = ""
    Private mLoading As Boolean = False
    Private mFontNameCurIDX As Integer = -1
    Private mFontSizeCurIDX As Integer = -1
#End Region

#Region "AppIniFileOp"
    Private Function zzAppIniFileOp(ByVal Load_0_QueryUnload_1_Resize_2_DoIniSave_3 As Long) As Boolean
        '読出し時に　INI ファイルが存在しない場合は　False　を返します。
        If gggAppIniFile Is Nothing Then Return False
        Return gggAppIniFile.aaAppIniFileOp_フォームサイズと位置だけ_共通処理(Load_0_QueryUnload_1_Resize_2_DoIniSave_3, Me, "360254")
    End Function
#End Region

#Region "フォームイベント"

    Friend Sub aaHelpWndShow(ByVal rOwner As Form, ByVal MeText As String, ByVal HTMpath As String, ByVal CSSpath As String)
        If False = Ⅹファイルは存在(HTMpath) Then
            Call ⅩMsgBox_OK_情報(HTMpath & gggCR2 & "ヘルプファイルが存在しません。" & gggCR2 & "このコマンドは実行できません。")
            Exit Sub
        End If
        mLoading = True
        Try
            Me.Owner = rOwner
            Me.Icon = rOwner.Icon
            Me.Text = GMCOMアプリタイトル("") & "　のヘルプ"
            mURL = HTMpath
            mCSS = CSSpath
            WebBrowser1.Navigate(mURL)
            If Not zzAppIniFileOp(0) Then gggint = ⅩFormMove(gcoフォームをスクリーン中心に移動, Me) 'INI ファイルが存在しない場合に、このフォームを画面のセンターに表示するコード。
            Me.Show()
            pnlFontSet.BringToFront()
            btnスタイル.Visible = True
            btnスタイル.BringToFront()
        Catch ex As Exception
            Call ⅩMsgBox_OK_情報("aaHelpWndShow()" & gggCR2 & ex.ToString)
        End Try
        mLoading = False
    End Sub

    Private Sub frmHelpWnd_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        gggint = zzAppIniFileOp(2)
        gggint = zzAppIniFileOp(1)
        'qqqqq("frmHelpWnd_FormClosing")
    End Sub

    Private Sub frmHelpWnd_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        qqqqq("frmHelpWnd_Disposed")
    End Sub

#End Region

#Region "コントロール　イベント"

    Private Sub btnスタイル_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnスタイル.Click
        If pnlFontSet.Visible = True Then
            Call btnこのパネルを閉じる_Click(Nothing, Nothing)
        Else
            Try
                If False = Ⅹファイルは存在(mURL) Or False = Ⅹファイルは存在(mCSS) Then
                    Call ⅩMsgBox_OK_情報(mURL & gggCR2 & mCSS & gggCR2 & "いずれかのファイルが存在しません。" & gggCR2 & "このコマンドは実行できません。")
                    Exit Sub
                End If
                Dim a, n, nn, m As Integer
                If lstフォント名.Items.Count = 0 Then
                    Dim wFonts() As String = {""}
                    n = Ⅹフォントコンボ簡易リスト作成(wFonts, Nothing, "", "", True)
                    gggint = Ⅹリストボックスに_文配列からリストを入れる(lstフォント名, wFonts, True, -1, -1)
                End If
                Dim mFileStr() As String = {""}, sss As String
                Dim OldFontName As String
                m = ⅩFileTextOpenSave(1, 1, mCSS, mFileStr, "")
                For a = 1 To m - 1
                    sss = mFileStr(a)
                    n = InStr(sss, cfontfamilyHED0)
                    nn = InStr(sss, cfontENDCOM)
                    If n > 0 And nn > n Then
                        OldFontName = Microsoft.VisualBasic.Mid(sss, 1 + mLenfontfamilyHED0)
                        OldFontName = Microsoft.VisualBasic.Left(OldFontName, Len(OldFontName) - mLenfontENDCOM)
                        lstフォント名.SelectedIndex = lstフォント名.FindString(OldFontName)
                        'qqqqq(OldFontName)
                        Exit For
                    End If
                Next
                Dim OldFontSize As String
                For a = 1 To m - 1
                    sss = mFileStr(a)
                    n = InStr(sss, cfontsizeHED0)
                    nn = InStr(sss, cfontENDCOM)
                    If n > 0 And nn > n Then
                        OldFontSize = Microsoft.VisualBasic.Mid(sss, 1 + mLenfontsizeHED0)
                        OldFontSize = Microsoft.VisualBasic.Left(OldFontSize, Len(OldFontSize) - mLenfontENDCOM)
                        OldFontSize = StrConv(CStr(Val(OldFontSize)), VbStrConv.Wide) + "％"
                        lstフォントサイズ.SelectedIndex = lstフォントサイズ.FindString(OldFontSize)
                        qqqqq(OldFontSize)
                        Exit For
                    End If
                Next
                pnlFontSet.Visible = True
                mFontNameCurIDX = lstフォント名.SelectedIndex
                mFontSizeCurIDX = lstフォントサイズ.SelectedIndex
                gggbol = zzEnabledSet()
            Catch ex As Exception
                Call ⅩMsgBox_OK_情報("btnスタイル_Click()" & gggCR2 & ex.ToString)
            End Try
        End If
    End Sub

    Private Sub btnこのパネルを閉じる_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnこのパネルを閉じる.Click
        pnlFontSet.Visible = False
    End Sub

    Private Sub btn新しく設定_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn新しく設定.Click
        Try
            Dim mFileStr() As String = {""}, sss As String
            ReDim mFileStr(4)
            sss = lstフォント名.Items(lstフォント名.SelectedIndex)
            mFileStr(1) = cfontfamilyHED0 & sss & cfontENDCOM 'BODY{font-family:メイリオ;}
            mFileStr(2) = cfontfamilyHED1 & sss & cfontENDCOM 'TABLE{font-family:メイリオ;}
            sss = StrConv(lstフォントサイズ.Items(lstフォントサイズ.SelectedIndex), VbStrConv.Narrow)
            Dim n As Integer = Val(sss)
            sss = StrConv(CStr(n), VbStrConv.Narrow) + "％"
            mFileStr(3) = cfontsizeHED0 & sss & cfontENDCOM   'BODY{font-size:80%;}
            '表内の文字はすこし大きめにする。
            n = n + ((100 - n) \ 2)
            sss = StrConv(CStr(n), VbStrConv.Narrow) + "％"
            mFileStr(4) = cfontsizeHED1 & sss & cfontENDCOM   'TABLE{font-size:80%;}
            '----------------------------------------
            gggint = ⅩFileTextOpenSave(2, 1, mCSS, mFileStr, "")
            mFontNameCurIDX = lstフォント名.SelectedIndex
            mFontSizeCurIDX = lstフォントサイズ.SelectedIndex
            gggbol = zzEnabledSet()
            WebBrowser1.Refresh()
        Catch ex As Exception
            Call ⅩMsgBox_OK_情報("btn新しく設定_Click()" & gggCR2 & ex.ToString)
        End Try
    End Sub

    Private Sub lstフォント名_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstフォント名.SelectedIndexChanged
        Dim n As Integer = lstフォント名.SelectedIndex
        If n < 0 Then Exit Sub
        With txtサンプル.Font
            gggbol = Ⅹコントロールフォント変更(txtサンプル, lstフォント名.Items(n), .Size, (.Bold Or .Italic Or .Underline))
        End With
        gggbol = zzEnabledSet()
    End Sub

    Private Sub lstフォントサイズ_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles lstフォントサイズ.SelectedIndexChanged
        gggbol = zzEnabledSet()
    End Sub

#End Region

#Region "ローカルヘルパー"

    Private Function zzEnabledSet() As Boolean
        If mLoading Then Return False
        btn新しく設定.Enabled = (mFontNameCurIDX <> lstフォント名.SelectedIndex Or mFontSizeCurIDX <> lstフォントサイズ.SelectedIndex)
        Return True
    End Function

#End Region

End Class

