diff --git a/src/mred/wxs/wxs_win.cxx b/src/mred/wxs/wxs_win.cxx index 900b456e8d..3df067381a 100644 --- a/src/mred/wxs/wxs_win.cxx +++ b/src/mred/wxs/wxs_win.cxx @@ -113,6 +113,15 @@ static long wxWindowGetHandle(wxWindow *w) #endif } +static void CenterWParent(wxWindow *w, int direction, wxWindow *parent) +{ +#ifdef wx_mac + w->Centre(direction, parent); +#else + w->Centre(direction); +#endif +} + static Scheme_Object *sizeMode_wxSIZE_AUTO_sym = NULL; static Scheme_Object *sizeMode_wxSIZE_USE_EXISTING_sym = NULL; static Scheme_Object *sizeMode_wxPOS_USE_MINUS_ONE_sym = NULL; @@ -803,24 +812,30 @@ static Scheme_Object *os_wxWindowPopupMenu(int n, Scheme_Object *p[]) return scheme_void; } -static Scheme_Object *os_wxWindowCenter(int n, Scheme_Object *p[]) +static Scheme_Object *os_wxWindowCenterWParent(int n, Scheme_Object *p[]) { WXS_USE_ARGUMENT(n) WXS_USE_ARGUMENT(p) REMEMBER_VAR_STACK(); objscheme_check_valid(os_wxWindow_class, "center in window%", n, p); int x0; + class wxWindow* x1 INIT_NULLED_OUT; - SETUP_VAR_STACK_REMEMBERED(1); + SETUP_VAR_STACK_REMEMBERED(2); VAR_STACK_PUSH(0, p); + VAR_STACK_PUSH(1, x1); if (n > (POFFSET+0)) { x0 = WITH_VAR_STACK(unbundle_symset_direction(p[POFFSET+0], "center in window%")); } else x0 = wxBOTH; + if (n > (POFFSET+1)) { + x1 = WITH_VAR_STACK(objscheme_unbundle_wxWindow(p[POFFSET+1], "center in window%", 1)); + } else + x1 = NULL; - WITH_VAR_STACK(((wxWindow *)((Scheme_Class_Object *)p[0])->primdata)->Center(x0)); + WITH_VAR_STACK(CenterWParent(((wxWindow *)((Scheme_Class_Object *)p[0])->primdata), x0, x1)); @@ -1369,7 +1384,7 @@ void objscheme_setup_wxWindow(Scheme_Env *env) WITH_VAR_STACK(scheme_add_method_w_arity(os_wxWindow_class, "get-width" " method", (Scheme_Method_Prim *)os_wxWindowwxSchemeWindowGetWidth, 0, 0)); WITH_VAR_STACK(scheme_add_method_w_arity(os_wxWindow_class, "get-height" " method", (Scheme_Method_Prim *)os_wxWindowwxSchemeWindowGetHeight, 0, 0)); WITH_VAR_STACK(scheme_add_method_w_arity(os_wxWindow_class, "popup-menu" " method", (Scheme_Method_Prim *)os_wxWindowPopupMenu, 3, 3)); - WITH_VAR_STACK(scheme_add_method_w_arity(os_wxWindow_class, "center" " method", (Scheme_Method_Prim *)os_wxWindowCenter, 0, 1)); + WITH_VAR_STACK(scheme_add_method_w_arity(os_wxWindow_class, "center" " method", (Scheme_Method_Prim *)os_wxWindowCenterWParent, 0, 2)); WITH_VAR_STACK(scheme_add_method_w_arity(os_wxWindow_class, "get-text-extent" " method", (Scheme_Method_Prim *)os_wxWindowGetTextExtent, 3, 7)); WITH_VAR_STACK(scheme_add_method_w_arity(os_wxWindow_class, "get-parent" " method", (Scheme_Method_Prim *)os_wxWindowGetParent, 0, 0)); WITH_VAR_STACK(scheme_add_method_w_arity(os_wxWindow_class, "refresh" " method", (Scheme_Method_Prim *)os_wxWindowRefresh, 0, 0)); diff --git a/src/mred/wxs/wxs_win.h b/src/mred/wxs/wxs_win.h index 362223f787..cdeebf0d69 100644 --- a/src/mred/wxs/wxs_win.h +++ b/src/mred/wxs/wxs_win.h @@ -8,6 +8,7 @@ extern class wxMouseEvent *objscheme_unbundle_wxMouseEvent(Scheme_Object *, cons extern class wxWindow *objscheme_unbundle_wxWindow(Scheme_Object *, const char *, int); extern class wxKeyEvent *objscheme_unbundle_wxKeyEvent(Scheme_Object *, const char *, int); extern class wxMenu *objscheme_unbundle_wxMenu(Scheme_Object *, const char *, int); +extern class wxWindow *objscheme_unbundle_wxWindow(Scheme_Object *, const char *, int); extern class wxFont *objscheme_unbundle_wxFont(Scheme_Object *, const char *, int); extern Scheme_Object *objscheme_bundle_wxWindow(class wxWindow *); extern class wxCursor *objscheme_unbundle_wxCursor(Scheme_Object *, const char *, int); diff --git a/src/mred/wxs/wxs_win.xc b/src/mred/wxs/wxs_win.xc index 02015e998d..73e86d7af7 100644 --- a/src/mred/wxs/wxs_win.xc +++ b/src/mred/wxs/wxs_win.xc @@ -87,6 +87,15 @@ static long wxWindowGetHandle(wxWindow *w) #endif } +static void CenterWParent(wxWindow *w, int direction, wxWindow *parent) +{ +#ifdef wx_mac + w->Centre(direction, parent); +#else + w->Centre(direction); +#endif +} + @BEGINSYMBOLS sizeMode > ONE > PRED BUNDLE @SYM "auto" : wxSIZE_AUTO @SYM "use-exsiting" : wxSIZE_USE_EXISTING @@ -128,7 +137,7 @@ static long wxWindowGetHandle(wxWindow *w) @ "refresh" : void Refresh(); @ "get-parent" : wxWindow^ GetParent(); @ "get-text-extent" : void GetTextExtent(string,double*,double*,double?=NULL,double?=NULL,wxFont^=NULL,bool=FALSE); -@ "center" : void Center(SYM[direction]=wxBOTH); +@ m "center" : void CenterWParent(SYM[direction]=wxBOTH, wxWindow^=NULL); @ "popup-menu" : void PopupMenu(wxMenu!, rint[0|10000], rint[0|10000]); diff --git a/src/wxmac/include/base/wb_dialg.h b/src/wxmac/include/base/wb_dialg.h index f6772878ad..122b615352 100644 --- a/src/wxmac/include/base/wb_dialg.h +++ b/src/wxmac/include/base/wb_dialg.h @@ -38,7 +38,7 @@ class wxbDialogBox: public wxFrame virtual void Iconize(Bool iconize) = 0; virtual Bool Iconized(void) = 0; - void Centre(int direction = wxBOTH); + void Centre(int direction = wxBOTH, wxWindow *parent = NULL); }; #define wxOPEN 1 diff --git a/src/wxmac/include/base/wb_frame.h b/src/wxmac/include/base/wb_frame.h index 8330b1823f..6114d5cdd0 100644 --- a/src/wxmac/include/base/wb_frame.h +++ b/src/wxmac/include/base/wb_frame.h @@ -75,7 +75,7 @@ class wxbFrame: public wxWindow virtual void SetStatusText(char *text, int number = 0) = 0; virtual Bool StatusLineExists(void); - void Centre(int direction = wxBOTH); + void Centre(int direction = wxBOTH, wxWindow *parent = NULL); // Iconize virtual void Iconize(Bool iconize) = 0; diff --git a/src/wxmac/include/base/wb_item.h b/src/wxmac/include/base/wb_item.h index a5443c8412..1787d85941 100644 --- a/src/wxmac/include/base/wb_item.h +++ b/src/wxmac/include/base/wb_item.h @@ -48,7 +48,7 @@ class wxbItem: public wxWindow virtual void ProcessCommand(wxCommandEvent *event); // Calls the callback and // Places item in centre of panel - so can't be used BEFORE panel->Fit() - void Centre(int direction = wxHORIZONTAL); + void Centre(int direction = wxHORIZONTAL, wxWindow *p = NULL); }; #endif // IN_CPROTO diff --git a/src/wxmac/include/base/wb_win.h b/src/wxmac/include/base/wb_win.h index cabce41ba3..3605c244d5 100644 --- a/src/wxmac/include/base/wb_win.h +++ b/src/wxmac/include/base/wb_win.h @@ -126,13 +126,10 @@ class wxbWindow: public wxObject virtual void SetName(char *name); inline virtual void Fit(void) {}; // Size window to fit contents - inline virtual void Centre(int direction) {}; // Centre item on panel, - // or frame on screen + inline virtual void Centre(int direction = wxBOTH, wxWindow *parent = NULL) {}; // Renamed from GetWindowStyle since it clashed with a // macro in windowsx.h. inline long GetWindowStyleFlag(void) { return windowStyle; } - // A concession to our friends across the pond - inline void Center(int direction = wxHORIZONTAL) { Centre(direction); } inline virtual void EnablePainting(Bool enable) { paintingEnabled = enable; } diff --git a/src/wxmac/include/mac/wx_dialg.h b/src/wxmac/include/mac/wx_dialg.h index bf34dfcd07..6d83ca510c 100644 --- a/src/wxmac/include/mac/wx_dialg.h +++ b/src/wxmac/include/mac/wx_dialg.h @@ -65,7 +65,7 @@ public: Bool OnClose(void); virtual void Fit(void); - virtual void Centre(int d) { cFrame->Centre(d); } + virtual void Centre(int d = wxBOTH, wxWindow *p = NULL) { cFrame->Centre(d, p); } void SetIcon(wxBitmap* icon) { cFrame->SetIcon(icon); } void Iconize(Bool iconize) { cFrame->Iconize(iconize); } diff --git a/src/wxmac/include/mac/wx_panel.h b/src/wxmac/include/mac/wx_panel.h index c31469c9bb..2e8a1cbffe 100644 --- a/src/wxmac/include/mac/wx_panel.h +++ b/src/wxmac/include/mac/wx_panel.h @@ -116,7 +116,7 @@ public: // Sizing methods //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ void DoSetSize(int x, int y, int width, int height); - void Centre(int direction); + void Centre(int direction = wxBOTH, wxWindow *p = NULL); void Fit(void); //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/src/wxmac/src/base/wb_dialg.cc b/src/wxmac/src/base/wb_dialg.cc index 9afaeaa350..882eaf0b95 100644 --- a/src/wxmac/src/base/wb_dialg.cc +++ b/src/wxmac/src/base/wb_dialg.cc @@ -84,8 +84,8 @@ wxbDialogBox::~wxbDialogBox() tlw->DeleteObject(this); } -void wxbDialogBox::Centre(int direction) +void wxbDialogBox::Centre(int direction, wxWindow *p) { - ((wxDialogBox *)this)->cFrame->Centre(direction); + ((wxDialogBox *)this)->cFrame->Centre(direction, p); } diff --git a/src/wxmac/src/base/wb_frame.cc b/src/wxmac/src/base/wb_frame.cc index 2f5ee9ac78..5b48c66421 100644 --- a/src/wxmac/src/base/wb_frame.cc +++ b/src/wxmac/src/base/wb_frame.cc @@ -133,20 +133,27 @@ Bool wxbFrame::StatusLineExists(void) return status_line_exists; } -void wxbFrame::Centre(int direction) +void wxbFrame::Centre(int direction, wxWindow *parent) { - int display_width, display_height, width, height, x, y; - wxDisplaySize(&display_width, &display_height); + int display_width, display_height, width, height, x, y, offset_x, offset_y; + + if (parent) { + parent->GetSize(&display_width, &display_height); + parent->GetPosition(&offset_x, &offset_y); + } else { + wxDisplaySize(&display_width, &display_height); + offset_x = offset_y = 0; + } GetSize(&width, &height); GetPosition(&x, &y); - + if (direction & wxHORIZONTAL) x = (int)((display_width - width)/2); if (direction & wxVERTICAL) y = (int)((display_height - height)/2); - - SetSize(x, y, width, height, wxPOS_USE_MINUS_ONE); + + SetSize(x + offset_x, y + offset_y, width, height, wxPOS_USE_MINUS_ONE); } // Call this to simulate a menu command diff --git a/src/wxmac/src/base/wb_item.cc b/src/wxmac/src/base/wb_item.cc index 9acdfc88dc..8075d80941 100644 --- a/src/wxmac/src/base/wb_item.cc +++ b/src/wxmac/src/base/wb_item.cc @@ -170,7 +170,7 @@ wxbItem::~wxbItem (void) } } -void wxbItem::Centre (int direction) +void wxbItem::Centre (int direction, wxWindow *) { int x, y, width, height, panel_width, panel_height, new_x, new_y; wxPanel *panel; diff --git a/src/wxmac/src/mac/wx_dialg.cc b/src/wxmac/src/mac/wx_dialg.cc index b38f413d9b..0a6e5bafe2 100644 --- a/src/wxmac/src/mac/wx_dialg.cc +++ b/src/wxmac/src/mac/wx_dialg.cc @@ -180,7 +180,7 @@ static wxFrame *make_dlog_frame(wxWindow *parentFrame, char *windowTitle, int x, //----------------------------------------------------------------------------- wxDialogBox::wxDialogBox // Constructor (for dialog window) ( - wxWindow* parentFrame, // this is ignored, used to be wxFrame* + wxWindow* parentFrame, char* windowTitle, Bool modal, int x, diff --git a/src/wxmac/src/mac/wx_frame.cc b/src/wxmac/src/mac/wx_frame.cc index 44a451577b..2a796e2367 100644 --- a/src/wxmac/src/mac/wx_frame.cc +++ b/src/wxmac/src/mac/wx_frame.cc @@ -60,7 +60,7 @@ static ControlUserPaneDrawUPP userPaneDrawFunctionUPP = NewControlUserPaneDrawUP //----------------------------------------------------------------------------- wxFrame::wxFrame // Constructor (for frame window) ( - wxFrame* parentFrame, // this is ignored + wxFrame* parentFrame, char* windowTitle, int x, int y, diff --git a/src/wxmac/src/mac/wx_panel.cc b/src/wxmac/src/mac/wx_panel.cc index faeb5444ea..9ce6bc575c 100644 --- a/src/wxmac/src/mac/wx_panel.cc +++ b/src/wxmac/src/mac/wx_panel.cc @@ -264,7 +264,7 @@ void wxPanel::DoSetSize(int x, int y, int width, int height) //----------------------------------------------------------------------------- -void wxPanel::Centre(int direction) +void wxPanel::Centre(int direction, wxWindow *) { int width, height, panel_width, panel_height, new_x, new_y; wxPanel* father;