Index: ps/trunk/source/tools/atlas/wxJS/gui/control/window.cpp =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/window.cpp (revision 7257) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/window.cpp (revision 7258) @@ -1,2461 +1,2481 @@ #include "precompiled.h" /* * wxJavaScript - window.cpp * * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project * * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * $Id: window.cpp 810 2007-07-13 20:07:05Z fbraem $ */ // window.cpp #include +#include #include "../../common/main.h" #include "../../ext/wxjs_ext.h" #include "window.h" #include "../misc/size.h" #include "../misc/rect.h" #include "../misc/colour.h" #include "../misc/font.h" #include "../misc/sizer.h" #include "../misc/validate.h" #include "../misc/acctable.h" using namespace wxjs; using namespace wxjs::gui; /*** * control/window * gui * * wxWindow is the prototype of all objects based on wxWindow. * This means that you can use all properties and methods in all those objects. * */ WXJS_INIT_CLASS(Window, "wxWindow", 0) void Window::InitClass(JSContext* WXUNUSED(cx), JSObject* WXUNUSED(obj), JSObject* WXUNUSED(proto)) { WindowEventHandler::InitConnectEventMap(); } /*** * * * * Can this window have focus? * * * can this window be given focus by keyboard navigation? if not, the * only way to give it focus (provided it accepts it at all) is to * click it * * * Indicates whether the layout method must be called automatically or not when a window is resized. * See @wxSizer * * * Get/Set the background colour of the window * * * Gets the size best suited for the window * * * Gets a list of children * * * Get the origin of the client area of the window relative to the * window top left corner (the client area may be shifted because of * the borders, scrollbars, other decorations...) * * * Get/Set the client height. * * * Gets the rectangle of the client area * * * Get/Set the clientsize of the window. You can also use * @wxRect (only when setting) * * * Get/Set the client width. * * * Enables/Disables the window * * * Get/Set the extra window styles. * See @wxWindow#extraStyles * * * Get/Set the font. * * * Get/Set the foreground colour of the window * * * Returns true when this window has the capture. * Set to true to capture this window, or false to release the capture. * (not possible in wxWindows) * * * Get/Set the height. * * * Gets the unique id of the window, or -1 when it is not set. * * * Get/Set the parent * * * Get/Set the position. * * * Gets the window rectangle * * * Returns true when the window is visible * See @wxWindow#visible property, @wxWindow#show method * * * Get/Set the size of the window. You can also use * @wxRect (only when setting) * * * Get/Set the sizer of the window. Set @wxWindow#autoLayout to true when you * want that the sizer is automatically used when the size of the window is changed. * * * Returns true when the window is a top level window. * Currently all frames and dialogs are considered to be * top-level windows (even if they have a parent window). * * * Get/Set the validator of the window * * * Show/Hide the window. * * * Get/Set the window flag styles. * Please note that some styles cannot be changed after the window * creation and that @wxWindow#refresh might be called after changing * the others for the change to take place immediately. * See @wxWindow#styles * * */ WXJS_BEGIN_PROPERTY_MAP(Window) WXJS_PROPERTY(P_AUTO_LAYOUT, "autoLayout") WXJS_PROPERTY(P_CLIENT_HEIGHT, "clientHeight") WXJS_PROPERTY(P_CLIENT_WIDTH, "clientWidth") WXJS_READONLY_PROPERTY(P_CLIENT_ORIGIN, "clientAreaOrigin") WXJS_READONLY_PROPERTY(P_ACCEPTS_FOCUS, "acceptsFocus") WXJS_READONLY_PROPERTY(P_ACCEPTS_FOCUS_KEYBOARD, "acceptsFocusFromKeyboard") WXJS_PROPERTY(P_ENABLE, "enable") WXJS_PROPERTY(P_HEIGHT, "height") WXJS_PROPERTY(P_VISIBLE, "visible") WXJS_PROPERTY(P_WIDTH, "width") WXJS_PROPERTY(P_SIZE, "size") WXJS_PROPERTY(P_SIZER, "sizer") WXJS_PROPERTY(P_CLIENT_SIZE, "clientSize") WXJS_PROPERTY(P_POSITION, "position") WXJS_READONLY_PROPERTY(P_ID, "id") WXJS_READONLY_PROPERTY(P_RECT, "rect") WXJS_READONLY_PROPERTY(P_CLIENT_RECT, "clientRect") WXJS_READONLY_PROPERTY(P_BEST_SIZE, "bestSize") WXJS_PROPERTY(P_WINDOW_STYLE, "windowStyle") WXJS_PROPERTY(P_EXTRA_STYLE, "extraStyle") WXJS_READONLY_PROPERTY(P_SHOWN, "shown") WXJS_READONLY_PROPERTY(P_TOP_LEVEL, "topLevel") WXJS_READONLY_PROPERTY(P_CHILDREN, "children") WXJS_PROPERTY(P_PARENT, "parent") WXJS_PROPERTY(P_VALIDATOR, "validator") WXJS_PROPERTY(P_ACCELERATOR_TABLE, "acceleratorTable") WXJS_PROPERTY(P_HAS_CAPTURE, "hasCapture") WXJS_PROPERTY(P_BACKGROUND_COLOUR, "backgroundColour") WXJS_PROPERTY(P_FOREGROUND_COLOUR, "foregroundColour") WXJS_PROPERTY(P_FONT, "font") + WXJS_PROPERTY(P_TOOL_TIP, "toolTip") WXJS_END_PROPERTY_MAP() bool Window::GetProperty(wxWindow *p, JSContext *cx, JSObject *obj, int id, jsval *vp) { switch (id) { case P_VISIBLE: case P_SHOWN: *vp = ToJS(cx, p->IsShown()); break; case P_ENABLE: *vp = ToJS(cx, p->IsEnabled()); break; case P_SIZE: *vp = Size::CreateObject(cx, new wxSize(p->GetSize())); break; case P_CLIENT_SIZE: *vp = Size::CreateObject(cx, new wxSize(p->GetClientSize())); break; case P_WIDTH: *vp = ToJS(cx, p->GetSize().GetWidth()); break; case P_HEIGHT: *vp = ToJS(cx, p->GetSize().GetHeight()); break; case P_CLIENT_HEIGHT: *vp = ToJS(cx, p->GetClientSize().GetHeight()); break; case P_CLIENT_WIDTH: *vp = ToJS(cx, p->GetClientSize().GetHeight()); break; case P_POSITION: *vp = wxjs::ext::CreatePoint(cx, p->GetPosition()); break; case P_CLIENT_ORIGIN: *vp = wxjs::ext::CreatePoint(cx, p->GetClientAreaOrigin()); break; case P_SIZER: { wxSizer *sizer = p->GetSizer(); if ( sizer != NULL ) { JavaScriptClientData *data = dynamic_cast(sizer->GetClientObject()); if ( data != NULL ) { *vp = OBJECT_TO_JSVAL(data->GetObject()); } } break; } case P_AUTO_LAYOUT: *vp = ToJS(cx, p->GetAutoLayout()); break; case P_ID: *vp = ToJS(cx, p->GetId()); break; case P_RECT: *vp = Rect::CreateObject(cx, new wxRect(p->GetRect())); break; case P_CLIENT_RECT: *vp = Rect::CreateObject(cx, new wxRect(p->GetClientRect())); break; case P_BEST_SIZE: *vp = Size::CreateObject(cx, new wxSize(p->GetBestSize())); break; case P_WINDOW_STYLE: *vp = ToJS(cx, p->GetWindowStyle()); break; case P_EXTRA_STYLE: *vp = ToJS(cx, p->GetExtraStyle()); break; case P_TOP_LEVEL: *vp = ToJS(cx, p->IsTopLevel()); break; case P_ACCEPTS_FOCUS: *vp = ToJS(cx, p->AcceptsFocus()); break; case P_ACCEPTS_FOCUS_KEYBOARD: *vp = ToJS(cx, p->AcceptsFocusFromKeyboard()); break; case P_CHILDREN: { wxWindowList &winList = p->GetChildren(); jsint count = winList.GetCount(); JSObject *objSelections = JS_NewArrayObject(cx, count, NULL); *vp = OBJECT_TO_JSVAL(objSelections); jsint i = 0; for (wxWindowList::Node *node = winList.GetFirst(); node; node = node->GetNext() ) { wxWindow *win = dynamic_cast(node->GetData()); if ( win ) { JavaScriptClientData *data = dynamic_cast(win->GetClientObject()); if ( data != NULL ) { jsval element = OBJECT_TO_JSVAL(data->GetObject()); JS_SetElement(cx, objSelections, i++, &element); } } } break; } case P_PARENT: { wxWindow *win = p->GetParent(); if ( win ) { JavaScriptClientData *data = dynamic_cast(win->GetClientObject()); if ( data != NULL ) { *vp = OBJECT_TO_JSVAL(data->GetObject()); } } break; } case P_VALIDATOR: { wxValidator *val = p->GetValidator(); if ( val ) { JavaScriptClientData *data = dynamic_cast(val->GetClientObject()); if ( data != NULL ) { *vp = OBJECT_TO_JSVAL(data->GetObject()); } } break; } case P_HAS_CAPTURE: *vp = ToJS(cx, p->HasCapture()); break; case P_BACKGROUND_COLOUR: *vp = Colour::CreateObject(cx, new wxColour(p->GetBackgroundColour())); break; case P_FOREGROUND_COLOUR: *vp = Colour::CreateObject(cx, new wxColour(p->GetForegroundColour())); break; case P_FONT: *vp = Font::CreateObject(cx, new wxFont(p->GetFont()), obj); break; + case P_TOOL_TIP: + if ( p->GetToolTip() == NULL ) + *vp = JSVAL_VOID; + else + *vp = ToJS(cx, p->GetToolTip()->GetTip()); + break; } return true; } bool Window::SetProperty(wxWindow *p, JSContext *cx, JSObject *obj, int id, jsval *vp) { switch(id) { case P_ACCELERATOR_TABLE: { wxAcceleratorTable *table = AcceleratorTable::GetPrivate(cx, *vp); if ( table != NULL ) p->SetAcceleratorTable(*table); break; } case P_VISIBLE: { bool visible; if ( FromJS(cx, *vp, visible) ) p->Show(visible); break; } case P_ENABLE: { bool enable; if ( FromJS(cx, *vp, enable) ) p->Enable(enable); break; } case P_WIDTH: { int size; if ( FromJS(cx, *vp, size) ) p->SetSize(size, -1); break; } case P_HEIGHT: { int height; if ( FromJS(cx, *vp, height) ) p->SetSize(-1, height); break; } case P_SIZE: { wxSize *size = Size::GetPrivate(cx, *vp); if ( size != NULL ) { p->SetSize(*size); } else { // Try wxRect wxRect *rect = Rect::GetPrivate(cx, *vp); if ( rect != NULL ) p->SetSize(*rect); } break; } case P_SIZER: { wxSizer *sizer = Sizer::GetPrivate(cx, *vp); if ( sizer != NULL ) { p->SetSizer(sizer); JavaScriptClientData *data = dynamic_cast(sizer->GetClientObject()); if ( data != NULL ) { data->Protect(true); data->SetOwner(false); } } break; } case P_CLIENT_HEIGHT: { int size; if ( FromJS(cx, *vp, size) ) p->SetClientSize(-1, size); break; } case P_CLIENT_WIDTH: { int size; if ( FromJS(cx, *vp, size) ) p->SetClientSize(size, -1); break; } case P_CLIENT_SIZE: { wxSize *size = Size::GetPrivate(cx, *vp); if ( size != NULL ) { p->SetClientSize(*size); } else { // Try wxRect wxRect *rect = Rect::GetPrivate(cx, *vp); if ( rect != NULL ) p->SetClientSize(*rect); } break; } case P_POSITION: { wxPoint *pt = wxjs::ext::GetPoint(cx, *vp); if ( pt != NULL ) p->Move(*pt); } break; case P_AUTO_LAYOUT: { bool autoLayout; if ( FromJS(cx, *vp, autoLayout) ) p->SetAutoLayout(autoLayout); break; } case P_WINDOW_STYLE: { int style; if ( FromJS(cx, *vp, style) ) p->SetWindowStyle(style); break; } case P_EXTRA_STYLE: { int style; if ( FromJS(cx, *vp, style) ) p->SetExtraStyle(style); break; } case P_PARENT: { wxWindow *win = Window::GetPrivate(cx, *vp); if ( win != NULL ) { p->Reparent(win); } } case P_VALIDATOR: { wxValidator *val = Validator::GetPrivate(cx, *vp); if ( val != NULL ) { val->SetClientObject(new JavaScriptClientData(cx, JSVAL_TO_OBJECT(*vp), true, true)); p->SetValidator(*val); val->SetWindow(p); // We do this, because otherwise we loose the knowledge // of WindowObject } break; } case P_HAS_CAPTURE: { bool capture; if ( FromJS(cx, *vp, capture) ) capture ? p->CaptureMouse() : p->ReleaseMouse(); break; } case P_BACKGROUND_COLOUR: { wxColour *colour = Colour::GetPrivate(cx, *vp); if ( colour != NULL ) p->SetBackgroundColour(*colour); break; } case P_FOREGROUND_COLOUR: { wxColour *colour = Colour::GetPrivate(cx, *vp); if ( colour != NULL ) p->SetForegroundColour(*colour); break; } case P_FONT: { wxFont *font = Font::GetPrivate(cx, *vp); if ( font != NULL ) p->SetFont(*font); break; } + case P_TOOL_TIP: + { + if ( JSVAL_IS_VOID(*vp) ) + p->SetToolTip(NULL); + else + { + wxString toolTip; + if ( FromJS(cx, *vp, toolTip) ) + p->SetToolTip(toolTip); + } + break; + } } return true; } /*** * * * Gets the window that has the capture. * See @wxWindow#hasCapture, @wxWindow#releaseMouse and @wxWindow#captureMouse * * */ WXJS_BEGIN_STATIC_PROPERTY_MAP(Window) WXJS_READONLY_STATIC_PROPERTY(P_CAPTURE, "capture") WXJS_END_PROPERTY_MAP() bool Window::GetStaticProperty(JSContext *cx, int id, jsval *vp) { if ( id == P_CAPTURE ) { wxWindow *win = wxWindow::GetCapture(); if ( win != NULL ) { JavaScriptClientData *data = dynamic_cast(win->GetClientObject()); if ( data != NULL ) { *vp = OBJECT_TO_JSVAL(data->GetObject()); } } } return true; } /*** * * * * * * * * * * * * * * * * * * * * TransferDataTo/FromWindow() and Validate() methods will recursively descend * into all children of the window if it has this style flag set. * * * Normally, the command events are propagared upwards to the window parent recursively * until a handler for them is found. Using this style allows to prevent them from being * propagated beyond this window. Notice that wxDialog has this style on by default for * the reasons explained in the event processing overview. * * * This can be used to prevent a window from being used as an implicit parent for the * dialogs which were created without a parent. It is useful for the windows which can * disappear at any moment as creating childs of such windows results in fatal problems. * * * * * Use internally-calculated width if -1 * * * Use internally-calculated height if -1 * * * Use internally-calculated width and height if each is -1 * * * Ignore missing (-1) dimensions (use existing). * * * Allow -1 as a valid position * * * Don't do parent client adjustments (for implementation only) * * * */ WXJS_BEGIN_CONSTANT_MAP(Window) WXJS_CONSTANT(wx, DOUBLE_BORDER) WXJS_CONSTANT(wx, SUNKEN_BORDER) WXJS_CONSTANT(wx, RAISED_BORDER) WXJS_CONSTANT(wx, BORDER) WXJS_CONSTANT(wx, SIMPLE_BORDER) WXJS_CONSTANT(wx, STATIC_BORDER) WXJS_CONSTANT(wx, NO_BORDER) WXJS_CONSTANT(wx, NO_3D) WXJS_CONSTANT(wx, CLIP_CHILDREN) WXJS_CONSTANT(wx, TAB_TRAVERSAL) WXJS_CONSTANT(wx, WANTS_CHARS) WXJS_CONSTANT(wx, NO_FULL_REPAINT_ON_RESIZE) WXJS_CONSTANT(wx, VSCROLL) WXJS_CONSTANT(wx, HSCROLL) WXJS_CONSTANT(wx, SIZE_AUTO_WIDTH) WXJS_CONSTANT(wx, SIZE_AUTO_HEIGHT) WXJS_CONSTANT(wx, SIZE_AUTO) WXJS_CONSTANT(wx, SIZE_USE_EXISTING) WXJS_CONSTANT(wx, SIZE_ALLOW_MINUS_ONE) WXJS_CONSTANT(wx, SIZE_NO_ADJUSTMENTS) WXJS_CONSTANT(wx, WS_EX_VALIDATE_RECURSIVELY) WXJS_CONSTANT(wx, WS_EX_BLOCK_EVENTS) WXJS_CONSTANT(wx, WS_EX_TRANSIENT) WXJS_END_CONSTANT_MAP() WXJS_BEGIN_METHOD_MAP(Window) WXJS_METHOD("captureMouse", captureMouse, 0) WXJS_METHOD("centre", centre, 1) WXJS_METHOD("center", centre, 1) WXJS_METHOD("clearBackground", clearBackground, 0) WXJS_METHOD("clientToScreen", clientToScreen, 1) WXJS_METHOD("close", close, 1) WXJS_METHOD("convertDialogToPixels", convertDialogToPixels, 1) WXJS_METHOD("convertPixelsToDialog", convertPixelsToDialog, 1) WXJS_METHOD("destroy", destroy, 0) WXJS_METHOD("destroyChildren", destroyChildren, 0) WXJS_METHOD("releaseMouse", releaseMouse, 0) WXJS_METHOD("layout", layout, 0) WXJS_METHOD("move", move, 2) WXJS_METHOD("lower", lower, 0) WXJS_METHOD("raise", raise, 0) WXJS_METHOD("centreOnParent", centreOnParent, 1) WXJS_METHOD("centerOnParent", centreOnParent, 1) WXJS_METHOD("show", show, 1) WXJS_METHOD("fit", fit, 0) WXJS_METHOD("setSizeHints", setSizeHints, 6) WXJS_METHOD("refresh", refresh, 2) WXJS_METHOD("setFocus", setFocus, 0) WXJS_METHOD("findWindow", findWindow, 1) WXJS_METHOD("initDialog", initDialog, 0) WXJS_METHOD("transferDataToWindow", transferDataToWindow, 0) WXJS_METHOD("transferDataFromWindow", transferDataFromWindow, 0) WXJS_METHOD("validate", validate, 0) WXJS_METHOD("makeModal", makeModal, 1) WXJS_METHOD("warpPointer", warpPointer, 1) WXJS_METHOD("update", update, 0) WXJS_METHOD("freeze", freeze, 0) WXJS_METHOD("thaw", thaw, 0) WXJS_END_METHOD_MAP() /*** * * * * Directs all mouse input to this window. Call @wxWindow#releaseMouse to release the capture. * See @wxWindow#hasCapture * * */ JSBool Window::captureMouse(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->CaptureMouse(); return JS_TRUE; } /*** * * * * You can use the constants from @wxOrientation * * * */ JSBool Window::centre(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; if ( argc == 0 ) { p->Centre(); } else if (argc == 1) { int direction; if ( FromJS(cx, argv[0], direction) ) { p->Centre(direction); } else { return JS_FALSE; } } else { return JS_FALSE; } return JS_TRUE; } /*** * * * * Clears the window by filling it with the current background color. * * */ JSBool Window::clearBackground(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->ClearBackground(); return JS_TRUE; } /*** * * * * The client position * * * * Returns the screen coordinates from coordinates relative to this window. * * */ JSBool Window::clientToScreen(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; wxPoint *pt = wxjs::ext::GetPoint(cx, argv[0]); if ( pt != NULL ) *rval = wxjs::ext::CreatePoint(cx, p->ClientToScreen(*pt)); else return JS_FALSE; return JS_TRUE; } /*** * * * * When true the application can't veto the close. By default Force is false. * * * * Closes the window. This applies only for @wxFrame and @wxDialog objects. * * */ JSBool Window::close(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; if ( argc == 1 ) { bool force = false; if ( FromJS(cx, argv[0], force) ) { p->Close(force); return JS_TRUE; } else { return JS_FALSE; } } else if ( argc == 0 ) { p->Close(); return JS_TRUE; } return JS_FALSE; } /*** * * * Converts a point * * * * Converts a size * * * * Converts a point or a size to from dialog units to pixels. * * */ JSBool Window::convertDialogToPixels(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; JSBool result = JS_FALSE; wxSize *size = Size::GetPrivate(cx, argv[0]); if ( size != NULL ) { *rval = Size::CreateObject(cx, new wxSize(p->ConvertDialogToPixels(*size))); return JS_TRUE; } else { wxPoint *pt = wxjs::ext::GetPoint(cx, argv[0]); if ( pt != NULL ) { *rval = wxjs::ext::CreatePoint(cx, p->ConvertDialogToPixels(*pt)); result = JS_TRUE; } } return result; } /*** * * * Converts a point * * * * Converts a size * * * * Converts a point or a size from pixels to dialog units. * * */ JSBool Window::convertPixelsToDialog(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; JSBool result = JS_FALSE; wxSize *size = Size::GetPrivate(cx, argv[0]); if ( size != NULL ) { *rval = Size::CreateObject(cx, new wxSize(p->ConvertPixelsToDialog(*size))); result = JS_TRUE; } else { wxPoint *pt = wxjs::ext::GetPoint(cx, argv[0]); if ( pt != NULL ) { *rval = wxjs::ext::CreatePoint(cx, p->ConvertPixelsToDialog(*pt)); result = JS_TRUE; } } return result; } /*** * * * * Destroys the window. Returns true when the window is destroyed. * * */ JSBool Window::destroy(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; *rval = ToJS(cx, p->Destroy()); return JS_TRUE; } /*** * * * * Destroys all children of the window. * * */ JSBool Window::destroyChildren(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->DestroyChildren(); return JS_TRUE; } /*** * * * * Releases mouse input captured by @wxWindow#captureMouse. * See @wxWindow#hasCapture and @wxWindow#captureMouse * * */ JSBool Window::releaseMouse(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->ReleaseMouse(); return JS_TRUE; } /*** * * * * * * * * * * Moves the mouse to the given position * * */ JSBool Window::warpPointer(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; if ( argc == 1 ) { wxPoint *pt = wxjs::ext::GetPoint(cx, argv[0]); if ( pt != NULL ) { p->WarpPointer(pt->x, pt->y); return JS_TRUE; } } else if ( argc == 2 ) { int x = 0; int y = 0; if ( FromJS(cx, argv[0], x) || FromJS(cx, argv[1], y) ) { p->WarpPointer(x, y); return JS_TRUE; } } return JS_FALSE; } /*** * * * * Layout the window using the sizer. * * */ JSBool Window::layout(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->Layout(); return JS_TRUE; } /*** * * * * * * * * * * Moves the window. * * */ JSBool Window::move(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; if ( argc > 2 ) argc = 2; JSBool result = JS_FALSE; switch(argc) { case 2: { int x; int y; if ( FromJS(cx, argv[0], x) && FromJS(cx, argv[1], y) ) { p->Move(x, y); result = JS_TRUE; } break; } case 1: { wxPoint *pt = wxjs::ext::GetPoint(cx, argv[0]); if ( pt == NULL ) { p->Move(*pt); result = JS_TRUE; } break; } } return result; } /*** * * * * X position in pixels, or -1 to indicate that the existing value should be used. * * * Y position in pixels, or -1 to indicate that the existing value should be used. * * * Width in pixels, or -1 to indicate that the existing value should be used. * * * Height in pixels, or -1 to indicate that the existing value should be used. * * * Indicates the interpretation of the parameters. * * * * * Width in pixels, or -1 to indicate that the existing value should be used. * * * Height in pixels, or -1 to indicate that the existing value should be used. * * * * Sets a new window size. * See @wxWindow#size property, @wxWindow#sizeFlags * * */ JSBool Window::setSize(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; JSBool result = JS_FALSE; int x; int y; int width; int height; int flag = wxSIZE_AUTO; if ( argc == 2 ) { if ( FromJS(cx, argv[0], width) && FromJS(cx, argv[1], height) ) { p->SetSize(width, height); result = JS_TRUE; } } else if ( argc > 3 ) { if ( FromJS(cx, argv[0], x) && FromJS(cx, argv[1], y) && FromJS(cx, argv[2], width) && FromJS(cx, argv[3], height) ) { if ( argc > 4 && ! FromJS(cx, argv[4], flag) ) { return JS_FALSE; } p->SetSize(x, y, width, height, flag); result = JS_TRUE; } } return result; } /*** * * * * Raises the window to the top of the window hierarchy if it is a managed window (dialog or frame). * * */ JSBool Window::raise(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->Raise(); return JS_TRUE; } /*** * * * * Lowers the window to the bottom of the window hierarchy if it is a managed window (dialog or frame). * * */ JSBool Window::lower(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->Lower(); return JS_TRUE; } /*** * * * * * * Centres the window based on the parent. centreOnParent is an alias for this method. * * */ JSBool Window::centreOnParent(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; if ( argc == 0 ) { p->CentreOnParent(); } else { int direction; if ( FromJS(cx, argv[0], direction) ) { p->CentreOnParent(direction); } else { return JS_FALSE; } } return JS_TRUE; } /*** * * * * Set window size to wrap around its children * * */ JSBool Window::fit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->Fit(); return JS_TRUE; } /*** * * * * The minimum width of the window. * * * The minimum height of the window. * * * The maximum width of the window. * * * The maximum height of the window. * * * The increment for resizing the width (Motif/Xt only). * * * The increment for resizing the height (Motif/Xt only). * * * * Allows specification of minimum and maximum window sizes, and window size increments. * If a pair of values is not set (or set to -1), the default values will be used. * If this function is called, the user will not be able to size the window * outside the given bounds. *

