⛏️ index : haiku.git

author Axel Dörfler <axeld@pinc-software.de> 2004-05-25 23:44:41.0 +00:00:00
committer Axel Dörfler <axeld@pinc-software.de> 2004-05-25 23:44:41.0 +00:00:00
commit
d9e5697c73d6b29cecb754cf1ff3e4e28cad68df [patch]
tree
68b66d08bf525ad5710e163d6f72cc772affcd5f
parent
ead8e787ae7defa0003ac39b767f5944399b2332
download
d9e5697c73d6b29cecb754cf1ff3e4e28cad68df.tar.gz

Selection changes via keyboard no longer copy DiskProbe's original behaviour, but can be done like in BTextView. Fixed a strange drawing bug that could happen on startup (R5): IsFocus() could return false, even if the view had focus.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7646 a95241bf-73f2-0310-859d-f6bbb57e9c96

Diff

 src/apps/diskprobe/DataView.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------
 src/apps/diskprobe/DataView.h   |   1 +
 2 files changed, 84 insertions(+), 19 deletions(-)

diff --git a/src/apps/diskprobe/DataView.cpp b/src/apps/diskprobe/DataView.cpp
index 6bdf765..a75c9ae 100644
--- a/src/apps/diskprobe/DataView.cpp
+++ b/src/apps/diskprobe/DataView.cpp
@@ -55,12 +55,13 @@
	fFocus(kHexFocus),
	fBase(kHexBase),
	fIsActive(true),
	fMouseSelectionStart(-1),
	fKeySelectionStart(-1),
	fBitPosition(0),
	fFitFontSize(false)
{
	fPositionLength = 4;
	fStart = fEnd = 0;
	fMouseSelectionStart = -1;

	if (fEditor.Lock()) {
		fDataSize = fEditor.ViewSize();
@@ -93,6 +94,9 @@
DataView::AttachedToWindow()
{
	fEditor.StartWatching(this);
	MakeFocus(true);
		// this seems to be necessary - if we don't do this here,
		// the view is sometimes focus, but IsFocus() returns false...
}


@@ -915,7 +919,7 @@
void 
DataView::MouseUp(BPoint where)
{
	fMouseSelectionStart = -1;
	fMouseSelectionStart = fKeySelectionStart = -1;
}


@@ -926,42 +930,102 @@
	if (Looper()->CurrentMessage() == NULL
		|| Looper()->CurrentMessage()->FindInt32("modifiers", &modifiers) != B_OK)
		modifiers = ::modifiers();

	// check if the selection is going to be changed
	switch (bytes[0]) {
		case B_LEFT_ARROW:
		case B_RIGHT_ARROW:
		case B_UP_ARROW:
		case B_DOWN_ARROW:
			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == -1)
					fKeySelectionStart = fStart;
			} else
				fKeySelectionStart = -1;
			break;
	}

	switch (bytes[0]) {
		case B_LEFT_ARROW:
			SetSelection(fStart - 1, modifiers & B_SHIFT_KEY ? fEnd : fStart - 1);
			MakeVisible(fStart);
		{
			int32 position = fStart - 1;

			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fEnd)
					SetSelection(fStart - 1, fEnd);
				else {
					SetSelection(fStart, fEnd - 1);
					position = fEnd;
				}
			} else
				SetSelection(fStart - 1, fStart - 1);

			MakeVisible(position);
			break;
		}
		case B_RIGHT_ARROW:
			SetSelection(modifiers & B_SHIFT_KEY ? fStart : fEnd + 1, fEnd + 1);
			MakeVisible(fEnd);
		{
			int32 position = fEnd + 1;

			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fStart)
					SetSelection(fStart, fEnd + 1);
				else
					SetSelection(fStart + 1, fEnd);
			} else
				SetSelection(fEnd + 1, fEnd + 1);

			MakeVisible(position);
			break;
		}
		case B_UP_ARROW:
		{
			int32 start = fStart - int32(kBlockSize);
			if (start < 0) {
				if (modifiers & B_SHIFT_KEY)
			int32 start, end;
			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fStart) {
					start = fEnd - int32(kBlockSize);
					end = fStart;
				} else {
					start = fStart - int32(kBlockSize);
					end = fEnd;
				}
				if (start < 0)
					start = 0;
				else
			} else {
				start = fStart - int32(kBlockSize);
				if (start < 0)
					start = fStart;

				end = start;
			}

			SetSelection(start, modifiers & B_SHIFT_KEY ? fEnd : start);
			MakeVisible(fStart);
			SetSelection(start, end);
			MakeVisible(start);
			break;
		}
		case B_DOWN_ARROW:
		{
			int32 end = fEnd + int32(kBlockSize);
			if (end >= int32(fSizeInView)) {
				if (modifiers & B_SHIFT_KEY)
			int32 start, end;
			if (modifiers & B_SHIFT_KEY) {
				if (fKeySelectionStart == fEnd) {
					start = fEnd;
					end = fStart + int32(kBlockSize);
				} else {
					start = fStart;
					end = fEnd + int32(kBlockSize);
				}
				if (end >= int32(fSizeInView))
					end = int32(fSizeInView) - 1;
				else
					end = fEnd;
			} else {
				end = fEnd + int32(kBlockSize);
				if (end >= int32(fSizeInView))
					start = fEnd;

				start = end;
			}

			SetSelection(modifiers & B_SHIFT_KEY ? fStart : end, end);
			MakeVisible(fEnd);
			SetSelection(start, end);
			MakeVisible(end);
			break;
		}

diff --git a/src/apps/diskprobe/DataView.h b/src/apps/diskprobe/DataView.h
index a5dbea8..3fcd38a 100644
--- a/src/apps/diskprobe/DataView.h
+++ b/src/apps/diskprobe/DataView.h
@@ -94,6 +94,7 @@
		bool		fIsActive;
		int32		fStart, fEnd;
		int32		fMouseSelectionStart;
		int32		fKeySelectionStart;
		int32		fBitPosition;
		bool		fFitFontSize;
};