static TEXTMETRIC wxGetTextMetrics(const wxWindowMSW *win);
// find the window for the mouse event at the specified position
-static wxWindowMSW *FindWindowForMouseEvent(wxWindow *win, int *x, int *y);
+static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y); //TW:REQ:Univ
// wrapper around BringWindowToTop() API
static inline void wxBringWindowToTop(HWND hwnd)
InitBase();
// MSW specific
- m_doubleClickAllowed = 0;
-
m_isBeingDeleted = FALSE;
- m_oldWndProc = 0;
+ m_oldWndProc = NULL;
m_useCtl3D = FALSE;
m_mouseInWindow = FALSE;
m_lastKeydownProcessed = FALSE;
// 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);
+ wxTopLevelWindow *frame = wxDynamicCast(win, wxTopLevelWindow);
if ( frame )
{
if ( frame->GetLastFocus() == this )
{
- frame->SetLastFocus((wxWindow*)NULL);
+ frame->SetLastFocus(NULL);
}
break;
}
#ifdef __WXUNIVERSAL__
// no borders, we draw them ourselves
- exstyle = 0;
+ exstyle &= ~(WS_EX_DLGMODALFRAME |
+ WS_EX_STATICEDGE |
+ WS_EX_CLIENTEDGE |
+ WS_EX_WINDOWEDGE);
msflags &= ~WS_BORDER;
#endif // wxUniversal
msflags |= WS_VISIBLE;
}
- return MSWCreate(wxCanvasClassName, NULL, pos, size, msflags, exstyle);
+ bool retVal = MSWCreate(wxCanvasClassName, NULL, pos, size, msflags, exstyle);
+ if (retVal)
+ SetWindowLong( (HWND)m_hWnd, GWL_WNDPROC, (LONG)wxWndProc);
+ return retVal;
}
// ---------------------------------------------------------------------------
}
else
{
- // don't bother restoring it neither
+ // don't bother restoring it neither: this also makes it easy to
+ // implement IsOfStandardClass() method which returns TRUE for the
+ // standard controls and FALSE for the wxWindows own windows as it can
+ // simply check m_oldWndProc
m_oldWndProc = NULL;
}
}
*exstyle |= WS_EX_DLGMODALFRAME;
break;
}
+
+ // wxUniv doesn't use Windows dialog navigation functions at all
+#ifndef __WXUNIVERSAL__
+ // to make the dialog navigation work with the nested panels we must
+ // use this style (top level windows such as dialogs don't need it)
+ if ( (flags & wxTAB_TRAVERSAL) && !IsTopLevel() )
+ {
+ *exstyle |= WS_EX_CONTROLPARENT;
+ }
+#endif // __WXUNIVERSAL__
}
return style;
// here we try to do all the job which ::IsDialogMessage() usually does
// internally
#if 1
- bool bProcess = TRUE;
- if ( msg->message != WM_KEYDOWN )
- bProcess = FALSE;
-
- if ( bProcess && (HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN )
- bProcess = FALSE;
-
- if ( bProcess )
+ if ( msg->message == WM_KEYDOWN )
{
bool bCtrlDown = wxIsCtrlDown();
bool bShiftDown = wxIsShiftDown();
bool bForward = TRUE,
bWindowChange = FALSE;
+ // should we process this message specially?
+ bool bProcess = TRUE;
switch ( msg->wParam )
{
case VK_TAB:
return TRUE;
}
- //else: no default button
+ else // no default button
+ {
#endif // wxUSE_BUTTON
- // treat Enter as TAB: pass to the next control
+ // this is a quick and dirty test for a text
+ // control
+ if ( !(lDlgCode & DLGC_HASSETSEL) )
+ {
+ // don't process Enter, the control might
+ // need it for itself and don't let
+ // ::IsDialogMessage() have it as it can
+ // eat the Enter events sometimes
+ return FALSE;
+ }
+ //else: treat Enter as TAB: pass to the next
+ // control as this is the best thing to do
+ // if the text doesn't handle Enter itself
+ }
}
}
break;
// place edit control from being closed with Escape in a dialog
if ( msg->message != WM_KEYDOWN || msg->wParam != VK_ESCAPE )
{
- if ( ::IsDialogMessage(GetHwnd(), msg) )
+ // ::IsDialogMessage() can enter in an infinite loop when the
+ // currently focused window is disabled or hidden and its parent
+ // has WS_EX_CONTROLPARENT style, so don't call it in this case
+ bool canSafelyCallIsDlgMsg = TRUE;
+
+ HWND hwndFocus = ::GetFocus();
+ while ( hwndFocus )
+ {
+ if ( !::IsWindowEnabled(hwndFocus) ||
+ !::IsWindowVisible(hwndFocus) )
+ {
+ // it would enter an infinite loop if we do this!
+ canSafelyCallIsDlgMsg = FALSE;
+
+ break;
+ }
+
+ if ( !(::GetWindowLong(hwndFocus, GWL_STYLE) & WS_CHILD) )
+ {
+ // it's a top level window, don't go further -- e.g. even
+ // if the parent of a dialog is disabled, this doesn't
+ // break navigation inside the dialog
+ break;
+ }
+
+ hwndFocus = ::GetParent(hwndFocus);
+ }
+
+ if ( canSafelyCallIsDlgMsg && ::IsDialogMessage(GetHwnd(), msg) )
{
// IsDialogMessage() did something...
return TRUE;
break;
}
- if (!processed)
-#endif // __WXMICROWIN__
- {
- // VZ: why do we need it here? DefWindowProc() is supposed
- // to do this for us anyhow
- if ( message == WM_LBUTTONDOWN && AcceptsFocus() )
- SetFocus();
+ if ( processed )
+ break;
- int x = GET_X_LPARAM(lParam),
- y = GET_Y_LPARAM(lParam);
+#endif // __WXMICROWIN__
+ // VZ: if you find a situation when this is needed, tell
+ // me about it, do *not* uncomment this code as it
+ // causes other strange problems
+#if 0
+ if ( message == WM_LBUTTONDOWN && AcceptsFocus() )
+ SetFocus();
+#endif // 0
- // redirect the event to a static control if necessary
- wxWindow *win = FindWindowForMouseEvent(this, &x, &y);
+ int x = GET_X_LPARAM(lParam),
+ y = GET_Y_LPARAM(lParam);
- processed = win->HandleMouseEvent(message, x, y, wParam);
+ // redirect the event to a static control if necessary by
+ // finding one under mouse
+ wxWindowMSW *win;
+ if ( GetCapture() == this )
+ {
+ // but don't do it if the mouse is captured by this window
+ // because then it should really get this event itself
+ win = this;
+ }
+ else
+ {
+ win = FindWindowForMouseEvent(this, &x, &y);
}
+
+ processed = win->HandleMouseEvent(message, x, y, wParam);
}
break;
#endif // defined(WM_DRAWITEM)
case WM_GETDLGCODE:
- if ( GetWindowStyleFlag() & wxWANTS_CHARS )
+ if ( !IsOfStandardClass() )
{
- // want everything: i.e. all keys and WM_CHAR message
- rc.result = DLGC_WANTARROWS | DLGC_WANTCHARS |
- DLGC_WANTTAB | DLGC_WANTMESSAGE;
+ // we always want to get the char events
+ rc.result = DLGC_WANTCHARS;
+
+ if ( GetWindowStyleFlag() & wxWANTS_CHARS )
+ {
+ // in fact, we want everything
+ rc.result |= DLGC_WANTARROWS |
+ DLGC_WANTTAB |
+ DLGC_WANTALLKEYS;
+ }
+
processed = TRUE;
}
//else: get the dlg code from the DefWindowProc()
return nonDefault;
}
+WXHWND wxWindowMSW::MSWGetParent() const
+{
+ return m_parent ? m_parent->GetHWND() : WXHWND(NULL);
+}
+
bool wxWindowMSW::MSWCreate(const wxChar *wclass,
const wxChar *title,
const wxPoint& pos,
int x, y, w, h;
(void)MSWGetCreateWindowCoords(pos, size, x, y, w, h);
- // find the correct parent HWND
- wxWindow *parent = GetParent();
- bool isChild = (style & WS_CHILD) != 0;
- HWND hParent;
- if ( GetWindowStyleFlag() & wxPOPUP_WINDOW )
- {
- // popup windows should have desktop as parent because they shouldn't
- // be limited to the parents client area as child windows usually are
- hParent = ::GetDesktopWindow();
- }
- else // !popup
- {
- if ( (isChild || HasFlag(wxFRAME_TOOL_WINDOW)) && parent )
- {
- // this is either a normal child window or a top level window with
- // wxFRAME_TOOL_WINDOW style (see below)
- hParent = GetHwndOf(parent);
- }
- else
- {
- // this is either a window for which no parent was specified (not
- // much we can do then) or a frame without wxFRAME_TOOL_WINDOW
- // style: we should use NULL parent HWND for it or it would be
- // always on top of its parent which is not what we usually want
- // (in fact, we only want it for frames with the special
- // wxFRAME_TOOL_WINDOW as above)
- hParent = NULL;
- }
-
- }
-
// controlId is menu handle for the top level windows, so set it to 0
// unless we're creating a child window
- int controlId;
- if ( isChild )
- {
- controlId = GetId();
-
- if ( GetWindowStyleFlag() & wxCLIP_SIBLINGS )
- {
- style |= WS_CLIPSIBLINGS;
- }
- }
- else // !child
- {
- controlId = 0;
- }
+ int controlId = style & WS_CHILD ? GetId() : 0;
// for each class "Foo" we have we also have "FooNR" ("no repaint") class
// which is the same but without CS_[HV]REDRAW class styles so using it
wxWindowCreationHook hook(this);
m_hWnd = (WXHWND)::CreateWindowEx
- (
- extendedStyle,
- className,
- title ? title : wxT(""),
- style,
- x, y, w, h,
- hParent,
- (HMENU)controlId,
- wxGetInstance(),
- NULL // no extra data
- );
+ (
+ extendedStyle,
+ className,
+ title ? title : wxT(""),
+ style,
+ x, y, w, h,
+ (HWND)MSWGetParent(),
+ (HMENU)controlId,
+ wxGetInstance(),
+ NULL // no extra data
+ );
if ( !m_hWnd )
{
// ---------------------------------------------------------------------------
#ifdef __WIN95__
-// FIXME: VZ: I'm not sure at all that the order of processing is correct
+
bool wxWindowMSW::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
{
#ifndef __WXMICROWIN__
HWND hWnd = hdr->hwndFrom;
wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd);
- // is this one of our windows?
+ // if the control is one of our windows, let it handle the message itself
if ( win )
{
return win->MSWOnNotify(idCtrl, lParam, result);
}
+ // VZ: why did we do it? normally this is unnecessary and, besides, it
+ // breaks the message processing for the toolbars because the tooltip
+ // notifications were being forwarded to the toolbar child controls
+ // (if it had any) before being passed to the toolbar itself, so in my
+ // example the tooltip for the combobox was always shown instead of the
+ // correct button tooltips
+#if 0
// try all our children
wxWindowList::Node *node = GetChildren().GetFirst();
while ( node )
node = node->GetNext();
}
+#endif // 0
- // finally try this window too (catches toolbar case)
+ // by default, handle it ourselves
return MSWOnNotify(idCtrl, lParam, result);
#else // __WXMICROWIN__
return FALSE;
#endif
}
+#if wxUSE_TOOLTIPS
+
+bool wxWindowMSW::HandleTooltipNotify(WXUINT code,
+ WXLPARAM lParam,
+ const wxString& ttip)
+{
+ // I don't know why it happens, but the versions of comctl32.dll starting
+ // from 4.70 sometimes send TTN_NEEDTEXTW even to ANSI programs (normally,
+ // this message is supposed to be sent to Unicode programs only) -- hence
+ // we need to handle it as well, otherwise no tooltips will be shown in
+ // this case
+
+ if ( !(code == (WXUINT) TTN_NEEDTEXTA || code == (WXUINT) TTN_NEEDTEXTW) || ttip.empty() )
+ {
+ // not a tooltip message or no tooltip to show anyhow
+ return FALSE;
+ }
+
+ LPTOOLTIPTEXT ttText = (LPTOOLTIPTEXT)lParam;
+
+ if ( code == (WXUINT) TTN_NEEDTEXTA )
+ {
+ ttText->lpszText = (wxChar *)ttip.c_str();
+ }
+ else
+ {
+#if wxUSE_UNICODE
+ ttText->lpszText = (wxChar *)ttip.c_str();
+#else // !Unicode
+ size_t lenAnsi = ttip.length();
+
+ // some compilers (MetroWerks and Cygwin) don't like calling mbstowcs
+ // with NULL argument
+ #if defined( __MWERKS__ ) || defined( __CYGWIN__ )
+ size_t lenUnicode = 2*lenAnsi;
+ #else
+ size_t lenUnicode = mbstowcs(NULL, ttip, lenAnsi);
+ #endif
+
+ // using the pointer of right type avoids us doing all sorts of
+ // pointer arithmetics ourselves
+ wchar_t *dst = (wchar_t *)ttText->szText,
+ *pwz = new wchar_t[lenUnicode + 1];
+ mbstowcs(pwz, ttip, lenAnsi + 1);
+ memcpy(dst, pwz, lenUnicode*sizeof(wchar_t));
+
+ // put the terminating wide NUL
+ dst[lenUnicode] = L'\0';
+
+ delete [] pwz;
+#endif // Unicode/!Unicode
+ }
+
+ return TRUE;
+}
+
+#endif // wxUSE_TOOLTIPS
+
bool wxWindowMSW::MSWOnNotify(int WXUNUSED(idCtrl),
- WXLPARAM lParam,
- WXLPARAM* WXUNUSED(result))
+ WXLPARAM lParam,
+ WXLPARAM* WXUNUSED(result))
{
#if wxUSE_TOOLTIPS
- NMHDR* hdr = (NMHDR *)lParam;
- if ( (int)hdr->code == TTN_NEEDTEXT && m_tooltip )
+ if ( m_tooltip )
{
- TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
- ttt->lpszText = (wxChar *)m_tooltip->GetTip().c_str();
-
- // processed
- return TRUE;
+ NMHDR* hdr = (NMHDR *)lParam;
+ if ( HandleTooltipNotify(hdr->code, lParam, m_tooltip->GetTip()))
+ {
+ // processed
+ return TRUE;
+ }
}
#endif // wxUSE_TOOLTIPS
return FALSE;
}
+
#endif // __WIN95__
// ---------------------------------------------------------------------------
// window creation/destruction
// ---------------------------------------------------------------------------
-bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT WXUNUSED(cs), bool *mayCreate)
+bool wxWindowMSW::HandleCreate(WXLPCREATESTRUCT cs, bool *mayCreate)
{
+ // if we have WS_EX_CONTROLPARENT flag we absolutely *must* set it for our
+ // parent as well as otherwise several Win32 functions using
+ // GetNextDlgTabItem() to iterate over all controls such as
+ // IsDialogMessage() or DefDlgProc() would enter an infinite loop: indeed,
+ // all of them iterate over all the controls starting from the focus and
+ // stop iterating when they get back to the focus but unless all parents
+ // have WS_EX_CONTROLPARENT bit set, they would never get back to focus
+ if ( ((CREATESTRUCT *)cs)->dwExStyle & WS_EX_CONTROLPARENT )
+ {
+ // there is no need to do anything for the top level windows
+ const wxWindow *parent = GetParent();
+ while ( parent && !parent->IsTopLevel() )
+ {
+ LONG exStyle = ::GetWindowLong(GetHwndOf(parent), GWL_EXSTYLE);
+ if ( !(exStyle & WS_EX_CONTROLPARENT) )
+ {
+ // force the parent to have this style
+ ::SetWindowLong(GetHwndOf(parent), GWL_EXSTYLE,
+ exStyle | WS_EX_CONTROLPARENT);
+ }
+
+ parent = parent->GetParent();
+ }
+ }
+
// TODO: should generate this event from WM_NCCREATE
wxWindowCreateEvent event((wxWindow *)this);
(void)GetEventHandler()->ProcessEvent(event);
if ( hWndPalChange != GetHWND() )
{
// check to see if we our our parents have a custom palette
- wxWindow *win = this;
+ wxWindowMSW *win = this;
while ( win && !win->HasCustomPalette() )
{
win = win->GetParent();
#if wxUSE_PALETTE
// check to see if we our our parents have a custom palette
- wxWindow *win = this;
+ wxWindowMSW *win = this;
while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent();
if (win->HasCustomPalette()) {
/* realize the palette to see whether redrawing is needed */
event.SetTimestamp(s_currentMsg.time);
event.m_eventObject = this;
+ event.SetId(GetId());
#if wxUSE_MOUSEEVENT_HACK
m_lastMouseX = x;
// Notice that this is not done for the mouse move events because this could
// (would?) be too slow, but only for clicks which means that the static texts
// still don't get move, enter nor leave events.
-static wxWindowMSW *FindWindowForMouseEvent(wxWindow *win, int *x, int *y)
+static wxWindowMSW *FindWindowForMouseEvent(wxWindowMSW *win, int *x, int *y) //TW:REQ:Univ
{
wxCHECK_MSG( x && y, win, _T("NULL pointer in FindWindowForMouseEvent") );