#include "wx/caret.h"
#endif // wxUSE_CARET
+#if wxUSE_SPINCTRL
+ #include "wx/spinctrl.h"
+#endif // wxUSE_SPINCTRL
+
#include "wx/intl.h"
#include "wx/log.h"
::ScreenToClient(hParentWnd, &point);
}
- // We may be faking the client origin. So a window that's really at (0,
- // 30) may appear (to wxWin apps) to be at (0, 0).
- wxPoint pt(parent->GetClientAreaOrigin());
- point.x -= pt.x;
- point.y -= pt.y;
+ if ( parent )
+ {
+ // We may be faking the client origin. So a window that's really at (0,
+ // 30) may appear (to wxWin apps) to be at (0, 0).
+ wxPoint pt(parent->GetClientAreaOrigin());
+ point.x -= pt.x;
+ point.y -= pt.y;
+ }
}
if ( x )
}
else if ( lDlgCode & DLGC_BUTTON )
{
- // buttons want process Enter themselevs
+ // let IsDialogMessage() handle this for all
+ // buttons except the owner-drawn ones which it
+ // just seems to ignore
+ long style = ::GetWindowLong(msg->hwnd, GWL_STYLE);
+ if ( (style & BS_OWNERDRAW) == BS_OWNERDRAW )
+ {
+ // emulate the button click
+ wxWindow *btn = wxFindWinFromHandle((WXHWND)msg->hwnd);
+ if ( btn )
+ btn->MSWCommand(BN_CLICKED, 0 /* unused */);
+ }
+
bProcess = FALSE;
}
else
case WM_LBUTTONDOWN:
// set focus to this window
- SetFocus();
+ if (AcceptsFocus())
+ SetFocus();
// fall through
rc.result = TRUE;
}
break;
+#ifdef __WIN32__
+ case WM_HELP:
+ {
+ HELPINFO* info = (HELPINFO*) lParam;
+ // Don't yet process menu help events, just windows
+ if (info->iContextType == HELPINFO_WINDOW)
+ {
+ wxWindow* subjectOfHelp = this;
+ bool eventProcessed = FALSE;
+ while (subjectOfHelp && !eventProcessed)
+ {
+ wxHelpEvent helpEvent(wxEVT_HELP, subjectOfHelp->GetId(), wxPoint(info->MousePos.x, info->MousePos.y) ) ; // info->iCtrlId);
+ helpEvent.SetEventObject(this);
+ eventProcessed = GetEventHandler()->ProcessEvent(helpEvent);
+
+ // Go up the window hierarchy until the event is handled (or not)
+ subjectOfHelp = subjectOfHelp->GetParent();
+ }
+ processed = eventProcessed;
+ }
+ else if (info->iContextType == HELPINFO_MENUITEM)
+ {
+ wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
+ helpEvent.SetEventObject(this);
+ processed = GetEventHandler()->ProcessEvent(helpEvent);
+ }
+ else processed = FALSE;
+ break;
+ }
+#endif
}
if ( !processed )
{
if ( m_hMenu )
{
+ wxChar buf[1024];
HMENU hMenu = (HMENU)m_hMenu;
int N = ::GetMenuItemCount(hMenu);
- int i;
- for (i = 0; i < N; i++)
+ for ( int i = 0; i < N; i++ )
{
- wxChar buf[100];
- int chars = GetMenuString(hMenu, i, buf, 100, MF_BYPOSITION);
- if ( !chars )
+ if ( !::GetMenuString(hMenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) )
{
wxLogLastError(wxT("GetMenuString"));
continue;
}
- if ( wxStrcmp(buf, wxT("&Window")) == 0 )
+ if ( wxStrcmp(buf, _("&Window")) == 0 )
{
- RemoveMenu(hMenu, i, MF_BYPOSITION);
+ if ( !::RemoveMenu(hMenu, i, MF_BYPOSITION) )
+ {
+ wxLogLastError(wxT("RemoveMenu"));
+ }
break;
}
}
#endif // 0
- HWND hParent = (HWND)NULL;
- if ( parent )
- hParent = (HWND) parent->GetHWND();
+ HWND hParent = parent ? GetHwndOf(parent) : NULL;
wxWndHook = this;
if ( dialog_template )
{
+ // for the dialogs without wxDIALOG_NO_PARENT style, use the top level
+ // app window as parent - this avoids creating modal dialogs without
+ // parent
+ if ( !hParent && !(GetWindowStyleFlag() & wxDIALOG_NO_PARENT) )
+ {
+ wxWindow *winTop = wxTheApp->GetTopWindow();
+ if ( winTop )
+ hParent = GetHwndOf(winTop);
+ }
+
m_hWnd = (WXHWND)::CreateDialog(wxGetInstance(),
dialog_template,
hParent,
if ( m_hWnd == 0 )
{
- wxLogError(_("Can't find dummy dialog template!\nCheck resource include path for finding wx.rc."));
+ wxLogError(_("Can't find dialog template '%s'!\nCheck resource include path for finding wx.rc."),
+ dialog_template);
return FALSE;
}
+ if ( extendedStyle != 0 )
+ {
+ ::SetWindowLong(GetHwnd(), GWL_EXSTYLE, extendedStyle);
+ ::SetWindowPos(GetHwnd(), NULL, 0, 0, 0, 0,
+ SWP_NOSIZE |
+ SWP_NOMOVE |
+ SWP_NOZORDER |
+ SWP_NOACTIVATE);
+ }
+
+#if defined(__WIN95__)
+ // For some reason, the system menu is activated when we use the
+ // WS_EX_CONTEXTHELP style, so let's set a reasonable icon
+ if (extendedStyle & WS_EX_CONTEXTHELP)
+ {
+ wxFrame *winTop = wxDynamicCast(wxTheApp->GetTopWindow(), wxFrame);
+ if ( winTop )
+ {
+ wxIcon icon = winTop->GetIcon();
+ if ( icon.Ok() )
+ {
+ ::SendMessage(GetHwnd(), WM_SETICON,
+ (WPARAM)TRUE,
+ (LPARAM)GetHiconOf(icon));
+ }
+ }
+ }
+#endif // __WIN95__
+
+
+ // JACS: is the following still necessary? The above seems to work.
+
// ::SetWindowLong(GWL_EXSTYLE) doesn't work for the dialogs, so try
// to take care of (at least some) extended style flags ourselves
if ( extendedStyle & WS_EX_TOPMOST )
wxLogLastError(wxT("MoveWindow"));
}
}
- else
+ else // creating a normal window, not a dialog
{
int controlId = 0;
if ( style & WS_CHILD )
}
wxWndHook = NULL;
+
#ifdef __WXDEBUG__
wxNode* node = wxWinHandleList->Member(this);
if (node)
wxLogError(wxT("A second HWND association is being added for the same window!"));
}
}
-#endif
+#endif // Debug
+
wxAssociateWinWithHandle((HWND) m_hWnd, this);
return TRUE;
return GetEventHandler()->ProcessEvent(event);
}
+#if wxUSE_SPINCTRL
+ else
+ {
+ // the text ctrl which is logically part of wxSpinCtrl sends WM_COMMAND
+ // notifications to its parent which we want to reflect back to
+ // wxSpinCtrl
+ wxSpinCtrl *spin = wxSpinCtrl::GetSpinForTextCtrl(control);
+ if ( spin && spin->ProcessTextCommand(cmd, id) )
+ return TRUE;
+ }
+#endif // wxUSE_SPINCTRL
return FALSE;
}
event.m_leftDown = ((flags & MK_LBUTTON) != 0);
event.m_middleDown = ((flags & MK_MBUTTON) != 0);
event.m_rightDown = ((flags & MK_RBUTTON) != 0);
- event.m_altDown = ::GetKeyState(VK_MENU) & 0x80000000;
+ event.m_altDown = (::GetKeyState(VK_MENU) & 0x80000000) != 0;
event.SetTimestamp(s_currentMsg.time);
event.m_eventObject = this;
return tm;
}
+
+// Find the wxWindow at the current mouse position, returning the mouse
+// position.
+wxWindow* wxFindWindowAtPointer(wxPoint& pt)
+{
+ return wxFindWindowAtPoint(wxGetMousePosition());
+}
+
+wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
+{
+ POINT pt2;
+ pt2.x = pt.x;
+ pt2.y = pt.y;
+ HWND hWndHit = ::WindowFromPoint(pt2);
+
+ wxWindow* win = wxFindWinFromHandle((WXHWND) hWndHit) ;
+ HWND hWnd = hWndHit;
+
+ // Try to find a window with a wxWindow associated with it
+ while (!win && (hWnd != 0))
+ {
+ hWnd = ::GetParent(hWnd);
+ win = wxFindWinFromHandle((WXHWND) hWnd) ;
+ }
+ return win;
+}
+
+// Get the current mouse position.
+wxPoint wxGetMousePosition()
+{
+ POINT pt;
+ GetCursorPos( & pt );
+ return wxPoint(pt.x, pt.y);
+}
+