#include "wx/listbox.h"
#include "wx/button.h"
#include "wx/msgdlg.h"
+ #include "wx/settings.h"
#include <stdio.h>
#endif
#define SIF_TRACKPOS 16
#endif
+#if wxUSE_MOUSEWHEEL
+ #ifndef WM_MOUSEWHEEL
+ #define WM_MOUSEWHEEL 0x020A
+ #endif
+ #ifndef WHEEL_DELTA
+ #define WHEEL_DELTA 120
+ #endif
+ #ifndef SPI_GETWHEELSCROLLLINES
+ #define SPI_GETWHEELSCROLLLINES 104
+ #endif
+#endif
+
+
// ---------------------------------------------------------------------------
// global variables
// ---------------------------------------------------------------------------
// Find an item given the MS Windows id
wxWindow *wxWindow::FindItem(long id) const
{
- wxControl *item = wxDynamicCast(this, wxControl);
+ wxControl *item = wxDynamicThisCast(this, wxControl);
if ( item )
{
// i it we or one of our "internal" children?
m_isBeingDeleted = TRUE;
MSWDetachWindowMenu();
+
+ // VS: make sure there's no wxFrame with last focus set to us:
+ for (wxWindow *win = GetParent(); win; win = win->GetParent())
+ {
+ wxFrame *frame = wxDynamicCast(win, wxFrame);
+ if ( frame )
+ {
+ if ( frame->GetLastFocus() == this )
+ frame->SetLastFocus((wxWindow*)NULL);
+ break;
+ }
+ }
if ( m_parent )
m_parent->RemoveChild(this);
DLGC_WANTTAB | DLGC_WANTMESSAGE;
}
- MSWCreate(m_windowId, parent, wxCanvasClassName, this, NULL,
- pos.x, pos.y,
- WidthDefault(size.x), HeightDefault(size.y),
- msflags, NULL, exStyle);
-
- return TRUE;
+ return MSWCreate(m_windowId, parent, wxCanvasClassName, this, NULL,
+ pos.x, pos.y,
+ WidthDefault(size.x), HeightDefault(size.y),
+ msflags, NULL, exStyle);
}
// ---------------------------------------------------------------------------
HWND hWnd = ::GetFocus();
if ( hWnd )
{
- return wxFindWinFromHandle((WXHWND) hWnd);
+ return wxGetWindowFromHWND((WXHWND)hWnd);
}
return NULL;
// VZ: no, this is a bad idea: imagine that you have a dialog with some
// disabled controls and disable it - you really wouldn't like the
- // disabled controls eb reenabled too when you reenable the dialog!
+ // disabled controls be reenabled too when you reenable the dialog!
#if 0
wxWindowList::Node *node = GetChildren().GetFirst();
while ( node )
SetBackgroundColour(GetParent()->GetBackgroundColour());
}
-void wxWindow::OnIdle(wxIdleEvent& event)
+void wxWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
{
// Check if we need to send a LEAVE event
if ( m_mouseInWindow )
state |= MK_MBUTTON;
if ( GetKeyState( VK_RBUTTON ) )
state |= MK_RBUTTON;
-
+
wxMouseEvent event(wxEVT_LEAVE_WINDOW);
InitMouseEvent(event, pt.x, pt.y, state);
}
// Set this window to be the child of 'parent'.
-bool wxWindow::Reparent(wxWindow *parent)
+bool wxWindow::Reparent(wxWindowBase *parent)
{
if ( !wxWindowBase::Reparent(parent) )
return FALSE;
}
else
{
- wxPanel *panel = wxDynamicCast(this, wxPanel);
+ wxPanel *panel = wxDynamicThisCast(this, wxPanel);
wxButton *btn = NULL;
if ( panel )
{
wParam);
break;
+#if wxUSE_MOUSEWHEEL
+ case WM_MOUSEWHEEL:
+ processed = HandleMouseWheel(wParam, lParam);
+ break;
+#endif
+
case WM_LBUTTONDOWN:
// set focus to this window
if (AcceptsFocus())
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)
+ 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) );
+ 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, subjectOfHelp->GetId(), wxPoint(info->MousePos.x, info->MousePos.y) ) ; // info->iCtrlId);
+ wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
helpEvent.SetEventObject(this);
- eventProcessed = GetEventHandler()->ProcessEvent(helpEvent);
+ processed = GetEventHandler()->ProcessEvent(helpEvent);
- // Go up the window hierarchy until the event is handled (or not)
- subjectOfHelp = subjectOfHelp->GetParent();
}
- processed = eventProcessed;
+ //else: processed is already FALSE
}
- else if (info->iContextType == HELPINFO_MENUITEM)
+ break;
+
+ case WM_CONTEXTMENU:
{
- wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId) ;
- helpEvent.SetEventObject(this);
- processed = GetEventHandler()->ProcessEvent(helpEvent);
+ // we don't convert from screen to client coordinates as
+ // the event may be handled by a parent window
+ wxPoint pt(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
+
+ wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, GetId(), pt);
+ GetEventHandler()->ProcessEvent(evtCtx);
+
+ // set processed to true even if the event is not handled
+ // because if we don't windows will propogate the
+ // WM_CONTEXTMENU up the parent window chain, which we have
+ // already done ourselves.
+ processed = true;
}
- else processed = FALSE;
break;
- }
-#endif
+#endif // __WIN32__
}
if ( !processed )
// Dialog window proc
LONG APIENTRY _EXPORT
-wxDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
+wxDlgProc(HWND WXUNUSED(hWnd), UINT message, WPARAM WXUNUSED(wParam), LPARAM WXUNUSED(lParam))
{
if ( message == WM_INITDIALOG )
{
bool wxWindow::MSWCreate(int id,
wxWindow *parent,
const wxChar *wclass,
- wxWindow *wx_win,
+ wxWindow *WXUNUSED(wx_win),
const wxChar *title,
int x,
int y,
height1 = parent_rect.bottom - parent_rect.top;
}
- if ( x > -1 ) x1 = x;
- if ( y > -1 ) y1 = y;
- if ( width > -1 ) width1 = width;
- if ( height > -1 ) height1 = height;
+ if ( x != -1 )
+ x1 = x;
+ if ( y != -1 )
+ y1 = y;
+ if ( width != -1 )
+ width1 = width;
+ if ( height != -1 )
+ height1 = height;
// unfortunately, setting WS_EX_CONTROLPARENT only for some windows in the
// hierarchy with several embedded panels (and not all of them) causes the
{
int controlId = 0;
if ( style & WS_CHILD )
- {
controlId = id;
- // all child windows should clip their siblings
- // style |= /* WS_CLIPSIBLINGS */ ;
- }
+
+ if ( GetWindowStyleFlag() & wxCLIP_SIBLINGS )
+ style |= WS_CLIPSIBLINGS;
wxString className(wclass);
if ( GetWindowStyleFlag() & wxNO_FULL_REPAINT_ON_RESIZE )
wxAssociateWinWithHandle((HWND) m_hWnd, this);
+ SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
+
return TRUE;
}
// window creation/destruction
// ---------------------------------------------------------------------------
-bool wxWindow::HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate)
+bool wxWindow::HandleCreate(WXLPCREATESTRUCT WXUNUSED(cs), bool *mayCreate)
{
// TODO: should generate this event from WM_NCCREATE
wxWindowCreateEvent event(this);
// miscellaneous
// ---------------------------------------------------------------------------
-bool wxWindow::HandleShow(bool show, int status)
+bool wxWindow::HandleShow(bool show, int WXUNUSED(status))
{
wxShowEvent event(GetId(), show);
event.m_eventObject = this;
return rc;
}
-bool wxWindow::HandleSetCursor(WXHWND hWnd,
+bool wxWindow::HandleSetCursor(WXHWND WXUNUSED(hWnd),
short nHitTest,
int WXUNUSED(mouseMsg))
{
wxCHECK( pMenuItem->IsKindOf(CLASSINFO(wxMenuItem)), FALSE );
- // prepare to call OnDrawItem()
- wxDC dc;
- dc.SetHDC((WXHDC)pDrawStruct->hDC, FALSE);
+ // prepare to call OnDrawItem(): notice using of wxDCTemp to prevent
+ // the DC from being released
+ wxDCTemp dc((WXHDC)pDrawStruct->hDC);
wxRect rect(pDrawStruct->rcItem.left, pDrawStruct->rcItem.top,
pDrawStruct->rcItem.right - pDrawStruct->rcItem.left,
pDrawStruct->rcItem.bottom - pDrawStruct->rcItem.top);
return pMenuItem->OnDrawItem
- (
- dc, rect,
- (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
- (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
- );
+ (
+ dc,
+ rect,
+ (wxOwnerDrawn::wxODAction)pDrawStruct->itemAction,
+ (wxOwnerDrawn::wxODStatus)pDrawStruct->itemState
+ );
}
wxWindow *item = FindItem(id);
}
// Define for each class of dialog and control
-WXHBRUSH wxWindow::OnCtlColor(WXHDC hDC,
- WXHWND hWnd,
- WXUINT nCtlColor,
- WXUINT message,
- WXWPARAM wParam,
- WXLPARAM lParam)
+WXHBRUSH wxWindow::OnCtlColor(WXHDC WXUNUSED(hDC),
+ WXHWND WXUNUSED(hWnd),
+ WXUINT WXUNUSED(nCtlColor),
+ WXUINT WXUNUSED(message),
+ WXWPARAM WXUNUSED(wParam),
+ WXLPARAM WXUNUSED(lParam))
{
return (WXHBRUSH)0;
}
if ( ::IsIconic(GetHwnd()) )
return TRUE;
- wxDC dc;
+ wxDCTemp dc(hdc);
- dc.SetHDC(hdc);
dc.SetWindow(this);
dc.BeginDrawing();
bool rc = GetEventHandler()->ProcessEvent(event);
dc.EndDrawing();
+
+ // must be called manually as ~wxDC doesn't do anything for wxDCTemp
dc.SelectOldObjects(hdc);
- dc.SetHDC((WXHDC) NULL);
return rc;
}
return FALSE;
}
-bool wxWindow::HandleSysCommand(WXWPARAM wParam, WXLPARAM lParam)
+bool wxWindow::HandleSysCommand(WXWPARAM wParam, WXLPARAM WXUNUSED(lParam))
{
// 4 bits are reserved
switch ( wParam & 0xFFFFFFF0 )
if ( (m_lastMouseEvent == wxEVT_RIGHT_DOWN ||
m_lastMouseEvent == wxEVT_LEFT_DOWN ||
m_lastMouseEvent == wxEVT_MIDDLE_DOWN) &&
- (m_lastMouseX == event.m_x && m_lastMouseY == event.m_y) )
+ (m_lastMouseX == x && m_lastMouseY == y) )
{
m_lastMouseEvent = wxEVT_MOTION;
return HandleMouseEvent(WM_MOUSEMOVE, x, y, flags);
}
+
+bool wxWindow::HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam)
+{
+#if wxUSE_MOUSEWHEEL
+ wxMouseEvent event(wxEVT_MOUSEWHEEL);
+ InitMouseEvent(event,
+ GET_X_LPARAM(lParam),
+ GET_Y_LPARAM(lParam),
+ LOWORD(wParam));
+ event.m_wheelRotation = (short)HIWORD(wParam);
+ event.m_wheelDelta = WHEEL_DELTA;
+
+#ifdef __WIN32__
+ static int s_linesPerRotation = -1;
+ if ( s_linesPerRotation == -1 )
+ {
+ if ( !::SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0,
+ &s_linesPerRotation, 0))
+ {
+ // this is not supposed to happen
+ wxLogLastError(_T("SystemParametersInfo(GETWHEELSCROLLLINES)"));
+
+ // the default is 3, so use it if SystemParametersInfo() failed
+ s_linesPerRotation = 3;
+ }
+ }
+#else // Win16
+ // no SystemParametersInfo() under Win16
+ static const int s_linesPerRotation = 3;
+#endif
+
+ event.m_linesPerAction = s_linesPerRotation;
+ return GetEventHandler()->ProcessEvent(event);
+
+#else
+ return FALSE;
+#endif
+}
+
+
// ---------------------------------------------------------------------------
// keyboard handling
// ---------------------------------------------------------------------------
// isASCII is TRUE only when we're called from WM_CHAR handler and not from
// WM_KEYDOWN one
-bool wxWindow::HandleChar(WXWORD wParam, WXLPARAM lParam, bool isASCII)
+bool wxWindow::HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII)
{
bool ctrlDown = FALSE;
return FALSE;
}
-bool wxWindow::HandleKeyDown(WXWORD wParam, WXLPARAM lParam)
+bool wxWindow::HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam)
{
int id = wxCharCodeMSWToWX(wParam);
return FALSE;
}
-bool wxWindow::HandleKeyUp(WXWORD wParam, WXLPARAM lParam)
+bool wxWindow::HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam)
{
int id = wxCharCodeMSWToWX(wParam);
win = wxFindWinFromHandle((WXHWND)hwnd);
if ( !win )
{
- // the radiobox pointer is stored in GWL_USERDATA only under Win32
+ // all these hacks only work under Win32 anyhow
#ifdef __WIN32__
+
+#if wxUSE_RADIOBOX
// native radiobuttons return DLGC_RADIOBUTTON here and for any
// wxWindow class which overrides WM_GETDLGCODE processing to
// do it as well, win would be already non NULL
- if ( ::SendMessage((HWND)hwnd, WM_GETDLGCODE,
- 0, 0) & DLGC_RADIOBUTTON )
+ if ( ::SendMessage(hwnd, WM_GETDLGCODE, 0, 0) & DLGC_RADIOBUTTON )
{
win = (wxWindow *)::GetWindowLong(hwnd, GWL_USERDATA);
}
- else
+ //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
+#endif // wxUSE_RADIOBOX
+
+ // spin control text buddy window should be mapped to spin ctrl
+ // itself so try it too
+#if wxUSE_SPINCTRL
+ if ( !win )
+ {
+ win = wxSpinCtrl::GetSpinForTextCtrl((WXHWND)hwnd);
+ }
+#endif // wxUSE_SPINCTRL
+
#endif // Win32
+
+ if ( !win )
{
// hwnd is not a wxWindow, try its parent next below
hwnd = ::GetParent(hwnd);
}
}
- //else: it's a wxRadioButton, not a radiobutton from wxRadioBox
}
while ( hwnd && !win )
else
{
UnhookWindowsHookEx(wxTheKeyboardHook);
- // avoids mingw warning about statement with no effect (FreeProcInstance
+
+ // avoids warning about statement with no effect (FreeProcInstance
// doesn't do anything under Win32)
-#ifndef __GNUC__
+#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32__) && !defined(__NT__) && !defined(__GNUWIN32__)
FreeProcInstance(wxTheKeyboardHookProc);
#endif
}
case 0x0207: return "WM_MBUTTONDOWN";
case 0x0208: return "WM_MBUTTONUP";
case 0x0209: return "WM_MBUTTONDBLCLK";
+ case 0x020A: return "WM_MOUSEWHEEL";
case 0x0210: return "WM_PARENTNOTIFY";
case 0x0211: return "WM_ENTERMENULOOP";
case 0x0212: return "WM_EXITMENULOOP";
// Find the wxWindow at the current mouse position, returning the mouse
// position.
-wxWindow* wxFindWindowAtPointer(wxPoint& pt)
+wxWindow* wxFindWindowAtPointer(wxPoint& WXUNUSED(pt))
{
return wxFindWindowAtPoint(wxGetMousePosition());
}