Dillo v3.1.1-111-gd4f56d0d
|
This class handles selections, as well as activation of links, which is closely related. More...
#include <selection.hh>
Public Types | |
enum | { END_OF_WORD = 1 << 30 } |
enum | EventType { BUTTON_PRESS , BUTTON_RELEASE , BUTTON_MOTION } |
Public Member Functions | |
SelectionState () | |
~SelectionState () | |
void | setLayout (Layout *layout) |
void | reset () |
bool | buttonPress (Iterator *it, int charPos, int linkNo, EventButton *event) |
bool | buttonRelease (Iterator *it, int charPos, int linkNo, EventButton *event) |
bool | buttonMotion (Iterator *it, int charPos, int linkNo, EventMotion *event) |
bool | handleEvent (EventType eventType, Iterator *it, int charPos, int linkNo, MousePositionEvent *event) |
General form of dw::core::SelectionState::buttonPress, dw::core::SelectionState::buttonRelease and dw::core::SelectionState::buttonMotion. | |
Private Types | |
enum | { NONE , SELECTING , SELECTED } |
enum | { LINK_NONE , LINK_PRESSED } |
Private Member Functions | |
void | resetSelection () |
void | resetLink () |
void | switchLinkToSelection (Iterator *it, int charPos) |
This method is called when the user decides not to activate a link, but instead select text. | |
void | adjustSelection (Iterator *it, int charPos) |
This method is used by core::dw::SelectionState::buttonMotion and core::dw::SelectionState::buttonRelease, and changes the second limit of the already existing selection region. | |
void | highlight (bool fl, int dir) |
void | highlight0 (bool fl, DeepIterator *from, int fromChar, DeepIterator *to, int toChar, int dir) |
void | copy () |
Static Private Member Functions | |
static int | correctCharPos (DeepIterator *it, int charPos) |
This method deals especially with the case that a widget passes dw::core::SelectionState::END_OF_WORD. | |
Private Attributes | |
Layout * | layout |
enum dw::core::SelectionState:: { ... } | selectionState |
DeepIterator * | from |
DeepIterator * | to |
int | fromChar |
int | toChar |
enum dw::core::SelectionState:: { ... } | linkState |
int | linkButton |
DeepIterator * | link |
int | linkChar |
int | linkNumber |
This class handles selections, as well as activation of links, which is closely related.
dw::core::SelectionState is associated with dw::core::Layout. The selection state is controlled by "abstract events", which are sent by single widgets by calling one of the following methods:
The widget must construct simple iterators (dw::core::Iterator), which will be transferred to deep iterators (dw::core::DeepIterator), see below for more details. All event handling methods have the same signature, the arguments in detail are:
dw::core::Iterator *it | the iterator pointing on the item under the mouse pointer; this iterator must be created with dw::core::Content::SELECTION_CONTENT as mask |
int charPos | the exact (character) position within the iterator, |
int linkNo | if this item is associated with a link, its number (see dw::core::Layout::LinkReceiver), otherwise -1 |
dw::core::EventButton *event | the event itself; only the button is used |
Look also at dw::core::SelectionState::handleEvent, which may be useful in some circumstances.
In some cases, charPos would be difficult to determine. E.g., when the dw::Textblock widget decides that the user is pointing on a position at the end of an image (DwImage), it constructs a simple iterator pointing on this image widget. In a simple iterator, that fact that the pointer is at the end, would be represented by charPos == 1. But when transferring this simple iterator into an deep iterator, this simple iterator is discarded and instead the stack has an iterator pointing to text at the top. As a result, only the first letter of the ALT text would be copied.
To avoid this problem, widgets should in this case pass dw::core::SelectionState::END_OF_WORD as charPos, which is then automatically reduced to the actual length of the deep(!) iterator.
The return value is the same as in DwWidget event handling methods. I.e., in most cases, they should simply return it. The events dw::core::Layout::LinkReceiver::press, dw::core::Layout::LinkReceiver::release and dw::core::Layout::LinkReceiver::click (but not dw::core::Layout::LinkReceiver::enter) are emitted by these methods, so that widgets which let dw::core::SelectionState handle links, should only emit dw::core::Layout::LinkReceiver::enter for themselves.
Selection interferes with handling the activation of links, so the latter is also handled by the dw::core::SelectionState. Details are based on following guidelines:
It should be simple to select links and to start selection in links. The rule to distinguish between link activation and selection is that the selection starts as soon as the user leaves the link. (This is, IMO, a useful feature. Even after drag and drop has been implemented in dillo, this should be somehow preserved.)
The latter leads to a model with two states: the selection state and the link handling state.
The general selection works, for events not pointing on links, like this (numbers in parantheses after the event denote the button, "n" means arbitrary button):
The selected region is represented by two instances of dw::core::DeepIterator.
Links are handled by a different state machine:
Switching selection simply means that the selection state will eventually be SELECTED/SELECTING, with the original and the current position making up the selection region. This happens for button 1, events with buttons other than 1 do not affect selection at all.
Definition at line 178 of file selection.hh.
anonymous enum |
Enumerator | |
---|---|
END_OF_WORD |
Definition at line 181 of file selection.hh.
|
private |
Enumerator | |
---|---|
NONE | |
SELECTING | |
SELECTED |
Definition at line 187 of file selection.hh.
|
private |
Enumerator | |
---|---|
LINK_NONE | |
LINK_PRESSED |
Definition at line 197 of file selection.hh.
Enumerator | |
---|---|
BUTTON_PRESS | |
BUTTON_RELEASE | |
BUTTON_MOTION |
Definition at line 220 of file selection.hh.
dw::core::SelectionState::SelectionState | ( | ) |
Definition at line 47 of file selection.cc.
References DBG_OBJ_CREATE, from, layout, link, LINK_NONE, linkState, NONE, selectionState, and to.
dw::core::SelectionState::~SelectionState | ( | ) |
Definition at line 61 of file selection.cc.
References DBG_OBJ_DELETE, and reset().
|
private |
This method is used by core::dw::SelectionState::buttonMotion and core::dw::SelectionState::buttonRelease, and changes the second limit of the already existing selection region.
Definition at line 293 of file selection.cc.
References dw::core::DeepIterator::compareTo(), correctCharPos(), dw::core::DeepIterator::createVariant(), END_OF_WORD, from, highlight(), dw::core::DeepIterator::highlight(), highlight0(), dw::core::HIGHLIGHT_SELECTION, to, and toChar.
Referenced by buttonMotion(), and buttonRelease().
bool dw::core::SelectionState::buttonMotion | ( | Iterator * | it, |
int | charPos, | ||
int | linkNo, | ||
EventMotion * | event | ||
) |
Definition at line 210 of file selection.cc.
References adjustSelection(), LINK_PRESSED, linkNumber, linkState, SELECTING, selectionState, and switchLinkToSelection().
Referenced by handleEvent().
bool dw::core::SelectionState::buttonPress | ( | Iterator * | it, |
int | charPos, | ||
int | linkNo, | ||
EventButton * | event | ||
) |
Definition at line 93 of file selection.cc.
References dw::core::EventButton::button, dw::core::DeepIterator::cloneDeepIterator(), correctCharPos(), DBG_IF_RTFL, DBG_OBJ_ENTER, DBG_OBJ_LEAVE, DBG_OBJ_MSGF, dw::core::Layout::emitLinkPress(), from, fromChar, lout::misc::StringBuffer::getChars(), dw::core::Iterator::getWidget(), highlight(), dw::core::Iterator::intoStringBuffer(), dw::core::DeepIterator::isEmpty(), layout, link, LINK_PRESSED, linkButton, linkChar, linkNumber, linkState, resetLink(), resetSelection(), SELECTING, selectionState, to, and toChar.
Referenced by handleEvent().
bool dw::core::SelectionState::buttonRelease | ( | Iterator * | it, |
int | charPos, | ||
int | linkNo, | ||
EventButton * | event | ||
) |
Definition at line 159 of file selection.cc.
References adjustSelection(), dw::core::EventButton::button, dw::core::DeepIterator::compareTo(), copy(), DBG_IF_RTFL, DBG_OBJ_ENTER, DBG_OBJ_LEAVE, DBG_OBJ_MSGF, dw::core::Layout::emitLinkClick(), dw::core::Layout::emitLinkRelease(), from, fromChar, lout::misc::StringBuffer::getChars(), dw::core::Iterator::getWidget(), dw::core::Iterator::intoStringBuffer(), layout, LINK_PRESSED, linkButton, linkNumber, linkState, resetLink(), resetSelection(), SELECTED, SELECTING, selectionState, switchLinkToSelection(), to, and toChar.
Referenced by handleEvent().
|
private |
Definition at line 425 of file selection.cc.
References lout::misc::StringBuffer::append(), lout::misc::StringBuffer::appendNoCopy(), dw::core::Content::BREAK, dw::core::Content::breakSpace, dw::core::DeepIterator::cloneDeepIterator(), dw::core::DeepIterator::compareTo(), dw::core::Layout::copySelection(), from, fromChar, lout::misc::StringBuffer::getChars(), dw::core::Iterator::getContent(), dw::core::DeepIterator::getContent(), dw::core::DeepIterator::getTopIterator(), layout, dw::core::DeepIterator::next(), dw::core::Content::space, strndup(), dw::core::Content::TEXT, dw::core::Content::text, to, toChar, and dw::core::Content::type.
Referenced by buttonRelease().
|
staticprivate |
This method deals especially with the case that a widget passes dw::core::SelectionState::END_OF_WORD.
Definition at line 356 of file selection.cc.
References dw::core::Iterator::getContent(), dw::core::DeepIterator::getTopIterator(), lout::misc::min(), dw::core::Content::TEXT, dw::core::Content::text, and dw::core::Content::type.
Referenced by adjustSelection(), buttonPress(), and switchLinkToSelection().
bool dw::core::SelectionState::handleEvent | ( | EventType | eventType, |
Iterator * | it, | ||
int | charPos, | ||
int | linkNo, | ||
MousePositionEvent * | event | ||
) |
General form of dw::core::SelectionState::buttonPress, dw::core::SelectionState::buttonRelease and dw::core::SelectionState::buttonMotion.
Definition at line 233 of file selection.cc.
References lout::misc::assertNotReached(), BUTTON_MOTION, BUTTON_PRESS, BUTTON_RELEASE, buttonMotion(), buttonPress(), and buttonRelease().
Referenced by dw::core::Widget::selectionHandleEvent().
|
inlineprivate |
Definition at line 212 of file selection.hh.
References from, fromChar, highlight0(), to, and toChar.
Referenced by adjustSelection(), buttonPress(), and switchLinkToSelection().
|
private |
Definition at line 369 of file selection.cc.
References dw::core::DeepIterator::cloneDeepIterator(), dw::core::DeepIterator::compareTo(), from, fromChar, dw::core::DeepIterator::getContent(), dw::core::DeepIterator::highlight(), dw::core::HIGHLIGHT_SELECTION, dw::core::DeepIterator::next(), dw::core::Content::TEXT, dw::core::Content::text, to, toChar, dw::core::Content::type, and dw::core::DeepIterator::unhighlight().
Referenced by adjustSelection(), and highlight().
void dw::core::SelectionState::reset | ( | ) |
Definition at line 67 of file selection.cc.
References resetLink(), and resetSelection().
Referenced by dw::core::Layout::removeWidget(), and ~SelectionState().
|
private |
Definition at line 85 of file selection.cc.
References link, LINK_NONE, and linkState.
Referenced by buttonPress(), buttonRelease(), reset(), and switchLinkToSelection().
|
private |
Definition at line 73 of file selection.cc.
References from, NONE, selectionState, and to.
Referenced by buttonPress(), buttonRelease(), reset(), and switchLinkToSelection().
|
inline |
Definition at line 225 of file selection.hh.
References layout.
Referenced by dw::core::Layout::Layout().
|
private |
This method is called when the user decides not to activate a link, but instead select text.
Definition at line 260 of file selection.cc.
References dw::core::DeepIterator::cloneDeepIterator(), correctCharPos(), dw::core::DeepIterator::createVariant(), from, fromChar, highlight(), link, linkChar, resetLink(), resetSelection(), SELECTING, selectionState, to, and toChar.
Referenced by buttonMotion(), and buttonRelease().
|
private |
Definition at line 193 of file selection.hh.
Referenced by adjustSelection(), buttonPress(), buttonRelease(), copy(), highlight(), highlight0(), resetSelection(), SelectionState(), and switchLinkToSelection().
|
private |
Definition at line 194 of file selection.hh.
Referenced by buttonPress(), buttonRelease(), copy(), highlight(), highlight0(), and switchLinkToSelection().
|
private |
Definition at line 184 of file selection.hh.
Referenced by buttonPress(), buttonRelease(), copy(), SelectionState(), and setLayout().
|
private |
Definition at line 203 of file selection.hh.
Referenced by buttonPress(), resetLink(), SelectionState(), and switchLinkToSelection().
|
private |
Definition at line 202 of file selection.hh.
Referenced by buttonPress(), and buttonRelease().
|
private |
Definition at line 204 of file selection.hh.
Referenced by buttonPress(), and switchLinkToSelection().
|
private |
Definition at line 204 of file selection.hh.
Referenced by buttonMotion(), buttonPress(), and buttonRelease().
enum { ... } dw::core::SelectionState::linkState |
Referenced by buttonMotion(), buttonPress(), buttonRelease(), resetLink(), and SelectionState().
enum { ... } dw::core::SelectionState::selectionState |
Referenced by buttonMotion(), buttonPress(), buttonRelease(), resetSelection(), SelectionState(), and switchLinkToSelection().
|
private |
Definition at line 193 of file selection.hh.
Referenced by adjustSelection(), buttonPress(), buttonRelease(), copy(), highlight(), highlight0(), resetSelection(), SelectionState(), and switchLinkToSelection().
|
private |
Definition at line 194 of file selection.hh.
Referenced by adjustSelection(), buttonPress(), buttonRelease(), copy(), highlight(), highlight0(), and switchLinkToSelection().