Clipboard.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/ByteBuffer.h>
  8. #include <AK/Function.h>
  9. #include <AK/HashMap.h>
  10. #include <AK/String.h>
  11. #include <LibGUI/Forward.h>
  12. #include <LibGfx/Forward.h>
  13. namespace GUI {
  14. class Clipboard {
  15. public:
  16. static Clipboard& the();
  17. ByteBuffer data() const { return data_and_type().data; }
  18. String mime_type() const { return data_and_type().mime_type; }
  19. void set_data(ReadonlyBytes, const String& mime_type = "text/plain", const HashMap<String, String>& metadata = {});
  20. void clear();
  21. void set_plain_text(const String& text)
  22. {
  23. set_data(text.bytes());
  24. }
  25. void set_bitmap(const Gfx::Bitmap&);
  26. RefPtr<Gfx::Bitmap> bitmap() const;
  27. struct DataAndType {
  28. ByteBuffer data;
  29. String mime_type;
  30. HashMap<String, String> metadata;
  31. };
  32. DataAndType data_and_type() const;
  33. Function<void(const String& mime_type)> on_change;
  34. static void initialize(Badge<Application>);
  35. private:
  36. Clipboard();
  37. };
  38. }