Style fixes. I'm pretty sure I got everything, too. :^)
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19691 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
AutoTextControlFilter::AutoTextControlFilter(AutoTextControl *box)
|
AutoTextControlFilter::AutoTextControlFilter(AutoTextControl *box)
|
||||||
: BMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE,B_KEY_DOWN),
|
: BMessageFilter(B_PROGRAMMED_DELIVERY, B_ANY_SOURCE,B_KEY_DOWN),
|
||||||
fBox(box),
|
fBox(box),
|
||||||
fMessenger(NULL),
|
fMessenger(NULL),
|
||||||
fCurrentMessage(NULL)
|
fCurrentMessage(NULL)
|
||||||
@@ -23,8 +23,9 @@ AutoTextControlFilter::~AutoTextControlFilter(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
filter_result AutoTextControlFilter::Filter(BMessage *msg, BHandler **target)
|
filter_result
|
||||||
{
|
AutoTextControlFilter::Filter(BMessage *msg, BHandler **target) {
|
||||||
|
|
||||||
// This is really slick -- all that is needed to allow Escape key cancelling is
|
// This is really slick -- all that is needed to allow Escape key cancelling is
|
||||||
// just calling SetEscapeCancel(true) for just *one* AutoTextControl in a window. *heh*
|
// just calling SetEscapeCancel(true) for just *one* AutoTextControl in a window. *heh*
|
||||||
int32 rawchar,mod;
|
int32 rawchar,mod;
|
||||||
@@ -32,16 +33,14 @@ filter_result AutoTextControlFilter::Filter(BMessage *msg, BHandler **target)
|
|||||||
msg->FindInt32("modifiers",&mod);
|
msg->FindInt32("modifiers",&mod);
|
||||||
|
|
||||||
|
|
||||||
if(rawchar == B_ESCAPE)
|
if (rawchar == B_ESCAPE) {
|
||||||
{
|
if (mod & B_COMMAND_KEY)
|
||||||
if(mod & B_COMMAND_KEY)
|
|
||||||
return B_DISPATCH_MESSAGE;
|
return B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
if(IsEscapeCancel())
|
if (IsEscapeCancel()) {
|
||||||
{
|
|
||||||
BLooper *loop = (*target)->Looper();
|
BLooper *loop = (*target)->Looper();
|
||||||
if(loop)
|
|
||||||
{
|
if (loop) {
|
||||||
BMessenger msgr(loop);
|
BMessenger msgr(loop);
|
||||||
msgr.SendMessage(B_QUIT_REQUESTED);
|
msgr.SendMessage(B_QUIT_REQUESTED);
|
||||||
return B_SKIP_MESSAGE;
|
return B_SKIP_MESSAGE;
|
||||||
@@ -49,12 +48,12 @@ filter_result AutoTextControlFilter::Filter(BMessage *msg, BHandler **target)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BView *v=dynamic_cast<BView*>(*target);
|
BView *v = dynamic_cast<BView*>(*target);
|
||||||
if(!v || strcmp("_input_",v->Name())!=0)
|
if (!v || strcmp("_input_",v->Name()) != 0)
|
||||||
return B_DISPATCH_MESSAGE;
|
return B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
AutoTextControl *text = dynamic_cast<AutoTextControl*>(v->Parent());
|
AutoTextControl *text = dynamic_cast<AutoTextControl*>(v->Parent());
|
||||||
if(!text || text!=fBox)
|
if (!text || text != fBox)
|
||||||
return B_DISPATCH_MESSAGE;
|
return B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
// handle instances where numlock is off and the user tries to punch in numbers.
|
// handle instances where numlock is off and the user tries to punch in numbers.
|
||||||
@@ -64,7 +63,7 @@ filter_result AutoTextControlFilter::Filter(BMessage *msg, BHandler **target)
|
|||||||
#ifndef HAIKU_TARGET_PLATFORM_R5
|
#ifndef HAIKU_TARGET_PLATFORM_R5
|
||||||
|
|
||||||
int32 scancode;
|
int32 scancode;
|
||||||
if(msg->FindInt32("key",&scancode)!=B_OK)
|
if (msg->FindInt32("key",&scancode) != B_OK)
|
||||||
scancode = -1;
|
scancode = -1;
|
||||||
|
|
||||||
HandleNoNumLock(scancode,rawchar,msg);
|
HandleNoNumLock(scancode,rawchar,msg);
|
||||||
@@ -75,101 +74,93 @@ filter_result AutoTextControlFilter::Filter(BMessage *msg, BHandler **target)
|
|||||||
filter_result result = KeyFilter(rawchar,mod);
|
filter_result result = KeyFilter(rawchar,mod);
|
||||||
fCurrentMessage = NULL;
|
fCurrentMessage = NULL;
|
||||||
|
|
||||||
if(fBox->fCharLimit && result == B_DISPATCH_MESSAGE)
|
if (fBox->fCharLimit && result == B_DISPATCH_MESSAGE) {
|
||||||
{
|
|
||||||
// See to it that we still allow shortcut keys
|
// See to it that we still allow shortcut keys
|
||||||
if(mod & B_COMMAND_KEY)
|
if (mod & B_COMMAND_KEY)
|
||||||
return B_DISPATCH_MESSAGE;
|
return B_DISPATCH_MESSAGE;
|
||||||
|
|
||||||
// We don't use strlen() because it is not UTF-8 aware, which can affect
|
// We don't use strlen() because it is not UTF-8 aware, which can affect
|
||||||
// how many characters can be typed.
|
// how many characters can be typed.
|
||||||
if(isprint(rawchar) && (uint32)BString(text->Text()).CountChars()==text->fCharLimit)
|
if (isprint(rawchar) && (uint32)BString(text->Text()).CountChars() == text->fCharLimit)
|
||||||
return B_SKIP_MESSAGE;
|
return B_SKIP_MESSAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
filter_result AutoTextControlFilter::KeyFilter(const int32 &rawchar, const int32 &mod)
|
filter_result
|
||||||
|
AutoTextControlFilter::KeyFilter(const int32 &rawchar, const int32 &mod)
|
||||||
{
|
{
|
||||||
if(fMessenger)
|
if (fMessenger)
|
||||||
fMessenger->SendMessage(fBox->ModificationMessage());
|
fMessenger->SendMessage(fBox->ModificationMessage());
|
||||||
else
|
else if (fBox)
|
||||||
if(fBox)
|
|
||||||
fBox->Invoke();
|
fBox->Invoke();
|
||||||
return B_DISPATCH_MESSAGE;
|
return B_DISPATCH_MESSAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTextControlFilter::SetMessenger(BMessenger *msgr)
|
void
|
||||||
|
AutoTextControlFilter::SetMessenger(BMessenger *msgr)
|
||||||
{
|
{
|
||||||
if(fMessenger)
|
if (fMessenger)
|
||||||
delete fMessenger;
|
delete fMessenger;
|
||||||
fMessenger = msgr;
|
fMessenger = msgr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTextControlFilter::SendMessage(BMessage *msg)
|
void
|
||||||
|
AutoTextControlFilter::SendMessage(BMessage *msg)
|
||||||
{
|
{
|
||||||
if(!msg)
|
if (!msg)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(fMessenger)
|
if (fMessenger)
|
||||||
fMessenger->SendMessage(msg);
|
fMessenger->SendMessage(msg);
|
||||||
else
|
else
|
||||||
delete msg;
|
delete msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTextControlFilter::HandleNoNumLock(const int32 &code, int32 &rawchar,
|
void
|
||||||
BMessage *msg)
|
AutoTextControlFilter::HandleNoNumLock(const int32 &code, int32 &rawchar, BMessage *msg)
|
||||||
{
|
{
|
||||||
switch(code)
|
switch(code) {
|
||||||
{
|
case 101: {
|
||||||
case 101: // Numlock .
|
// Numlock .
|
||||||
{
|
|
||||||
rawchar = '.';
|
rawchar = '.';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 100: // Numlock 0
|
case 100: {
|
||||||
{
|
// Numlock 0
|
||||||
rawchar = '0';
|
rawchar = '0';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 88:
|
case 88: {
|
||||||
{
|
|
||||||
rawchar = '1';
|
rawchar = '1';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 89:
|
case 89: {
|
||||||
{
|
|
||||||
rawchar = '2';
|
rawchar = '2';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 90:
|
case 90: {
|
||||||
{
|
|
||||||
rawchar = '3';
|
rawchar = '3';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 72:
|
case 72: {
|
||||||
{
|
|
||||||
rawchar = '4';
|
rawchar = '4';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 74:
|
case 74: {
|
||||||
{
|
|
||||||
rawchar = '6';
|
rawchar = '6';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 55:
|
case 55: {
|
||||||
{
|
|
||||||
rawchar = '7';
|
rawchar = '7';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 56:
|
case 56: {
|
||||||
{
|
|
||||||
rawchar = '8';
|
rawchar = '8';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 57:
|
case 57: {
|
||||||
{
|
|
||||||
rawchar = '9';
|
rawchar = '9';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -185,12 +176,13 @@ void AutoTextControlFilter::HandleNoNumLock(const int32 &code, int32 &rawchar,
|
|||||||
msg->ReplaceInt8("byte",(int8)rawchar);
|
msg->ReplaceInt8("byte",(int8)rawchar);
|
||||||
|
|
||||||
int32 mod;
|
int32 mod;
|
||||||
if(msg->FindInt32("modifiers",&mod)==B_OK)
|
if (msg->FindInt32("modifiers",&mod)==B_OK) {
|
||||||
{
|
|
||||||
uint32 mask = B_NUM_LOCK;
|
uint32 mask = B_NUM_LOCK;
|
||||||
if(mod & B_CAPS_LOCK)
|
|
||||||
|
if (mod & B_CAPS_LOCK)
|
||||||
mask |= B_CAPS_LOCK;
|
mask |= B_CAPS_LOCK;
|
||||||
if(mod & B_SCROLL_LOCK)
|
|
||||||
|
if (mod & B_SCROLL_LOCK)
|
||||||
mask |= B_SCROLL_LOCK;
|
mask |= B_SCROLL_LOCK;
|
||||||
|
|
||||||
set_keyboard_locks(mask);
|
set_keyboard_locks(mask);
|
||||||
@@ -199,8 +191,9 @@ void AutoTextControlFilter::HandleNoNumLock(const int32 &code, int32 &rawchar,
|
|||||||
|
|
||||||
|
|
||||||
AutoTextControl::AutoTextControl(const BRect &frame, const char *name, const char *label,
|
AutoTextControl::AutoTextControl(const BRect &frame, const char *name, const char *label,
|
||||||
const char *text, BMessage *msg, uint32 resize, uint32 flags)
|
const char *text, BMessage *msg, uint32 resize,
|
||||||
: BTextControl(frame,name,label,text,msg,resize,flags),
|
uint32 flags)
|
||||||
|
: BTextControl(frame,name,label,text,msg,resize,flags),
|
||||||
fFilter(NULL),
|
fFilter(NULL),
|
||||||
fEscapeCancel(false),
|
fEscapeCancel(false),
|
||||||
fCharLimit(0)
|
fCharLimit(0)
|
||||||
@@ -210,45 +203,49 @@ AutoTextControl::AutoTextControl(const BRect &frame, const char *name, const cha
|
|||||||
|
|
||||||
AutoTextControl::~AutoTextControl(void)
|
AutoTextControl::~AutoTextControl(void)
|
||||||
{
|
{
|
||||||
if(Window())
|
if (Window())
|
||||||
Window()->RemoveCommonFilter(fFilter);
|
Window()->RemoveCommonFilter(fFilter);
|
||||||
|
|
||||||
delete fFilter;
|
delete fFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTextControl::AttachedToWindow(void)
|
void
|
||||||
|
AutoTextControl::AttachedToWindow(void)
|
||||||
{
|
{
|
||||||
BTextControl::AttachedToWindow();
|
BTextControl::AttachedToWindow();
|
||||||
if(fFilter)
|
if (fFilter)
|
||||||
Window()->AddCommonFilter(fFilter);
|
Window()->AddCommonFilter(fFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTextControl::DetachedFromWindow(void)
|
void
|
||||||
|
AutoTextControl::DetachedFromWindow(void)
|
||||||
{
|
{
|
||||||
if(fFilter)
|
if (fFilter)
|
||||||
Window()->RemoveCommonFilter(fFilter);
|
Window()->RemoveCommonFilter(fFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTextControl::SetCharacterLimit(const uint32 &limit)
|
void
|
||||||
|
AutoTextControl::SetCharacterLimit(const uint32 &limit)
|
||||||
{
|
{
|
||||||
fCharLimit = limit;
|
fCharLimit = limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 AutoTextControl::GetCharacterLimit(const uint32 &limit)
|
uint32
|
||||||
|
AutoTextControl::GetCharacterLimit(const uint32 &limit)
|
||||||
{
|
{
|
||||||
return fCharLimit;
|
return fCharLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AutoTextControl::SetFilter(AutoTextControlFilter *filter)
|
void
|
||||||
|
AutoTextControl::SetFilter(AutoTextControlFilter *filter)
|
||||||
{
|
{
|
||||||
if(fFilter)
|
if (fFilter) {
|
||||||
{
|
if (Window())
|
||||||
if(Window())
|
|
||||||
Window()->RemoveCommonFilter(fFilter);
|
Window()->RemoveCommonFilter(fFilter);
|
||||||
delete fFilter;
|
delete fFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
fFilter = filter;
|
fFilter = filter;
|
||||||
if(Window())
|
if (Window())
|
||||||
Window()->AddCommonFilter(fFilter);
|
Window()->AddCommonFilter(fFilter);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,7 @@
|
|||||||
|
|
||||||
class AutoTextControlFilter;
|
class AutoTextControlFilter;
|
||||||
|
|
||||||
enum
|
enum {
|
||||||
{
|
|
||||||
M_PREVIOUS_FIELD='mprf',
|
M_PREVIOUS_FIELD='mprf',
|
||||||
M_NEXT_FIELD='mnxf',
|
M_NEXT_FIELD='mnxf',
|
||||||
M_ENTER_NAVIGATION='ennv'
|
M_ENTER_NAVIGATION='ennv'
|
||||||
@@ -24,52 +23,55 @@ enum
|
|||||||
class AutoTextControl : public BTextControl
|
class AutoTextControl : public BTextControl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AutoTextControl(const BRect &frame, const char *name, const char *label,
|
AutoTextControl(const BRect &frame, const char *name,
|
||||||
const char *text, BMessage *msg,
|
const char *label, const char *text,
|
||||||
uint32 resize = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
BMessage *msg,
|
||||||
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
uint32 resize = B_FOLLOW_LEFT | B_FOLLOW_TOP,
|
||||||
virtual ~AutoTextControl(void);
|
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
|
||||||
virtual void AttachedToWindow(void);
|
virtual ~AutoTextControl(void);
|
||||||
virtual void DetachedFromWindow(void);
|
virtual void AttachedToWindow(void);
|
||||||
void SetFilter(AutoTextControlFilter *filter);
|
virtual void DetachedFromWindow(void);
|
||||||
AutoTextControlFilter *GetFilter(void) { return fFilter; }
|
void SetFilter(AutoTextControlFilter *filter);
|
||||||
|
AutoTextControlFilter * GetFilter(void) { return fFilter; }
|
||||||
|
|
||||||
void SetCharacterLimit(const uint32 &limit);
|
void SetCharacterLimit(const uint32 &limit);
|
||||||
uint32 GetCharacterLimit(const uint32 &limit);
|
uint32 GetCharacterLimit(const uint32 &limit);
|
||||||
|
|
||||||
void SetEscapeCancel(const bool &value) { fEscapeCancel = value; }
|
void SetEscapeCancel(const bool &value) { fEscapeCancel = value; }
|
||||||
bool IsEscapeCancel(void) const { return fEscapeCancel; }
|
bool IsEscapeCancel(void) const { return fEscapeCancel; }
|
||||||
private:
|
private:
|
||||||
friend AutoTextControlFilter;
|
friend AutoTextControlFilter;
|
||||||
AutoTextControlFilter *fFilter;
|
|
||||||
bool fEscapeCancel;
|
AutoTextControlFilter *fFilter;
|
||||||
uint32 fCharLimit;
|
bool fEscapeCancel;
|
||||||
|
uint32 fCharLimit;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AutoTextControlFilter : public BMessageFilter
|
class AutoTextControlFilter : public BMessageFilter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AutoTextControlFilter(AutoTextControl *checkview);
|
AutoTextControlFilter(AutoTextControl *checkview);
|
||||||
~AutoTextControlFilter(void);
|
~AutoTextControlFilter(void);
|
||||||
virtual filter_result Filter(BMessage *msg, BHandler **target);
|
virtual filter_result Filter(BMessage *msg, BHandler **target);
|
||||||
virtual filter_result KeyFilter(const int32 &key, const int32 &mod);
|
virtual filter_result KeyFilter(const int32 &key, const int32 &mod);
|
||||||
|
|
||||||
AutoTextControl *TextControl(void) const { return fBox; }
|
AutoTextControl * TextControl(void) const { return fBox; }
|
||||||
|
|
||||||
void SetMessenger(BMessenger *msgr);
|
void SetMessenger(BMessenger *msgr);
|
||||||
BMessenger *GetMessenger(void) const { return fMessenger; }
|
BMessenger * GetMessenger(void) const { return fMessenger; }
|
||||||
void SendMessage(BMessage *msg);
|
void SendMessage(BMessage *msg);
|
||||||
BMessage *GetCurrentMessage(void) { return fCurrentMessage; }
|
BMessage * GetCurrentMessage(void) { return fCurrentMessage; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool IsEscapeCancel(void) const { return fBox->IsEscapeCancel(); }
|
bool IsEscapeCancel(void) const { return fBox->IsEscapeCancel(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void HandleNoNumLock(const int32 &code, int32 &rawchar, BMessage *msg);
|
void HandleNoNumLock(const int32 &code, int32 &rawchar,
|
||||||
|
BMessage *msg);
|
||||||
|
|
||||||
AutoTextControl *fBox;
|
AutoTextControl *fBox;
|
||||||
BMessenger *fMessenger;
|
BMessenger *fMessenger;
|
||||||
BMessage *fCurrentMessage;
|
BMessage *fCurrentMessage;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user