* The resizing increments are only significant under Motif or Xt. *
*
*/ JSBool Window::setSizeHints(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; int minWidth = -1; int minHeight = -1; int maxWidth = -1; int maxHeight = -1; int incWidth = -1; int incHeight = -1; if ( JS_ConvertArguments(cx, argc, argv, "/iiiiii", &minWidth, &minHeight, &maxWidth, &maxHeight, &incWidth, &incHeight) == JS_TRUE ) { p->SetSizeHints(minWidth, minHeight, maxWidth, maxHeight, incWidth, incHeight); } else return JS_FALSE; return JS_TRUE; } /*** * * * * * * Shows (true) or hides (false) the window. * See @wxWindow#visible property, @wxWindow#shown property * * */ JSBool Window::show(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; if ( argc == 0 ) p->Show(); else { bool visible; if ( FromJS(cx, argv[0], visible) ) p->Show(visible); else return JS_FALSE; } return JS_TRUE; } /*** * * * * When true the background is erased. * * * When set, the given rectangle will be treated as damaged. * * * * Generates an event for repainting the window * * */ JSBool Window::refresh(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; bool erase = true; wxRect *rect = NULL; if ( argc > 2 ) argc = 2; switch(argc) { case 2: rect = Rect::GetPrivate(cx, argv[1]); if ( rect == NULL ) break; // Fall Through case 1: if ( ! FromJS(cx, argv[0], erase) ) break; // Fall Through default: p->Refresh(erase, rect); return JS_TRUE; } return JS_FALSE; } /*** * * * * This sets the window to receive keyboard input. * * */ JSBool Window::setFocus(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->SetFocus(); return JS_TRUE; } /*** * * * The id of a window * * * The name of a window * * * Find a child of this window, by identifier or by name * * */ JSBool Window::findWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; wxWindow *win; int id; if ( FromJS(cx, argv[0], id) ) { win = p->FindWindow(id); } else { wxString name; FromJS(cx, argv[0], name); win = p->FindWindow(name); } if ( win == (wxWindow*) NULL ) { *rval = JSVAL_VOID; } else { JavaScriptClientData *data = dynamic_cast(win->GetClientObject()); if ( data == NULL ) { *rval = JSVAL_VOID; } else { *rval = OBJECT_TO_JSVAL(data->GetObject()); } } return JS_TRUE; } /*** * * * * Sends an onInitDialog event, which in turn transfers data to the dialog via validators * * */ JSBool Window::initDialog(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->InitDialog(); return JS_TRUE; } /*** * * * * Transfers values to child controls from data areas specified by their validators * Returns FALSE if a transfer failed. * * */ JSBool Window::transferDataToWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; *rval = ToJS(cx, p->TransferDataToWindow()); return JS_TRUE; } /*** * * * * Transfers values from child controls to data areas specified by their validators. * Returns false if a transfer failed. * * */ JSBool Window::transferDataFromWindow(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; *rval = ToJS(cx, p->TransferDataToWindow()); return JS_TRUE; } /*** * * * * Validates the current values of the child controls using their validators. * * */ JSBool Window::validate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; *rval = ToJS(cx, p->Validate()); return JS_TRUE; } /*** * * * * * * Make modal or not. * When flag is true, all other windows are disabled. * * */ JSBool Window::makeModal(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; if ( argc == 1 ) { bool flag; if ( FromJS(cx, argv[0], flag) ) { p->MakeModal(flag); } else { return JS_FALSE; } } else p->MakeModal(); return JS_TRUE; } /*** * * * * Repaint all invalid areas of the window immediately * * */ JSBool Window::update(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->Update(); return JS_TRUE; } /*** * * * * Freeze the window: don't redraw it until it is thawed * See @wxWindow#thaw * * */ JSBool Window::freeze(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->Freeze(); return JS_TRUE; } /*** * * * * Thaw the window: redraw it after it had been frozen. * See @wxWindow#freeze * * */ JSBool Window::thaw(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *p = GetPrivate(cx, obj); if ( p == NULL ) return JS_FALSE; p->Thaw(); return JS_TRUE; } WXJS_BEGIN_STATIC_METHOD_MAP(Window) WXJS_METHOD("findFocus", findFocus, 0) WXJS_METHOD("findWindowById", findWindowById, 1) WXJS_METHOD("findWindowByLabel", findWindowByLabel, 1) WXJS_END_METHOD_MAP() /*** * * * * Finds the window or control which currently has the keyboard focus * * */ JSBool Window::findFocus(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxWindow *win = wxWindow::FindFocus(); if ( win == NULL ) { *rval = JSVAL_VOID; } else { JavaScriptClientData *data = dynamic_cast(win->GetClientObject()); if ( data == NULL ) { *rval = JSVAL_VOID; } else { *rval = OBJECT_TO_JSVAL(data->GetObject()); } } return JS_TRUE; } /*** * * * The id of a window * * * Find a window by identifier * * */ JSBool Window::findWindowById(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { int id; if ( FromJS(cx, argv[0], id) ) { wxWindow *win = wxWindow::FindWindowById(id); if ( win == (wxWindow*) NULL ) { *rval = JSVAL_VOID; } else { JavaScriptClientData *data = dynamic_cast(win->GetClientObject()); if ( data == NULL ) { *rval = JSVAL_VOID; } else { *rval = OBJECT_TO_JSVAL(data->GetObject()); } } } return JS_TRUE; } /*** * * * The label of a window * * * Find a window by label * * */ JSBool Window::findWindowByLabel(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { wxString label; if ( FromJS(cx, argv[0], label) ) { wxWindow *win = wxWindow::FindWindowByLabel(label); if ( win == (wxWindow*) NULL ) { *rval = JSVAL_VOID; } else { JavaScriptClientData *data = dynamic_cast(win->GetClientObject()); if ( data == NULL ) { *rval = JSVAL_VOID; } else { *rval = OBJECT_TO_JSVAL(data->GetObject()); } } } return JS_TRUE; } /*** * * * Called when the window is activated/disactivated. The function * gets a @wxActivateEvent as argument. * * * Called when the user enters a character. The function * gets a @wxKeyEvent object as argument. * * * This event is triggered to allow the window to intercept keyboard events before they are * processed by child windows. The function gets a @wxKeyEvent as argument. * * * Called when the user has pressed a key, before it is translated into an * ASCII value using other modifier keys that might be pressed at the same time. * The function gets a @wxKeyEvent object as argument. * * * Called when the user has released the key. * The function gets a @wxKeyEvent object as argument. * * * Called when the window gets the focus. * The function gets a @wxFocusEvent object as argument. * * * Called when the window looses the focus. * The function gets a @wxFocusEvent object as argument. * * * Used for handling all the mouse events. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the mouse enters the window. The function * gets a @wxMouseEvent as argument. * Under Windows mouse enter and leave events are not natively supported by the * system but are generated by wxWindows itself. This has several drawbacks: * the @wxWindow#onLeaveWindow event might be received some time after the mouse left * the window and the state variables for it may have changed during this time. * See @wxWindow#onLeaveWindow * * * Event triggered when the mouse leaves the window. The function * gets a @wxMouseEvent as argument. * Under Windows mouse enter and leave events are not natively supported by the * system but are generated by wxWindows itself. This has several drawbacks: * the onLeaveWindow event might be received some time after the mouse left * the window and the state variables for it may have changed during this time. * See @wxWindow#onEnterWindow * * * Event triggered when the left button is pressed. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the left button is released. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the left button is double clicked. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the middle button is pressed. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the middle button is released. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the middle button is double clicked. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the right button is pressed. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the right button is released. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the right button is double clicked. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the mouse is moved. The function * gets a @wxMouseEvent as argument. * * * Event triggered when the mousewheel is used. The function * gets a @wxMouseEvent as argument. * * * Called when the window is moved. The function gets a @wxMoveEvent as argument. * * * Called when the window is resized. The function gets a @wxSizeEvent as argument. * * * Catch all scroll commands. The argument of the function is a @wxScrollWinEvent. * * * Catch a command to put the scroll thumb at the maximum position. * The argument of the function is a @wxScrollWinEvent. * * * Catch a command to put the scroll thumb at the maximum position. * The argument of the function is a @wxScrollWinEvent. * * * Catch a line up command. * The argument of the function is a @wxScrollWinEvent. * * * Catch a line down command. * The argument of the function is a @wxScrollWinEvent. * * * Catch a page up command. * The argument of the function is a @wxScrollWinEvent. * * * Catch a page down command. * The argument of the function is a @wxScrollWinEvent. * * * Catch a thumbtrack command (continuous movement of the scroll thumb). * The argument of the function is a @wxScrollWinEvent. * * * Catch a thumbtrack release command. * The argument of the function is a @wxScrollWinEvent. * * * Triggered when the user pressed F1 (on Windows) or * when the user requested context-sensitive help. * The argument of the function is a @wxHelpEvent. * See @wxContextHelp, @wxHelpEvent and @wxContextHelpButton * * */ #include "../event/jsevent.h" #include "../event/key.h" #include "../event/activate.h" #include "../event/mouse.h" #include "../event/move.h" #include "../event/sizeevt.h" #include "../event/help.h" #include "../event/scrollwin.h" WXJS_INIT_EVENT_MAP(wxWindow) const wxString WXJS_SETFOCUS_EVENT(wxT("onSetFocus")); const wxString WXJS_CHAR_EVENT(wxT("onChar")); const wxString WXJS_CHAR_HOOK_EVENT(wxT("onCharHook")); const wxString WXJS_KEY_DOWN_EVENT(wxT("onKeyDown")); const wxString WXJS_KEY_UP_EVENT(wxT("onKeyUp")); const wxString WXJS_ACTIVATE_EVENT(wxT("onActivate")); const wxString WXJS_SET_FOCUS_EVENT(wxT("onSetFocus")); const wxString WXJS_KILL_FOCUS_EVENT(wxT("onKillFocus")); const wxString WXJS_LEFT_DOWN_EVENT(wxT("onLeftDown")); const wxString WXJS_LEFT_UP_EVENT(wxT("onLeftUp")); const wxString WXJS_LEFT_DCLICK_EVENT(wxT("onLeftDClick")); const wxString WXJS_MIDDLE_DOWN_EVENT(wxT("onMiddleDown")); const wxString WXJS_MIDDLE_UP_EVENT(wxT("onMiddleUp")); const wxString WXJS_MIDDLE_DCLICK_EVENT(wxT("onMiddleDClick")); const wxString WXJS_RIGHT_DOWN_EVENT(wxT("onRightDown")); const wxString WXJS_RIGHT_UP_EVENT(wxT("onRightUp")); const wxString WXJS_RIGHT_DCLICK_EVENT(wxT("onRightDClick")); const wxString WXJS_MOTION_EVENT(wxT("onMotion")); const wxString WXJS_ENTER_WINDOW_EVENT(wxT("onEnterWindow")); const wxString WXJS_LEAVE_WINDOW_EVENT(wxT("onLeaveWindow")); const wxString WXJS_MOUSE_WHEEL_EVENT(wxT("onMouseWheel")); const wxString WXJS_MOVE_EVENT(wxT("onMove")); const wxString WXJS_SIZE_EVENT(wxT("onSize")); const wxString WXJS_SCROLL_EVENT(wxT("onScroll")); const wxString WXJS_SCROLL_TOP_EVENT(wxT("onScrollTop")); const wxString WXJS_SCROLL_BOTTOM_EVENT(wxT("onScrollBottom")); const wxString WXJS_SCROLL_LINEUP_EVENT(wxT("onScrollLineUp")); const wxString WXJS_SCROLL_LINEDOWN_EVENT(wxT("onScrollLineDown")); const wxString WXJS_SCROLL_PAGEUP_EVENT(wxT("onScrollPageUp")); const wxString WXJS_SCROLL_PAGEDOWN_EVENT(wxT("onScrollPageDown")); const wxString WXJS_SCROLL_THUMBTRACK_EVENT(wxT("onScrollThumbtrack")); const wxString WXJS_SCROLL_THUMBRELEASE(wxT("onScrollThumbRelease")); const wxString WXJS_HELP_EVENT(wxT("onHelp")); void WindowEventHandler::OnChar(wxKeyEvent &event) { PrivKeyEvent::Fire(event, WXJS_CHAR_EVENT); } void WindowEventHandler::OnCharHook(wxKeyEvent &event) { PrivKeyEvent::Fire(event, WXJS_CHAR_HOOK_EVENT); } void WindowEventHandler::OnKeyDown(wxKeyEvent &event) { PrivKeyEvent::Fire(event, WXJS_KEY_DOWN_EVENT); } void WindowEventHandler::OnKeyUp(wxKeyEvent &event) { PrivKeyEvent::Fire(event, WXJS_KEY_UP_EVENT); } void WindowEventHandler::OnActivate(wxActivateEvent &event) { PrivActivateEvent::Fire(event, WXJS_ACTIVATE_EVENT); } void WindowEventHandler::OnSetFocus(wxFocusEvent &event) { PrivFocusEvent::Fire(event, WXJS_SET_FOCUS_EVENT); } void WindowEventHandler::OnKillFocus(wxFocusEvent &event) { PrivFocusEvent::Fire(event, WXJS_KILL_FOCUS_EVENT); } void WindowEventHandler::OnLeftDown(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_LEFT_DOWN_EVENT); } void WindowEventHandler::OnLeftUp(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_LEFT_UP_EVENT); } void WindowEventHandler::OnLeftDClick(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_LEFT_DCLICK_EVENT); } void WindowEventHandler::OnMiddleDown(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_MIDDLE_DOWN_EVENT); } void WindowEventHandler::OnMiddleUp(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_MIDDLE_UP_EVENT); } void WindowEventHandler::OnMiddleDClick(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_MIDDLE_DCLICK_EVENT); } void WindowEventHandler::OnRightDown(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_RIGHT_DOWN_EVENT); } void WindowEventHandler::OnRightUp(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_RIGHT_UP_EVENT); } void WindowEventHandler::OnRightDClick(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_RIGHT_DCLICK_EVENT); } void WindowEventHandler::OnMotion(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_MOTION_EVENT); } void WindowEventHandler::OnEnterWindow(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_ENTER_WINDOW_EVENT); } void WindowEventHandler::OnLeaveWindow(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_LEAVE_WINDOW_EVENT); } void WindowEventHandler::OnMouseWheel(wxMouseEvent &event) { PrivMouseEvent::Fire(event, WXJS_MOUSE_WHEEL_EVENT); } void WindowEventHandler::OnMove(wxMoveEvent &event) { PrivMoveEvent::Fire(event, WXJS_MOVE_EVENT); } void WindowEventHandler::OnSize(wxSizeEvent &event) { PrivSizeEvent::Fire(event, WXJS_SIZE_EVENT); } void WindowEventHandler::OnScrollTop(wxScrollWinEvent& event) { PrivScrollWinEvent::Fire(event, WXJS_SCROLL_TOP_EVENT); } void WindowEventHandler::OnScrollBottom(wxScrollWinEvent& event) { PrivScrollWinEvent::Fire(event, WXJS_SCROLL_BOTTOM_EVENT); } void WindowEventHandler::OnScrollLineUp(wxScrollWinEvent& event) { PrivScrollWinEvent::Fire(event, WXJS_SCROLL_LINEUP_EVENT); } void WindowEventHandler::OnScrollLineDown(wxScrollWinEvent& event) { PrivScrollWinEvent::Fire(event, WXJS_SCROLL_LINEDOWN_EVENT); } void WindowEventHandler::OnScrollPageUp(wxScrollWinEvent& event) { PrivScrollWinEvent::Fire(event, WXJS_SCROLL_PAGEUP_EVENT); } void WindowEventHandler::OnScrollPageDown(wxScrollWinEvent& event) { PrivScrollWinEvent::Fire(event, WXJS_SCROLL_PAGEDOWN_EVENT); } void WindowEventHandler::OnScrollThumbTrack(wxScrollWinEvent& event) { PrivScrollWinEvent::Fire(event, WXJS_SCROLL_THUMBTRACK_EVENT); } void WindowEventHandler::OnScrollThumbRelease(wxScrollWinEvent& event) { PrivScrollWinEvent::Fire(event, WXJS_SCROLL_THUMBRELEASE); } void WindowEventHandler::OnHelp(wxHelpEvent &event) { PrivHelpEvent::Fire(event, WXJS_HELP_EVENT); } void WindowEventHandler::InitConnectEventMap(void) { AddConnector(WXJS_CHAR_EVENT, ConnectChar); AddConnector(WXJS_KEY_DOWN_EVENT, ConnectKeyDown); AddConnector(WXJS_KEY_UP_EVENT, ConnectKeyUp); AddConnector(WXJS_CHAR_HOOK_EVENT, ConnectCharHook); AddConnector(WXJS_ACTIVATE_EVENT, ConnectActivate); AddConnector(WXJS_SET_FOCUS_EVENT, ConnectSetFocus); AddConnector(WXJS_KILL_FOCUS_EVENT, ConnectKillFocus); AddConnector(WXJS_MOVE_EVENT, ConnectMove); AddConnector(WXJS_SIZE_EVENT, ConnectSize); AddConnector(WXJS_SCROLL_TOP_EVENT, ConnectScrollTop); AddConnector(WXJS_SCROLL_BOTTOM_EVENT, ConnectScrollBottom); AddConnector(WXJS_SCROLL_LINEUP_EVENT, ConnectScrollLineUp); AddConnector(WXJS_SCROLL_LINEDOWN_EVENT, ConnectScrollLineDown); AddConnector(WXJS_SCROLL_PAGEUP_EVENT, ConnectScrollPageUp); AddConnector(WXJS_SCROLL_PAGEDOWN_EVENT, ConnectScrollPageDown); AddConnector(WXJS_SCROLL_THUMBTRACK_EVENT, ConnectScrollThumbTrack); AddConnector(WXJS_SCROLL_THUMBRELEASE, ConnectScrollThumbRelease); AddConnector(WXJS_HELP_EVENT, ConnectHelp); AddConnector(WXJS_LEFT_DOWN_EVENT, ConnectLeftDown); AddConnector(WXJS_LEFT_UP_EVENT, ConnectLeftUp); AddConnector(WXJS_LEFT_DCLICK_EVENT, ConnectLeftDClick); AddConnector(WXJS_MIDDLE_DOWN_EVENT, ConnectMiddleDown); AddConnector(WXJS_MIDDLE_UP_EVENT, ConnectMiddleUp); AddConnector(WXJS_MIDDLE_DCLICK_EVENT, ConnectMiddleDClick); AddConnector(WXJS_RIGHT_DOWN_EVENT, ConnectRightDown); AddConnector(WXJS_RIGHT_UP_EVENT, ConnectRightUp); AddConnector(WXJS_RIGHT_DCLICK_EVENT, ConnectRightDClick); AddConnector(WXJS_MOTION_EVENT, ConnectMotion); AddConnector(WXJS_ENTER_WINDOW_EVENT, ConnectEnterWindow); AddConnector(WXJS_LEAVE_WINDOW_EVENT, ConnectLeaveWindow); AddConnector(WXJS_MOUSE_WHEEL_EVENT, ConnectMouseWheel); } void WindowEventHandler::ConnectChar(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_CHAR, wxCharEventHandler(WindowEventHandler::OnChar)); } else { p->Disconnect(wxEVT_CHAR, wxCharEventHandler(WindowEventHandler::OnChar)); } } void WindowEventHandler::ConnectKeyDown(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(WindowEventHandler::OnKeyDown)); } else { p->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(WindowEventHandler::OnKeyDown)); } } void WindowEventHandler::ConnectKeyUp(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_KEY_UP, wxKeyEventHandler(WindowEventHandler::OnKeyUp)); } else { p->Disconnect(wxEVT_KEY_UP, wxKeyEventHandler(WindowEventHandler::OnKeyUp)); } } void WindowEventHandler::ConnectCharHook(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_CHAR_HOOK, wxCharEventHandler(WindowEventHandler::OnCharHook)); } else { p->Disconnect(wxEVT_CHAR_HOOK, wxCharEventHandler(WindowEventHandler::OnCharHook)); } } void WindowEventHandler::ConnectActivate(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_ACTIVATE, wxActivateEventHandler(WindowEventHandler::OnActivate)); } else { p->Disconnect(wxEVT_ACTIVATE, wxActivateEventHandler(WindowEventHandler::OnActivate)); } } void WindowEventHandler::ConnectSetFocus(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(WindowEventHandler::OnSetFocus)); } else { p->Disconnect(wxEVT_SET_FOCUS, wxFocusEventHandler(WindowEventHandler::OnSetFocus)); } } void WindowEventHandler::ConnectKillFocus(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_KILL_FOCUS, wxFocusEventHandler(WindowEventHandler::OnKillFocus)); } else { p->Disconnect(wxEVT_KILL_FOCUS, wxFocusEventHandler(WindowEventHandler::OnKillFocus)); } } void WindowEventHandler::ConnectMove(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_MOVE, wxMoveEventHandler(WindowEventHandler::OnMove)); } else { p->Disconnect(wxEVT_MOVE, wxMoveEventHandler(WindowEventHandler::OnMove)); } } void WindowEventHandler::ConnectSize(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_SIZE, wxSizeEventHandler(WindowEventHandler::OnSize)); } else { p->Disconnect(wxEVT_SIZE, wxSizeEventHandler(WindowEventHandler::OnSize)); } } void WindowEventHandler::ConnectScrollTop(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_SCROLL_TOP, wxScrollWinEventHandler(WindowEventHandler::OnScrollTop)); } else { p->Disconnect(wxEVT_SCROLL_TOP, wxScrollWinEventHandler(WindowEventHandler::OnScrollTop)); } } void WindowEventHandler::ConnectScrollBottom(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_SCROLL_BOTTOM, wxScrollWinEventHandler(WindowEventHandler::OnScrollBottom)); } else { p->Disconnect(wxEVT_SCROLL_BOTTOM, wxScrollWinEventHandler(WindowEventHandler::OnScrollBottom)); } } void WindowEventHandler::ConnectScrollLineUp(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_SCROLL_LINEUP, wxScrollWinEventHandler(WindowEventHandler::OnScrollLineUp)); } else { p->Disconnect(wxEVT_SCROLL_LINEUP, wxScrollWinEventHandler(WindowEventHandler::OnScrollLineUp)); } } void WindowEventHandler::ConnectScrollLineDown(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_SCROLL_LINEDOWN, wxScrollWinEventHandler(WindowEventHandler::OnScrollLineDown)); } else { p->Disconnect(wxEVT_SCROLL_LINEDOWN, wxScrollWinEventHandler(WindowEventHandler::OnScrollLineDown)); } } void WindowEventHandler::ConnectScrollPageUp(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_SCROLL_PAGEUP, wxScrollWinEventHandler(WindowEventHandler::OnScrollPageUp)); } else { p->Disconnect(wxEVT_SCROLL_PAGEUP, wxScrollWinEventHandler(WindowEventHandler::OnScrollPageUp)); } } void WindowEventHandler::ConnectScrollPageDown(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_SCROLL_PAGEDOWN, wxScrollWinEventHandler(WindowEventHandler::OnScrollPageDown)); } else { p->Disconnect(wxEVT_SCROLL_PAGEDOWN, wxScrollWinEventHandler(WindowEventHandler::OnScrollPageDown)); } } void WindowEventHandler::ConnectScrollThumbTrack(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_SCROLL_THUMBTRACK, wxScrollWinEventHandler(WindowEventHandler::OnScrollThumbTrack)); } else { p->Disconnect(wxEVT_SCROLL_THUMBTRACK, wxScrollWinEventHandler(WindowEventHandler::OnScrollThumbTrack)); } } void WindowEventHandler::ConnectScrollThumbRelease(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_SCROLL_THUMBRELEASE, wxScrollWinEventHandler(WindowEventHandler::OnScrollThumbRelease)); } else { p->Disconnect(wxEVT_SCROLL_THUMBRELEASE, wxScrollWinEventHandler(WindowEventHandler::OnScrollThumbRelease)); } } void WindowEventHandler::ConnectHelp(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_HELP, wxHelpEventHandler(WindowEventHandler::OnHelp)); } else { p->Disconnect(wxEVT_HELP, wxHelpEventHandler(WindowEventHandler::OnHelp)); } } void WindowEventHandler::ConnectLeftDown(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_LEFT_DOWN, wxMouseEventHandler(WindowEventHandler::OnLeftDown)); } else { p->Disconnect(wxEVT_LEFT_DOWN, wxMouseEventHandler(WindowEventHandler::OnLeftDown)); } } void WindowEventHandler::ConnectLeftUp(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_LEFT_UP, wxMouseEventHandler(WindowEventHandler::OnLeftUp)); } else { p->Disconnect(wxEVT_LEFT_UP, wxMouseEventHandler(WindowEventHandler::OnLeftUp)); } } void WindowEventHandler::ConnectLeftDClick(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(WindowEventHandler::OnLeftDClick)); } else { p->Disconnect(wxEVT_LEFT_DCLICK, wxMouseEventHandler(WindowEventHandler::OnLeftDClick)); } } void WindowEventHandler::ConnectMiddleDown(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(WindowEventHandler::OnMiddleDown)); } else { p->Disconnect(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(WindowEventHandler::OnMiddleDown)); } } void WindowEventHandler::ConnectMiddleUp(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_MIDDLE_UP, wxMouseEventHandler(WindowEventHandler::OnMiddleUp)); } else { p->Disconnect(wxEVT_MIDDLE_UP, wxMouseEventHandler(WindowEventHandler::OnMiddleUp)); } } void WindowEventHandler::ConnectMiddleDClick(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(WindowEventHandler::OnMiddleDClick)); } else { p->Disconnect(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(WindowEventHandler::OnMiddleDClick)); } } void WindowEventHandler::ConnectRightDown(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(WindowEventHandler::OnRightDown)); } else { p->Disconnect(wxEVT_RIGHT_DOWN, wxMouseEventHandler(WindowEventHandler::OnRightDown)); } } void WindowEventHandler::ConnectRightUp(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_RIGHT_UP, wxMouseEventHandler(WindowEventHandler::OnRightUp)); } else { p->Disconnect(wxEVT_RIGHT_UP, wxMouseEventHandler(WindowEventHandler::OnRightUp)); } } void WindowEventHandler::ConnectRightDClick(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(WindowEventHandler::OnRightDClick)); } else { p->Disconnect(wxEVT_RIGHT_DCLICK, wxMouseEventHandler(WindowEventHandler::OnRightDClick)); } } void WindowEventHandler::ConnectMotion(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_MOTION, wxMouseEventHandler(WindowEventHandler::OnMotion)); } else { p->Disconnect(wxEVT_MOTION, wxMouseEventHandler(WindowEventHandler::OnMotion)); } } void WindowEventHandler::ConnectEnterWindow(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(WindowEventHandler::OnEnterWindow)); } else { p->Disconnect(wxEVT_ENTER_WINDOW, wxMouseEventHandler(WindowEventHandler::OnEnterWindow)); } } void WindowEventHandler::ConnectLeaveWindow(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(WindowEventHandler::OnLeaveWindow)); } else { p->Disconnect(wxEVT_LEAVE_WINDOW, wxMouseEventHandler(WindowEventHandler::OnLeaveWindow)); } } void WindowEventHandler::ConnectMouseWheel(wxWindow *p, bool connect) { if ( connect ) { p->Connect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(WindowEventHandler::OnMouseWheel)); } else { p->Disconnect(wxEVT_MOUSEWHEEL, wxMouseEventHandler(WindowEventHandler::OnMouseWheel)); } } Index: ps/trunk/source/tools/atlas/wxJS/gui/control/window.h =================================================================== --- ps/trunk/source/tools/atlas/wxJS/gui/control/window.h (revision 7257) +++ ps/trunk/source/tools/atlas/wxJS/gui/control/window.h (revision 7258) @@ -1,210 +1,211 @@ /* * wxJavaScript - window.h * * Copyright (c) 2002-2007 Franky Braem and the wxJavaScript project * * Project Info: http://www.wxjavascript.net or http://wxjs.sourceforge.net * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, * USA. * * $Id: window.h 745 2007-06-11 20:16:54Z fbraem $ */ #ifndef _WXJSWINDOW_H #define _WXJSWINDOW_H #include "../../common/evtconn.h" namespace wxjs { namespace gui { class Window : public ApiWrapper { public: static void InitClass(JSContext* cx, JSObject* obj, JSObject* proto); static bool GetProperty(wxWindow *p, JSContext *cx, JSObject *obj, int id, jsval *vp); static bool SetProperty(wxWindow *p, JSContext *cx, JSObject *obj, int id, jsval *vp); static bool GetStaticProperty(JSContext *cx, int id, jsval *vp); WXJS_DECLARE_METHOD_MAP() WXJS_DECLARE_METHOD(captureMouse) WXJS_DECLARE_METHOD(centre) WXJS_DECLARE_METHOD(clearBackground) WXJS_DECLARE_METHOD(clientToScreen) WXJS_DECLARE_METHOD(close) WXJS_DECLARE_METHOD(move) WXJS_DECLARE_METHOD(convertDialogToPixels) WXJS_DECLARE_METHOD(convertPixelsToDialog) WXJS_DECLARE_METHOD(destroy) WXJS_DECLARE_METHOD(destroyChildren) WXJS_DECLARE_METHOD(releaseMouse) WXJS_DECLARE_METHOD(layout) WXJS_DECLARE_METHOD(setSize) WXJS_DECLARE_METHOD(raise) WXJS_DECLARE_METHOD(lower) WXJS_DECLARE_METHOD(centreOnParent) WXJS_DECLARE_METHOD(fit) WXJS_DECLARE_METHOD(setSizeHints) WXJS_DECLARE_METHOD(show) WXJS_DECLARE_METHOD(refresh) WXJS_DECLARE_METHOD(setFocus) WXJS_DECLARE_METHOD(findFocus) WXJS_DECLARE_METHOD(findWindow) WXJS_DECLARE_METHOD(initDialog) WXJS_DECLARE_METHOD(transferDataToWindow) WXJS_DECLARE_METHOD(transferDataFromWindow) WXJS_DECLARE_METHOD(validate) WXJS_DECLARE_METHOD(makeModal) WXJS_DECLARE_METHOD(warpPointer) WXJS_DECLARE_METHOD(update) WXJS_DECLARE_METHOD(freeze) WXJS_DECLARE_METHOD(thaw) WXJS_DECLARE_METHOD(findWindowById) WXJS_DECLARE_METHOD(findWindowByLabel) WXJS_DECLARE_STATIC_METHOD_MAP() WXJS_DECLARE_STATIC_PROPERTY_MAP() WXJS_DECLARE_CONSTANT_MAP() WXJS_DECLARE_PROPERTY_MAP() enum { P_CLIENT_HEIGHT = -128 , P_AUTO_LAYOUT , P_CLIENT_WIDTH , P_CLIENT_ORIGIN , P_ENABLE , P_HEIGHT , P_TITLE , P_VISIBLE , P_WIDTH , P_POSITION , P_SIZE , P_SIZER , P_CLIENT_SIZE , P_ID , P_RECT , P_CLIENT_RECT , P_BEST_SIZE , P_WINDOW_STYLE , P_EXTRA_STYLE , P_SHOWN , P_TOP_LEVEL , P_ACCEPTS_FOCUS , P_ACCEPTS_FOCUS_KEYBOARD , P_DEFAULT_ITEM , P_CHILDREN , P_PARENT , P_VALIDATOR , P_ACCELERATOR_TABLE , P_CAPTURE , P_HAS_CAPTURE , P_UPDATE_REGION , P_BACKGROUND_COLOUR , P_FOREGROUND_COLOUR , P_FONT + , P_TOOL_TIP }; }; class WindowEventHandler : public EventConnector , public wxEvtHandler { public: void OnChar(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event); void OnKeyUp(wxKeyEvent &event); void OnCharHook(wxKeyEvent &event); void OnActivate(wxActivateEvent &event); void OnSetFocus(wxFocusEvent &event); void OnKillFocus(wxFocusEvent &event); void OnMouseEvents(wxMouseEvent &event); void OnMove(wxMoveEvent &event); void OnSize(wxSizeEvent &event); void OnScrollTop(wxScrollWinEvent& event); void OnScrollBottom(wxScrollWinEvent& event); void OnScrollLineUp(wxScrollWinEvent& event); void OnScrollLineDown(wxScrollWinEvent& event); void OnScrollPageUp(wxScrollWinEvent& event); void OnScrollPageDown(wxScrollWinEvent& event); void OnScrollThumbTrack(wxScrollWinEvent& event); void OnScrollThumbRelease(wxScrollWinEvent& event); void OnHelp(wxHelpEvent &event); void OnLeftDown(wxMouseEvent &event); void OnLeftUp(wxMouseEvent &event); void OnLeftDClick(wxMouseEvent &event); void OnMiddleDown(wxMouseEvent &event); void OnMiddleUp(wxMouseEvent &event); void OnMiddleDClick(wxMouseEvent &event); void OnRightDown(wxMouseEvent &event); void OnRightUp(wxMouseEvent &event); void OnRightDClick(wxMouseEvent &event); void OnMotion(wxMouseEvent &event); void OnEnterWindow(wxMouseEvent &event); void OnLeaveWindow(wxMouseEvent &event); void OnMouseWheel(wxMouseEvent &event); static void InitConnectEventMap(void); private: static void ConnectChar(wxWindow *p, bool connect); static void ConnectKeyDown(wxWindow *p, bool connect); static void ConnectKeyUp(wxWindow *p, bool connect); static void ConnectCharHook(wxWindow *p, bool connect); static void ConnectActivate(wxWindow *p, bool connect); static void ConnectSetFocus(wxWindow *p, bool connect); static void ConnectKillFocus(wxWindow *p, bool connect); static void ConnectMouseEvents(wxWindow *p, bool connect); static void ConnectMove(wxWindow *p, bool connect); static void ConnectSize(wxWindow *p, bool connect); static void ConnectScrollTop(wxWindow *p, bool connect); static void ConnectScrollBottom(wxWindow *p, bool connect); static void ConnectScrollLineUp(wxWindow *p, bool connect); static void ConnectScrollLineDown(wxWindow *p, bool connect); static void ConnectScrollPageUp(wxWindow *p, bool connect); static void ConnectScrollPageDown(wxWindow *p, bool connect); static void ConnectScrollThumbTrack(wxWindow *p, bool connect); static void ConnectScrollThumbRelease(wxWindow *p, bool connect); static void ConnectHelp(wxWindow *p, bool connect); static void ConnectLeftDown(wxWindow *p, bool connect); static void ConnectLeftUp(wxWindow *p, bool connect); static void ConnectLeftDClick(wxWindow *p, bool connect); static void ConnectMiddleDown(wxWindow *p, bool connect); static void ConnectMiddleUp(wxWindow *p, bool connect); static void ConnectMiddleDClick(wxWindow *p, bool connect); static void ConnectRightDown(wxWindow *p, bool connect); static void ConnectRightUp(wxWindow *p, bool connect); static void ConnectRightDClick(wxWindow *p, bool connect); static void ConnectMotion(wxWindow *p, bool connect); static void ConnectEnterWindow(wxWindow *p, bool connect); static void ConnectLeaveWindow(wxWindow *p, bool connect); static void ConnectMouseWheel(wxWindow *p, bool connect); }; }; // namespace gui }; // namespace wxjs #endif // _WXJSWINDOW_H