X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/203feea88869a178e17080d37eea5e0789fa9209..2224580a415da12d7c453943c4ae4a1b58ecd369:/utils/dialoged/src/dlghndlr.cpp diff --git a/utils/dialoged/src/dlghndlr.cpp b/utils/dialoged/src/dlghndlr.cpp index b63762d66d..721af4b4b0 100644 --- a/utils/dialoged/src/dlghndlr.cpp +++ b/utils/dialoged/src/dlghndlr.cpp @@ -29,16 +29,6 @@ #include #include -#if wxUSE_IOSTREAMH -#if defined(__WXMSW__) && !defined(__GNUWIN32__) -#include -#else -#include -#endif -#else -#include -#endif - #include "reseditr.h" #include "winprop.h" #include "dlghndlr.h" @@ -104,7 +94,7 @@ void wxResourceEditorDialogHandler::OnPaint(wxPaintEvent& WXUNUSED(event)) // Add event handlers for all children void wxResourceEditorDialogHandler::AddChildHandlers(void) { - wxNode *node = handlerDialog->GetChildren()->First(); + wxNode *node = handlerDialog->GetChildren().First(); while ( node ) { wxControl *child = (wxControl *)node->Data(); @@ -127,7 +117,7 @@ void wxResourceEditorDialogHandler::OnLeftClick(int x, int y, int keys) if (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection() == RESED_POINTER) { int needsRefresh = 0; - wxNode *node = handlerDialog->GetChildren()->First(); + wxNode *node = handlerDialog->GetChildren().First(); while (node) { wxControl *item = (wxControl *)node->Data(); @@ -149,6 +139,20 @@ 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) + { + wxPoint pt = handlerDialog->ConvertPixelsToDialog(wxPoint(x, y)); + + // Convert back so we've rounded down + pt = handlerDialog->ConvertDialogToPixels(pt); + pt = handlerDialog->ConvertPixelsToDialog(pt); + pt = handlerDialog->ConvertDialogToPixels(pt); + x = pt.x; + y = pt.y; + } + switch (wxResourceManager::GetCurrentResourceManager()->GetEditorControlList()->GetSelection()) { case RESED_BUTTON: @@ -256,7 +260,7 @@ void wxResourceEditorDialogHandler::OnItemLeftClick(wxControl *item, int WXUNUSE int needsRefresh = 0; if (!(keys & wxKEY_SHIFT)) { - wxNode *node = item->GetParent()->GetChildren()->First(); + wxNode *node = item->GetParent()->GetChildren().First(); while (node) { wxControl *child = (wxControl *)node->Data(); @@ -327,11 +331,11 @@ void wxResourceEditorDialogHandler::OnMouseEvent(wxMouseEvent& event) return; } - long x, y; - event.Position(&x, &y); + wxCoord x, y; + event.GetPosition(&x, &y); // Find which selection handle we're on, if any - wxNode *node = handlerDialog->GetChildren()->First(); + wxNode *node = handlerDialog->GetChildren().First(); while (node) { wxWindow *win = (wxWindow *)node->Data(); @@ -397,7 +401,7 @@ void wxResourceEditorDialogHandler::OnItemEvent(wxControl *item, wxMouseEvent& e // Not a selection handle event: just a normal item event. // Transform to panel coordinates. - int x, y; + wxCoord x, y; item->GetPosition(&x, &y); event.m_x = event.m_x + x; @@ -410,8 +414,8 @@ void wxResourceEditorDialogHandler::ProcessItemEvent(wxControl *item, wxMouseEve { wxResourceEditorControlHandler *childHandler = (wxResourceEditorControlHandler *)item->GetEventHandler(); - long x, y; - event.Position(&x, &y); + wxCoord x, y; + event.GetPosition(&x, &y); int keys = 0; if (event.ShiftDown()) keys = keys | wxKEY_SHIFT; if (event.ControlDown()) keys = keys | wxKEY_CTRL; @@ -601,7 +605,7 @@ void wxResourceEditorDialogHandler::PaintSelectionHandles(wxDC& dc) dc.BeginDrawing(); - wxNode *node = handlerDialog->GetChildren()->First(); + wxNode *node = handlerDialog->GetChildren().First(); while (node) { wxWindow *win = (wxWindow *)node->Data(); @@ -730,8 +734,8 @@ void wxResourceEditorControlHandler::DrawSelectionHandles(wxDC& dc, bool WXUNUSE dc.SetOptimization(FALSE); dc.SetLogicalFunction(wxCOPY); - dc.SetPen(wxBLACK_PEN); - dc.SetBrush(wxBLACK_BRUSH); + dc.SetPen(* wxBLACK_PEN); + dc.SetBrush(* wxBLACK_BRUSH); dc.SetOptimization(TRUE); @@ -770,11 +774,11 @@ void wxResourceEditorControlHandler::OnDragBegin(int x, int y, int WXUNUSED(keys dc.SetOptimization(FALSE); - dc.SetLogicalFunction(wxXOR); + dc.SetLogicalFunction(wxINVERT); wxPen pen(wxColour(0, 0, 0), 1, wxDOT); dc.SetPen(pen); - dc.SetBrush(wxTRANSPARENT_BRUSH); + dc.SetBrush(* wxTRANSPARENT_BRUSH); dc.SetOptimization(TRUE); @@ -794,7 +798,7 @@ void wxResourceEditorControlHandler::OnDragBegin(int x, int y, int WXUNUSED(keys DrawBoundingBox(dc, xpos, ypos, width, height); // Also draw bounding boxes for other selected items - wxNode *node = panel->GetChildren()->First(); + wxNode *node = panel->GetChildren().First(); while (node) { wxWindow *win = (wxWindow *)node->Data(); @@ -888,10 +892,10 @@ void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt), int } dc.BeginDrawing(); - dc.SetLogicalFunction(wxXOR); + dc.SetLogicalFunction(wxINVERT); wxPen pen(wxColour(0, 0, 0), 1, wxDOT); dc.SetPen(pen); - dc.SetBrush(wxTRANSPARENT_BRUSH); + dc.SetBrush(* wxTRANSPARENT_BRUSH); DrawBoundingBox(dc, x1, y1, width1, height1); @@ -900,15 +904,15 @@ void wxResourceEditorControlHandler::OnDragContinue(bool WXUNUSED(paintIt), int else { dc.BeginDrawing(); - dc.SetLogicalFunction(wxXOR); + dc.SetLogicalFunction(wxINVERT); wxPen pen(wxColour(0, 0, 0), 1, wxDOT); dc.SetPen(pen); - dc.SetBrush(wxTRANSPARENT_BRUSH); + dc.SetBrush(* wxTRANSPARENT_BRUSH); DrawBoundingBox(dc, (int)(x - dragOffsetX), (int)(y - dragOffsetY), width, height); // Also draw bounding boxes for other selected items - wxNode *node = panel->GetChildren()->First(); + wxNode *node = panel->GetChildren().First(); while (node) { wxWindow *win = (wxWindow *)node->Data(); @@ -1000,37 +1004,69 @@ void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys), height1 = (ypos + height) - y; break; } - handlerControl->SetSize(x1, y1, width1, height1); - - // Also update the associated resource + // Update the associated resource // We need to convert to dialog units if this is not a dialog or panel, but // the parent resource specifies dialog units. + int resourceX = x1; + int resourceY = y1; + int resourceWidth = width1; + int resourceHeight = height1; + if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) { wxPoint pt = handlerControl->GetParent()->ConvertPixelsToDialog(wxPoint(x1, y1)); - x1 = pt.x; y1 = pt.y; wxSize sz = handlerControl->GetParent()->ConvertPixelsToDialog(wxSize(width1, height1)); - width1 = sz.x; height1 = sz.y; + + // Convert back so we've rounded down + sz = handlerControl->GetParent()->ConvertDialogToPixels(sz); + sz = handlerControl->GetParent()->ConvertPixelsToDialog(sz); + resourceWidth = sz.x; resourceHeight = sz.y; + + sz = handlerControl->GetParent()->ConvertDialogToPixels(sz); + width1 = sz.x; + height1 = sz.y; + + pt = handlerControl->GetParent()->ConvertDialogToPixels(pt); + pt = handlerControl->GetParent()->ConvertPixelsToDialog(pt); + resourceX = pt.x; resourceY = pt.y; + + pt = handlerControl->GetParent()->ConvertDialogToPixels(pt); + x1 = pt.x; + y1 = pt.y; } - resource->SetSize(x1, y1, width1, height1); + handlerControl->SetSize(x1, y1, width1, height1); + resource->SetSize(resourceX, resourceY, resourceWidth, resourceHeight); } else { + // Correction 31/12/98. We need to round down the values to take into account + // the fact that several pixels map to the same dialog unit. + int newX = (int)(x - dragOffsetX); int newY = (int)(y - dragOffsetY); - handlerControl->Move(newX, newY); - OldOnMove(newX, newY); + int resourceX = newX; + int resourceY = newY; - // Also update the associated resource + // Update the associated resource if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) { wxPoint pt = handlerControl->GetParent()->ConvertPixelsToDialog(wxPoint(newX, newY)); - newX = pt.x; newY = pt.y; + pt = handlerControl->GetParent()->ConvertDialogToPixels(pt); + pt = handlerControl->GetParent()->ConvertPixelsToDialog(pt); + resourceX = pt.x; resourceY = pt.y; + pt = handlerControl->GetParent()->ConvertDialogToPixels(pt); + + // Having converted it several times, we know it'll map to dialog units exactly. + newX = pt.x; + newY = pt.y; } - resource->SetSize(newX, newY, resource->GetWidth(), resource->GetHeight()); + handlerControl->Move(newX, newY); + OldOnMove(newX, newY); + + resource->SetSize(resourceX, resourceY, resource->GetWidth(), resource->GetHeight()); // Also move other selected items - wxNode *node = panel->GetChildren()->First(); + wxNode *node = panel->GetChildren().First(); while (node) { wxWindow *win = (wxWindow *)node->Data(); @@ -1044,18 +1080,28 @@ void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys), item->GetPosition(&x1, &y1); int x2 = (int)(x1 + (x - dragOffsetX) - xpos); int y2 = (int)(y1 + (y - dragOffsetY) - ypos); - item->Move(x2, y2); - ((wxResourceEditorControlHandler *)item->GetEventHandler())->OldOnMove(x2, y2); - ((wxResourceEditorControlHandler *)item->GetEventHandler())->DrawSelectionHandles(dc); - // Also update the associated resource + // Update the associated resource resource = wxResourceManager::GetCurrentResourceManager()->FindResourceForWindow(item); if (parentResource->GetResourceStyle() & wxRESOURCE_DIALOG_UNITS) { - wxPoint pt = item->GetParent()->ConvertPixelsToDialog(wxPoint(newX, newY)); - x2 = pt.x; y2 = pt.y; + wxPoint pt = item->GetParent()->ConvertPixelsToDialog(wxPoint(x2, y2)); + pt = item->GetParent()->ConvertDialogToPixels(pt); + pt = item->GetParent()->ConvertPixelsToDialog(pt); + + resourceX = pt.x; resourceY = pt.y; + pt = handlerControl->GetParent()->ConvertDialogToPixels(pt); + + // Having converted it several times, we know it'll map to dialog units exactly + x2 = pt.x; + y2 = pt.y; } - resource->SetSize(x2, y2, resource->GetWidth(), resource->GetHeight()); + + item->Move(x2, y2); + ((wxResourceEditorControlHandler *)item->GetEventHandler())->OldOnMove(x2, y2); + ((wxResourceEditorControlHandler *)item->GetEventHandler())->DrawSelectionHandles(dc); + + resource->SetSize(resourceX, resourceY, resource->GetWidth(), resource->GetHeight()); } } @@ -1065,8 +1111,8 @@ void wxResourceEditorControlHandler::OnDragEnd(int x, int y, int WXUNUSED(keys), dc.SetOptimization(FALSE); dc.SetLogicalFunction(wxCOPY); - dc.SetPen(wxBLACK_PEN); - dc.SetBrush(wxBLACK_BRUSH); + dc.SetPen(* wxBLACK_PEN); + dc.SetBrush(* wxBLACK_BRUSH); dc.SetOptimization(TRUE);