RetroZilla/embedding/browser/powerplant/source/CUrlField.cp

73 lines
1.8 KiB
C++
Raw Normal View History

2015-10-21 05:03:22 +02:00
#include "CUrlField.h"
#include <LString.h>
#include <PP_KeyCodes.h>
// CUrlField:
// A text edit field that broadcasts its PaneID on Return or Enter.
// ---------------------------------------------------------------------------
// <09> CUrlField Stream Constructor [public]
// ---------------------------------------------------------------------------
CUrlField::CUrlField(LStream* inStream)
: LEditText(inStream)
{
}
// ---------------------------------------------------------------------------
// <09> ~CUrlField Destructor [public]
// ---------------------------------------------------------------------------
CUrlField::~CUrlField()
{
}
// ---------------------------------------------------------------------------
// <09> HandleKeyPress
// ---------------------------------------------------------------------------
// Broadcast the paneID when the user hits Return or Enter
Boolean
CUrlField::HandleKeyPress(const EventRecord &inKeyEvent)
{
Boolean keyHandled = true;
SInt16 theChar = (SInt16) (inKeyEvent.message & charCodeMask);
if (theChar == char_Return || theChar == char_Enter)
{
Str255 urlString;
BroadcastMessage(GetPaneID(), (void*)GetDescriptor(urlString));
}
else
keyHandled = Inherited::HandleKeyPress(inKeyEvent);
return keyHandled;
}
// ---------------------------------------------------------------------------
// <09> ClickSelf
// ---------------------------------------------------------------------------
// Select everything when a single click gives us the focus
void
CUrlField::ClickSelf(const SMouseDownEvent &inMouseDown)
{
Boolean wasTarget = IsTarget();
Inherited::ClickSelf(inMouseDown);
if (!wasTarget)
{
ControlEditTextSelectionRec selection;
GetSelection(selection);
if (selection.selStart == selection.selEnd)
SelectAll();
}
}