Skip to content

Commit

Permalink
Change OS Version checks
Browse files Browse the repository at this point in the history
Switch to KD Unicode normalization
Prefix with 2 spaces when using fixed width font in list box
  • Loading branch information
ManiacDC committed Jul 30, 2015
1 parent fbb9c0c commit ecaed65
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 25 deletions.
37 changes: 35 additions & 2 deletions Source/Includes/Conversions.ahk
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
; these functions handle database conversion
; always set the SetDbVersion default argument to the current highest version

SetDbVersion(dBVersion = 5)
SetDbVersion(dBVersion = 6)
{
global g_WordListDB
g_WordListDB.Query("INSERT OR REPLACE INTO LastState VALUES ('databaseVersion', '" . dBVersion . "', NULL);")
Expand Down Expand Up @@ -69,6 +69,11 @@ MaybeConvertDatabase()
RunConversionFive()
}

if (databaseVersion < 6)
{
RunConversionSix()
}

return, false
}

Expand Down Expand Up @@ -152,7 +157,8 @@ RunConversionThree()
RunConversionFour()
{
global g_WordListDB
g_WordListDB.BeginTransaction()
;superseded by conversion 6
/*g_WordListDB.BeginTransaction()
Words := g_WordListDB.Query("SELECT word, wordindexed, wordreplacement FROM Words;")
Expand All @@ -174,6 +180,7 @@ RunConversionFour()
SetDbVersion(4)
g_WordListDB.EndTransaction()
*/
}

;Creates the Wordlists table
Expand All @@ -188,6 +195,32 @@ RunConversionFive()
g_WordListDB.EndTransaction()
}

; normalize accented characters
RunConversionSix()
{
global g_WordListDB
g_WordListDB.BeginTransaction()

Words := g_WordListDB.Query("SELECT word, wordindexed, wordreplacement FROM Words;")
WordDescription =

for each, row in Words.Rows
{
Word := row[1]
WordIndexed := row[2]
WordReplacement := row[3]

TransformWord(Word, WordReplacement, WordDescription, WordTransformed, WordIndexTransformed, WordReplacementTransformed, WordDescriptionTransformed)

StringReplace, OldWordIndexedTransformed, WordIndex, ', '', All

g_WordListDB.Query("UPDATE Words SET wordindexed = '" . WordIndexTransformed . "' WHERE word = '" . WordTransformed . "' AND wordindexed = '" . OldWordIndexedTransformed . "' AND wordreplacement = '" . WordReplacementTransformed . "';")
}

SetDbVersion(6)
g_WordListDB.EndTransaction()
}

