summaryrefslogtreecommitdiffstats
path: root/kviewshell/selection.cpp
blob: 83b9b5db033729162e00cd970be3592b6f72d501 (plain)
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
59
60
61
62
63
64
65
66
//
// selection.cpp
//
// Part of KDVI - A previewer for TeX DVI files.
//
// (C) 2001--2004 Stefan Kebekus
// Distributed under the GPL

#include <config.h>

#include <tqapplication.h>
#include <tqclipboard.h>

#include "selection.h"

TextSelection::TextSelection()
  : page(PageNumber::invalidPage),
    selectedText(TQString::null)
{}


void TextSelection::set(const PageNumber& pageNr, Q_INT32 start, Q_INT32 end, const TQString& text)
{
  page              = pageNr;
  selectedTextStart = start;
  selectedTextEnd   = end;
  if (page != 0)
    selectedText = text;
  else
    selectedText = TQString::null;

  if (page != 0) {
    TQApplication::clipboard()->setSelectionMode(true);
    TQApplication::clipboard()->setText(selectedText);
  }
}


bool TextSelection::operator== (const TextSelection& s) const
{
  // We don't check if the strings are equal because for corretly constructed selection objects this is always
  // the case if the following condition holds.
  return (page == s.page && selectedTextStart == s.selectedTextStart && selectedTextEnd == s.selectedTextEnd);
}


bool TextSelection::operator!= (const TextSelection& s) const
{
  return !(*this == s);
}


void TextSelection::copyText() const
{
  if (!isEmpty()) {
    TQApplication::clipboard()->setSelectionMode(false);
    TQApplication::clipboard()->setText(selectedText);
  }
}


void TextSelection::clear()
{
  set(0, -1, -1, TQString::null);
}