#include "wx/menu.h"
#include "wx/dc.h"
#include "wx/dcclient.h"
+ #include "wx/dcmemory.h"
#include "wx/utils.h"
#include "wx/app.h"
#include "wx/layout.h"
// global variables
// ---------------------------------------------------------------------------
-// the last Windows message we got (MT-UNSAFE)
+// the last Windows message we got (FIXME-MT)
extern MSG s_currentMsg;
#if wxUSE_MENUS_NATIVE
extern const wxChar *wxCanvasClassName;
+// true if we had already created the std colour map, used by
+// wxGetStdColourMap() and wxWindow::OnSysColourChanged() (FIXME-MT)
+static bool gs_hasStdCmap = FALSE;
+
// ---------------------------------------------------------------------------
// private functions
// ---------------------------------------------------------------------------
m_hWnd = 0;
- // pass WM_GETDLGCODE to DefWindowProc()
- m_lDlgCode = 0;
-
m_xThumbSize = 0;
m_yThumbSize = 0;
m_backgroundTransparent = FALSE;
{
m_isBeingDeleted = TRUE;
- MSWDetachWindowMenu();
-
#ifndef __WXUNIVERSAL__
// VS: make sure there's no wxFrame with last focus set to us:
for ( wxWindow *win = GetParent(); win; win = win->GetParent() )
{
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;
- }
#endif // wxUniversal/!wxUniversal
if ( style & wxPOPUP_WINDOW )
return wxGetWindowText(GetHWND());
}
-void wxWindowMSW::CaptureMouse()
+void wxWindowMSW::DoCaptureMouse()
{
HWND hWnd = GetHwnd();
if ( hWnd )
}
}
-void wxWindowMSW::ReleaseMouse()
+void wxWindowMSW::DoReleaseMouse()
{
if ( !::ReleaseCapture() )
{
void wxWindowMSW::ScrollWindow(int dx, int dy, const wxRect *prect)
{
RECT rect;
+ RECT *pr;
if ( prect )
{
rect.left = prect->x;
rect.top = prect->y;
rect.right = prect->x + prect->width;
rect.bottom = prect->y + prect->height;
+ pr = ▭
+ }
+ else
+ {
+ pr = NULL;
}
- ::ScrollWindow(GetHwnd(), dx, dy, prect ? &rect : NULL, NULL);
+ ::ScrollWindow(GetHwnd(), dx, dy, pr, pr);
}
static bool ScrollVertically(HWND hwnd, int kind, int count)
// Check if we need to send a LEAVE event
if ( m_mouseInWindow )
{
- if ( !IsMouseInWindow() )
+ if ( !IsMouseInWindow() && !HasCapture())
{
// Generate a LEAVE event
m_mouseInWindow = FALSE;
::GetClientRect(GetHwnd(), &rectClient);
// if the size is already ok, stop here (rectClient.left = top = 0)
- if ( rectClient.right == width && rectClient.bottom == height )
+ if ( (rectClient.right == width || width == -1) &&
+ (rectClient.bottom == height || height == -1) )
{
break;
}
#if wxUSE_ACCEL && !defined(__WXUNIVERSAL__)
return m_acceleratorTable.Translate(this, pMsg);
#else
+ (void) pMsg;
return FALSE;
#endif // wxUSE_ACCEL
}
-bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG* pMsg)
+bool wxWindowMSW::MSWShouldPreProcessMessage(WXMSG* WXUNUSED(pMsg))
{
// preprocess all messages by default
return TRUE;
#endif // defined(WM_DRAWITEM)
case WM_GETDLGCODE:
- if ( m_lDlgCode )
+ if ( GetWindowStyleFlag() & wxWANTS_CHARS )
{
- rc.result = m_lDlgCode;
+ // want everything: i.e. all keys and WM_CHAR message
+ rc.result = DLGC_WANTARROWS | DLGC_WANTCHARS |
+ DLGC_WANTTAB | DLGC_WANTMESSAGE;
processed = TRUE;
}
//else: get the dlg code from the DefWindowProc()
break;
#endif // !__WXMICROWIN__
- // the return value for this message is ignored
case WM_SYSCOLORCHANGE:
+ // the return value for this message is ignored
processed = HandleSysColorChange();
break;
+ case WM_DISPLAYCHANGE:
+ processed = HandleDisplayChange();
+ break;
+
case WM_PALETTECHANGED:
processed = HandlePaletteChanged((WXHWND) (HWND) wParam);
break;
{
}
-void wxWindowMSW::MSWDetachWindowMenu()
-{
-#ifndef __WXUNIVERSAL__
- if ( m_hMenu )
- {
- wxChar buf[1024];
- HMENU hMenu = (HMENU)m_hMenu;
-
- int N = ::GetMenuItemCount(hMenu);
- for ( int i = 0; i < N; i++ )
- {
- if ( !::GetMenuString(hMenu, i, buf, WXSIZEOF(buf), MF_BYPOSITION) )
- {
- wxLogLastError(wxT("GetMenuString"));
-
- continue;
- }
-
- if ( wxStrcmp(buf, _("&Window")) == 0 )
- {
- if ( !::RemoveMenu(hMenu, i, MF_BYPOSITION) )
- {
- wxLogLastError(wxT("RemoveMenu"));
- }
-
- break;
- }
- }
- }
-#endif // __WXUNIVERSAL__
-}
-
bool wxWindowMSW::MSWGetCreateWindowCoords(const wxPoint& pos,
const wxSize& size,
int& x, int& y,
return FALSE;
}
+bool wxWindowMSW::HandleDisplayChange()
+{
+ wxDisplayChangedEvent event;
+ event.SetEventObject(this);
+
+ return GetEventHandler()->ProcessEvent(event);
+}
+
bool wxWindowMSW::HandleCtlColor(WXHBRUSH *brush,
WXHDC pDC,
WXHWND pWnd,
bool wxWindowMSW::HandlePaletteChanged(WXHWND hWndPalChange)
{
+#if wxUSE_PALETTE
+ // same as below except we don't respond to our own messages
+ if ( hWndPalChange != GetHWND() )
+ {
+ // check to see if we our our parents have a custom palette
+ wxWindow *win = this;
+ while ( win && !win->HasCustomPalette() )
+ {
+ win = win->GetParent();
+ }
+
+ if ( win && win->HasCustomPalette() )
+ {
+ // realize the palette to see whether redrawing is needed
+ HDC hdc = ::GetDC((HWND) hWndPalChange);
+ win->m_palette.SetHPALETTE((WXHPALETTE)
+ ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
+
+ int result = ::RealizePalette(hdc);
+
+ // restore the palette (before releasing the DC)
+ win->m_palette.SetHPALETTE((WXHPALETTE)
+ ::SelectPalette(hdc, GetHpaletteOf(win->m_palette), FALSE));
+ ::RealizePalette(hdc);
+ ::ReleaseDC((HWND) hWndPalChange, hdc);
+
+ // now check for the need to redraw
+ if (result > 0)
+ InvalidateRect((HWND) hWndPalChange, NULL, TRUE);
+ }
+
+ }
+#endif // wxUSE_PALETTE
+
wxPaletteChangedEvent event(GetId());
event.SetEventObject(this);
event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange));
bool wxWindowMSW::HandleQueryNewPalette()
{
+
+#if wxUSE_PALETTE
+ // check to see if we our our parents have a custom palette
+ wxWindow *win = this;
+ while (!win->HasCustomPalette() && win->GetParent()) win = win->GetParent();
+ if (win->HasCustomPalette()) {
+ /* realize the palette to see whether redrawing is needed */
+ HDC hdc = GetDC((HWND) GetHWND());
+ win->m_palette.SetHPALETTE( (WXHPALETTE)
+ ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), FALSE) );
+
+ int result = ::RealizePalette(hdc);
+ /* restore the palette (before releasing the DC) */
+ win->m_palette.SetHPALETTE( (WXHPALETTE)
+ ::SelectPalette(hdc, (HPALETTE) win->m_palette.GetHPALETTE(), TRUE) );
+ ::RealizePalette(hdc);
+ ::ReleaseDC((HWND) GetHWND(), hdc);
+ /* now check for the need to redraw */
+ if (result > 0)
+ ::InvalidateRect((HWND) GetHWND(), NULL, TRUE);
+ }
+#endif // wxUSE_PALETTE
+
wxQueryNewPaletteEvent event(GetId());
event.SetEventObject(this);
}
// Responds to colour changes: passes event on to children.
-void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& event)
+void wxWindowMSW::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event))
{
+ // the top level window also reset the standard colour map as it might have
+ // changed (there is no need to do it for the non top level windows as we
+ // only have to do it once)
+ if ( IsTopLevel() )
+ {
+ // FIXME-MT
+ gs_hasStdCmap = FALSE;
+ }
wxWindowList::Node *node = GetChildren().GetFirst();
while ( node )
{
}
}
+extern wxCOLORMAP *wxGetStdColourMap()
+{
+ static COLORREF s_stdColours[wxSTD_COL_MAX];
+ static wxCOLORMAP s_cmap[wxSTD_COL_MAX];
+
+ if ( !gs_hasStdCmap )
+ {
+ static bool s_coloursInit = FALSE;
+
+ if ( !s_coloursInit )
+ {
+ // When a bitmap is loaded, the RGB values can change (apparently
+ // because Windows adjusts them to care for the old programs always
+ // using 0xc0c0c0 while the transparent colour for the new Windows
+ // versions is different). But we do this adjustment ourselves so
+ // we want to avoid Windows' "help" and for this we need to have a
+ // reference bitmap which can tell us what the RGB values change
+ // to.
+ wxBitmap stdColourBitmap(_T("wxBITMAP_STD_COLOURS"));
+ if ( stdColourBitmap.Ok() )
+ {
+ // the pixels in the bitmap must correspond to wxSTD_COL_XXX!
+ wxASSERT_MSG( stdColourBitmap.GetWidth() == wxSTD_COL_MAX,
+ _T("forgot to update wxBITMAP_STD_COLOURS!") );
+
+ wxMemoryDC memDC;
+ memDC.SelectObject(stdColourBitmap);
+
+ wxColour colour;
+ for ( size_t i = 0; i < WXSIZEOF(s_stdColours); i++ )
+ {
+ memDC.GetPixel(i, 0, &colour);
+ s_stdColours[i] = wxColourToRGB(colour);
+ }
+ }
+ else // wxBITMAP_STD_COLOURS couldn't be loaded
+ {
+ s_stdColours[0] = RGB(000,000,000); // black
+ s_stdColours[1] = RGB(128,128,128); // dark grey
+ s_stdColours[2] = RGB(192,192,192); // light grey
+ s_stdColours[3] = RGB(255,255,255); // white
+ //s_stdColours[4] = RGB(000,000,255); // blue
+ //s_stdColours[5] = RGB(255,000,255); // magenta
+ }
+
+ s_coloursInit = TRUE;
+ }
+
+ gs_hasStdCmap = TRUE;
+
+ // create the colour map
+#define INIT_CMAP_ENTRY(col) \
+ s_cmap[wxSTD_COL_##col].from = s_stdColours[wxSTD_COL_##col]; \
+ s_cmap[wxSTD_COL_##col].to = ::GetSysColor(COLOR_##col)
+
+ INIT_CMAP_ENTRY(BTNTEXT);
+ INIT_CMAP_ENTRY(BTNSHADOW);
+ INIT_CMAP_ENTRY(BTNFACE);
+ INIT_CMAP_ENTRY(BTNHIGHLIGHT);
+
+#undef INIT_CMAP_ENTRY
+ }
+
+ return s_cmap;
+}
+
// ---------------------------------------------------------------------------
// painting
// ---------------------------------------------------------------------------