summaryrefslogtreecommitdiffstats
path: root/quanta/parts/kafka/cursors.cpp
blob: 970dfd051c3bb503f35e62d30dc5721a4bfbb625 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/***************************************************************************
                                   cursor.cpp
                             -------------------

    copyright            : (C) 2004 - Nicolas Deschildre
    email                : ndeschildre@tdewebdev.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
 

#include "wkafkapart.h"
#include "kafkacommon.h"
#include "viewmanager.h"
  
#include "cursors.h"
 
 
NodeSelectionInd::NodeSelectionInd()
    : m_cursorOffset(-1), m_cursorOffsetEndSel(-1), m_cursorAtSelectionStart(true)
{
}

NodeSelectionInd::NodeSelectionInd(Node* cursor_node, int cursor_offset)
    : m_cursorOffset(cursor_offset), m_cursorOffsetEndSel(-1), m_cursorAtSelectionStart(true)
{
    setCursorNode(kafkaCommon::getLocation(cursor_node));
}

NodeSelectionInd::NodeSelectionInd(Node* start_node, int start_offset, Node* end_node, int end_offset)
    : m_cursorOffset(end_offset), m_cursorOffsetEndSel(end_offset), m_cursorAtSelectionStart(false)
{
    setCursorNode(kafkaCommon::getLocation(start_node));
    setCursorOffset(start_offset);
    setCursorNodeEndSel(kafkaCommon::getLocation(end_node));
    setCursorOffsetEndSel(end_offset);
}
  
NodeSelectionInd::~NodeSelectionInd()
{
}

bool NodeSelectionInd::operator==(const NodeSelectionInd & nodeSelection)
{
  return (m_cursorNode == nodeSelection.m_cursorNode && m_cursorNodeEndSel == nodeSelection.m_cursorNodeEndSel &&
    m_cursorOffset == nodeSelection.m_cursorOffset && m_cursorOffsetEndSel == nodeSelection.m_cursorOffsetEndSel &&
    m_cursorAtSelectionStart == nodeSelection.m_cursorAtSelectionStart);
}

void NodeSelectionInd::operator=(const NodeSelectionInd & nodeSelection)
{
  m_cursorNode = nodeSelection.m_cursorNode;
  m_cursorNodeEndSel = nodeSelection.m_cursorNodeEndSel;
  m_cursorOffset = nodeSelection.m_cursorOffset;
  m_cursorOffsetEndSel = nodeSelection.m_cursorOffsetEndSel;
  m_cursorAtSelectionStart = nodeSelection.m_cursorAtSelectionStart;
}

void NodeSelectionInd::fillWithVPLCursorSelection()
{
  KafkaDocument *kafkaDoc;
  DOM::Node domNode, domNodeEndSel;
  long domOffset, domOffsetEndSel;
  Node *node = 0L;
  Node *nodeEndSel = 0L;
  long offset, offsetEndSel;

  kafkaDoc = KafkaDocument::ref();
  kafkaDoc->getKafkaWidget()->getCurrentNode(domNode, domOffset);
  kafkaDoc->translateKafkaIntoNodeCursorPosition(domNode, domOffset, &node, offset);
  m_cursorNode = kafkaCommon::getLocation(node);
  m_cursorOffset = offset;
  
  if(kafkaDoc->getKafkaWidget()->hasSelection())
  {
    kafkaDoc->getKafkaWidget()->selection(domNode, domOffset, domNodeEndSel, domOffsetEndSel);
    KafkaDocument::ref()->translateKafkaIntoNodeCursorPosition(domNodeEndSel, domOffsetEndSel,
      &nodeEndSel, offsetEndSel);
    m_cursorNodeEndSel = kafkaCommon::getLocation(nodeEndSel);
    m_cursorOffsetEndSel = offsetEndSel;
    
    m_cursorAtSelectionStart = !(m_cursorOffsetEndSel == m_cursorOffset && m_cursorNodeEndSel == m_cursorNode);
    
    if(!m_cursorAtSelectionStart)
    {
      KafkaDocument::ref()->translateKafkaIntoNodeCursorPosition(domNode, domOffset, &node, offset);
      m_cursorNode = kafkaCommon::getLocation(node);
      m_cursorOffset = offset;
    }
  }
}

bool NodeSelectionInd::hasSelection() const
{
    return KafkaDocument::ref()->getKafkaWidget()->hasSelection();
}