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:
DarkWyrm 2007-01-03 21:57:42 +00:00
parent dceaa55687
commit 8eb93fe5e3
2 changed files with 101 additions and 102 deletions

View File

@ -12,7 +12,7 @@
#include <ctype.h>
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),
fMessenger(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
// just calling SetEscapeCancel(true) for just *one* AutoTextControl in a window. *heh*
int32 rawchar,mod;
@ -32,16 +33,14 @@ filter_result AutoTextControlFilter::Filter(BMessage *msg, BHandler **target)
msg->FindInt32("modifiers",&mod);
if(rawchar == B_ESCAPE)
{
if(mod & B_COMMAND_KEY)
if (rawchar == B_ESCAPE) {
if (mod & B_COMMAND_KEY)
return B_DISPATCH_MESSAGE;
if(IsEscapeCancel())
{
if (IsEscapeCancel()) {
BLooper *loop = (*target)->Looper();
if(loop)
{
if (loop) {
BMessenger msgr(loop);
msgr.SendMessage(B_QUIT_REQUESTED);
return B_SKIP_MESSAGE;
@ -49,12 +48,12 @@ filter_result AutoTextControlFilter::Filter(BMessage *msg, BHandler **target)
}
}
BView *v=dynamic_cast<BView*>(*target);
if(!v || strcmp("_input_",v->Name())!=0)
BView *v = dynamic_cast<BView*>(*target);
if (!v || strcmp("_input_",v->Name()) != 0)
return B_DISPATCH_MESSAGE;
AutoTextControl *text = dynamic_cast<AutoTextControl*>(v->Parent());
if(!text || text!=fBox)
if (!text || text != fBox)
return B_DISPATCH_MESSAGE;
// 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
int32 scancode;
if(msg->FindInt32("key",&scancode)!=B_OK)
if (msg->FindInt32("key",&scancode) != B_OK)
scancode = -1;
HandleNoNumLock(scancode,rawchar,msg);
@ -75,101 +74,93 @@ filter_result AutoTextControlFilter::Filter(BMessage *msg, BHandler **target)
filter_result result = KeyFilter(rawchar,mod);
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
if(mod & B_COMMAND_KEY)
if (mod & B_COMMAND_KEY)
return B_DISPATCH_MESSAGE;
// We don't use strlen() because it is not UTF-8 aware, which can affect
// 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 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());
else
if(fBox)
else if (fBox)
fBox->Invoke();
return B_DISPATCH_MESSAGE;
}
void AutoTextControlFilter::SetMessenger(BMessenger *msgr)
void
AutoTextControlFilter::SetMessenger(BMessenger *msgr)
{
if(fMessenger)
if (fMessenger)
delete fMessenger;
fMessenger = msgr;
}
void AutoTextControlFilter::SendMessage(BMessage *msg)
void
AutoTextControlFilter::SendMessage(BMessage *msg)
{
if(!msg)
if (!msg)
return;
if(fMessenger)
if (fMessenger)
fMessenger->SendMessage(msg);
else
delete msg;
}
void AutoTextControlFilter::HandleNoNumLock(const int32 &code, int32 &rawchar,
BMessage *msg)
void
AutoTextControlFilter::HandleNoNumLock(const int32 &code, int32 &rawchar, BMessage *msg)
{
switch(code)
{
case 101: // Numlock .
{
switch(code) {
case 101: {
// Numlock .
rawchar = '.';
break;
}
case 100: // Numlock 0
{
case 100: {
// Numlock 0
rawchar = '0';
break;
}
case 88:
{
case 88: {
rawchar = '1';
break;
}
case 89:
{
case 89: {
rawchar = '2';
break;
}
case 90:
{
case 90: {
rawchar = '3';
break;
}
case 72:
{
case 72: {
rawchar = '4';
break;
}
case 74:
{
case 74: {
rawchar = '6';
break;
}
case 55:
{
case 55: {
rawchar = '7';
break;
}
case 56:
{
case 56: {
rawchar = '8';
break;
}
case 57:
{
case 57: {
rawchar = '9';
break;
}
@ -185,12 +176,13 @@ void AutoTextControlFilter::HandleNoNumLock(const int32 &code, int32 &rawchar,
msg->ReplaceInt8("byte",(int8)rawchar);
int32 mod;
if(msg->FindInt32("modifiers",&mod)==B_OK)
{
if (msg->FindInt32("modifiers",&mod)==B_OK) {
uint32 mask = B_NUM_LOCK;
if(mod & B_CAPS_LOCK)
if (mod & B_CAPS_LOCK)
mask |= B_CAPS_LOCK;
if(mod & B_SCROLL_LOCK)
if (mod & B_SCROLL_LOCK)
mask |= B_SCROLL_LOCK;
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,
const char *text, BMessage *msg, uint32 resize, uint32 flags)
: BTextControl(frame,name,label,text,msg,resize,flags),
const char *text, BMessage *msg, uint32 resize,
uint32 flags)
: BTextControl(frame,name,label,text,msg,resize,flags),
fFilter(NULL),
fEscapeCancel(false),
fCharLimit(0)
@ -210,45 +203,49 @@ AutoTextControl::AutoTextControl(const BRect &frame, const char *name, const cha
AutoTextControl::~AutoTextControl(void)
{
if(Window())
if (Window())
Window()->RemoveCommonFilter(fFilter);
delete fFilter;
}
void AutoTextControl::AttachedToWindow(void)
void
AutoTextControl::AttachedToWindow(void)
{
BTextControl::AttachedToWindow();
if(fFilter)
if (fFilter)
Window()->AddCommonFilter(fFilter);
}
void AutoTextControl::DetachedFromWindow(void)
void
AutoTextControl::DetachedFromWindow(void)
{
if(fFilter)
if (fFilter)
Window()->RemoveCommonFilter(fFilter);
}
void AutoTextControl::SetCharacterLimit(const uint32 &limit)
void
AutoTextControl::SetCharacterLimit(const uint32 &limit)
{
fCharLimit = limit;
}
uint32 AutoTextControl::GetCharacterLimit(const uint32 &limit)
uint32
AutoTextControl::GetCharacterLimit(const uint32 &limit)
{
return fCharLimit;
}
void AutoTextControl::SetFilter(AutoTextControlFilter *filter)
void
AutoTextControl::SetFilter(AutoTextControlFilter *filter)
{
if(fFilter)
{
if(Window())
if (fFilter) {
if (Window())
Window()->RemoveCommonFilter(fFilter);
delete fFilter;
}
fFilter = filter;
if(Window())
if (Window())
Window()->AddCommonFilter(fFilter);
}

View File

@ -14,8 +14,7 @@
class AutoTextControlFilter;
enum
{
enum {
M_PREVIOUS_FIELD='mprf',
M_NEXT_FIELD='mnxf',
M_ENTER_NAVIGATION='ennv'
@ -24,52 +23,55 @@ enum
class AutoTextControl : public BTextControl
{
public:
AutoTextControl(const BRect &frame, const char *name, const char *label,
const char *text, BMessage *msg,
uint32 resize = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
virtual ~AutoTextControl(void);
virtual void AttachedToWindow(void);
virtual void DetachedFromWindow(void);
void SetFilter(AutoTextControlFilter *filter);
AutoTextControlFilter *GetFilter(void) { return fFilter; }
AutoTextControl(const BRect &frame, const char *name,
const char *label, const char *text,
BMessage *msg,
uint32 resize = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
virtual ~AutoTextControl(void);
virtual void AttachedToWindow(void);
virtual void DetachedFromWindow(void);
void SetFilter(AutoTextControlFilter *filter);
AutoTextControlFilter * GetFilter(void) { return fFilter; }
void SetCharacterLimit(const uint32 &limit);
uint32 GetCharacterLimit(const uint32 &limit);
void SetCharacterLimit(const uint32 &limit);
uint32 GetCharacterLimit(const uint32 &limit);
void SetEscapeCancel(const bool &value) { fEscapeCancel = value; }
bool IsEscapeCancel(void) const { return fEscapeCancel; }
void SetEscapeCancel(const bool &value) { fEscapeCancel = value; }
bool IsEscapeCancel(void) const { return fEscapeCancel; }
private:
friend AutoTextControlFilter;
AutoTextControlFilter *fFilter;
bool fEscapeCancel;
uint32 fCharLimit;
friend AutoTextControlFilter;
AutoTextControlFilter *fFilter;
bool fEscapeCancel;
uint32 fCharLimit;
};
class AutoTextControlFilter : public BMessageFilter
{
public:
AutoTextControlFilter(AutoTextControl *checkview);
~AutoTextControlFilter(void);
virtual filter_result Filter(BMessage *msg, BHandler **target);
virtual filter_result KeyFilter(const int32 &key, const int32 &mod);
AutoTextControlFilter(AutoTextControl *checkview);
~AutoTextControlFilter(void);
virtual filter_result Filter(BMessage *msg, BHandler **target);
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);
BMessenger *GetMessenger(void) const { return fMessenger; }
void SendMessage(BMessage *msg);
BMessage *GetCurrentMessage(void) { return fCurrentMessage; }
void SetMessenger(BMessenger *msgr);
BMessenger * GetMessenger(void) const { return fMessenger; }
void SendMessage(BMessage *msg);
BMessage * GetCurrentMessage(void) { return fCurrentMessage; }
protected:
bool IsEscapeCancel(void) const { return fBox->IsEscapeCancel(); }
bool IsEscapeCancel(void) const { return fBox->IsEscapeCancel(); }
private:
void HandleNoNumLock(const int32 &code, int32 &rawchar, BMessage *msg);
void HandleNoNumLock(const int32 &code, int32 &rawchar,
BMessage *msg);
AutoTextControl *fBox;
BMessenger *fMessenger;
BMessage *fCurrentMessage;
AutoTextControl *fBox;
BMessenger *fMessenger;
BMessage *fCurrentMessage;
};
#endif