* Implemented Copy(), Cut(), and Paste() for the hex mode. Additionally, the
text view will now accept raw data in text mode as well. * This closes bug #3327. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28976 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,21 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2004, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2004-2009, Axel Dörfler, [email protected].
|
||||||
** Distributed under the terms of the Haiku License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "FindWindow.h"
|
#include "FindWindow.h"
|
||||||
|
|
||||||
|
#include "DataView.h"
|
||||||
#include "DiskProbe.h"
|
#include "DiskProbe.h"
|
||||||
|
|
||||||
|
#include <AutoLocker.h>
|
||||||
|
|
||||||
#include <Application.h>
|
#include <Application.h>
|
||||||
#include <TextView.h>
|
#include <Autolock.h>
|
||||||
#include <MenuField.h>
|
|
||||||
#include <PopUpMenu.h>
|
|
||||||
#include <MenuItem.h>
|
|
||||||
#include <Button.h>
|
|
||||||
#include <ScrollView.h>
|
|
||||||
#include <CheckBox.h>
|
|
||||||
#include <Beep.h>
|
#include <Beep.h>
|
||||||
|
#include <Button.h>
|
||||||
|
#include <CheckBox.h>
|
||||||
|
#include <Clipboard.h>
|
||||||
|
#include <MenuField.h>
|
||||||
|
#include <MenuItem.h>
|
||||||
|
#include <Mime.h>
|
||||||
|
#include <PopUpMenu.h>
|
||||||
|
#include <ScrollView.h>
|
||||||
|
#include <TextView.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -27,39 +34,44 @@ static const uint32 kMsgStartFind = 'SFnd';
|
|||||||
|
|
||||||
|
|
||||||
class FindTextView : public BTextView {
|
class FindTextView : public BTextView {
|
||||||
public:
|
public:
|
||||||
FindTextView(BRect frame, const char *name, BRect textRect, uint32 resizeMask);
|
FindTextView(BRect frame, const char* name,
|
||||||
|
BRect textRect, uint32 resizeMask);
|
||||||
|
|
||||||
virtual void MakeFocus(bool state);
|
virtual void MakeFocus(bool state);
|
||||||
virtual void TargetedByScrollView(BScrollView *view);
|
virtual void TargetedByScrollView(BScrollView* view);
|
||||||
|
|
||||||
find_mode Mode() const { return fMode; }
|
find_mode Mode() const { return fMode; }
|
||||||
status_t SetMode(find_mode mode);
|
status_t SetMode(find_mode mode);
|
||||||
|
|
||||||
void SetData(BMessage &message);
|
void SetData(BMessage& message);
|
||||||
void GetData(BMessage &message);
|
void GetData(BMessage& message);
|
||||||
|
|
||||||
virtual void KeyDown(const char *bytes, int32 numBytes);
|
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||||
|
|
||||||
protected:
|
virtual bool AcceptsPaste(BClipboard* clipboard);
|
||||||
virtual void InsertText(const char *text, int32 length,
|
virtual void Copy(BClipboard* clipboard);
|
||||||
int32 offset, const text_run_array *runs);
|
virtual void Cut(BClipboard* clipboard);
|
||||||
|
virtual void Paste(BClipboard* clipboard);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
void HexReformat(int32 oldCursor, int32 &newCursor);
|
virtual void InsertText(const char* text, int32 length,
|
||||||
status_t GetHexFromData(const uint8 *in, size_t inSize, char **_hex, size_t *_hexSize);
|
int32 offset, const text_run_array* runs);
|
||||||
status_t GetDataFromHex(const char *text, size_t textLength, uint8 **_data, size_t *_dataSize);
|
|
||||||
|
|
||||||
BScrollView *fScrollView;
|
private:
|
||||||
find_mode fMode;
|
void _HexReformat(int32 oldCursor, int32& newCursor);
|
||||||
|
status_t _GetHexFromData(const uint8* in, size_t inSize,
|
||||||
|
char** _hex, size_t* _hexSize);
|
||||||
|
status_t _GetDataFromHex(const char* text, size_t textLength,
|
||||||
|
uint8** _data, size_t* _dataSize);
|
||||||
|
|
||||||
|
BScrollView* fScrollView;
|
||||||
|
find_mode fMode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
//---------------
|
FindTextView::FindTextView(BRect frame, const char* name, BRect textRect,
|
||||||
|
uint32 resizeMask)
|
||||||
|
|
||||||
FindTextView::FindTextView(BRect frame, const char *name, BRect textRect,
|
|
||||||
uint32 resizeMask)
|
|
||||||
: BTextView(frame, name, textRect, resizeMask),
|
: BTextView(frame, name, textRect, resizeMask),
|
||||||
fScrollView(NULL),
|
fScrollView(NULL),
|
||||||
fMode(kAsciiMode)
|
fMode(kAsciiMode)
|
||||||
@@ -77,8 +89,8 @@ FindTextView::MakeFocus(bool state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FindTextView::TargetedByScrollView(BScrollView *view)
|
FindTextView::TargetedByScrollView(BScrollView* view)
|
||||||
{
|
{
|
||||||
BTextView::TargetedByScrollView(view);
|
BTextView::TargetedByScrollView(view);
|
||||||
fScrollView = view;
|
fScrollView = view;
|
||||||
@@ -86,11 +98,11 @@ FindTextView::TargetedByScrollView(BScrollView *view)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FindTextView::HexReformat(int32 oldCursor, int32 &newCursor)
|
FindTextView::_HexReformat(int32 oldCursor, int32& newCursor)
|
||||||
{
|
{
|
||||||
const char *text = Text();
|
const char* text = Text();
|
||||||
int32 textLength = TextLength();
|
int32 textLength = TextLength();
|
||||||
char *insert = (char *)malloc(textLength * 2);
|
char* insert = (char*)malloc(textLength * 2);
|
||||||
if (insert == NULL)
|
if (insert == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -130,8 +142,8 @@ FindTextView::HexReformat(int32 oldCursor, int32 &newCursor)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FindTextView::InsertText(const char *text, int32 length, int32 offset,
|
FindTextView::InsertText(const char* text, int32 length, int32 offset,
|
||||||
const text_run_array *runs)
|
const text_run_array* runs)
|
||||||
{
|
{
|
||||||
if (fMode == kHexMode) {
|
if (fMode == kHexMode) {
|
||||||
if (offset > TextLength())
|
if (offset > TextLength())
|
||||||
@@ -145,7 +157,7 @@ FindTextView::InsertText(const char *text, int32 length, int32 offset,
|
|||||||
GetSelection(&start, &end);
|
GetSelection(&start, &end);
|
||||||
|
|
||||||
int32 cursor;
|
int32 cursor;
|
||||||
HexReformat(offset, cursor);
|
_HexReformat(offset, cursor);
|
||||||
|
|
||||||
if (length == 1 && start == offset)
|
if (length == 1 && start == offset)
|
||||||
Select(cursor + 1, cursor + 1);
|
Select(cursor + 1, cursor + 1);
|
||||||
@@ -154,8 +166,8 @@ FindTextView::InsertText(const char *text, int32 length, int32 offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FindTextView::KeyDown(const char *bytes, int32 numBytes)
|
FindTextView::KeyDown(const char* bytes, int32 numBytes)
|
||||||
{
|
{
|
||||||
if (fMode == kHexMode) {
|
if (fMode == kHexMode) {
|
||||||
// filter out invalid (for hex mode) characters
|
// filter out invalid (for hex mode) characters
|
||||||
@@ -193,7 +205,7 @@ FindTextView::KeyDown(const char *bytes, int32 numBytes)
|
|||||||
if (bytes[0] == B_BACKSPACE)
|
if (bytes[0] == B_BACKSPACE)
|
||||||
GetSelection(&start, &end);
|
GetSelection(&start, &end);
|
||||||
|
|
||||||
HexReformat(start, start);
|
_HexReformat(start, start);
|
||||||
Select(start, start);
|
Select(start, start);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -217,29 +229,144 @@ FindTextView::KeyDown(const char *bytes, int32 numBytes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
bool
|
||||||
FindTextView::GetHexFromData(const uint8 *in, size_t inSize, char **_hex, size_t *_hexSize)
|
FindTextView::AcceptsPaste(BClipboard* clipboard)
|
||||||
{
|
{
|
||||||
char *hex = (char *)malloc(inSize * 3 + 1);
|
if (clipboard == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
AutoLocker<BClipboard> _(clipboard);
|
||||||
|
|
||||||
|
BMessage* clip = clipboard->Data();
|
||||||
|
if (clip == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (clip->HasData(B_FILE_MIME_TYPE, B_MIME_TYPE)
|
||||||
|
|| clip->HasData("text/plain", B_MIME_TYPE))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return BTextView::AcceptsPaste(clipboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FindTextView::Copy(BClipboard* clipboard)
|
||||||
|
{
|
||||||
|
if (fMode != kHexMode) {
|
||||||
|
BTextView::Copy(clipboard);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 start, end;
|
||||||
|
GetSelection(&start, &end);
|
||||||
|
|
||||||
|
if (clipboard == NULL || start == end)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AutoLocker<BClipboard> _(clipboard);
|
||||||
|
|
||||||
|
BMessage* clip = clipboard->Data();
|
||||||
|
if (clip == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// convert hex-text to real data
|
||||||
|
uint8* data;
|
||||||
|
size_t dataSize;
|
||||||
|
if (_GetDataFromHex(Text() + start, end - start, &data, &dataSize)
|
||||||
|
!= B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
clip->AddData(B_FILE_MIME_TYPE, B_MIME_TYPE, data, dataSize);
|
||||||
|
|
||||||
|
if (is_valid_utf8(data, dataSize))
|
||||||
|
clip->AddData("text/plain", B_MIME_TYPE, data, dataSize);
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FindTextView::Cut(BClipboard* clipboard)
|
||||||
|
{
|
||||||
|
if (fMode != kHexMode) {
|
||||||
|
BTextView::Cut(clipboard);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32 start, end;
|
||||||
|
GetSelection(&start, &end);
|
||||||
|
if (clipboard == NULL || start == end)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AutoLocker<BClipboard> _(clipboard);
|
||||||
|
|
||||||
|
BMessage* clip = clipboard->Data();
|
||||||
|
if (clip == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Copy(clipboard);
|
||||||
|
Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
FindTextView::Paste(BClipboard* clipboard)
|
||||||
|
{
|
||||||
|
if (clipboard == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
AutoLocker<BClipboard> _(clipboard);
|
||||||
|
|
||||||
|
BMessage* clip = clipboard->Data();
|
||||||
|
if (clip == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const uint8* data;
|
||||||
|
ssize_t dataSize;
|
||||||
|
if (clip->FindData(B_FILE_MIME_TYPE, B_MIME_TYPE, (const void**)&data,
|
||||||
|
&dataSize) == B_OK) {
|
||||||
|
if (fMode == kHexMode) {
|
||||||
|
char* hex;
|
||||||
|
size_t hexSize;
|
||||||
|
if (_GetHexFromData(data, dataSize, &hex, &hexSize) < B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetText(hex, hexSize);
|
||||||
|
free(hex);
|
||||||
|
} else
|
||||||
|
SetText((char*)data, dataSize);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BTextView::Paste(clipboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
FindTextView::_GetHexFromData(const uint8* in, size_t inSize, char** _hex,
|
||||||
|
size_t* _hexSize)
|
||||||
|
{
|
||||||
|
char* hex = (char*)malloc(inSize * 3 + 1);
|
||||||
if (hex == NULL)
|
if (hex == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
char *out = hex;
|
char* out = hex;
|
||||||
for (uint32 i = 0; i < inSize; i++) {
|
for (uint32 i = 0; i < inSize; i++) {
|
||||||
out += sprintf(out, "%02x", *(unsigned char *)(in + i));
|
out += sprintf(out, "%02x", *(unsigned char*)(in + i));
|
||||||
}
|
}
|
||||||
out[0] = '\0';
|
out[0] = '\0';
|
||||||
|
|
||||||
*_hex = hex;
|
*_hex = hex;
|
||||||
*_hexSize = out + 1 - hex;
|
*_hexSize = out + 1 - hex;
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
FindTextView::GetDataFromHex(const char *text, size_t textLength, uint8 **_data, size_t *_dataSize)
|
FindTextView::_GetDataFromHex(const char* text, size_t textLength, uint8** _data,
|
||||||
|
size_t* _dataSize)
|
||||||
{
|
{
|
||||||
uint8 *data = (uint8 *)malloc(textLength);
|
uint8* data = (uint8*)malloc(textLength);
|
||||||
if (data == NULL)
|
if (data == NULL)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
@@ -283,9 +410,10 @@ FindTextView::SetMode(find_mode mode)
|
|||||||
if (mode == kHexMode) {
|
if (mode == kHexMode) {
|
||||||
// convert text to hex mode
|
// convert text to hex mode
|
||||||
|
|
||||||
char *hex;
|
char* hex;
|
||||||
size_t hexSize;
|
size_t hexSize;
|
||||||
if (GetHexFromData((const uint8 *)Text(), TextLength(), &hex, &hexSize) < B_OK)
|
if (_GetHexFromData((const uint8*)Text(), TextLength(), &hex, &hexSize)
|
||||||
|
< B_OK)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
fMode = mode;
|
fMode = mode;
|
||||||
@@ -294,56 +422,57 @@ FindTextView::SetMode(find_mode mode)
|
|||||||
free(hex);
|
free(hex);
|
||||||
} else {
|
} else {
|
||||||
// convert hex to ascii
|
// convert hex to ascii
|
||||||
|
|
||||||
uint8 *data;
|
uint8* data;
|
||||||
size_t dataSize;
|
size_t dataSize;
|
||||||
if (GetDataFromHex(Text(), TextLength(), &data, &dataSize) < B_OK)
|
if (_GetDataFromHex(Text(), TextLength(), &data, &dataSize) < B_OK)
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
fMode = mode;
|
fMode = mode;
|
||||||
|
|
||||||
SetText((const char *)data, dataSize);
|
SetText((const char*)data, dataSize);
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FindTextView::SetData(BMessage &message)
|
FindTextView::SetData(BMessage& message)
|
||||||
{
|
{
|
||||||
const uint8 *data;
|
const uint8* data;
|
||||||
ssize_t dataSize;
|
ssize_t dataSize;
|
||||||
if (message.FindData("data", B_RAW_TYPE, (const void **)&data, &dataSize) != B_OK)
|
if (message.FindData("data", B_RAW_TYPE,
|
||||||
|
(const void**)&data, &dataSize) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fMode == kHexMode) {
|
if (fMode == kHexMode) {
|
||||||
char *hex;
|
char* hex;
|
||||||
size_t hexSize;
|
size_t hexSize;
|
||||||
if (GetHexFromData(data, dataSize, &hex, &hexSize) < B_OK)
|
if (_GetHexFromData(data, dataSize, &hex, &hexSize) < B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SetText(hex, hexSize);
|
SetText(hex, hexSize);
|
||||||
free(hex);
|
free(hex);
|
||||||
} else
|
} else
|
||||||
SetText((char *)data, dataSize);
|
SetText((char*)data, dataSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FindTextView::GetData(BMessage &message)
|
FindTextView::GetData(BMessage& message)
|
||||||
{
|
{
|
||||||
if (fMode == kHexMode) {
|
if (fMode == kHexMode) {
|
||||||
// convert hex-text to real data
|
// convert hex-text to real data
|
||||||
uint8 *data;
|
uint8* data;
|
||||||
size_t dataSize;
|
size_t dataSize;
|
||||||
if (GetDataFromHex(Text(), TextLength(), &data, &dataSize) != B_OK)
|
if (_GetDataFromHex(Text(), TextLength(), &data, &dataSize) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
message.AddData("data", B_RAW_TYPE, data, dataSize);
|
message.AddData("data", B_RAW_TYPE, data, dataSize);
|
||||||
free(data);
|
free(data);
|
||||||
} else
|
} else
|
||||||
message.AddData("data", B_RAW_TYPE, Text(), TextLength());
|
message.AddData("data", B_RAW_TYPE, Text(), TextLength());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -351,12 +480,12 @@ FindTextView::GetData(BMessage &message)
|
|||||||
// #pragma mark -
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
FindWindow::FindWindow(BRect _rect, BMessage &previous, BMessenger &target,
|
FindWindow::FindWindow(BRect _rect, BMessage& previous, BMessenger& target,
|
||||||
const BMessage *settings)
|
const BMessage* settings)
|
||||||
: BWindow(_rect, "Find", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS),
|
: BWindow(_rect, "Find", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS),
|
||||||
fTarget(target)
|
fTarget(target)
|
||||||
{
|
{
|
||||||
BView *view = new BView(Bounds(), "main", B_FOLLOW_ALL, 0);
|
BView* view = new BView(Bounds(), "main", B_FOLLOW_ALL, 0);
|
||||||
view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||||
AddChild(view);
|
AddChild(view);
|
||||||
|
|
||||||
@@ -367,41 +496,44 @@ FindWindow::FindWindow(BRect _rect, BMessage &previous, BMessenger &target,
|
|||||||
// add the top widgets
|
// add the top widgets
|
||||||
|
|
||||||
fMenu = new BPopUpMenu("mode");
|
fMenu = new BPopUpMenu("mode");
|
||||||
BMessage *message;
|
BMessage* message;
|
||||||
BMenuItem *item;
|
BMenuItem* item;
|
||||||
fMenu->AddItem(item = new BMenuItem("Text", message = new BMessage(kMsgFindMode)));
|
fMenu->AddItem(item = new BMenuItem("Text",
|
||||||
|
message = new BMessage(kMsgFindMode)));
|
||||||
message->AddInt8("mode", kAsciiMode);
|
message->AddInt8("mode", kAsciiMode);
|
||||||
if (mode == kAsciiMode)
|
if (mode == kAsciiMode)
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
fMenu->AddItem(item = new BMenuItem("Hexadecimal", message = new BMessage(kMsgFindMode)));
|
fMenu->AddItem(item = new BMenuItem("Hexadecimal",
|
||||||
|
message = new BMessage(kMsgFindMode)));
|
||||||
message->AddInt8("mode", kHexMode);
|
message->AddInt8("mode", kHexMode);
|
||||||
if (mode == kHexMode)
|
if (mode == kHexMode)
|
||||||
item->SetMarked(true);
|
item->SetMarked(true);
|
||||||
|
|
||||||
BRect rect = Bounds().InsetByCopy(5, 5);
|
BRect rect = Bounds().InsetByCopy(5, 5);
|
||||||
BMenuField *menuField = new BMenuField(rect, B_EMPTY_STRING,
|
BMenuField* menuField = new BMenuField(rect, B_EMPTY_STRING,
|
||||||
"Mode:", fMenu, B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
"Mode:", fMenu, B_FOLLOW_LEFT | B_FOLLOW_TOP);
|
||||||
menuField->SetDivider(menuField->StringWidth(menuField->Label()) + 8);
|
menuField->SetDivider(menuField->StringWidth(menuField->Label()) + 8);
|
||||||
menuField->ResizeToPreferred();
|
menuField->ResizeToPreferred();
|
||||||
view->AddChild(menuField);
|
view->AddChild(menuField);
|
||||||
|
|
||||||
// add the bottom widgets
|
// add the bottom widgets
|
||||||
|
|
||||||
BButton *button = new BButton(rect, B_EMPTY_STRING, "Find", new BMessage(kMsgStartFind),
|
BButton* button = new BButton(rect, B_EMPTY_STRING, "Find",
|
||||||
B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
new BMessage(kMsgStartFind), B_FOLLOW_RIGHT | B_FOLLOW_BOTTOM);
|
||||||
button->MakeDefault(true);
|
button->MakeDefault(true);
|
||||||
button->ResizeToPreferred();
|
button->ResizeToPreferred();
|
||||||
button->MoveTo(rect.right - button->Bounds().Width(),
|
button->MoveTo(rect.right - button->Bounds().Width(),
|
||||||
rect.bottom - button->Bounds().Height());
|
rect.bottom - button->Bounds().Height());
|
||||||
view->AddChild(button);
|
view->AddChild(button);
|
||||||
|
|
||||||
fCaseCheckBox = new BCheckBox(rect, B_EMPTY_STRING, "Case sensitive",
|
fCaseCheckBox = new BCheckBox(rect, B_EMPTY_STRING, "Case sensitive",
|
||||||
NULL, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
|
NULL, B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
|
||||||
fCaseCheckBox->ResizeToPreferred();
|
fCaseCheckBox->ResizeToPreferred();
|
||||||
fCaseCheckBox->MoveTo(5, button->Frame().top);
|
fCaseCheckBox->MoveTo(5, button->Frame().top);
|
||||||
bool caseSensitive;
|
bool caseSensitive;
|
||||||
if (previous.FindBool("case_sensitive", &caseSensitive) != B_OK) {
|
if (previous.FindBool("case_sensitive", &caseSensitive) != B_OK) {
|
||||||
if (settings == NULL || settings->FindBool("case_sensitive", &caseSensitive) != B_OK)
|
if (settings == NULL
|
||||||
|
|| settings->FindBool("case_sensitive", &caseSensitive) != B_OK)
|
||||||
caseSensitive = true;
|
caseSensitive = true;
|
||||||
}
|
}
|
||||||
fCaseCheckBox->SetValue(caseSensitive);
|
fCaseCheckBox->SetValue(caseSensitive);
|
||||||
@@ -413,19 +545,19 @@ FindWindow::FindWindow(BRect _rect, BMessage &previous, BMessenger &target,
|
|||||||
rect.bottom = fCaseCheckBox->Frame().top - 8;
|
rect.bottom = fCaseCheckBox->Frame().top - 8;
|
||||||
rect.InsetBy(2, 2);
|
rect.InsetBy(2, 2);
|
||||||
fTextView = new FindTextView(rect, B_EMPTY_STRING,
|
fTextView = new FindTextView(rect, B_EMPTY_STRING,
|
||||||
rect.OffsetToCopy(B_ORIGIN).InsetByCopy(3, 3),
|
rect.OffsetToCopy(B_ORIGIN).InsetByCopy(3, 3), B_FOLLOW_ALL);
|
||||||
B_FOLLOW_ALL);
|
|
||||||
fTextView->SetWordWrap(true);
|
fTextView->SetWordWrap(true);
|
||||||
fTextView->SetMode((find_mode)mode);
|
fTextView->SetMode((find_mode)mode);
|
||||||
fTextView->SetData(previous);
|
fTextView->SetData(previous);
|
||||||
|
|
||||||
BScrollView *scrollView = new BScrollView("scroller", fTextView, B_FOLLOW_ALL, B_WILL_DRAW, false, false);
|
BScrollView* scrollView = new BScrollView("scroller", fTextView,
|
||||||
|
B_FOLLOW_ALL, B_WILL_DRAW, false, false);
|
||||||
view->AddChild(scrollView);
|
view->AddChild(scrollView);
|
||||||
|
|
||||||
ResizeTo(290, button->Frame().Height() * 3 + 30);
|
ResizeTo(290, button->Frame().Height() * 3 + 30);
|
||||||
|
|
||||||
SetSizeLimits(fCaseCheckBox->Bounds().Width() + button->Bounds().Width() + 20,
|
SetSizeLimits(fCaseCheckBox->Bounds().Width() + button->Bounds().Width()
|
||||||
32768, button->Frame().Height() * 3 + 10, 32768);
|
+ 20, 32768, button->Frame().Height() * 3 + 10, 32768);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -434,15 +566,15 @@ FindWindow::~FindWindow()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FindWindow::WindowActivated(bool active)
|
FindWindow::WindowActivated(bool active)
|
||||||
{
|
{
|
||||||
fTextView->MakeFocus(active);
|
fTextView->MakeFocus(active);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FindWindow::MessageReceived(BMessage *message)
|
FindWindow::MessageReceived(BMessage* message)
|
||||||
{
|
{
|
||||||
switch (message->what) {
|
switch (message->what) {
|
||||||
case kMsgFindMode:
|
case kMsgFindMode:
|
||||||
@@ -471,14 +603,14 @@ FindWindow::MessageReceived(BMessage *message)
|
|||||||
PostMessage(B_QUIT_REQUESTED);
|
PostMessage(B_QUIT_REQUESTED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
BWindow::MessageReceived(message);
|
BWindow::MessageReceived(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
FindWindow::QuitRequested()
|
FindWindow::QuitRequested()
|
||||||
{
|
{
|
||||||
// update the application's settings
|
// update the application's settings
|
||||||
@@ -492,8 +624,8 @@ FindWindow::QuitRequested()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
FindWindow::SetTarget(BMessenger &target)
|
FindWindow::SetTarget(BMessenger& target)
|
||||||
{
|
{
|
||||||
fTarget = target;
|
fTarget = target;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user