From: Robin Dunn Date: Fri, 5 Nov 1999 06:56:53 +0000 (+0000) Subject: Change a Popup menu from using a callback to using events. Can't test X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/20f2deb3cf287fd2857940cba0d5efbcfc3bb0ad Change a Popup menu from using a callback to using events. Can't test it right now but it compiles. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4365 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/utils/ogl/src/composit.cpp b/utils/ogl/src/composit.cpp index f8161b4153..a6f0ba5aaf 100644 --- a/utils/ogl/src/composit.cpp +++ b/utils/ogl/src/composit.cpp @@ -37,8 +37,6 @@ // construct themselves. wxExprDatabase *GlobalwxExprDatabase = NULL; -// Popup menu for editing divisions -wxMenu *oglPopupDivisionMenu = NULL; /* * Division control point @@ -1572,10 +1570,32 @@ bool wxDivisionShape::ResizeAdjoining(int side, double newPos, bool test) * Popup menu for editing divisions * */ +class OGLPopupDivisionMenu : public wxMenu { +public: + OGLPopupDivisionMenu() : wxMenu() { + Append(DIVISION_MENU_SPLIT_HORIZONTALLY, "Split horizontally"); + Append(DIVISION_MENU_SPLIT_VERTICALLY, "Split vertically"); + AppendSeparator(); + Append(DIVISION_MENU_EDIT_LEFT_EDGE, "Edit left edge"); + Append(DIVISION_MENU_EDIT_TOP_EDGE, "Edit top edge"); + } + + void OnMenu(wxCommandEvent& event); + + DECLARE_EVENT_TABLE(); +}; -void oglGraphicsDivisionMenuProc(wxMenu& menu, wxCommandEvent& event) +BEGIN_EVENT_TABLE(OGLPopupDivisionMenu, wxMenu) + EVT_CUSTOM_RANGE(wxEVT_COMMAND_MENU_SELECTED, + DIVISION_MENU_SPLIT_HORIZONTALLY, + DIVISION_MENU_EDIT_BOTTOM_EDGE, + OGLPopupDivisionMenu::OnMenu) +END_EVENT_TABLE() + + +void OGLPopupDivisionMenu::OnMenu(wxCommandEvent& event) { - wxDivisionShape *division = (wxDivisionShape *)menu.GetClientData(); + wxDivisionShape *division = (wxDivisionShape *)GetClientData(); switch (event.GetInt()) { case DIVISION_MENU_SPLIT_HORIZONTALLY: @@ -1714,6 +1734,8 @@ void wxDivisionShape::EditEdge(int side) // Popup menu void wxDivisionShape::PopupMenu(double x, double y) { + wxMenu* oglPopupDivisionMenu = new OGLPopupDivisionMenu; + oglPopupDivisionMenu->SetClientData((void *)this); if (m_leftSide) oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_LEFT_EDGE, TRUE); @@ -1737,6 +1759,7 @@ void wxDivisionShape::PopupMenu(double x, double y) int mouse_y = (int)(dc.LogicalToDeviceY((long)(y - y1*unit_y))); m_canvas->PopupMenu(oglPopupDivisionMenu, mouse_x, mouse_y); + delete oglPopupDivisionMenu; } void wxDivisionShape::SetLeftSideColour(const wxString& colour) diff --git a/utils/ogl/src/composit.h b/utils/ogl/src/composit.h index 505667c2bd..bbbcc835d3 100644 --- a/utils/ogl/src/composit.h +++ b/utils/ogl/src/composit.h @@ -225,8 +225,6 @@ class wxDivisionShape: public wxCompositeShape wxString m_topSideStyle; }; -extern wxMenu *oglPopupDivisionMenu; -extern void oglGraphicsDivisionMenuProc(wxMenu& menu, wxCommandEvent& event); #define DIVISION_MENU_SPLIT_HORIZONTALLY 1 #define DIVISION_MENU_SPLIT_VERTICALLY 2 diff --git a/utils/ogl/src/misc.cpp b/utils/ogl/src/misc.cpp index 50ed2669dc..7e0ecae5fc 100644 --- a/utils/ogl/src/misc.cpp +++ b/utils/ogl/src/misc.cpp @@ -55,6 +55,8 @@ char* oglBuffer = NULL; wxList oglObjectCopyMapping(wxKEY_INTEGER); + + void wxOGLInitialize() { g_oglBullseyeCursor = new wxCursor(wxCURSOR_BULLSEYE); @@ -73,15 +75,6 @@ void wxOGLInitialize() // Initialize big buffer used when writing images oglBuffer = new char[3000]; - if (!oglPopupDivisionMenu) - { - oglPopupDivisionMenu = new wxMenu("", (wxFunction)oglGraphicsDivisionMenuProc); - oglPopupDivisionMenu->Append(DIVISION_MENU_SPLIT_HORIZONTALLY, "Split horizontally"); - oglPopupDivisionMenu->Append(DIVISION_MENU_SPLIT_VERTICALLY, "Split vertically"); - oglPopupDivisionMenu->AppendSeparator(); - oglPopupDivisionMenu->Append(DIVISION_MENU_EDIT_LEFT_EDGE, "Edit left edge"); - oglPopupDivisionMenu->Append(DIVISION_MENU_EDIT_TOP_EDGE, "Edit top edge"); - } } void wxOGLCleanUp() @@ -92,11 +85,6 @@ void wxOGLCleanUp() oglBuffer = NULL; } oglBuffer = NULL; - if (oglPopupDivisionMenu) - { - delete oglPopupDivisionMenu; - oglPopupDivisionMenu = NULL; - } if (g_oglBullseyeCursor) { delete g_oglBullseyeCursor; @@ -190,7 +178,7 @@ int FontSizeDialog(wxFrame *parent, int old_size) return 0; } return new_size; -/* +/* char *strings[8]; strings[0] = "4"; strings[1] = "6"; @@ -563,7 +551,7 @@ void oglFindPolylineCentroid(wxList *points, double *x, double *y) * Used by functions below. * */ -void oglCheckLineIntersection(double x1, double y1, double x2, double y2, +void oglCheckLineIntersection(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, double *ratio1, double *ratio2) { @@ -583,7 +571,7 @@ void oglCheckLineIntersection(double x1, double y1, double x2, double y2, // Check for intersection if ((line_constant < 1.0) && (line_constant > 0.0)) { - // Now must check that other line hits + // Now must check that other line hits if (((y4 - y3) < 0.005) && ((y4 - y3) > -0.005)) k_line = ((x1 - x3) + line_constant*(x2 - x1))/(x4 - x3); else @@ -603,7 +591,7 @@ void oglCheckLineIntersection(double x1, double y1, double x2, double y2, * (*x3, *y3) is the point where it hits. * */ -void oglFindEndForPolyline(double n, double xvec[], double yvec[], +void oglFindEndForPolyline(double n, double xvec[], double yvec[], double x1, double y1, double x2, double y2, double *x3, double *y3) { int i; @@ -645,7 +633,7 @@ void oglFindEndForPolyline(double n, double xvec[], double yvec[], * */ -void oglFindEndForBox(double width, double height, +void oglFindEndForBox(double width, double height, double x1, double y1, // Centre of box (possibly) double x2, double y2, // other end of line double *x3, double *y3) // End on box edge @@ -672,7 +660,7 @@ void oglFindEndForBox(double width, double height, * */ -void oglFindEndForCircle(double radius, +void oglFindEndForCircle(double radius, double x1, double y1, // Centre of circle double x2, double y2, // Other end of line double *x3, double *y3) @@ -729,7 +717,7 @@ void oglGetArrowPoints(double x1, double y1, double x2, double y2, * This function assumes that the centre of the ellipse is at x1, y1, and the * ellipse has a width of width1 and a height of height1. It also assumes you are * wanting to draw an arc FROM point x2, y2 TOWARDS point x3, y3. - * This function calculates the x,y coordinates of the intersection point of + * This function calculates the x,y coordinates of the intersection point of * the arc with the ellipse. * Author: Ian Harrison */ @@ -754,7 +742,7 @@ void oglDrawArcToEllipse(double x1, double y1, double width1, double height1, do *y4 = (double)(y1 + b1); return; } -*/ +*/ // Check that x2 != x3 if (fabs(x2 - x3) < 0.05) { @@ -783,7 +771,7 @@ void oglDrawArcToEllipse(double x1, double y1, double width1, double height1, do if (K >= 0) // In this case the line intersects the ellipse, so calculate intersection - { + { if(x2 >= x1) { ellipse1_x = (double)(((F * -1) + sqrt(K)) / (2 * E)); @@ -804,7 +792,7 @@ void oglDrawArcToEllipse(double x1, double y1, double width1, double height1, do *x4 = ellipse1_x; *y4 = ellipse1_y; -/* +/* // Draw a little circle (radius = 2) at the end of the arc where it hits // the ellipse . @@ -848,7 +836,7 @@ static char sg_HexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', unsigned int oglHexToDec(char* buf) { int firstDigit, secondDigit; - + if (buf[0] >= 'A') firstDigit = buf[0] - 'A' + 10; else @@ -858,7 +846,7 @@ unsigned int oglHexToDec(char* buf) secondDigit = buf[1] - 'A' + 10; else secondDigit = buf[1] - '0'; - + return firstDigit * 16 + secondDigit; }