Removed an ugly hack - using a BTextView for a BTextControl
Fixed font sensitivity Removed the now-unsused DialogTextView class Escape key now closes the window (for free, from AutoTextControl class) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19681 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -39,6 +39,7 @@ All rights reserved.
|
|||||||
|
|
||||||
#include "FindWindow.h"
|
#include "FindWindow.h"
|
||||||
#include "Mail.h"
|
#include "Mail.h"
|
||||||
|
#include "AutoTextControl.h"
|
||||||
|
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
#include <Button.h>
|
#include <Button.h>
|
||||||
@@ -48,6 +49,10 @@ All rights reserved.
|
|||||||
|
|
||||||
#include <MDRLanguage.h>
|
#include <MDRLanguage.h>
|
||||||
|
|
||||||
|
enum {
|
||||||
|
M_FIND_STRING_CHANGED = 'fsch'
|
||||||
|
};
|
||||||
|
|
||||||
void TextBevel(BView& view, BRect r);
|
void TextBevel(BView& view, BRect r);
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -116,22 +121,20 @@ FindPanel::FindPanel(BRect rect)
|
|||||||
: BBox(rect, "FindPanel", B_FOLLOW_LEFT_RIGHT,
|
: BBox(rect, "FindPanel", B_FOLLOW_LEFT_RIGHT,
|
||||||
B_WILL_DRAW)
|
B_WILL_DRAW)
|
||||||
{
|
{
|
||||||
BRect r = Bounds();
|
BRect r = Bounds().InsetByCopy(10,10);
|
||||||
r.InsetBy(8,8);
|
|
||||||
r.bottom -= 44;
|
|
||||||
BRect text = r;
|
|
||||||
text.OffsetTo(B_ORIGIN);
|
|
||||||
text.InsetBy(2,2);
|
|
||||||
|
|
||||||
mBTextView = new DialogTextView(r,"BTextView",text,B_FOLLOW_ALL,B_WILL_DRAW);
|
mBTextControl = new AutoTextControl(r,"BTextControl",NULL,sPreviousFind.String(),
|
||||||
mBTextView->DisallowChar('\n');
|
new BMessage(M_FIND_STRING_CHANGED),
|
||||||
mBTextView->SetText(sPreviousFind.String());
|
B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
|
||||||
mBTextView->MakeFocus();
|
mBTextControl->SetText(sPreviousFind.String());
|
||||||
AddChild(mBTextView);
|
mBTextControl->MakeFocus();
|
||||||
|
mBTextControl->SetEscapeCancel(true);
|
||||||
|
AddChild(mBTextControl);
|
||||||
|
|
||||||
mFindButton = new BButton(BRect(0,0,90,20),"FINDBUTTON",
|
mFindButton = new BButton(BRect(0,0,90,20),"FINDBUTTON",
|
||||||
MDR_DIALECT_CHOICE ("Find","検索"),
|
MDR_DIALECT_CHOICE ("Find","検索"),
|
||||||
new BMessage(FINDBUTTON),B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
|
new BMessage(FINDBUTTON),B_FOLLOW_LEFT | B_FOLLOW_BOTTOM);
|
||||||
|
mFindButton->ResizeToPreferred();
|
||||||
AddChild(mFindButton);
|
AddChild(mFindButton);
|
||||||
r = mFindButton->Bounds();
|
r = mFindButton->Bounds();
|
||||||
|
|
||||||
@@ -142,7 +145,7 @@ FindPanel::FindPanel(BRect rect)
|
|||||||
|
|
||||||
FindPanel::~FindPanel()
|
FindPanel::~FindPanel()
|
||||||
{
|
{
|
||||||
sPreviousFind = mBTextView->Text();
|
sPreviousFind = mBTextControl->Text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FindPanel::AttachedToWindow()
|
void FindPanel::AttachedToWindow()
|
||||||
@@ -151,8 +154,13 @@ void FindPanel::AttachedToWindow()
|
|||||||
SetViewColor(216,216,216);
|
SetViewColor(216,216,216);
|
||||||
Window()->SetDefaultButton(mFindButton);
|
Window()->SetDefaultButton(mFindButton);
|
||||||
mFindButton->SetTarget(this);
|
mFindButton->SetTarget(this);
|
||||||
mBTextView->MakeFocus(true);
|
|
||||||
mBTextView->SelectAll();
|
mBTextControl->SetTarget(this);
|
||||||
|
mBTextControl->ResizeToPreferred();
|
||||||
|
mBTextControl->ResizeTo(Bounds().Width() - 20, mBTextControl->Frame().Height());
|
||||||
|
|
||||||
|
mBTextControl->MakeFocus(true);
|
||||||
|
mBTextControl->TextView()->SelectAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FindPanel::MouseDown(BPoint point)
|
void FindPanel::MouseDown(BPoint point)
|
||||||
@@ -163,12 +171,12 @@ void FindPanel::MouseDown(BPoint point)
|
|||||||
|
|
||||||
void FindPanel::Draw(BRect)
|
void FindPanel::Draw(BRect)
|
||||||
{
|
{
|
||||||
TextBevel(*this,mBTextView->Frame());
|
// TextBevel(*this,mBTextView->Frame());
|
||||||
}
|
}
|
||||||
|
|
||||||
void FindPanel::KeyDown(const char *, int32)
|
void FindPanel::KeyDown(const char *, int32)
|
||||||
{
|
{
|
||||||
int32 length = mBTextView->TextLength();
|
int32 length = mBTextControl->TextView()->TextLength();
|
||||||
bool enabled = mFindButton->IsEnabled();
|
bool enabled = mFindButton->IsEnabled();
|
||||||
|
|
||||||
if (length > 0 && !enabled)
|
if (length > 0 && !enabled)
|
||||||
@@ -180,10 +188,18 @@ void FindPanel::KeyDown(const char *, int32)
|
|||||||
void FindPanel::MessageReceived(BMessage *msg)
|
void FindPanel::MessageReceived(BMessage *msg)
|
||||||
{
|
{
|
||||||
switch (msg->what) {
|
switch (msg->what) {
|
||||||
case FINDBUTTON:
|
case M_FIND_STRING_CHANGED: {
|
||||||
|
if (strlen(mBTextControl->Text()) == 0)
|
||||||
|
mFindButton->SetEnabled(false);
|
||||||
|
else
|
||||||
|
mFindButton->SetEnabled(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case FINDBUTTON: {
|
||||||
Find();
|
Find();
|
||||||
Window()->PostMessage(B_QUIT_REQUESTED);
|
Window()->PostMessage(B_QUIT_REQUESTED);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
BView::MessageReceived(msg);
|
BView::MessageReceived(msg);
|
||||||
}
|
}
|
||||||
@@ -191,8 +207,8 @@ void FindPanel::MessageReceived(BMessage *msg)
|
|||||||
|
|
||||||
void FindPanel::Find()
|
void FindPanel::Find()
|
||||||
{
|
{
|
||||||
mBTextView->SelectAll();
|
mBTextControl->TextView()->SelectAll();
|
||||||
const char *text = mBTextView->Text();
|
const char *text = mBTextControl->Text();
|
||||||
if (text == NULL || text[0] == 0) return;
|
if (text == NULL || text[0] == 0) return;
|
||||||
|
|
||||||
BWindow *window = NULL;
|
BWindow *window = NULL;
|
||||||
@@ -259,38 +275,3 @@ const char *FindWindow::GetFindString()
|
|||||||
{
|
{
|
||||||
return sPreviousFind.String();
|
return sPreviousFind.String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DialogTextView::DialogTextView(BRect frame, const char *name, BRect textRect,
|
|
||||||
uint32 resizingMode, uint32 flags)
|
|
||||||
: BTextView(frame, name, textRect, resizingMode, flags)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void DialogTextView::KeyDown(const char *bytes, int32 numBytes)
|
|
||||||
{
|
|
||||||
BTextView::KeyDown(bytes, numBytes);
|
|
||||||
if (Parent())
|
|
||||||
Parent()->KeyDown(bytes, numBytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DialogTextView::MouseDown(BPoint point)
|
|
||||||
{
|
|
||||||
Window()->Activate();
|
|
||||||
BTextView::MouseDown(point);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DialogTextView::InsertText(const char *inText, int32 inLength, int32 inOffset,
|
|
||||||
const text_run_array *inRuns)
|
|
||||||
{
|
|
||||||
BTextView::InsertText(inText, inLength, inOffset, inRuns);
|
|
||||||
if (Parent())
|
|
||||||
Parent()->KeyDown(NULL, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DialogTextView::DeleteText(int32 fromOffset, int32 toOffset)
|
|
||||||
{
|
|
||||||
BTextView::DeleteText(fromOffset, toOffset);
|
|
||||||
if (Parent())
|
|
||||||
Parent()->KeyDown(NULL, 0);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ All rights reserved.
|
|||||||
|
|
||||||
#include <AppDefs.h>
|
#include <AppDefs.h>
|
||||||
#include <Box.h>
|
#include <Box.h>
|
||||||
#include <TextView.h>
|
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
class FindPanel;
|
class FindPanel;
|
||||||
|
class AutoTextControl;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// Floating find window, just one of them.....
|
// Floating find window, just one of them.....
|
||||||
@@ -85,21 +85,10 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
BButton* mFindButton;
|
BButton* mFindButton;
|
||||||
BTextView* mBTextView;
|
AutoTextControl* mBTextControl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class DialogTextView : public BTextView {
|
|
||||||
public:
|
|
||||||
DialogTextView(BRect frame, const char *name, BRect textRect,
|
|
||||||
uint32 resizingMode, uint32 flags);
|
|
||||||
virtual void KeyDown(const char *bytes, int32 numBytes);
|
|
||||||
virtual void MouseDown(BPoint point);
|
|
||||||
virtual void InsertText(const char *inText, int32 inLength,
|
|
||||||
int32 inOffset, const text_run_array *inRuns);
|
|
||||||
virtual void DeleteText(int32 fromOffset, int32 toOffset);
|
|
||||||
};
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
#endif // #ifndef _FINDWINDOW_H
|
#endif // #ifndef _FINDWINDOW_H
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ UsePrivateHeaders shared ;
|
|||||||
|
|
||||||
AddResources BeMail : BeMail.rdef pictures.rdef ;
|
AddResources BeMail : BeMail.rdef pictures.rdef ;
|
||||||
Application BeMail :
|
Application BeMail :
|
||||||
|
AutoTextControl.cpp
|
||||||
BmapButton.cpp
|
BmapButton.cpp
|
||||||
ButtonBar.cpp
|
ButtonBar.cpp
|
||||||
ComboBox.cpp
|
ComboBox.cpp
|
||||||
|
|||||||
Reference in New Issue
Block a user