layout_selection.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "layout/layout_selection.h"
  8. bool IsSubGroupSelection(TextSelection selection) {
  9. return (selection.from == 0xFFFF) && (selection.to != 0xFFFF);
  10. }
  11. bool IsGroupItemSelection(
  12. TextSelection selection,
  13. int index) {
  14. Expects(index >= 0 && index < 0x0F);
  15. return IsSubGroupSelection(selection) && (selection.to & (1 << index));
  16. }
  17. TextSelection AddGroupItemSelection(
  18. TextSelection selection,
  19. int index) {
  20. Expects(index >= 0 && index < 0x0F);
  21. const auto bit = uint16(1U << index);
  22. return TextSelection(
  23. 0xFFFF,
  24. IsSubGroupSelection(selection) ? (selection.to | bit) : bit);
  25. }
  26. TextSelection RemoveGroupItemSelection(
  27. TextSelection selection,
  28. int index) {
  29. Expects(index >= 0 && index < 0x0F);
  30. const auto bit = uint16(1U << index);
  31. return IsSubGroupSelection(selection)
  32. ? TextSelection(0xFFFF, selection.to & ~bit)
  33. : selection;
  34. }