X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f6bcfd974ef26faf6f91a62cac09827e09463fd1..0dfb2393ddd200cb698351dbd44590898590d8c1:/utils/dialoged/src/dlghndlr.cpp diff --git a/utils/dialoged/src/dlghndlr.cpp b/utils/dialoged/src/dlghndlr.cpp index e6760ed49e..f6d3358712 100644 --- a/utils/dialoged/src/dlghndlr.cpp +++ b/utils/dialoged/src/dlghndlr.cpp @@ -34,6 +34,7 @@ #include "dlghndlr.h" #include "edlist.h" + IMPLEMENT_CLASS(wxResourceEditorDialogHandler, wxEvtHandler) IMPLEMENT_CLASS(wxResourceEditorControlHandler, wxEvtHandler) @@ -41,6 +42,8 @@ BEGIN_EVENT_TABLE(wxResourceEditorDialogHandler, wxEvtHandler) EVT_PAINT(wxResourceEditorDialogHandler::OnPaint) EVT_MOUSE_EVENTS(wxResourceEditorDialogHandler::OnMouseEvent) EVT_SIZE(wxResourceEditorDialogHandler::OnSize) +EVT_MENU(OBJECT_MENU_EDIT, wxResourceEditorDialogHandler::OnObjectEdit) +EVT_MENU(OBJECT_MENU_DELETE, wxResourceEditorDialogHandler::OnObjectDelete) END_EVENT_TABLE() BEGIN_EVENT_TABLE(wxResourceEditorControlHandler, wxEvtHandler) @@ -138,7 +141,7 @@ void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys) } return; } - + // Round down to take account of dialog units wxItemResource* resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(handlerDialog); if (resource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) @@ -218,6 +221,12 @@ void wxResourceEditorDialogHandler::OnRightClick(int x, int y, int WXUNUSED(keys { wxMenu *menu = resourceManager->GetPopupMenu(); menu->SetClientData((char *)handlerDialog); + + wxString str("wxDialog : "); + str += handlerDialog->GetName(); + + menu->SetLabel(OBJECT_MENU_TITLE,str); + handlerDialog->PopupMenu(menu, x, y); } @@ -298,6 +307,22 @@ return; wxMenu *menu = resourceManager->GetPopupMenu(); menu->SetClientData((char *)item); + + wxWindow *win = (wxWindow *)item; + + wxWindowPropertyInfo *info = resourceManager->CreatePropertyInfoForWindow(win); + if (info) + { + info->SetResource(resourceManager->FindResourceForWindow(win)); + wxString str; + str = win->GetClassInfo()->GetClassName(); + str += " : "; + if (win->GetName() != "") + str += win->GetName(); + + menu->SetLabel(OBJECT_MENU_TITLE,str); + } + handlerDialog->PopupMenu(menu, x, y); } @@ -327,8 +352,12 @@ void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event) // continue dragging. if (dragMode != wxDRAG_MODE_NONE) { - ProcessItemEvent(dragItem, event, dragType); - return; + if (dragType != wxDRAG_TYPE_BOUNDING_BOX && + dragItem != NULL) + { + ProcessItemEvent(dragItem, event, dragType); + return; + } } wxCoord x, y; @@ -352,7 +381,7 @@ void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event) } node = node->Next(); } - + // We're not on an item or selection handle. // so... check for a left or right click event // to send to the application. @@ -360,15 +389,160 @@ void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event) if (event.ShiftDown()) keys = keys | wxKEY_SHIFT; if (event.ControlDown()) keys = keys | wxKEY_CTRL; - if (event.LeftUp()) + if (node == NULL) + { + if (event.Dragging() && + (dragType == wxDRAG_TYPE_BOUNDING_BOX)) + + { + if (dragMode == wxDRAG_MODE_CONTINUE_LEFT) + { + wxClientDC dc(handlerDialog); + OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, NULL); + OnDragContinue(TRUE, x, y, keys, dc, NULL); + oldDragX = x; oldDragY = y; + } +/* + else if (event.LeftUp() && dragMode == wxDRAG_MODE_CONTINUE_LEFT) + { + + wxClientDC dc(handlerDialog); + OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, NULL); + OnDragContinue(TRUE, x, y, keys, dc, NULL); + oldDragX = x; oldDragY = y; + } +*/ + } + } + + if (event.LeftDown()) + { + if (!m_mouseCaptured) + { + handlerDialog->CaptureMouse(); + m_mouseCaptured = TRUE; + } + + // Starting to draw a bounding box around + // some numbe of controls on the dialog + if (node == NULL && + wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER) + { + dragItem = NULL; + dragMode = wxDRAG_MODE_START_LEFT; + firstDragX = x; + firstDragY = y; + dragType = wxDRAG_TYPE_BOUNDING_BOX; + wxClientDC dc(handlerDialog); + OnDragBegin(x, y, keys, dc, 0); + dragMode = wxDRAG_MODE_CONTINUE_LEFT; + oldDragX = x; oldDragY = y; + } + + event.Skip(); + } + else if (event.LeftUp()) { if (m_mouseCaptured) { handlerDialog->ReleaseMouse(); m_mouseCaptured = FALSE; } - - OnLeftClick(x, y, keys); + + if (dragType == wxDRAG_TYPE_BOUNDING_BOX) + { + // Determine the bounds of the surrounding box + int upperLeftX = (x < firstDragX) ? x : firstDragX; + int upperLeftY = (y < firstDragY) ? y : firstDragY; + int lowerRightX = (x > firstDragX) ? x : firstDragX; + int lowerRightY = (y > firstDragY) ? y : firstDragY; + + int xpos,ypos; + int width,height; + + bool widgetWithinBounds = FALSE; + + int needsRefresh = 0; + + wxClientDC dc(handlerDialog); + + // Determine what widgets which fall within the bounding box + // and select them + wxNode *node = handlerDialog->GetChildren().First(); + while (node) + { + widgetWithinBounds = FALSE; + wxWindow *win = (wxWindow *)node->Data(); + if (win->IsKindOf(CLASSINFO(wxControl))) + { + wxControl *item = (wxControl *)win; + wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); + + // Unselect all widgets that are currently selected + if (!(keys & wxKEY_SHIFT) && childHandler->IsSelected()) + { + needsRefresh ++; + OnItemSelect(item, FALSE); + childHandler->SelectItem(FALSE); + } + + // Get X,Y and WIDTH,HEIGHT of the widget to be able + // to determine if any portion of it is within the bounded + // area + childHandler->handlerControl->GetPosition(&xpos, &ypos); + childHandler->handlerControl->GetSize(&width, &height); + + // Check if the current widget is inside the rectangle + // that was just bounded + if (xpos >= upperLeftX && xpos <= lowerRightX) + { + if (ypos >= upperLeftY && ypos <= lowerRightY) + widgetWithinBounds = TRUE; + else if (ypos+height >= upperLeftY && ypos+height <= lowerRightY) + widgetWithinBounds = TRUE; + } + else if (xpos+width >= upperLeftX && xpos <= lowerRightX) + { + if (ypos >= upperLeftY && ypos <= lowerRightY) + widgetWithinBounds = TRUE; + else if (ypos+height >= upperLeftY && ypos+height <= lowerRightY) + widgetWithinBounds = TRUE; + } + + if (widgetWithinBounds) + { + childHandler->SelectItem(TRUE); + OnItemSelect(item, TRUE); + +// childHandler->DrawSelectionHandles(dc); + } + + } + node = node->Next(); + } + + OnDragContinue(FALSE, oldDragX, oldDragY, keys, dc, NULL); + OnDragEnd(x, y, keys, dc, NULL); + + if (needsRefresh > 0) + { + dc.Clear(); + handlerDialog->Refresh(); + } + + // Always paint, in case the bounding box overlapped with + // the handles of any selected widgets, that way when the + // bounding box is cleared, the handles don't get partially + // erased where the overlap occured + PaintSelectionHandles(dc); + + dragMode = wxDRAG_MODE_NONE; + checkTolerance = TRUE; + dragItem = NULL; + dragType = wxDRAG_TYPE_NONE; + } + else + OnLeftClick(x, y, keys); } else if (event.RightDown()) { @@ -420,6 +594,7 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve if (event.ShiftDown()) keys = keys | wxKEY_SHIFT; if (event.ControlDown()) keys = keys | wxKEY_CTRL; bool dragging = event.Dragging(); + if (dragging) { int dx = (int)abs((x - firstDragX)); @@ -624,6 +799,116 @@ void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC& dc) dc.EndDrawing(); } + + +void wxResourceEditorDialogHandler::DrawBoundingBox(wxDC& dc, int x, int y, int w, int h) +{ + dc.DrawRectangle(x, y, w, h); +} + + +void wxResourceEditorDialogHandler::OnDragBegin(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle) +{ +/* + dc.BeginDrawing(); + + dc.SetOptimization(FALSE); + + dc.SetLogicalFunction(wxINVERT); + + wxPen pen(wxColour(0, 0, 0), 1, wxDOT); + dc.SetPen(pen); + dc.SetBrush(* wxTRANSPARENT_BRUSH); + + dc.SetOptimization(TRUE); + +// Refresh(); +// DrawBoundingBox(dc, xpos, ypos, width, height); + + dc.EndDrawing(); +*/ +} //wxResourceEditorDialogHandler::OnDragBegin() + + +void wxResourceEditorDialogHandler::OnDragContinue(bool WXUNUSED(paintIt), int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle) +{ + int upperLeftX = (x < firstDragX) ? x : firstDragX; + int upperLeftY = (y < firstDragY) ? y : firstDragY; + int lowerRightX = (x > firstDragX) ? x : firstDragX; + int lowerRightY = (y > firstDragY) ? y : firstDragY; + + dc.BeginDrawing(); + dc.SetLogicalFunction(wxINVERT); + wxPen pen(wxColour(0, 0, 0), 1, wxDOT); + dc.SetPen(pen); + dc.SetBrush(* wxTRANSPARENT_BRUSH); + + DrawBoundingBox(dc, (int)upperLeftX, upperLeftY, + lowerRightX-upperLeftX, lowerRightY-upperLeftY); + + dc.EndDrawing(); + +} // wxResourceEditorDialogHandler::OnDragContinue() + + +void wxResourceEditorDialogHandler::OnDragEnd(int x, int y, int WXUNUSED(keys), wxDC& dc, int selectionHandle) +{ +/* + dc.BeginDrawing(); + + dc.SetOptimization(FALSE); + + dc.SetLogicalFunction(wxCOPY); + dc.SetPen(* wxBLACK_PEN); + dc.SetBrush(* wxBLACK_BRUSH); + + dc.SetOptimization(TRUE); + + dc.EndDrawing(); +*/ + +} // wxResourceEditorDialogHandler::OnDragEnd() + +void wxResourceEditorDialogHandler::OnObjectEdit(wxCommandEvent& event) +{ + wxMenu* menu = (wxMenu*) event.GetEventObject(); + + wxWindow *data = (wxWindow *)menu->GetClientData(); + if (!data) + return; + + wxResourceManager::GetCurrentResourceManager()->EditWindow(data); +} + +void wxResourceEditorDialogHandler::OnObjectDelete(wxCommandEvent& event) +{ + wxMenu* menu = (wxMenu*) event.GetEventObject(); + + wxWindow *data = (wxWindow *)menu->GetClientData(); + if (!data) + return; + + // Before deleting a dialog, give the user a last chance + // change their mind, in case they accidentally right + // clicked the dialog rather than the widget they were + // aiming for. + if (data->IsKindOf(CLASSINFO(wxPanel))) + { + wxString str(wxT("Deleting dialog : ")); + str += data->GetName(); + if (wxMessageBox(wxT("Are you sure?"), str, wxYES_NO | wxCENTRE) == wxNO) + return; + } + + wxResourceManager::GetCurrentResourceManager()->DeselectItemIfNecessary(data); + + wxResourceManager::GetCurrentResourceManager()->SaveInfoAndDeleteHandler(data); + wxResourceManager::GetCurrentResourceManager()->DeleteResource(data); + wxResourceManager::GetCurrentResourceManager()->DeleteWindow(data); +} + + + /* * Event handler for controls */