Ce code fonctionne, mais renvoi pleins d'erreurs :
Code : Tout sélectionner
;Philipp Schmieder (WishMaster/vonTurnundTaxis)
;http://www.noname-development.de
;03.01.2007
;Released under the terms of the LGPL (http://www.gnu.org/licenses/lgpl.html)
Define StartIter.GtkTextIter
Define EndIter.GtkTextIter
Define PBStartIter.GtkTextIter
Define PBEndIter.GtkTextIter
Enumeration
#Pango_Style_Normal
#Pango_Style_Oblique
EndEnumeration
#Pango_Weight_Normal = 400
#Pango_Weight_Bold = 800
If OpenWindow(1, 1, 1, 800, 530, "")
If CreateGadgetList(WindowID(1))
EditorGadget(1, 0, 0, 800, 500)
SetGadgetText(1, "PureBasic" + Chr(10) + "PureBasic, ontwikkeld door Frédéric Laboureur (Fantaisie Software, Frankrijk)," + Chr(10) + "is een commerciële compiler voor Windows, Linux, AmigaOS en Mac OS. De programma's zijn klein en" + Chr(10) + "snel, de syntax een mix tussen BASIC en C. Naast de vele krachtig geoptimaliseerde bibliotheken" + Chr(10) + "(GUI-gadgets, beeld, geluid, netwerk, database, compressie, cryptografie, ....) kan men rechtstreeks" + Chr(10) + "WinAPI aanspreken en Assembler-code gebruiken (Inline-Assembler). Bovendien is het mogelijk om" + Chr(10) + "een bibliotheek te schrijven. Verder biedt PureBasic sinds versie 3.5 een rudimentaire 3D-engine" + Chr(10) + "(OGRE 3D), waarmee het mogelijk is snel en eenvoudig kleine 3-D toepassingen te programmeren." + Chr(10) + Chr(10) + "Een essentieel voordeel vergeleken met andere programmeertalen is het bijzondere feit dat de taal" + Chr(10) + "doorlopend ontwikkeld wordt, steeds krachtiger wordt en dat nieuwe instructies de taal verder" + Chr(10) + "optimaliseren. De aanschaf van PureBasic houdt automatisch in dat alle toekomstige updates gratis" + Chr(10) + "zijn in de vorm van downloads. Verdere kosten bij het verkopen van door u ontwikkelde programma's" + Chr(10) + "zijn er niet, geschreven programma's kunnen licentie-vrij verhandeld worden zonder rekening te" + Chr(10) + "hoeven houden met beperkingen van de kant van de fabrikant.")
Buffer = gtk_text_view_get_buffer_(GadgetID(1))
ButtonGadget(2, 0, 500, 200, 30, "Reset Styles")
ButtonGadget(3, 200, 500, 200, 30, "Bold")
ButtonGadget(4, 400, 500, 200, 30, "Oblique")
ComboBoxGadget(5, 600, 500, 200, 30)
AddGadgetItem(5, 0, "very small")
AddGadgetItem(5, 0, "small")
AddGadgetItem(5, 0, "big")
AddGadgetItem(5, 0, "huge")
gtk_text_buffer_create_tag_(Buffer, "bold", "weight", #Pango_Weight_Bold)
gtk_text_buffer_create_tag_(Buffer, "oblique", "style", #Pango_Style_Oblique)
gtk_text_buffer_create_tag_(Buffer, "very small", "size", 4000)
gtk_text_buffer_create_tag_(Buffer, "small", "size", 9000)
gtk_text_buffer_create_tag_(Buffer, "big", "size", 15000)
gtk_text_buffer_create_tag_(Buffer, "huge", "size", 30000)
gtk_text_buffer_get_iter_at_offset_(Buffer, @PBStartIter, 0)
gtk_text_buffer_get_iter_at_offset_(Buffer, @PBEndIter, 9)
gtk_text_buffer_apply_tag_by_name_(Buffer, "bold", @PBStartIter, @PBEndIter)
gtk_text_buffer_apply_tag_by_name_(Buffer, "big", @PBStartIter, @PBEndIter)
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case 2
gtk_text_buffer_get_selection_bounds_(Buffer, @StartIter, @EndIter)
gtk_text_buffer_remove_all_tags_(Buffer, @StartIter, @EndIter)
Case 3
gtk_text_buffer_get_selection_bounds_(Buffer, @StartIter, @EndIter)
gtk_text_buffer_apply_tag_by_name_(Buffer, "bold", @StartIter, @EndIter)
Case 4
gtk_text_buffer_get_selection_bounds_(Buffer, @StartIter, @EndIter)
gtk_text_buffer_apply_tag_by_name_(Buffer, "oblique", @StartIter, @EndIter)
Case 5
gtk_text_buffer_get_selection_bounds_(Buffer, @StartIter, @EndIter)
gtk_text_buffer_remove_tag_by_name_(Buffer, "small", @StartIter, @EndIter)
gtk_text_buffer_remove_tag_by_name_(Buffer, "very small", @StartIter, @EndIter)
gtk_text_buffer_remove_tag_by_name_(Buffer, "big", @StartIter, @EndIter)
gtk_text_buffer_remove_tag_by_name_(Buffer, "huge", @StartIter, @EndIter)
gtk_text_buffer_apply_tag_by_name_(Buffer, GetGadgetText(5), @StartIter, @EndIter)
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
EndIf
Par contre comment faire pour mettre en gras (ensuite j'imagine que c'est simple pour italique et souligné) et de changer la taille du texte.
Le post original est ici.
Code : Tout sélectionner
; Auteur : Shardik
; http://www.purebasic.fr/english/viewtopic.php?p=323004#p323004
*buffer.GtkTextBuffer
*tag.GtkTextTag
start.GtkTextIter
ende.GtkTextIter
If OpenWindow(0, 100, 200, 600, 200, "Test", #PB_Window_ScreenCentered)
CreateStatusBar(0, WindowID(0))
AddStatusBarField(#PB_Ignore)
StatusBarText(0, 0, "Test", 0)
EditorGadget(14, 10, 10, 580, 100)
SetGadgetColor(14, #PB_Gadget_BackColor, RGB(255, 255, 210))
AddGadgetItem(14, -1, "This is just an example and it works, as in my code it does as well.")
AddGadgetItem(14, -1, "But when compiling, I get an annoying warning!")
AddGadgetItem(14, -1, "Line 20, Glib-GObject: A_g_object_set_valist: object class 'GtkTextTag' has no property named ...")
EndIf
*buffer = gtk_text_view_get_buffer_(GadgetID(14))
*tag = gtk_text_tag_new_(0)
*tag\table = *buffer\tag_table
PropertyText.S = "orange"
Property.GValue
Property\g_type = 16 << 2
Property\data\v_pointer = @PropertyText
g_object_set_property_(*tag, "background", @Property)
gtk_text_buffer_get_iter_at_offset_(*buffer, @start, 8)
gtk_text_buffer_get_iter_at_offset_(*buffer, @ende, 12)
gtk_text_buffer_apply_tag_(*buffer, *tag, @start, @ende)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
End
Je pense que cela se joue ici :
*tag = gtk_text_tag_new_(0)
*tag\table = *buffer\tag_table
Pour mettre ce tag dans un tableau. Donc ajouter une nouvelle couleur c'est certainement ajouter une nouvelle case au tableau ?
Mais comme je ne comprend pas le code, forcement ça n'aide pas.
Bye.