bool LayoutManager::ProcessKeys(Msg msg, Key key) { switch( msg ) { case Msg::KEYUP: break; case Msg::KEYDOWN: if(UIWindow *wnd = GetFocusWnd() ) { while( wnd ) { if( wnd->OnKeyPressed(key) ) { return true; } wnd = wnd->GetParent(); } } else { GetDesktop()->OnKeyPressed(key); } break; default: assert(false); } return false; }
void Ctrl::DoMouseFB(int event, Point p, int zdelta, CParser& cp) { ReadKeyMods(cp); MousePos = p; int a = event & ACTION; if(a == UP && Ctrl::ignoreclick) { EndIgnore(); return; } else if(a == DOWN && ignoreclick) return; LLOG("### Mouse event: " << event << " position " << p << " zdelta " << zdelta << ", capture " << Upp::Name(captureCtrl)); if(captureCtrl) MouseEventFB(captureCtrl->GetTopCtrl(), event, p, zdelta); else for(int i = topctrl.GetCount() - 1; i >= 0; i--) { Ptr<Ctrl> t = topctrl[i]; Rect rr = t->GetRect(); if(rr.Contains(p)) { MouseEventFB(t, event, p, zdelta); return; } } Ctrl *desktop = GetDesktop(); if(desktop) { desktop->DispatchMouse(event, p, zdelta); desktop->PostInput(); } }
LRESULT DesktopManager::OnCmdSwitchDesktop(HWND /*hWnd*/, UINT /*message*/, WPARAM /*wParam*/, LPARAM lParam) { Desktop * desk = GetDesktop(lParam); if (desk) SwitchToDesktop(desk); else MessageBox(NULL, TEXT("No such desktop"), TEXT("Error"), MB_OK|MB_ICONERROR); return 0; }
bool Ctrl::DoKeyFB(dword key, int cnt) { LLOG("DoKeyFB [" << GetKeyDesc(key) << "] " << key << ", " << cnt); bool b = DispatchKey(key, cnt); SyncCaret(); Ctrl *desktop = GetDesktop(); if(desktop) desktop->PostInput(); return b; }
bool LayoutManager::ProcessText(int c) const { if (UIWindow *wnd = GetFocusWnd()) { while (wnd) { if (wnd->OnChar(c)) { return true; } wnd = wnd->GetParent(); } } else { GetDesktop()->OnChar(c); } return false; }
GUIWindow *GetActiveWindow() { GUIWindow *TargetWnd = GetDesktop(); while (TargetWnd->ActiveChild != 0) { // TODO: Shouldn't it be the window's responsibility to switch active children if the currently active child // is no longer visible? That would mean this could need to work a little differently.... if (TargetWnd->ActiveChild->IsWindow() && TargetWnd->ActiveChild->IsVisible()) { TargetWnd = TargetWnd->ActiveChild; } else { break; } } return TargetWnd; }
void RecieveKeyboardKey(KeyboardKey *Key) { if (!GetDesktop()->IsVisible()) { return; } bool IsShiftPressed = Input::IsShiftDown(); GUIWindow *TargetControl = GUI::GetActiveControl(); GUIWindow *TargetWindow = GUI::GetActiveWindow(); // Mouse handling. if (Key->KeyCode == 0x01) // Handle left clicks. { Point ClickPoint; ClickPoint.X = Input::ClientCursorPos.x; ClickPoint.Y = Input::ClientCursorPos.y; GUIWindow *ClickedWindow = GetDesktop()->ChildAtPoint(ClickPoint); // Check if a valid window was found. if (ClickedWindow != 0) { bool WasActive = false; if (ClickedWindow->Active()) { WasActive = true; } else { GetDesktop()->SetActiveChild(ClickedWindow); } GUIWindow *ClickedControl = ClickedWindow->ChildAtPoint(ClickPoint); // Check if a valid control was found. if (ClickedControl != 0) { ClickedWindow->SetActiveChild(ClickedControl); if (ClickedControl->IsButton()) { ClickedControl->PushState = PUSH_STATE_PUSHED; } } else { if (WasActive) { ClickedWindow->SetActiveChild(0); } } } } // Keyboard (typing stuff) handling. if (TargetControl != 0 && TargetWindow != 0) { if (Key->KeyCode == 0x0D) // Handle enter. { if (TargetControl->OnEnter != 0) { (*TargetControl->OnEnter)(); } } if (TargetControl->CanBeTypedIn()) { if (Key->CheckForRepeat()) { Key->SetRepeatComplete(); } if ((Key->HasCapitalChar() && IsShiftPressed)) { TargetControl->Text += Key->CapitalKey; TargetControl->CaretPosition += 1; } else if (Key->HasChar()) { TargetControl->Text += Key->Key; TargetControl->CaretPosition += 1; } else if (Key->KeyCode == 0x08) // Handle backspace. { if (TargetControl->Text.length() > 0 && TargetControl->CaretPosition > 0) { TargetControl->Text.Trim(TargetControl->CaretPosition-1, TargetControl->CaretPosition); TargetControl->CaretPosition -= 1; } } else if (Key->KeyCode == 0x2E) // Handle delete. { if (TargetControl->Text.length() > 0 && TargetControl->CaretPosition < TargetControl->Text.length()) { TargetControl->Text.Trim(TargetControl->CaretPosition, TargetControl->CaretPosition+1); } } else if (Key->KeyCode == 0x25) // Handle left arrow key { if (TargetControl->CaretPosition > 0) { TargetControl->CaretPosition -= 1; } } else if (Key->KeyCode == 0x27) // Handle right arrow key { if (TargetControl->CaretPosition < TargetControl->Text.length()) { TargetControl->CaretPosition += 1; } } } } }