#ifndef WX_PRECOMP
#include <windows.h>
#include "wx/msw/winundef.h"
+ #include "wx/window.h"
#include "wx/accel.h"
#include "wx/setup.h"
#include "wx/menu.h"
wxMenu *wxCurrentPopupMenu = NULL;
extern wxList WXDLLEXPORT wxPendingDelete;
-extern char wxCanvasClassName[];
-
-#ifdef __WXDEBUG__
- // see comments in dcclient.cpp where g_isPainting is defined
- extern bool g_isPainting;
-
- inline static void wxStartPainting() { g_isPainting = TRUE; }
- inline static void wxEndPainting() { g_isPainting = FALSE; }
-#else // !debug
- inline static void wxStartPainting() { }
- inline static void wxEndPainting() { }
-#endif // debug/!debug
+extern wxChar wxCanvasClassName[];
// ---------------------------------------------------------------------------
// private functions
// wxWnd
m_hMenu = 0;
+ m_hWnd = 0;
+
+ // pass WM_GETDLGCODE to DefWindowProc()
+ m_lDlgCode = 0;
+
m_xThumbSize = 0;
m_yThumbSize = 0;
m_backgroundTransparent = FALSE;
{
if ( !::DestroyWindow(GetHwnd()) )
wxLogLastError("DestroyWindow");
- }
- // Restore old Window proc, if required and remove hWnd <-> wxWindow
- // association
- UnsubclassWin();
+ // remove hWnd <-> wxWindow association
+ wxRemoveHandleAssociation(this);
+ }
}
// real construction (Init() must have been called before!)
long style,
const wxString& name)
{
- wxCHECK_MSG( parent, FALSE, "can't create wxWindow without parent" );
+ wxCHECK_MSG( parent, FALSE, _T("can't create wxWindow without parent") );
CreateBase(parent, id, pos, size, style, name);
msflags |= WS_BORDER;
}
+ // calculate the value to return from WM_GETDLGCODE handler
+ if ( GetWindowStyleFlag() & wxWANTS_CHARS )
+ {
+ // want everything: i.e. all keys and WM_CHAR message
+ m_lDlgCode = DLGC_WANTARROWS | DLGC_WANTCHARS |
+ DLGC_WANTTAB | DLGC_WANTMESSAGE;
+ }
+
MSWCreate(m_windowId, parent, wxCanvasClassName, this, NULL,
pos.x, pos.y,
WidthDefault(size.x), HeightDefault(size.y),
wxASSERT_MSG( hFont, _T("should have valid font") );
- ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, TRUE);
+ ::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
}
return TRUE;
void wxWindow::SubclassWin(WXHWND hWnd)
{
- wxASSERT_MSG( !m_oldWndProc, "subclassing window twice?" );
+ wxASSERT_MSG( !m_oldWndProc, _T("subclassing window twice?") );
+
+ HWND hwnd = (HWND)hWnd;
+ wxCHECK_RET( ::IsWindow(hwnd), _T("invalid HWND in SubclassWin") );
- wxAssociateWinWithHandle((HWND)hWnd, this);
+ wxAssociateWinWithHandle(hwnd, this);
- m_oldWndProc = (WXFARPROC) GetWindowLong((HWND) hWnd, GWL_WNDPROC);
- SetWindowLong((HWND) hWnd, GWL_WNDPROC, (LONG) wxWndProc);
+ m_oldWndProc = (WXFARPROC) GetWindowLong(hwnd, GWL_WNDPROC);
+ SetWindowLong(hwnd, GWL_WNDPROC, (LONG) wxWndProc);
}
void wxWindow::UnsubclassWin()
wxRemoveHandleAssociation(this);
// Restore old Window proc
- if ( GetHwnd() )
+ HWND hwnd = GetHwnd();
+ if ( hwnd )
{
- FARPROC farProc = (FARPROC) GetWindowLong(GetHwnd(), GWL_WNDPROC);
+ m_hWnd = 0;
+
+ wxCHECK_RET( ::IsWindow(hwnd), _T("invalid HWND in SubclassWin") );
+
+ FARPROC farProc = (FARPROC) GetWindowLong(hwnd, GWL_WNDPROC);
if ( (m_oldWndProc != 0) && (farProc != (FARPROC) m_oldWndProc) )
{
- SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG) m_oldWndProc);
+ SetWindowLong(hwnd, GWL_WNDPROC, (LONG) m_oldWndProc);
m_oldWndProc = 0;
}
-
- m_hWnd = 0;
}
}
return exStyle;
}
-#if WXWIN_COMPATIBILITY_2
+#if WXWIN_COMPATIBILITY
// If nothing defined for this, try the parent.
// E.g. we may be a button loaded from a resource, with no callback function
// defined.
void wxWindow::DoGetPosition(int *x, int *y) const
{
HWND hWnd = GetHwnd();
- HWND hParentWnd = 0;
- if ( GetParent() )
- hParentWnd = (HWND) GetParent()->GetHWND();
RECT rect;
GetWindowRect(hWnd, &rect);
- // Since we now have the absolute screen coords, if there's a parent we
- // must subtract its top left corner
POINT point;
point.x = rect.left;
point.y = rect.top;
- if ( hParentWnd )
- {
- ::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).
- if ( GetParent() )
+ // we do the adjustments with respect to the parent only for the "real"
+ // children, not for the dialogs/frames
+ if ( !IsTopLevel() )
{
- wxPoint pt(GetParent()->GetClientAreaOrigin());
- point.x -= pt.x;
- point.y -= pt.y;
+ HWND hParentWnd = 0;
+ wxWindow *parent = GetParent();
+ if ( parent )
+ hParentWnd = GetWinHwnd(parent);
+
+ // Since we now have the absolute screen coords, if there's a parent we
+ // must subtract its top left corner
+ if ( hParentWnd )
+ {
+ ::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).
+ if ( parent )
+ {
+ wxPoint pt(parent->GetClientAreaOrigin());
+ point.x -= pt.x;
+ point.y -= pt.y;
+ }
}
if ( x )
*y = rect.bottom;
}
+// set the size of the window: if the dimensions are positive, just use them,
+// but if any of them is equal to -1, it means that we must find the value for
+// it ourselves (unless sizeFlags contains wxSIZE_ALLOW_MINUS_ONE flag, in
+// which case -1 is a valid value for x and y)
+//
+// If sizeFlags contains wxSIZE_AUTO_WIDTH/HEIGHT flags (default), we calculate
+// the width/height to best suit our contents, otherwise we reuse the current
+// width/height
void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
+ // get the current size and position...
int currentX, currentY;
GetPosition(¤tX, ¤tY);
int currentW,currentH;
GetSize(¤tW, ¤tH);
- if ( x == currentX && y == currentY && width == currentW && height == currentH )
+ // ... and don't do anything (avoiding flicker) if it's already ok
+ if ( x == currentX && y == currentY &&
+ width == currentW && height == currentH )
+ {
return;
+ }
- int actualWidth = width;
- int actualHeight = height;
- int actualX = x;
- int actualY = y;
if ( x == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
- actualX = currentX;
+ x = currentX;
if ( y == -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) )
- actualY = currentY;
+ y = currentY;
- AdjustForParentClientOrigin(actualX, actualY, sizeFlags);
+ AdjustForParentClientOrigin(x, y, sizeFlags);
+ wxSize size(-1, -1);
if ( width == -1 )
- actualWidth = currentW;
+ {
+ if ( sizeFlags && wxSIZE_AUTO_WIDTH )
+ {
+ size = DoGetBestSize();
+ width = size.x;
+ }
+ else
+ {
+ // just take the current one
+ width = currentW;
+ }
+ }
+
if ( height == -1 )
- actualHeight = currentH;
+ {
+ if ( sizeFlags && wxSIZE_AUTO_HEIGHT )
+ {
+ if ( size.x == -1 )
+ {
+ size= DoGetBestSize();
+ }
+ //else: already called DoGetBestSize() above
- HWND hWnd = GetHwnd();
- if ( hWnd )
- MoveWindow(hWnd, actualX, actualY, actualWidth, actualHeight, (BOOL)TRUE);
+ height = size.y;
+ }
+ else
+ {
+ // just take the current one
+ height = currentH;
+ }
+ }
+
+ if ( !::MoveWindow(GetHwnd(), x, y, width, height, TRUE) )
+ {
+ wxLogLastError("MoveWindow");
+ }
+}
+
+// for a generic window there is no natural best size - just use the current one
+wxSize wxWindow::DoGetBestSize()
+{
+ return GetSize();
}
void wxWindow::DoSetClientSize(int width, int height)
// a toolbar that it manages itself).
void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
{
- if ( ((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent() )
+ // don't do it for the dialogs/frames - they float independently of their
+ // parent
+ if ( !IsTopLevel() )
{
- wxPoint pt(GetParent()->GetClientAreaOrigin());
- x += pt.x; y += pt.y;
+ wxWindow *parent = GetParent();
+ if ( !(sizeFlags & wxSIZE_NO_ADJUSTMENTS) && parent )
+ {
+ wxPoint pt(parent->GetClientAreaOrigin());
+ x += pt.x; y += pt.y;
+ }
}
}
SIZE sizeRect;
TEXTMETRIC tm;
- GetTextExtentPoint(dc, (const char *)string, (int)string.Length(), &sizeRect);
+ GetTextExtentPoint(dc, string, (int)string.Length(), &sizeRect);
GetTextMetrics(dc, &tm);
if ( fontToUse && fnt && hfontOld )
if ( externalLeading ) *externalLeading = tm.tmExternalLeading;
}
-#if wxUSE_CARET
+#if wxUSE_CARET && WXWIN_COMPATIBILITY
// ---------------------------------------------------------------------------
// Caret manipulation
// ---------------------------------------------------------------------------
}
#endif // wxUSE_CARET
+// ---------------------------------------------------------------------------
+// popup menu
+// ---------------------------------------------------------------------------
+
+bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
+{
+ menu->SetInvokingWindow(this);
+ menu->UpdateUI();
+
+ HWND hWnd = GetHwnd();
+ HMENU hMenu = GetHmenuOf(menu);
+ POINT point;
+ point.x = x;
+ point.y = y;
+ ::ClientToScreen(hWnd, &point);
+ wxCurrentPopupMenu = menu;
+ ::TrackPopupMenu(hMenu, TPM_RIGHTBUTTON, point.x, point.y, 0, hWnd, NULL);
+ wxYield();
+ wxCurrentPopupMenu = NULL;
+
+ menu->SetInvokingWindow(NULL);
+
+ return TRUE;
+}
+
// ===========================================================================
// pre/post message processing
// ===========================================================================
if ( bProcess )
{
bool bCtrlDown = (::GetKeyState(VK_CONTROL) & 0x100) != 0;
+ bool bShiftDown = (::GetKeyState(VK_SHIFT) & 0x100) != 0;
// WM_GETDLGCODE: ask the control if it wants the key for itself,
// don't process it if it's the case (except for Ctrl-Tab/Enter
switch ( msg->wParam )
{
case VK_TAB:
- if ( lDlgCode & DLGC_WANTTAB ) {
+ // assume that nobody wants Shift-TAB for himself - if we
+ // don't do it there is no easy way for a control to grab
+ // TABs but still let Shift-TAB work as navugation key
+ if ( (lDlgCode & DLGC_WANTTAB) && !bShiftDown ) {
bProcess = FALSE;
}
else {
// Ctrl-Tab cycles thru notebook pages
bWindowChange = bCtrlDown;
- bForward = !(::GetKeyState(VK_SHIFT) & 0x100);
+ bForward = !bShiftDown;
}
break;
case VK_RETURN:
{
- if ( lDlgCode & DLGC_WANTMESSAGE )
+ if ( (lDlgCode & DLGC_WANTMESSAGE) && !bCtrlDown )
{
// control wants to process Enter itself, don't
// call IsDialogMessage() which would interpret
// it
return FALSE;
}
-#ifndef __WIN16__
- wxButton *btnDefault = GetDefaultItem();
- if ( btnDefault && !bCtrlDown )
+ else if ( lDlgCode & DLGC_BUTTON )
{
- // if there is a default button, Enter should
- // press it
- (void)::SendMessage((HWND)btnDefault->GetHWND(),
- BM_CLICK, 0, 0);
- return TRUE;
+ // buttons want process Enter themselevs
+ bProcess = FALSE;
+ }
+ else
+ {
+ wxPanel *panel = wxDynamicCast(this, wxPanel);
+ wxButton *btn = NULL;
+ if ( panel )
+ {
+ // panel may have a default button which should
+ // be activated by Enter
+ btn = panel->GetDefaultItem();
+ }
+
+ if ( btn && btn->IsEnabled() )
+ {
+ // if we do have a default button, do press it
+ btn->MSWCommand(BN_CLICKED, 0 /* unused */);
+
+ return TRUE;
+ }
+ // else: but if it does not it makes sense to make
+ // it work like a TAB - and that's what we do.
+ // Note that Ctrl-Enter always works this way.
}
- // else: but if there is not it makes sense to make it
- // work like a TAB - and that's what we do.
- // Note that Ctrl-Enter always works this way.
-#endif
}
break;
event.SetEventObject(this);
if ( GetEventHandler()->ProcessEvent(event) )
+ {
+ wxButton *btn = wxDynamicCast(FindFocus(), wxButton);
+ if ( btn )
+ {
+ // the button which has focus should be default
+ btn->SetDefault();
+ }
+
return TRUE;
+ }
}
}
bool wxWindow::MSWTranslateMessage(WXMSG* pMsg)
{
- return m_acceleratorTable.Ok() &&
- ::TranslateAccelerator(GetHwnd(),
- GetTableHaccel(m_acceleratorTable),
- (MSG *)pMsg);
+ return m_acceleratorTable.Translate(this, pMsg);
}
// ---------------------------------------------------------------------------
void wxWindow::UnpackCtlColor(WXWPARAM wParam, WXLPARAM lParam,
WXWORD *nCtlColor, WXHDC *hdc, WXHWND *hwnd)
{
- *control = (WXHWND)LOWORD(lParam);
+ *hwnd = (WXHWND)LOWORD(lParam);
*nCtlColor = (int)HIWORD(lParam);
*hdc = (WXHDC)wParam;
}
{
// trace all messages - useful for the debugging
#ifdef __WXDEBUG__
- wxLogTrace(wxTraceMessages, "Processing %s(wParam=%8lx, lParam=%8lx)",
+ wxLogTrace(wxTraceMessages, _T("Processing %s(wParam=%8lx, lParam=%8lx)"),
wxGetMessageName(message), wParam, lParam);
#endif // __WXDEBUG__
break;
case WM_PAINT:
- wxStartPainting();
processed = HandlePaint();
- wxEndPainting();
break;
case WM_CLOSE:
case WM_MBUTTONUP:
case WM_MBUTTONDBLCLK:
{
- int x = LOWORD(lParam);
- int y = HIWORD(lParam);
+ short x = LOWORD(lParam);
+ short y = HIWORD(lParam);
processed = HandleMouseEvent(message, x, y, wParam);
}
break;
case WM_GETDLGCODE:
- if ( GetWindowStyleFlag() & wxWANTS_CHARS )
+ if ( m_lDlgCode )
{
- rc.result = DLGC_WANTARROWS | DLGC_WANTCHARS | DLGC_WANTTAB;
+ rc.result = m_lDlgCode;
processed = TRUE;
}
+ //else: get the dlg code from the DefWindowProc()
break;
case WM_KEYDOWN:
case VK_RETURN:
case VK_BACK:
case VK_TAB:
- processed = TRUE;
+ // but set processed to FALSE, not TRUE to still pass them to
+ // the control's default window proc - otherwise built-in
+ // keyboard handling won't work
+ processed = FALSE;
break;
break;
case WM_GETMINMAXINFO:
- processed = HandleGetMinMaxInfo((LPMINMAXINFO)lParam);
+ processed = HandleGetMinMaxInfo((MINMAXINFO*)lParam);
break;
case WM_SETCURSOR:
if ( !processed )
{
#ifdef __WXDEBUG__
- wxLogTrace(wxTraceMessages, "Forwarding %s to DefWindowProc.",
+ wxLogTrace(wxTraceMessages, _T("Forwarding %s to DefWindowProc."),
wxGetMessageName(message));
#endif // __WXDEBUG__
rc.result = MSWDefWindowProc(message, wParam, lParam);
// adding NULL hWnd is (first) surely a result of an error and
// (secondly) breaks menu command processing
wxCHECK_RET( hWnd != (HWND)NULL,
- "attempt to add a NULL hWnd to window list ignored" );
+ _T("attempt to add a NULL hWnd to window list ignored") );
if ( !wxWinHandleList->Find((long)hWnd) )
wxWinHandleList->Append((long)hWnd, win);
int i;
for (i = 0; i < N; i++)
{
- char buf[100];
+ wxChar buf[100];
int chars = GetMenuString(hMenu, i, buf, 100, MF_BYPOSITION);
if ( !chars )
{
- wxLogLastError("GetMenuString");
+ wxLogLastError(_T("GetMenuString"));
continue;
}
- if ( strcmp(buf, "&Window") == 0 )
+ if ( wxStrcmp(buf, _T("&Window")) == 0 )
{
RemoveMenu(hMenu, i, MF_BYPOSITION);
bool wxWindow::MSWCreate(int id,
wxWindow *parent,
- const char *wclass,
+ const wxChar *wclass,
wxWindow *wx_win,
- const char *title,
+ const wxChar *title,
int x,
int y,
int width,
int height,
WXDWORD style,
- const char *dialog_template,
+ const wxChar *dialog_template,
WXDWORD extendedStyle)
{
int x1 = CW_USEDEFAULT;
if ( width > -1 ) width1 = width;
if ( height > -1 ) height1 = height;
+#ifdef __WXWINE__
+ HWND hParent = (HWND)NULL;
+#else
HWND hParent = NULL;
+#endif
if ( parent )
hParent = (HWND) parent->GetHWND();
if ( !::SetWindowPos(GetHwnd(), HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE) )
{
- wxLogLastError("SetWindowPos");
+ wxLogLastError(_T("SetWindowPos"));
}
}
// move the dialog to its initial position without forcing repainting
if ( !::MoveWindow(GetHwnd(), x1, y1, width1, height1, FALSE) )
{
- wxLogLastError("MoveWindow");
+ wxLogLastError(_T("MoveWindow"));
}
}
else
m_hWnd = (WXHWND)CreateWindowEx(extendedStyle,
wclass,
- title ? title : "",
+ title ? title : _T(""),
style,
x1, y1,
width1, height1,
if ( hdr->code == TTN_NEEDTEXT && m_tooltip )
{
TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
- ttt->lpszText = (char *)m_tooltip->GetTip().c_str();
+ ttt->lpszText = (wxChar *)m_tooltip->GetTip().c_str();
// processed
return TRUE;
#endif // wxUSE_CARET
// panel wants to track the window which was the last to have focus in it
- wxWindow *parent = GetParent();
- if ( parent && parent->IsKindOf(CLASSINFO(wxPanel)) )
+ wxPanel *panel = wxDynamicCast(GetParent(), wxPanel);
+ if ( panel )
{
- ((wxPanel *)parent)->SetLastFocus(GetId());
+ panel->SetLastFocus(this);
}
wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
int wIndex;
for (wIndex=0; wIndex < (int)gwFilesDropped; wIndex++)
{
- DragQueryFile (hFilesInfo, wIndex, (LPSTR) wxBuffer, 1000);
+ DragQueryFile (hFilesInfo, wIndex, (LPTSTR) wxBuffer, 1000);
files[wIndex] = wxBuffer;
}
DragFinish (hFilesInfo);
return FALSE;
}
-#if wxUSE_OWNER_DRAWN
// ---------------------------------------------------------------------------
// owner drawn stuff
// ---------------------------------------------------------------------------
bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct)
{
+#if wxUSE_OWNER_DRAWN
// is it a menu item?
if ( id == 0 )
{
return ((wxControl *)item)->MSWOnDraw(itemStruct);
}
else
+#endif
return FALSE;
+
}
bool wxWindow::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct)
{
+#if wxUSE_OWNER_DRAWN
// is it a menu item?
if ( id == 0 )
{
{
return ((wxControl *)item)->MSWOnMeasure(itemStruct);
}
-
+#endif // owner-drawn menus
return FALSE;
}
-#endif // owner-drawn menus
// ---------------------------------------------------------------------------
// colours and palettes
break;
default:
- wxFAIL_MSG("no such joystick event");
+ wxFAIL_MSG(_T("no such joystick event"));
return FALSE;
}