Added missing SearchBarTextcontrol class
This commit is contained in:
parent
088a1bb5f5
commit
8ec3b19976
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright 2012, Dario Casalinuovo. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Dario Casalinuovo, dario.casalinuovo@gmail.com
|
||||
*/
|
||||
|
||||
#include "CayaConstants.h"
|
||||
#include "SearchBarTextControl.h"
|
||||
|
||||
#include <Font.h>
|
||||
#include <String.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
const char* kSearchText = "Search...";
|
||||
|
||||
|
||||
SearchBarTextControl::SearchBarTextControl(BMessage* message)
|
||||
:
|
||||
BTextControl("searchBox", NULL, NULL, message)
|
||||
{
|
||||
SetEventMask(B_POINTER_EVENTS);
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
rgb_color color = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
||||
SetText(kSearchText);
|
||||
TextView()->SetName("SearchBoxTextView");
|
||||
TextView()->SetFontAndColor(NULL, B_FONT_ALL, &color);
|
||||
TextView()->MakeSelectable(false);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SearchBarTextControl::MouseDown(BPoint position)
|
||||
{
|
||||
BString text(Text());
|
||||
BPoint currentPosition;
|
||||
uint32 buttons;
|
||||
GetMouse(¤tPosition, &buttons);
|
||||
BView* view = Window()->FindView(currentPosition);
|
||||
|
||||
if (view != NULL && (view->Name() == TextView()->Name()
|
||||
|| view->Name() == Name())) {
|
||||
BTextControl::MouseDown(position);
|
||||
SetText("");
|
||||
}
|
||||
|
||||
if (TextView()->IsFocus()) {
|
||||
SetText("");
|
||||
} else if (!TextView()->IsFocus()) {
|
||||
SetText(kSearchText);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SearchBarTextControl::KeyDown(const char* bytes, int32 numBytes)
|
||||
{
|
||||
if (TextView()->IsFocus()) {
|
||||
if (Text() == kSearchText)
|
||||
SetText("");
|
||||
|
||||
BTextControl::KeyDown(bytes, numBytes);
|
||||
BString text(Text());
|
||||
if (TextView()->IsFocus() && text.Length() > 0) {
|
||||
BMessage* msg = ModificationMessage();
|
||||
msg->AddPointer("source", this);
|
||||
Window()->MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright 2012, Dario Casalinuovo. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Dario Casalinuovo, dario.casalinuovo@gmail.com
|
||||
*/
|
||||
|
||||
#include "CayaConstants.h"
|
||||
#include "SearchBarTextControl.h"
|
||||
|
||||
#include <Font.h>
|
||||
#include <String.h>
|
||||
#include <Window.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
const char* kSearchText = "Search...";
|
||||
|
||||
|
||||
SearchBarTextControl::SearchBarTextControl(BMessage* message)
|
||||
:
|
||||
BTextControl("searchBox", NULL, NULL, message)
|
||||
{
|
||||
//SetEventMask(B_POINTER_EVENTS);
|
||||
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
|
||||
rgb_color color = tint_color(ViewColor(), B_DARKEN_1_TINT);
|
||||
SetText(kSearchText);
|
||||
TextView()->SetName("SearchBoxTextView");
|
||||
TextView()->SetFontAndColor(NULL, B_FONT_ALL, &color);
|
||||
TextView()->MakeSelectable(false);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SearchBarTextControl::MouseDown(BPoint position)
|
||||
{
|
||||
BString text(Text());
|
||||
BPoint currentPosition;
|
||||
uint32 buttons;
|
||||
GetMouse(¤tPosition, &buttons);
|
||||
BView* view = Window()->FindView(currentPosition);
|
||||
if (view != NULL) {
|
||||
if (view->Name() == TextView()->Name()
|
||||
|| view->Name() == Name()) {
|
||||
//TextView()->Select(0,0);
|
||||
if (TextView()->IsFocus()) {
|
||||
SetText("");
|
||||
printf("mouse down\n");
|
||||
BTextControl::MouseDown(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!TextView()->IsFocus()) {
|
||||
printf("is not focus\n");
|
||||
BView* buddyView = Window()->FindView("buddyView");
|
||||
if (text.Length() == 0 || text == kSearchText
|
||||
|| !buddyView->IsFocus())
|
||||
SetText(kSearchText);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SearchBarTextControl::KeyDown(const char* bytes, int32 numBytes)
|
||||
{
|
||||
if (TextView()->IsFocus()) {
|
||||
if (Text() == kSearchText)
|
||||
SetText("");
|
||||
|
||||
BTextControl::KeyDown(bytes, numBytes);
|
||||
BString text(Text());
|
||||
if (TextView()->IsFocus() && text.Length() > 0) {
|
||||
BMessage* msg = ModificationMessage();
|
||||
msg->AddPointer("source", this);
|
||||
Window()->MessageReceived(msg);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/*
|
||||
* Copyright 2012, Dario Casalinuovo. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
#ifndef _SEARCHBAR_TEXT_CONTROL_H
|
||||
#define _SEARCHBAR_TEXT_CONTROL_H
|
||||
|
||||
#include <TextControl.h>
|
||||
|
||||
class SearchBarTextControl : public BTextControl {
|
||||
public:
|
||||
SearchBarTextControl(BMessage* message);
|
||||
virtual void MouseDown(BPoint position);
|
||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||
};
|
||||
|
||||
#endif // _SEARCHBAR_TEXT_CONTROL_H
|
Ŝarĝante…
Reference in New Issue