CreateLastStateTable()
{
global g_WordListDB
Expand Down
13 changes: 10 additions & 3 deletions Source/Includes/ListBox.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,22 @@ AddToMatchList(position, MaxLength, HalfLength, LongestBaseLength, ComputeBaseLe
global g_SingleMatchReplacement
global prefs_ListBoxFontFixed

IfEqual, prefs_ListBoxFontFixed, On
{
blankprefix := " "
} else {
blankprefix =
}

IfEqual, g_NumKeyMethod, Off
{
prefix =
prefix := blankprefix
} else IfLess, position, %g_MatchStart%
{
prefix =
prefix := blankprefix
} else if ( position > ( g_MatchStart + 9 ) )
{
prefix =
prefix := blankprefix
} else {
prefix := Mod(position - g_MatchStart +1,10) . " "
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Includes/Window.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ GetIncludedActiveWindow()
{
global g_Active_Pid
global g_DpiAware
global g_OSVersion
global g_Process_DPI_Unaware
global g_Process_System_DPI_Aware
global g_Process_Per_Monitor_DPI_Aware
Expand All @@ -127,7 +128,7 @@ GetIncludedActiveWindow()
; we'll first assume the software is system DPI aware
DpiAware := g_Process_System_DPI_Aware
; if Win 8.1 or higher, we can actually check if it's system DPI aware
if A_OSVersion not in WIN_7,WIN_8,WIN_VISTA,WIN_2003,WIN_XP,WIN_2000
if (g_OSVersion >= 6.3)
{
ProcessHandle := DllCall("OpenProcess", "int", g_PROCESS_QUERY_INFORMATION | g_PROCESS_QUERY_LIMITED_INFORMATION, "int", 0, "UInt", g_Active_Pid)
DllCall("GetProcessDpiAwareness", "Ptr", ProcessHandle, "Uint*", DpiAware)
Expand Down
49 changes: 30 additions & 19 deletions Source/Includes/Wordlist.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -201,43 +201,35 @@ AddWordToList(AddWord,ForceCountNewOnly,ForceLearn=false, ByRef LearnedWordsCoun
if !(CheckValid(AddWord,ForceLearn))
return

StringUpper, AddWordIndex, AddWord

; normalize accented characters
AddWordIndex := StrUnmark(AddWordIndex)

StringReplace, AddWordEscaped, AddWord, ', '', All
StringReplace, AddWordIndexEscaped, AddWordIndex, ', '', All
StringReplace, AddWordReplacementEscaped, AddWordReplacement, ', '', All
StringReplace, AddWordDescriptionEscaped, AddWordDescription, ', '', All
TransformWord(AddWord, AddWordReplacement, AddWordDescription, AddWordTransformed, AddWordIndexTransformed, AddWordReplacementTransformed, AddWordDescriptionTransformed)

IfEqual, g_WordListDone, 0 ;if this is read from the wordlist
{
IfNotEqual,LearnedWordsCount, ;if this is a stored learned word, this will only have a value when LearnedWords are read in from the wordlist
{
; must update wordreplacement since SQLLite3 considers nulls unique
g_WordListDB.Query("INSERT INTO words (wordindexed, word, count, wordreplacement) VALUES ('" . AddWordIndexEscaped . "','" . AddWordEscaped . "','" . LearnedWordsCount++ . "','');")
g_WordListDB.Query("INSERT INTO words (wordindexed, word, count, wordreplacement) VALUES ('" . AddWordIndexTransformed . "','" . AddWordTransformed . "','" . LearnedWordsCount++ . "','');")
} else {
if (AddWordReplacement)
{
WordReplacementQuery := "'" . AddWordReplacementEscaped . "'"
WordReplacementQuery := "'" . AddWordReplacementTransformed . "'"
} else {
WordReplacementQuery := "''"
}

if (AddWordDescription)
{
WordDescriptionQuery := "'" . AddWordDescriptionEscaped . "'"
WordDescriptionQuery := "'" . AddWordDescriptionTransformed . "'"
} else {
WordDescriptionQuery := "NULL"
}
g_WordListDB.Query("INSERT INTO words (wordindexed, word, worddescription, wordreplacement) VALUES ('" . AddWordIndexEscaped . "','" . AddWordEscaped . "'," . WordDescriptionQuery . "," . WordReplacementQuery . ");")
g_WordListDB.Query("INSERT INTO words (wordindexed, word, worddescription, wordreplacement) VALUES ('" . AddWordIndexTransformed . "','" . AddWordTransformed . "'," . WordDescriptionQuery . "," . WordReplacementQuery . ");")
}

} else if (prefs_LearnMode = "On" || ForceCountNewOnly == 1)
{
; If this is an on-the-fly learned word
AddWordInList := g_WordListDB.Query("SELECT * FROM words WHERE word = '" . AddWordEscaped . "';")
AddWordInList := g_WordListDB.Query("SELECT * FROM words WHERE word = '" . AddWordTransformed . "';")

IF !( AddWordInList.Count() > 0 ) ; if the word is not in the list
{
Expand All @@ -260,7 +252,7 @@ AddWordToList(AddWord,ForceCountNewOnly,ForceLearn=false, ByRef LearnedWordsCoun
}

; must update wordreplacement since SQLLite3 considers nulls unique
g_WordListDB.Query("INSERT INTO words (wordindexed, word, count, wordreplacement) VALUES ('" . AddWordIndexEscaped . "','" . AddWordEscaped . "','" . CountValue . "','');")
g_WordListDB.Query("INSERT INTO words (wordindexed, word, count, wordreplacement) VALUES ('" . AddWordIndexTransformed . "','" . AddWordTransformed . "','" . CountValue . "','');")
} else IfEqual, prefs_LearnMode, On
{
IfEqual, ForceCountNewOnly, 1
Expand All @@ -273,7 +265,7 @@ AddWordToList(AddWord,ForceCountNewOnly,ForceLearn=false, ByRef LearnedWordsCoun

IF ( CountValue < prefs_LearnCount )
{
g_WordListDB.QUERY("UPDATE words SET count = ('" . prefs_LearnCount . "') WHERE word = '" . AddWordEscaped . "');")
g_WordListDB.QUERY("UPDATE words SET count = ('" . prefs_LearnCount . "') WHERE word = '" . AddWordTransformed . "');")
}
} else {
UpdateWordCount(AddWord,0) ;Increment the word count if it's already in the list and we aren't forcing it on
Expand Down Expand Up @@ -322,6 +314,23 @@ CheckValid(Word,ForceLearn=false)
Return, 1
}

TransformWord(AddWord, AddWordReplacement, AddWordDescription, ByRef AddWordTransformed, ByRef AddWordIndexTransformed, ByRef AddWordReplacementTransformed, ByRef AddWordDescriptionTransformed)
{
StringUpper, AddWordIndex, AddWord

; normalize accented characters
AddWordIndex := StrUnmark(AddWordIndex)

StringReplace, AddWordTransformed, AddWord, ', '', All
StringReplace, AddWordIndexTransformed, AddWordIndex, ', '', All
if (AddWordReplacement) {
StringReplace, AddWordReplacementTransformed, AddWordReplacement, ', '', All
}
if (AddWordDescription) {
StringReplace, AddWordDescriptionTransformed, AddWordDescription, ', '', All
}
}

DeleteWordFromList(DeleteWord)
{
global prefs_LearnMode
Expand Down Expand Up @@ -436,15 +445,17 @@ MaybeUpdateWordlist()
; Removes marks from letters. Requires Windows Vista or later.
; Code by Lexikos, based on MS documentation
StrUnmark(string) {
if (A_OSVersion == "WIN_2003" || A_OSVersion == "WIN_XP" || A_OSVersion == "WIN_2000")
global g_OSVersion
global g_NormalizationKD
if (g_OSVersion < 6.0)
{
return string
}

len := DllCall("Normaliz.dll\NormalizeString", "int", 2, "wstr", string, "int", StrLen(string), "ptr", 0, "int", 0) ; Get *estimated* required buffer size.
len := DllCall("Normaliz.dll\NormalizeString", "int", g_NormalizationKD, "wstr", string, "int", StrLen(string), "ptr", 0, "int", 0) ; Get *estimated* required buffer size.
Loop {
VarSetCapacity(buf, len * 2)
len := DllCall("Normaliz.dll\NormalizeString", "int", 2, "wstr", string, "int", StrLen(string), "ptr", &buf, "int", len)
len := DllCall("Normaliz.dll\NormalizeString", "int", g_NormalizationKD, "wstr", string, "int", StrLen(string), "ptr", &buf, "int", len)
if len >= 0
break
if (A_LastError != 122) ; ERROR_INSUFFICIENT_BUFFER
Expand Down
10 changes: 10 additions & 0 deletions Source/TypingAid.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Suspend, On
#NoEnv
ListLines Off

g_OSVersion := GetOSVersion()

;Set the Coordinate Modes before any threads can be executed
CoordMode, Caret, Screen
CoordMode, Mouse, Screen
Expand Down Expand Up @@ -52,6 +54,7 @@ g_IDC_HAND := 32649
g_IDC_HELP := 32651
g_IMAGE_CURSOR := 2
g_LR_SHARED := 0x8000
g_NormalizationKD := 0x6
g_NULL := 0
g_Process_DPI_Unaware := 0
g_Process_System_DPI_Aware := 1
Expand Down Expand Up @@ -1200,6 +1203,13 @@ MaybeFixFileEncoding(File,Encoding)

;------------------------------------------------------------------------

GetOSVersion()
{
return ((r := DllCall("GetVersion") & 0xFFFF) & 0xFF) "." (r >> 8)
}

;------------------------------------------------------------------------

MaybeCoInitializeEx()
{
global g_NULL
Expand Down

0 comments on commit ecaed65

Please sign in to comment.