// /// Handle the DRAGLISTMSGSTRING notification by calling virtual functions /// based on the notification message. // /// Responds to the DL_BEGINDRAG, DL_DRAGGING, DL_DROPPED, and DL_CANCELDRAG /// messages by calling the BeginDrag, Dragging, Dropped, and CancelDrag functions /// respectively. // TResult TDragList::DragNotify(TParam1, TParam2 lp) { DRAGLISTINFO * info = (DRAGLISTINFO *)lp; if (info) { TPoint p = info->ptCursor; int item = ItemFromPoint(p); switch (info->uNotification) { case DL_BEGINDRAG: return BeginDrag(item, p); case DL_DRAGGING: return Dragging(item, p); case DL_DROPPED: Dropped(item, p); break; case DL_CANCELDRAG: CancelDrag(item, p); break; default: // Should not ever happen. ///TH perhaps throw an exception? break; } } return 0; }
BOOL CFileBrowserListCtrl::PreTranslateMessage(MSG* pMsg) { // The list control is supposed to send an NM_RETURN notification to the // parent window if the Enter key is pressed, but it doesn't. This is a // known bug, and some folks work around it by handling WM_GETDLGCODE and // returning DLGC_WANTALLKEYS. This solution sucks, because it makes the // list control EAT system keys, which causes unexpected behavior in the // parent window, e.g. if the parent is a dialog, the dialog navigation // keys won't work while the list control has input focus. It's better to // detect Enter here, send NM_RETURN, and then dispatch the key as usual. if (pMsg->message == WM_KEYDOWN) { switch (pMsg->wParam) { case VK_RETURN: if (!m_LabelEdit) { CWnd *wp = GetParent(); if (wp != NULL) { NMHDR nmh; nmh.hwndFrom = m_hWnd; nmh.idFrom = GetDlgCtrlID(); nmh.code = NM_RETURN; wp->SendMessage(WM_NOTIFY, nmh.idFrom, (LPARAM)&nmh); } } break; case VK_ESCAPE: if (m_LabelEdit) m_LabelEdit = FALSE; // cancel label edit else CancelDrag(); break; } } return CListCtrl::PreTranslateMessage(pMsg); }
////////////////// // Escape key cancels sizing. // void CSizerBar::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar==VK_ESCAPE && m_bDragging) { CancelDrag(); return; } CStatic::OnChar(nChar, nRepCnt, nFlags); }
bool psSlotManager::HandleEvent( iEvent& ev ) { if(isDragging) { if(ev.Name == MouseMove) { if(isPlacing) { // Update item position. UpdateItem(); } } else if(ev.Name == MouseDown) { uint button = csMouseEventHelper::GetButton(&ev); if(button == 0) // Left { if(isPlacing) { // Drop the item at the current position. if(isRotating) { DropItem(); return true; } // Else begin rotate... isRotating = true; basePoint = PawsManager::GetSingleton().GetMouse()->GetPosition(); psengine->GetSceneManipulator()->SaveCoordinates(csVector2(basePoint.x, basePoint.y)); return false; } // Else place... PlaceItem(); } else { CancelDrag(); // Show the inventory window, remove outline mesh etc. if we're placing. if(isPlacing) { PawsManager::GetSingleton().GetMainWidget()->FindWidget("InventoryWindow")->Show(); // Remove outline mesh. psengine->GetSceneManipulator()->RemoveSelected(); isPlacing = false; isRotating = false; } } } } return false; }
////////////////// // User let go of mouse: leave size-drag mode // void CSizerBar::OnLButtonUp(UINT nFlags, CPoint pt) { if (m_bDragging) { pt = Constrain(pt); // don't go outside constraints pt = Rectify(pt); // clip x or y CPoint ptDelta = pt-m_ptOriginal; // distance moved CancelDrag(); // cancel drag mode NotifyMoved(ptDelta); // notify parent } }
//--------------------------------------------------------------------------- void __fastcall ShowAsModal(TForm * Form, void *& Storage) { SetCorrectFormParent(Form); CancelDrag(); if (GetCapture() != 0) SendMessage(GetCapture(), WM_CANCELMODE, 0, 0); ReleaseCapture(); (static_cast<TPublicForm*>(Form))->FFormState << fsModal; TShowAsModalStorage * AStorage = new TShowAsModalStorage; AStorage->FocusActiveWindow = GetActiveWindow(); AStorage->FocusState = SaveFocusState(); Screen->SaveFocusedList->Insert(0, Screen->FocusedForm); Screen->FocusedForm = Form; AStorage->FocusWindowList = DisableTaskWindows(0); Form->Show(); SendMessage(Form->Handle, CM_ACTIVATE, 0, 0); Storage = AStorage; }
bool psSlotManager::HandleEvent( iEvent& ev ) { if(isDragging) { int button = csMouseEventHelper::GetButton(&ev); if(ev.Name == MouseMove) { if(isPlacing) { // Update item position. UpdateItem(); } } else if(ev.Name == MouseDown) { if(button == csmbLeft) // Left { if(isPlacing) { // Drop the item at the current position. DropItem(!(csMouseEventHelper::GetModifiers(&ev) & CSMASK_SHIFT)); return true; } else { PlaceItem(); } } else if(button == csmbRight) // right { if(!isRotating) { basePoint = PawsManager::GetSingleton().GetMouse()->GetPosition(); isRotating = true; if(csMouseEventHelper::GetModifiers(&ev) & CSMASK_SHIFT) { psengine->GetSceneManipulator()->SetRotation(PS_MANIPULATE_PITCH,PS_MANIPULATE_YAW); } else { psengine->GetSceneManipulator()->SetRotation(PS_MANIPULATE_ROLL,PS_MANIPULATE_NONE); } return true; } } else { CancelDrag(); } } else if(ev.Name == MouseUp) { if(button == csmbRight) // right { if(isRotating) { //PawsManager::GetSingleton().GetMouse()->SetPosition(basePoint.x, basePoint.y); psengine->GetG2D()->SetMousePosition(basePoint.x, basePoint.y); psengine->GetSceneManipulator()->SetPosition(csVector2(basePoint.x, basePoint.y)); isRotating = false; return true; } } } /*else if(ev.Name == KeyDown) { } else if(ev.Name == KeyUp) { }*/ } return false; }
void psSlotManager::Handle( pawsDnDButton* target ) { if( target==NULL ) { return; } if ( !IsDragging() ) { // Make sure other code isn't drag-and-dropping a different object. pawsWidget *dndWidget = PawsManager::GetSingleton().GetDragDropWidget(); if (dndWidget) { return; } if( (target->GetMaskingImage()==NULL || *(target->GetMaskingImage()->GetName())==0) && (target->GetName()==NULL || *(target->GetName())==0 ) ) { //there's nothing in this button, don't drag it. return; } pawsDnDButton* widget = new pawsDnDButton(); widget->SetRelativeFrame( 0,0, target->GetDefaultFrame().Width(), target->GetDefaultFrame().Height() ); widget->PlaceItem( target->GetMaskingImage()!=NULL?target->GetMaskingImage()->GetName():NULL, target->GetName(), target->GetToolTip(), target->GetAction() ); if( target->GetMaskingImage()==NULL || *(target->GetMaskingImage()->GetName()) == 0 ) { widget->SetText(target->GetName()); } widget->SetBackgroundAlpha(0); widget->SetParent( NULL ); widget->SetIndexBase( target->GetIndexBase() ); //SetDragDetails(parent, 0); SetDragDetails(target); isDragging = true; PawsManager::GetSingleton().SetDragDropWidget( widget ); } else if( draggingSlot.stackCount == 0 ) //dragging from a dndbutton { //do nothing if it's the same slot and we aren't dragging a split item if(target == (pawsDnDButton *)draggingSlot.slot ) { CancelDrag(); return; } if ( target->GetDnDLock() ) //state "down" == true == editable { target->Clear(); target->SetImageNameCallback( ((pawsDnDButton *)draggingSlot.slot)->GetImageNameCallback() ); target->SetNameCallback( ((pawsDnDButton *)draggingSlot.slot)->GetNameCallback() ); target->SetActionCallback( ((pawsDnDButton *)draggingSlot.slot)->GetActionCallback() ); if( target->PlaceItem( ((pawsDnDButton *)draggingSlot.slot)->GetMaskingImage()!=NULL?((pawsDnDButton *)draggingSlot.slot)->GetMaskingImage()->GetName():NULL, ((pawsDnDButton *)draggingSlot.slot)->GetName(), ((pawsDnDButton *)draggingSlot.slot)->GetToolTip(), ((pawsDnDButton *)draggingSlot.slot)->GetAction() ) ) { //move key bindings csString editedCmd; const psControl* keyBinding; csString keyName; uint32 keyButton, keyMods; psControl::Device keyDevice; editedCmd.Format("Shortcut %d",((pawsDnDButton *)draggingSlot.slot)->GetButtonIndex()+1 ); keyBinding = psengine->GetCharControl()->GetTrigger( editedCmd ); if( keyBinding->name.Length()>0 ) { keyButton = keyBinding->button; keyMods = keyBinding->mods; keyDevice = keyBinding->device; psengine->GetCharControl()->RemapTrigger(editedCmd,psControl::NONE,0,0); editedCmd.Format("Shortcut %d",target->GetButtonIndex()+1 ); psengine->GetCharControl()->RemapTrigger( editedCmd, keyDevice, keyButton, keyMods ); } //set text if there's no icon if( ((pawsDnDButton *)draggingSlot.slot)->GetMaskingImage()==NULL || *(((pawsDnDButton *)draggingSlot.slot)->GetMaskingImage()->GetName()) == 0 ) { target->SetText( ((pawsDnDButton *)draggingSlot.slot)->GetName() ); } //clear contents of the originating button ((pawsDnDButton *)draggingSlot.slot)->Clear(); //redraw the parent window to change layout target->SetParent( ((pawsDnDButton *)draggingSlot.slot)->GetParent() ); target->GetParent()->GetParent()->OnResize(); // parent is the buttonHolder, grandparent is the shortcut window. } CancelDrag(); } } else //dragging from a Slot { CancelDrag(); if( !draggingSlot.Action.IsEmpty() ) { target->PlaceItem( ((pawsSlot *)draggingSlot.slot)->ImageName(), draggingSlot.toolTip, draggingSlot.toolTip, draggingSlot.Action ); } else { csString t = "/use " + draggingSlot.toolTip; target->PlaceItem( ((pawsSlot *)draggingSlot.slot)->ImageName(), draggingSlot.toolTip, draggingSlot.toolTip, t ); draggingSlot.stackCount--; } } }
void psSlotManager::Handle( pawsSlot* slot, bool grabOne, bool grabAll ) { if ( !isDragging ) { // Make sure other code isn't drag-and-dropping a different object. pawsWidget *dndWidget = PawsManager::GetSingleton().GetDragDropWidget(); if (dndWidget) return; if( !slot->GetLock() ){ int stackCount = slot->StackCount(); if ( stackCount > 0 ) { int tmpID = (int)slotsInUse.Push(slot); if ( stackCount == 1 || grabOne ) { int old_count = last_count; OnNumberEntered("StackCount",tmpID, 1); last_count = old_count; } else if ( grabAll ) { int old_count = last_count; OnNumberEntered("StackCount",tmpID, stackCount); last_count = old_count; } else // Ask for the number of items to grab { csString max; max.Format("Max %d", stackCount ); pawsNumberPromptWindow::Create(max, last_count, 1, stackCount, this, "StackCount", tmpID); } } } } else { // Do nothing if it's the same slot and we aren't dropping a split stack. // Note that crafters use this to pick up one item from a stack, // drop it on the stack, and have the server put the item in a // different slot. if(slot == draggingSlot.slot && !draggingSlot.split) { CancelDrag(); return; } if( !slot->GetLock() ) { //printf("Slot->ID: %d\n", slot->ID() ); //printf("Container: %d\n", slot->ContainerID() ); //printf("DraggingSlot.ID %d\n", draggingSlot.slotID); if ( draggingSlot.containerID == CONTAINER_SPELL_BOOK ) { // Stop dragging the spell around CancelDrag(); // Set the image to this slot. slot->PlaceItem( ((pawsSlot *)draggingSlot.slot)->ImageName(), "", "", draggingSlot.stackCount); } else { psSlotMovementMsg msg( draggingSlot.containerID, draggingSlot.slotID, slot->ContainerID(), slot->ID(), draggingSlot.stackCount ); msg.SendMessage(); // Reset widgets/objects/status. PawsManager::GetSingleton().SetDragDropWidget( NULL ); isDragging = false; if(isPlacing) { psengine->GetSceneManipulator()->RemoveSelected(); if(hadInventory) { PawsManager::GetSingleton().GetMainWidget()->FindWidget("InventoryWindow")->Show(); } isPlacing = false; isRotating = false; hadInventory = false; } } } } }
BOOL COXDragDockContext::Track() { // don't handle if capture already set if (::GetCapture() != NULL) return FALSE; // set capture to the window which received this message m_pBar->SetCapture(); ASSERT(m_pBar == CWnd::GetCapture()); // get messages until capture lost or cancelled/accepted while(CWnd::GetCapture() == m_pBar) { MSG msg; #ifndef _MAC if (!::GetMessage(&msg, NULL, 0, 0)) #else // don't allow yielding while tracking since we don't have LockWindowUpdate if (!PeekMessage(&msg, NULL, 0, 0, PM_REMOVE|PM_NOYIELD)) continue; if (msg.message == WM_QUIT) #endif { AfxPostQuitMessage(PtrToInt(msg.wParam)); break; } switch (msg.message) { case WM_LBUTTONUP: // drag finished EndDrag(); return TRUE; case WM_MOUSEMOVE: Move(msg.pt); break; case WM_KEYUP: OnKey((int)msg.wParam, FALSE); break; case WM_KEYDOWN: OnKey((int)msg.wParam, TRUE); if (msg.wParam == VK_ESCAPE) goto exit_cancel_drag; break; case WM_RBUTTONDOWN: goto exit_cancel_drag; // just dispatch rest of the messages default: DispatchMessage(&msg); break; } } exit_cancel_drag: // goto - can't use break as we're inside a switch() CancelDrag(); return FALSE; }
void COXDragDockContext::EndDrag() { CancelDrag(); if (m_ptStart == m_ptLast) return; m_dwOverDockStyle = m_bForceFrame ? 0 : CanDock(); if (m_dwOverDockStyle != 0) { // dockbar we're going to dock at. CDockBar* pDockBar = GetDockBar(); ASSERT(pDockBar != NULL); // check the original dockbar - if a valid CSizeDockBar... // work out the row number. CDockBar* pOrigDockBar = m_pBar->m_pDockBar; int nOrigCheckSum = -1; if (pOrigDockBar != NULL && pOrigDockBar->IsKindOf(RUNTIME_CLASS(COXSizeDockBar))) nOrigCheckSum = ((COXSizeDockBar*)pOrigDockBar)->CheckSumBars(); // Now we're going to actually dock the window. // Update the appropriate size in the control bar. if (HORZF(m_dwOverDockStyle)) { ((COXSizeControlBar*)m_pBar)->m_HorzDockSize = m_rectDragDock.Size(); } else { ((COXSizeControlBar*)m_pBar)->m_VertDockSize = m_rectDragDock.Size(); } m_pDockSite->DockControlBar(m_pBar, pDockBar, m_rectDragDock); // if into a sizeable dockbar (always we be !), then adjust other bars in the same row // to attempt to maintain size if (pDockBar->IsKindOf(RUNTIME_CLASS(COXSizeDockBar))) { if (pOrigDockBar != pDockBar || ((COXSizeDockBar*)pDockBar)->CheckSumBars() != nOrigCheckSum) { ((COXSizeDockBar*)pDockBar)->AdjustForNewBar(m_pBar); } // force RecalcLayout below to adjust sizes always for the bar into // which we have docked - this is needed as if the bar doesn't // actually changed position in the array, but has changed size // (because the docking algorithm above guess the size wrong, then // we need to set it back again. ((COXSizeDockBar*)pDockBar)->m_CountBars = 0; } // This RecalcLayout is what will adjust the size. m_pDockSite->RecalcLayout(); } else { m_ptMRUFloatPos = m_rectFrameDragHorz.TopLeft(); m_pDockSite->FloatControlBar(m_pBar, m_rectFrameDragHorz.TopLeft(), CBRS_ALIGN_TOP | (m_dwDockStyle & CBRS_FLOAT_MULTI)); m_pBar->SendMessage(WM_OX_APP_AFTERFLOAT_MSG); // set flag to indicate user has moved the bar - done as a style flag on the window. CWnd* pFrameWnd = m_pBar->GetParentFrame(); ASSERT(pFrameWnd->IsKindOf(RUNTIME_CLASS(CMiniDockFrameWnd))); pFrameWnd->ModifyStyle(0, CBRS_MOVED_BY_USER); } }
////////////////// // Handle WM_CANCELMODE. This is probably unnecessary. // void CSizerBar::OnCancelMode() { if (m_bDragging) CancelDrag(); }
BOOL CSSplitter::PreTranslateMessage(MSG* pMsg) { if ( (pMsg->message == WM_KEYDOWN)&&( pMsg->wParam == VK_ESCAPE )) CancelDrag(); return CWnd::PreTranslateMessage(pMsg); }