En gros, il crée un fichier qui contient tous les caractères d'une langue.
Ce qui est intéressant dans ce code, c'est le principe d'affichage de la table de caractère unicode.
Dans une table de caractère, on a toujours des valeurs qui ne correspondent à aucun caractère. Comme le caractère 13 ou le 10.
Cela affiche un joli carré.
Dans la table de caractère unicode, il y a plein de valeurs qui ne correspondent à aucun caractère.
il a donc fallu nettoyer tout ça pour avoir qlqchose de plus lisible.
Je dessine un caractère qui n'existe pas sur une image (par exemple le caractère 13)
Ensuite, je dessine chaque caractère sur une autre image et je compare.
Si c'est identique, le caractère n'existe pas.
Si c'est différent, c'est bon.
Bien sur, je ne compare pas pixel par pixel. J'utilise ma librairie Effect.
Vous entrez le nom du clavier puis vous arrivez sur la fenêtre.
De la, vous avez à gauche la liste de caractère qui vont donner le clavier de la langue en cours
A droite, une liste de caractère UNICODE. Pour insérer un caractère dans un StringGadget, faites un double clic dans la liste.
. Voir sur
Code : Tout sélectionner
; Auteur : Le Soldat Inconnu
; Version de PB : 4
;
; Explication du programme :
; Création des claviers
Procedure EditText(Gadget, Type, Text_Start.s, Text_End.s = "")
; type = 0 : Insertion de texte sur le curseur
; type = 1 : insertion de texte autour de la sélection
Protected Debut_Position, Fin_position, Texte.s, Index.l
If IsGadget(Gadget)
Select GadgetType(Gadget)
Case #PB_GadgetType_String
SendMessage_(GadgetID(Gadget), #EM_GETSEL, @Debut_Position, @Fin_position)
Texte = GetGadgetText(Gadget)
If Type = 0
Texte = Left(Texte, Debut_Position) + Text_Start + Text_End + Right(Texte, Len(Texte) - Fin_position)
Debut_Position + Len(Text_Start + Text_End)
Fin_position = Debut_Position
Else
Texte = Left(Texte, Debut_Position) + Text_Start + Mid(Texte, Debut_Position + 1, Fin_position - Debut_Position) + Text_End + Right(Texte, Len(Texte) - Fin_position)
Debut_Position + Len(Text_Start)
Fin_position + Len(Text_Start)
EndIf
SetGadgetText(Gadget, Texte)
SendMessage_(GadgetID(Gadget), #EM_SETSEL, Debut_Position, Fin_position)
SetActiveGadget(Gadget)
Case #PB_GadgetType_Editor
SendMessage_(GadgetID(Gadget), #EM_GETSEL, @Debut_Position, @Fin_position)
For Index = 0 To CountGadgetItems(Gadget) - 1
If Texte <> ""
Texte + Chr(10)
EndIf
Texte + GetGadgetItemText(Gadget, Index)
Next
If Type = 0
Texte = Left(Texte, Debut_Position) + Text_Start + Text_End + Right(Texte, Len(Texte) - Fin_position)
Debut_Position + Len(Text_Start + Text_End)
Fin_position = Debut_Position
Else
Texte = Left(Texte, Debut_Position) + Text_Start + Mid(Texte, Debut_Position + 1, Fin_position - Debut_Position) + Text_End + Right(Texte, Len(Texte) - Fin_position)
Debut_Position + Len(Text_Start)
Fin_position + Len(Text_Start)
EndIf
SetGadgetText(Gadget, Texte)
SendMessage_(GadgetID(Gadget), #EM_SETSEL, Debut_Position, Fin_position)
SetActiveGadget(Gadget)
EndSelect
EndIf
EndProcedure
Fichier.s = InputRequester("Keyboard", "Language name :", "FR")
; Création de la fenêtre et de la GadgetList
If OpenWindow(0, 0, 0, 500, 500, "Keyboard", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_MinimizeGadget) = 0 Or CreateGadgetList(WindowID(0)) = 0
End
EndIf
LoadFont(0, "Tahoma", 11, #PB_Font_HighQuality)
; ListIconGadget(0, 0, 0, 250, 500, "low case character", 220, #PB_ListIcon_CheckBoxes)
; SetGadgetFont(0, FontID(0))
; For n = 1 To 1023
; AddGadgetItem(0, -1, Chr(n) + " (" + Str(n) + ")")
; Next
; ListIconGadget(1, 250, 0, 250, 500, "choose up case character", 220, #PB_ListIcon_CheckBoxes)
; SetGadgetFont(1, FontID(0))
; For n = 1 To 1023
; AddGadgetItem(1, -1, Chr(n) + " (" + Str(n) + ")")
; Next
ListIconGadget(0, 0, 0, 240, 500, "low", 65, #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines | #PB_ListIcon_AlwaysShowSelection)
SetGadgetFont(0, FontID(0))
AddGadgetColumn(0, 1, "up", 65)
AddGadgetColumn(0, 2, "simple", 65)
ListIconGadget(10, 360, 0, 130, 500, "char", 50, #PB_ListIcon_FullRowSelect | #PB_ListIcon_GridLines)
SetGadgetFont(10, FontID(0))
AddGadgetColumn(10, 1, "n", 50)
ButtonGadget(1, 240, 0, 120, 25, "Move up")
ButtonGadget(2, 240, 25, 120, 25, "Move down")
ButtonGadget(3, 240, 60, 120, 25, "Add")
TextGadget(#PB_Any, 240, 95, 120, 15, "Low charater (é) :")
StringGadget(5, 240, 110, 120, 25, "")
TextGadget(#PB_Any, 240, 135, 120, 15, "Up charater (E) :")
StringGadget(6, 240, 150, 120, 25, "")
TextGadget(#PB_Any, 240, 175, 120, 15, "Simple character (e) :")
StringGadget(7, 240, 190, 120, 25, "")
ButtonGadget(4, 240, 215, 120, 25, "Accept")
ButtonGadget(8, 240, 250, 120, 25, "Delete")
#Taille = 20
CreateImage(0, #Taille, #Taille)
Dim Image0(#Taille - 1, #Taille - 1)
StartDrawing(ImageOutput(0))
Box(0, 0, #Taille, #Taille, 0)
DrawingFont(FontID(0))
DrawText(0, 0, Chr(10), $FFFFFF, 0)
StopDrawing()
GetImageBits(ImageID(0), @Image0())
CreateImage(1, #Taille, #Taille)
Dim Image1(#Taille - 1, #Taille - 1)
For n = 32 To 4095
StartDrawing(ImageOutput(1))
Box(0, 0, #Taille, #Taille, 0)
DrawingFont(FontID(0))
DrawText(0, 0, Chr(n), $FFFFFF, 0)
StopDrawing()
GetImageBits(ImageID(1), @Image1())
If CompareMemory(@Image0(), @Image1(), #Taille * #Taille * 4) = 0
AddGadgetItem(10, -1, Chr(n) + Chr(10) + Str(n))
EndIf
Next
If ReadFile(0, Fichier + ".clv")
ReadStringFormat(0)
n = -1
Repeat
n + 1
Ligne.s = ReadString(0, #PB_Unicode)
AddGadgetItem(0, -1, StringField(Ligne, 1, Chr(9)))
SetGadgetItemText(0, n, StringField(Ligne, 2, Chr(9)), 1)
SetGadgetItemText(0, n, StringField(Ligne, 3, Chr(9)), 2)
Until Eof(0)
CloseFile(0)
EndIf
Repeat
Event = WaitWindowEvent()
;{ Focus
Focus = GetActiveGadget()
If Focus <> -1 And (GadgetType(Focus) = #PB_GadgetType_String Or GadgetType(Focus) = #PB_GadgetType_Editor)
Gadget_TextFocus = Focus
EndIf
;}
Select Event
Case #PB_Event_Menu
Select EventMenu() ; Menus
EndSelect
Case #PB_Event_Gadget
Select EventGadget() ; Gadgets
Case 10
Select EventType()
Case #PB_EventType_LeftDoubleClick
Position = GetGadgetState(10)
If Position >= 0
EditText(Gadget_TextFocus, 0, GetGadgetItemText(10, Position, 0))
EndIf
EndSelect
Case 0
Position = GetGadgetState(0)
If Position >= 0
SetGadgetText(5, GetGadgetItemText(0, Position, 0))
SetGadgetText(6, GetGadgetItemText(0, Position, 1))
SetGadgetText(7, GetGadgetItemText(0, Position, 2))
EndIf
Case 4
Position = GetGadgetState(0)
If Position >= 0
SetGadgetItemText(0, Position, GetGadgetText(5), 0)
SetGadgetItemText(0, Position, GetGadgetText(6), 1)
SetGadgetItemText(0, Position, GetGadgetText(7), 2)
EndIf
Case 3
Position = GetGadgetState(0) + 1
AddGadgetItem(0, Position, "")
SetGadgetState(0, Position)
SetActiveGadget(5)
Case 2
Position = GetGadgetState(0)
If Position >= 0 And Position < CountGadgetItems(0) - 1
Texte.s = GetGadgetItemText(0, Position, 0) + Chr(10) + GetGadgetItemText(0, Position, 1) + Chr(10) + GetGadgetItemText(0, Position, 2)
RemoveGadgetItem(0, Position)
AddGadgetItem(0, Position + 1, Texte)
SetGadgetState(0, Position + 1)
EndIf
Case 1
Position = GetGadgetState(0)
If Position >= 1
Texte.s = GetGadgetItemText(0, Position, 0) + Chr(10) + GetGadgetItemText(0, Position, 1) + Chr(10) + GetGadgetItemText(0, Position, 2)
RemoveGadgetItem(0, Position)
AddGadgetItem(0, Position - 1, Texte)
SetGadgetState(0, Position - 1)
EndIf
Case 8
Position = GetGadgetState(0)
If Position >= 0
RemoveGadgetItem(0, Position)
SetGadgetState(0, Position - 1)
EndIf
Case 5
Select EventType()
Case #PB_EventType_Change
If GetGadgetText(6) = ""
SetGadgetText(6, UCase(GetGadgetText(5)))
EndIf
If GetGadgetText(7) = ""
SetGadgetText(7, LCase(GetGadgetText(5)))
EndIf
EndSelect
EndSelect
EndSelect
Until Event = #PB_Event_CloseWindow
If CreateFile(0, Fichier + ".clv")
WriteStringFormat(0, #PB_Unicode)
For n = 0 To CountGadgetItems(0) - 1
If GetGadgetItemText(0, n, 0) And GetGadgetItemText(0, n, 0) And GetGadgetItemText(0, n, 0)
Ligne = GetGadgetItemText(0, n, 0) + Chr(9) + GetGadgetItemText(0, n, 1) + Chr(9) + GetGadgetItemText(0, n, 2)
WriteStringN(0, Ligne, #PB_Unicode)
EndIf
Next
CloseFile(0)
EndIf
End