void _BTextInput_::MakeFocus(bool state) { if (state == IsFocus()) return; BTextView::MakeFocus(state); if (state) { SetInitialText(); SelectAll(); } else { if (strcmp(Text(), fPreviousText) != 0) TextControl()->Invoke(); free(fPreviousText); fPreviousText = NULL; } if (Window() != NULL) { // Invalidate parent to draw or remove the focus mark if (BTextControl* parent = dynamic_cast<BTextControl*>(Parent())) { BRect frame = Frame(); frame.InsetBy(-1.0, -1.0); parent->Invalidate(frame); } } }
void BComboBox::TextInput::MakeFocus(bool state) { //+ PRINT(("_BTextInput_::MakeFocus(state=%d, view=%s)\n", state, //+ Parent()->Name())); if (state == IsFocus()) return; BComboBox* parent = dynamic_cast<BComboBox*>(Parent()); ASSERT(parent); BTextView::MakeFocus(state); if (state) { SetInitialText(); fClean = true; // text hasn't been dirtied yet. BMessage *m; if (Window() && (m = Window()->CurrentMessage()) != 0 && m->what == B_KEY_DOWN) { // we're being focused by a keyboard event, so // select all... SelectAll(); } } else { ASSERT(fInitialText); if (strcmp(fInitialText, Text()) != 0) parent->CommitValue(); free(fInitialText); fInitialText = NULL; fClean = false; BMessage *m; if (Window() && (m = Window()->CurrentMessage()) != 0 && m->what == B_MOUSE_DOWN) Select(0,0); // hide popup window if it's showing when the text input loses focus if (parent->fPopupWindow && parent->fPopupWindow->Lock()) { if (!parent->fPopupWindow->IsHidden()) parent->HidePopupWindow(); parent->fPopupWindow->Unlock(); } } // make sure the focus indicator gets drawn or undrawn if (Window()) { BRect invalRect(Bounds()); invalRect.InsetBy(-kTextInputMargin, -kTextInputMargin); parent->Draw(invalRect); parent->Flush(); } }