sdlada_2.5.20_cd53c280/src/sdl-clipboard.adb

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
--------------------------------------------------------------------------------------------------------------------
--  This source code is subject to the Zlib license, see the LICENCE file in the root of this directory.
--------------------------------------------------------------------------------------------------------------------
with Interfaces.C.Strings;

with SDL.Error;
with SDL.Video.Windows;

package body SDL.Clipboard is
   package C renames Interfaces.C;

   procedure Check_For_Window is
      Init_Value : constant SDL.Init_Flags := SDL.Was_Initialised and SDL.Enable_Screen;
   begin
      if Init_Value /= SDL.Enable_Screen then
         raise Clipboard_Error with "SDL screen subsystem has not been initialised.";
      end if;

      if SDL.Video.Windows.Exist = False then
         raise Clipboard_Error with "No windows have been created.";
      end if;
   end Check_For_Window;

   function Get return Ada.Strings.UTF_Encoding.UTF_8_String is
      function SDL_Get_Clipboard_Text return C.Strings.chars_ptr with
        Import        => True,
        Convention    => C,
        External_Name => "SDL_GetClipboardText";
   begin
      Check_For_Window;

      return C.Strings.Value (SDL_Get_Clipboard_Text);
   end Get;

   function Is_Empty return Boolean is
      function SDL_Has_Clipboard_Text return SDL_Bool with
        Import        => True,
        Convention    => C,
        External_Name => "SDL_HasClipboardText";
   begin
      Check_For_Window;

      return (if SDL_Has_Clipboard_Text = SDL_True then False else True);
   end Is_Empty;

   procedure Set (Text : in Ada.Strings.UTF_Encoding.UTF_8_String) is
      function SDL_Set_Clipboard_Text (C_Str : in C.char_array) return C.int with
        Import        => True,
        Convention    => C,
        External_Name => "SDL_SetClipboardText";
   begin
      Check_For_Window;

      if SDL_Set_Clipboard_Text (C.To_C (Text)) /= Success then
         raise Clipboard_Error with SDL.Error.Get;
      end if;
   end Set;
end SDL.Clipboard;