Commit e5b5487a authored by Benoît Minisini's avatar Benoît Minisini

Search dialog: text highlight now works correctly whatever the editor font is.

[DEVELOPMENT ENVIRONMENT]
* BUG: Search dialog: text highlight now works correctly whatever the editor font is.

[GB.EVAL.HIGHLIGHT]
* NEW: TextHighlighter: Paint() is a new method that paints the highlighted text.

[GB.GUI.BASE]
* NEW: Paint: Add an hidden undocumented method that computes the character width of a fixed font.
parent 75b1d595
This diff is collapsed.
......@@ -222,7 +222,7 @@
msgid ""
msgstr ""
"Project-Id-Version: gambas3 3.12.90\n"
"POT-Creation-Date: 2019-01-15 13:12 UTC\n"
"POT-Creation-Date: 2019-01-16 13:37 UTC\n"
"PO-Revision-Date: 2019-01-12 15:35 UTC\n"
"Last-Translator: gian <gian@gian>\n"
"Language: it\n"
......@@ -979,7 +979,7 @@ msgstr "Estensioni IDE"
#: FPublish.class:273 FReportBorderChooser.form:48
#: FReportBoxShadowChooser.form:27 FReportBrushChooser.form:36
#: FReportCoordChooser.form:26 FReportPaddingChooser.form:75 FSave.form:28
#: FSaveProjectAs.form:81 FSearch.class:943 FSelectComponent.form:39
#: FSaveProjectAs.form:81 FSearch.class:945 FSelectComponent.form:39
#: FSelectExtraFile.form:43 FSelectIcon.form:87 FSelectLibrary.form:66
#: FSnippet.form:57 FSoftwareFarm.class:545 FTableChooser.form:68 FText.form:41
#: FTranslate.class:652 FVersionControl.form:77 FWebFontChooser.form:129
......@@ -1008,7 +1008,7 @@ msgid "Files"
msgstr "File"
#: CProjectTree.class:343 FHelpShortcut.form:22 FMain.form:413
#: FOption.class:1097 FSearch.class:108 FSelectIcon.form:31
#: FOption.class:1097 FSearch.class:110 FSelectIcon.form:31
msgid "Project"
msgstr "Progetto"
......@@ -2230,7 +2230,7 @@ msgstr "Cerca ancora"
msgid "Show search window"
msgstr "Mostra la finestra di ricerca"
#: FDebugInfo.form:331 FSearch.class:543 FTranslate.class:614
#: FDebugInfo.form:331 FSearch.class:545 FTranslate.class:614
msgid "Search string cannot be found."
msgstr "La stringa cercata non è stata trovata."
......@@ -5335,23 +5335,23 @@ msgstr "Nuovo nome del progetto"
msgid "Take screenshot"
msgstr "Fai uno screenshot"
#: FSearch.class:545
#: FSearch.class:547
msgid "Search string replaced once."
msgstr "La stringa cercata è stata sostituita una volta."
#: FSearch.class:547
#: FSearch.class:549
msgid "Search string replaced &1 times."
msgstr "La stringa cercata è stata sostituita &1 volte."
#: FSearch.class:644
#: FSearch.class:646
msgid "One match"
msgstr "Una corrispondenza"
#: FSearch.class:646
#: FSearch.class:648
msgid "&1 matches"
msgstr "&1 corrisponde"
#: FSearch.class:943
#: FSearch.class:945
msgid "Do you really want to replace every string?"
msgstr "Vuoi veramente rimpiazzare ogni stringa?"
......
......@@ -2,7 +2,7 @@
Title=Gambas 3
Startup=Project
Icon=img/logo/logo-ide.png
Version=3.12.1
Version=3.12.90
VersionFile=1
Component=gb.image
Component=gb.gui.qt
......@@ -20,12 +20,12 @@ Component=gb.util
Component=gb.form.editor
Component=gb.settings
Component=gb.form.mdi
Component=gb.net
Component=gb.net.curl
Component=gb.form.stock
Component=gb.term
Component=gb.form.terminal
Component=gb.gui.qt.webkit
Component=gb.net
Component=gb.net.curl
Component=gb.markdown
Component=gb.signal
Description="Integrated Development Environment for Gambas"
......
......@@ -25,7 +25,7 @@ Private $bCancel As Boolean
Private $cGrepCache As New Collection
Private $cRefreshBrowse As New Collection
Private $hFont As Font
Private $CW As Integer
Private $CW As Float
Private $hStyle As TextHighlighterStyle[]
Private gvwFind As GridView
......@@ -84,15 +84,18 @@ Public Sub ReadConfig()
Project.SetSmallFont(gvwFind)
$hFont = Font[Settings["/Editor/Font", Project.DEFAULT_FONT]]
While $hFont.Height > Application.Font.Height
While $hFont.Height > gvwFind.Font.Height
Dec $hFont.Size
If $hFont.Size < 6 Then Break
Wend
$CW = Paint._EstimateFixedFontCharWidth($hFont)
$hStyle = MTheme.GetStyles()
For I = 0 To $aBrowse.Max
$aBrowse[I].RichText = ""
Next
gvwFind.Refresh
End
......@@ -996,7 +999,6 @@ End
Public Sub gvwFind_Font()
$CW = $hFont.TextWidth("W")
gvwFind.Rows.Height = Max(gvwFind.Font.Height, $hFont.Height) + 4
gvwFind.Columns[0].Width = -1
gvwFind.Columns[1].Width = -1
......@@ -1004,71 +1006,114 @@ Public Sub gvwFind_Font()
End
Public Sub gvwFind_Draw(X As Integer, Y As Integer, Width As Integer, Height As Integer, Row As Integer, Column As Integer)
Public Sub gvwFind_Draw(X As Integer, Y As Integer, (Width) As Integer, Height As Integer, Row As Integer, Column As Integer)
Dim hResult As CFindResult
Dim sText As String
Dim iLen As Integer
Dim iCol As Integer
Dim iPos As Integer
Dim bRichText As Boolean
Dim XX As Integer
Dim WW As Integer
If Column <> 4 Then Return
hResult = $aBrowse[Row]
sText = hResult.Text
iLen = String.Len(sText)
iCol = hResult.Column
If hResult.Highlight And If iLen < 1024 Then
sText = hResult.RichText
If Not sText Then
sText = TextHighlighter[TextEditor.GetModeFromPath(hResult.Path)].ToRichText(hResult.Text, $hStyle)
hResult.RichText = sText
Endif
bRichText = True
Endif
Paint.Font = $hFont
If System.RightToLeft Then
X -= -1000000
Width += 1000000
Width -= Desktop.Scale \ 2
Else
X += Desktop.Scale \ 2
Width = 1000000
Endif
If iCol > 40 And If iLen > 80 Then
iPos = 20
Else
iPos = iCol
Endif
Paint.FillRect(X + iPos * $CW, Y, hResult.Length * $CW, Height, $hStyle[Highlight.Highlight].Color)
X += Desktop.Scale \ 2
Paint.Background = $hStyle[Highlight.Normal].Color
If hResult.Highlight And Len(sText) < 1024 Then
If iCol > 40 And If iLen > 80 Then
If bRichText Then
Paint.DrawRichText(sText, X - (iCol - 20) * $CW, Y, Width, Height, Align.Normal)
If $CW Then
XX = $CW * iCol
WW = $CW * hResult.Length
X -= Max(0, XX - $CW * 40)
Else
Paint.DrawText(String.Mid$(sText, iCol - 21, 1024), X - $CW * 2, Y, Width, Height, Align.Normal)
XX = $hFont.TextWidth(String.Left(sText, iCol))
WW = $hFont.TextWidth(String.Left(sText, iCol + hResult.Length)) - XX
X -= Max(0, XX - $hFont.TextWidth("0") * 40)
Endif
Paint.FillRect(X + XX, Y, WW, Height, $hStyle[Highlight.Highlight].Color)
TextHighlighter[hResult.Highlight].Paint(sText, X, Y, $hStyle)
Else
If bRichText Then
Paint.DrawRichText(sText, X, Y, Width, Height, Align.Normal)
If iCol > 40 Then
sText = String.Mid$(sText, iCol - 40)
iCol = 41
Endif
If $CW Then
XX = $CW * iCol
WW = $CW * hResult.Length
Else
Paint.DrawText(sText, X, Y, Width, Height, Align.Normal)
XX = $hFont.TextWidth(String.Left(sText, iCol))
WW = $hFont.TextWidth(String.Left(sText, iCol + hResult.Length)) - XX
Endif
Paint.FillRect(X + XX, Y, WW, Height, $hStyle[Highlight.Highlight].Color)
Paint.Background = $hStyle[Highlight.Normal].Color
Paint.DrawText(sText, X, Y + $hFont.Ascent)
Endif
' If $CW And If hResult.Highlight And If iLen < 1024 Then
'
' sText = hResult.RichText
'
' If Not sText Then
' sText = TextHighlighter[TextEditor.GetModeFromPath(hResult.Path)].ToRichText(hResult.Text, $hStyle)
' hResult.RichText = sText
' Endif
'
' bRichText = True
'
' Endif
'
' Paint.Font = $hFont
'
' ' If bRichText Then
' ' If iCol >= 40 Then
' ' X -= (iCol - 40) * $CW
' ' Endif
' ' Else
' If iCol >= 40 Then
' sText = String.Mid$(sText, iCol - 39)
' iCol = 40
' Endif
' 'Endif
'
' If System.RightToLeft Then
' X -= -1000000
' Width += 1000000
' Width -= Desktop.Scale \ 2
' Else
' X += Desktop.Scale \ 2
' Width = 1000000
' If $CW Then
' XX = X + $CW * iCol '$hFont.TextWidth(String.Left(sText, iCol))
' WW = $CW * hResult.Length '$hFont.TextWidth(String.Mid$(sText, iCol + 1, hResult.Length))
' Else
' XX = X + $hFont.TextWidth(String.Left(sText, iCol))
' WW = $hFont.TextWidth(String.Mid$(sText, iCol + 1, hResult.Length))
' Endif
' Endif
'
' Paint.FillRect(XX, Y, WW, Height, $hStyle[Highlight.Highlight].Color)
'
' Paint.Background = $hStyle[Highlight.Normal].Color
'
' If bRichText Then
' Paint.DrawRichText(sText, X, Y, Width, Height, Align.Normal)
' Else
' Paint.DrawText(sText, X, Y, Width, Height, Align.Normal)
' Endif
End
......
[Component]
Key=gb.eval.highlight
Version=3.12.0
Version=3.12.90
Requires=gb.eval
# Gambas Project File 3.0
Title=gb.eval.highlight
Startup=Main
Version=3.12.0
Version=3.12.90
VersionFile=1
Component=gb.eval
Component=gb.net
......
[Component]
Key=gb.form.editor
Version=3.12.0
Version=3.12.90
Needs=Form
Requires=gb.eval.highlight,gb.util
......@@ -2,7 +2,7 @@
Title=Text editor with syntax highlighting
Startup=FTestEditor
Icon=.hidden/control/texteditor.png
Version=3.12.0
Version=3.12.90
VersionFile=1
Component=gb.image
Component=gb.gui
......
......@@ -277,8 +277,6 @@ End
Private Sub CalcSizes()
Dim I As Integer
Dim sText As String
Dim hParent As Control
$hFont = $hView.Font
......@@ -308,20 +306,21 @@ Private Sub CalcSizes()
$fTabSymbolSize = Max(1, $hRows.H / 5)
$hTabImage = Null
$fCharWidth = $iSpaceWidth
For I = 33 To 255
If I > 126 And If I < 160 Then Continue
If I = 173 Then Continue
If $hFont.TextWidth(String.Chr$(I)) <> $iSpaceWidth Then
$fCharWidth = 0
Break
Endif
Next
If $fCharWidth Then
sText = String$(4, "AbCdEfGh01#@WwmM")
$fCharWidth = $hFont.TextWidth(sText) / Len(sText)
Endif
$fCharWidth = Paint._EstimateFixedFontCharWidth($hFont)
' $fCharWidth = $iSpaceWidth
' For I = 33 To 255
' If I > 126 And If I < 160 Then Continue
' If I = 173 Then Continue
' If $hFont.TextWidth(String.Chr$(I)) <> $iSpaceWidth Then
' $fCharWidth = 0
' Break
' Endif
' Next
'
' If $fCharWidth Then
' sText = String$(4, "AbCdEfGh01#@WwmM")
' $fCharWidth = $hFont.TextWidth(sText) / Len(sText)
' Endif
If Not $bRemoteDisplay Then
$sCacheTextKey = $hFont.ToString()
......
[Component]
Key=gb.gui.base
Version=3.11.90
Version=3.12.90
Hidden=True
Needs=Form
# Gambas Project File 3.0
Title=Common controls and classes for GUI components
Startup=FScrollArea
Version=3.11.90
Version=3.12.90
VersionFile=1
Component=gb.image
Component=gb.gui
......
......@@ -2,6 +2,9 @@
Export
Static Private $fLastWidth As Float
Static Private $sLastFont As String
Static Private Sub AddThreeDots(sStr As String) As String
While InStr(". \n", Right(sStr))
......@@ -276,6 +279,35 @@ Static Public Sub DrawRect(X As Float, Y As Float, Width As Float, Height As Flo
End
Static Public Sub _EstimateFixedFontCharWidth(hFont As Font) As Float
Dim iSpaceWidth As Integer
Dim I As Integer
Dim sText As String
Dim sFont As String
sFont = hFont.ToString()
If sFont = $sLastFont Then Return $fLastWidth
$sLastFont = sFont
iSpaceWidth = hFont.TextWidth(" ")
For I = 33 To 255
If I > 126 And If I < 160 Then Continue
If I = 173 Then Continue
If hFont.TextWidth(String.Chr$(I)) <> iSpaceWidth Then
$fLastWidth = 0
Return 0
Endif
Next
sText = String$(4, "AbCdEfGh01#@WwmM")
$fLastWidth = hFont.TextWidth(sText) / Len(sText)
Return $fLastWidth
End
' Static Public Debug As Boolean
'
......
[Component]
Key=gb.media.form
Version=3.11.90
Version=3.12.90
Needs=Form
Requires=gb.media
......@@ -2,7 +2,7 @@
Title=gb.media.form
Startup=FTest
Icon=.hidden/control/mediaview.png
Version=3.11.90
Version=3.12.90
VersionFile=1
Component=gb.image
Component=gb.gui
......
comp/src/gb.web.form/.icon.png

10.3 KB | W: | H:

comp/src/gb.web.form/.icon.png

10.7 KB | W: | H:

comp/src/gb.web.form/.icon.png
comp/src/gb.web.form/.icon.png
comp/src/gb.web.form/.icon.png
comp/src/gb.web.form/.icon.png
  • 2-up
  • Swipe
  • Onion skin
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment