comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: GtkAda and €
Date: Sat, 11 Sep 2021 12:04:40 +0200	[thread overview]
Message-ID: <shhuvp$1sik$1@gioia.aioe.org> (raw)
In-Reply-To: 234ee351-3abb-445e-9d34-d5abd7a8a9b6n@googlegroups.com

On 2021-09-11 11:20, AdaMagica wrote:
> Is there no way to use the character € directly? Imagine, you want to write cyrillc on label of a gui? Would you use hex values or would you write
> Я говорю по-русски.

I would never use Cyrillic in the source code.

Anyway, this is a question regarding the encoding of literals in Ada. 
Ada 2X supports Unicode and GNAT supports Unicode sources.

I never tried it but I suppose the following should work:

    Strings_Edit.UTF8.Handling.To_UTF8 ('€');

Here '€' should be resolved to Wide_Character'('€') and then converted 
to a UTF-8 encoded String.

As for labels, icons etc, I use GTK style properties.

I.e. let I have a label with a text on it. Usually this label would be 
packed in some larger container widget, e.g. Gtk_Grid_Record. I derive a 
custom widget from Gtk_Grid_Record. Then I call Initialize_Class_Record 
once to create the new widget "type" (used G_New). There I add style 
properties like this:

    Class_Record : aliased Ada_GObject_Class := Uninitialized_Class;
    ...

    procedure Initialize
              (  Widget : not null access My_Widget_Record'Class
              )  is
    begin
       G_New (Widget, Get_Type); -- Get_Type will register class
       ...


    function Get_Type return GType is
    begin
       if Initialize_Class_Record
          (  Ancestor     => Gtk.Grid.Get_Type, -- Parent class
             Class_Record => Class_Record'Access,
             Type_Name    => "mywidget"
          )  then -- Not yet registerd
          Install_Style_Property
          (  GLib.Types.Class_Ref (Class_Record.The_Type),
             Gnew_String
             (  Name    => "label",
                Nick    => "Label",
                Blurb   => "Label text I want to be able to change",
                Default => "I speak English"
          )  );
          ...
       end if;
       return Class_Record.The_Type;
   end Get_Type;

The widget must handle "style-updated" from where it would use Style_Get 
to get the label text and set it into the label.

So, a Russian localization would be a CSS sheet file defining the 
property "label":
---------------------------
mywidget {
    -mywidget-label: "Я говорю по-русски";
}
---------------------------

P.S. Inventors of GTK CSS sheets apparently misspelled the word "sheet", 
they should have used the letter 'i'! (:-))

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  parent reply	other threads:[~2021-09-11 10:04 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-10 17:56 GtkAda and € AdaMagica
2021-09-10 18:53 ` Dmitry A. Kazakov
2021-09-11  9:20   ` AdaMagica
2021-09-11  9:57     ` AdaMagica
2021-09-11 10:04     ` Dmitry A. Kazakov [this message]
2021-09-11 11:11       ` Emmanuel Briot
2021-09-11 12:47         ` Dmitry A. Kazakov
2021-09-11 13:26       ` AdaMagica
2021-09-11 13:51         ` AdaMagica
2021-09-11 14:13           ` Dmitry A. Kazakov
2021-09-11 17:46           ` Manuel Gomez
2021-09-12  7:04             ` AdaMagica
2021-09-12 11:44               ` Manuel Gomez
2021-09-13  7:21           ` Vadim Godunko
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox