From 7f6226e52884b13e7b24ed5c53da7bdfd51ea147 Mon Sep 17 00:00:00 2001
From: Markus Himmel <markus@himmel-villmar.de>
Date: Thu, 1 Jan 2015 19:51:25 +0000
Subject: [PATCH] DiskProbe: Make block offset and file offset editable
Fix #4046
---
src/apps/diskprobe/ProbeView.cpp | 79 ++++++++++++++++++++++++++++------------
1 file changed, 55 insertions(+), 24 deletions(-)
diff --git a/src/apps/diskprobe/ProbeView.cpp b/src/apps/diskprobe/ProbeView.cpp
index e0a7a4c..1a4e2e4 100644
a
|
b
|
class HeaderView : public BGridView, public BInvoker {
|
131 | 131 | base_type Base() const { return fBase; } |
132 | 132 | void SetBase(base_type); |
133 | 133 | |
134 | | off_t CursorOffset() const { return fOffset; } |
| 134 | off_t CursorOffset() const { return fPosition % fBlockSize; } |
135 | 135 | off_t Position() const { return fPosition; } |
136 | 136 | uint32 BlockSize() const { return fBlockSize; } |
137 | 137 | void SetTo(off_t position, uint32 blockSize); |
… |
… |
class HeaderView : public BGridView, public BInvoker {
|
148 | 148 | const char *fAttribute; |
149 | 149 | off_t fFileSize; |
150 | 150 | uint32 fBlockSize; |
151 | | off_t fOffset; |
152 | 151 | base_type fBase; |
153 | 152 | off_t fPosition; |
154 | 153 | off_t fLastPosition; |
… |
… |
class HeaderView : public BGridView, public BInvoker {
|
157 | 156 | BTextControl *fPositionControl; |
158 | 157 | BStringView *fPathView; |
159 | 158 | BStringView *fSizeView; |
160 | | BStringView *fOffsetView; |
161 | | BStringView *fFileOffsetView; |
| 159 | BTextControl *fOffsetControl; |
| 160 | BTextControl *fFileOffsetControl; |
162 | 161 | PositionSlider *fPositionSlider; |
163 | 162 | IconView *fIconView; |
164 | 163 | BButton *fStopButton; |
… |
… |
HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)
|
477 | 476 | fAttribute(editor.Attribute()), |
478 | 477 | fFileSize(editor.FileSize()), |
479 | 478 | fBlockSize(editor.BlockSize()), |
480 | | fOffset(0), |
481 | 479 | fBase(kHexBase), |
482 | 480 | fPosition(0), |
483 | 481 | fLastPosition(0) |
… |
… |
HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)
|
551 | 549 | stringView->SetFont(&boldFont); |
552 | 550 | line->AddChild(stringView); |
553 | 551 | |
| 552 | BMessage* msg = new BMessage(kMsgPositionUpdate); |
| 553 | msg->AddBool("fPositionControl", true); |
554 | 554 | // BTextControl oddities |
555 | | fPositionControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0", |
556 | | new BMessage(kMsgPositionUpdate)); |
| 555 | fPositionControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0", msg); |
557 | 556 | fPositionControl->SetDivider(0.0); |
558 | 557 | fPositionControl->SetFont(&plainFont); |
559 | 558 | fPositionControl->TextView()->SetFontAndColor(&plainFont); |
560 | | fPositionControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_RIGHT); |
| 559 | fPositionControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT); |
561 | 560 | line->AddChild(fPositionControl); |
562 | 561 | |
563 | 562 | fSizeView = new BStringView(B_EMPTY_STRING, B_TRANSLATE_COMMENT("of " |
… |
… |
HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)
|
572 | 571 | stringView->SetFont(&boldFont); |
573 | 572 | line->AddChild(stringView); |
574 | 573 | |
575 | | fOffsetView = new BStringView(B_EMPTY_STRING, "0x0"); |
576 | | fOffsetView->SetFont(&plainFont); |
577 | | line->AddChild(fOffsetView); |
| 574 | msg = new BMessage(kMsgPositionUpdate); |
| 575 | msg->AddBool("fOffsetControl", false); |
| 576 | fOffsetControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0", msg); |
| 577 | fOffsetControl->SetDivider(0.0); |
| 578 | fOffsetControl->SetFont(&plainFont); |
| 579 | fOffsetControl->TextView()->SetFontAndColor(&plainFont); |
| 580 | fOffsetControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT); |
| 581 | line->AddChild(fOffsetControl); |
578 | 582 | UpdateOffsetViews(false); |
579 | 583 | |
580 | 584 | stringView = new BStringView(B_EMPTY_STRING, editor.IsAttribute() |
… |
… |
HeaderView::HeaderView(const entry_ref *ref, DataEditor &editor)
|
583 | 587 | stringView->SetFont(&boldFont); |
584 | 588 | line->AddChild(stringView); |
585 | 589 | |
586 | | fFileOffsetView = new BStringView(B_EMPTY_STRING, "0x0"); |
587 | | fFileOffsetView->SetFont(&plainFont); |
588 | | line->AddChild(fFileOffsetView); |
| 590 | msg = new BMessage(kMsgPositionUpdate); |
| 591 | msg->AddBool("fFileOffsetControl", false); |
| 592 | fFileOffsetControl = new BTextControl(B_EMPTY_STRING, NULL, "0x0", msg); |
| 593 | fFileOffsetControl->SetDivider(0.0); |
| 594 | fFileOffsetControl->SetFont(&plainFont); |
| 595 | fFileOffsetControl->TextView()->SetFontAndColor(&plainFont); |
| 596 | fFileOffsetControl->SetAlignment(B_ALIGN_LEFT, B_ALIGN_LEFT); |
| 597 | line->AddChild(fFileOffsetControl); |
589 | 598 | |
590 | 599 | BGroupLayoutBuilder(line).AddGlue(); |
591 | 600 | |
… |
… |
HeaderView::AttachedToWindow()
|
609 | 618 | |
610 | 619 | fStopButton->SetTarget(Parent()); |
611 | 620 | fPositionControl->SetTarget(this); |
| 621 | fOffsetControl->SetTarget(this); |
| 622 | fFileOffsetControl->SetTarget(this); |
612 | 623 | fPositionSlider->SetTarget(this); |
613 | 624 | |
614 | 625 | BMessage *message; |
… |
… |
HeaderView::UpdatePositionViews(bool all)
|
660 | 671 | fPositionControl->SetText(buffer); |
661 | 672 | |
662 | 673 | if (all) { |
663 | | FormatValue(buffer, sizeof(buffer), fPosition + fOffset); |
664 | | fFileOffsetView->SetText(buffer); |
| 674 | FormatValue(buffer, sizeof(buffer), fPosition); |
| 675 | fFileOffsetControl->SetText(buffer); |
665 | 676 | } |
666 | 677 | } |
667 | 678 | |
… |
… |
void
|
670 | 681 | HeaderView::UpdateOffsetViews(bool all) |
671 | 682 | { |
672 | 683 | char buffer[64]; |
673 | | FormatValue(buffer, sizeof(buffer), fOffset); |
674 | | fOffsetView->SetText(buffer); |
| 684 | FormatValue(buffer, sizeof(buffer), fPosition % fBlockSize); |
| 685 | fOffsetControl->SetText(buffer); |
675 | 686 | |
676 | 687 | if (all) { |
677 | | FormatValue(buffer, sizeof(buffer), fPosition + fOffset); |
678 | | fFileOffsetView->SetText(buffer); |
| 688 | FormatValue(buffer, sizeof(buffer), fPosition); |
| 689 | fFileOffsetControl->SetText(buffer); |
679 | 690 | } |
680 | 691 | } |
681 | 692 | |
… |
… |
HeaderView::MessageReceived(BMessage *message)
|
743 | 754 | case kDataViewCursorPosition: |
744 | 755 | off_t offset; |
745 | 756 | if (message->FindInt64("position", &offset) == B_OK) { |
746 | | fOffset = offset; |
| 757 | fPosition = (fPosition / fBlockSize) * fBlockSize |
| 758 | + offset; |
747 | 759 | UpdateOffsetViews(); |
748 | 760 | } |
749 | 761 | break; |
… |
… |
HeaderView::MessageReceived(BMessage *message)
|
810 | 822 | |
811 | 823 | off_t position; |
812 | 824 | int32 delta; |
| 825 | bool round = true; |
813 | 826 | if (message->FindInt64("position", &position) == B_OK) |
814 | 827 | fPosition = position; |
815 | 828 | else if (message->FindInt64("block", &position) == B_OK) { |
… |
… |
HeaderView::MessageReceived(BMessage *message)
|
822 | 835 | try { |
823 | 836 | ExpressionParser parser; |
824 | 837 | parser.SetSupportHexInput(true); |
825 | | fPosition = parser.EvaluateToInt64( |
826 | | fPositionControl->Text()) * fBlockSize; |
| 838 | if (message->FindBool("fPositionControl", &round) |
| 839 | == B_OK) { |
| 840 | fPosition = parser.EvaluateToInt64( |
| 841 | fPositionControl->Text()) * fBlockSize; |
| 842 | } else if (message->FindBool("fOffsetControl", &round) |
| 843 | == B_OK) { |
| 844 | fPosition = (fPosition / fBlockSize) * fBlockSize + |
| 845 | parser.EvaluateToInt64(fOffsetControl->Text()); |
| 846 | } else if (message->FindBool("fFileOffsetControl", &round) |
| 847 | == B_OK) { |
| 848 | fPosition = parser.EvaluateToInt64( |
| 849 | fFileOffsetControl->Text()); |
| 850 | } |
827 | 851 | } catch (...) { |
828 | 852 | beep(); |
829 | 853 | break; |
… |
… |
HeaderView::MessageReceived(BMessage *message)
|
831 | 855 | } |
832 | 856 | |
833 | 857 | fLastPosition = lastPosition; |
834 | | fPosition = (fPosition / fBlockSize) * fBlockSize; |
| 858 | |
| 859 | if (round) |
| 860 | fPosition = (fPosition / fBlockSize) * fBlockSize; |
835 | 861 | // round to block size |
836 | 862 | |
837 | 863 | if (fPosition < 0) |
… |
… |
EditorLooper::MessageReceived(BMessage *message)
|
975 | 1001 | if (message->FindInt64("position", &position) == B_OK) { |
976 | 1002 | BAutolock locker(fEditor); |
977 | 1003 | fEditor.SetViewOffset(position); |
| 1004 | |
| 1005 | BMessage message(kMsgSetSelection); |
| 1006 | message.AddInt64("start", position - fEditor.ViewOffset()); |
| 1007 | message.AddInt64("end", position - fEditor.ViewOffset()); |
| 1008 | fMessenger.SendMessage(&message); |
978 | 1009 | } |
979 | 1010 | break; |
980 | 1011 | } |