From a23fd0e1d1329a4a258b4defb3e0b0001b700c6e Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 13 May 1999 21:21:04 +0000 Subject: [PATCH] 1. MSW message handling simplifications 2. wxDC split into wxDC and wxDCBase 3. Several minor bug fixes, many major new bugs git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2455 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dc.h | 598 ++++++++++- include/wx/defs.h | 22 +- include/wx/gdicmn.h | 13 +- include/wx/gtk/dc.h | 411 ++------ include/wx/gtk/window.h | 1 + include/wx/gtk1/dc.h | 411 ++------ include/wx/gtk1/window.h | 1 + include/wx/msw/control.h | 10 +- include/wx/msw/dc.h | 523 +++------- include/wx/msw/dialog.h | 6 +- include/wx/msw/frame.h | 35 +- include/wx/msw/listctrl.h | 2 +- include/wx/msw/mdi.h | 287 ++--- include/wx/msw/notebook.h | 2 +- include/wx/msw/private.h | 172 +-- include/wx/msw/scrolbar.h | 96 +- include/wx/msw/slider95.h | 4 +- include/wx/msw/slidrmsw.h | 4 +- include/wx/msw/spinbutt.h | 29 +- include/wx/msw/tabctrl.h | 2 +- include/wx/msw/tbar95.h | 2 +- include/wx/msw/treectrl.h | 2 +- include/wx/msw/window.h | 162 +-- include/wx/tbarbase.h | 5 - include/wx/window.h | 5 +- include/wx/wxchar.h | 2 + samples/image/image.cpp | 36 +- src/common/gdicmn.cpp | 86 +- src/common/tbarbase.cpp | 8 - src/common/wincmn.cpp | 20 +- src/gtk/dc.cpp | 264 +---- src/gtk1/dc.cpp | 264 +---- src/msw/checklst.cpp | 2 +- src/msw/control.cpp | 160 +-- src/msw/dc.cpp | 1075 +++++++++---------- src/msw/dialog.cpp | 38 +- src/msw/frame.cpp | 246 +++-- src/msw/listbox.cpp | 87 +- src/msw/listctrl.cpp | 4 +- src/msw/mdi.cpp | 472 ++++----- src/msw/notebook.cpp | 6 +- src/msw/scrolbar.cpp | 142 ++- src/msw/slider95.cpp | 259 ++--- src/msw/slidrmsw.cpp | 203 ++-- src/msw/spinbutt.cpp | 189 ++-- src/msw/tabctrl.cpp | 6 +- src/msw/tbar95.cpp | 2 +- src/msw/textctrl.cpp | 4 +- src/msw/treectrl.cpp | 4 +- src/msw/window.cpp | 2073 ++++++++++++++----------------------- 50 files changed, 3672 insertions(+), 4785 deletions(-) diff --git a/include/wx/dc.h b/include/wx/dc.h index 2cf32f30d2..ef4e0e331b 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -1,18 +1,604 @@ #ifndef _WX_DC_H_BASE_ #define _WX_DC_H_BASE_ +#ifdef __GNUG__ + #pragma interface "dcbase.h" +#endif + +// ---------------------------------------------------------------------------- +// headers which we must include here +// ---------------------------------------------------------------------------- + +#include "wx/object.h" // the base class + +#include "wx/cursor.h" // we have member variables of these classes +#include "wx/font.h" // so we can't do without them +#include "wx/colour.h" +#include "wx/brush.h" +#include "wx/pen.h" +#include "wx/palette.h" + +#include "wx/list.h" // we use wxList in inline functions + +// --------------------------------------------------------------------------- +// types +// --------------------------------------------------------------------------- + +// type which should be used (whenever possible, i.e. as long as it doesn't +// break compatibility) for screen coordinates +typedef int wxCoord; + +// --------------------------------------------------------------------------- +// global variables +// --------------------------------------------------------------------------- + +WXDLLEXPORT_DATA(extern int) wxPageNumber; + +// --------------------------------------------------------------------------- +// wxDC is the device context - object on which any drawing is done +// --------------------------------------------------------------------------- + +class WXDLLEXPORT wxDCBase : public wxObject +{ + DECLARE_ABSTRACT_CLASS(wxDCBase) + +public: + wxDCBase() + { + m_clipping = FALSE; + m_ok = TRUE; + + m_minX = m_minY = m_maxX = m_maxY = 0; + + m_signX = m_signY = 1; + + m_logicalOriginX = m_logicalOriginY = + m_deviceOriginX = m_deviceOriginY = 0; + + m_logicalScaleX = m_logicalScaleY = + m_userScaleX = m_userScaleY = + m_scaleX = m_scaleY = 1.0; + + m_logicalFunction = -1; + + m_backgroundMode = wxTRANSPARENT; + + m_mappingMode = wxMM_TEXT; + + m_backgroundBrush = *wxWHITE_BRUSH; + + m_textForegroundColour = *wxBLACK; + m_textBackgroundColour = *wxWHITE; + + m_colour = wxColourDisplay(); + } + + ~wxDCBase() { } + + virtual void BeginDrawing() { } + virtual void EndDrawing() { } + + // graphic primitives + // ------------------ + + void FloodFill(long x, long y, const wxColour& col, + int style = wxFLOOD_SURFACE) + { DoFloodFill(x, y, col, style); } + void FloodFill(const wxPoint& pt, const wxColour& col, + int style = wxFLOOD_SURFACE) + { DoFloodFill(pt.x, pt.y, col, style); } + + bool GetPixel(long x, long y, wxColour *col) const + { return DoGetPixel(x, y, col); } + bool GetPixel(const wxPoint& pt, wxColour *col) const + { return DoGetPixel(pt.x, pt.y, col); } + + void DrawLine(long x1, long y1, long x2, long y2) + { DoDrawLine(x1, y1, x2, y2); } + void DrawLine(const wxPoint& pt1, const wxPoint& pt2) + { DoDrawLine(pt1.x, pt1.y, pt2.x, pt2.y); } + + void CrossHair(long x, long y) + { DoCrossHair(x, y); } + void CrossHair(const wxPoint& pt) + { DoCrossHair(pt.x, pt.y); } + + void DrawArc(long x1, long y1, long x2, long y2, long xc, long yc) + { DoDrawArc(x1, y1, x2, y2, xc, yc); } + void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre) + { DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); } + + void DrawEllipticArc(long x, long y, long w, long h, double sa, double ea) + { DoDrawEllipticArc(x, y, x, y, sa, ea); } + void DrawEllipticArc(const wxPoint& pt, const wxSize& sz, + double sa, double ea) + { DoDrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); } + + void DrawPoint(long x, long y) + { DoDrawPoint(x, y); } + void DrawPoint(const wxPoint& pt) + { DoDrawPoint(pt.x, pt.y); } + + void DrawLines(int n, wxPoint points[], long xoffset = 0, long yoffset = 0) + { DoDrawLines(n, points, xoffset, yoffset); } + void DrawLines(const wxList *list, long xoffset = 0, long yoffset = 0) + { + int n = list->Number(); + wxPoint *points = new wxPoint[n]; + + int i = 0; + for ( wxNode *node = list->First(); node; node = node->Next(), i++ ) + { + wxPoint *point = (wxPoint *)node->Data(); + points[i].x = point->x; + points[i].y = point->y; + } + + DoDrawLines(n, points, xoffset, yoffset); + + delete [] points; + } + + void DrawPolygon(int n, wxPoint points[], + long xoffset = 0, long yoffset = 0, + int fillStyle = wxODDEVEN_RULE) + { DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); } + + void DrawPolygon(const wxList *list, + long xoffset = 0, long yoffset = 0, + int fillStyle = wxODDEVEN_RULE) + { + int n = list->Number(); + wxPoint *points = new wxPoint[n]; + + int i = 0; + for ( wxNode *node = list->First(); node; node = node->Next(), i++ ) + { + wxPoint *point = (wxPoint *)node->Data(); + points[i].x = point->x; + points[i].y = point->y; + } + + DoDrawPolygon(n, points, xoffset, yoffset, fillStyle); + + delete [] points; + } + + void DrawRectangle(long x, long y, long width, long height) + { DoDrawRectangle(x, y, width, height); } + void DrawRectangle(const wxPoint& pt, const wxSize& sz) + { DoDrawRectangle(pt.x, pt.y, sz.x, sz.y); } + void DrawRectangle(const wxRect& rect) + { DoDrawRectangle(rect.x, rect.y, rect.width, rect.height); } + + void DrawRoundedRectangle(long x, long y, long width, long height, + double radius) + { DoDrawRoundedRectangle(x, y, width, height, radius); } + void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, + double radius) + { DoDrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); } + void DrawRoundedRectangle(const wxRect& r, double radius) + { DoDrawRoundedRectangle(r.x, r.y, r.width, r.height, radius); } + + void DrawEllipse(long x, long y, long width, long height) + { DoDrawEllipse(x, y, width, height); } + void DrawEllipse(const wxPoint& pt, const wxSize& sz) + { DoDrawEllipse(pt.x, pt.y, sz.x, sz.y); } + void DrawEllipse(const wxRect& rect) + { DoDrawEllipse(rect.x, rect.y, rect.width, rect.height); } + + void DrawIcon(const wxIcon& icon, long x, long y) + { DoDrawIcon(icon, x, y); } + void DrawIcon(const wxIcon& icon, const wxPoint& pt) + { DoDrawIcon(icon, pt.x, pt.y); } + + void DrawBitmap(const wxBitmap &bmp, long x, long y, bool useMask = FALSE) + { DoDrawBitmap(bmp, x, y, useMask); } + void DrawBitmap(const wxBitmap &bmp, const wxPoint& pt, + bool useMask = FALSE) + { DoDrawBitmap(bmp, pt.x, pt.y, useMask); } + + void DrawText(const wxString& text, long x, long y) + { DoDrawText(text, x, y); } + void DrawText(const wxString& text, const wxPoint& pt) + { DoDrawText(text, pt.x, pt.y); } + + bool Blit(long xdest, long ydest, long width, long height, + wxDC *source, long xsrc, long ysrc, + int rop = wxCOPY, bool useMask = FALSE) + { + return DoBlit(xdest, ydest, width, height, + source, xsrc, ysrc, rop, useMask); + } + bool Blit(const wxPoint& destPt, const wxSize& sz, + wxDC *source, const wxPoint& srcPt, + int rop = wxCOPY, bool useMask = FALSE) + { + return DoBlit(destPt.x, destPt.y, sz.x, sz.y, + source, srcPt.x, srcPt.y, rop, useMask); + } + +#if wxUSE_SPLINES + // TODO: this API needs fixing (wxPointList, why (!const) "wxList *"?) + void DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3) + { + wxList point_list; + + wxPoint *point1 = new wxPoint; + point1->x = x1; point1->y = y1; + point_list.Append((wxObject*)point1); + + wxPoint *point2 = new wxPoint; + point2->x = x2; point2->y = y2; + point_list.Append((wxObject*)point2); + + wxPoint *point3 = new wxPoint; + point3->x = x3; point3->y = y3; + point_list.Append((wxObject*)point3); + + DrawSpline(&point_list); + + for( wxNode *node = point_list.First(); node; node = node->Next() ) + { + wxPoint *p = (wxPoint *)node->Data(); + delete p; + } + } + + void DrawSpline(int n, wxPoint points[]) + { + wxList list; + for (int i =0; i < n; i++) + { + list.Append((wxObject*)&points[i]); + } + + DrawSpline(&list); + } + + void DrawSpline(wxList *points) { DoDrawSpline(points); } +#endif // wxUSE_SPLINES + + // global DC operations + // -------------------- + + virtual void Clear() = 0; + + virtual bool StartDoc(const wxString& message) = 0; + virtual void EndDoc() = 0; + + virtual void StartPage() = 0; + virtual void EndPage() = 0; + + // set objects to use for drawing + // ------------------------------ + + virtual void SetFont(const wxFont& font) = 0; + virtual void SetPen(const wxPen& pen) = 0; + virtual void SetBrush(const wxBrush& brush) = 0; + virtual void SetBackground(const wxBrush& brush) = 0; + virtual void SetBackgroundMode(int mode) = 0; + virtual void SetPalette(const wxPalette& palette) = 0; + + // clipping region + // --------------- + + void SetClippingRegion(long x, long y, long width, long height) + { DoSetClippingRegion(x, y, width, height); } + void SetClippingRegion(const wxPoint& pt, const wxSize& sz) + { DoSetClippingRegion(pt.x, pt.y, sz.x, sz.y); } + void SetClippingRegion(const wxRect& rect) + { DoSetClippingRegion(rect.x, rect.y, rect.width, rect.height); } + void SetClippingRegion(const wxRegion& region) + { DoSetClippingRegionAsRegion(region); } + + virtual void DestroyClippingRegion() = 0; + + void GetClippingBox(long *x, long *y, long *w, long *h) const + { DoGetClippingBox(x, y, w, h); } + void GetClippingBox(wxRect& rect) const + { DoGetClippingBox(&rect.x, &rect.y, &rect.width, &rect.height); } + + // text extent + // ----------- + + virtual long GetCharHeight() const = 0; + virtual long GetCharWidth() const = 0; + virtual void GetTextExtent(const wxString& string, + long *x, long *y, + long *descent = NULL, + long *externalLeading = NULL, + wxFont *theFont = NULL) const = 0; + + // size and resolution + // ------------------- + + // in device units + void GetSize(int *width, int *height) const + { DoGetSize(width, height); } + wxSize GetSize() const + { + int w, h; + DoGetSize(&w, &h); + + return wxSize(w, h); + } + + // in mm + void GetSizeMM(int* width, int* height) const + { DoGetSizeMM(width, height); } + wxSize GetSizeMM() const + { + int w, h; + DoGetSizeMM(&w, &h); + + return wxSize(w, h); + } + + // coordinates conversions + // ----------------------- + + // This group of functions does actual conversion of the input, as you'd + // expect. + long DeviceToLogicalX(long x) const; + long DeviceToLogicalY(long y) const; + long DeviceToLogicalXRel(long x) const; + long DeviceToLogicalYRel(long y) const; + long LogicalToDeviceX(long x) const; + long LogicalToDeviceY(long y) const; + long LogicalToDeviceXRel(long x) const; + long LogicalToDeviceYRel(long y) const; + + // query DC capabilities + // --------------------- + + virtual bool CanDrawBitmap() const = 0; + virtual bool CanGetTextExtent() const = 0; + + // colour depth + virtual int GetDepth() const = 0; + + // Resolution in Pixels per inch + virtual wxSize GetPPI() const = 0; + + virtual bool Ok() const { return m_ok; } + + // accessors + // --------- + + // const... + const wxBrush& GetBackground() const { return m_backgroundBrush; } + const wxBrush& GetBrush() const { return m_brush; } + const wxFont& GetFont() const { return m_font; } + const wxPen& GetPen() const { return m_pen; } + const wxColour& GetTextBackground() const { return m_textBackgroundColour; } + const wxColour& GetTextForeground() const { return m_textForegroundColour; } + + // ... and non const + wxBrush& GetBackground() { return m_backgroundBrush; } + wxBrush& GetBrush() { return m_brush; } + wxFont& GetFont() { return m_font; } + wxPen& GetPen() { return m_pen; } + wxColour& GetTextBackground() { return m_textBackgroundColour; } + wxColour& GetTextForeground() { return m_textForegroundColour; } + + virtual void SetTextForeground(const wxColour& colour) + { m_textForegroundColour = colour; } + virtual void SetTextBackground(const wxColour& colour) + { m_textBackgroundColour = colour; } + + int GetMapMode() const { return m_mappingMode; } + virtual void SetMapMode(int mode) = 0; + + virtual void GetUserScale(double *x, double *y) const + { + if ( x ) *x = m_userScaleX; + if ( y ) *y = m_userScaleY; + } + virtual void SetUserScale(double x, double y) = 0; + + virtual void SetSystemScale(double x, double y) = 0; + + virtual void GetLogicalScale(double *x, double *y) + { + if ( x ) *x = m_logicalScaleX; + if ( y ) *y = m_logicalScaleY; + } + virtual void SetLogicalScale(double x, double y) + { + m_logicalScaleX = x; + m_logicalScaleY = y; + } + + void GetLogicalOrigin(long *x, long *y) const + { DoGetLogicalOrigin(x, y); } + wxPoint GetLogicalOrigin() const + { long x, y; DoGetLogicalOrigin(&x, &y); return wxPoint(x, y); } + virtual void SetLogicalOrigin(long x, long y) = 0; + + void GetDeviceOrigin(long *x, long *y) const + { DoGetDeviceOrigin(x, y); } + wxPoint GetDeviceOrigin() const + { long x, y; DoGetDeviceOrigin(&x, &y); return wxPoint(x, y); } + virtual void SetDeviceOrigin(long x, long y) = 0; + + virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp) = 0; + + int GetLogicalFunction() const { return m_logicalFunction; } + virtual void SetLogicalFunction(int function) = 0; + + // Sometimes we need to override optimization, e.g. if other software is + // drawing onto our surface and we can't be sure of who's done what. + // + // FIXME: is this (still) used? + virtual void SetOptimization(bool WXUNUSED(opt)) { } + virtual bool GetOptimization() { return FALSE; } + + // bounding box + // ------------ + + virtual void CalcBoundingBox(long x, long y) + { + if (x < m_minX) m_minX = x; + if (y < m_minY) m_minY = y; + if (x > m_maxX) m_maxX = x; + if (y > m_maxY) m_maxY = y; + } + + // Get the final bounding box of the PostScript or Metafile picture. + long MinX() const { return m_minX; } + long MaxX() const { return m_maxX; } + long MinY() const { return m_minY; } + long MaxY() const { return m_maxY; } + + // misc old functions + // ------------------ + +#if WXWIN_COMPATIBILITY + virtual void SetColourMap(const wxPalette& palette) { SetPalette(palette); } + void GetTextExtent(const wxString& string, float *x, float *y, + float *descent = NULL, float *externalLeading = NULL, + wxFont *theFont = NULL, bool use16bit = FALSE) const ; + void GetSize(float* width, float* height) const { int w, h; GetSize(& w, & h); *width = w; *height = h; } + void GetSizeMM(float *width, float *height) const { long w, h; GetSizeMM(& w, & h); *width = (float) w; *height = (float) h; } +#endif // WXWIN_COMPATIBILITY + +protected: + // the pure virtual functions which should be implemented by wxDC + virtual void DoFloodFill(long x, long y, const wxColour& col, + int style = wxFLOOD_SURFACE) = 0; + + virtual bool DoGetPixel(long x, long y, wxColour *col) const = 0; + + virtual void DoDrawPoint(long x, long y) = 0; + virtual void DoDrawLine(long x1, long y1, long x2, long y2) = 0; + + virtual void DoDrawArc(long x1, long y1, + long x2, long y2, + long xc, long yc) = 0; + virtual void DoDrawEllipticArc(long x, long y, long w, long h, + double sa, double ea) = 0; + + virtual void DoDrawRectangle(long x, long y, long width, long height) = 0; + virtual void DoDrawRoundedRectangle(long x, long y, + long width, long height, + double radius) = 0; + virtual void DoDrawEllipse(long x, long y, long width, long height) = 0; + + virtual void DoCrossHair(long x, long y) = 0; + + virtual void DoDrawIcon(const wxIcon& icon, long x, long y) = 0; + virtual void DoDrawBitmap(const wxBitmap &bmp, long x, long y, + bool useMask = FALSE) = 0; + + virtual void DoDrawText(const wxString& text, long x, long y) = 0; + + virtual bool DoBlit(long xdest, long ydest, long width, long height, + wxDC *source, long xsrc, long ysrc, + int rop = wxCOPY, bool useMask = FALSE) = 0; + + virtual void DoGetSize(int *width, int *height) const = 0; + virtual void DoGetSizeMM(int* width, int* height) const = 0; + + virtual void DoDrawLines(int n, wxPoint points[], + long xoffset, long yoffset) = 0; + virtual void DoDrawPolygon(int n, wxPoint points[], + long xoffset, long yoffset, + int fillStyle = wxODDEVEN_RULE) = 0; + + virtual void DoSetClippingRegionAsRegion(const wxRegion& region) = 0; + virtual void DoSetClippingRegion(long x, long y, + long width, long height) = 0; + virtual void DoGetClippingRegion(long *x, long *y, + long *width, long *height) = 0; + virtual void DoGetClippingBox(long *x, long *y, + long *w, long *h) const + { + if ( m_clipping ) + { + if ( x ) *x = m_clipX1; + if ( y ) *y = m_clipY1; + if ( w ) *w = m_clipX2 - m_clipX1; + if ( h ) *h = m_clipY2 - m_clipY1; + } + else + { + *x = *y = *w = *h = 0; + } + } + + virtual void DoGetLogicalOrigin(long *x, long *y) const + { + if ( x ) *x = m_logicalOriginX; + if ( y ) *y = m_logicalOriginY; + } + + virtual void DoGetDeviceOrigin(long *x, long *y) const + { + if ( x ) *x = m_deviceOriginX; + if ( y ) *y = m_deviceOriginY; + } + + virtual void DoDrawSpline(wxList *points) = 0; + +protected: + // flags + bool m_colour:1; + bool m_ok:1; + bool m_clipping:1; + bool m_isInteractive:1; + + // coordinate system variables + + // TODO short descriptions of what exactly they are would be nice... + + long m_logicalOriginX, m_logicalOriginY; + long m_deviceOriginX, m_deviceOriginY; + + double m_logicalScaleX, m_logicalScaleY; + double m_userScaleX, m_userScaleY; + double m_scaleX, m_scaleY; + + // Used by SetAxisOrientation() to invert the axes + int m_signX, m_signY; + + // bounding and clipping boxes + long m_minX, m_minY, m_maxX, m_maxY; + long m_clipX1, m_clipY1, m_clipX2, m_clipY2; + + int m_logicalFunction; + int m_backgroundMode; + int m_mappingMode; + + // GDI objects + wxPen m_pen; + wxBrush m_brush; + wxBrush m_backgroundBrush; + wxColour m_textForegroundColour; + wxColour m_textBackgroundColour; + wxFont m_font; + wxPalette m_palette; + +private: + DECLARE_NO_COPY_CLASS(wxDCBase); +}; + +// ---------------------------------------------------------------------------- +// now include the declaration of wxDC class +// ---------------------------------------------------------------------------- + #if defined(__WXMSW__) -#include "wx/msw/dc.h" + #include "wx/msw/dc.h" #elif defined(__WXMOTIF__) -#include "wx/motif/dc.h" + #include "wx/motif/dc.h" #elif defined(__WXGTK__) -#include "wx/gtk/dc.h" + #include "wx/gtk/dc.h" #elif defined(__WXQT__) -#include "wx/qt/dc.h" + #include "wx/qt/dc.h" #elif defined(__WXMAC__) -#include "wx/mac/dc.h" + #include "wx/mac/dc.h" #elif defined(__WXSTUBS__) -#include "wx/stubs/dc.h" + #include "wx/stubs/dc.h" #endif #endif diff --git a/include/wx/defs.h b/include/wx/defs.h index a67a754a5a..47dd0a3d46 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -81,6 +81,8 @@ #ifdef __VISUALC__ # pragma warning(disable:4244) // conversion from double to float # pragma warning(disable:4100) // unreferenced formal parameter +# pragma warning(disable:4511) // copy ctor couldn't be generated +# pragma warning(disable:4512) // operator=() couldn't be generated #endif // __VISUALC__ // suppress some Salford C++ warnings @@ -1066,8 +1068,7 @@ typedef enum { #ifdef __WXMSW__ -/* Stand-ins for Windows types, to avoid - * #including all of windows.h */ +// Stand-ins for Windows types, to avoid #including all of windows.h typedef unsigned long WXHWND; typedef unsigned long WXHANDLE; typedef unsigned long WXHICON; @@ -1095,15 +1096,17 @@ typedef void * WXMSG; typedef unsigned long WXHCONV; typedef unsigned long WXHKEY; typedef unsigned long WXHTREEITEM; + typedef void * WXDRAWITEMSTRUCT; typedef void * WXMEASUREITEMSTRUCT; typedef void * WXLPCREATESTRUCT; + #ifdef __GNUWIN32__ -typedef int (*WXFARPROC)(); + typedef int (*WXFARPROC)(); #elif defined(__WIN32__) -typedef int (__stdcall *WXFARPROC)(); + typedef int (__stdcall *WXFARPROC)(); #else -typedef int (*WXFARPROC)(); + typedef int (*WXFARPROC)(); #endif typedef WXHWND WXWidget; @@ -1198,5 +1201,14 @@ typedef GtkWidget *WXWidget; #endif // __WXMSW__ +// --------------------------------------------------------------------------- +// macro to define a class without copy ctor nor assignment operator +// --------------------------------------------------------------------------- + +#define DECLARE_NO_COPY_CLASS(classname) \ + private: \ + classname(const classname&); \ + classname& operator=(const classname&) + #endif // _WX_DEFS_H_ diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 6ec9156556..564ed2e3fe 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -223,11 +223,13 @@ public: class WXDLLEXPORT wxRect { public: - wxRect(); - wxRect(long x, long y, long w, long h); + wxRect() { x = y = width = height = 0; } + wxRect(long xx, long yy, long ww, long hh) + { x = xx; y = yy; width = ww; height = hh; } wxRect(const wxPoint& topLeft, const wxPoint& bottomRight); wxRect(const wxPoint& pos, const wxSize& size); - wxRect(const wxRect& rect); + + // default copy ctor and assignment operators ok long GetX() const { return x; } void SetX(long xx) { x = xx; } @@ -249,9 +251,8 @@ public: long GetBottom() const { return y + height; } long GetRight() const { return x + width; } - wxRect& operator = (const wxRect& rect); - bool operator == (const wxRect& rect); - bool operator != (const wxRect& rect); + bool operator == (const wxRect& rect) const; + bool operator != (const wxRect& rect) const { return !(*this == rect); } public: long x, y, width, height; diff --git a/include/wx/gtk/dc.h b/include/wx/gtk/dc.h index f7875edf7a..779d6463ef 100644 --- a/include/wx/gtk/dc.h +++ b/include/wx/gtk/dc.h @@ -15,15 +15,6 @@ #pragma interface #endif -#include "wx/defs.h" -#include "wx/object.h" -#include "wx/gdicmn.h" -#include "wx/pen.h" -#include "wx/brush.h" -#include "wx/icon.h" -#include "wx/font.h" -#include "wx/gdicmn.h" - //----------------------------------------------------------------------------- // classes //----------------------------------------------------------------------------- @@ -34,350 +25,134 @@ class wxDC; // constants //----------------------------------------------------------------------------- -#define MM_TEXT 0 +#define MM_TEXT 0 #define MM_ISOTROPIC 1 -#define MM_ANISOTROPIC 2 -#define MM_LOMETRIC 3 -#define MM_HIMETRIC 4 -#define MM_TWIPS 5 -#define MM_POINTS 6 -#define MM_METRIC 7 - -//----------------------------------------------------------------------------- -// global variables -//----------------------------------------------------------------------------- - -extern int wxPageNumber; +#define MM_ANISOTROPIC 2 +#define MM_LOMETRIC 3 +#define MM_HIMETRIC 4 +#define MM_TWIPS 5 +#define MM_POINTS 6 +#define MM_METRIC 7 //----------------------------------------------------------------------------- // wxDC //----------------------------------------------------------------------------- -class wxDC: public wxObject +class wxDC : public wxDCBase { - DECLARE_ABSTRACT_CLASS(wxDC) + DECLARE_ABSTRACT_CLASS(wxDC) public: + wxDC(); + ~wxDC() { } - wxDC(); - ~wxDC(); - - virtual void BeginDrawing() {} - virtual void EndDrawing() {} - - virtual bool Ok() const; - - virtual void FloodFill( long x, long y, const wxColour& col, int style=wxFLOOD_SURFACE ) = 0; - inline void FloodFill(const wxPoint& pt, const wxColour& col, int style=wxFLOOD_SURFACE) - { - FloodFill(pt.x, pt.y, col, style); - } - virtual bool GetPixel( long x, long y, wxColour *col ) const = 0; - inline bool GetPixel(const wxPoint& pt, wxColour *col) const - { - return GetPixel(pt.x, pt.y, col); - } - - virtual void DrawLine( long x1, long y1, long x2, long y2 ) = 0; - inline void DrawLine(const wxPoint& pt1, const wxPoint& pt2) - { - DrawLine(pt1.x, pt1.y, pt2.x, pt2.y); - } - virtual void CrossHair( long x, long y ) = 0; - inline void CrossHair(const wxPoint& pt) - { - CrossHair(pt.x, pt.y); - } - virtual void DrawArc( long x1, long y1, long x2, long y2, long xc, long yc ); - inline void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre) - { - DrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); - } - virtual void DrawEllipticArc( long x, long y, long width, long height, double sa, double ea ) = 0; - virtual void DrawEllipticArc (const wxPoint& pt, const wxSize& sz, double sa, double ea) - { - DrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); - } - virtual void DrawPoint( long x, long y ) = 0; - inline void DrawPoint(const wxPoint& pt) - { - DrawPoint(pt.x, pt.y); - } - virtual void DrawPoint( wxPoint& point ); - - virtual void DrawLines( int n, wxPoint points[], long xoffset = 0, long yoffset = 0 ) = 0; - virtual void DrawLines( wxList *points, long xoffset = 0, long yoffset = 0 ); - virtual void DrawPolygon( int n, wxPoint points[], long xoffset = 0, long yoffset = 0, - int fillStyle=wxODDEVEN_RULE ) = 0; - virtual void DrawPolygon( wxList *lines, long xoffset = 0, long yoffset = 0, - int fillStyle=wxODDEVEN_RULE ); - - virtual void DrawRectangle( long x, long y, long width, long height ) = 0; - inline void DrawRectangle(const wxPoint& pt, const wxSize& sz) - { - DrawRectangle(pt.x, pt.y, sz.x, sz.y); - } - inline void DrawRectangle(const wxRect& rect) - { - DrawRectangle(rect.x, rect.y, rect.width, rect.height); - } - virtual void DrawRoundedRectangle( long x, long y, long width, long height, double radius = 20.0 ) = 0; - inline void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius = 20.0) - { - DrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); - } - inline void DrawRoundedRectangle(const wxRect& rect, double radius = 20.0) - { - DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, radius); - } - virtual void DrawEllipse( long x, long y, long width, long height ) = 0; - inline void DrawEllipse(const wxPoint& pt, const wxSize& sz) - { - DrawEllipse(pt.x, pt.y, sz.x, sz.y); - } - inline void DrawEllipse(const wxRect& rect) - { - DrawEllipse(rect.x, rect.y, rect.width, rect.height); - } - - virtual void DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 ); - virtual void DrawSpline( wxList *points ) = 0; - virtual void DrawSpline( int n, wxPoint points[] ); - - virtual bool CanDrawBitmap(void) const = 0; - virtual void DrawIcon( const wxIcon &icon, long x, long y ) = 0; - inline void DrawIcon( const wxIcon& icon, const wxPoint& pt ) - { - DrawIcon(icon, pt.x, pt.y); - } - virtual void DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask=FALSE ) = 0; - inline void DrawBitmap( const wxBitmap& bitmap, const wxPoint& pt, bool useMask=FALSE ) - { - DrawBitmap(bitmap, pt.x, pt.y, useMask ); - } - virtual bool Blit( long xdest, long ydest, - long width, long height, - wxDC *source, - long xsrc, long ysrc, - int logical_func=wxCOPY, - bool useMask=FALSE ) = 0; - inline bool Blit( const wxPoint& destPt, - const wxSize& sz, - wxDC *source, - const wxPoint& srcPt, - int rop = wxCOPY, - bool useMask=FALSE) - { - return Blit(destPt.x, destPt.y, sz.x, sz.y, source, srcPt.x, srcPt.y, rop, useMask); - } - - virtual void DrawText( const wxString &text, long x, long y, bool use16 = FALSE ) = 0; - inline void DrawText(const wxString& text, const wxPoint& pt, bool use16bit = FALSE ) - { - DrawText(text, pt.x, pt.y, use16bit); - } - virtual bool CanGetTextExtent(void) const = 0; - virtual void GetTextExtent( const wxString &string, - long *width, long *height, - long *descent = (long *) NULL, - long *externalLeading = (long *) NULL, - wxFont *theFont = (wxFont *) NULL, - bool use16 = FALSE ) = 0; - virtual long GetCharWidth(void) = 0; - virtual long GetCharHeight(void) = 0; - - virtual void Clear() = 0; - - virtual void SetFont( const wxFont &font ) = 0; - virtual wxFont& GetFont() const { return (wxFont&)m_font; }; - - virtual void SetPen( const wxPen &pen ) = 0; - virtual wxPen& GetPen() const { return (wxPen&)m_pen; }; - - virtual void SetBrush( const wxBrush &brush ) = 0; - virtual wxBrush& GetBrush() const { return (wxBrush&)m_brush; }; - - virtual void SetBackground( const wxBrush &brush ) = 0; - virtual wxBrush& GetBackground() const { return (wxBrush&)m_backgroundBrush; }; - - virtual void SetLogicalFunction( int function ) = 0; - virtual int GetLogicalFunction() { return m_logicalFunction; }; - - virtual void SetTextForeground( const wxColour &col ); - virtual void SetTextBackground( const wxColour &col ); - virtual wxColour& GetTextBackground() const { return (wxColour&)m_textBackgroundColour; }; - virtual wxColour& GetTextForeground() const { return (wxColour&)m_textForegroundColour; }; - - virtual void SetBackgroundMode( int mode ) = 0; - virtual int GetBackgroundMode() { return m_backgroundMode; }; - - virtual void SetPalette( const wxPalette& palette ) = 0; - void SetColourMap( const wxPalette& palette ) { SetPalette(palette); }; + void SetColourMap( const wxPalette& palette ) { SetPalette(palette); }; // the first two must be overridden and called - virtual void DestroyClippingRegion(void); - virtual void SetClippingRegion( long x, long y, long width, long height ); - virtual void GetClippingBox( long *x, long *y, long *width, long *height ) const; - virtual void SetClippingRegion( const wxRegion ®ion ) = 0; - - virtual long MinX() const { return m_minX; } - virtual long MaxX() const { return m_maxX; } - virtual long MinY() const { return m_minY; } - virtual long MaxY() const { return m_maxY; } - - // Size in device units - virtual void GetSize( int* width, int* height ) const; - inline wxSize GetSize(void) const { int w, h; GetSize(&w, &h); return wxSize(w, h); } - - // Size in millimetres - virtual void GetSizeMM( int* width, int* height ) const; - inline wxSize GetSizeMM(void) const { int w, h; GetSizeMM(&w, &h); return wxSize(w, h); } - - // Resolution in pixels per logical inch - virtual wxSize GetPPI(void) const; - - virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return TRUE; } - virtual void EndDoc() {} - virtual void StartPage() {} - virtual void EndPage() {} - - virtual void SetMapMode( int mode ); - virtual int GetMapMode(void) const { return m_mappingMode; }; - - virtual void SetUserScale( double x, double y ); - virtual void GetUserScale( double *x, double *y ); - virtual void SetLogicalScale( double x, double y ); - virtual void GetLogicalScale( double *x, double *y ); + virtual void DestroyClippingRegion(); - virtual void SetLogicalOrigin( long x, long y ); - virtual void GetLogicalOrigin( long *x, long *y ); - virtual void SetDeviceOrigin( long x, long y ); - virtual void GetDeviceOrigin( long *x, long *y ); + // Resolution in pixels per logical inch + virtual wxSize GetPPI() const; - virtual void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); + virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return TRUE; } + virtual void EndDoc() { } + virtual void StartPage() { } + virtual void EndPage() { } - virtual void SetOptimization( bool WXUNUSED(optimize) ) {} - virtual bool GetOptimization() { return m_optimize; } + virtual void SetMapMode( int mode ); + virtual void SetUserScale( double x, double y ); + virtual void SetLogicalScale( double x, double y ); + virtual void SetLogicalOrigin( long x, long y ); + virtual void SetDeviceOrigin( long x, long y ); - virtual long DeviceToLogicalX(long x) const; - virtual long DeviceToLogicalY(long y) const; - virtual long DeviceToLogicalXRel(long x) const; - virtual long DeviceToLogicalYRel(long y) const; - virtual long LogicalToDeviceX(long x) const; - virtual long LogicalToDeviceY(long y) const; - virtual long LogicalToDeviceXRel(long x) const; - virtual long LogicalToDeviceYRel(long y) const; + virtual void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); - // implementation + // implementation + // -------------- - void CalcBoundingBox( long x, long y ); void ComputeScaleAndOrigin(); long XDEV2LOG(long x) const - { - long new_x = x - m_deviceOriginX; - if (new_x > 0) - return (long)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX; - else - return (long)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX; - } + { + long new_x = x - m_deviceOriginX; + if (new_x > 0) + return (long)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX; + else + return (long)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX; + } long XDEV2LOGREL(long x) const - { - if (x > 0) - return (long)((double)(x) / m_scaleX + 0.5); - else - return (long)((double)(x) / m_scaleX - 0.5); - } + { + if (x > 0) + return (long)((double)(x) / m_scaleX + 0.5); + else + return (long)((double)(x) / m_scaleX - 0.5); + } long YDEV2LOG(long y) const - { - long new_y = y - m_deviceOriginY; - if (new_y > 0) - return (long)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY; - else - return (long)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY; - } + { + long new_y = y - m_deviceOriginY; + if (new_y > 0) + return (long)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY; + else + return (long)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY; + } long YDEV2LOGREL(long y) const - { - if (y > 0) - return (long)((double)(y) / m_scaleY + 0.5); - else - return (long)((double)(y) / m_scaleY - 0.5); - } + { + if (y > 0) + return (long)((double)(y) / m_scaleY + 0.5); + else + return (long)((double)(y) / m_scaleY - 0.5); + } long XLOG2DEV(long x) const - { - long new_x = x - m_logicalOriginX; - if (new_x > 0) - return (long)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX; - else - return (long)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX; - } + { + long new_x = x - m_logicalOriginX; + if (new_x > 0) + return (long)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX; + else + return (long)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX; + } long XLOG2DEVREL(long x) const - { - if (x > 0) - return (long)((double)(x) * m_scaleX + 0.5); - else - return (long)((double)(x) * m_scaleX - 0.5); - } + { + if (x > 0) + return (long)((double)(x) * m_scaleX + 0.5); + else + return (long)((double)(x) * m_scaleX - 0.5); + } long YLOG2DEV(long y) const - { - long new_y = y - m_logicalOriginY; - if (new_y > 0) - return (long)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY; - else - return (long)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY; - } + { + long new_y = y - m_logicalOriginY; + if (new_y > 0) + return (long)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY; + else + return (long)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY; + } long YLOG2DEVREL(long y) const - { - if (y > 0) - return (long)((double)(y) * m_scaleY + 0.5); - else - return (long)((double)(y) * m_scaleY - 0.5); - } + { + if (y > 0) + return (long)((double)(y) * m_scaleY + 0.5); + else + return (long)((double)(y) * m_scaleY - 0.5); + } + +protected: + // base class pure virtuals implemented here + virtual void DoSetClippingRegion(long x, long y, long width, long height); + virtual void DoGetSize(int *width, int *height) const; + virtual void DoGetSizeMM(int* width, int* height) const; +public: + // GTK-specific member variables - public: - - bool m_ok; - bool m_colour; - - // not sure, what these mean - bool m_clipping; // Is clipping on right now ? - bool m_isInteractive; // Is GetPixel possible ? - bool m_autoSetting; // wxMSW only ? - bool m_dontDelete; // wxMSW only ? - bool m_optimize; // wxMSW only ? - - wxPen m_pen; - wxBrush m_brush; - wxBrush m_backgroundBrush; - wxColour m_textForegroundColour; - wxColour m_textBackgroundColour; - wxFont m_font; - - int m_logicalFunction; - int m_backgroundMode; int m_textAlignment; // gone in wxWin 2.0 ? - int m_mappingMode; + // not sure what for, but what is a mm on a screen you don't know the size + // of? + double m_mm_to_pix_x, + m_mm_to_pix_y; - // not sure what for, but what is a mm on a screen you don't know the size of? - double m_mm_to_pix_x,m_mm_to_pix_y; - - long m_deviceOriginX,m_deviceOriginY; - - long m_logicalOriginX,m_logicalOriginY; // User defined. - - double m_scaleX,m_scaleY; - double m_logicalScaleX,m_logicalScaleY; - double m_userScaleX,m_userScaleY; - long m_signX,m_signY; - - bool m_needComputeScaleX,m_needComputeScaleY; // not yet used + bool m_needComputeScaleX, + m_needComputeScaleY; // not yet used float m_scaleFactor; // wxPSDC wants to have this. Will disappear. - - long m_clipX1,m_clipY1,m_clipX2,m_clipY2; - long m_minX,m_maxX,m_minY,m_maxY; }; #endif // __GTKDCH__ diff --git a/include/wx/gtk/window.h b/include/wx/gtk/window.h index 84de58e5ff..beb38b7c4b 100644 --- a/include/wx/gtk/window.h +++ b/include/wx/gtk/window.h @@ -230,6 +230,7 @@ public: void Init(); private: + DECLARE_NO_COPY_CLASS(wxWindow); DECLARE_EVENT_TABLE() }; diff --git a/include/wx/gtk1/dc.h b/include/wx/gtk1/dc.h index f7875edf7a..779d6463ef 100644 --- a/include/wx/gtk1/dc.h +++ b/include/wx/gtk1/dc.h @@ -15,15 +15,6 @@ #pragma interface #endif -#include "wx/defs.h" -#include "wx/object.h" -#include "wx/gdicmn.h" -#include "wx/pen.h" -#include "wx/brush.h" -#include "wx/icon.h" -#include "wx/font.h" -#include "wx/gdicmn.h" - //----------------------------------------------------------------------------- // classes //----------------------------------------------------------------------------- @@ -34,350 +25,134 @@ class wxDC; // constants //----------------------------------------------------------------------------- -#define MM_TEXT 0 +#define MM_TEXT 0 #define MM_ISOTROPIC 1 -#define MM_ANISOTROPIC 2 -#define MM_LOMETRIC 3 -#define MM_HIMETRIC 4 -#define MM_TWIPS 5 -#define MM_POINTS 6 -#define MM_METRIC 7 - -//----------------------------------------------------------------------------- -// global variables -//----------------------------------------------------------------------------- - -extern int wxPageNumber; +#define MM_ANISOTROPIC 2 +#define MM_LOMETRIC 3 +#define MM_HIMETRIC 4 +#define MM_TWIPS 5 +#define MM_POINTS 6 +#define MM_METRIC 7 //----------------------------------------------------------------------------- // wxDC //----------------------------------------------------------------------------- -class wxDC: public wxObject +class wxDC : public wxDCBase { - DECLARE_ABSTRACT_CLASS(wxDC) + DECLARE_ABSTRACT_CLASS(wxDC) public: + wxDC(); + ~wxDC() { } - wxDC(); - ~wxDC(); - - virtual void BeginDrawing() {} - virtual void EndDrawing() {} - - virtual bool Ok() const; - - virtual void FloodFill( long x, long y, const wxColour& col, int style=wxFLOOD_SURFACE ) = 0; - inline void FloodFill(const wxPoint& pt, const wxColour& col, int style=wxFLOOD_SURFACE) - { - FloodFill(pt.x, pt.y, col, style); - } - virtual bool GetPixel( long x, long y, wxColour *col ) const = 0; - inline bool GetPixel(const wxPoint& pt, wxColour *col) const - { - return GetPixel(pt.x, pt.y, col); - } - - virtual void DrawLine( long x1, long y1, long x2, long y2 ) = 0; - inline void DrawLine(const wxPoint& pt1, const wxPoint& pt2) - { - DrawLine(pt1.x, pt1.y, pt2.x, pt2.y); - } - virtual void CrossHair( long x, long y ) = 0; - inline void CrossHair(const wxPoint& pt) - { - CrossHair(pt.x, pt.y); - } - virtual void DrawArc( long x1, long y1, long x2, long y2, long xc, long yc ); - inline void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre) - { - DrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); - } - virtual void DrawEllipticArc( long x, long y, long width, long height, double sa, double ea ) = 0; - virtual void DrawEllipticArc (const wxPoint& pt, const wxSize& sz, double sa, double ea) - { - DrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); - } - virtual void DrawPoint( long x, long y ) = 0; - inline void DrawPoint(const wxPoint& pt) - { - DrawPoint(pt.x, pt.y); - } - virtual void DrawPoint( wxPoint& point ); - - virtual void DrawLines( int n, wxPoint points[], long xoffset = 0, long yoffset = 0 ) = 0; - virtual void DrawLines( wxList *points, long xoffset = 0, long yoffset = 0 ); - virtual void DrawPolygon( int n, wxPoint points[], long xoffset = 0, long yoffset = 0, - int fillStyle=wxODDEVEN_RULE ) = 0; - virtual void DrawPolygon( wxList *lines, long xoffset = 0, long yoffset = 0, - int fillStyle=wxODDEVEN_RULE ); - - virtual void DrawRectangle( long x, long y, long width, long height ) = 0; - inline void DrawRectangle(const wxPoint& pt, const wxSize& sz) - { - DrawRectangle(pt.x, pt.y, sz.x, sz.y); - } - inline void DrawRectangle(const wxRect& rect) - { - DrawRectangle(rect.x, rect.y, rect.width, rect.height); - } - virtual void DrawRoundedRectangle( long x, long y, long width, long height, double radius = 20.0 ) = 0; - inline void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius = 20.0) - { - DrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); - } - inline void DrawRoundedRectangle(const wxRect& rect, double radius = 20.0) - { - DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, radius); - } - virtual void DrawEllipse( long x, long y, long width, long height ) = 0; - inline void DrawEllipse(const wxPoint& pt, const wxSize& sz) - { - DrawEllipse(pt.x, pt.y, sz.x, sz.y); - } - inline void DrawEllipse(const wxRect& rect) - { - DrawEllipse(rect.x, rect.y, rect.width, rect.height); - } - - virtual void DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 ); - virtual void DrawSpline( wxList *points ) = 0; - virtual void DrawSpline( int n, wxPoint points[] ); - - virtual bool CanDrawBitmap(void) const = 0; - virtual void DrawIcon( const wxIcon &icon, long x, long y ) = 0; - inline void DrawIcon( const wxIcon& icon, const wxPoint& pt ) - { - DrawIcon(icon, pt.x, pt.y); - } - virtual void DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask=FALSE ) = 0; - inline void DrawBitmap( const wxBitmap& bitmap, const wxPoint& pt, bool useMask=FALSE ) - { - DrawBitmap(bitmap, pt.x, pt.y, useMask ); - } - virtual bool Blit( long xdest, long ydest, - long width, long height, - wxDC *source, - long xsrc, long ysrc, - int logical_func=wxCOPY, - bool useMask=FALSE ) = 0; - inline bool Blit( const wxPoint& destPt, - const wxSize& sz, - wxDC *source, - const wxPoint& srcPt, - int rop = wxCOPY, - bool useMask=FALSE) - { - return Blit(destPt.x, destPt.y, sz.x, sz.y, source, srcPt.x, srcPt.y, rop, useMask); - } - - virtual void DrawText( const wxString &text, long x, long y, bool use16 = FALSE ) = 0; - inline void DrawText(const wxString& text, const wxPoint& pt, bool use16bit = FALSE ) - { - DrawText(text, pt.x, pt.y, use16bit); - } - virtual bool CanGetTextExtent(void) const = 0; - virtual void GetTextExtent( const wxString &string, - long *width, long *height, - long *descent = (long *) NULL, - long *externalLeading = (long *) NULL, - wxFont *theFont = (wxFont *) NULL, - bool use16 = FALSE ) = 0; - virtual long GetCharWidth(void) = 0; - virtual long GetCharHeight(void) = 0; - - virtual void Clear() = 0; - - virtual void SetFont( const wxFont &font ) = 0; - virtual wxFont& GetFont() const { return (wxFont&)m_font; }; - - virtual void SetPen( const wxPen &pen ) = 0; - virtual wxPen& GetPen() const { return (wxPen&)m_pen; }; - - virtual void SetBrush( const wxBrush &brush ) = 0; - virtual wxBrush& GetBrush() const { return (wxBrush&)m_brush; }; - - virtual void SetBackground( const wxBrush &brush ) = 0; - virtual wxBrush& GetBackground() const { return (wxBrush&)m_backgroundBrush; }; - - virtual void SetLogicalFunction( int function ) = 0; - virtual int GetLogicalFunction() { return m_logicalFunction; }; - - virtual void SetTextForeground( const wxColour &col ); - virtual void SetTextBackground( const wxColour &col ); - virtual wxColour& GetTextBackground() const { return (wxColour&)m_textBackgroundColour; }; - virtual wxColour& GetTextForeground() const { return (wxColour&)m_textForegroundColour; }; - - virtual void SetBackgroundMode( int mode ) = 0; - virtual int GetBackgroundMode() { return m_backgroundMode; }; - - virtual void SetPalette( const wxPalette& palette ) = 0; - void SetColourMap( const wxPalette& palette ) { SetPalette(palette); }; + void SetColourMap( const wxPalette& palette ) { SetPalette(palette); }; // the first two must be overridden and called - virtual void DestroyClippingRegion(void); - virtual void SetClippingRegion( long x, long y, long width, long height ); - virtual void GetClippingBox( long *x, long *y, long *width, long *height ) const; - virtual void SetClippingRegion( const wxRegion ®ion ) = 0; - - virtual long MinX() const { return m_minX; } - virtual long MaxX() const { return m_maxX; } - virtual long MinY() const { return m_minY; } - virtual long MaxY() const { return m_maxY; } - - // Size in device units - virtual void GetSize( int* width, int* height ) const; - inline wxSize GetSize(void) const { int w, h; GetSize(&w, &h); return wxSize(w, h); } - - // Size in millimetres - virtual void GetSizeMM( int* width, int* height ) const; - inline wxSize GetSizeMM(void) const { int w, h; GetSizeMM(&w, &h); return wxSize(w, h); } - - // Resolution in pixels per logical inch - virtual wxSize GetPPI(void) const; - - virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return TRUE; } - virtual void EndDoc() {} - virtual void StartPage() {} - virtual void EndPage() {} - - virtual void SetMapMode( int mode ); - virtual int GetMapMode(void) const { return m_mappingMode; }; - - virtual void SetUserScale( double x, double y ); - virtual void GetUserScale( double *x, double *y ); - virtual void SetLogicalScale( double x, double y ); - virtual void GetLogicalScale( double *x, double *y ); + virtual void DestroyClippingRegion(); - virtual void SetLogicalOrigin( long x, long y ); - virtual void GetLogicalOrigin( long *x, long *y ); - virtual void SetDeviceOrigin( long x, long y ); - virtual void GetDeviceOrigin( long *x, long *y ); + // Resolution in pixels per logical inch + virtual wxSize GetPPI() const; - virtual void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); + virtual bool StartDoc( const wxString& WXUNUSED(message) ) { return TRUE; } + virtual void EndDoc() { } + virtual void StartPage() { } + virtual void EndPage() { } - virtual void SetOptimization( bool WXUNUSED(optimize) ) {} - virtual bool GetOptimization() { return m_optimize; } + virtual void SetMapMode( int mode ); + virtual void SetUserScale( double x, double y ); + virtual void SetLogicalScale( double x, double y ); + virtual void SetLogicalOrigin( long x, long y ); + virtual void SetDeviceOrigin( long x, long y ); - virtual long DeviceToLogicalX(long x) const; - virtual long DeviceToLogicalY(long y) const; - virtual long DeviceToLogicalXRel(long x) const; - virtual long DeviceToLogicalYRel(long y) const; - virtual long LogicalToDeviceX(long x) const; - virtual long LogicalToDeviceY(long y) const; - virtual long LogicalToDeviceXRel(long x) const; - virtual long LogicalToDeviceYRel(long y) const; + virtual void SetAxisOrientation( bool xLeftRight, bool yBottomUp ); - // implementation + // implementation + // -------------- - void CalcBoundingBox( long x, long y ); void ComputeScaleAndOrigin(); long XDEV2LOG(long x) const - { - long new_x = x - m_deviceOriginX; - if (new_x > 0) - return (long)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX; - else - return (long)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX; - } + { + long new_x = x - m_deviceOriginX; + if (new_x > 0) + return (long)((double)(new_x) / m_scaleX + 0.5) * m_signX + m_logicalOriginX; + else + return (long)((double)(new_x) / m_scaleX - 0.5) * m_signX + m_logicalOriginX; + } long XDEV2LOGREL(long x) const - { - if (x > 0) - return (long)((double)(x) / m_scaleX + 0.5); - else - return (long)((double)(x) / m_scaleX - 0.5); - } + { + if (x > 0) + return (long)((double)(x) / m_scaleX + 0.5); + else + return (long)((double)(x) / m_scaleX - 0.5); + } long YDEV2LOG(long y) const - { - long new_y = y - m_deviceOriginY; - if (new_y > 0) - return (long)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY; - else - return (long)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY; - } + { + long new_y = y - m_deviceOriginY; + if (new_y > 0) + return (long)((double)(new_y) / m_scaleY + 0.5) * m_signY + m_logicalOriginY; + else + return (long)((double)(new_y) / m_scaleY - 0.5) * m_signY + m_logicalOriginY; + } long YDEV2LOGREL(long y) const - { - if (y > 0) - return (long)((double)(y) / m_scaleY + 0.5); - else - return (long)((double)(y) / m_scaleY - 0.5); - } + { + if (y > 0) + return (long)((double)(y) / m_scaleY + 0.5); + else + return (long)((double)(y) / m_scaleY - 0.5); + } long XLOG2DEV(long x) const - { - long new_x = x - m_logicalOriginX; - if (new_x > 0) - return (long)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX; - else - return (long)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX; - } + { + long new_x = x - m_logicalOriginX; + if (new_x > 0) + return (long)((double)(new_x) * m_scaleX + 0.5) * m_signX + m_deviceOriginX; + else + return (long)((double)(new_x) * m_scaleX - 0.5) * m_signX + m_deviceOriginX; + } long XLOG2DEVREL(long x) const - { - if (x > 0) - return (long)((double)(x) * m_scaleX + 0.5); - else - return (long)((double)(x) * m_scaleX - 0.5); - } + { + if (x > 0) + return (long)((double)(x) * m_scaleX + 0.5); + else + return (long)((double)(x) * m_scaleX - 0.5); + } long YLOG2DEV(long y) const - { - long new_y = y - m_logicalOriginY; - if (new_y > 0) - return (long)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY; - else - return (long)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY; - } + { + long new_y = y - m_logicalOriginY; + if (new_y > 0) + return (long)((double)(new_y) * m_scaleY + 0.5) * m_signY + m_deviceOriginY; + else + return (long)((double)(new_y) * m_scaleY - 0.5) * m_signY + m_deviceOriginY; + } long YLOG2DEVREL(long y) const - { - if (y > 0) - return (long)((double)(y) * m_scaleY + 0.5); - else - return (long)((double)(y) * m_scaleY - 0.5); - } + { + if (y > 0) + return (long)((double)(y) * m_scaleY + 0.5); + else + return (long)((double)(y) * m_scaleY - 0.5); + } + +protected: + // base class pure virtuals implemented here + virtual void DoSetClippingRegion(long x, long y, long width, long height); + virtual void DoGetSize(int *width, int *height) const; + virtual void DoGetSizeMM(int* width, int* height) const; +public: + // GTK-specific member variables - public: - - bool m_ok; - bool m_colour; - - // not sure, what these mean - bool m_clipping; // Is clipping on right now ? - bool m_isInteractive; // Is GetPixel possible ? - bool m_autoSetting; // wxMSW only ? - bool m_dontDelete; // wxMSW only ? - bool m_optimize; // wxMSW only ? - - wxPen m_pen; - wxBrush m_brush; - wxBrush m_backgroundBrush; - wxColour m_textForegroundColour; - wxColour m_textBackgroundColour; - wxFont m_font; - - int m_logicalFunction; - int m_backgroundMode; int m_textAlignment; // gone in wxWin 2.0 ? - int m_mappingMode; + // not sure what for, but what is a mm on a screen you don't know the size + // of? + double m_mm_to_pix_x, + m_mm_to_pix_y; - // not sure what for, but what is a mm on a screen you don't know the size of? - double m_mm_to_pix_x,m_mm_to_pix_y; - - long m_deviceOriginX,m_deviceOriginY; - - long m_logicalOriginX,m_logicalOriginY; // User defined. - - double m_scaleX,m_scaleY; - double m_logicalScaleX,m_logicalScaleY; - double m_userScaleX,m_userScaleY; - long m_signX,m_signY; - - bool m_needComputeScaleX,m_needComputeScaleY; // not yet used + bool m_needComputeScaleX, + m_needComputeScaleY; // not yet used float m_scaleFactor; // wxPSDC wants to have this. Will disappear. - - long m_clipX1,m_clipY1,m_clipX2,m_clipY2; - long m_minX,m_maxX,m_minY,m_maxY; }; #endif // __GTKDCH__ diff --git a/include/wx/gtk1/window.h b/include/wx/gtk1/window.h index 84de58e5ff..beb38b7c4b 100644 --- a/include/wx/gtk1/window.h +++ b/include/wx/gtk1/window.h @@ -230,6 +230,7 @@ public: void Init(); private: + DECLARE_NO_COPY_CLASS(wxWindow); DECLARE_EVENT_TABLE() }; diff --git a/include/wx/msw/control.h b/include/wx/msw/control.h index eb9b852be1..e4410e7b0d 100644 --- a/include/wx/msw/control.h +++ b/include/wx/msw/control.h @@ -57,11 +57,9 @@ public: // MSW-specific - // Window procedure - virtual void MSWOnMouseMove(int x, int y, WXUINT flags); - virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result); - - void OnEraseBackground(wxEraseEvent& event); +#ifdef __WIN95__ + virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); +#endif // Win95 // For ownerdraw items virtual bool MSWOnDraw(WXDRAWITEMSTRUCT *WXUNUSED(item)) { return FALSE; }; @@ -70,6 +68,8 @@ public: wxFunction GetCallback() { return m_callback; } wxList& GetSubcontrols() { return m_subControls; } + void OnEraseBackground(wxEraseEvent& event); + protected: wxFunction m_callback; // Callback associated with the window diff --git a/include/wx/msw/dc.h b/include/wx/msw/dc.h index 07d81cb653..f2ca533725 100644 --- a/include/wx/msw/dc.h +++ b/include/wx/msw/dc.h @@ -6,397 +6,185 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_DC_H_ #define _WX_DC_H_ #ifdef __GNUG__ -#pragma interface "dc.h" + #pragma interface "dc.h" #endif -#include "wx/pen.h" -#include "wx/brush.h" -#include "wx/icon.h" -#include "wx/font.h" -#include "wx/gdicmn.h" -#include "wx/window.h" - -// Clash with Windows header files -#ifdef StartDoc -#undef StartDoc -#endif - -#ifdef DrawText -#undef DrawText -#endif - -#ifdef GetCharWidth -#undef GetCharWidth -#endif - -class WXDLLEXPORT wxDC: public wxObject +class WXDLLEXPORT wxDC : public wxDCBase { - DECLARE_ABSTRACT_CLASS(wxDC) - protected: + DECLARE_DYNAMIC_CLASS(wxDC) + public: - wxDC(void); - ~wxDC(void); - -#ifdef WX_COMP_INLINE_NO_CLASS - inline void BeginDrawing(void) {} - inline void EndDrawing(void) {} -#else - inline void wxDC::BeginDrawing(void) {} - inline void wxDC::EndDrawing(void) {} -#endif + wxDC(); + ~wxDC(); + + // implement base class pure virtuals + // ---------------------------------- + + virtual void Clear(); + + virtual bool StartDoc(const wxString& message); + virtual void EndDoc(); + + virtual void StartPage(); + virtual void EndPage(); + + virtual void SetFont(const wxFont& font); + virtual void SetPen(const wxPen& pen); + virtual void SetBrush(const wxBrush& brush); + virtual void SetBackground(const wxBrush& brush); + virtual void SetBackgroundMode(int mode); + virtual void SetPalette(const wxPalette& palette); + + virtual void DestroyClippingRegion(); + + virtual long GetCharHeight() const; + virtual long GetCharWidth() const; + virtual void GetTextExtent(const wxString& string, + long *x, long *y, + long *descent = NULL, + long *externalLeading = NULL, + wxFont *theFont = NULL) const; + + virtual bool CanDrawBitmap() const; + virtual bool CanGetTextExtent() const; + virtual int GetDepth() const; + virtual wxSize GetPPI() const; + + virtual void SetMapMode(int mode); + virtual void SetUserScale(double x, double y); + virtual void SetSystemScale(double x, double y); + virtual void SetLogicalScale(double x, double y); + virtual void SetLogicalOrigin(long x, long y); + virtual void SetDeviceOrigin(long x, long y); + virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); + virtual void SetLogicalFunction(int function); + + // implementation from now on + // -------------------------- + + virtual void SetRop(WXHDC cdc); + virtual void DoClipping(WXHDC cdc); + virtual void SelectOldObjects(WXHDC dc); + + wxWindow *GetWindow() const { return m_canvas; } + void SetWindow(wxWindow *win) { m_canvas = win; } + + WXHDC GetHDC() const { return m_hDC; } + void SetHDC(WXHDC dc, bool bOwnsDC = FALSE) + { + m_hDC = dc; + m_bOwnsDC = bOwnsDC; + } - virtual void FloodFill(long x1, long y1, const wxColour& col, int style=wxFLOOD_SURFACE) ; - inline void FloodFill(const wxPoint& pt, const wxColour& col, int style=wxFLOOD_SURFACE) - { - FloodFill(pt.x, pt.y, col, style); - } - - virtual bool GetPixel(long x1, long y1, wxColour *col) const ; - inline bool GetPixel(const wxPoint& pt, wxColour *col) const - { - return GetPixel(pt.x, pt.y, col); - } - - virtual void DrawLine(long x1, long y1, long x2, long y2); - inline void DrawLine(const wxPoint& pt1, const wxPoint& pt2) - { - DrawLine(pt1.x, pt1.y, pt2.x, pt2.y); - } - - virtual void CrossHair(long x, long y) ; - inline void CrossHair(const wxPoint& pt) - { - CrossHair(pt.x, pt.y); - } - - virtual void DrawArc(long x1,long y1,long x2,long y2,long xc, long yc); - inline void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre) - { - DrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); - } - - virtual void DrawEllipticArc (long x, long y, long w, long h, double sa, double ea); - virtual void DrawEllipticArc (const wxPoint& pt, const wxSize& sz, double sa, double ea) - { - DrawEllipticArc(pt.x, pt.y, sz.x, sz.y, sa, ea); - } - - virtual void DrawPoint(long x, long y); - inline void DrawPoint(const wxPoint& pt) - { - DrawPoint(pt.x, pt.y); - } - - virtual void DrawLines(int n, wxPoint points[], long xoffset = 0, long yoffset = 0); - - virtual void DrawPolygon(int n, wxPoint points[], long xoffset = 0, long yoffset = 0, int fillStyle=wxODDEVEN_RULE); - - virtual void DrawRectangle(long x, long y, long width, long height); - inline void DrawRectangle(const wxPoint& pt, const wxSize& sz) - { - DrawRectangle(pt.x, pt.y, sz.x, sz.y); - } - inline void DrawRectangle(const wxRect& rect) - { - DrawRectangle(rect.x, rect.y, rect.width, rect.height); - } - - virtual void DrawRoundedRectangle(long x, long y, long width, long height, double radius = 20.0); - inline void DrawRoundedRectangle(const wxPoint& pt, const wxSize& sz, double radius = 20.0) - { - DrawRoundedRectangle(pt.x, pt.y, sz.x, sz.y, radius); - } - inline void DrawRoundedRectangle(const wxRect& rect, double radius = 20.0) - { - DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, radius); - } - - virtual void DrawEllipse(long x, long y, long width, long height); - inline void DrawEllipse(const wxPoint& pt, const wxSize& sz) - { - DrawEllipse(pt.x, pt.y, sz.x, sz.y); - } - inline void DrawEllipse(const wxRect& rect) - { - DrawEllipse(rect.x, rect.y, rect.width, rect.height); - } - - virtual void DrawIcon(const wxIcon& icon, long x, long y); - inline void DrawIcon(const wxIcon& icon, const wxPoint& pt) - { - DrawIcon(icon, pt.x, pt.y); - } - - virtual void DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask=FALSE ); - - inline void DrawPoint(wxPoint& point) { DrawPoint(point.x, point.y); } - virtual void DrawLines(wxList *list, long xoffset = 0, long yoffset = 0); - virtual void DrawPolygon(wxList *list, long xoffset = 0, long yoffset = 0, int fillStyle=wxODDEVEN_RULE); - - virtual void DrawText(const wxString& text, long x, long y, bool use16bit = FALSE); - inline void DrawText(const wxString& text, const wxPoint& pt, bool use16bit = FALSE) - { - DrawText(text, pt.x, pt.y, use16bit); - } - - virtual bool Blit(long xdest, long ydest, long width, long height, - wxDC *source, long xsrc, long ysrc, int rop = wxCOPY, bool useMask = FALSE); - inline bool Blit(const wxPoint& destPt, const wxSize& sz, - wxDC *source, const wxPoint& srcPt, int rop = wxCOPY, bool useMask = FALSE) - { - return Blit(destPt.x, destPt.y, sz.x, sz.y, source, srcPt.x, srcPt.y, rop, useMask); - } +protected: + virtual void DoFloodFill(long x, long y, const wxColour& col, + int style = wxFLOOD_SURFACE); + + virtual bool DoGetPixel(long x, long y, wxColour *col) const; + + virtual void DoDrawPoint(long x, long y); + virtual void DoDrawLine(long x1, long y1, long x2, long y2); + + virtual void DoDrawArc(long x1, long y1, + long x2, long y2, + long xc, long yc); + virtual void DoDrawEllipticArc(long x, long y, long w, long h, + double sa, double ea); + + virtual void DoDrawRectangle(long x, long y, long width, long height); + virtual void DoDrawRoundedRectangle(long x, long y, + long width, long height, + double radius); + virtual void DoDrawEllipse(long x, long y, long width, long height); + + virtual void DoCrossHair(long x, long y); + + virtual void DoDrawIcon(const wxIcon& icon, long x, long y); + virtual void DoDrawBitmap(const wxBitmap &bmp, long x, long y, + bool useMask = FALSE); + + virtual void DoDrawText(const wxString& text, long x, long y); + + virtual bool DoBlit(long xdest, long ydest, long width, long height, + wxDC *source, long xsrc, long ysrc, + int rop = wxCOPY, bool useMask = FALSE); + + // this is gnarly - we can't even call this function DoSetClippingRegion() + // because of virtual function hiding + virtual void DoSetClippingRegionAsRegion(const wxRegion& region); + virtual void DoSetClippingRegion(long x, long y, + long width, long height); + virtual void DoGetClippingRegion(long *x, long *y, + long *width, long *height) + { + GetClippingBox(x, y, width, height); + } + + virtual void DoGetSize(int *width, int *height) const; + virtual void DoGetSizeMM(int* width, int* height) const; + + virtual void DoDrawLines(int n, wxPoint points[], + long xoffset, long yoffset); + virtual void DoDrawPolygon(int n, wxPoint points[], + long xoffset, long yoffset, + int fillStyle = wxODDEVEN_RULE); #if wxUSE_SPLINES - // Splines - // 3-point spline - virtual void DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3); - // Any number of control points - a list of pointers to wxPoints - virtual void DrawSpline(wxList *points); - virtual void DrawSpline(int n, wxPoint points[]); -#endif - virtual void Clear(void); - virtual void SetFont(const wxFont& font); - virtual void SetPen(const wxPen& pen); - virtual void SetBrush(const wxBrush& brush); - virtual void SetLogicalFunction(int function); - virtual void SetBackground(const wxBrush& brush); - virtual void SetBackgroundMode(int mode); - - virtual void SetClippingRegion(long x, long y, long width, long height); - inline void SetClippingRegion(const wxPoint& pt, const wxSize& sz) - { - SetClippingRegion(pt.x, pt.y, sz.x, sz.y); - } - inline void SetClippingRegion(const wxRect& rect) - { - SetClippingRegion(rect.x, rect.y, rect.width, rect.height); - } - virtual void SetClippingRegion(const wxRegion& region); - - virtual void SetPalette(const wxPalette& palette); -#if WXWIN_COMPATIBILITY - virtual inline void SetColourMap(const wxPalette& palette) { SetPalette(palette); }; -#endif - virtual void DestroyClippingRegion(void); - virtual long GetCharHeight(void) const; - virtual long GetCharWidth(void) const; - virtual void GetTextExtent(const wxString& string, long *x, long *y, - long *descent = NULL, long *externalLeading = NULL, - wxFont *theFont = NULL, bool use16bit = FALSE) const; -#if WXWIN_COMPATIBILITY - void GetTextExtent(const wxString& string, float *x, float *y, - float *descent = NULL, float *externalLeading = NULL, - wxFont *theFont = NULL, bool use16bit = FALSE) const ; -#endif - - // Size in device units - virtual void GetSize(int* width, int* height) const; - inline wxSize GetSize() const { int w, h; GetSize(&w, &h); return wxSize(w, h); } - - // Size in mm - virtual void GetSizeMM(int* width, int* height) const ; - inline wxSize GetSizeMM() const { int w, h; GetSizeMM(&w, &h); return wxSize(w, h); } - - // Resolution in Pixels per inch - virtual wxSize GetPPI(void) const ; - - // Compatibility -#if WXWIN_COMPATIBILITY - inline void GetSize(float* width, float* height) const { int w, h; GetSize(& w, & h); *width = w; *height = h; } - inline void GetSizeMM(float *width, float *height) const { long w, h; GetSizeMM(& w, & h); *width = (float) w; *height = (float) h; } -#endif - - virtual bool StartDoc(const wxString& message); - virtual void EndDoc(void); - virtual void StartPage(void); - virtual void EndPage(void); - virtual void SetMapMode(int mode); - virtual void SetUserScale(double x, double y); - virtual void SetSystemScale(double x, double y); - virtual void SetLogicalOrigin(long x, long y); - virtual void SetDeviceOrigin(long x, long y); - virtual void SetAxisOrientation(bool xLeftRight, bool yBottomUp); - - // This group of functions does actual conversion - // of the input, as you'd expect. - - long DeviceToLogicalX(long x) const; - long DeviceToLogicalY(long y) const; - long DeviceToLogicalXRel(long x) const; - long DeviceToLogicalYRel(long y) const; - long LogicalToDeviceX(long x) const; - long LogicalToDeviceY(long y) const; - long LogicalToDeviceXRel(long x) const; - long LogicalToDeviceYRel(long y) const; - - // This group of functions may not do any conversion - // if m_scaleGDI is TRUE, since the HDC does the - // conversion automatically. - // m_scaleGDI NOW OBSOLETE - long ImplDeviceToLogicalX(long x) const; - long ImplDeviceToLogicalY(long y) const; - long ImplDeviceToLogicalXRel(long x) const; - long ImplDeviceToLogicalYRel(long y) const; - long ImplLogicalToDeviceX(long x) const; - long ImplLogicalToDeviceY(long y) const; - long ImplLogicalToDeviceXRel(long x) const; - long ImplLogicalToDeviceYRel(long y) const; - - virtual bool CanDrawBitmap(void) const; - virtual bool CanGetTextExtent(void) const; - - virtual void SetTextForeground(const wxColour& colour); - virtual void SetTextBackground(const wxColour& colour); - inline virtual bool Ok(void) const {return m_ok;}; - inline virtual int GetMapMode(void) const {return m_mappingMode;}; - - inline virtual wxBrush& GetBackground(void) const { return (wxBrush&) m_backgroundBrush ;} - inline virtual wxBrush& GetBrush(void) const { return (wxBrush&) m_brush ;} - inline virtual wxFont& GetFont(void) const { return (wxFont&) m_font ;} - inline virtual int GetLogicalFunction(void) const { return m_logicalFunction ;} - inline virtual wxPen& GetPen(void) const { return (wxPen&) m_pen ;} - inline virtual wxColour&GetTextBackground(void) const { return (wxColour&) m_textBackgroundColour ;} - inline virtual wxColour&GetTextForeground(void) const { return (wxColour&) m_textForegroundColour ;} - - virtual void SetLogicalScale(double x, double y); - virtual inline void GetUserScale(double* x, double *y) const { *x = m_userScaleX; *y = m_userScaleY; } - virtual void CalcBoundingBox(long x, long y); - // Get the final bounding box of the PostScript or Metafile picture. - virtual inline long MinX(void) const { return m_minX; } - virtual inline long MaxX(void) const { return m_maxX; } - virtual inline long MinY(void) const { return m_minY; } - virtual inline long MaxY(void) const { return m_maxY; } - // Sometimes we need to override optimization, e.g. - // if other software is drawing onto our surface and we - // can't be sure of who's done what. - virtual inline void SetOptimization(bool WXUNUSED(opt)) { } - virtual inline bool GetOptimization(void) { return FALSE; } - - virtual void GetClippingBox(long *x,long *y,long *w,long *h) const ; - inline void GetClippingBox(wxRect& rect) const - { - long x, y, w, h; - GetClippingBox(&x, &y, &w, &h); rect.x = x; rect.y = y; rect.width = w; rect.height = h; - } - - // This should probably be made available on other platforms -#ifdef WX_COMP_INLINE_NO_CLASS - int GetDepth(void) const ; -#else - int wxDC::GetDepth(void) const ; -#endif - -// Implementation - virtual void SetRop(WXHDC cdc); - virtual void DoClipping(WXHDC cdc); - virtual void SelectOldObjects(WXHDC dc); - - inline wxWindow *GetWindow(void) const { return m_canvas; } - inline void SetWindow(wxWindow *win) { m_canvas = win; } - inline WXHDC GetHDC(void) const { return m_hDC; } - inline void SetHDC(WXHDC dc, bool bOwnsDC = FALSE) { m_hDC = dc; m_bOwnsDC = bOwnsDC; } - -protected: - bool m_colour; - bool m_ok; - bool m_clipping; - bool m_isInteractive; - - // Coordinate system variables - long m_logicalOriginX; - long m_logicalOriginY; - - long m_deviceOriginX; - long m_deviceOriginY; - - double m_logicalScaleX; - double m_logicalScaleY; - - double m_userScaleX; - double m_userScaleY; - - int m_signX; // Used by SetAxisOrientation() to - int m_signY; // invert the axes - - int m_mappingMode; - - long m_minX; // bounding box - long m_minY; - long m_maxX; - long m_maxY; - - int m_logicalFunction; - int m_backgroundMode; - - wxPen m_pen; - wxBrush m_brush; - wxBrush m_backgroundBrush; - wxColour m_textForegroundColour; - wxColour m_textBackgroundColour; - wxFont m_font; - wxPalette m_palette; - int m_clipX1; - int m_clipY1; - int m_clipX2; - int m_clipY2; -// bool m_dontDelete; - int m_windowExtX; - int m_windowExtY; - double m_systemScaleX; - double m_systemScaleY; - - wxWindow * m_canvas; - wxBitmap m_selectedBitmap; - - // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it - bool m_bOwnsDC; - - WXHDC m_hDC; - int m_hDCCount; - - // Store all old GDI objects when do a SelectObject, - // so we can select them back in (this unselecting user's - // objects) so we can safely delete the DC. - WXHBITMAP m_oldBitmap; - WXHPEN m_oldPen; - WXHBRUSH m_oldBrush; - WXHFONT m_oldFont; - WXHPALETTE m_oldPalette; - - // Stores scaling, translation, rotation -// wxTransformMatrix m_transformMatrix; - - // Do we wish to scale GDI objects too, e.g. pen width? -// bool m_scaleGDI; + virtual void DoDrawSpline(wxList *points); +#endif // wxUSE_SPLINES + + // MSW-specific member variables + int m_windowExtX; + int m_windowExtY; + + // the window associated with this DC (may be NULL) + wxWindow *m_canvas; + + wxBitmap m_selectedBitmap; + + // TRUE => DeleteDC() in dtor, FALSE => only ReleaseDC() it + bool m_bOwnsDC:1; + + // our HDC and its usage count: we only free it when the usage count drops + // to 0 + WXHDC m_hDC; + int m_hDCCount; + + // Store all old GDI objects when do a SelectObject, so we can select them + // back in (this unselecting user's objects) so we can safely delete the + // DC. + WXHBITMAP m_oldBitmap; + WXHPEN m_oldPen; + WXHBRUSH m_oldBrush; + WXHFONT m_oldFont; + WXHPALETTE m_oldPalette; }; // Logical to device // Absolute -#define XLOG2DEV(x) ImplLogicalToDeviceX(x) - -#define YLOG2DEV(y) ImplLogicalToDeviceY(y) +#define XLOG2DEV(x) (x) +#define YLOG2DEV(y) (y) // Relative -#define XLOG2DEVREL(x) ImplLogicalToDeviceXRel(x) -#define YLOG2DEVREL(y) ImplLogicalToDeviceYRel(y) +#define XLOG2DEVREL(x) (x) +#define YLOG2DEVREL(y) (y) // Device to logical // Absolute -#define XDEV2LOG(x) ImplDeviceToLogicalX(x) +#define XDEV2LOG(x) (x) -#define YDEV2LOG(y) ImplDeviceToLogicalY(y) +#define YDEV2LOG(y) (y) // Relative -#define XDEV2LOGREL(x) ImplDeviceToLogicalXRel(x) -#define YDEV2LOGREL(y) ImplDeviceToLogicalYRel(y) +#define XDEV2LOGREL(x) (x) +#define YDEV2LOGREL(y) (y) /* * Have the same macros as for XView but not for every operation: @@ -426,8 +214,6 @@ protected: #define MM_POINTS 9 #define MM_METRIC 10 -extern int wxPageNumber; - // Conversion #define METRIC_CONVERSION_CONSTANT 0.0393700787 @@ -443,6 +229,5 @@ extern int wxPageNumber; #define wx_round(a) (int)((a)+.5) - #endif // _WX_DC_H_ diff --git a/include/wx/msw/dialog.h b/include/wx/msw/dialog.h index c6f248b545..c4e4a0b6ce 100644 --- a/include/wx/msw/dialog.h +++ b/include/wx/msw/dialog.h @@ -107,8 +107,9 @@ public: // Responds to colour changes void OnSysColourChanged(wxSysColourChangedEvent& event); - // IMPLEMENTATION - virtual bool MSWOnClose(); + // implementation + // -------------- + virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXUINT message, WXWPARAM wParam, WXLPARAM lParam); @@ -124,6 +125,7 @@ protected: bool m_modalShowing; WXHWND m_hwndOldFocus; // the window which had focus before we were shown +private: #if wxUSE_TOOLTIPS WXHWND m_hwndToolTip; #endif // tooltips diff --git a/include/wx/msw/frame.h b/include/wx/msw/frame.h index 86a5d191fc..efa973ec85 100644 --- a/include/wx/msw/frame.h +++ b/include/wx/msw/frame.h @@ -157,30 +157,40 @@ public: // event handlers bool MSWOnPaint(); WXHICON MSWOnQueryDragIcon(); - void MSWOnSize(int x, int y, WXUINT flag); + bool MSWOnSize(int x, int y, WXUINT flag); bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); - bool MSWOnClose(); - void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu); + bool MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu); bool MSWProcessMessage(WXMSG *msg); bool MSWTranslateMessage(WXMSG *msg); - void MSWCreate(int id, wxWindow *parent, const char *wclass, + bool MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title, int x, int y, int width, int height, long style); + bool HandleMenuSelect(WXWORD nItem, WXWORD nFlags, WXHMENU hMenu); + // tooltip management #if wxUSE_TOOLTIPS - WXHWND GetToolTipCtrl() const { return m_hwndToolTip; } - void SetToolTipCtrl(WXHWND hwndTT) { m_hwndToolTip = hwndTT; } + WXHWND GetToolTipCtrl() const { return m_hwndToolTip; } + void SetToolTipCtrl(WXHWND hwndTT) { m_hwndToolTip = hwndTT; } #endif // tooltips protected: - void DoGetClientSize(int *width, int *height) const; - void DoGetSize(int *width, int *height) const ; - void DoGetPosition(int *x, int *y) const ; + // override base class virtuals + virtual void DoGetClientSize(int *width, int *height) const; + virtual void DoGetSize(int *width, int *height) const ; + virtual void DoGetPosition(int *x, int *y) const ; + + virtual void DoSetSize(int x, int y, + int width, int height, + int sizeFlags = wxSIZE_AUTO); + virtual void DoSetClientSize(int width, int height); // propagate our state change to all child frames void IconizeChildFrames(bool bIconize); + // window proc for the frames + long MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); + wxMenuBar * m_frameMenuBar; wxStatusBar * m_frameStatusBar; wxIcon m_icon; @@ -190,16 +200,11 @@ protected: static bool m_useNativeStatusBar; +private: #if wxUSE_TOOLTIPS WXHWND m_hwndToolTip; #endif // tooltips - virtual void DoSetSize(int x, int y, - int width, int height, - int sizeFlags = wxSIZE_AUTO); - virtual void DoSetClientSize(int width, int height); - -private: DECLARE_EVENT_TABLE() }; diff --git a/include/wx/msw/listctrl.h b/include/wx/msw/listctrl.h index d7b79413c9..8ee5162ed2 100644 --- a/include/wx/msw/listctrl.h +++ b/include/wx/msw/listctrl.h @@ -419,7 +419,7 @@ class WXDLLEXPORT wxListCtrl: public wxControl // IMPLEMENTATION virtual bool MSWCommand(WXUINT param, WXWORD id); - virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result); + virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); // Recreate window - seems to be necessary when changing a style. void RecreateWindow(); diff --git a/include/wx/msw/mdi.h b/include/wx/msw/mdi.h index fa1f382db5..f19bf39b8e 100644 --- a/include/wx/msw/mdi.h +++ b/include/wx/msw/mdi.h @@ -6,14 +6,14 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_MDI_H_ #define _WX_MDI_H_ #ifdef __GNUG__ -#pragma interface "mdi.h" + #pragma interface "mdi.h" #endif #include "wx/frame.h" @@ -24,185 +24,188 @@ WXDLLEXPORT_DATA(extern const wxChar*) wxStatusLineNameStr; class WXDLLEXPORT wxMDIClientWindow; class WXDLLEXPORT wxMDIChildFrame; -class WXDLLEXPORT wxMDIParentFrame: public wxFrame +// --------------------------------------------------------------------------- +// wxMDIParentFrame +// --------------------------------------------------------------------------- + +class WXDLLEXPORT wxMDIParentFrame : public wxFrame { - DECLARE_DYNAMIC_CLASS(wxMDIParentFrame) - - friend class WXDLLEXPORT wxMDIChildFrame; - public: - - wxMDIParentFrame(void); - inline wxMDIParentFrame(wxWindow *parent, - wxWindowID id, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL, - const wxString& name = wxFrameNameStr) - { - Create(parent, id, title, pos, size, style, name); - } - - ~wxMDIParentFrame(void); - - bool Create(wxWindow *parent, - wxWindowID id, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL, - const wxString& name = wxFrameNameStr); - -/* -#if WXWIN_COMPATIBILITY - virtual void OldOnActivate(bool flag); - virtual void OldOnSize(int x, int y); -#endif -*/ + DECLARE_DYNAMIC_CLASS(wxMDIParentFrame) + +public: + wxMDIParentFrame(); + wxMDIParentFrame(wxWindow *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL, + const wxString& name = wxFrameNameStr) + { + Create(parent, id, title, pos, size, style, name); + } + + ~wxMDIParentFrame(); + + bool Create(wxWindow *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE | wxVSCROLL | wxHSCROLL, + const wxString& name = wxFrameNameStr); + + // accessors + // --------- + + void SetMenuBar(wxMenuBar *menu_bar); + + // Get the active MDI child window (Windows only) + wxMDIChildFrame *GetActiveChild() const ; - void OnSize(wxSizeEvent& event); - void OnActivate(wxActivateEvent& event); + // Get the client window + wxMDIClientWindow *GetClientWindow() const { return m_clientWindow; } - void SetMenuBar(wxMenuBar *menu_bar); + // Create the client window class (don't Create the window, + // just return a new class) + virtual wxMDIClientWindow *OnCreateClient(void) ; - // Get the active MDI child window (Windows only) - wxMDIChildFrame *GetActiveChild(void) const ; + WXHMENU GetWindowMenu() const { return m_windowMenu; } - // Get the client window - inline wxMDIClientWindow *GetClientWindow(void) const ; + // MDI operations + // -------------- + virtual void Cascade(); + virtual void Tile(); + virtual void ArrangeIcons(); + virtual void ActivateNext(); + virtual void ActivatePrevious(); - // Create the client window class (don't Create the window, - // just return a new class) - virtual wxMDIClientWindow *OnCreateClient(void) ; + // handlers + // -------- - inline WXHMENU GetWindowMenu(void) const ; + // Responds to colour changes + void OnSysColourChanged(wxSysColourChangedEvent& event); - // MDI operations - virtual void Cascade(void); - virtual void Tile(void); - virtual void ArrangeIcons(void); - virtual void ActivateNext(void); - virtual void ActivatePrevious(void); + void OnSize(wxSizeEvent& event); + void OnActivate(wxActivateEvent& event); - // Handlers - void MSWOnSize(int x, int y, WXUINT flag); - bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); - void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu); - bool MSWProcessMessage(WXMSG *msg); - bool MSWTranslateMessage(WXMSG *msg); - void MSWOnCreate(WXLPCREATESTRUCT cs); - long MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - bool MSWOnEraseBkgnd(WXHDC pDC); - bool MSWOnDestroy(void); - bool MSWOnActivate(int state, bool minimized, WXHWND activate); + virtual bool MSWOnActivate(int state, bool minimized, WXHWND activate); + virtual bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); - // Responds to colour changes - void OnSysColourChanged(wxSysColourChangedEvent& event); + // override window proc for MDI-specific message processing + virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); - protected: - // Gets the size available for subwindows after menu size, toolbar size - // and status bar size have been subtracted. If you want to manage your own - // toolbar(s), don't call SetToolBar. - void DoGetClientSize(int *width, int *height) const; + virtual long MSWDefWindowProc(WXUINT, WXWPARAM, WXLPARAM); + virtual bool MSWProcessMessage(WXMSG* msg); + virtual bool MSWTranslateMessage(WXMSG* msg); +protected: wxMDIClientWindow * m_clientWindow; wxMDIChildFrame * m_currentChild; WXHMENU m_windowMenu; - bool m_parentFrameActive; // TRUE if MDI Frame is intercepting - // commands, not child -DECLARE_EVENT_TABLE() + + // TRUE if MDI Frame is intercepting commands, not child + bool m_parentFrameActive; + +private: + friend class WXDLLEXPORT wxMDIChildFrame; + + DECLARE_EVENT_TABLE() }; -// Inlines -inline wxMDIClientWindow *wxMDIParentFrame::GetClientWindow(void) const { return m_clientWindow; } -inline WXHMENU wxMDIParentFrame::GetWindowMenu(void) const { return m_windowMenu; } +// --------------------------------------------------------------------------- +// wxMDIChildFrame +// --------------------------------------------------------------------------- -class WXDLLEXPORT wxMDIChildFrame: public wxFrame +class WXDLLEXPORT wxMDIChildFrame : public wxFrame { - DECLARE_DYNAMIC_CLASS(wxMDIChildFrame) - public: - - wxMDIChildFrame(void); - inline wxMDIChildFrame(wxMDIParentFrame *parent, - wxWindowID id, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr) - { - Create(parent, id, title, pos, size, style, name); - } - - ~wxMDIChildFrame(void); - - bool Create(wxMDIParentFrame *parent, - wxWindowID id, - const wxString& title, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxDEFAULT_FRAME_STYLE, - const wxString& name = wxFrameNameStr); - - // Set menu bar - void SetMenuBar(wxMenuBar *menu_bar); - - // MDI operations - virtual void Maximize(void); - virtual void Restore(void); - virtual void Activate(void); - - // Handlers - - long MSWOnMDIActivate(long bActivate, WXHWND, WXHWND); - void MSWOnSize(int x, int y, WXUINT); - void MSWOnWindowPosChanging(void *lpPos); + DECLARE_DYNAMIC_CLASS(wxMDIChildFrame) + +public: + wxMDIChildFrame(); + wxMDIChildFrame(wxMDIParentFrame *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = wxFrameNameStr) + { + Create(parent, id, title, pos, size, style, name); + } + + ~wxMDIChildFrame(); + + bool Create(wxMDIParentFrame *parent, + wxWindowID id, + const wxString& title, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxDEFAULT_FRAME_STYLE, + const wxString& name = wxFrameNameStr); + + // Set menu bar + void SetMenuBar(wxMenuBar *menu_bar); + + // MDI operations + virtual void Maximize(); + virtual void Restore(); + virtual void Activate(); + + // Handlers + + bool MSWOnMDIActivate(long bActivate, WXHWND, WXHWND); + bool MSWOnSize(int x, int y, WXUINT); + bool MSWOnWindowPosChanging(void *lpPos); bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); long MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam); bool MSWProcessMessage(WXMSG *msg); bool MSWTranslateMessage(WXMSG *msg); - void MSWDestroyWindow(void); + void MSWDestroyWindow(); // Implementation bool ResetWindowStyle(void *vrect); protected: - void DoGetPosition(int *x, int *y) const ; - void DoSetClientSize(int width, int height); + virtual void DoGetPosition(int *x, int *y) const ; + virtual void DoSetClientSize(int width, int height); }; -class WXDLLEXPORT wxMDIClientWindow: public wxWindow -{ - DECLARE_DYNAMIC_CLASS(wxMDIClientWindow) - public: +// --------------------------------------------------------------------------- +// wxMDIClientWindow +// --------------------------------------------------------------------------- - wxMDIClientWindow(void) ; - inline wxMDIClientWindow(wxMDIParentFrame *parent, long style = 0) - { - CreateClient(parent, style); - } +class WXDLLEXPORT wxMDIClientWindow : public wxWindow +{ + DECLARE_DYNAMIC_CLASS(wxMDIClientWindow) - ~wxMDIClientWindow(void); +public: + wxMDIClientWindow(); + wxMDIClientWindow(wxMDIParentFrame *parent, long style = 0) + { + CreateClient(parent, style); + } - // Note: this is virtual, to allow overridden behaviour. - virtual bool CreateClient(wxMDIParentFrame *parent, long style = wxVSCROLL | wxHSCROLL); + ~wxMDIClientWindow(); - // Explicitly call default scroll behaviour - void OnScroll(wxScrollEvent& event); + // Note: this is virtual, to allow overridden behaviour. + virtual bool CreateClient(wxMDIParentFrame *parent, + long style = wxVSCROLL | wxHSCROLL); - // Window procedure - virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); + // Explicitly call default scroll behaviour + void OnScroll(wxScrollEvent& event); - // Calls an appropriate default window procedure - virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); + // Window procedure + virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); - // Should hand the message to the default proc - long MSWOnMDIActivate(long bActivate, WXHWND, WXHWND); + // Calls an appropriate default window procedure + virtual long MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); protected: - int m_scrollX; - int m_scrollY; -DECLARE_EVENT_TABLE() + int m_scrollX, m_scrollY; + +private: + DECLARE_EVENT_TABLE() }; #endif diff --git a/include/wx/msw/notebook.h b/include/wx/msw/notebook.h index 3f4697fab9..7ad3e36e14 100644 --- a/include/wx/msw/notebook.h +++ b/include/wx/msw/notebook.h @@ -181,7 +181,7 @@ public: // base class virtuals // ------------------- virtual void Command(wxCommandEvent& event); - virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result); + virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); virtual void SetConstraintSizes(bool recurse = TRUE); virtual bool DoPhase(int nPhase); diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index cb5f9dcb06..39292f3c98 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -1,6 +1,8 @@ ///////////////////////////////////////////////////////////////////////////// // Name: private.h -// Purpose: Private declarations +// Purpose: Private declarations: as this header is only included by +// wxWindows itself, it may contain identifiers which don't start +// with "wx". // Author: Julian Smart // Modified by: // Created: 01/02/97 @@ -12,18 +14,13 @@ #ifndef _WX_PRIVATE_H_ #define _WX_PRIVATE_H_ -#include "wx/defs.h" - #include -#define VIEWPORT_EXTENT 1000 - -class WXDLLEXPORT wxFont ; +class WXDLLEXPORT wxFont; -WXDLLEXPORT void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font); -WXDLLEXPORT void wxSliderEvent(WXHWND control, WXWORD wParam, WXWORD pos); -WXDLLEXPORT wxWindow* wxFindWinFromHandle(WXHWND hWnd); -WXDLLEXPORT void wxScrollBarEvent(WXHWND hbar, WXWORD wParam, WXWORD pos); +// --------------------------------------------------------------------------- +// standard icons from the resources +// --------------------------------------------------------------------------- WXDLLEXPORT_DATA(extern HICON) wxSTD_FRAME_ICON; WXDLLEXPORT_DATA(extern HICON) wxSTD_MDIPARENTFRAME_ICON; @@ -33,11 +30,10 @@ WXDLLEXPORT_DATA(extern HICON) wxDEFAULT_MDIPARENTFRAME_ICON; WXDLLEXPORT_DATA(extern HICON) wxDEFAULT_MDICHILDFRAME_ICON; WXDLLEXPORT_DATA(extern HFONT) wxSTATUS_LINE_FONT; -WXDLLEXPORT HINSTANCE wxGetInstance(); -WXDLLEXPORT void wxSetInstance(HINSTANCE hInst); -WXDLLEXPORT void wxFillLogFont(LOGFONT *logFont, wxFont *font); -WXDLLEXPORT wxFont wxCreateFontFromLogFont(LOGFONT *logFont); // , bool createNew = TRUE); - +// --------------------------------------------------------------------------- +// this defines a CASTWNDPROC macro which casts a pointer to the type of a +// window proc +// --------------------------------------------------------------------------- #ifdef __GNUWIN32__ # define CASTWNDPROC (long unsigned) #else @@ -68,19 +64,26 @@ WXDLLEXPORT wxFont wxCreateFontFromLogFont(LOGFONT *logFont); // , bool createNe # endif #endif +// --------------------------------------------------------------------------- +// some stuff for old Windows versions (FIXME: what does it do here??) +// --------------------------------------------------------------------------- + #if !defined(APIENTRY) // NT defines APIENTRY, 3.x not -#define APIENTRY FAR PASCAL + #define APIENTRY FAR PASCAL #endif #ifdef __WIN32__ -#define _EXPORT /**/ + #define _EXPORT #else -#define _EXPORT _export -typedef signed short int SHORT ; + #define _EXPORT _export +#endif + +#ifndef __WIN32__ + typedef signed short int SHORT; #endif #if !defined(__WIN32__) // 3.x uses FARPROC for dialogs -#define DLGPROC FARPROC + #define DLGPROC FARPROC #endif #if wxUSE_PENWIN @@ -90,31 +93,18 @@ typedef signed short int SHORT ; #endif // wxUSE_PENWIN #if wxUSE_ITSY_BITSY -#define IBS_HORZCAPTION 0x4000L -#define IBS_VERTCAPTION 0x8000L + #define IBS_HORZCAPTION 0x4000L + #define IBS_VERTCAPTION 0x8000L -UINT WINAPI ibGetCaptionSize( HWND hWnd ) ; -UINT WINAPI ibSetCaptionSize( HWND hWnd, UINT nSize ) ; -LRESULT WINAPI ibDefWindowProc( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam ) ; -VOID WINAPI ibAdjustWindowRect( HWND hWnd, LPRECT lprc ) ; -#endif - -/* When implementing a new item, be sure to: - * - * - add the item to the parent panel - * - set window_parent to the parent - * - NULL any extra child window pointers not created for this item - * (e.g. label control that wasn't needed) - * - delete any extra child windows in the destructor (e.g. label control) - * - implement DoSetSize - * - to find panel position if coordinates are (-1, -1), use GetPosition - * - call AdvanceCursor after creation, for panel layout mechanism. - * - */ + UINT WINAPI ibGetCaptionSize( HWND hWnd ) ; + UINT WINAPI ibSetCaptionSize( HWND hWnd, UINT nSize ) ; + LRESULT WINAPI ibDefWindowProc( HWND hWnd, UINT uiMsg, WPARAM wParam, LPARAM lParam ) ; + VOID WINAPI ibAdjustWindowRect( HWND hWnd, LPRECT lprc ) ; +#endif // wxUSE_ITSY_BITSY #if wxUSE_CTL3D -#include -#endif + #include "wx/msw/ctl3d/ctl3d.h" +#endif // wxUSE_CTL3D /* * Decide what window classes we're going to use @@ -139,6 +129,10 @@ VOID WINAPI ibAdjustWindowRect( HWND hWnd, LPRECT lprc ) ; #define BITRADIO_FLAGS (FC_BUTTONDRAW|FB_BITMAP|FC_RADIO|WS_CHILD|WS_VISIBLE) */ +// --------------------------------------------------------------------------- +// misc macros +// --------------------------------------------------------------------------- + #define MEANING_CHARACTER '0' #define DEFAULT_ITEM_WIDTH 200 #define DEFAULT_ITEM_HEIGHT 80 @@ -151,16 +145,78 @@ VOID WINAPI ibAdjustWindowRect( HWND hWnd, LPRECT lprc ) ; extern LONG APIENTRY _EXPORT wxSubclassedGenericControlProc(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam); -// Find maximum size of window/rectangle -WXDLLEXPORT extern void wxFindMaxSize(WXHWND hwnd, RECT *rect); +// --------------------------------------------------------------------------- +// constants which might miss from some compilers' headers +// --------------------------------------------------------------------------- + +#if !defined(__WIN32__) && !defined(WS_EX_CLIENTEDGE) + #define WS_EX_CLIENTEDGE 0 +#endif + +#if defined(__WIN32__) && !defined(WS_EX_CLIENTEDGE) + #define WS_EX_CLIENTEDGE 0x00000200L +#endif + +#ifndef ENDSESSION_LOGOFF + #define ENDSESSION_LOGOFF 0x80000000 +#endif + +// --------------------------------------------------------------------------- +// debug messages +// --------------------------------------------------------------------------- +#if defined(__WIN95__) && defined(__WXDEBUG__) && wxUSE_DBWIN32 + + #ifndef __TWIN32__ + #ifdef OutputDebugString + #undef OutputDebugString + #endif + + #define OutputDebugString OutputDebugStringW95 + #endif // __TWIN32__ + + extern void OutputDebugStringW95(const wxChar*, ...); +#endif // USE_DBWIN32 + +// --------------------------------------------------------------------------- +// macros to make casting between WXFOO and FOO a bit easier +// --------------------------------------------------------------------------- + +#define GetHwnd() ((HWND)GetHWND()) +#define GetWinHwnd(win) ((HWND)((win)->GetHWND())) + +#define GetHdc() ((HDC)GetHDC()) + +#define GetHaccel() ((HACCEL)GetHACCEL()) +#define GetTableHaccel(table) ((HACCEL)((table)->GetHACCEL())) + +// --------------------------------------------------------------------------- +// global data +// --------------------------------------------------------------------------- -// List of scrollbar controls -WXDLLEXPORT_DATA(extern wxList) wxScrollBarList; // The MakeProcInstance version of the function wxSubclassedGenericControlProc WXDLLEXPORT_DATA(extern FARPROC) wxGenericControlSubClassProc; WXDLLEXPORT_DATA(extern wxChar*) wxBuffer; WXDLLEXPORT_DATA(extern HINSTANCE) wxhInstance; +// --------------------------------------------------------------------------- +// global functions +// --------------------------------------------------------------------------- + +WXDLLEXPORT HINSTANCE wxGetInstance(); +WXDLLEXPORT void wxSetInstance(HINSTANCE hInst); + +WXDLLEXPORT wxWindow* wxFindWinFromHandle(WXHWND hWnd); + +WXDLLEXPORT void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font); +WXDLLEXPORT void wxFillLogFont(LOGFONT *logFont, wxFont *font); +WXDLLEXPORT wxFont wxCreateFontFromLogFont(LOGFONT *logFont); + +WXDLLEXPORT void wxSliderEvent(WXHWND control, WXWORD wParam, WXWORD pos); +WXDLLEXPORT void wxScrollBarEvent(WXHWND hbar, WXWORD wParam, WXWORD pos); + +// Find maximum size of window/rectangle +WXDLLEXPORT extern void wxFindMaxSize(WXHWND hwnd, RECT *rect); + WXDLLEXPORT wxWindow* wxFindControlFromHandle(WXHWND hWnd); WXDLLEXPORT void wxAddControlHandle(WXHWND hWnd, wxWindow *item); @@ -180,29 +236,5 @@ inline bool wxStyleHasBorder(long style) wxSUNKEN_BORDER | wxDOUBLE_BORDER)) != 0; } -#if !defined(__WIN32__) && !defined(WS_EX_CLIENTEDGE) - #define WS_EX_CLIENTEDGE 0 -#endif - -#if defined(__WIN32__) && !defined(WS_EX_CLIENTEDGE) - #define WS_EX_CLIENTEDGE 0x00000200L -#endif - -// --------------------------------------------------------------------------- -// debug messages -// --------------------------------------------------------------------------- -#if defined(__WIN95__) && defined(__WXDEBUG__) && wxUSE_DBWIN32 - - #ifndef __TWIN32__ - #ifdef OutputDebugString - #undef OutputDebugString - #endif - - #define OutputDebugString OutputDebugStringW95 - #endif // __TWIN32__ - - extern void OutputDebugStringW95(const wxChar*, ...); -#endif // USE_DBWIN32 - #endif // _WX_PRIVATE_H_ diff --git a/include/wx/msw/scrolbar.h b/include/wx/msw/scrolbar.h index 588d3d1321..77adfa9575 100644 --- a/include/wx/msw/scrolbar.h +++ b/include/wx/msw/scrolbar.h @@ -23,68 +23,68 @@ WXDLLEXPORT_DATA(extern const char*) wxScrollBarNameStr; // Scrollbar item class WXDLLEXPORT wxScrollBar: public wxControl { - DECLARE_DYNAMIC_CLASS(wxScrollBar) + DECLARE_DYNAMIC_CLASS(wxScrollBar) public: - inline wxScrollBar(void) { m_pageSize = 0; m_viewSize = 0; m_objectSize = 0; } - ~wxScrollBar(void); - - inline wxScrollBar(wxWindow *parent, wxWindowID id, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSB_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxScrollBarNameStr) - { - Create(parent, id, pos, size, style, validator, name); - } - bool Create(wxWindow *parent, wxWindowID id, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, - long style = wxSB_HORIZONTAL, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxScrollBarNameStr); - - int GetThumbPosition(void) const ; - inline int GetThumbSize() const { return m_pageSize; } - inline int GetPageSize() const { return m_viewSize; } - inline int GetRange() const { return m_objectSize; } - - virtual void SetThumbPosition(int viewStart); - virtual void SetScrollbar(int position, int thumbSize, int range, int pageSize, - bool refresh = TRUE); + wxScrollBar() { m_pageSize = 0; m_viewSize = 0; m_objectSize = 0; } + ~wxScrollBar(); + + wxScrollBar(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxSB_HORIZONTAL, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxScrollBarNameStr) + { + Create(parent, id, pos, size, style, validator, name); + } + bool Create(wxWindow *parent, wxWindowID id, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxSB_HORIZONTAL, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxScrollBarNameStr); + + int GetThumbPosition() const ; + int GetThumbSize() const { return m_pageSize; } + int GetPageSize() const { return m_viewSize; } + int GetRange() const { return m_objectSize; } + + virtual void SetThumbPosition(int viewStart); + virtual void SetScrollbar(int position, int thumbSize, int range, int pageSize, + bool refresh = TRUE); #if WXWIN_COMPATIBILITY - // Backward compatibility - inline int GetValue(void) const { return GetThumbPosition(); } - inline void SetValue(int viewStart) { SetThumbPosition(viewStart); } - void GetValues(int *viewStart, int *viewLength, int *objectLength, - int *pageLength) const ; - inline int GetViewLength() const { return m_viewSize; } - inline int GetObjectLength() const { return m_objectSize; } - - void SetPageSize(int pageLength); - void SetObjectLength(int objectLength); - void SetViewLength(int viewLength); + // Backward compatibility + int GetValue() const { return GetThumbPosition(); } + void SetValue(int viewStart) { SetThumbPosition(viewStart); } + void GetValues(int *viewStart, int *viewLength, int *objectLength, + int *pageLength) const ; + int GetViewLength() const { return m_viewSize; } + int GetObjectLength() const { return m_objectSize; } + + void SetPageSize(int pageLength); + void SetObjectLength(int objectLength); + void SetViewLength(int viewLength); #endif - void Command(wxCommandEvent& event); - virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - void MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control); - void MSWOnHScroll(WXWORD wParam, WXWORD pos, WXHWND control); + void Command(wxCommandEvent& event); + virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, + WXUINT message, WXWPARAM wParam, WXLPARAM lParam); + virtual bool MSWOnScroll(int orientation, WXWORD wParam, + WXWORD pos, WXHWND control); #if WXWIN_COMPATIBILITY - // Backward compatibility: generate an old-style scroll command - void OnScroll(wxScrollEvent& event); -#endif + // Backward compatibility: generate an old-style scroll command + void OnScroll(wxScrollEvent& event); +#endif // WXWIN_COMPATIBILITY protected: int m_pageSize; int m_viewSize; int m_objectSize; -DECLARE_EVENT_TABLE() + DECLARE_EVENT_TABLE() }; #endif diff --git a/include/wx/msw/slider95.h b/include/wx/msw/slider95.h index a94978d8b1..ce0c8c6385 100644 --- a/include/wx/msw/slider95.h +++ b/include/wx/msw/slider95.h @@ -87,8 +87,8 @@ public: void Command(wxCommandEvent& event); virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - void MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control); - void MSWOnHScroll(WXWORD wParam, WXWORD pos, WXHWND control); + virtual bool MSWOnScroll(int orientation, WXWORD wParam, + WXWORD pos, WXHWND control); protected: WXHWND m_staticMin; diff --git a/include/wx/msw/slidrmsw.h b/include/wx/msw/slidrmsw.h index a53b8857ed..0da889422e 100644 --- a/include/wx/msw/slidrmsw.h +++ b/include/wx/msw/slidrmsw.h @@ -87,8 +87,8 @@ public: void Command(wxCommandEvent& event); virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - void MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control); - void MSWOnHScroll(WXWORD wParam, WXWORD pos, WXHWND control); + virtual bool MSWOnScroll(int orientation, WXWORD wParam, + WXWORD pos, WXHWND control); protected: WXHWND m_staticMin; diff --git a/include/wx/msw/spinbutt.h b/include/wx/msw/spinbutt.h index b00a23faf7..98d4410feb 100644 --- a/include/wx/msw/spinbutt.h +++ b/include/wx/msw/spinbutt.h @@ -40,7 +40,7 @@ public: * Public interface */ wxSpinButton(); - + wxSpinButton(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, @@ -50,37 +50,36 @@ public: { Create(parent, id, pos, size, style, name); } - + virtual ~wxSpinButton(); - + bool Create(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, - long style = wxSP_VERTICAL | wxSP_ARROW_KEYS, + long style = wxSP_VERTICAL | wxSP_ARROW_KEYS, const wxString& name = "wxSpinButton"); - - + + // Attributes //////////////////////////////////////////////////////////////////////////// - + int GetValue() const ; void SetValue(int val) ; void SetRange(int minVal, int maxVal); int GetMin() const { return m_min; } int GetMax() const { return m_max; } - + // Operations //////////////////////////////////////////////////////////////////////////// - + void Command(wxCommandEvent& event) { ProcessCommand(event); }; - + // IMPLEMENTATION virtual bool MSWCommand(WXUINT param, WXWORD id); - virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result); - virtual void MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control); - virtual void MSWOnHScroll(WXWORD wParam, WXWORD pos, WXHWND control); - + virtual bool MSWOnScroll(int orientation, WXWORD wParam, + WXWORD pos, WXHWND control); + protected: int m_min; int m_max; @@ -89,7 +88,7 @@ protected: class WXDLLEXPORT wxSpinEvent: public wxScrollEvent { DECLARE_DYNAMIC_CLASS(wxSpinEvent) - + public: wxSpinEvent(wxEventType commandType = wxEVT_NULL, int id = 0); }; diff --git a/include/wx/msw/tabctrl.h b/include/wx/msw/tabctrl.h index cd975821e2..9f425689f1 100644 --- a/include/wx/msw/tabctrl.h +++ b/include/wx/msw/tabctrl.h @@ -124,7 +124,7 @@ class WXDLLEXPORT wxTabCtrl: public wxControl void Command(wxCommandEvent& event); virtual bool MSWCommand(WXUINT param, WXWORD id); - virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result); + virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); // Responds to colour changes void OnSysColourChanged(wxSysColourChangedEvent& event); diff --git a/include/wx/msw/tbar95.h b/include/wx/msw/tbar95.h index 17c0d2c5b7..6485d207f5 100644 --- a/include/wx/msw/tbar95.h +++ b/include/wx/msw/tbar95.h @@ -83,7 +83,7 @@ class WXDLLEXPORT wxToolBar95: public wxToolBarBase // IMPLEMENTATION virtual bool MSWCommand(WXUINT param, WXWORD id); - virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result); + virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); // Responds to colour changes void OnSysColourChanged(wxSysColourChangedEvent& event); diff --git a/include/wx/msw/treectrl.h b/include/wx/msw/treectrl.h index 6f4050df46..105b567447 100644 --- a/include/wx/msw/treectrl.h +++ b/include/wx/msw/treectrl.h @@ -449,7 +449,7 @@ public: // -------------- void Command(wxCommandEvent& event) { ProcessCommand(event); }; virtual bool MSWCommand(WXUINT param, WXWORD id); - virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result); + virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); protected: // SetImageList helper diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index f84926536d..04771fc5de 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -29,6 +29,13 @@ #undef FindWindow #endif +// VZ: apparently some version of Windows send extra mouse move messages after +// a mouse click. My tests under NT 4.0 and 95 didn't show it so I'm +// tempted to think that it was just an effect of a poor mouse and so the +// code to work around this is currently disabled - just define this as 1 +// to reenable it +#define wxUSE_MOUSEEVENT_HACK 0 + // --------------------------------------------------------------------------- // forward declarations // --------------------------------------------------------------------------- @@ -176,10 +183,6 @@ public: // event handlers // -------------- void OnEraseBackground(wxEraseEvent& event); - void OnKeyDown(wxKeyEvent& event); - void OnKeyUp(wxKeyEvent& event); - void OnPaint(wxPaintEvent& event); - void OnChar(wxKeyEvent& event); void OnIdle(wxIdleEvent& event); // a window may have a default button @@ -199,11 +202,10 @@ public: // Windows subclassing void SubclassWin(WXHWND hWnd); void UnsubclassWin(); - virtual long Default(); virtual bool MSWCommand(WXUINT param, WXWORD id); - // returns TRUE if the event was processed - virtual bool MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result); + WXFARPROC MSWGetOldWndProc() const { return m_oldWndProc; } + void MSWSetOldWndProc(WXFARPROC proc) { m_oldWndProc = proc; } virtual wxWindow *FindItem(int id) const; virtual wxWindow *FindItemByHWND(WXHWND hWnd, bool controlOnly = FALSE) const ; @@ -219,10 +221,16 @@ public: wxObject *GetChild(int number) const ; - void MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title, - int x, int y, int width, int height, - WXDWORD style, const char *dialog_template = NULL, - WXDWORD exendedStyle = 0); + // returns TRUE if the window has been created + bool MSWCreate(int id, + wxWindow *parent, + const char *wclass, + wxWindow *wx_win, + const char *title, + int x, int y, int width, int height, + WXDWORD style, + const char *dialog_template = NULL, + WXDWORD exendedStyle = 0); // Actually defined in wx_canvs.cc since requires wxCanvas declaration virtual void MSWDeviceToLogical(float *x, float *y) const ; @@ -236,75 +244,66 @@ public: // Setup background and foreground colours correctly virtual void SetupColours(); - // Saves the last message information before calling base version - virtual bool ProcessEvent(wxEvent& event); + // ------------------------------------------------------------------------ + // internal handlers for MSW messages: all handlers return a boolen value: + // TRUE means that the handler processed the event and FALSE that it didn't + // ------------------------------------------------------------------------ - // Handlers - virtual void MSWOnCreate(WXLPCREATESTRUCT cs); + // TODO: all this should go away, overriding MSWWindowProc() is enough to + // implement this functionality + virtual bool MSWOnCreate(WXLPCREATESTRUCT cs, bool *mayCreate); virtual bool MSWOnPaint(); - virtual WXHICON MSWOnQueryDragIcon() { return 0; } - virtual void MSWOnSize(int x, int y, WXUINT flag); - virtual void MSWOnWindowPosChanging(void *lpPos); - virtual void MSWOnHScroll(WXWORD nSBCode, WXWORD pos, WXHWND control); - virtual void MSWOnVScroll(WXWORD nSBCode, WXWORD pos, WXHWND control); - virtual bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); - virtual long MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam); - virtual long MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam); - virtual WXHBRUSH MSWOnCtlColor(WXHDC dc, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - virtual bool MSWOnColorChange(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam); - virtual long MSWOnPaletteChanged(WXHWND hWndPalChange); - virtual long MSWOnQueryNewPalette(); virtual bool MSWOnEraseBkgnd(WXHDC pDC); - virtual void MSWOnMenuHighlight(WXWORD item, WXWORD flags, WXHMENU sysmenu); - virtual void MSWOnInitMenuPopup(WXHMENU menu, int pos, bool isSystem); - virtual bool MSWOnClose(); - // Return TRUE to end session, FALSE to veto end session. - virtual bool MSWOnQueryEndSession(long logOff); + virtual bool MSWOnSize(int x, int y, WXUINT flag); + + virtual bool MSWOnQueryDragIcon(WXHICON *hIcon); + virtual bool MSWOnWindowPosChanging(void *lpPos); + + // both horizontal and vertical + virtual bool MSWOnScroll(int orientation, WXWORD nSBCode, + WXWORD pos, WXHWND control); + + virtual bool MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control); + virtual bool MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam); + +#ifdef __WIN95__ + virtual bool MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); +#endif // __WIN95__ + + virtual bool MSWOnCtlColor(WXHBRUSH *hBrush, + WXHDC hdc, + WXHWND hWnd, + WXUINT nCtlColor, + WXUINT message, + WXWPARAM wParam, + WXLPARAM lParam); + + virtual bool MSWOnPaletteChanged(WXHWND hWndPalChange); + virtual bool MSWOnQueryNewPalette(); + + virtual bool MSWOnQueryEndSession(long logOff, bool *mayEnd); virtual bool MSWOnEndSession(bool endSession, long logOff); + virtual bool MSWOnDestroy(); virtual bool MSWOnSetFocus(WXHWND wnd); virtual bool MSWOnKillFocus(WXHWND wnd); - virtual void MSWOnDropFiles(WXWPARAM wParam); + virtual bool MSWOnDropFiles(WXWPARAM wParam); virtual bool MSWOnInitDialog(WXHWND hWndFocus); - virtual void MSWOnShow(bool show, int status); + virtual bool MSWOnShow(bool show, int status); - // TODO: rationalise these functions into 1 or 2 which take the - // event type as argument. - virtual void MSWOnLButtonDown(int x, int y, WXUINT flags); - virtual void MSWOnLButtonUp(int x, int y, WXUINT flags); - virtual void MSWOnLButtonDClick(int x, int y, WXUINT flags); + virtual bool MSWOnMouseEvent(WXUINT msg, int x, int y, WXUINT flags); + virtual bool MSWOnMouseMove(int x, int y, WXUINT flags); - virtual void MSWOnMButtonDown(int x, int y, WXUINT flags); - virtual void MSWOnMButtonUp(int x, int y, WXUINT flags); - virtual void MSWOnMButtonDClick(int x, int y, WXUINT flags); - - virtual void MSWOnRButtonDown(int x, int y, WXUINT flags); - virtual void MSWOnRButtonUp(int x, int y, WXUINT flags); - virtual void MSWOnRButtonDClick(int x, int y, WXUINT flags); - - virtual void MSWOnMouseMove(int x, int y, WXUINT flags); - virtual void MSWOnMouseEnter(int x, int y, WXUINT flags); - virtual void MSWOnMouseLeave(int x, int y, WXUINT flags); - - // These return TRUE if an event handler was found, FALSE otherwise (not processed) virtual bool MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII = FALSE); virtual bool MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam); virtual bool MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam); virtual bool MSWOnActivate(int flag, bool minimized, WXHWND activate); - virtual long MSWOnMDIActivate(long flag, WXHWND activate, WXHWND deactivate); + virtual bool MSWOnMDIActivate(long flag, WXHWND activate, WXHWND deactivate); virtual bool MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *item); virtual bool MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *item); - virtual void MSWOnJoyDown(int joystick, int x, int y, WXUINT flags); - virtual void MSWOnJoyUp(int joystick, int x, int y, WXUINT flags); - virtual void MSWOnJoyMove(int joystick, int x, int y, WXUINT flags); - virtual void MSWOnJoyZMove(int joystick, int z, WXUINT flags); - - virtual long MSWGetDlgCode(); - // Window procedure virtual long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); @@ -317,12 +316,14 @@ public: // Detach "Window" menu from menu bar so it doesn't get deleted void MSWDetachWindowMenu(); - inline WXFARPROC MSWGetOldWndProc() const; - inline void MSWSetOldWndProc(WXFARPROC proc); - - // Define for each class of dialog and control - virtual WXHBRUSH OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam); + // this function should return the brush to paint the window background + // with or 0 for the default brush + virtual WXHBRUSH OnCtlColor(WXHDC hDC, + WXHWND hWnd, + WXUINT nCtlColor, + WXUINT message, + WXWPARAM wParam, + WXLPARAM lParam); #if WXWIN_COMPATIBILITY void SetShowing(bool show) { (void)Show(show); } @@ -332,13 +333,8 @@ public: // Responds to colour changes: passes event on to children. void OnSysColourChanged(wxSysColourChangedEvent& event); - // remember the parameters of the last message - void PushLastMessage(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam) - { - m_lastMsg = msg; - m_lastWParam = wParam; - m_lastLParam = lParam; - } + // initialize various fields of wxMouseEvent (common part of MSWOnMouseXXX) + void InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags); protected: // the window handle @@ -365,15 +361,12 @@ protected: int m_xThumbSize; int m_yThumbSize; - // the coordinates of the last mouse event and the typoe of it +#if wxUSE_MOUSEEVENT_HACK + // the coordinates of the last mouse event and the type of it long m_lastMouseX, m_lastMouseY; int m_lastMouseEvent; - - // the parameters of the last message used in Default() - WXUINT m_lastMsg; - WXWPARAM m_lastWParam; - WXLPARAM m_lastLParam; +#endif // wxUSE_MOUSEEVENT_HACK WXHMENU m_hMenu; // Menu, if any @@ -396,6 +389,15 @@ private: // common part of all ctors void Init(); + // the (non-virtual) handlers for the events + bool HandleMove(int x, int y); + bool HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags); + +#ifdef __WIN95__ + bool HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result); +#endif // __WIN95__ + + DECLARE_NO_COPY_CLASS(wxWindow); DECLARE_EVENT_TABLE() }; diff --git a/include/wx/tbarbase.h b/include/wx/tbarbase.h index 3aa02843b5..97ff12eafb 100644 --- a/include/wx/tbarbase.h +++ b/include/wx/tbarbase.h @@ -208,11 +208,6 @@ class WXDLLEXPORT wxToolBarBase : public wxControl void OnSize(wxSizeEvent& event); void OnIdle(wxIdleEvent& event); - // Required to force normal cursor-setting behaviour in Windows -#ifdef __WXMSW__ - virtual void MSWOnMouseMove(int x, int y, WXUINT flags); -#endif - protected: wxList m_tools; // int m_tilingDirection; diff --git a/include/wx/window.h b/include/wx/window.h index 78b1fd342a..e801a29cf5 100644 --- a/include/wx/window.h +++ b/include/wx/window.h @@ -723,10 +723,7 @@ private: // contains the last id generated by NewControlId static int ms_lastControlId; - // no copy ctor/assignment operator - wxWindowBase(const wxWindowBase&); - wxWindowBase& operator=(const wxWindowBase&); - + DECLARE_NO_COPY_CLASS(wxWindowBase); DECLARE_EVENT_TABLE() }; diff --git a/include/wx/wxchar.h b/include/wx/wxchar.h index 96db64a224..a31a3825e4 100644 --- a/include/wx/wxchar.h +++ b/include/wx/wxchar.h @@ -44,6 +44,8 @@ // Windows (VC++) has broad TCHAR support #if defined(__VISUALC__) && defined(__WIN32__) +#define HAVE_WCSLEN 1 + #include #if wxUSE_UNICODE // temporary - preserve binary compatibility typedef _TCHAR wxChar; diff --git a/samples/image/image.cpp b/samples/image/image.cpp index 466618e351..c13b9f3d85 100644 --- a/samples/image/image.cpp +++ b/samples/image/image.cpp @@ -20,6 +20,8 @@ #include "wx/image.h" +#include "wx/file.h" + // derived classes class MyFrame; @@ -103,23 +105,33 @@ MyCanvas::MyCanvas( wxWindow *parent, wxWindowID id, dc.DrawRectangle( 0, 0, 100, 100 ); dc.SelectObject( wxNullBitmap ); - wxString dir(""); - -#ifdef __WXGTK__ - dir = wxString("../"); -#endif + // try to find the directory with our images + wxString dir; + if ( wxFile::Exists("./horse.png") ) + dir = "./"; + else if ( wxFile::Exists("../horse.png") ) + dir = "../"; + else + wxLogWarning("Can't find image files in either '.' or '..'!"); wxImage image( bitmap ); - image.SaveFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG ); + if ( !image.SaveFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG ) ) + wxLogError("Can't save file"); - image.LoadFile( dir + wxString("horse.png"), wxBITMAP_TYPE_PNG ); - my_horse_png = new wxBitmap( image.ConvertToBitmap() ); + if ( !image.LoadFile( dir + wxString("horse.png"), wxBITMAP_TYPE_PNG ) ) + wxLogError("Can't load PNG image"); + else + my_horse_png = new wxBitmap( image.ConvertToBitmap() ); - image.LoadFile( dir + wxString("horse.jpg"), wxBITMAP_TYPE_JPEG ); - my_horse_jpeg = new wxBitmap( image.ConvertToBitmap() ); + if ( !image.LoadFile( dir + wxString("horse.jpg"), wxBITMAP_TYPE_JPEG ) ) + wxLogError("Can't load JPG image"); + else + my_horse_jpeg = new wxBitmap( image.ConvertToBitmap() ); - image.LoadFile( dir + wxString("horse.gif"), wxBITMAP_TYPE_GIF ); - my_horse_gif = new wxBitmap( image.ConvertToBitmap() ); + if ( !image.LoadFile( dir + wxString("horse.gif"), wxBITMAP_TYPE_GIF ) ) + wxLogError("Can't load GIF image"); + else + my_horse_gif = new wxBitmap( image.ConvertToBitmap() ); image.LoadFile( dir + wxString("test.png"), wxBITMAP_TYPE_PNG ); my_square = new wxBitmap( image.ConvertToBitmap() ); diff --git a/src/common/gdicmn.cpp b/src/common/gdicmn.cpp index fa54d946b1..4a7784f0b4 100644 --- a/src/common/gdicmn.cpp +++ b/src/common/gdicmn.cpp @@ -43,29 +43,16 @@ #endif #if !USE_SHARED_LIBRARY -IMPLEMENT_CLASS(wxColourDatabase, wxList) -IMPLEMENT_DYNAMIC_CLASS(wxFontList, wxList) -IMPLEMENT_DYNAMIC_CLASS(wxPenList, wxList) -IMPLEMENT_DYNAMIC_CLASS(wxBrushList, wxList) -IMPLEMENT_DYNAMIC_CLASS(wxBitmapList, wxList) -IMPLEMENT_DYNAMIC_CLASS(wxResourceCache, wxList) -/* -IMPLEMENT_DYNAMIC_CLASS(wxRect, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxPoint, wxObject) -IMPLEMENT_DYNAMIC_CLASS(wxRealPoint, wxObject) -*/ + IMPLEMENT_CLASS(wxColourDatabase, wxList) + IMPLEMENT_DYNAMIC_CLASS(wxFontList, wxList) + IMPLEMENT_DYNAMIC_CLASS(wxPenList, wxList) + IMPLEMENT_DYNAMIC_CLASS(wxBrushList, wxList) + IMPLEMENT_DYNAMIC_CLASS(wxBitmapList, wxList) + IMPLEMENT_DYNAMIC_CLASS(wxResourceCache, wxList) + + IMPLEMENT_ABSTRACT_CLASS(wxDCBase, wxObject) #endif -wxRect::wxRect() -{ - x = 0; y = 0; width = 0; height = 0; -} - -wxRect::wxRect(long xx, long yy, long w, long h) -{ - x = xx; y = yy; width = w; height = h; -} - wxRect::wxRect(const wxPoint& topLeft, const wxPoint& bottomRight) { x = topLeft.x; @@ -92,21 +79,7 @@ wxRect::wxRect(const wxPoint& point, const wxSize& size) width = size.x; height = size.y; } -wxRect::wxRect(const wxRect& rect) -{ - x = rect.x; - y = rect.y; - width = rect.width; - height = rect.height; -} - -wxRect& wxRect::operator = (const wxRect& rect) -{ - x = rect.x; y = rect.y; width = rect.width; height = rect.height; - return *this; -} - -bool wxRect::operator == (const wxRect& rect) +bool wxRect::operator==(const wxRect& rect) const { return ((x == rect.x) && (y == rect.y) && @@ -114,16 +87,7 @@ bool wxRect::operator == (const wxRect& rect) (height == rect.height)); } -bool wxRect::operator != (const wxRect& rect) -{ - return ((x != rect.x) || - (y != rect.y) || - (width != rect.width) || - (height != rect.height)); -} - -wxColourDatabase::wxColourDatabase (int type): -wxList (type) +wxColourDatabase::wxColourDatabase (int type) : wxList (type) { } @@ -321,23 +285,29 @@ wxColour *wxColourDatabase::FindColour(const wxString& colour) wxString wxColourDatabase::FindName (const wxColour& colour) const { - unsigned char red = colour.Red (); - unsigned char green = colour.Green (); - unsigned char blue = colour.Blue (); + wxString name; - for (wxNode * node = First (); node; node = node->Next ()) - { - wxColour *col = (wxColour *) node->Data (); + unsigned char red = colour.Red (); + unsigned char green = colour.Green (); + unsigned char blue = colour.Blue (); + + for (wxNode * node = First (); node; node = node->Next ()) + { + wxColour *col = (wxColour *) node->Data (); - if (col->Red () == red && col->Green () == green && col->Blue () == blue) + if (col->Red () == red && col->Green () == green && col->Blue () == blue) { - const wxChar *found = node->GetKeyString(); - if (found) - return wxString(found); + const wxChar *found = node->GetKeyString(); + if ( found ) + { + name = found; + + break; + } } - } - return wxString(""); // Not Found + } + return name; } void wxInitializeStockLists () { diff --git a/src/common/tbarbase.cpp b/src/common/tbarbase.cpp index ae86a28759..751873f2b3 100644 --- a/src/common/tbarbase.cpp +++ b/src/common/tbarbase.cpp @@ -768,12 +768,4 @@ void wxToolBarBase::DoToolbarUpdates() } } -#ifdef __WXMSW__ -// Circumvent wxControl::MSWOnMouseMove which doesn't set the cursor. -void wxToolBarBase::MSWOnMouseMove(int x, int y, WXUINT flags) -{ - wxWindow::MSWOnMouseMove(x, y, flags); -} -#endif - #endif diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 153a0408af..2fead4a77e 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -178,7 +178,7 @@ wxWindowBase::~wxWindowBase() // Just in case we've loaded a top-level window via LoadNativeDialog but // we weren't a dialog class wxTopLevelWindows.DeleteObject(this); - + wxASSERT_MSG( GetChildren().GetCount() == 0, "children not destroyed" ); if ( m_windowValidator ) @@ -244,15 +244,21 @@ bool wxWindowBase::Close(bool force) bool wxWindowBase::DestroyChildren() { wxWindowList::Node *node; - while ( (node = GetChildren().GetFirst()) ) + for ( ;; ) { + // we iterate until the list becomes empty + node = GetChildren().GetFirst(); + if ( !node ) + break; + wxWindow *child = node->GetData(); - - wxASSERT_MSG( child, "m_children contains empty nodes" ); - + + wxASSERT_MSG( child, "children list contains empty nodes" ); + delete child; - - wxASSERT_MSG( !GetChildren().Find(child), "child didn't remove itself using RemoveChild()" ); + + wxASSERT_MSG( !GetChildren().Find(child), + "child didn't remove itself using RemoveChild()" ); } return TRUE; diff --git a/src/gtk/dc.cpp b/src/gtk/dc.cpp index d4e7c7b3ba..d43a7294b4 100644 --- a/src/gtk/dc.cpp +++ b/src/gtk/dc.cpp @@ -4,12 +4,12 @@ // Author: Robert Roebling // RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Markus Holzem -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "dc.h" + #pragma implementation "dc.h" #endif #include "wx/dc.h" @@ -21,145 +21,40 @@ // constants //----------------------------------------------------------------------------- -#define mm2inches 0.0393700787402 -#define inches2mm 25.4 -#define mm2twips 56.6929133859 -#define twips2mm 0.0176388888889 -#define mm2pt 2.83464566929 -#define pt2mm 0.352777777778 +#define mm2inches 0.0393700787402 +#define inches2mm 25.4 +#define mm2twips 56.6929133859 +#define twips2mm 0.0176388888889 +#define mm2pt 2.83464566929 +#define pt2mm 0.352777777778 //----------------------------------------------------------------------------- // wxDC //----------------------------------------------------------------------------- -IMPLEMENT_ABSTRACT_CLASS(wxDC,wxObject) +IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase) wxDC::wxDC() { m_ok = FALSE; + m_optimize = FALSE; m_autoSetting = FALSE; - m_colour = TRUE; - m_clipping = FALSE; - + m_mm_to_pix_x = 1.0; m_mm_to_pix_y = 1.0; - - m_logicalOriginX = 0; - m_logicalOriginY = 0; - m_deviceOriginX = 0; - m_deviceOriginY = 0; - - m_logicalScaleX = 1.0; - m_logicalScaleY = 1.0; - m_userScaleX = 1.0; - m_userScaleY = 1.0; - m_scaleX = 1.0; - m_scaleY = 1.0; - - m_mappingMode = wxMM_TEXT; + m_needComputeScaleX = FALSE; /* not used yet */ m_needComputeScaleY = FALSE; /* not used yet */ - - m_signX = 1; /* default x-axis left to right */ - m_signY = 1; /* default y-axis top down. -1 in postscript. */ - - m_maxX = 0; - m_maxY = 0; - m_minX = 0; - m_minY = 0; m_logicalFunction = wxCOPY; -// m_textAlignment = wxALIGN_TOP_LEFT; - m_backgroundMode = wxTRANSPARENT; - - m_textForegroundColour = *wxBLACK; - m_textBackgroundColour = *wxWHITE; + m_pen = *wxBLACK_PEN; m_font = *wxNORMAL_FONT; m_brush = *wxTRANSPARENT_BRUSH; - m_backgroundBrush = *wxWHITE_BRUSH; - -// m_palette = wxAPP_COLOURMAP; /* I'll learn to handle palettes later in my life */ } -wxDC::~wxDC() -{ -} - -bool wxDC::Ok() const -{ - return m_ok; -} - -void wxDC::DrawArc( long WXUNUSED(x1), long WXUNUSED(y1), long WXUNUSED(x2), long WXUNUSED(y2), - long WXUNUSED(xc), long WXUNUSED(yc) ) -{ -} - -void wxDC::DrawPoint( wxPoint& point ) -{ - DrawPoint( point.x, point.y ); -} - -void wxDC::DrawPolygon( wxList *list, long xoffset, long yoffset, int fillStyle ) -{ - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for( wxNode *node = list->First(); node; node = node->Next() ) - { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - } - - DrawPolygon( n, points, xoffset, yoffset, fillStyle ); - delete[] points; -} - -void wxDC::DrawLines( wxList *list, long xoffset, long yoffset ) -{ - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for( wxNode *node = list->First(); node; node = node->Next() ) - { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - } - - DrawLines( n, points, xoffset, yoffset ); - delete []points; -} - -void wxDC::DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 ) -{ - wxList list; - list.Append( (wxObject*)new wxPoint(x1, y1) ); - list.Append( (wxObject*)new wxPoint(x2, y2) ); - list.Append( (wxObject*)new wxPoint(x3, y3) ); - DrawSpline(&list); - wxNode *node = list.First(); - while (node) - { - wxPoint *p = (wxPoint*)node->Data(); - delete p; - node = node->Next(); - } -} - -void wxDC::DrawSpline( int n, wxPoint points[] ) -{ - wxList list; - for (int i = 0; i < n; i++) list.Append( (wxObject*)&points[i] ); - DrawSpline( &list ); -} - -void wxDC::SetClippingRegion( long x, long y, long width, long height ) +void wxDC::DoSetClippingRegion( long x, long y, long width, long height ) { m_clipping = TRUE; m_clipX1 = x; @@ -173,28 +68,17 @@ void wxDC::DestroyClippingRegion() m_clipping = FALSE; } -void wxDC::GetClippingBox( long *x, long *y, long *width, long *height ) const -{ - if (m_clipping) - { - if (x) *x = m_clipX1; - if (y) *y = m_clipY1; - if (width) *width = (m_clipX2 - m_clipX1); - if (height) *height = (m_clipY2 - m_clipY1); - } - else - { - *x = *y = *width = *height = 0; - } -} +// --------------------------------------------------------------------------- +// get DC capabilities +// --------------------------------------------------------------------------- -void wxDC::GetSize( int* width, int* height ) const +void wxDC::DoGetSize( int* width, int* height ) const { if (width) *width = m_maxX-m_minX; if (height) *height = m_maxY-m_minY; } -void wxDC::GetSizeMM( int* width, int* height ) const +void wxDC::DoGetSizeMM( int* width, int* height ) const { int w = 0; int h = 0; @@ -204,25 +88,42 @@ void wxDC::GetSizeMM( int* width, int* height ) const } // Resolution in pixels per logical inch -wxSize wxDC::GetPPI(void) const +wxSize wxDC::GetPPI() const { // TODO (should probably be pure virtual) return wxSize(0, 0); } -void wxDC::SetTextForeground( const wxColour &col ) -{ - m_textForegroundColour = col; -} +// --------------------------------------------------------------------------- +// set various DC parameters +// --------------------------------------------------------------------------- -void wxDC::SetTextBackground( const wxColour &col ) +void wxDC::ComputeScaleAndOrigin() { - m_textBackgroundColour = col; + // CMB: copy scale to see if it changes + double origScaleX = m_scaleX; + double origScaleY = m_scaleY; + + m_scaleX = m_logicalScaleX * m_userScaleX; + m_scaleY = m_logicalScaleY * m_userScaleY; + + // CMB: if scale has changed call SetPen to recalulate the line width + if (m_scaleX != origScaleX || m_scaleY != origScaleY) + { + // this is a bit artificial, but we need to force wxDC to think + // the pen has changed + // It gives an Assert, Robert Roebling +/* + wxPen pen = m_pen; + m_pen = wxNullPen; + SetPen( pen ); +*/ + } } void wxDC::SetMapMode( int mode ) { - switch (mode) + switch (mode) { case wxMM_TWIPS: SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); @@ -258,12 +159,6 @@ void wxDC::SetUserScale( double x, double y ) ComputeScaleAndOrigin(); } -void wxDC::GetUserScale( double *x, double *y ) -{ - if (x) *x = m_userScaleX; - if (y) *y = m_userScaleY; -} - void wxDC::SetLogicalScale( double x, double y ) { // allow negative ? @@ -272,12 +167,6 @@ void wxDC::SetLogicalScale( double x, double y ) ComputeScaleAndOrigin(); } -void wxDC::GetLogicalScale( double *x, double *y ) -{ - if (x) *x = m_logicalScaleX; - if (y) *y = m_logicalScaleY; -} - void wxDC::SetLogicalOrigin( long x, long y ) { m_logicalOriginX = x * m_signX; // is this still correct ? @@ -285,26 +174,14 @@ void wxDC::SetLogicalOrigin( long x, long y ) ComputeScaleAndOrigin(); } -void wxDC::GetLogicalOrigin( long *x, long *y ) -{ - if (x) *x = m_logicalOriginX; - if (y) *y = m_logicalOriginY; -} - void wxDC::SetDeviceOrigin( long x, long y ) { // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there - m_deviceOriginX = x; + m_deviceOriginX = x; m_deviceOriginY = y; ComputeScaleAndOrigin(); } -void wxDC::GetDeviceOrigin( long *x, long *y ) -{ - if (x) *x = m_deviceOriginX; - if (y) *y = m_deviceOriginY; -} - void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there @@ -313,74 +190,47 @@ void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) ComputeScaleAndOrigin(); } -long wxDC::DeviceToLogicalX(long x) const +// --------------------------------------------------------------------------- +// coordinates transformations +// --------------------------------------------------------------------------- + +long wxDCBase::DeviceToLogicalX(long x) const { return XDEV2LOG(x); } -long wxDC::DeviceToLogicalY(long y) const +long wxDCBase::DeviceToLogicalY(long y) const { return YDEV2LOG(y); } -long wxDC::DeviceToLogicalXRel(long x) const +long wxDCBase::DeviceToLogicalXRel(long x) const { return XDEV2LOGREL(x); } -long wxDC::DeviceToLogicalYRel(long y) const +long wxDCBase::DeviceToLogicalYRel(long y) const { return YDEV2LOGREL(y); } -long wxDC::LogicalToDeviceX(long x) const +long wxDCBase::LogicalToDeviceX(long x) const { return XLOG2DEV(x); } -long wxDC::LogicalToDeviceY(long y) const +long wxDCBase::LogicalToDeviceY(long y) const { return YLOG2DEV(y); } -long wxDC::LogicalToDeviceXRel(long x) const +long wxDCBase::LogicalToDeviceXRel(long x) const { return XLOG2DEVREL(x); } -long wxDC::LogicalToDeviceYRel(long y) const +long wxDCBase::LogicalToDeviceYRel(long y) const { return YLOG2DEVREL(y); } - -void wxDC::CalcBoundingBox( long x, long y ) -{ - if (x < m_minX) m_minX = x; - if (y < m_minY) m_minY = y; - if (x > m_maxX) m_maxX = x; - if (y > m_maxY) m_maxY = y; -} - -void wxDC::ComputeScaleAndOrigin() -{ - // CMB: copy scale to see if it changes - double origScaleX = m_scaleX; - double origScaleY = m_scaleY; - - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; - - // CMB: if scale has changed call SetPen to recalulate the line width - if (m_scaleX != origScaleX || m_scaleY != origScaleY) - { - // this is a bit artificial, but we need to force wxDC to think - // the pen has changed - // It gives an Assert, Robert Roebling -/* - wxPen pen = m_pen; - m_pen = wxNullPen; - SetPen( pen ); -*/ - } -} diff --git a/src/gtk1/dc.cpp b/src/gtk1/dc.cpp index d4e7c7b3ba..d43a7294b4 100644 --- a/src/gtk1/dc.cpp +++ b/src/gtk1/dc.cpp @@ -4,12 +4,12 @@ // Author: Robert Roebling // RCS-ID: $Id$ // Copyright: (c) 1998 Robert Roebling, Markus Holzem -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "dc.h" + #pragma implementation "dc.h" #endif #include "wx/dc.h" @@ -21,145 +21,40 @@ // constants //----------------------------------------------------------------------------- -#define mm2inches 0.0393700787402 -#define inches2mm 25.4 -#define mm2twips 56.6929133859 -#define twips2mm 0.0176388888889 -#define mm2pt 2.83464566929 -#define pt2mm 0.352777777778 +#define mm2inches 0.0393700787402 +#define inches2mm 25.4 +#define mm2twips 56.6929133859 +#define twips2mm 0.0176388888889 +#define mm2pt 2.83464566929 +#define pt2mm 0.352777777778 //----------------------------------------------------------------------------- // wxDC //----------------------------------------------------------------------------- -IMPLEMENT_ABSTRACT_CLASS(wxDC,wxObject) +IMPLEMENT_ABSTRACT_CLASS(wxDC, wxDCBase) wxDC::wxDC() { m_ok = FALSE; + m_optimize = FALSE; m_autoSetting = FALSE; - m_colour = TRUE; - m_clipping = FALSE; - + m_mm_to_pix_x = 1.0; m_mm_to_pix_y = 1.0; - - m_logicalOriginX = 0; - m_logicalOriginY = 0; - m_deviceOriginX = 0; - m_deviceOriginY = 0; - - m_logicalScaleX = 1.0; - m_logicalScaleY = 1.0; - m_userScaleX = 1.0; - m_userScaleY = 1.0; - m_scaleX = 1.0; - m_scaleY = 1.0; - - m_mappingMode = wxMM_TEXT; + m_needComputeScaleX = FALSE; /* not used yet */ m_needComputeScaleY = FALSE; /* not used yet */ - - m_signX = 1; /* default x-axis left to right */ - m_signY = 1; /* default y-axis top down. -1 in postscript. */ - - m_maxX = 0; - m_maxY = 0; - m_minX = 0; - m_minY = 0; m_logicalFunction = wxCOPY; -// m_textAlignment = wxALIGN_TOP_LEFT; - m_backgroundMode = wxTRANSPARENT; - - m_textForegroundColour = *wxBLACK; - m_textBackgroundColour = *wxWHITE; + m_pen = *wxBLACK_PEN; m_font = *wxNORMAL_FONT; m_brush = *wxTRANSPARENT_BRUSH; - m_backgroundBrush = *wxWHITE_BRUSH; - -// m_palette = wxAPP_COLOURMAP; /* I'll learn to handle palettes later in my life */ } -wxDC::~wxDC() -{ -} - -bool wxDC::Ok() const -{ - return m_ok; -} - -void wxDC::DrawArc( long WXUNUSED(x1), long WXUNUSED(y1), long WXUNUSED(x2), long WXUNUSED(y2), - long WXUNUSED(xc), long WXUNUSED(yc) ) -{ -} - -void wxDC::DrawPoint( wxPoint& point ) -{ - DrawPoint( point.x, point.y ); -} - -void wxDC::DrawPolygon( wxList *list, long xoffset, long yoffset, int fillStyle ) -{ - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for( wxNode *node = list->First(); node; node = node->Next() ) - { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - } - - DrawPolygon( n, points, xoffset, yoffset, fillStyle ); - delete[] points; -} - -void wxDC::DrawLines( wxList *list, long xoffset, long yoffset ) -{ - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for( wxNode *node = list->First(); node; node = node->Next() ) - { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - } - - DrawLines( n, points, xoffset, yoffset ); - delete []points; -} - -void wxDC::DrawSpline( long x1, long y1, long x2, long y2, long x3, long y3 ) -{ - wxList list; - list.Append( (wxObject*)new wxPoint(x1, y1) ); - list.Append( (wxObject*)new wxPoint(x2, y2) ); - list.Append( (wxObject*)new wxPoint(x3, y3) ); - DrawSpline(&list); - wxNode *node = list.First(); - while (node) - { - wxPoint *p = (wxPoint*)node->Data(); - delete p; - node = node->Next(); - } -} - -void wxDC::DrawSpline( int n, wxPoint points[] ) -{ - wxList list; - for (int i = 0; i < n; i++) list.Append( (wxObject*)&points[i] ); - DrawSpline( &list ); -} - -void wxDC::SetClippingRegion( long x, long y, long width, long height ) +void wxDC::DoSetClippingRegion( long x, long y, long width, long height ) { m_clipping = TRUE; m_clipX1 = x; @@ -173,28 +68,17 @@ void wxDC::DestroyClippingRegion() m_clipping = FALSE; } -void wxDC::GetClippingBox( long *x, long *y, long *width, long *height ) const -{ - if (m_clipping) - { - if (x) *x = m_clipX1; - if (y) *y = m_clipY1; - if (width) *width = (m_clipX2 - m_clipX1); - if (height) *height = (m_clipY2 - m_clipY1); - } - else - { - *x = *y = *width = *height = 0; - } -} +// --------------------------------------------------------------------------- +// get DC capabilities +// --------------------------------------------------------------------------- -void wxDC::GetSize( int* width, int* height ) const +void wxDC::DoGetSize( int* width, int* height ) const { if (width) *width = m_maxX-m_minX; if (height) *height = m_maxY-m_minY; } -void wxDC::GetSizeMM( int* width, int* height ) const +void wxDC::DoGetSizeMM( int* width, int* height ) const { int w = 0; int h = 0; @@ -204,25 +88,42 @@ void wxDC::GetSizeMM( int* width, int* height ) const } // Resolution in pixels per logical inch -wxSize wxDC::GetPPI(void) const +wxSize wxDC::GetPPI() const { // TODO (should probably be pure virtual) return wxSize(0, 0); } -void wxDC::SetTextForeground( const wxColour &col ) -{ - m_textForegroundColour = col; -} +// --------------------------------------------------------------------------- +// set various DC parameters +// --------------------------------------------------------------------------- -void wxDC::SetTextBackground( const wxColour &col ) +void wxDC::ComputeScaleAndOrigin() { - m_textBackgroundColour = col; + // CMB: copy scale to see if it changes + double origScaleX = m_scaleX; + double origScaleY = m_scaleY; + + m_scaleX = m_logicalScaleX * m_userScaleX; + m_scaleY = m_logicalScaleY * m_userScaleY; + + // CMB: if scale has changed call SetPen to recalulate the line width + if (m_scaleX != origScaleX || m_scaleY != origScaleY) + { + // this is a bit artificial, but we need to force wxDC to think + // the pen has changed + // It gives an Assert, Robert Roebling +/* + wxPen pen = m_pen; + m_pen = wxNullPen; + SetPen( pen ); +*/ + } } void wxDC::SetMapMode( int mode ) { - switch (mode) + switch (mode) { case wxMM_TWIPS: SetLogicalScale( twips2mm*m_mm_to_pix_x, twips2mm*m_mm_to_pix_y ); @@ -258,12 +159,6 @@ void wxDC::SetUserScale( double x, double y ) ComputeScaleAndOrigin(); } -void wxDC::GetUserScale( double *x, double *y ) -{ - if (x) *x = m_userScaleX; - if (y) *y = m_userScaleY; -} - void wxDC::SetLogicalScale( double x, double y ) { // allow negative ? @@ -272,12 +167,6 @@ void wxDC::SetLogicalScale( double x, double y ) ComputeScaleAndOrigin(); } -void wxDC::GetLogicalScale( double *x, double *y ) -{ - if (x) *x = m_logicalScaleX; - if (y) *y = m_logicalScaleY; -} - void wxDC::SetLogicalOrigin( long x, long y ) { m_logicalOriginX = x * m_signX; // is this still correct ? @@ -285,26 +174,14 @@ void wxDC::SetLogicalOrigin( long x, long y ) ComputeScaleAndOrigin(); } -void wxDC::GetLogicalOrigin( long *x, long *y ) -{ - if (x) *x = m_logicalOriginX; - if (y) *y = m_logicalOriginY; -} - void wxDC::SetDeviceOrigin( long x, long y ) { // only wxPostScripDC has m_signX = -1, we override SetDeviceOrigin there - m_deviceOriginX = x; + m_deviceOriginX = x; m_deviceOriginY = y; ComputeScaleAndOrigin(); } -void wxDC::GetDeviceOrigin( long *x, long *y ) -{ - if (x) *x = m_deviceOriginX; - if (y) *y = m_deviceOriginY; -} - void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) { // only wxPostScripDC has m_signX = -1, we override SetAxisOrientation there @@ -313,74 +190,47 @@ void wxDC::SetAxisOrientation( bool xLeftRight, bool yBottomUp ) ComputeScaleAndOrigin(); } -long wxDC::DeviceToLogicalX(long x) const +// --------------------------------------------------------------------------- +// coordinates transformations +// --------------------------------------------------------------------------- + +long wxDCBase::DeviceToLogicalX(long x) const { return XDEV2LOG(x); } -long wxDC::DeviceToLogicalY(long y) const +long wxDCBase::DeviceToLogicalY(long y) const { return YDEV2LOG(y); } -long wxDC::DeviceToLogicalXRel(long x) const +long wxDCBase::DeviceToLogicalXRel(long x) const { return XDEV2LOGREL(x); } -long wxDC::DeviceToLogicalYRel(long y) const +long wxDCBase::DeviceToLogicalYRel(long y) const { return YDEV2LOGREL(y); } -long wxDC::LogicalToDeviceX(long x) const +long wxDCBase::LogicalToDeviceX(long x) const { return XLOG2DEV(x); } -long wxDC::LogicalToDeviceY(long y) const +long wxDCBase::LogicalToDeviceY(long y) const { return YLOG2DEV(y); } -long wxDC::LogicalToDeviceXRel(long x) const +long wxDCBase::LogicalToDeviceXRel(long x) const { return XLOG2DEVREL(x); } -long wxDC::LogicalToDeviceYRel(long y) const +long wxDCBase::LogicalToDeviceYRel(long y) const { return YLOG2DEVREL(y); } - -void wxDC::CalcBoundingBox( long x, long y ) -{ - if (x < m_minX) m_minX = x; - if (y < m_minY) m_minY = y; - if (x > m_maxX) m_maxX = x; - if (y > m_maxY) m_maxY = y; -} - -void wxDC::ComputeScaleAndOrigin() -{ - // CMB: copy scale to see if it changes - double origScaleX = m_scaleX; - double origScaleY = m_scaleY; - - m_scaleX = m_logicalScaleX * m_userScaleX; - m_scaleY = m_logicalScaleY * m_userScaleY; - - // CMB: if scale has changed call SetPen to recalulate the line width - if (m_scaleX != origScaleX || m_scaleY != origScaleY) - { - // this is a bit artificial, but we need to force wxDC to think - // the pen has changed - // It gives an Assert, Robert Roebling -/* - wxPen pen = m_pen; - m_pen = wxNullPen; - SetPen( pen ); -*/ - } -} diff --git a/src/msw/checklst.cpp b/src/msw/checklst.cpp index a2ec7b6f5a..5e46c81073 100644 --- a/src/msw/checklst.cpp +++ b/src/msw/checklst.cpp @@ -365,7 +365,7 @@ void wxCheckListBox::OnChar(wxKeyEvent& event) if ( event.KeyCode() == WXK_SPACE ) GetItem(GetSelection())->Toggle(); else - wxListBox::OnChar(event); + event.Skip(); } void wxCheckListBox::OnLeftClick(wxMouseEvent& event) diff --git a/src/msw/control.cpp b/src/msw/control.cpp index 408813f4f6..542d3d7b08 100644 --- a/src/msw/control.cpp +++ b/src/msw/control.cpp @@ -6,7 +6,7 @@ // Created: 01/02/97 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -43,7 +43,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) BEGIN_EVENT_TABLE(wxControl, wxWindow) - EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground) + EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground) END_EVENT_TABLE() #endif @@ -119,136 +119,54 @@ void wxFindMaxSize(WXHWND wnd, RECT *rect) } -/* -// Not currently used -void wxConvertDialogToPixels(wxWindow *control, int *x, int *y) +#ifdef __WIN95__ +bool wxControl::MSWOnNotify(int idCtrl, + WXLPARAM lParam, + WXLPARAM* result) { - if (control->m_windowParent && control->m_windowParent->is_dialog) - { - DWORD word = GetDialogBaseUnits(); - int xs = LOWORD(word); - int ys = HIWORD(word); - *x = (int)(*x * xs/4); - *y = (int)(*y * ys/8); - } - else - { - *x = *x; - *y = *y; - } -} -*/ + wxCommandEvent event(wxEVT_NULL, m_windowId); + wxEventType eventType = wxEVT_NULL; + NMHDR *hdr1 = (NMHDR*) lParam; + switch ( hdr1->code ) + { + case NM_CLICK: + eventType = wxEVT_COMMAND_LEFT_CLICK; + break; -void wxControl::MSWOnMouseMove(int x, int y, WXUINT flags) -{ -/* - // Trouble with this is that it sets the cursor for controls too :-( - if (m_windowCursor.Ok() && !wxIsBusy()) - ::SetCursor(m_windowCursor.GetHCURSOR()); -*/ + case NM_DBLCLK: + eventType = wxEVT_COMMAND_LEFT_DCLICK; + break; - if (!m_mouseInWindow) - { - // Generate an ENTER event - m_mouseInWindow = TRUE; - MSWOnMouseEnter(x, y, flags); - } + case NM_RCLICK: + eventType = wxEVT_COMMAND_RIGHT_CLICK; + break; - wxMouseEvent event(wxEVT_MOTION); - - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.SetEventObject( this ); - - // Window gets a click down message followed by a mouse move - // message even if position isn't changed! We want to discard - // the trailing move event if x and y are the same. - if ((m_lastMouseEvent == wxEVT_RIGHT_DOWN || m_lastMouseEvent == wxEVT_LEFT_DOWN || - m_lastMouseEvent == wxEVT_MIDDLE_DOWN) && - (m_lastMouseX == event.GetX() && m_lastMouseY == event.GetY())) - { - m_lastMouseX = event.GetX(); m_lastMouseY = event.GetY(); - m_lastMouseEvent = wxEVT_MOTION; - return; - } + case NM_RDBLCLK: + eventType = wxEVT_COMMAND_RIGHT_DCLICK; + break; - m_lastMouseEvent = wxEVT_MOTION; - m_lastMouseX = event.GetX(); m_lastMouseY = event.GetY(); + case NM_SETFOCUS: + eventType = wxEVT_COMMAND_SET_FOCUS; + break; - if (!GetEventHandler()->ProcessEvent(event)) - Default(); -} + case NM_KILLFOCUS: + eventType = wxEVT_COMMAND_KILL_FOCUS; + break; -bool wxControl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, - WXLPARAM* result) -{ -#if defined(__WIN95__) - wxCommandEvent event(wxEVT_NULL, m_windowId); - wxEventType eventType = wxEVT_NULL; - NMHDR *hdr1 = (NMHDR*) lParam; - switch ( hdr1->code ) - { - case NM_CLICK: - { - eventType = wxEVT_COMMAND_LEFT_CLICK; - break; - } - case NM_DBLCLK: - { - eventType = wxEVT_COMMAND_LEFT_DCLICK; - break; - } - case NM_RCLICK: - { - eventType = wxEVT_COMMAND_RIGHT_CLICK; - break; - } - case NM_RDBLCLK: - { - eventType = wxEVT_COMMAND_RIGHT_DCLICK; - break; - } - case NM_SETFOCUS: - { - eventType = wxEVT_COMMAND_SET_FOCUS; - break; - } - case NM_KILLFOCUS: - { - eventType = wxEVT_COMMAND_KILL_FOCUS; - break; - } - case NM_RETURN: - { - eventType = wxEVT_COMMAND_ENTER; - break; - } -/* Not implemented - case NM_OUTOFMEMORY: - { - eventType = wxEVT_COMMAND_OUT_OF_MEMORY; - break; - } -*/ - default: - return wxWindow::MSWNotify(wParam, lParam, result); - } + case NM_RETURN: + eventType = wxEVT_COMMAND_ENTER; + break; + + default: + return wxWindow::MSWOnNotify(idCtrl, lParam, result); + } event.SetEventType(eventType); - event.SetEventObject(this); + event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) ) - return FALSE; - return TRUE; -#else // !Win95 - return FALSE; -#endif + return GetEventHandler()->ProcessEvent(event); } +#endif // Win95 void wxControl::ProcessCommand (wxCommandEvent & event) { diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp index b300d73dfe..33423e3172 100644 --- a/src/msw/dc.cpp +++ b/src/msw/dc.cpp @@ -9,25 +9,33 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// =========================================================================== +// declarations +// =========================================================================== + +// --------------------------------------------------------------------------- +// headers +// --------------------------------------------------------------------------- + #ifdef __GNUG__ -#pragma implementation "dc.h" + #pragma implementation "dc.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP -#include "wx/frame.h" -#include "wx/dc.h" -#include "wx/utils.h" -#include "wx/dialog.h" -#include "wx/app.h" -#include "wx/bitmap.h" -#include "wx/dcmemory.h" + #include "wx/frame.h" + #include "wx/dc.h" + #include "wx/utils.h" + #include "wx/dialog.h" + #include "wx/app.h" + #include "wx/bitmap.h" + #include "wx/dcmemory.h" #endif #include "wx/dcprint.h" @@ -37,92 +45,82 @@ #include #if wxUSE_COMMON_DIALOGS -#include + #include #endif #ifndef __WIN32__ -#include + #include #endif #ifdef DrawText -#undef DrawText + #undef DrawText #endif #ifdef GetCharWidth -#undef GetCharWidth + #undef GetCharWidth #endif #ifdef StartDoc -#undef StartDoc + #undef StartDoc #endif #if !USE_SHARED_LIBRARY -IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) + IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) #endif -// Declarations local to this file +// --------------------------------------------------------------------------- +// constants +// --------------------------------------------------------------------------- + +#define VIEWPORT_EXTENT 1000 + +// --------------------------------------------------------------------------- +// macros +// --------------------------------------------------------------------------- #define YSCALE(y) (yorigin - (y)) -// #define wx_round(a) (int)((a)+.5) +// =========================================================================== +// implementation +// =========================================================================== + +// --------------------------------------------------------------------------- +// wxDC +// --------------------------------------------------------------------------- // Default constructor -wxDC::wxDC(void) +wxDC::wxDC() { - m_minX = 0; m_minY = 0; m_maxX = 0; m_maxY = 0; - m_clipping = FALSE; - m_canvas = NULL; + m_oldBitmap = 0; m_oldPen = 0; m_oldBrush = 0; m_oldFont = 0; m_oldPalette = 0; - m_minX = 0; m_minY = 0; m_maxX = 0; m_maxY = 0; - m_logicalOriginX = 0; - m_logicalOriginY = 0; - m_deviceOriginX = 0; - m_deviceOriginY = 0; - m_logicalScaleX = 1.0; - m_logicalScaleY = 1.0; - m_userScaleX = 1.0; - m_userScaleY = 1.0; - m_signX = 1; - m_signY = 1; - m_systemScaleX = 1.0; - m_systemScaleY = 1.0; - m_mappingMode = wxMM_TEXT; + m_bOwnsDC = FALSE; m_hDC = 0; - m_clipping = FALSE; - m_ok = TRUE; + m_windowExtX = VIEWPORT_EXTENT; m_windowExtY = VIEWPORT_EXTENT; - m_logicalFunction = -1; - - m_backgroundBrush = *wxWHITE_BRUSH; - - m_textForegroundColour = *wxBLACK; - m_textBackgroundColour = *wxWHITE; - - m_colour = wxColourDisplay(); - + m_hDCCount = 0; } -wxDC::~wxDC(void) +wxDC::~wxDC() { if ( m_hDC != 0 ) { SelectOldObjects(m_hDC); if ( m_bOwnsDC ) { if ( m_canvas == NULL ) - ::DeleteDC((HDC)m_hDC); + ::DeleteDC(GetHdc()); else - ::ReleaseDC((HWND)m_canvas->GetHWND(), (HDC)m_hDC); + ::ReleaseDC((HWND)m_canvas->GetHWND(), GetHdc()); } } - + } // This will select current objects out of the DC, @@ -140,30 +138,30 @@ void wxDC::SelectOldObjects(WXHDC dc) m_selectedBitmap.SetSelectedInto(NULL); } } - m_oldBitmap = 0 ; + m_oldBitmap = 0; if (m_oldPen) { ::SelectObject((HDC) dc, (HPEN) m_oldPen); } - m_oldPen = 0 ; + m_oldPen = 0; if (m_oldBrush) { ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush); } - m_oldBrush = 0 ; + m_oldBrush = 0; if (m_oldFont) { ::SelectObject((HDC) dc, (HFONT) m_oldFont); } - m_oldFont = 0 ; + m_oldFont = 0; if (m_oldPalette) { ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE); } - m_oldPalette = 0 ; + m_oldPalette = 0; } - - m_brush = wxNullBrush ; + + m_brush = wxNullBrush; m_pen = wxNullPen; m_palette = wxNullPalette; m_font = wxNullFont; @@ -171,34 +169,37 @@ void wxDC::SelectOldObjects(WXHDC dc) m_selectedBitmap = wxNullBitmap; } -void wxDC::SetClippingRegion(long cx, long cy, long cw, long ch) +// --------------------------------------------------------------------------- +// clipping +// --------------------------------------------------------------------------- + +void wxDC::DoSetClippingRegion(long cx, long cy, long cw, long ch) { m_clipping = TRUE; m_clipX1 = (int)cx; m_clipY1 = (int)cy; m_clipX2 = (int)(cx + cw); m_clipY2 = (int)(cy + ch); - + DoClipping((WXHDC) m_hDC); } -void wxDC::SetClippingRegion(const wxRegion& region) +void wxDC::DoSetClippingRegionAsRegion(const wxRegion& region) { - if (!region.GetHRGN()) - return; - + wxCHECK_RET( region.GetHRGN(), _T("invalid clipping region") ); + wxRect box = region.GetBox(); - + m_clipping = TRUE; m_clipX1 = box.x; m_clipY1 = box.y; m_clipX2 = box.x + box.width; m_clipY2 = box.y + box.height; - + #ifdef __WIN16__ - SelectClipRgn((HDC) m_hDC, (HRGN) region.GetHRGN()); + SelectClipRgn(GetHdc(), (HRGN) region.GetHRGN()); #else - ExtSelectClipRgn((HDC) m_hDC, (HRGN) region.GetHRGN(), RGN_AND); + ExtSelectClipRgn(GetHdc(), (HRGN) region.GetHRGN(), RGN_AND); #endif } @@ -207,11 +208,11 @@ void wxDC::DoClipping(WXHDC dc) if (m_clipping && dc) { IntersectClipRect((HDC) dc, XLOG2DEV(m_clipX1), YLOG2DEV(m_clipY1), - XLOG2DEV(m_clipX2), YLOG2DEV(m_clipY2)); + XLOG2DEV(m_clipX2), YLOG2DEV(m_clipY2)); } } -void wxDC::DestroyClippingRegion(void) +void wxDC::DestroyClippingRegion() { if (m_clipping && m_hDC) { @@ -219,67 +220,39 @@ void wxDC::DestroyClippingRegion(void) // so that OnPaint processing works correctly, and the update clipping region // doesn't get destroyed after the first DestroyClippingRegion. HRGN rgn = CreateRectRgn(0, 0, 32000, 32000); - SelectClipRgn((HDC) m_hDC, rgn); + SelectClipRgn(GetHdc(), rgn); DeleteObject(rgn); } m_clipping = FALSE; } -bool wxDC::CanDrawBitmap(void) const +// --------------------------------------------------------------------------- +// query capabilities +// --------------------------------------------------------------------------- + +bool wxDC::CanDrawBitmap() const { return TRUE; } -bool wxDC::CanGetTextExtent(void) const +bool wxDC::CanGetTextExtent() const { // What sort of display is it? - int technology = ::GetDeviceCaps((HDC) m_hDC, TECHNOLOGY); - - bool ok; - - if (technology != DT_RASDISPLAY && technology != DT_RASPRINTER) - ok = FALSE; - else ok = TRUE; - - return ok; + int technology = ::GetDeviceCaps(GetHdc(), TECHNOLOGY); + + return (technology == DT_RASDISPLAY) || (technology == DT_RASPRINTER); } -void wxDC::SetPalette(const wxPalette& palette) +int wxDC::GetDepth() const { - // Set the old object temporarily, in case the assignment deletes an object - // that's not yet selected out. - if (m_oldPalette) - { - ::SelectPalette((HDC) m_hDC, (HPALETTE) m_oldPalette, TRUE); - m_oldPalette = 0; - } - - m_palette = palette; - - if (!m_palette.Ok()) - { - // Setting a NULL colourmap is a way of restoring - // the original colourmap - if (m_oldPalette) - { - ::SelectPalette((HDC) m_hDC, (HPALETTE) m_oldPalette, TRUE); - m_oldPalette = 0; - } - - return; - } - - if (m_palette.Ok() && m_palette.GetHPALETTE()) - { - HPALETTE oldPal = ::SelectPalette((HDC) m_hDC, (HPALETTE) m_palette.GetHPALETTE(), TRUE); - if (!m_oldPalette) - m_oldPalette = (WXHPALETTE) oldPal; - - ::RealizePalette((HDC) m_hDC); - } + return (int)::GetDeviceCaps(GetHdc(), BITSPIXEL); } -void wxDC::Clear(void) +// --------------------------------------------------------------------------- +// drawing +// --------------------------------------------------------------------------- + +void wxDC::Clear() { RECT rect; if (m_canvas) @@ -290,108 +263,106 @@ void wxDC::Clear(void) rect.right = m_selectedBitmap.GetWidth(); rect.bottom = m_selectedBitmap.GetHeight(); } - (void) ::SetMapMode((HDC) m_hDC, MM_TEXT); - - DWORD colour = GetBkColor((HDC) m_hDC); + (void) ::SetMapMode(GetHdc(), MM_TEXT); + + DWORD colour = GetBkColor(GetHdc()); HBRUSH brush = CreateSolidBrush(colour); - FillRect((HDC) m_hDC, &rect, brush); + FillRect(GetHdc(), &rect, brush); DeleteObject(brush); - - ::SetMapMode((HDC) m_hDC, MM_ANISOTROPIC); - ::SetViewportExtEx((HDC) m_hDC, VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); - ::SetWindowExtEx((HDC) m_hDC, m_windowExtX, m_windowExtY, NULL); - ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); - ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); -} - -void wxDC::FloodFill(long x, long y, const wxColour& col, int style) -{ - (void)ExtFloodFill((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), - col.GetPixel(), - style==wxFLOOD_SURFACE? -FLOODFILLSURFACE:FLOODFILLBORDER - ); - + + ::SetMapMode(GetHdc(), MM_ANISOTROPIC); + ::SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); + ::SetWindowExtEx(GetHdc(), m_windowExtX, m_windowExtY, NULL); + ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); + ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); +} + +void wxDC::DoFloodFill(long x, long y, const wxColour& col, int style) +{ + (void)ExtFloodFill(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), + col.GetPixel(), + style == wxFLOOD_SURFACE ? FLOODFILLSURFACE + : FLOODFILLBORDER); + CalcBoundingBox(x, y); } -bool wxDC::GetPixel(long x, long y, wxColour *col) const +bool wxDC::DoGetPixel(long x, long y, wxColour *col) const { // added by steve 29.12.94 (copied from DrawPoint) // returns TRUE for pixels in the color of the current pen // and FALSE for all other pixels colors // if col is non-NULL return the color of the pixel - + // get the color of the pixel - COLORREF pixelcolor = ::GetPixel((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y)); + COLORREF pixelcolor = ::GetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y)); // get the color of the pen COLORREF pencolor = 0x00ffffff; if (m_pen.Ok()) { - pencolor = m_pen.GetColour().GetPixel() ; + pencolor = m_pen.GetColour().GetPixel(); } - + // return the color of the pixel if(col) col->Set(GetRValue(pixelcolor),GetGValue(pixelcolor),GetBValue(pixelcolor)); - + // check, if color of the pixels is the same as the color // of the current pen return(pixelcolor==pencolor); } -void wxDC::CrossHair(long x, long y) -{ - // We suppose that our screen is 2000x2000 max. - long x1 = x-2000; - long y1 = y-2000; - long x2 = x+2000; - long y2 = y+2000; - - (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x1), YLOG2DEV(y), NULL); - (void)LineTo((HDC) m_hDC, XLOG2DEV(x2), YLOG2DEV(y)); - - (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y1), NULL); - (void)LineTo((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y2)); - +void wxDC::DoCrossHair(long x, long y) +{ + long x1 = x-VIEWPORT_EXTENT; + long y1 = y-VIEWPORT_EXTENT; + long x2 = x+VIEWPORT_EXTENT; + long y2 = y+VIEWPORT_EXTENT; + + (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y), NULL); + (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y)); + + (void)MoveToEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y1), NULL); + (void)LineTo(GetHdc(), XLOG2DEV(x), YLOG2DEV(y2)); + CalcBoundingBox(x1, y1); CalcBoundingBox(x2, y2); } -void wxDC::DrawLine(long x1, long y1, long x2, long y2) +void wxDC::DoDrawLine(long x1, long y1, long x2, long y2) { - (void)MoveToEx((HDC) m_hDC, XLOG2DEV(x1), YLOG2DEV(y1), NULL); - (void)LineTo((HDC) m_hDC, XLOG2DEV(x2), YLOG2DEV(y2)); - + (void)MoveToEx(GetHdc(), XLOG2DEV(x1), YLOG2DEV(y1), NULL); + (void)LineTo(GetHdc(), XLOG2DEV(x2), YLOG2DEV(y2)); + /* MATTHEW: [6] New normalization */ #if WX_STANDARD_GRAPHICS - (void)LineTo((HDC) m_hDC, XLOG2DEV(x2) + 1, YLOG2DEV(y2)); + (void)LineTo(GetHdc(), XLOG2DEV(x2) + 1, YLOG2DEV(y2)); #endif - + CalcBoundingBox(x1, y1); CalcBoundingBox(x2, y2); } -void wxDC::DrawArc(long x1,long y1,long x2,long y2, long xc, long yc) +void wxDC::DoDrawArc(long x1,long y1,long x2,long y2, long xc, long yc) { - double dx = xc-x1 ; - double dy = yc-y1 ; + double dx = xc-x1; + double dy = yc-y1; double radius = (double)sqrt(dx*dx+dy*dy) ;; if (x1==x2 && x2==y2) { - DrawEllipse(xc,yc,(long)(radius*2.0),(long)(radius*2.0)) ; - return ; + DrawEllipse(xc,yc,(long)(radius*2.0),(long)(radius*2.0)); + return; } - - long xx1 = XLOG2DEV(x1) ; - long yy1 = YLOG2DEV(y1) ; - long xx2 = XLOG2DEV(x2) ; - long yy2 = YLOG2DEV(y2) ; - long xxc = XLOG2DEV(xc) ; - long yyc = YLOG2DEV(yc) ; - long ray = (long) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1))) ; - - (void)MoveToEx((HDC) m_hDC, (int) xx1, (int) yy1, NULL); + + long xx1 = XLOG2DEV(x1); + long yy1 = YLOG2DEV(y1); + long xx2 = XLOG2DEV(x2); + long yy2 = YLOG2DEV(y2); + long xxc = XLOG2DEV(xc); + long yyc = YLOG2DEV(yc); + long ray = (long) sqrt(double((xxc-xx1)*(xxc-xx1)+(yyc-yy1)*(yyc-yy1))); + + (void)MoveToEx(GetHdc(), (int) xx1, (int) yy1, NULL); long xxx1 = (long) (xxc-ray); long yyy1 = (long) (yyc-ray); long xxx2 = (long) (xxc+ray); @@ -403,31 +374,31 @@ void wxDC::DrawArc(long x1,long y1,long x2,long y2, long xc, long yc) // Unfortunately this is not a reliable method, depends // on the size of shape. // TODO: figure out why this happens! - Pie((HDC) m_hDC,xxx1,yyy1,xxx2+1,yyy2+1, - xx1,yy1,xx2,yy2) ; + Pie(GetHdc(),xxx1,yyy1,xxx2+1,yyy2+1, + xx1,yy1,xx2,yy2); } else - Arc((HDC) m_hDC,xxx1,yyy1,xxx2,yyy2, - xx1,yy1,xx2,yy2) ; - + Arc(GetHdc(),xxx1,yyy1,xxx2,yyy2, + xx1,yy1,xx2,yy2); + CalcBoundingBox((xc-radius), (yc-radius)); CalcBoundingBox((xc+radius), (yc+radius)); } -void wxDC::DrawPoint(long x, long y) +void wxDC::DoDrawPoint(long x, long y) { COLORREF color = 0x00ffffff; if (m_pen.Ok()) { - color = m_pen.GetColour().GetPixel() ; + color = m_pen.GetColour().GetPixel(); } - - SetPixel((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), color); - + + SetPixel(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), color); + CalcBoundingBox(x, y); } -void wxDC::DrawPolygon(int n, wxPoint points[], long xoffset, long yoffset,int fillStyle) +void wxDC::DoDrawPolygon(int n, wxPoint points[], long xoffset, long yoffset,int fillStyle) { // Do things less efficiently if we have offsets if (xoffset != 0 || yoffset != 0) @@ -438,12 +409,12 @@ void wxDC::DrawPolygon(int n, wxPoint points[], long xoffset, long yoffset,int f { cpoints[i].x = (int)(points[i].x + xoffset); cpoints[i].y = (int)(points[i].y + yoffset); - + CalcBoundingBox(cpoints[i].x, cpoints[i].y); } - int prev = SetPolyFillMode((HDC) m_hDC,fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING) ; - (void)Polygon((HDC) m_hDC, cpoints, n); - SetPolyFillMode((HDC) m_hDC,prev) ; + int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); + (void)Polygon(GetHdc(), cpoints, n); + SetPolyFillMode(GetHdc(),prev); delete[] cpoints; } else @@ -451,14 +422,14 @@ void wxDC::DrawPolygon(int n, wxPoint points[], long xoffset, long yoffset,int f int i; for (i = 0; i < n; i++) CalcBoundingBox(points[i].x, points[i].y); - - int prev = SetPolyFillMode((HDC) m_hDC,fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING) ; - (void)Polygon((HDC) m_hDC, (POINT*) points, n); - SetPolyFillMode((HDC) m_hDC,prev) ; + + int prev = SetPolyFillMode(GetHdc(),fillStyle==wxODDEVEN_RULE?ALTERNATE:WINDING); + (void)Polygon(GetHdc(), (POINT*) points, n); + SetPolyFillMode(GetHdc(),prev); } } -void wxDC::DrawLines(int n, wxPoint points[], long xoffset, long yoffset) +void wxDC::DoDrawLines(int n, wxPoint points[], long xoffset, long yoffset) { // Do things less efficiently if we have offsets if (xoffset != 0 || yoffset != 0) @@ -469,10 +440,10 @@ void wxDC::DrawLines(int n, wxPoint points[], long xoffset, long yoffset) { cpoints[i].x = (int)(points[i].x + xoffset); cpoints[i].y = (int)(points[i].y + yoffset); - + CalcBoundingBox(cpoints[i].x, cpoints[i].y); } - (void)Polyline((HDC) m_hDC, cpoints, n); + (void)Polyline(GetHdc(), cpoints, n); delete[] cpoints; } else @@ -480,60 +451,60 @@ void wxDC::DrawLines(int n, wxPoint points[], long xoffset, long yoffset) int i; for (i = 0; i < n; i++) CalcBoundingBox(points[i].x, points[i].y); - - (void)Polyline((HDC) m_hDC, (POINT*) points, n); + + (void)Polyline(GetHdc(), (POINT*) points, n); } } -void wxDC::DrawRectangle(long x, long y, long width, long height) +void wxDC::DoDrawRectangle(long x, long y, long width, long height) { long x2 = x + width; long y2 = y + height; - + /* MATTHEW: [6] new normalization */ #if WX_STANDARD_GRAPHICS bool do_brush, do_pen; - + do_brush = m_brush.Ok() && m_brush.GetStyle() != wxTRANSPARENT; do_pen = m_pen.Ok() && m_pen.GetStyle() != wxTRANSPARENT; - + if (do_brush) { HPEN orig_pen = NULL; - + if (do_pen || !m_pen.Ok()) - orig_pen = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN) ::GetStockObject(NULL_PEN)); - - (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), + orig_pen = (HPEN) ::SelectObject(GetHdc(), (HPEN) ::GetStockObject(NULL_PEN)); + + (void)Rectangle(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2) + 1, YLOG2DEV(y2) + 1); - + if (do_pen || !m_pen.Ok()) - ::SelectObject((HDC) m_hDC , orig_pen); + ::SelectObject(GetHdc() , orig_pen); } if (do_pen) { HBRUSH orig_brush = NULL; - + if (do_brush || !m_brush.Ok()) - orig_brush = (HBRUSH) ::SelectObject((HDC) m_hDC, (HBRUSH) ::GetStockObject(NULL_BRUSH)); - - (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), + orig_brush = (HBRUSH) ::SelectObject(GetHdc(), (HBRUSH) ::GetStockObject(NULL_BRUSH)); + + (void)Rectangle(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); - + if (do_brush || !m_brush.Ok()) - ::SelectObject((HDC) m_hDC, orig_brush); + ::SelectObject(GetHdc(), orig_brush); } #else - (void)Rectangle((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); + (void)Rectangle(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); #endif - + CalcBoundingBox(x, y); CalcBoundingBox(x2, y2); } -void wxDC::DrawRoundedRectangle(long x, long y, long width, long height, double radius) +void wxDC::DoDrawRoundedRectangle(long x, long y, long width, long height, double radius) { // Now, a negative radius value is interpreted to mean // 'the proportion of the smallest X or Y dimension' - + if (radius < 0.0) { double smallest = 0.0; @@ -543,34 +514,34 @@ void wxDC::DrawRoundedRectangle(long x, long y, long width, long height, double smallest = height; radius = (- radius * smallest); } - + long x2 = (x+width); long y2 = (y+height); - - (void)RoundRect((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), + + (void)RoundRect(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2), 2*XLOG2DEV(radius), 2*YLOG2DEV(radius)); - + CalcBoundingBox(x, y); CalcBoundingBox(x2, y2); } -void wxDC::DrawEllipse(long x, long y, long width, long height) +void wxDC::DoDrawEllipse(long x, long y, long width, long height) { long x2 = (x+width); long y2 = (y+height); - - (void)Ellipse((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); - + + (void)Ellipse(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2)); + CalcBoundingBox(x, y); CalcBoundingBox(x2, y2); } // Chris Breeze 20/5/98: first implementation of DrawEllipticArc on Windows -void wxDC::DrawEllipticArc(long x,long y,long w,long h,double sa,double ea) +void wxDC::DoDrawEllipticArc(long x,long y,long w,long h,double sa,double ea) { long x2 = (x+w); long y2 = (y+h); - + const double deg2rad = 3.14159265359 / 180.0; int rx1 = XLOG2DEV(x+w/2); int ry1 = YLOG2DEV(y+h/2); @@ -580,51 +551,51 @@ void wxDC::DrawEllipticArc(long x,long y,long w,long h,double sa,double ea) ry1 -= (int)(100.0 * abs(h) * m_signY * sin(sa * deg2rad)); rx2 += (int)(100.0 * abs(w) * cos(ea * deg2rad)); ry2 -= (int)(100.0 * abs(h) * m_signY * sin(ea * deg2rad)); - + // draw pie with NULL_PEN first and then outline otherwise a line is // drawn from the start and end points to the centre - HPEN orig_pen = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN) ::GetStockObject(NULL_PEN)); + HPEN orig_pen = (HPEN) ::SelectObject(GetHdc(), (HPEN) ::GetStockObject(NULL_PEN)); if (m_signY > 0) { - (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2)+1, YLOG2DEV(y2)+1, + (void)Pie(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2)+1, YLOG2DEV(y2)+1, rx1, ry1, rx2, ry2); } else { - (void)Pie((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y)-1, XLOG2DEV(x2)+1, YLOG2DEV(y2), + (void)Pie(GetHdc(), XLOG2DEV(x), YLOG2DEV(y)-1, XLOG2DEV(x2)+1, YLOG2DEV(y2), rx1, ry1-1, rx2, ry2-1); } - ::SelectObject((HDC) m_hDC, orig_pen); - (void)Arc((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2), + ::SelectObject(GetHdc(), orig_pen); + (void)Arc(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), XLOG2DEV(x2), YLOG2DEV(y2), rx1, ry1, rx2, ry2); - + CalcBoundingBox(x, y); CalcBoundingBox(x2, y2); } -void wxDC::DrawIcon(const wxIcon& icon, long x, long y) +void wxDC::DoDrawIcon(const wxIcon& icon, long x, long y) { #if defined(__WIN32__) && !defined(__SC__) && !defined(__TWIN32__) - ::DrawIconEx((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON(), + ::DrawIconEx(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON(), icon.GetWidth(), icon.GetHeight(), 0, 0, DI_NORMAL); #else - ::DrawIcon((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON()); + ::DrawIcon(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), (HICON) icon.GetHICON()); #endif - + CalcBoundingBox(x, y); CalcBoundingBox(x+icon.GetWidth(), y+icon.GetHeight()); } -void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) +void wxDC::DoDrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) { if (!bmp.Ok()) return; - + // If we're not drawing transparently, and not drawing to a printer, // optimize this function to use Windows functions. if (!useMask && !IsKindOf(CLASSINFO(wxPrinterDC))) { - HDC cdc = (HDC)m_hDC; + HDC cdc = GetHdc(); HDC memdc = ::CreateCompatibleDC( cdc ); HBITMAP hbitmap = (HBITMAP) bmp.GetHBITMAP( ); ::SelectObject( memdc, hbitmap ); @@ -637,7 +608,7 @@ void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) // Rather than reproduce wxDC::Blit, let's do it at the wxWin API level wxMemoryDC memDC; memDC.SelectObject(bmp); - + /* Not sure if we need this. The mask should leave the * masked areas as per the original background of this DC. */ @@ -647,38 +618,105 @@ void wxDC::DrawBitmap( const wxBitmap &bmp, long x, long y, bool useMask ) memDC.SetBackground(* GetBackground()); memDC.Clear(); */ - + Blit(x, y, bmp.GetWidth(), bmp.GetHeight(), & memDC, 0, 0, wxCOPY, useMask); - + memDC.SelectObject(wxNullBitmap); } } +void wxDC::DoDrawText(const wxString& text, long x, long y) +{ + if (m_textForegroundColour.Ok()) + SetTextColor(GetHdc(), m_textForegroundColour.GetPixel() ); + + DWORD old_background = 0; + if (m_textBackgroundColour.Ok()) + { + old_background = SetBkColor(GetHdc(), m_textBackgroundColour.GetPixel() ); + } + + if (m_backgroundMode == wxTRANSPARENT) + SetBkMode(GetHdc(), TRANSPARENT); + else + SetBkMode(GetHdc(), OPAQUE); + + (void)TextOut(GetHdc(), XLOG2DEV(x), YLOG2DEV(y), (char *) (const char *)text, strlen((const char *)text)); + + if (m_textBackgroundColour.Ok()) + (void)SetBkColor(GetHdc(), old_background); + + CalcBoundingBox(x, y); + + long w, h; + GetTextExtent(text, &w, &h); + CalcBoundingBox((x + w), (y + h)); +} + +// --------------------------------------------------------------------------- +// set GDI objects +// --------------------------------------------------------------------------- + +void wxDC::SetPalette(const wxPalette& palette) +{ + // Set the old object temporarily, in case the assignment deletes an object + // that's not yet selected out. + if (m_oldPalette) + { + ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, TRUE); + m_oldPalette = 0; + } + + m_palette = palette; + + if (!m_palette.Ok()) + { + // Setting a NULL colourmap is a way of restoring + // the original colourmap + if (m_oldPalette) + { + ::SelectPalette(GetHdc(), (HPALETTE) m_oldPalette, TRUE); + m_oldPalette = 0; + } + + return; + } + + if (m_palette.Ok() && m_palette.GetHPALETTE()) + { + HPALETTE oldPal = ::SelectPalette(GetHdc(), (HPALETTE) m_palette.GetHPALETTE(), TRUE); + if (!m_oldPalette) + m_oldPalette = (WXHPALETTE) oldPal; + + ::RealizePalette(GetHdc()); + } +} + void wxDC::SetFont(const wxFont& the_font) { // Set the old object temporarily, in case the assignment deletes an object // that's not yet selected out. if (m_oldFont) { - ::SelectObject((HDC) m_hDC, (HFONT) m_oldFont); + ::SelectObject(GetHdc(), (HFONT) m_oldFont); m_oldFont = 0; } - + m_font = the_font; - + if (!the_font.Ok()) { if (m_oldFont) - ::SelectObject((HDC) m_hDC, (HFONT) m_oldFont); - m_oldFont = 0 ; + ::SelectObject(GetHdc(), (HFONT) m_oldFont); + m_oldFont = 0; } - + if (m_font.Ok() && m_font.GetResourceHandle()) { - HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle()); + HFONT f = (HFONT) ::SelectObject(GetHdc(), (HFONT) m_font.GetResourceHandle()); if (f == (HFONT) NULL) { - wxDebugMsg("::SelectObject failed in wxDC::SetFont."); + wxLogDebug("::SelectObject failed in wxDC::SetFont."); } if (!m_oldFont) m_oldFont = (WXHFONT) f; @@ -691,24 +729,24 @@ void wxDC::SetPen(const wxPen& pen) // that's not yet selected out. if (m_oldPen) { - ::SelectObject((HDC) m_hDC, (HPEN) m_oldPen); + ::SelectObject(GetHdc(), (HPEN) m_oldPen); m_oldPen = 0; } - + m_pen = pen; - + if (!m_pen.Ok()) { if (m_oldPen) - ::SelectObject((HDC) m_hDC, (HPEN) m_oldPen); - m_oldPen = 0 ; + ::SelectObject(GetHdc(), (HPEN) m_oldPen); + m_oldPen = 0; } - + if (m_pen.Ok()) { if (m_pen.GetResourceHandle()) { - HPEN p = (HPEN) ::SelectObject((HDC) m_hDC, (HPEN)m_pen.GetResourceHandle()) ; + HPEN p = (HPEN) ::SelectObject(GetHdc(), (HPEN)m_pen.GetResourceHandle()); if (!m_oldPen) m_oldPen = (WXHPEN) p; } @@ -721,76 +759,38 @@ void wxDC::SetBrush(const wxBrush& brush) // that's not yet selected out. if (m_oldBrush) { - ::SelectObject((HDC) m_hDC, (HBRUSH) m_oldBrush); + ::SelectObject(GetHdc(), (HBRUSH) m_oldBrush); m_oldBrush = 0; } - + m_brush = brush; - + if (!m_brush.Ok()) { if (m_oldBrush) - ::SelectObject((HDC) m_hDC, (HBRUSH) m_oldBrush); - m_oldBrush = 0 ; + ::SelectObject(GetHdc(), (HBRUSH) m_oldBrush); + m_oldBrush = 0; } - + if (m_brush.Ok()) { if (m_brush.GetResourceHandle()) { HBRUSH b = 0; - b = (HBRUSH) ::SelectObject((HDC) m_hDC, (HBRUSH)m_brush.GetResourceHandle()) ; + b = (HBRUSH) ::SelectObject(GetHdc(), (HBRUSH)m_brush.GetResourceHandle()); if (!m_oldBrush) m_oldBrush = (WXHBRUSH) b; } } } -void wxDC::DrawText(const wxString& text, long x, long y, bool use16bit) -{ - // Should be unnecessary: SetFont should have done this already. -#if 0 - if (m_font.Ok() && m_font.GetResourceHandle()) - { - HFONT f = (HFONT) ::SelectObject((HDC) m_hDC, (HFONT) m_font.GetResourceHandle()); - if (!m_oldFont) - m_oldFont = (WXHFONT) f; - } -#endif - - if (m_textForegroundColour.Ok()) - SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ; - - DWORD old_background = 0; - if (m_textBackgroundColour.Ok()) - { - old_background = SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ; - } - - if (m_backgroundMode == wxTRANSPARENT) - SetBkMode((HDC) m_hDC, TRANSPARENT); - else - SetBkMode((HDC) m_hDC, OPAQUE); - - (void)TextOut((HDC) m_hDC, XLOG2DEV(x), YLOG2DEV(y), (char *) (const char *)text, strlen((const char *)text)); - - if (m_textBackgroundColour.Ok()) - (void)SetBkColor((HDC) m_hDC, old_background); - - CalcBoundingBox(x, y); - - long w, h; - GetTextExtent(text, &w, &h); - CalcBoundingBox((x + w), (y + h)); -} - void wxDC::SetBackground(const wxBrush& brush) { m_backgroundBrush = brush; - + if (!m_backgroundBrush.Ok()) return; - + if (m_canvas) { bool customColours = TRUE; @@ -798,7 +798,7 @@ void wxDC::SetBackground(const wxBrush& brush) // change background colours from the control-panel specified colours. if (m_canvas->IsKindOf(CLASSINFO(wxWindow)) && ((m_canvas->GetWindowStyleFlag() & wxUSER_COLOURS) != wxUSER_COLOURS)) customColours = FALSE; - + if (customColours) { if (m_backgroundBrush.GetStyle()==wxTRANSPARENT) @@ -819,26 +819,26 @@ void wxDC::SetBackground(const wxBrush& brush) } } } - COLORREF new_color = m_backgroundBrush.GetColour().GetPixel() ; + COLORREF new_color = m_backgroundBrush.GetColour().GetPixel(); { - (void)SetBkColor((HDC) m_hDC, new_color); + (void)SetBkColor(GetHdc(), new_color); } } void wxDC::SetBackgroundMode(int mode) { m_backgroundMode = mode; - + if (m_backgroundMode == wxTRANSPARENT) - ::SetBkMode((HDC) m_hDC, TRANSPARENT); + ::SetBkMode(GetHdc(), TRANSPARENT); else - ::SetBkMode((HDC) m_hDC, OPAQUE); + ::SetBkMode(GetHdc(), OPAQUE); } void wxDC::SetLogicalFunction(int function) { m_logicalFunction = function; - + SetRop((WXHDC) m_hDC); } @@ -846,7 +846,7 @@ void wxDC::SetRop(WXHDC dc) { if (!dc || m_logicalFunction < 0) return; - + int c_rop; // These may be wrong switch (m_logicalFunction) @@ -878,49 +878,54 @@ bool wxDC::StartDoc(const wxString& message) return TRUE; } -void wxDC::EndDoc(void) +void wxDC::EndDoc() { } -void wxDC::StartPage(void) +void wxDC::StartPage() { } -void wxDC::EndPage(void) +void wxDC::EndPage() { } -long wxDC::GetCharHeight(void) const +// --------------------------------------------------------------------------- +// text metrics +// --------------------------------------------------------------------------- + +long wxDC::GetCharHeight() const { TEXTMETRIC lpTextMetric; - - GetTextMetrics((HDC) m_hDC, &lpTextMetric); - + + GetTextMetrics(GetHdc(), &lpTextMetric); + return YDEV2LOGREL(lpTextMetric.tmHeight); } -long wxDC::GetCharWidth(void) const +long wxDC::GetCharWidth() const { TEXTMETRIC lpTextMetric; - - GetTextMetrics((HDC) m_hDC, &lpTextMetric); - + + GetTextMetrics(GetHdc(), &lpTextMetric); + return XDEV2LOGREL(lpTextMetric.tmAveCharWidth); } void wxDC::GetTextExtent(const wxString& string, long *x, long *y, - long *descent, long *externalLeading, wxFont *theFont, bool use16bit) const + long *descent, long *externalLeading, + wxFont *theFont) const { wxFont *fontToUse = (wxFont*) theFont; if (!fontToUse) fontToUse = (wxFont*) &m_font; - + SIZE sizeRect; TEXTMETRIC tm; - - GetTextExtentPoint((HDC) m_hDC, (char *)(const char *) string, strlen((char *)(const char *) string), &sizeRect); - GetTextMetrics((HDC) m_hDC, &tm); - + + GetTextExtentPoint(GetHdc(), (char *)(const char *) string, strlen((char *)(const char *) string), &sizeRect); + GetTextMetrics(GetHdc(), &tm); + if (x) *x = XDEV2LOGREL(sizeRect.cx); if (y) *y = YDEV2LOGREL(sizeRect.cy); if (descent) *descent = tm.tmDescent; @@ -930,25 +935,25 @@ void wxDC::GetTextExtent(const wxString& string, long *x, long *y, void wxDC::SetMapMode(int mode) { m_mappingMode = mode; - + int pixel_width = 0; int pixel_height = 0; int mm_width = 0; int mm_height = 0; - - pixel_width = GetDeviceCaps((HDC) m_hDC, HORZRES); - pixel_height = GetDeviceCaps((HDC) m_hDC, VERTRES); - mm_width = GetDeviceCaps((HDC) m_hDC, HORZSIZE); - mm_height = GetDeviceCaps((HDC) m_hDC, VERTSIZE); - + + pixel_width = GetDeviceCaps(GetHdc(), HORZRES); + pixel_height = GetDeviceCaps(GetHdc(), VERTRES); + mm_width = GetDeviceCaps(GetHdc(), HORZSIZE); + mm_height = GetDeviceCaps(GetHdc(), VERTSIZE); + if ((pixel_width == 0) || (pixel_height == 0) || (mm_width == 0) || (mm_height == 0)) { return; } - + double mm2pixelsX = pixel_width/mm_width; double mm2pixelsY = pixel_height/mm_height; - + switch (mode) { case wxMM_TWIPS: @@ -983,23 +988,23 @@ void wxDC::SetMapMode(int mode) break; } } - - if (::GetMapMode((HDC) m_hDC) != MM_ANISOTROPIC) - ::SetMapMode((HDC) m_hDC, MM_ANISOTROPIC); - - SetViewportExtEx((HDC) m_hDC, VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); + + if (::GetMapMode(GetHdc()) != MM_ANISOTROPIC) + ::SetMapMode(GetHdc(), MM_ANISOTROPIC); + + SetViewportExtEx(GetHdc(), VIEWPORT_EXTENT, VIEWPORT_EXTENT, NULL); m_windowExtX = (int)MS_XDEV2LOGREL(VIEWPORT_EXTENT); m_windowExtY = (int)MS_YDEV2LOGREL(VIEWPORT_EXTENT); - ::SetWindowExtEx((HDC) m_hDC, m_windowExtX, m_windowExtY, NULL); - ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); - ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); + ::SetWindowExtEx(GetHdc(), m_windowExtX, m_windowExtY, NULL); + ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); + ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); } void wxDC::SetUserScale(double x, double y) { m_userScaleX = x; m_userScaleY = y; - + SetMapMode(m_mappingMode); } @@ -1007,15 +1012,15 @@ void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp) { m_signX = xLeftRight ? 1 : -1; m_signY = yBottomUp ? -1 : 1; - + SetMapMode(m_mappingMode); } void wxDC::SetSystemScale(double x, double y) { - m_systemScaleX = x; - m_systemScaleY = y; - + m_scaleX = x; + m_scaleY = y; + SetMapMode(m_mappingMode); } @@ -1023,131 +1028,86 @@ void wxDC::SetLogicalOrigin(long x, long y) { m_logicalOriginX = x; m_logicalOriginY = y; - - ::SetWindowOrgEx((HDC) m_hDC, (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); + + ::SetWindowOrgEx(GetHdc(), (int)m_logicalOriginX, (int)m_logicalOriginY, NULL); } void wxDC::SetDeviceOrigin(long x, long y) { m_deviceOriginX = x; m_deviceOriginY = y; - - ::SetViewportOrgEx((HDC) m_hDC, (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); -} - -long wxDC::DeviceToLogicalX(long x) const -{ - return (long) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX) - m_logicalOriginX) ; -} -long wxDC::DeviceToLogicalXRel(long x) const -{ - return (long) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX)) ; + ::SetViewportOrgEx(GetHdc(), (int)m_deviceOriginX, (int)m_deviceOriginY, NULL); } -long wxDC::DeviceToLogicalY(long y) const -{ - return (long) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY) - m_logicalOriginY) ; -} +// --------------------------------------------------------------------------- +// coordinates transformations +// --------------------------------------------------------------------------- -long wxDC::DeviceToLogicalYRel(long y) const +long wxDCBase::DeviceToLogicalX(long x) const { - return (long) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY)) ; + return (long) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX); } -long wxDC::LogicalToDeviceX(long x) const +long wxDCBase::DeviceToLogicalXRel(long x) const { - return (long) (floor((x) - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX + m_deviceOriginX) ; + return (long) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX)); } -long wxDC::LogicalToDeviceXRel(long x) const -{ - return (long) (floor(x)*m_logicalScaleX*m_userScaleX*m_signX*m_systemScaleX) ; -} - -long wxDC::LogicalToDeviceY(long y) const -{ - return (long) (floor((y) - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY + m_deviceOriginY); -} - -long wxDC::LogicalToDeviceYRel(long y) const -{ - return (long) (floor(y)*m_logicalScaleY*m_userScaleY*m_signY*m_systemScaleY) ; -} - -// This group of functions may not do any conversion -// if m_scaleGDI is TRUE, since the HDC does the -// conversion automatically. - -long wxDC::ImplDeviceToLogicalX(long x) const +long wxDCBase::DeviceToLogicalY(long y) const { - // return (m_scaleGDI ? x : DeviceToLogicalX(x)); - return x; + return (long) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY); } -long wxDC::ImplDeviceToLogicalY(long y) const +long wxDCBase::DeviceToLogicalYRel(long y) const { - // return (m_scaleGDI ? y : DeviceToLogicalY(y)); - return y; + return (long) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY)); } -long wxDC::ImplDeviceToLogicalXRel(long x) const +long wxDCBase::LogicalToDeviceX(long x) const { - // return (m_scaleGDI ? x : DeviceToLogicalXRel(x)); - return x; + return (long) (floor((x) - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX); } -long wxDC::ImplDeviceToLogicalYRel(long y) const +long wxDCBase::LogicalToDeviceXRel(long x) const { - // return (m_scaleGDI ? y : DeviceToLogicalYRel(y)); - return y; + return (long) (floor(x)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX); } -long wxDC::ImplLogicalToDeviceX(long x) const +long wxDCBase::LogicalToDeviceY(long y) const { - // return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceX(x)); - return x; + return (long) (floor((y) - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY); } -long wxDC::ImplLogicalToDeviceY(long y) const +long wxDCBase::LogicalToDeviceYRel(long y) const { - // return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceY(y)); - return y; + return (long) (floor(y)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY); } -long wxDC::ImplLogicalToDeviceXRel(long x) const -{ - // return (m_scaleGDI ? (floor(double(x))) : LogicalToDeviceXRel(x)); - return x; -} - -long wxDC::ImplLogicalToDeviceYRel(long y) const -{ - // return (m_scaleGDI ? (floor(double(y))) : LogicalToDeviceYRel(y)); - return y; -} - -bool wxDC::Blit(long xdest, long ydest, long width, long height, - wxDC *source, long xsrc, long ysrc, int rop, bool useMask) +// --------------------------------------------------------------------------- +// bit blit +// --------------------------------------------------------------------------- +bool wxDC::DoBlit(long xdest, long ydest, long width, long height, + wxDC *source, long xsrc, long ysrc, int rop, bool useMask) { long xdest1 = xdest; long ydest1 = ydest; long xsrc1 = xsrc; long ysrc1 = ysrc; - + // Chris Breeze 18/5/98: use text foreground/background colours // when blitting from 1-bit bitmaps - COLORREF old_textground = ::GetTextColor((HDC)m_hDC); - COLORREF old_background = ::GetBkColor((HDC)m_hDC); + COLORREF old_textground = ::GetTextColor(GetHdc()); + COLORREF old_background = ::GetBkColor(GetHdc()); if (m_textForegroundColour.Ok()) { - ::SetTextColor((HDC) m_hDC, m_textForegroundColour.GetPixel() ) ; + ::SetTextColor(GetHdc(), m_textForegroundColour.GetPixel() ); } if (m_textBackgroundColour.Ok()) { - ::SetBkColor((HDC) m_hDC, m_textBackgroundColour.GetPixel() ) ; + ::SetBkColor(GetHdc(), m_textBackgroundColour.GetPixel() ); } - + DWORD dwRop = rop == wxCOPY ? SRCCOPY : rop == wxCLEAR ? WHITENESS : rop == wxSET ? BLACKNESS : @@ -1161,14 +1121,14 @@ bool wxDC::Blit(long xdest, long ydest, long width, long height, rop == wxSRC_OR ? SRCPAINT : rop == wxSRC_AND ? SRCAND : SRCCOPY; - + bool success = TRUE; if (useMask && source->m_selectedBitmap.Ok() && source->m_selectedBitmap.GetMask()) { - + #if 0 // __WIN32__ // Not implemented under Win95 (or maybe a specific device?) - if (MaskBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, + if (MaskBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC, xsrc1, ysrc1, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap(), 0, 0, 0xAACC0020)) { @@ -1181,16 +1141,16 @@ bool wxDC::Blit(long xdest, long ydest, long width, long height, #if 0 HDC dc_mask = CreateCompatibleDC((HDC) source->m_hDC); ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); - success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, + success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, dc_mask, xsrc1, ysrc1, 0x00220326 /* NOTSRCAND */) != 0); - success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, + success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC, xsrc1, ysrc1, SRCPAINT) != 0); ::SelectObject(dc_mask, 0); ::DeleteDC(dc_mask); #endif // New code from Chris Breeze, 15/7/98 // Blit bitmap with mask - + if (IsKindOf(CLASSINFO(wxPrinterDC))) { // If we are printing source colours are screen colours @@ -1199,7 +1159,7 @@ bool wxDC::Blit(long xdest, long ydest, long width, long height, RECT rect; HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC); HDC dc_src = (HDC) source->m_hDC; - + ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); for (int x = 0; x < width; x++) { @@ -1211,7 +1171,7 @@ bool wxDC::Blit(long xdest, long ydest, long width, long height, HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y)); rect.left = xdest1 + x; rect.right = rect.left + 1; rect.top = ydest1 + y; rect.bottom = rect.top + 1; - ::FillRect((HDC) m_hDC, &rect, brush); + ::FillRect(GetHdc(), &rect, brush); ::DeleteObject(brush); } } @@ -1223,37 +1183,37 @@ bool wxDC::Blit(long xdest, long ydest, long width, long height, { // create a temp buffer bitmap and DCs to access it and the mask HDC dc_mask = ::CreateCompatibleDC((HDC) source->m_hDC); - HDC dc_buffer = ::CreateCompatibleDC((HDC) m_hDC); - HBITMAP buffer_bmap = ::CreateCompatibleBitmap((HDC) m_hDC, width, height); + HDC dc_buffer = ::CreateCompatibleDC(GetHdc()); + HBITMAP buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height); ::SelectObject(dc_mask, (HBITMAP) source->m_selectedBitmap.GetMask()->GetMaskBitmap()); ::SelectObject(dc_buffer, buffer_bmap); - + // copy dest to buffer ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, - (HDC) m_hDC, xdest1, ydest1, SRCCOPY); - + GetHdc(), xdest1, ydest1, SRCCOPY); + // copy src to buffer using selected raster op ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, (HDC) source->m_hDC, xsrc1, ysrc1, dwRop); - + // set masked area in buffer to BLACK (pixel value 0) - COLORREF prevBkCol = ::SetBkColor((HDC) m_hDC, RGB(255, 255, 255)); - COLORREF prevCol = ::SetTextColor((HDC) m_hDC, RGB(0, 0, 0)); + COLORREF prevBkCol = ::SetBkColor(GetHdc(), RGB(255, 255, 255)); + COLORREF prevCol = ::SetTextColor(GetHdc(), RGB(0, 0, 0)); ::BitBlt(dc_buffer, 0, 0, (int)width, (int)height, dc_mask, xsrc1, ysrc1, SRCAND); - + // set unmasked area in dest to BLACK - ::SetBkColor((HDC) m_hDC, RGB(0, 0, 0)); - ::SetTextColor((HDC) m_hDC, RGB(255, 255, 255)); - ::BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, + ::SetBkColor(GetHdc(), RGB(0, 0, 0)); + ::SetTextColor(GetHdc(), RGB(255, 255, 255)); + ::BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, dc_mask, xsrc1, ysrc1, SRCAND); - ::SetBkColor((HDC) m_hDC, prevBkCol); // restore colours to original values - ::SetTextColor((HDC) m_hDC, prevCol); - + ::SetBkColor(GetHdc(), prevBkCol); // restore colours to original values + ::SetTextColor(GetHdc(), prevCol); + // OR buffer to dest - success = (::BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, + success = (::BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, dc_buffer, 0, 0, SRCPAINT) != 0); - + // tidy up temporary DCs and bitmap ::SelectObject(dc_mask, 0); ::DeleteDC(dc_mask); @@ -1279,85 +1239,41 @@ bool wxDC::Blit(long xdest, long ydest, long width, long height, HBRUSH brush = ::CreateSolidBrush(::GetPixel(dc_src, x, y)); rect.left = xdest1 + x; rect.right = rect.left + 1; rect.top = ydest1 + y; rect.bottom = rect.top + 1; - ::FillRect((HDC) m_hDC, &rect, brush); + ::FillRect(GetHdc(), &rect, brush); ::DeleteObject(brush); } } } else { - success = (BitBlt((HDC) m_hDC, xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC, + success = (BitBlt(GetHdc(), xdest1, ydest1, (int)width, (int)height, (HDC) source->m_hDC, xsrc1, ysrc1, dwRop) != 0); } } - ::SetTextColor((HDC)m_hDC, old_textground); - ::SetBkColor((HDC)m_hDC, old_background); - - return success; -} + ::SetTextColor(GetHdc(), old_textground); + ::SetBkColor(GetHdc(), old_background); -void wxDC::GetSize(int* width, int* height) const -{ - long w=::GetDeviceCaps((HDC) m_hDC,HORZRES); - long h=::GetDeviceCaps((HDC) m_hDC,VERTRES); - *width = w; - *height = h; + return success; } -void wxDC::GetSizeMM(int *width, int *height) const +void wxDC::DoGetSize(int *w, int *h) const { - int w=::GetDeviceCaps((HDC) m_hDC,HORZSIZE); - int h=::GetDeviceCaps((HDC) m_hDC,VERTSIZE); - *width = w; - *height = h; + if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZRES); + if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTRES); } -// Resolution in Pixels per inch -wxSize wxDC::GetPPI(void) const +void wxDC::DoGetSizeMM(int *w, int *h) const { - int x=::GetDeviceCaps((HDC) m_hDC,LOGPIXELSX); - int y=::GetDeviceCaps((HDC) m_hDC,LOGPIXELSY); - return wxSize(x, y); + if ( w ) *w = ::GetDeviceCaps(GetHdc(), HORZSIZE); + if ( h ) *h = ::GetDeviceCaps(GetHdc(), VERTSIZE); } -void wxDC::DrawPolygon(wxList *list, long xoffset, long yoffset,int fillStyle) +wxSize wxDC::GetPPI() const { - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for(wxNode *node = list->First(); node; node = node->Next()) { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - } - DrawPolygon(n, points, xoffset, yoffset,fillStyle); - delete[] points; -} + int x = ::GetDeviceCaps(GetHdc(), LOGPIXELSX); + int y = ::GetDeviceCaps(GetHdc(), LOGPIXELSY); -void wxDC::DrawLines(wxList *list, long xoffset, long yoffset) -{ - int n = list->Number(); - wxPoint *points = new wxPoint[n]; - - int i = 0; - for(wxNode *node = list->First(); node; node = node->Next()) { - wxPoint *point = (wxPoint *)node->Data(); - points[i].x = point->x; - points[i++].y = point->y; - } - DrawLines(n, points, xoffset, yoffset); - delete []points; -} - -void wxDC::SetTextForeground(const wxColour& colour) -{ - m_textForegroundColour = colour; -} - -void wxDC::SetTextBackground(const wxColour& colour) -{ - m_textBackgroundColour = colour; + return wxSize(x, y); } // For use by wxWindows only, unless custom units are required. @@ -1367,29 +1283,8 @@ void wxDC::SetLogicalScale(double x, double y) m_logicalScaleY = y; } -void wxDC::CalcBoundingBox(long x, long y) -{ - if (x < m_minX) m_minX = x; - if (y < m_minY) m_minY = y; - if (x > m_maxX) m_maxX = x; - if (y > m_maxY) m_maxY = y; -} - -void wxDC::GetClippingBox(long *x,long *y,long *w,long *h) const -{ - if (m_clipping) - { - *x = m_clipX1 ; - *y = m_clipY1 ; - *w = (m_clipX2 - m_clipX1) ; - *h = (m_clipY2 - m_clipY1) ; - } - else - *x = *y = *w = *h = 0 ; -} - #if WXWIN_COMPATIBILITY -void wxDC::GetTextExtent(const wxString& string, float *x, float *y, +void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, float *descent, float *externalLeading, wxFont *theFont, bool use16bit) const { @@ -1403,69 +1298,30 @@ void wxDC::GetTextExtent(const wxString& string, float *x, float *y, } #endif -int wxDC::GetDepth(void) const -{ - return (int) ::GetDeviceCaps((HDC) m_hDC,BITSPIXEL); -} +// --------------------------------------------------------------------------- +// spline drawing code +// --------------------------------------------------------------------------- #if wxUSE_SPLINES -// Make a 3-point spline -void wxDC::DrawSpline(long x1, long y1, long x2, long y2, long x3, long y3) -{ - wxList *point_list = new wxList; - - wxPoint *point1 = new wxPoint; - point1->x = x1; point1->y = y1; - point_list->Append((wxObject*)point1); - - wxPoint *point2 = new wxPoint; - point2->x = x2; point2->y = y2; - point_list->Append((wxObject*)point2); - - wxPoint *point3 = new wxPoint; - point3->x = x3; point3->y = y3; - point_list->Append((wxObject*)point3); - - DrawSpline(point_list); - - for(wxNode *node = point_list->First(); node; node = node->Next()) { - wxPoint *p = (wxPoint *)node->Data(); - delete p; - } - delete point_list; -} - -////#define wx_round(a) (int)((a)+.5) -//#define wx_round(a) (a) - class wxSpline: public wxObject { public: int type; wxList *points; - + wxSpline(wxList *list); - void DeletePoints(void); - + void DeletePoints(); + // Doesn't delete points - ~wxSpline(void); + ~wxSpline(); }; -void wxDC::DrawSpline(int n, wxPoint points[]) -{ - wxList list; - int i; - for (i =0; i < n; i++) - list.Append((wxObject*)&points[i]); - DrawSpline((wxList *)&list); -} - void wx_draw_open_spline(wxDC *dc, wxSpline *spline); void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4, double b4); -void wx_clear_stack(void); +void wx_clear_stack(); int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3, double *y3, double *x4, double *y4); void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, @@ -1474,14 +1330,13 @@ static bool wx_spline_add_point(double x, double y); static void wx_spline_draw_point_array(wxDC *dc); wxSpline *wx_make_spline(int x1, int y1, int x2, int y2, int x3, int y3); -void wxDC::DrawSpline(wxList *list) +void wxDC::DoDrawSpline(wxList *list) { wxSpline spline(list); - + wx_draw_open_spline(this, &spline); } - wxList wx_spline_point_list; void wx_draw_open_spline(wxDC *dc, wxSpline *spline) @@ -1489,25 +1344,25 @@ void wx_draw_open_spline(wxDC *dc, wxSpline *spline) wxPoint *p; double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; double x1, y1, x2, y2; - + wxNode *node = spline->points->First(); p = (wxPoint *)node->Data(); - + x1 = p->x; y1 = p->y; - + node = node->Next(); p = (wxPoint *)node->Data(); - + x2 = p->x; y2 = p->y; cx1 = (double)((x1 + x2) / 2); cy1 = (double)((y1 + y2) / 2); cx2 = (double)((cx1 + x2) / 2); cy2 = (double)((cy1 + y2) / 2); - + wx_spline_add_point(x1, y1); - + while ((node = node->Next()) != NULL) { p = (wxPoint *)node->Data(); @@ -1519,37 +1374,37 @@ void wx_draw_open_spline(wxDC *dc, wxSpline *spline) cy4 = (double)(y1 + y2) / 2; cx3 = (double)(x1 + cx4) / 2; cy3 = (double)(y1 + cy4) / 2; - + wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4); - + cx1 = cx4; cy1 = cy4; cx2 = (double)(cx1 + x2) / 2; cy2 = (double)(cy1 + y2) / 2; } - + wx_spline_add_point((double)wx_round(cx1), (double)wx_round(cy1)); wx_spline_add_point(x2, y2); - + wx_spline_draw_point_array(dc); - + } /********************* CURVES FOR SPLINES ***************************** The following spline drawing routine is from - + "An Algorithm for High-Speed Curve Generation" by George Merrill Chaikin, Computer Graphics and Image Processing, 3, Academic Press, 1974, 346-349. - + and - + "On Chaikin's Algorithm" by R. F. Riesenfeld, Computer Graphics and Image Processing, 4, Academic Press, 1975, 304-310. - + ***********************************************************************/ #define half(z1, z2) ((z1+z2)/2.0) @@ -1562,10 +1417,10 @@ void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, { register double xmid, ymid; double x1, y1, x2, y2, x3, y3, x4, y4; - + wx_clear_stack(); wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4); - + while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) { xmid = (double)half(x2, x3); ymid = (double)half(y2, y3); @@ -1596,7 +1451,7 @@ static Stack wx_spline_stack[SPLINE_STACK_DEPTH]; static Stack *wx_stack_top; static int wx_stack_count; -void wx_clear_stack(void) +void wx_clear_stack() { wx_stack_top = wx_spline_stack; wx_stack_count = 0; @@ -1636,7 +1491,7 @@ int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, static bool wx_spline_add_point(double x, double y) { - wxPoint *point = new wxPoint ; + wxPoint *point = new wxPoint; point->x = (int) x; point->y = (int) y; wx_spline_point_list.Append((wxObject*)point); @@ -1661,11 +1516,11 @@ wxSpline::wxSpline(wxList *list) points = list; } -wxSpline::~wxSpline(void) +wxSpline::~wxSpline() { } -void wxSpline::DeletePoints(void) +void wxSpline::DeletePoints() { for(wxNode *node = points->First(); node; node = points->First()) { diff --git a/src/msw/dialog.cpp b/src/msw/dialog.cpp index ec5d44eae2..f58e8d9693 100644 --- a/src/msw/dialog.cpp +++ b/src/msw/dialog.cpp @@ -40,8 +40,8 @@ // Lists to keep track of windows, so we can disable/enable them // for modal dialogs -wxList wxModalDialogs; -wxList wxModelessWindows; // Frames and modeless dialogs +wxWindowList wxModalDialogs; +wxWindowList wxModelessWindows; // Frames and modeless dialogs extern wxList WXDLLEXPORT wxPendingDelete; #if !USE_SHARED_LIBRARY @@ -58,12 +58,7 @@ extern wxList WXDLLEXPORT wxPendingDelete; END_EVENT_TABLE() #endif -bool wxDialog::MSWOnClose(void) -{ - return Close(); -} - -wxDialog::wxDialog(void) +wxDialog::wxDialog() { m_isShown = FALSE; m_modalShowing = FALSE; @@ -235,7 +230,7 @@ void wxDialog::OnPaint(wxPaintEvent& event) // wxWindow::OnPaint(event); } -void wxDialog::Fit(void) +void wxDialog::Fit() { wxWindow::Fit(); } @@ -245,7 +240,7 @@ void wxDialog::Iconize(bool WXUNUSED(iconize)) // Windows dialog boxes can't be iconized } -bool wxDialog::IsIconized(void) const +bool wxDialog::IsIconized() const { return FALSE; } @@ -282,7 +277,7 @@ void wxDialog::GetPosition(int *x, int *y) const *y = rect.top; } -bool wxDialog::IsShown(void) const +bool wxDialog::IsShown() const { return m_isShown; } @@ -299,13 +294,13 @@ bool wxDialog::Show(bool show) #if WXGARBAGE_COLLECTION_ON /* MATTHEW: GC */ if (!modal) { if (show) { - if (!wxModelessWindows.Member(this)) - wxModelessWindows.Append(this); + if (!wxModelessWindows.Find(this)) + wxModelessWindows.Append(this); } else wxModelessWindows.DeleteObject(this); } if (show) { - if (!wxTopLevelWindows.Member(this)) + if (!wxTopLevelWindows.Find(this)) wxTopLevelWindows.Append(this); } else wxTopLevelWindows.DeleteObject(this); @@ -355,13 +350,13 @@ bool wxDialog::Show(bool show) EnableWindow((HWND) GetHWND(), TRUE); BringWindowToTop((HWND) GetHWND()); - if (!wxModalDialogs.Member(this)) + if ( !wxModalDialogs.Find(this) ) wxModalDialogs.Append(this); MSG msg; // Must test whether this dialog still exists: we may not process // a message before the deletion. - while (wxModalDialogs.Member(this) && m_modalShowing && GetMessage(&msg, NULL, 0, 0)) + while (wxModalDialogs.Find(this) && m_modalShowing && GetMessage(&msg, NULL, 0, 0)) { if ( m_acceleratorTable.Ok() && ::TranslateAccelerator((HWND)GetHWND(), @@ -394,7 +389,7 @@ bool wxDialog::Show(bool show) node=disabledWindows.First(); while(node) { wxWindow* win = (wxWindow*) node->Data(); - if (wxModalDialogs.Member(win) || wxModelessWindows.Member(win)) + if (wxModalDialogs.Find(win) || wxModelessWindows.Find(win)) { HWND hWnd = (HWND) win->GetHWND(); if (::IsWindow(hWnd)) @@ -480,7 +475,7 @@ void wxDialog::SetTitle(const wxString& title) SetWindowText((HWND) GetHWND(), (const char *)title); } -wxString wxDialog::GetTitle(void) const +wxString wxDialog::GetTitle() const { GetWindowText((HWND) GetHWND(), wxBuffer, 1000); return wxString(wxBuffer); @@ -516,7 +511,7 @@ void wxDialog::Centre(int direction) } // Replacement for Show(TRUE) for modal dialogs - returns return code -int wxDialog::ShowModal(void) +int wxDialog::ShowModal() { m_windowStyle |= wxDIALOG_MODAL; Show(TRUE); @@ -605,7 +600,7 @@ void wxDialog::OnCloseWindow(wxCloseEvent& event) } // Destroy the window (delayed, if a managed window) -bool wxDialog::Destroy(void) +bool wxDialog::Destroy() { if (!wxPendingDelete.Member(this)) wxPendingDelete.Append(this); @@ -616,7 +611,8 @@ void wxDialog::OnSize(wxSizeEvent& WXUNUSED(event)) { // if we're using constraints - do use them #if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) { + if ( GetAutoLayout() ) + { Layout(); } #endif diff --git a/src/msw/frame.cpp b/src/msw/frame.cpp index 5b108f17f9..459843e361 100644 --- a/src/msw/frame.cpp +++ b/src/msw/frame.cpp @@ -45,7 +45,7 @@ #include #endif -extern wxList wxModelessWindows; +extern wxWindowList wxModelessWindows; extern wxList WXDLLEXPORT wxPendingDelete; extern char wxFrameClassName[]; extern wxMenu *wxCurrentPopupMenu; @@ -552,7 +552,7 @@ void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event) * */ -void wxFrame::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title, +bool wxFrame::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title, int x, int y, int width, int height, long style) { @@ -611,12 +611,16 @@ void wxFrame::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow * extendedStyle |= WS_EX_TOPMOST; m_iconized = FALSE; - wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, - msflags, NULL, extendedStyle); + if ( !wxWindow::MSWCreate(id, parent, wclass, wx_win, title, x, y, width, height, + msflags, NULL, extendedStyle) ) + return FALSE; + // Seems to be necessary if we use WS_POPUP // style instead of WS_OVERLAPPED if (width > -1 && height > -1) ::PostMessage((HWND) GetHWND(), WM_SIZE, SIZE_RESTORED, MAKELPARAM(width, height)); + + return TRUE; } bool wxFrame::MSWOnPaint() @@ -673,60 +677,58 @@ WXHICON wxFrame::MSWOnQueryDragIcon() return m_defaultIcon; } -void wxFrame::MSWOnSize(int x, int y, WXUINT id) +bool wxFrame::MSWOnSize(int x, int y, WXUINT id) { - switch (id) - { - case SIZENORMAL: - // only do it it if we were iconized before, otherwise resizing the - // parent frame has a curious side effect of bringing it under it's - // children - if ( !m_iconized ) - break; + bool processed = FALSE; + + switch ( id ) + { + case SIZENORMAL: + // only do it it if we were iconized before, otherwise resizing the + // parent frame has a curious side effect of bringing it under it's + // children + if ( !m_iconized ) + break; - // restore all child frames too - IconizeChildFrames(FALSE); + // restore all child frames too + IconizeChildFrames(FALSE); - // fall through + // fall through - case SIZEFULLSCREEN: - m_iconized = FALSE; - break; + case SIZEFULLSCREEN: + m_iconized = FALSE; + break; - case SIZEICONIC: - // iconize all child frames too - IconizeChildFrames(TRUE); + case SIZEICONIC: + // iconize all child frames too + IconizeChildFrames(TRUE); - m_iconized = TRUE; - break; - } + m_iconized = TRUE; + break; + } - if (!m_iconized) - { - // forward WM_SIZE to status bar control + if ( !m_iconized ) + { + // forward WM_SIZE to status bar control #if wxUSE_NATIVE_STATUSBAR - if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) - { - wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); - event.SetEventObject( m_frameStatusBar ); + if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) + { + wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); + event.SetEventObject( m_frameStatusBar ); - ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); - } -#endif + ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); + } +#endif // wxUSE_NATIVE_STATUSBAR - PositionStatusBar(); - PositionToolBar(); + PositionStatusBar(); + PositionToolBar(); - wxSizeEvent event(wxSize(x, y), m_windowId); - event.SetEventObject( this ); - if (!GetEventHandler()->ProcessEvent(event)) - Default(); - } -} + wxSizeEvent event(wxSize(x, y), m_windowId); + event.SetEventObject( this ); + processed = GetEventHandler()->ProcessEvent(event); + } -bool wxFrame::MSWOnClose() -{ - return Close(); + return processed; } bool wxFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) @@ -758,22 +760,6 @@ bool wxFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) return wxWindow::MSWOnCommand(id, cmd, control); } -void wxFrame::MSWOnMenuHighlight(WXWORD nItem, WXWORD nFlags, WXHMENU hSysMenu) -{ - if (nFlags == 0xFFFF && hSysMenu == 0) - { - wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, -1); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); - } - else if ((nFlags != MF_SEPARATOR) && (nItem != 0) && (nItem != 65535)) - { - wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, nItem); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); - } -} - bool wxFrame::MSWProcessMessage(WXMSG* pMsg) { return FALSE; @@ -788,44 +774,45 @@ bool wxFrame::MSWTranslateMessage(WXMSG* pMsg) return FALSE; } -// Default resizing behaviour - if only ONE subwindow, -// resize to client rectangle size +// Default resizing behaviour - if only ONE subwindow, resize to client +// rectangle size void wxFrame::OnSize(wxSizeEvent& event) { - // if we're using constraints - do use them - #if wxUSE_CONSTRAINTS - if ( GetAutoLayout() ) { - Layout(); - return; + // if we're using constraints - do use them +#if wxUSE_CONSTRAINTS + if ( GetAutoLayout() ) + { + Layout(); + return; } - #endif +#endif - // do we have _exactly_ one child? - wxWindow *child = NULL; - for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) - { - wxWindow *win = (wxWindow *)node->Data(); - if ( !win->IsKindOf(CLASSINFO(wxFrame)) && - !win->IsKindOf(CLASSINFO(wxDialog)) && - (win != GetStatusBar()) && - (win != GetToolBar()) ) + // do we have _exactly_ one child? + wxWindow *child = NULL; + for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) { - if ( child ) - return; // it's our second subwindow - nothing to do - child = win; + wxWindow *win = (wxWindow *)node->Data(); + if ( !win->IsKindOf(CLASSINFO(wxFrame)) && + !win->IsKindOf(CLASSINFO(wxDialog)) && + (win != GetStatusBar()) && + (win != GetToolBar()) ) + { + if ( child ) + return; // it's our second subwindow - nothing to do + child = win; + } } - } - if ( child ) { - // we have exactly one child - set it's size to fill the whole frame - int clientW, clientH; - GetClientSize(&clientW, &clientH); + if ( child ) { + // we have exactly one child - set it's size to fill the whole frame + int clientW, clientH; + GetClientSize(&clientW, &clientH); - int x = 0; - int y = 0; + int x = 0; + int y = 0; - child->SetSize(x, y, clientW, clientH); - } + child->SetSize(x, y, clientW, clientH); + } } // Default activation behaviour - set the focus for the first child @@ -1031,14 +1018,79 @@ void wxFrame::PositionToolBar() } } -// propagate our state change to all child frames +// propagate our state change to all child frames: this allows us to emulate X +// Windows behaviour where child frames float independently of the parent one +// on the desktop, but are iconized/restored with it void wxFrame::IconizeChildFrames(bool bIconize) { - for ( wxNode *node = GetChildren().First(); node; node = node->Next() ) { - wxWindow *win = (wxWindow *)node->Data(); - if ( win->IsKindOf(CLASSINFO(wxFrame)) ) { - ((wxFrame *)win)->Iconize(bIconize); + for ( wxWindowList::Node *node = GetChildren().GetFirst(); + node; + node = node->GetNext() ) + { + wxWindow *win = node->GetData(); + + if ( win->IsKindOf(CLASSINFO(wxFrame)) ) + { + ((wxFrame *)win)->Iconize(bIconize); + } } - } } +// =========================================================================== +// our private (non virtual) message handlers +// =========================================================================== + +bool wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD nFlags, WXHMENU hMenu) +{ + int item; + if ( nFlags == 0xFFFF && hMenu == 0 ) + { + // FIXME: what does this do? does it ever happen? + item = -1; + } + else if ((nFlags != MF_SEPARATOR) && (nItem != 0) && (nItem != 65535)) + { + item = nItem; + } + else + { + return FALSE; + } + + wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item); + event.SetEventObject( this ); + + return GetEventHandler()->ProcessEvent(event); +} + +// --------------------------------------------------------------------------- +// the window proc for wxFrame +// --------------------------------------------------------------------------- + +long wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +{ + long rc = 0; + bool processed = FALSE; + + switch ( message ) + { + case WM_MENUSELECT: + { + WORD item = (WORD)wParam; +#ifdef __WIN32__ + WORD flags = HIWORD(wParam); + HMENU sysmenu = (HMENU)lParam; +#else + WORD flags = LOWORD(lParam); + HMENU sysmenu = (HMENU)HIWORD(lParam); +#endif + processed = HandleMenuSelect(item, flags, (WXHMENU)sysmenu); + } + break; + } + + if ( !processed ) + rc = wxWindow::MSWWindowProc(message, wParam, lParam); + + return rc; +} diff --git a/src/msw/listbox.cpp b/src/msw/listbox.cpp index 63574bbefd..4ca6a3955b 100644 --- a/src/msw/listbox.cpp +++ b/src/msw/listbox.cpp @@ -83,9 +83,6 @@ wxOwnerDrawn *wxListBox::CreateItem(size_t n) // list box control implementation // ============================================================================ -// this macro is dangerous but still better than tons of (HWND)GetHWND() -#define hwnd (HWND)GetHWND() - bool wxListBox::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) { /* @@ -213,7 +210,7 @@ bool wxListBox::Create(wxWindow *parent, #if wxUSE_CTL3D if (want3D) { - Ctl3dSubclassCtl(hwnd); + Ctl3dSubclassCtl(GetHwnd()); m_useCtl3D = TRUE; } #endif @@ -227,7 +224,7 @@ bool wxListBox::Create(wxWindow *parent, } if ( (m_windowStyle & wxLB_MULTIPLE) == 0 ) - SendMessage(hwnd, LB_SETCURSEL, 0, 0); + SendMessage(GetHwnd(), LB_SETCURSEL, 0, 0); SetFont(parent->GetFont()); @@ -259,7 +256,7 @@ void wxListBox::SetFirstItem(int N) wxCHECK_RET( N >= 0 && N < m_noItems, "invalid index in wxListBox::SetFirstItem" ); - SendMessage(hwnd,LB_SETTOPINDEX,(WPARAM)N,(LPARAM)0) ; + SendMessage(GetHwnd(),LB_SETTOPINDEX,(WPARAM)N,(LPARAM)0) ; } void wxListBox::SetFirstItem(const wxString& s) @@ -275,7 +272,7 @@ void wxListBox::Delete(int N) wxCHECK_RET( N >= 0 && N < m_noItems, "invalid index in wxListBox::Delete" ); - SendMessage(hwnd, LB_DELETESTRING, N, 0); + SendMessage(GetHwnd(), LB_DELETESTRING, N, 0); m_noItems--; SetHorizontalExtent(""); @@ -283,7 +280,7 @@ void wxListBox::Delete(int N) void wxListBox::Append(const wxString& item) { - int index = ListBox_AddString(hwnd, item); + int index = ListBox_AddString(GetHwnd(), item); m_noItems ++; #if wxUSE_OWNER_DRAWN @@ -291,7 +288,7 @@ void wxListBox::Append(const wxString& item) wxOwnerDrawn *pNewItem = CreateItem(index); // dummy argument pNewItem->SetName(item); m_aItems.Add(pNewItem); - ListBox_SetItemData(hwnd, index, pNewItem); + ListBox_SetItemData(GetHwnd(), index, pNewItem); } #endif @@ -300,7 +297,7 @@ void wxListBox::Append(const wxString& item) void wxListBox::Append(const wxString& item, char *Client_data) { - int index = ListBox_AddString(hwnd, item); + int index = ListBox_AddString(GetHwnd(), item); m_noItems ++; #if wxUSE_OWNER_DRAWN @@ -312,21 +309,21 @@ void wxListBox::Append(const wxString& item, char *Client_data) else #endif - ListBox_SetItemData(hwnd, index, Client_data); + ListBox_SetItemData(GetHwnd(), index, Client_data); SetHorizontalExtent(item); } void wxListBox::Set(int n, const wxString *choices, char** clientData) { - ShowWindow(hwnd, SW_HIDE); - ListBox_ResetContent(hwnd); + ShowWindow(GetHwnd(), SW_HIDE); + ListBox_ResetContent(GetHwnd()); int i; for (i = 0; i < n; i++) { - ListBox_AddString(hwnd, choices[i]); + ListBox_AddString(GetHwnd(), choices[i]); if ( clientData ) - ListBox_SetItemData(hwnd, i, clientData[i]); + ListBox_SetItemData(GetHwnd(), i, clientData[i]); } m_noItems = n; @@ -344,7 +341,7 @@ void wxListBox::Set(int n, const wxString *choices, char** clientData) wxOwnerDrawn *pNewItem = CreateItem(ui); pNewItem->SetName(choices[ui]); m_aItems.Add(pNewItem); - ListBox_SetItemData(hwnd, ui, pNewItem); + ListBox_SetItemData(GetHwnd(), ui, pNewItem); wxASSERT_MSG(clientData[ui] == NULL, "Can't use client data with owner-drawn listboxes"); @@ -353,12 +350,12 @@ void wxListBox::Set(int n, const wxString *choices, char** clientData) #endif SetHorizontalExtent(""); - ShowWindow(hwnd, SW_SHOW); + ShowWindow(GetHwnd(), SW_SHOW); } int wxListBox::FindString(const wxString& s) const { - int pos = ListBox_FindStringExact(hwnd, (WPARAM)-1, s); + int pos = ListBox_FindStringExact(GetHwnd(), (WPARAM)-1, s); if (pos == LB_ERR) return -1; else @@ -367,7 +364,7 @@ int wxListBox::FindString(const wxString& s) const void wxListBox::Clear() { - ListBox_ResetContent(hwnd); + ListBox_ResetContent(GetHwnd()); #if wxUSE_OWNER_DRAWN size_t uiCount = m_aItems.Count(); @@ -379,7 +376,7 @@ void wxListBox::Clear() #endif // wxUSE_OWNER_DRAWN m_noItems = 0; - ListBox_GetHorizontalExtent(hwnd); + ListBox_GetHorizontalExtent(GetHwnd()); } void wxListBox::SetSelection(int N, bool select) @@ -388,13 +385,13 @@ void wxListBox::SetSelection(int N, bool select) "invalid index in wxListBox::SetSelection" ); if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED)) - SendMessage(hwnd, LB_SETSEL, select, N); + SendMessage(GetHwnd(), LB_SETSEL, select, N); else { int N1 = N; if (!select) N1 = -1; - SendMessage(hwnd, LB_SETCURSEL, N1, 0); + SendMessage(GetHwnd(), LB_SETCURSEL, N1, 0); } } @@ -403,7 +400,7 @@ bool wxListBox::Selected(int N) const wxCHECK_MSG( N >= 0 && N < m_noItems, FALSE, "invalid index in wxListBox::Selected" ); - return SendMessage(hwnd, LB_GETSEL, N, 0) == 0 ? FALSE : TRUE; + return SendMessage(GetHwnd(), LB_GETSEL, N, 0) == 0 ? FALSE : TRUE; } void wxListBox::Deselect(int N) @@ -412,7 +409,7 @@ void wxListBox::Deselect(int N) "invalid index in wxListBox::Deselect" ); if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED)) - SendMessage(hwnd, LB_SETSEL, FALSE, N); + SendMessage(GetHwnd(), LB_SETSEL, FALSE, N); } char *wxListBox::GetClientData(int N) const @@ -420,7 +417,7 @@ char *wxListBox::GetClientData(int N) const wxCHECK_MSG( N >= 0 && N < m_noItems, NULL, "invalid index in wxListBox::GetClientData" ); - return (char *)SendMessage(hwnd, LB_GETITEMDATA, N, 0); + return (char *)SendMessage(GetHwnd(), LB_GETITEMDATA, N, 0); } void wxListBox::SetClientData(int N, char *Client_data) @@ -428,7 +425,7 @@ void wxListBox::SetClientData(int N, char *Client_data) wxCHECK_RET( N >= 0 && N < m_noItems, "invalid index in wxListBox::SetClientData" ); - if ( ListBox_SetItemData(hwnd, N, Client_data) == LB_ERR ) + if ( ListBox_SetItemData(GetHwnd(), N, Client_data) == LB_ERR ) wxLogDebug("LB_SETITEMDATA failed"); } @@ -439,10 +436,10 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const if ((m_windowStyle & wxLB_MULTIPLE) || (m_windowStyle & wxLB_EXTENDED)) { - int no_sel = ListBox_GetSelCount(hwnd); + int no_sel = ListBox_GetSelCount(GetHwnd()); if (no_sel != 0) { int *selections = new int[no_sel]; - if ( ListBox_GetSelItems(hwnd, no_sel, selections) == LB_ERR ) { + if ( ListBox_GetSelItems(GetHwnd(), no_sel, selections) == LB_ERR ) { wxFAIL_MSG("This listbox can't have single-selection style!"); } @@ -457,7 +454,7 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const } else // single-selection listbox { - aSelections.Add(ListBox_GetCurSel(hwnd)); + aSelections.Add(ListBox_GetCurSel(GetHwnd())); return 1; } @@ -472,7 +469,7 @@ int wxListBox::GetSelection() const "GetSelection() can't be used with multiple-selection " "listboxes, use GetSelections() instead." ); - return ListBox_GetCurSel(hwnd); + return ListBox_GetCurSel(GetHwnd()); } // Find string for position @@ -481,11 +478,11 @@ wxString wxListBox::GetString(int N) const wxCHECK_MSG( N >= 0 && N < m_noItems, "", "invalid index in wxListBox::GetClientData" ); - int len = ListBox_GetTextLen(hwnd, N); + int len = ListBox_GetTextLen(GetHwnd(), N); // +1 for terminating NUL wxString result; - ListBox_GetText(hwnd, N, result.GetWriteBuf(len + 1)); + ListBox_GetText(GetHwnd(), N, result.GetWriteBuf(len + 1)); result.UngetWriteBuf(); return result; @@ -540,7 +537,7 @@ void wxListBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (control_width <= 0) control_width = (float)DEFAULT_ITEM_WIDTH; - MoveWindow(hwnd, + MoveWindow(GetHwnd(), (int)control_x, (int)control_y, (int)control_width, (int)control_height, TRUE); @@ -560,8 +557,8 @@ void wxListBox::SetHorizontalExtent(const wxString& s) if (s != "") { - int existingExtent = (int)SendMessage(hwnd, LB_GETHORIZONTALEXTENT, 0, 0L); - HDC dc = GetWindowDC(hwnd); + int existingExtent = (int)SendMessage(GetHwnd(), LB_GETHORIZONTALEXTENT, 0, 0L); + HDC dc = GetWindowDC(GetHwnd()); HFONT oldFont = 0; if (GetFont().Ok() && GetFont().GetResourceHandle()) oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle()); @@ -574,15 +571,15 @@ void wxListBox::SetHorizontalExtent(const wxString& s) if (oldFont) ::SelectObject(dc, oldFont); - ReleaseDC(hwnd, dc); + ReleaseDC(GetHwnd(), dc); if (extentX > existingExtent) - SendMessage(hwnd, LB_SETHORIZONTALEXTENT, LOWORD(extentX), 0L); + SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(extentX), 0L); return; } else { int largestExtent = 0; - HDC dc = GetWindowDC(hwnd); + HDC dc = GetWindowDC(GetHwnd()); HFONT oldFont = 0; if (GetFont().Ok() && GetFont().GetResourceHandle()) oldFont = (HFONT) ::SelectObject(dc, (HFONT) GetFont().GetResourceHandle()); @@ -591,7 +588,7 @@ void wxListBox::SetHorizontalExtent(const wxString& s) int i; for (i = 0; i < m_noItems; i++) { - int len = (int)SendMessage(hwnd, LB_GETTEXT, i, (LONG)wxBuffer); + int len = (int)SendMessage(GetHwnd(), LB_GETTEXT, i, (LONG)wxBuffer); wxBuffer[len] = 0; SIZE extentXY; ::GetTextExtentPoint(dc, (LPSTR)wxBuffer, len, &extentXY); @@ -602,8 +599,8 @@ void wxListBox::SetHorizontalExtent(const wxString& s) if (oldFont) ::SelectObject(dc, oldFont); - ReleaseDC(hwnd, dc); - SendMessage(hwnd, LB_SETHORIZONTALEXTENT, LOWORD(largestExtent), 0L); + ReleaseDC(GetHwnd(), dc); + SendMessage(GetHwnd(), LB_SETHORIZONTALEXTENT, LOWORD(largestExtent), 0L); } } @@ -615,7 +612,7 @@ wxListBox::InsertItems(int nItems, const wxString items[], int pos) int i; for (i = 0; i < nItems; i++) - ListBox_InsertString(hwnd, i + pos, items[i]); + ListBox_InsertString(GetHwnd(), i + pos, items[i]); m_noItems += nItems; SetHorizontalExtent(""); @@ -632,13 +629,13 @@ void wxListBox::SetString(int N, const wxString& s) char *oldData = (char *)wxListBox::GetClientData(N); - SendMessage(hwnd, LB_DELETESTRING, N, 0); + SendMessage(GetHwnd(), LB_DELETESTRING, N, 0); int newN = N; if (N == (m_noItems - 1)) newN = -1; - SendMessage(hwnd, LB_INSERTSTRING, newN, (LPARAM) (const char *)s); + SendMessage(GetHwnd(), LB_INSERTSTRING, newN, (LPARAM) (const char *)s); if (oldData) wxListBox::SetClientData(N, oldData); @@ -769,7 +766,7 @@ bool wxListBox::MSWOnDraw(WXDRAWITEMSTRUCT *item) DRAWITEMSTRUCT *pStruct = (DRAWITEMSTRUCT *)item; - long data = ListBox_GetItemData(hwnd, pStruct->itemID); + long data = ListBox_GetItemData(GetHwnd(), pStruct->itemID); wxCHECK( data && (data != LB_ERR), FALSE ); diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index bdf3afc655..91d71d0a8a 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1157,7 +1157,7 @@ bool wxListCtrl::MSWCommand(WXUINT cmd, WXWORD id) else return FALSE; } -bool wxListCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result) +bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) { wxListEvent event(wxEVT_NULL, m_windowId); wxEventType eventType = wxEVT_NULL; @@ -1275,7 +1275,7 @@ bool wxListCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result) } default : - return wxControl::MSWNotify(wParam, lParam, result); + return wxControl::MSWOnNotify(idCtrl, lParam, result); } event.SetEventObject( this ); diff --git a/src/msw/mdi.cpp b/src/msw/mdi.cpp index dd0e325caf..7f933c7c84 100644 --- a/src/msw/mdi.cpp +++ b/src/msw/mdi.cpp @@ -9,73 +9,102 @@ // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// +// =========================================================================== +// declarations +// =========================================================================== + +// --------------------------------------------------------------------------- +// headers +// --------------------------------------------------------------------------- + #ifdef __GNUG__ -#pragma implementation "mdi.h" + #pragma implementation "mdi.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP -#include "wx/setup.h" -#include "wx/frame.h" -#include "wx/menu.h" -#include "wx/app.h" -#include "wx/utils.h" -#include "wx/dialog.h" -#include "wx/statusbr.h" -#include "wx/settings.h" + #include "wx/setup.h" + #include "wx/frame.h" + #include "wx/menu.h" + #include "wx/app.h" + #include "wx/utils.h" + #include "wx/dialog.h" + #include "wx/statusbr.h" + #include "wx/settings.h" #endif #include "wx/mdi.h" #include "wx/msw/private.h" #if wxUSE_NATIVE_STATUSBAR -#include + #include #endif #include -extern wxList wxModelessWindows; +// --------------------------------------------------------------------------- +// global variables +// --------------------------------------------------------------------------- + +extern wxWindowList wxModelessWindows; // from dialog.cpp extern wxMenu *wxCurrentPopupMenu; -#define IDM_WINDOWTILE 4001 -#define IDM_WINDOWCASCADE 4002 -#define IDM_WINDOWICONS 4003 -#define IDM_WINDOWNEXT 4004 -// This range gives a maximum of 500 -// MDI children. Should be enough :-) -#define wxFIRST_MDI_CHILD 4100 -#define wxLAST_MDI_CHILD 4600 +extern char wxMDIFrameClassName[]; +extern char wxMDIChildFrameClassName[]; +extern wxWindow *wxWndHook; // from window.cpp + +extern wxList *wxWinHandleList; + +// --------------------------------------------------------------------------- +// constants +// --------------------------------------------------------------------------- + +static const int IDM_WINDOWTILE = 4001; +static const int IDM_WINDOWCASCADE = 4002; +static const int IDM_WINDOWICONS = 4003; +static const int IDM_WINDOWNEXT = 4004; + +// This range gives a maximum of 500 MDI children. Should be enough :-) +static const int wxFIRST_MDI_CHILD = 4100; +static const int wxLAST_MDI_CHILD = 4600; // Status border dimensions -#define wxTHICK_LINE_BORDER 3 -#define wxTHICK_LINE_WIDTH 1 +static const int wxTHICK_LINE_BORDER = 3; +static const int wxTHICK_LINE_WIDTH = 1; -extern char wxMDIFrameClassName[]; -extern char wxMDIChildFrameClassName[]; -extern wxWindow *wxWndHook; +// =========================================================================== +// implementation +// =========================================================================== + +// --------------------------------------------------------------------------- +// wxWin macros +// --------------------------------------------------------------------------- #if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) -IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) -IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) + IMPLEMENT_DYNAMIC_CLASS(wxMDIParentFrame, wxFrame) + IMPLEMENT_DYNAMIC_CLASS(wxMDIChildFrame, wxFrame) + IMPLEMENT_DYNAMIC_CLASS(wxMDIClientWindow, wxWindow) +#endif // USE_SHARED_LIBRARY BEGIN_EVENT_TABLE(wxMDIParentFrame, wxFrame) - EVT_SIZE(wxMDIParentFrame::OnSize) - EVT_ACTIVATE(wxMDIParentFrame::OnActivate) - EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) + EVT_SIZE(wxMDIParentFrame::OnSize) + EVT_ACTIVATE(wxMDIParentFrame::OnActivate) + EVT_SYS_COLOUR_CHANGED(wxMDIParentFrame::OnSysColourChanged) END_EVENT_TABLE() BEGIN_EVENT_TABLE(wxMDIClientWindow, wxWindow) - EVT_SCROLL(wxMDIClientWindow::OnScroll) + EVT_SCROLL(wxMDIClientWindow::OnScroll) END_EVENT_TABLE() -#endif +// --------------------------------------------------------------------------- +// wxMDIParentFrame +// --------------------------------------------------------------------------- wxMDIParentFrame::wxMDIParentFrame() { @@ -86,12 +115,12 @@ wxMDIParentFrame::wxMDIParentFrame() } bool wxMDIParentFrame::Create(wxWindow *parent, - wxWindowID id, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) + wxWindowID id, + const wxString& title, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) { m_defaultIcon = (WXHICON) (wxSTD_MDIPARENTFRAME_ICON ? wxSTD_MDIPARENTFRAME_ICON : wxDEFAULT_MDIPARENTFRAME_ICON); @@ -163,30 +192,6 @@ wxMDIParentFrame::~wxMDIParentFrame() delete m_clientWindow; } -// Get size *available for subwindows* i.e. excluding menu bar. -void wxMDIParentFrame::DoGetClientSize(int *x, int *y) const -{ - RECT rect; - ::GetClientRect((HWND) GetHWND(), &rect); - - int cwidth = rect.right; - int cheight = rect.bottom; - - if ( GetStatusBar() ) - { - int sw, sh; - GetStatusBar()->GetSize(&sw, &sh); - cheight -= sh; - } - - wxPoint pt(GetClientAreaOrigin()); - cheight -= pt.y; - cwidth -= pt.x; - - *x = cwidth; - *y = cheight; -} - void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) { if (!menu_bar) @@ -246,9 +251,13 @@ void wxMDIParentFrame::SetMenuBar(wxMenuBar *menu_bar) void wxMDIParentFrame::OnSize(wxSizeEvent& event) { #if wxUSE_CONSTRAINTS - if (GetAutoLayout()) - Layout(); -#endif + if ( GetAutoLayout() ) + { + Layout(); + return; + } +#endif // wxUSE_CONSTRAINTS + int x = 0; int y = 0; int width, height; @@ -256,15 +265,6 @@ void wxMDIParentFrame::OnSize(wxSizeEvent& event) if ( GetClientWindow() ) GetClientWindow()->SetSize(x, y, width, height); - -/* Already done in MSWOnSize - // forward WM_SIZE to status bar control -#if wxUSE_NATIVE_STATUSBAR - if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) - ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); -#endif -*/ - } void wxMDIParentFrame::OnActivate(wxActivateEvent& event) @@ -275,19 +275,19 @@ void wxMDIParentFrame::OnActivate(wxActivateEvent& event) // Returns the active MDI child window wxMDIChildFrame *wxMDIParentFrame::GetActiveChild() const { -// HWND hWnd = (HWND)LOWORD(SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L)); - HWND hWnd = (HWND)SendMessage((HWND) GetClientWindow()->GetHWND(), WM_MDIGETACTIVE, 0, 0L); - if (hWnd == 0) - return NULL; - else - return (wxMDIChildFrame *)wxFindWinFromHandle((WXHWND) hWnd); + HWND hWnd = (HWND)::SendMessage(GetWinHwnd(GetClientWindow()), + WM_MDIGETACTIVE, 0, 0L); + if ( hWnd == 0 ) + return NULL; + else + return (wxMDIChildFrame *)wxFindWinFromHandle((WXHWND) hWnd); } -// Create the client window class (don't Create the window, -// just return a new class) +// Create the client window class (don't Create the window, just return a new +// class) wxMDIClientWindow *wxMDIParentFrame::OnCreateClient() { - return new wxMDIClientWindow ; + return new wxMDIClientWindow; } // Responds to colour changes, and passes event on to children. @@ -314,100 +314,110 @@ void wxMDIParentFrame::OnSysColourChanged(wxSysColourChangedEvent& event) // MDI operations void wxMDIParentFrame::Cascade() { - ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDICASCADE, 0, 0); + ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDICASCADE, 0, 0); } void wxMDIParentFrame::Tile() { - ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDITILE, MDITILE_HORIZONTAL, 0); + ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDITILE, MDITILE_HORIZONTAL, 0); } void wxMDIParentFrame::ArrangeIcons() { - ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDIICONARRANGE, 0, 0); + ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDIICONARRANGE, 0, 0); } void wxMDIParentFrame::ActivateNext() { - ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDINEXT, 0, 0); + ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 0); } void wxMDIParentFrame::ActivatePrevious() { - ::SendMessage( (HWND) GetClientWindow()->GetHWND(), WM_MDINEXT, 0, 1); + ::SendMessage(GetWinHwnd(GetClientWindow()), WM_MDINEXT, 0, 1); } - -/* -// Returns a style for the client window - usually 0 -// or, for example, wxHSCROLL | wxVSCROLL -long wxMDIParentFrame::GetClientStyle() const +// the MDI parent frame window proc +long wxMDIParentFrame::MSWWindowProc(WXUINT message, + WXWPARAM wParam, + WXLPARAM lParam) { - return wxHSCROLL | wxVSCROLL ; -} -*/ + long rc = 0; + bool processed = FALSE; -bool wxMDIParentFrame::MSWOnDestroy() -{ - return FALSE; -} + switch ( message ) + { + case WM_CREATE: + m_clientWindow = OnCreateClient(); + // Uses own style for client style + if ( !m_clientWindow->CreateClient(this, GetWindowStyleFlag()) ) + { + wxLogMessage(_("Failed to create MDI parent frame.")); -void wxMDIParentFrame::MSWOnCreate(WXLPCREATESTRUCT WXUNUSED(cs)) -{ - m_clientWindow = OnCreateClient(); - // Uses own style for client style - m_clientWindow->CreateClient(this, GetWindowStyleFlag()); -} + rc = -1; + } -void wxMDIParentFrame::MSWOnSize(int x, int y, WXUINT id) -{ - switch (id) - { - case SIZEFULLSCREEN: - case SIZENORMAL: - m_iconized = FALSE; - break; - case SIZEICONIC: - m_iconized = TRUE; - break; - } + processed = TRUE; + break; - if (!m_iconized) - { - // forward WM_SIZE to status bar control -#if wxUSE_NATIVE_STATUSBAR - if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) - { - wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); - event.SetEventObject( m_frameStatusBar ); + case WM_ERASEBKGND: + processed = TRUE; - ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); - } + // we erase background ourselves + rc = TRUE; + break; + + case WM_MENUSELECT: + { + WORD item = (WORD)wParam; +#ifdef __WIN32__ + WORD flags = HIWORD(wParam); + HMENU menu = (HMENU)lParam; +#else + WORD flags = LOWORD(lParam); + HMENU menu = (HMENU)HIWORD(lParam); #endif + if ( m_parentFrameActive ) + { + processed = HandleMenuSelect(item, flags, (WXHMENU)menu); + } + else if (m_currentChild) + { + processed = m_currentChild-> + HandleMenuSelect(item, flags, (WXHMENU)menu); + } + } + break; + } - PositionStatusBar(); - PositionToolBar(); + if ( !processed ) + rc = wxFrame::MSWWindowProc(message, wParam, lParam); - wxSizeEvent event(wxSize(x, y), m_windowId); - event.SetEventObject( this ); - if (!GetEventHandler()->ProcessEvent(event)) - Default(); - } + return rc; } bool wxMDIParentFrame::MSWOnActivate(int state, bool minimized, WXHWND activate) { - wxWindow::MSWOnActivate(state, minimized, activate); + bool processed = FALSE; + + if ( wxWindow::MSWOnActivate(state, minimized, activate) ) + { + // already processed + processed = TRUE; + } // If this window is an MDI parent, we must also send an OnActivate message // to the current child. - if ((m_currentChild != NULL) && ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE))) + if ( (m_currentChild != NULL) && + ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)) ) { wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_currentChild->GetId()); event.SetEventObject( m_currentChild ); - m_currentChild->GetEventHandler()->ProcessEvent(event); + if ( m_currentChild->GetEventHandler()->ProcessEvent(event) ) + processed = TRUE; } - return 0; + + return processed; } bool wxMDIParentFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) @@ -495,29 +505,6 @@ bool wxMDIParentFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) return wxWindow::MSWOnCommand(id, cmd, control); } -void wxMDIParentFrame::MSWOnMenuHighlight(WXWORD nItem, WXWORD nFlags, WXHMENU hSysMenu) -{ - if (m_parentFrameActive) - { - if (nFlags == 0xFFFF && hSysMenu == (WXHMENU) NULL) - { - wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, -1); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); - } - else if (nFlags != MF_SEPARATOR) - { - wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, nItem); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); - } - } - else if (m_currentChild) - { - m_currentChild->MSWOnMenuHighlight(nItem, nFlags, hSysMenu); - } -} - long wxMDIParentFrame::MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { WXHWND clientWnd; @@ -526,45 +513,45 @@ long wxMDIParentFrame::MSWDefWindowProc(WXUINT message, WXWPARAM wParam, WXLPARA else clientWnd = 0; - return DefFrameProc((HWND) GetHWND(), (HWND) clientWnd, message, wParam, lParam); + return DefFrameProc(GetHwnd(), (HWND)clientWnd, message, wParam, lParam); } bool wxMDIParentFrame::MSWProcessMessage(WXMSG* msg) { - if ((m_currentChild != (wxWindow *)NULL) && (m_currentChild->GetHWND() != (WXHWND) NULL) && m_currentChild->MSWProcessMessage(msg)) - return TRUE; - - return FALSE; + return m_currentChild && m_currentChild->GetHWND() && + m_currentChild->MSWProcessMessage(msg); } bool wxMDIParentFrame::MSWTranslateMessage(WXMSG* msg) { - MSG *pMsg = (MSG *)msg; - - if ((m_currentChild != (wxWindow *)NULL) && (m_currentChild->GetHWND() != (WXHWND) NULL) && m_currentChild->MSWTranslateMessage(msg)) - return TRUE; - - if (m_acceleratorTable.Ok() && - ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), pMsg)) - return TRUE; + MSG *pMsg = (MSG *)msg; - if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN) - { - if (::TranslateMDISysAccel((HWND) GetClientWindow()->GetHWND(), pMsg)) - return TRUE; - } + if ( m_currentChild && m_currentChild->GetHWND() && + m_currentChild->MSWTranslateMessage(msg) ) + { + return TRUE; + } - return FALSE; -} + if ( m_acceleratorTable.Ok() && + ::TranslateAccelerator(GetHwnd(), + GetTableHaccel(&m_acceleratorTable), + pMsg) ) + { + return TRUE; + } + if ( pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN ) + { + if ( ::TranslateMDISysAccel(GetWinHwnd(GetClientWindow()), pMsg)) + return TRUE; + } -bool wxMDIParentFrame::MSWOnEraseBkgnd(WXHDC WXUNUSED(pDC)) -{ - return TRUE; + return FALSE; } -extern wxWindow *wxWndHook; -extern wxList *wxWinHandleList; +// --------------------------------------------------------------------------- +// wxMDIChildFrame +// --------------------------------------------------------------------------- wxMDIChildFrame::wxMDIChildFrame() { @@ -572,12 +559,12 @@ wxMDIChildFrame::wxMDIChildFrame() } bool wxMDIChildFrame::Create(wxMDIParentFrame *parent, - wxWindowID id, - const wxString& title, - const wxPoint& pos, - const wxSize& size, - long style, - const wxString& name) + wxWindowID id, + const wxString& title, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) { m_defaultIcon = (WXHICON) (wxSTD_MDICHILDFRAME_ICON ? wxSTD_MDICHILDFRAME_ICON : wxDEFAULT_MDICHILDFRAME_ICON); @@ -797,46 +784,49 @@ void wxMDIChildFrame::Activate() } static HWND invalidHandle = 0; -void wxMDIChildFrame::MSWOnSize(int x, int y, WXUINT id) +bool wxMDIChildFrame::MSWOnSize(int x, int y, WXUINT id) { - if (!GetHWND()) return; - - if (invalidHandle == (HWND) GetHWND()) - { - return; - } - - (void)MSWDefWindowProc(m_lastMsg, m_lastWParam, m_lastLParam); - - switch (id) - { - case SIZEFULLSCREEN: - case SIZENORMAL: - m_iconized = FALSE; - break; - case SIZEICONIC: - m_iconized = TRUE; - break; - } - - if (!m_iconized) - { - // forward WM_SIZE to status bar control -#if wxUSE_NATIVE_STATUSBAR - if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) + HWND hwnd = GetHwnd(); + + if ( !hwnd || hwnd == invalidHandle ) { - wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); - event.SetEventObject( m_frameStatusBar ); - - ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); + return FALSE; + } + + switch (id) + { + case SIZEFULLSCREEN: + case SIZENORMAL: + m_iconized = FALSE; + break; + + case SIZEICONIC: + m_iconized = TRUE; + break; } + + if (!m_iconized) + { + // forward WM_SIZE to status bar control +#if wxUSE_NATIVE_STATUSBAR + if (m_frameStatusBar && m_frameStatusBar->IsKindOf(CLASSINFO(wxStatusBar95))) + { + wxSizeEvent event(wxSize(x, y), m_frameStatusBar->GetId()); + event.SetEventObject( m_frameStatusBar ); + + ((wxStatusBar95 *)m_frameStatusBar)->OnSize(event); + } #endif - - PositionStatusBar(); - PositionToolBar(); - - wxWindow::MSWOnSize(x, y, id); - } + + PositionStatusBar(); + PositionToolBar(); + + return wxWindow::MSWOnSize(x, y, id); + } + else + { + return FALSE; + } } bool wxMDIChildFrame::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) @@ -895,7 +885,7 @@ bool wxMDIChildFrame::MSWTranslateMessage(WXMSG* msg) return FALSE; } -long wxMDIChildFrame::MSWOnMDIActivate(long activate, WXHWND WXUNUSED(one), WXHWND WXUNUSED(two)) +bool wxMDIChildFrame::MSWOnMDIActivate(long activate, WXHWND WXUNUSED(one), WXHWND WXUNUSED(two)) { wxMDIParentFrame *parent = (wxMDIParentFrame *)GetParent(); HMENU parent_menu = (HMENU) parent->GetWinMenu(); @@ -922,7 +912,7 @@ long wxMDIChildFrame::MSWOnMDIActivate(long activate, WXHWND WXUNUSED(one), WXHW } wxActivateEvent event(wxEVT_ACTIVATE, TRUE, m_windowId); event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); + return GetEventHandler()->ProcessEvent(event); } else { @@ -931,7 +921,8 @@ long wxMDIChildFrame::MSWOnMDIActivate(long activate, WXHWND WXUNUSED(one), WXHW wxActivateEvent event(wxEVT_ACTIVATE, FALSE, m_windowId); event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); + if ( GetEventHandler()->ProcessEvent(event) ) + return TRUE; // m_active = FALSE; if (parent_menu) @@ -953,8 +944,7 @@ long wxMDIChildFrame::MSWOnMDIActivate(long activate, WXHWND WXUNUSED(one), WXHW bool flag = (activate != 0); wxActivateEvent event(wxEVT_ACTIVATE, flag, m_windowId); event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); - return 0; + return GetEventHandler()->ProcessEvent(event); } void wxMDIChildFrame::MSWDestroyWindow() @@ -1021,7 +1011,7 @@ bool wxMDIChildFrame::ResetWindowStyle(void *vrect) #endif } -void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos) +bool wxMDIChildFrame::MSWOnWindowPosChanging(void *pos) { WINDOWPOS *lpPos = (WINDOWPOS *)pos; #if defined(__WIN95__) @@ -1045,7 +1035,8 @@ void wxMDIChildFrame::MSWOnWindowPosChanging(void *pos) } } #endif - Default(); + + return FALSE; } // Client window @@ -1123,10 +1114,3 @@ void wxMDIClientWindow::OnScroll(wxScrollEvent& event) Default(); } - -// Should hand the message to the default proc -long wxMDIClientWindow::MSWOnMDIActivate(long bActivate, WXHWND, WXHWND) -{ - return Default(); -} - diff --git a/src/msw/notebook.cpp b/src/msw/notebook.cpp index 049703b142..8eb91dbc34 100644 --- a/src/msw/notebook.cpp +++ b/src/msw/notebook.cpp @@ -464,7 +464,7 @@ void wxNotebook::Command(wxCommandEvent& event) wxFAIL_MSG("wxNotebook::Command not implemented"); } -bool wxNotebook::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM* result) +bool wxNotebook::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM* result) { wxNotebookEvent event(wxEVT_NULL, m_windowId); @@ -479,13 +479,13 @@ bool wxNotebook::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM* result) break; default: - return wxControl::MSWNotify(wParam, lParam, result); + return wxControl::MSWOnNotify(idCtrl, lParam, result); } event.SetSelection(TabCtrl_GetCurSel(m_hwnd)); event.SetOldSelection(m_nSelection); event.SetEventObject(this); - event.SetInt(LOWORD(wParam)); // ctrl id + event.SetInt(idCtrl); bool processed = GetEventHandler()->ProcessEvent(event); *result = !event.IsAllowed(); diff --git a/src/msw/scrolbar.cpp b/src/msw/scrolbar.cpp index bac5e67a09..2d9071894f 100644 --- a/src/msw/scrolbar.cpp +++ b/src/msw/scrolbar.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -28,9 +28,6 @@ #include "wx/scrolbar.h" #include "wx/msw/private.h" -// extern wxList wxScrollBarList; -extern void wxFindMaxSize(HWND hwnd, RECT *rect); - #if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxScrollBar, wxControl) @@ -53,16 +50,16 @@ bool wxScrollBar::Create(wxWindow *parent, wxWindowID id, return FALSE; parent->AddChild(this); SetName(name); - SetValidator(validator); + SetValidator(validator); SetBackgroundColour(parent->GetBackgroundColour()) ; SetForegroundColour(parent->GetForegroundColour()) ; m_windowStyle = style; if ( id == -1 ) - m_windowId = (int)NewControlId(); + m_windowId = (int)NewControlId(); else - m_windowId = id; + m_windowId = id; int x = pos.x; int y = pos.y; @@ -116,84 +113,85 @@ wxScrollBar::~wxScrollBar(void) { } -void wxScrollBar::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control) +bool wxScrollBar::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, + WXWORD pos, WXHWND control) { int position = ::GetScrollPos((HWND) control, SB_CTL); int minPos, maxPos; ::GetScrollRange((HWND) control, SB_CTL, &minPos, &maxPos); + #if defined(__WIN95__) - // A page size greater than one has the effect of reducing the - // effective range, therefore the range has already been - // boosted artificially - so reduce it again. - if ( m_pageSize > 1 ) - maxPos -= (m_pageSize - 1); -#endif + // A page size greater than one has the effect of reducing the effective + // range, therefore the range has already been boosted artificially - so + // reduce it again. + if ( m_pageSize > 1 ) + maxPos -= (m_pageSize - 1); +#endif // __WIN95__ wxEventType scrollEvent = wxEVT_NULL; int nScrollInc; switch ( wParam ) { - case SB_TOP: - nScrollInc = maxPos - position; - scrollEvent = wxEVT_SCROLL_TOP; - break; - - case SB_BOTTOM: - nScrollInc = - position; - scrollEvent = wxEVT_SCROLL_BOTTOM; - break; - - case SB_LINEUP: - nScrollInc = -1; - scrollEvent = wxEVT_SCROLL_LINEUP; - break; - - case SB_LINEDOWN: - nScrollInc = 1; - scrollEvent = wxEVT_SCROLL_LINEDOWN; - break; - - case SB_PAGEUP: - nScrollInc = -GetPageSize(); - scrollEvent = wxEVT_SCROLL_PAGEUP; - break; - - case SB_PAGEDOWN: - nScrollInc = GetPageSize(); - scrollEvent = wxEVT_SCROLL_PAGEDOWN; - break; - - case SB_THUMBTRACK: - case SB_THUMBPOSITION: - nScrollInc = pos - position; - scrollEvent = wxEVT_SCROLL_THUMBTRACK; - break; - - default: - nScrollInc = 0; + case SB_TOP: + nScrollInc = maxPos - position; + scrollEvent = wxEVT_SCROLL_TOP; + break; + + case SB_BOTTOM: + nScrollInc = - position; + scrollEvent = wxEVT_SCROLL_BOTTOM; + break; + + case SB_LINEUP: + nScrollInc = -1; + scrollEvent = wxEVT_SCROLL_LINEUP; + break; + + case SB_LINEDOWN: + nScrollInc = 1; + scrollEvent = wxEVT_SCROLL_LINEDOWN; + break; + + case SB_PAGEUP: + nScrollInc = -GetPageSize(); + scrollEvent = wxEVT_SCROLL_PAGEUP; + break; + + case SB_PAGEDOWN: + nScrollInc = GetPageSize(); + scrollEvent = wxEVT_SCROLL_PAGEDOWN; + break; + + case SB_THUMBTRACK: + case SB_THUMBPOSITION: + nScrollInc = pos - position; + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + break; + + default: + nScrollInc = 0; } - if (nScrollInc != 0) + if ( nScrollInc == 0 ) { - int new_pos = position + nScrollInc; - - if (new_pos < 0) - new_pos = 0; - if (new_pos > maxPos) - new_pos = maxPos; - - SetThumbPosition(new_pos); - wxScrollEvent event(scrollEvent, m_windowId); - event.SetPosition(new_pos); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); + // no event to process, so don't process it + return FALSE; } -} -void wxScrollBar::MSWOnHScroll(WXWORD wParam, WXWORD pos, WXHWND control) -{ - MSWOnVScroll(wParam, pos, control); + int new_pos = position + nScrollInc; + + if (new_pos < 0) + new_pos = 0; + if (new_pos > maxPos) + new_pos = maxPos; + + SetThumbPosition(new_pos); + wxScrollEvent event(scrollEvent, m_windowId); + event.SetPosition(new_pos); + event.SetEventObject( this ); + + return GetEventHandler()->ProcessEvent(event); } void wxScrollBar::SetThumbPosition(int viewStart) @@ -233,7 +231,7 @@ void wxScrollBar::SetScrollbar(int position, int thumbSize, int range, int pageS // (see comment for SetPageLength) if ( m_pageSize > 1 ) { - range1 += (m_pageSize - 1); + range1 += (m_pageSize - 1); } SCROLLINFO info; @@ -291,7 +289,7 @@ void wxScrollBar::SetObjectLength(int objectLength) // (see comment for SetPageLength) if ( m_pageSize > 1 ) { - range += (m_pageSize - 1); + range += (m_pageSize - 1); } SCROLLINFO info; @@ -324,7 +322,7 @@ void wxScrollBar::GetValues(int *viewStart, int *viewLength, int *objectLength, #endif WXHBRUSH wxScrollBar::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) + WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { return 0; } diff --git a/src/msw/slider95.cpp b/src/msw/slider95.cpp index d7a322184a..f9aa9ea5c1 100644 --- a/src/msw/slider95.cpp +++ b/src/msw/slider95.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -75,9 +75,9 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id, m_tickFreq = 0; if ( id == -1 ) - m_windowId = (int)NewControlId(); + m_windowId = (int)NewControlId(); else - m_windowId = id; + m_windowId = id; int x = pos.x; int y = pos.y; @@ -113,23 +113,23 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id, msStyle = TBS_HORZ | WS_CHILD | WS_VISIBLE | WS_TABSTOP ; if ( m_windowStyle & wxSL_AUTOTICKS ) - msStyle |= TBS_AUTOTICKS ; + msStyle |= TBS_AUTOTICKS ; if ( m_windowStyle & wxSL_LEFT ) - msStyle |= TBS_LEFT; + msStyle |= TBS_LEFT; else if ( m_windowStyle & wxSL_RIGHT ) - msStyle |= TBS_RIGHT; + msStyle |= TBS_RIGHT; else if ( m_windowStyle & wxSL_TOP ) - msStyle |= TBS_TOP; + msStyle |= TBS_TOP; else if ( m_windowStyle & wxSL_BOTTOM ) - msStyle |= TBS_BOTTOM; + msStyle |= TBS_BOTTOM; else if ( m_windowStyle & wxSL_BOTH ) - msStyle |= TBS_BOTH; + msStyle |= TBS_BOTH; else if ( ! (m_windowStyle & wxSL_AUTOTICKS) ) - msStyle |= TBS_NOTICKS; + msStyle |= TBS_NOTICKS; if ( m_windowStyle & wxSL_SELRANGE ) - msStyle |= TBS_ENABLESELRANGE ; + msStyle |= TBS_ENABLESELRANGE ; HWND scroll_bar = CreateWindowEx(MakeExtendedStyle(m_windowStyle), TRACKBAR_CLASS, wxBuffer, msStyle, @@ -167,14 +167,14 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id, { if (GetFont().GetResourceHandle()) { - if ( m_staticMin ) - SendMessage((HWND)m_staticMin,WM_SETFONT, - (WPARAM)GetFont().GetResourceHandle(),0L); - if ( m_staticMax ) - SendMessage((HWND)m_staticMax,WM_SETFONT, + if ( m_staticMin ) + SendMessage((HWND)m_staticMin,WM_SETFONT, + (WPARAM)GetFont().GetResourceHandle(),0L); + if ( m_staticMax ) + SendMessage((HWND)m_staticMax,WM_SETFONT, (WPARAM)GetFont().GetResourceHandle(),0L); - if (m_staticValue) - SendMessage((HWND)m_staticValue,WM_SETFONT, + if (m_staticValue) + SendMessage((HWND)m_staticValue,WM_SETFONT, (WPARAM)GetFont().GetResourceHandle(),0L); } } @@ -186,7 +186,8 @@ bool wxSlider95::Create(wxWindow *parent, wxWindowID id, return TRUE; } -void wxSlider95::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control) +bool wxSlider95::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, + WXWORD pos, WXHWND control) { int position = 0; // Dummy - not used in this mode @@ -194,74 +195,74 @@ void wxSlider95::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control) wxEventType scrollEvent = wxEVT_NULL; switch ( wParam ) { - case SB_TOP: - nScrollInc = m_rangeMax - position; - scrollEvent = wxEVT_SCROLL_TOP; - break; - - case SB_BOTTOM: - nScrollInc = - position; - scrollEvent = wxEVT_SCROLL_BOTTOM; - break; - - case SB_LINEUP: - nScrollInc = - GetLineSize(); - scrollEvent = wxEVT_SCROLL_LINEUP; - break; - - case SB_LINEDOWN: - nScrollInc = GetLineSize(); - scrollEvent = wxEVT_SCROLL_LINEDOWN; - break; - - case SB_PAGEUP: - nScrollInc = -GetPageSize(); - scrollEvent = wxEVT_SCROLL_PAGEUP; - break; - - case SB_PAGEDOWN: - nScrollInc = GetPageSize(); - scrollEvent = wxEVT_SCROLL_PAGEDOWN; - break; - - case SB_THUMBTRACK: - case SB_THUMBPOSITION: + case SB_TOP: + nScrollInc = m_rangeMax - position; + scrollEvent = wxEVT_SCROLL_TOP; + break; + + case SB_BOTTOM: + nScrollInc = - position; + scrollEvent = wxEVT_SCROLL_BOTTOM; + break; + + case SB_LINEUP: + nScrollInc = - GetLineSize(); + scrollEvent = wxEVT_SCROLL_LINEUP; + break; + + case SB_LINEDOWN: + nScrollInc = GetLineSize(); + scrollEvent = wxEVT_SCROLL_LINEDOWN; + break; + + case SB_PAGEUP: + nScrollInc = -GetPageSize(); + scrollEvent = wxEVT_SCROLL_PAGEUP; + break; + + case SB_PAGEDOWN: + nScrollInc = GetPageSize(); + scrollEvent = wxEVT_SCROLL_PAGEDOWN; + break; + + case SB_THUMBTRACK: + case SB_THUMBPOSITION: #ifdef __WIN32__ - nScrollInc = (signed short)pos - position; -#else - nScrollInc = pos - position; -#endif - scrollEvent = wxEVT_SCROLL_THUMBTRACK; - break; + nScrollInc = (signed short)pos - position; +#else // Win16 + nScrollInc = pos - position; +#endif // Win32/16 + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + break; + + default: + nScrollInc = 0; + } - default: - nScrollInc = 0; - return; + if ( nScrollInc == 0 ) + { + // no event... + return FALSE; } + int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0); + if ( (newPos < GetMin()) || (newPos > GetMax()) ) { + // out of range - but we did process it + return TRUE; + } - int newPos = (int)::SendMessage((HWND) control, TBM_GETPOS, 0, 0); - if (!(newPos < GetMin() || newPos > GetMax())) - { - SetValue(newPos); + SetValue(newPos); - wxScrollEvent event(scrollEvent, m_windowId); - event.SetPosition(newPos); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); + wxScrollEvent event(scrollEvent, m_windowId); + event.SetPosition(newPos); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); - wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() ); - cevent.SetEventObject( this ); - GetEventHandler()->ProcessEvent( cevent ); + wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() ); + cevent.SetEventObject( this ); - } - } -} - -void wxSlider95::MSWOnHScroll(WXWORD wParam, WXWORD pos, WXHWND control) -{ - MSWOnVScroll(wParam, pos, control); + return GetEventHandler()->ProcessEvent( cevent ); } wxSlider95::~wxSlider95() @@ -372,8 +373,8 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) { - if ( m_windowStyle & wxSL_LABELS ) - { + if ( m_windowStyle & wxSL_LABELS ) + { int min_len = 0; GetWindowText((HWND) m_staticMin, buf, 300); @@ -386,15 +387,15 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (m_staticValue) { int new_width = (int)(wxMax(min_len, max_len)); - int valueHeight = (int)cyf; + int valueHeight = (int)cyf; #ifdef __WIN32__ // For some reason, under Win95, the text edit control has // a lot of space before the first character new_width += 3*cx; #endif // The height needs to be a bit bigger under Win95 if using native - // 3D effects. - valueHeight = (int) (valueHeight * 1.5) ; + // 3D effects. + valueHeight = (int) (valueHeight * 1.5) ; MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); x_offset += new_width + cx; } @@ -405,8 +406,8 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) int slider_length = (int)(w1 - x_offset - max_len - cx); int slider_height = h1; - if (slider_height < 0 ) - slider_height = 20; + if (slider_height < 0 ) + slider_height = 20; // Slider must have a minimum/default length/height if (slider_length < 100) @@ -417,25 +418,25 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); } - else - { - // No labels - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) - { - GetSize(&w1, &h1); - } - if ( w1 < 0 ) - w1 = 200; - if ( h1 < 0 ) - h1 = 20; - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); - } + else + { + // No labels + // If we're prepared to use the existing size, then... + if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) + { + GetSize(&w1, &h1); + } + if ( w1 < 0 ) + w1 = 200; + if ( h1 < 0 ) + h1 = 20; + MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + } } else { - if ( m_windowStyle & wxSL_LABELS ) - { + if ( m_windowStyle & wxSL_LABELS ) + { int min_len; GetWindowText((HWND) m_staticMin, buf, 300); GetTextExtent(buf, &min_len, &cyf,NULL,NULL, & this->GetFont()); @@ -447,7 +448,7 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (m_staticValue) { int new_width = (int)(wxMax(min_len, max_len)); - int valueHeight = (int)cyf; + int valueHeight = (int)cyf; /*** Suggested change by George Tasker - remove this block... #ifdef __WIN32__ // For some reason, under Win95, the text edit control has @@ -458,8 +459,8 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) new_width += cx; // The height needs to be a bit bigger under Win95 if using native - // 3D effects. - valueHeight = (int) (valueHeight * 1.5) ; + // 3D effects. + valueHeight = (int) (valueHeight * 1.5) ; MoveWindow((HWND) m_staticValue, x_offset, y_offset, new_width, valueHeight, TRUE); y_offset += valueHeight; @@ -471,8 +472,8 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) int slider_length = (int)(h1 - y_offset - cy - cy); int slider_width = w1; - if (slider_width < 0 ) - slider_width = 20; + if (slider_width < 0 ) + slider_width = 20; // Slider must have a minimum/default length if (slider_length < 100) @@ -483,20 +484,20 @@ void wxSlider95::DoSetSize(int x, int y, int width, int height, int sizeFlags) MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); } - else - { - // No labels - // If we're prepared to use the existing size, then... - if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) - { - GetSize(&w1, &h1); - } - if ( w1 < 0 ) - w1 = 20; - if ( h1 < 0 ) - h1 = 200; - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); - } + else + { + // No labels + // If we're prepared to use the existing size, then... + if (width == -1 && height == -1 && ((sizeFlags & wxSIZE_AUTO) != wxSIZE_AUTO)) + { + GetSize(&w1, &h1); + } + if ( w1 < 0 ) + w1 = 20; + if ( h1 < 0 ) + h1 = 200; + MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + } } } @@ -510,8 +511,8 @@ void wxSlider95::SetRange(int minValue, int maxValue) char buf[40]; if ( m_staticMin ) { - sprintf(buf, "%d", m_rangeMin); - SetWindowText((HWND) m_staticMin, buf); + sprintf(buf, "%d", m_rangeMin); + SetWindowText((HWND) m_staticMin, buf); } if ( m_staticMax ) @@ -522,10 +523,10 @@ void wxSlider95::SetRange(int minValue, int maxValue) } WXHBRUSH wxSlider95::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) + WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { if ( nCtlColor == CTLCOLOR_SCROLLBAR ) - return 0; + return 0; // Otherwise, it's a static if (GetParent()->GetTransparentBackground()) @@ -611,7 +612,7 @@ void wxSlider95::SetTick(int tickPos) bool wxSlider95::ContainsHWND(WXHWND hWnd) const { - return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); + return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); } void wxSlider95::Command (wxCommandEvent & event) @@ -622,7 +623,7 @@ void wxSlider95::Command (wxCommandEvent & event) bool wxSlider95::Show(bool show) { - wxWindow::Show(show); + wxWindow::Show(show); int cshow; if (show) @@ -631,11 +632,11 @@ bool wxSlider95::Show(bool show) cshow = SW_HIDE; if(m_staticValue) - ShowWindow((HWND) m_staticValue, (BOOL)cshow); + ShowWindow((HWND) m_staticValue, (BOOL)cshow); if(m_staticMin) - ShowWindow((HWND) m_staticMin, (BOOL)cshow); + ShowWindow((HWND) m_staticMin, (BOOL)cshow); if(m_staticMax) - ShowWindow((HWND) m_staticMax, (BOOL)cshow); + ShowWindow((HWND) m_staticMax, (BOOL)cshow); return TRUE; } diff --git a/src/msw/slidrmsw.cpp b/src/msw/slidrmsw.cpp index 26d7488832..2ec3e8536e 100644 --- a/src/msw/slidrmsw.cpp +++ b/src/msw/slidrmsw.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -69,9 +69,9 @@ bool wxSliderMSW::Create(wxWindow *parent, wxWindowID id, m_tickFreq = 0; if ( id == -1 ) - m_windowId = (int)NewControlId(); + m_windowId = (int)NewControlId(); else - m_windowId = id; + m_windowId = id; int x = pos.x; int y = pos.y; @@ -138,14 +138,14 @@ bool wxSliderMSW::Create(wxWindow *parent, wxWindowID id, // GetFont()->RealizeResource(); if (GetFont().GetResourceHandle()) { - if ( m_staticMin ) - SendMessage((HWND)m_staticMin,WM_SETFONT, - (WPARAM)GetFont().GetResourceHandle(),0L); - if ( m_staticMax ) - SendMessage((HWND)m_staticMax,WM_SETFONT, + if ( m_staticMin ) + SendMessage((HWND)m_staticMin,WM_SETFONT, + (WPARAM)GetFont().GetResourceHandle(),0L); + if ( m_staticMax ) + SendMessage((HWND)m_staticMax,WM_SETFONT, (WPARAM)GetFont().GetResourceHandle(),0L); - if (m_staticValue) - SendMessage((HWND)m_staticValue,WM_SETFONT, + if (m_staticValue) + SendMessage((HWND)m_staticValue,WM_SETFONT, (WPARAM)GetFont().GetResourceHandle(),0L); } } @@ -156,7 +156,8 @@ bool wxSliderMSW::Create(wxWindow *parent, wxWindowID id, return TRUE; } -void wxSliderMSW::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control) +bool wxSliderMSW::MSWOnScroll(int WXUNUSED(orientation), WXWORD wParam, + WXWORD pos, WXHWND control) { int position = ::GetScrollPos((HWND)control, SB_CTL); @@ -164,75 +165,75 @@ void wxSliderMSW::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control) wxEventType scrollEvent = wxEVT_NULL; switch ( wParam ) { - case SB_TOP: - nScrollInc = m_rangeMax - position; - scrollEvent = wxEVT_SCROLL_TOP; - break; - - case SB_BOTTOM: - nScrollInc = - position; - scrollEvent = wxEVT_SCROLL_BOTTOM; - break; - - case SB_LINEUP: - nScrollInc = - GetLineSize(); - scrollEvent = wxEVT_SCROLL_LINEUP; - break; - - case SB_LINEDOWN: - nScrollInc = GetLineSize(); - scrollEvent = wxEVT_SCROLL_LINEDOWN; - break; - - case SB_PAGEUP: - nScrollInc = -GetPageSize(); - scrollEvent = wxEVT_SCROLL_PAGEUP; - break; - - case SB_PAGEDOWN: - nScrollInc = GetPageSize(); - scrollEvent = wxEVT_SCROLL_PAGEDOWN; - break; - - case SB_THUMBTRACK: - case SB_THUMBPOSITION: + case SB_TOP: + nScrollInc = m_rangeMax - position; + scrollEvent = wxEVT_SCROLL_TOP; + break; + + case SB_BOTTOM: + nScrollInc = - position; + scrollEvent = wxEVT_SCROLL_BOTTOM; + break; + + case SB_LINEUP: + nScrollInc = - GetLineSize(); + scrollEvent = wxEVT_SCROLL_LINEUP; + break; + + case SB_LINEDOWN: + nScrollInc = GetLineSize(); + scrollEvent = wxEVT_SCROLL_LINEDOWN; + break; + + case SB_PAGEUP: + nScrollInc = -GetPageSize(); + scrollEvent = wxEVT_SCROLL_PAGEUP; + break; + + case SB_PAGEDOWN: + nScrollInc = GetPageSize(); + scrollEvent = wxEVT_SCROLL_PAGEDOWN; + break; + + case SB_THUMBTRACK: + case SB_THUMBPOSITION: #ifdef __WIN32__ - nScrollInc = (signed short)pos - position; + nScrollInc = (signed short)pos - position; #else - nScrollInc = pos - position; + nScrollInc = pos - position; #endif - scrollEvent = wxEVT_SCROLL_THUMBTRACK; - break; + scrollEvent = wxEVT_SCROLL_THUMBTRACK; + break; - default: - nScrollInc = 0; - return; + default: + nScrollInc = 0; } - if (nScrollInc != 0) + if (nScrollInc == 0) { + // no event... + return FALSE; + } - int newPos = position + nScrollInc; + int newPos = position + nScrollInc; - if (!(newPos < GetMin() || newPos > GetMax())) - { - SetValue(newPos); + if ( (newPos < GetMin()) || (newPos > GetMax()) ) + { + // out of range - but we did process it + return TRUE; + } - wxScrollEvent event(scrollEvent, m_windowId); - event.SetPosition(newPos); - event.SetEventObject( this ); - GetEventHandler()->ProcessEvent(event); + SetValue(newPos); - wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() ); - cevent.SetEventObject( this ); - GetEventHandler()->ProcessEvent( cevent ); - } - } -} + wxScrollEvent event(scrollEvent, m_windowId); + event.SetPosition(newPos); + event.SetEventObject( this ); + GetEventHandler()->ProcessEvent(event); -void wxSliderMSW::MSWOnHScroll(WXWORD wParam, WXWORD pos, WXHWND control) -{ - MSWOnVScroll(wParam, pos, control); + wxCommandEvent cevent( wxEVT_COMMAND_SLIDER_UPDATED, GetId() ); + cevent.SetEventObject( this ); + + return GetEventHandler()->ProcessEvent( cevent ); } wxSliderMSW::~wxSliderMSW() @@ -343,8 +344,8 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) if ((m_windowStyle & wxSL_VERTICAL) != wxSL_VERTICAL) { - if ( m_windowStyle & wxSL_LABELS ) - { + if ( m_windowStyle & wxSL_LABELS ) + { int min_len = 0; GetWindowText((HWND) m_staticMin, buf, 300); @@ -357,7 +358,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (m_staticValue) { int new_width = (int)(wxMax(min_len, max_len)); - int valueHeight = (int)cyf; + int valueHeight = (int)cyf; #ifdef __WIN32__ // For some reason, under Win95, the text edit control has // a lot of space before the first character @@ -383,20 +384,20 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); } - else - { - // No labels - if ( w1 < 0 ) - w1 = 200; - if ( h1 < 0 ) - h1 = 20; - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); - } + else + { + // No labels + if ( w1 < 0 ) + w1 = 200; + if ( h1 < 0 ) + h1 = 20; + MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + } } else { - if ( m_windowStyle & wxSL_LABELS ) - { + if ( m_windowStyle & wxSL_LABELS ) + { int min_len; GetWindowText((HWND) m_staticMin, buf, 300); GetTextExtent(buf, &min_len, &cyf,NULL,NULL,& this->GetFont()); @@ -408,7 +409,7 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) if (m_staticValue) { int new_width = (int)(wxMax(min_len, max_len)); - int valueHeight = (int)cyf; + int valueHeight = (int)cyf; /*** Suggested change by George Tasker - remove this block... #ifdef __WIN32__ // For some reason, under Win95, the text edit control has @@ -439,15 +440,15 @@ void wxSliderMSW::DoSetSize(int x, int y, int width, int height, int sizeFlags) MoveWindow((HWND) m_staticMax, x_offset, y_offset, (int)max_len, cy, TRUE); } - else - { - // No labels - if ( w1 < 0 ) - w1 = 20; - if ( h1 < 0 ) - h1 = 200; - MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); - } + else + { + // No labels + if ( w1 < 0 ) + w1 = 20; + if ( h1 < 0 ) + h1 = 200; + MoveWindow((HWND) GetHWND(), x1, y1, w1, h1, TRUE); + } } } @@ -460,8 +461,8 @@ void wxSliderMSW::SetRange(int minValue, int maxValue) char buf[40]; if ( m_staticMin ) { - sprintf(buf, "%d", m_rangeMin); - SetWindowText((HWND) m_staticMin, buf); + sprintf(buf, "%d", m_rangeMin); + SetWindowText((HWND) m_staticMin, buf); } if ( m_staticMax ) @@ -472,10 +473,10 @@ void wxSliderMSW::SetRange(int minValue, int maxValue) } WXHBRUSH wxSliderMSW::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) + WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { if ( nCtlColor == CTLCOLOR_SCROLLBAR ) - return 0; + return 0; // Otherwise, it's a static if (GetParent()->GetTransparentBackground()) @@ -553,7 +554,7 @@ void wxSliderMSW::SetTick(int tickPos) bool wxSliderMSW::ContainsHWND(WXHWND hWnd) const { - return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); + return ( hWnd == GetStaticMin() || hWnd == GetStaticMax() || hWnd == GetEditValue() ); } void wxSliderMSW::Command (wxCommandEvent & event) @@ -564,7 +565,7 @@ void wxSliderMSW::Command (wxCommandEvent & event) bool wxSliderMSW::Show(bool show) { - wxWindow::Show(show); + wxWindow::Show(show); int cshow; if (show) @@ -573,11 +574,11 @@ bool wxSliderMSW::Show(bool show) cshow = SW_HIDE; if(m_staticValue) - ShowWindow((HWND) m_staticValue, (BOOL)cshow); + ShowWindow((HWND) m_staticValue, (BOOL)cshow); if(m_staticMin) - ShowWindow((HWND) m_staticMin, (BOOL)cshow); + ShowWindow((HWND) m_staticMin, (BOOL)cshow); if(m_staticMax) - ShowWindow((HWND) m_staticMax, (BOOL)cshow); + ShowWindow((HWND) m_staticMax, (BOOL)cshow); return TRUE; } diff --git a/src/msw/spinbutt.cpp b/src/msw/spinbutt.cpp index 03657deaa0..e1efced86e 100644 --- a/src/msw/spinbutt.cpp +++ b/src/msw/spinbutt.cpp @@ -6,22 +6,22 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ -#pragma implementation "spinbutt.h" + #pragma implementation "spinbutt.h" #endif // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif #ifndef WX_PRECOMP -#include "wx/wx.h" + #include "wx/wx.h" #endif // Can't resolve reference to CreateUpDownControl in @@ -33,17 +33,17 @@ #include "wx/msw/private.h" #if !defined(__GNUWIN32__) || defined(__TWIN32__) -#include + #include #endif #if !USE_SHARED_LIBRARY -IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) + IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl) #endif -wxSpinButton::wxSpinButton(void) +wxSpinButton::wxSpinButton() { - m_min = 0; - m_max = 100; + m_min = 0; + m_max = 100; } bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, @@ -81,11 +81,11 @@ bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, c DWORD wstyle = WS_VISIBLE | WS_CHILD | WS_TABSTOP; if ( m_windowStyle & wxSP_HORIZONTAL ) - wstyle |= UDS_HORZ; + wstyle |= UDS_HORZ; if ( m_windowStyle & wxSP_ARROW_KEYS ) - wstyle |= UDS_ARROWKEYS; + wstyle |= UDS_ARROWKEYS; if ( m_windowStyle & wxSP_WRAP ) - wstyle |= UDS_WRAP; + wstyle |= UDS_WRAP; // Create the ListView control. HWND hWndListControl = CreateUpDownControl(wstyle, @@ -94,177 +94,106 @@ bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, c m_windowId, wxGetInstance(), 0, - m_min, m_max, m_min); + m_min, m_max, m_min); m_hWnd = (WXHWND) hWndListControl; if (parent) parent->AddChild(this); // TODO: have this for all controls. if ( !m_hWnd ) - return FALSE; + return FALSE; SubclassWin((WXHWND) m_hWnd); return TRUE; } -wxSpinButton::~wxSpinButton(void) +wxSpinButton::~wxSpinButton() { } // Attributes //////////////////////////////////////////////////////////////////////////// -int wxSpinButton::GetValue(void) const +int wxSpinButton::GetValue() const { - return (int) ::SendMessage((HWND) GetHWND(), UDM_GETPOS, 0, 0); + return (int) ::SendMessage((HWND) GetHWND(), UDM_GETPOS, 0, 0); } void wxSpinButton::SetValue(int val) { - ::SendMessage((HWND) GetHWND(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0)); + ::SendMessage((HWND) GetHWND(), UDM_SETPOS, 0, (LPARAM) MAKELONG((short) val, 0)); } void wxSpinButton::SetRange(int minVal, int maxVal) { - m_min = minVal; - m_max = maxVal; - ::SendMessage((HWND) GetHWND(), UDM_SETRANGE, 0, + m_min = minVal; + m_max = maxVal; + ::SendMessage((HWND) GetHWND(), UDM_SETRANGE, 0, (LPARAM) MAKELONG((short)maxVal, (short)minVal)); } -void wxSpinButton::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control) +bool wxSpinButton::MSWOnScroll(int orientation, WXWORD wParam, + WXWORD pos, WXHWND control) { - if (control) - { + if ( !control ) + return FALSE; + wxSpinEvent event(wxEVT_NULL, m_windowId); event.SetPosition(pos); - event.SetOrientation(wxVERTICAL); - event.SetEventObject( this ); + event.SetOrientation(orientation); + event.SetEventObject(this); - switch ( wParam ) - { - case SB_TOP: - event.m_eventType = wxEVT_SCROLL_TOP; - break; + switch ( wParam ) + { + case SB_TOP: + event.m_eventType = wxEVT_SCROLL_TOP; + break; - case SB_BOTTOM: - event.m_eventType = wxEVT_SCROLL_BOTTOM; - break; + case SB_BOTTOM: + event.m_eventType = wxEVT_SCROLL_BOTTOM; + break; - case SB_LINEUP: - event.m_eventType = wxEVT_SCROLL_LINEUP; - break; + case SB_LINEUP: + event.m_eventType = wxEVT_SCROLL_LINEUP; + break; - case SB_LINEDOWN: - event.m_eventType = wxEVT_SCROLL_LINEDOWN; - break; + case SB_LINEDOWN: + event.m_eventType = wxEVT_SCROLL_LINEDOWN; + break; - case SB_PAGEUP: - event.m_eventType = wxEVT_SCROLL_PAGEUP; - break; + case SB_PAGEUP: + event.m_eventType = wxEVT_SCROLL_PAGEUP; + break; - case SB_PAGEDOWN: - event.m_eventType = wxEVT_SCROLL_PAGEDOWN; - break; + case SB_PAGEDOWN: + event.m_eventType = wxEVT_SCROLL_PAGEDOWN; + break; case SB_THUMBTRACK: case SB_THUMBPOSITION: - event.m_eventType = wxEVT_SCROLL_THUMBTRACK; - break; - - default: - return; - break; - } - if (!GetEventHandler()->ProcessEvent(event)) - Default(); - } -} - -void wxSpinButton::MSWOnHScroll( WXWORD wParam, WXWORD pos, WXHWND control) -{ - if (control) - { - wxSpinEvent event(wxEVT_NULL, m_windowId); - event.SetPosition(pos); - event.SetOrientation(wxHORIZONTAL); - event.SetEventObject( this ); - - switch ( wParam ) - { - case SB_TOP: - event.m_eventType = wxEVT_SCROLL_TOP; - break; - - case SB_BOTTOM: - event.m_eventType = wxEVT_SCROLL_BOTTOM; - break; - - case SB_LINEUP: - event.m_eventType = wxEVT_SCROLL_LINEUP; - break; + event.m_eventType = wxEVT_SCROLL_THUMBTRACK; + break; - case SB_LINEDOWN: - event.m_eventType = wxEVT_SCROLL_LINEDOWN; - break; + default: + return FALSE; + } - case SB_PAGEUP: - event.m_eventType = wxEVT_SCROLL_PAGEUP; - break; - - case SB_PAGEDOWN: - event.m_eventType = wxEVT_SCROLL_PAGEDOWN; - break; - - case SB_THUMBTRACK: - case SB_THUMBPOSITION: - event.m_eventType = wxEVT_SCROLL_THUMBTRACK; - break; - - default: - return; - break; - } - if (!GetEventHandler()->ProcessEvent(event)) - Default(); - } + return GetEventHandler()->ProcessEvent(event); } bool wxSpinButton::MSWCommand(WXUINT cmd, WXWORD id) { - // No command messages - return FALSE; -} - -bool wxSpinButton::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM* result) -{ - NMHDR* hdr1 = (NMHDR*) lParam; - switch ( hdr1->code ) - { - /* We don't process this message, currently */ - case UDN_DELTAPOS: - - default : - return wxControl::MSWNotify(wParam, lParam, result); - break; - } -/* - event.eventObject = this; - event.SetEventType(eventType); - - if ( !GetEventHandler()->ProcessEvent(event) ) - return FALSE; -*/ - return TRUE; + // No command messages + return FALSE; } // Spin event IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxScrollEvent) -wxSpinEvent::wxSpinEvent(wxEventType commandType, int id): - wxScrollEvent(commandType, id) +wxSpinEvent::wxSpinEvent(wxEventType commandType, int id) + : wxScrollEvent(commandType, id) { } -#endif +#endif // __WIN95__ diff --git a/src/msw/tabctrl.cpp b/src/msw/tabctrl.cpp index 9537e0fbc9..e41562b853 100644 --- a/src/msw/tabctrl.cpp +++ b/src/msw/tabctrl.cpp @@ -148,7 +148,7 @@ bool wxTabCtrl::MSWCommand(WXUINT cmd, WXWORD id) return FALSE; } -bool wxTabCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result) +bool wxTabCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) { wxTabEvent event(wxEVT_NULL, m_windowId); wxEventType eventType = wxEVT_NULL; @@ -171,12 +171,12 @@ bool wxTabCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result) } default : - return wxControl::MSWNotify(wParam, lParam, result); + return wxControl::MSWOnNotify(idCtrl, lParam, result); } event.SetEventObject( this ); event.SetEventType(eventType); - event.SetInt( (int) LOWORD(wParam) ) ; + event.SetInt(idCtrl) ; return ProcessEvent(event); } diff --git a/src/msw/tbar95.cpp b/src/msw/tbar95.cpp index eeb63e3051..fb02e9d4b8 100644 --- a/src/msw/tbar95.cpp +++ b/src/msw/tbar95.cpp @@ -346,7 +346,7 @@ bool wxToolBar95::MSWCommand(WXUINT cmd, WXWORD id) return TRUE; } -bool wxToolBar95::MSWNotify(WXWPARAM WXUNUSED(wParam), +bool wxToolBar95::MSWOnNotify(int WXUNUSED(idCtrl), WXLPARAM lParam, WXLPARAM *result) { diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 630fc27176..8a4f405bd4 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -1234,7 +1234,7 @@ bool wxTextCtrl::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) // For Rich Edit controls. Do we need it? #if 0 #if wxUSE_RICHEDIT -bool wxTextCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam) +bool wxTextCtrl::MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam) { wxCommandEvent event(0, m_windowId); int eventType = 0; @@ -1243,7 +1243,7 @@ bool wxTextCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam) { // Insert case code here default : - return wxControl::MSWNotify(wParam, lParam); + return wxControl::MSWOnNotify(wParam, lParam); break; } diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 89f4ad0dbb..10ad765ff2 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -914,7 +914,7 @@ bool wxTreeCtrl::MSWCommand(WXUINT cmd, WXWORD id) } // process WM_NOTIFY Windows message -bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result) +bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) { wxTreeEvent event(wxEVT_NULL, m_windowId); wxEventType eventType = wxEVT_NULL; @@ -1050,7 +1050,7 @@ bool wxTreeCtrl::MSWNotify(WXWPARAM wParam, WXLPARAM lParam, WXLPARAM *result) } default: - return wxControl::MSWNotify(wParam, lParam, result); + return wxControl::MSWOnNotify(idCtrl, lParam, result); } event.SetEventObject(this); diff --git a/src/msw/window.cpp b/src/msw/window.cpp index aa59774ba1..3a7107fbba 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -2,15 +2,23 @@ // Name: windows.cpp // Purpose: wxWindow // Author: Julian Smart -// Modified by: +// Modified by: VZ on 13.05.99: no more Default(), MSWOnXXX() reorganisation // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart and Markus Holzem // Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// +// =========================================================================== +// declarations +// =========================================================================== + +// --------------------------------------------------------------------------- +// headers +// --------------------------------------------------------------------------- + #ifdef __GNUG__ -#pragma implementation "window.h" + #pragma implementation "window.h" #endif // For compilers that support precompilation, includes "wx.h". @@ -97,6 +105,18 @@ #undef GetClassInfo #endif +// --------------------------------------------------------------------------- +// macros +// --------------------------------------------------------------------------- + +// standard macros missing from some compilers headers +#ifndef GET_X_LPARAM + #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) + #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) +#endif // GET_X_LPARAM + +// --------------------------------------------------------------------------- +// --------------------------------------------------------------------------- #ifdef __WXDEBUG__ const char *wxGetMessageName(int message); #endif //__WXDEBUG__ @@ -114,14 +134,21 @@ wxWindow *wxFindWinFromHandle(WXHWND hWnd); IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) #endif +// --------------------------------------------------------------------------- +// event tables +// --------------------------------------------------------------------------- + BEGIN_EVENT_TABLE(wxWindow, wxWindowBase) - EVT_CHAR(wxWindow::OnChar) EVT_ERASE_BACKGROUND(wxWindow::OnEraseBackground) EVT_SYS_COLOUR_CHANGED(wxWindow::OnSysColourChanged) EVT_INIT_DIALOG(wxWindow::OnInitDialog) EVT_IDLE(wxWindow::OnIdle) END_EVENT_TABLE() +// =========================================================================== +// implementation +// =========================================================================== + // Find an item given the MS Windows id wxWindow *wxWindow::FindItem(int id) const { @@ -190,11 +217,43 @@ bool wxWindow::MSWCommand(WXUINT WXUNUSED(param), WXWORD WXUNUSED(id)) return FALSE; } -bool wxWindow::MSWNotify(WXWPARAM WXUNUSED(wParam), - WXLPARAM lParam, - WXLPARAM* WXUNUSED(result)) -{ #ifdef __WIN95__ +// FIXME: VZ: I'm not sure at all that the order of processing is correct +bool wxWindow::HandleNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) +{ + LPNMHDR hdr = (LPNMHDR)lParam; + HWND hWnd = hdr->hwndFrom; + wxWindow *win = wxFindWinFromHandle((WXHWND)hWnd); + + // is this one of our windows? + if ( win ) + { + return win->MSWOnNotify(idCtrl, lParam, result); + } + + // try all our children + wxWindowList::Node *node = GetChildren().GetFirst(); + while ( node ) + { + wxWindow *child = node->GetData(); + if ( child->MSWOnNotify(idCtrl, lParam, result) ) + { + return TRUE; + + break; + } + + node = node->GetNext(); + } + + // finally try this window too (catches toolbar case) + return MSWOnNotify(idCtrl, lParam, result); +} + +bool wxWindow::MSWOnNotify(int WXUNUSED(idCtrl), + WXLPARAM lParam, + WXLPARAM* WXUNUSED(result)) +{ #if wxUSE_TOOLTIPS NMHDR* hdr = (NMHDR *)lParam; if ( hdr->code == TTN_NEEDTEXT && m_tooltip ) @@ -205,11 +264,11 @@ bool wxWindow::MSWNotify(WXWPARAM WXUNUSED(wParam), // processed return TRUE; } -#endif -#endif +#endif // wxUSE_TOOLTIPS return FALSE; } +#endif // __WIN95__ void wxWindow::PreDelete(WXHDC WXUNUSED(dc)) { @@ -242,18 +301,17 @@ void wxWindow::Init() m_mouseInWindow = FALSE; // wxWnd - m_lastMsg = 0; - m_lastWParam = 0; - m_lastLParam = 0; m_hMenu = 0; m_xThumbSize = 0; m_yThumbSize = 0; m_backgroundTransparent = FALSE; +#if wxUSE_MOUSEEVENT_HACK m_lastMouseX = m_lastMouseY = -1; m_lastMouseEvent = -1; +#endif // wxUSE_MOUSEEVENT_HACK } // Destructor @@ -263,6 +321,11 @@ wxWindow::~wxWindow() MSWDetachWindowMenu(); + if ( m_parent ) + m_parent->RemoveChild(this); + + DestroyChildren(); + if ( m_hWnd ) ::DestroyWindow((HWND)m_hWnd); @@ -318,7 +381,7 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, void wxWindow::SetFocus() { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) ::SetFocus(hWnd); } @@ -328,7 +391,7 @@ bool wxWindow::Enable(bool enable) if ( !wxWindowBase::Enable(enable) ) return FALSE; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) ::EnableWindow(hWnd, (BOOL)enable); @@ -337,7 +400,7 @@ bool wxWindow::Enable(bool enable) void wxWindow::CaptureMouse() { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd && !m_winCaptured ) { SetCapture(hWnd); @@ -377,7 +440,7 @@ void wxWindow::SetDropTarget(wxDropTarget *pDropTarget) // JACS void wxWindow::DragAcceptFiles(bool accept) { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) ::DragAcceptFiles(hWnd, (BOOL)accept); } @@ -390,7 +453,7 @@ void wxWindow::DragAcceptFiles(bool accept) void wxWindow::DoSetToolTip(wxToolTip *tooltip) { - wxWindowBase::SetToolTip(tooltip); + wxWindowBase::DoSetToolTip(tooltip); if ( m_tooltip ) m_tooltip->SetWindow(this); @@ -401,7 +464,7 @@ void wxWindow::DoSetToolTip(wxToolTip *tooltip) // Get total size void wxWindow::DoGetSize(int *x, int *y) const { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); RECT rect; GetWindowRect(hWnd, &rect); @@ -413,7 +476,7 @@ void wxWindow::DoGetSize(int *x, int *y) const void wxWindow::DoGetPosition(int *x, int *y) const { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); HWND hParentWnd = 0; if ( GetParent() ) hParentWnd = (HWND) GetParent()->GetHWND(); @@ -454,7 +517,7 @@ void wxWindow::ScreenToClient(int *x, int *y) const if ( y ) pt.y = *y; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); ::ScreenToClient(hWnd, &pt); if ( x ) @@ -471,7 +534,7 @@ void wxWindow::ClientToScreen(int *x, int *y) const if ( y ) pt.y = *y; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); ::ClientToScreen(hWnd, &pt); if ( x ) @@ -491,7 +554,7 @@ bool wxWindow::SetCursor(const wxCursor& cursor) wxASSERT_MSG( m_cursor.Ok(), _T("cursor must be valid after call to the base version")); - HWND hWnd = (HWND)GetHWND(); + HWND hWnd = GetHwnd(); // Change the cursor NOW if we're within the correct window POINT point; @@ -509,7 +572,7 @@ bool wxWindow::SetCursor(const wxCursor& cursor) // Get size *available for subwindows* i.e. excluding menu bar etc. void wxWindow::DoGetClientSize(int *x, int *y) const { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); RECT rect; ::GetClientRect(hWnd, &rect); if ( x ) @@ -544,7 +607,7 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) if ( height == -1 ) actualHeight = currentH ; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) MoveWindow(hWnd, actualX, actualY, actualWidth, actualHeight, (BOOL)TRUE); } @@ -552,7 +615,7 @@ void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags) void wxWindow::DoSetClientSize(int width, int height) { wxWindow *parent = GetParent(); - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); HWND hParentWnd = (HWND) 0; if ( parent ) hParentWnd = (HWND) parent->GetHWND(); @@ -610,7 +673,7 @@ bool wxWindow::Show(bool show) if ( !wxWindowBase::Show(show) ) return FALSE; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); int cshow = show ? SW_SHOW : SW_HIDE; ::ShowWindow(hWnd, cshow); @@ -625,7 +688,7 @@ bool wxWindow::Show(bool show) int wxWindow::GetCharHeight(void) const { TEXTMETRIC lpTextMetric; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); HDC dc = ::GetDC(hWnd); GetTextMetrics(dc, &lpTextMetric); @@ -637,7 +700,7 @@ int wxWindow::GetCharHeight(void) const int wxWindow::GetCharWidth(void) const { TEXTMETRIC lpTextMetric; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); HDC dc = ::GetDC(hWnd); GetTextMetrics(dc, &lpTextMetric); @@ -653,7 +716,7 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, if ( !fontToUse ) fontToUse = (wxFont *) & m_font; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); HDC dc = ::GetDC(hWnd); HFONT fnt = 0; @@ -686,7 +749,7 @@ void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, void wxWindow::Refresh(bool eraseBack, const wxRect *rect) { - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) { if ( rect ) @@ -704,37 +767,27 @@ void wxWindow::Refresh(bool eraseBack, const wxRect *rect) } } -bool wxWindow::ProcessEvent(wxEvent& event) -{ - // we save here the information about the last message because it might be - // overwritten if the event handler sends any messages to our window (case - // in point: wxNotebook::OnSize) - and then if we call Default() later - // (which is done quite often if the message is not processed) it will use - // incorrect values for m_lastXXX variables - WXUINT lastMsg = m_lastMsg; - WXWPARAM lastWParam = m_lastWParam; - WXLPARAM lastLParam = m_lastLParam; - - // call the base version - bool bProcessed = wxEvtHandler::ProcessEvent(event); - - // restore - m_lastMsg = lastMsg; - m_lastWParam = lastWParam; - m_lastLParam = lastLParam; - - return bProcessed; -} +// --------------------------------------------------------------------------- +// Main wxWindows window proc and the window proc for wxWindow +// --------------------------------------------------------------------------- -// Hook for new window just as it's being created, -// when the window isn't yet associated with the handle +// Hook for new window just as it's being created, when the window isn't yet +// associated with the handle wxWindow *wxWndHook = NULL; // Main window proc LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { + // trace all messages - useful for the debugging +#ifdef __WXDEBUG__ + wxLogTrace(wxTraceMessages, "Processing %s(wParam=%8lx, lParam=%8lx)", + wxGetMessageName(message), wParam, lParam); +#endif // __WXDEBUG__ + wxWindow *wnd = wxFindWinFromHandle((WXHWND) hWnd); + // when we get the first message for the HWND we just created, we associate + // it with wxWindow stored in wxWndHook if ( !wnd && wxWndHook ) { wxAssociateWinWithHandle(hWnd, wxWndHook); @@ -743,597 +796,401 @@ LRESULT APIENTRY _EXPORT wxWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARA wnd->SetHWND((WXHWND)hWnd); } + LRESULT rc; + // Stop right here if we don't have a valid handle in our wxWindow object. - if ( wnd && !wnd->GetHWND() ) { + if ( wnd && !wnd->GetHWND() ) + { + // FIXME: why do we do this? wnd->SetHWND((WXHWND) hWnd); - long res = wnd->MSWDefWindowProc(message, wParam, lParam ); + rc = wnd->MSWDefWindowProc(message, wParam, lParam ); wnd->SetHWND(0); - return res; - } - - if ( wnd ) { - wnd->PushLastMessage(message, wParam, lParam); } - if ( wnd ) - return wnd->MSWWindowProc(message, wParam, lParam); else - return DefWindowProc( hWnd, message, wParam, lParam ); -} + { + if ( wnd ) + rc = wnd->MSWWindowProc(message, wParam, lParam); + else + rc = DefWindowProc( hWnd, message, wParam, lParam ); + } -// Should probably have a test for 'genuine' NT -#if defined(__WIN32__) - #define DIMENSION_TYPE short -#else - #define DIMENSION_TYPE int -#endif + return rc; +} -// Main Windows window proc long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { - wxASSERT( m_lastMsg == message && - m_lastWParam == wParam && m_lastLParam == lParam ); + // did we process the message? + bool processed = FALSE; -#ifdef __WXDEBUG__ - wxLogTrace(wxTraceMessages, "Processing %s(%lx, %lx)", - wxGetMessageName(message), wParam, lParam); -#endif // __WXDEBUG__ + // the return value + union + { + bool allow; + long result; + WXHICON hIcon; + WXHBRUSH hBrush; + } rc; + + // for most messages we should return 0 when we do process the message + rc.result = 0; - HWND hWnd = (HWND)m_hWnd; + HWND hWnd = GetHwnd(); - switch (message) + switch ( message ) { - case WM_ACTIVATE: - { + case WM_ACTIVATE: + { #ifdef __WIN32__ - WORD state = LOWORD(wParam); - WORD minimized = HIWORD(wParam); - HWND hwnd = (HWND)lParam; + WORD state = LOWORD(wParam); + WORD minimized = HIWORD(wParam); + HWND hwnd = (HWND)lParam; #else - WORD state = (WORD)wParam; - WORD minimized = LOWORD(lParam); - HWND hwnd = (HWND)HIWORD(lParam); + WORD state = (WORD)wParam; + WORD minimized = LOWORD(lParam); + HWND hwnd = (HWND)HIWORD(lParam); #endif - MSWOnActivate(state, (minimized != 0), (WXHWND) hwnd); - return 0; + processed = MSWOnActivate(state, minimized != 0, (WXHWND)hwnd); + } break; - } - case WM_SETFOCUS: - { - HWND hwnd = (HWND)wParam; - // return OnSetFocus(hwnd); - if ( MSWOnSetFocus((WXHWND) hwnd) ) - return 0; - else return MSWDefWindowProc(message, wParam, lParam ); - break; - } - case WM_KILLFOCUS: - { - HWND hwnd = (HWND)lParam; - // return OnKillFocus(hwnd); - if ( MSWOnKillFocus((WXHWND) hwnd) ) - return 0; - else - return MSWDefWindowProc(message, wParam, lParam ); - break; - } - case WM_CREATE: - { - MSWOnCreate((WXLPCREATESTRUCT) (LPCREATESTRUCT)lParam); - return 0; - break; - } - case WM_SHOWWINDOW: - { - MSWOnShow((wParam != 0), (int) lParam); - break; - } - case WM_PAINT: - { - if ( MSWOnPaint() ) - return 0; - else return MSWDefWindowProc(message, wParam, lParam ); + case WM_CLOSE: + // process this message for any toplevel window + if ( !GetParent() ) + { + // if we can't close, tell the system that we processed the + // message - otherwise it would close us + processed = !Close(); + } break; - } - case WM_QUERYDRAGICON: - { - HICON hIcon = (HICON)MSWOnQueryDragIcon(); - if ( hIcon ) - return (long)hIcon; - else - return MSWDefWindowProc(message, wParam, lParam ); + + case WM_SETFOCUS: + processed = MSWOnSetFocus((WXHWND)(HWND)wParam); break; - } - case WM_SIZE: - { - int width = LOWORD(lParam); - int height = HIWORD(lParam); - MSWOnSize(width, height, wParam); + case WM_KILLFOCUS: + processed = MSWOnKillFocus((WXHWND)(HWND)wParam); break; - } - case WM_MOVE: - { - wxMoveEvent event(wxPoint(LOWORD(lParam), HIWORD(lParam)), - m_windowId); - event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); - } - break; + case WM_CREATE: + { + bool allow; + processed = MSWOnCreate((WXLPCREATESTRUCT)lParam, &allow); - case WM_WINDOWPOSCHANGING: - { - MSWOnWindowPosChanging((void *)lParam); + // we should return 0 to allow window creation + rc.result = !allow; + } break; - } - case WM_RBUTTONDOWN: - { - int x = (DIMENSION_TYPE) LOWORD(lParam); - int y = (DIMENSION_TYPE) HIWORD(lParam); - MSWOnRButtonDown(x, y, wParam); - break; - } - case WM_RBUTTONUP: - { - int x = (DIMENSION_TYPE) LOWORD(lParam); - int y = (DIMENSION_TYPE) HIWORD(lParam); - MSWOnRButtonUp(x, y, wParam); + case WM_SHOWWINDOW: + processed = MSWOnShow(wParam != 0, (int)lParam); break; - } - case WM_RBUTTONDBLCLK: - { - int x = (DIMENSION_TYPE) LOWORD(lParam); - int y = (DIMENSION_TYPE) HIWORD(lParam); - MSWOnRButtonDClick(x, y, wParam); - break; - } - case WM_MBUTTONDOWN: - { - int x = (DIMENSION_TYPE) LOWORD(lParam); - int y = (DIMENSION_TYPE) HIWORD(lParam); - MSWOnMButtonDown(x, y, wParam); - break; - } - case WM_MBUTTONUP: - { - int x = (DIMENSION_TYPE) LOWORD(lParam); - int y = (DIMENSION_TYPE) HIWORD(lParam); - MSWOnMButtonUp(x, y, wParam); - break; - } - case WM_MBUTTONDBLCLK: - { - int x = (DIMENSION_TYPE) LOWORD(lParam); - int y = (DIMENSION_TYPE) HIWORD(lParam); - MSWOnMButtonDClick(x, y, wParam); + + case WM_PAINT: + processed = MSWOnPaint(); break; - } - case WM_LBUTTONDOWN: - { - int x = (DIMENSION_TYPE) LOWORD(lParam); - int y = (DIMENSION_TYPE) HIWORD(lParam); - MSWOnLButtonDown(x, y, wParam); + + case WM_QUERYDRAGICON: + processed = MSWOnQueryDragIcon(&rc.hIcon); break; - } - case WM_LBUTTONUP: - { - int x = (DIMENSION_TYPE) LOWORD(lParam); - int y = (DIMENSION_TYPE) HIWORD(lParam); - MSWOnLButtonUp(x, y, wParam); + + case WM_SIZE: + processed = MSWOnSize(LOWORD(lParam), HIWORD(lParam), wParam); break; - } - case WM_LBUTTONDBLCLK: - { - int x = (DIMENSION_TYPE) LOWORD(lParam); - int y = (DIMENSION_TYPE) HIWORD(lParam); - MSWOnLButtonDClick(x, y, wParam); + + case WM_MOVE: + processed = HandleMove(LOWORD(lParam), HIWORD(lParam)); break; - } - case WM_MOUSEMOVE: - { - int x = (DIMENSION_TYPE) LOWORD(lParam); - int y = (DIMENSION_TYPE) HIWORD(lParam); - MSWOnMouseMove(x, y, wParam); + + case WM_WINDOWPOSCHANGING: + processed = MSWOnWindowPosChanging((void *)lParam); break; - } - case MM_JOY1BUTTONDOWN: - { - int x = LOWORD(lParam); - int y = HIWORD(lParam); - MSWOnJoyDown(wxJOYSTICK1, x, y, wParam); + + case WM_MOUSEMOVE: + case WM_LBUTTONDOWN: + case WM_LBUTTONUP: + case WM_LBUTTONDBLCLK: + case WM_RBUTTONDOWN: + case WM_RBUTTONUP: + case WM_RBUTTONDBLCLK: + case WM_MBUTTONDOWN: + case WM_MBUTTONUP: + case WM_MBUTTONDBLCLK: + { + int x = LOWORD(lParam); + int y = HIWORD(lParam); + + processed = MSWOnMouseEvent(message, x, y, wParam); + } break; - } - case MM_JOY2BUTTONDOWN: - { - int x = LOWORD(lParam); - int y = HIWORD(lParam); - MSWOnJoyDown(wxJOYSTICK2, x, y, wParam); + + case MM_JOY1MOVE: + case MM_JOY2MOVE: + case MM_JOY1ZMOVE: + case MM_JOY2ZMOVE: + case MM_JOY1BUTTONDOWN: + case MM_JOY2BUTTONDOWN: + case MM_JOY1BUTTONUP: + case MM_JOY2BUTTONUP: + { + int x = LOWORD(lParam); + int y = HIWORD(lParam); + + processed = HandleJoystickEvent(message, x, y, wParam); + } break; - } - case MM_JOY1BUTTONUP: - { - int x = LOWORD(lParam); - int y = HIWORD(lParam); - MSWOnJoyUp(wxJOYSTICK1, x, y, wParam); + + case WM_DESTROY: + processed = MSWOnDestroy(); break; - } - case MM_JOY2BUTTONUP: - { - int x = LOWORD(lParam); - int y = HIWORD(lParam); - MSWOnJoyUp(wxJOYSTICK2, x, y, wParam); + + case WM_SYSCOMMAND: + processed = MSWOnSysCommand(wParam, lParam); break; - } - case MM_JOY1MOVE: - { - int x = LOWORD(lParam); - int y = HIWORD(lParam); - MSWOnJoyMove(wxJOYSTICK1, x, y, wParam); + + case WM_COMMAND: + { +#ifdef __WIN32__ + WORD id = LOWORD(wParam); + HWND hwnd = (HWND)lParam; + WORD cmd = HIWORD(wParam); +#else + WORD id = (WORD)wParam; + HWND hwnd = (HWND)LOWORD(lParam) ; + WORD cmd = HIWORD(lParam); +#endif + processed = MSWOnCommand(id, cmd, (WXHWND)hwnd); + } break; - } - case MM_JOY2MOVE: - { - int x = LOWORD(lParam); - int y = HIWORD(lParam); - MSWOnJoyMove(wxJOYSTICK2, x, y, wParam); + +#ifdef __WIN95__ + case WM_NOTIFY: + processed = HandleNotify((int)wParam, lParam, &rc.result); break; - } - case MM_JOY1ZMOVE: - { - int z = LOWORD(lParam); - MSWOnJoyZMove(wxJOYSTICK1, z, wParam); +#endif // Win95 + + // for these messages we must return TRUE if process the message + case WM_DRAWITEM: + case WM_MEASUREITEM: + { + int idCtrl = (UINT)wParam; + if ( message == WM_DRAWITEM ) + { + processed = MSWOnDrawItem(idCtrl, + (WXDRAWITEMSTRUCT *)lParam); + } + else + { + processed = MSWOnMeasureItem(idCtrl, + (WXMEASUREITEMSTRUCT *)lParam); + } + + if ( processed ) + rc.result = TRUE; + } break; - } - case MM_JOY2ZMOVE: - { - int z = LOWORD(lParam); - MSWOnJoyZMove(wxJOYSTICK2, z, wParam); + + case WM_KEYDOWN: + // If this has been processed by an event handler, + // return 0 now (we've handled it). + if ( MSWOnKeyDown((WORD) wParam, lParam) ) + { + processed = TRUE; + + break; + } + + // we consider these message "not interesting" to OnChar + if ( wParam == VK_SHIFT || wParam == VK_CONTROL ) + { + break; + } + + switch ( wParam ) + { + // avoid duplicate messages to OnChar for these ASCII keys: they + // will be translated by TranslateMessage() and received in WM_CHAR + case VK_ESCAPE: + case VK_SPACE: + case VK_RETURN: + case VK_BACK: + case VK_TAB: + break; + +#ifdef VK_APPS + // special case of VK_APPS: treat it the same as right mouse + // click because both usually pop up a context menu + case VK_APPS: + { + // construct the key mask + WPARAM fwKeys = MK_RBUTTON; + if ( (::GetKeyState(VK_CONTROL) & 0x100) != 0 ) + fwKeys |= MK_CONTROL; + if ( (::GetKeyState(VK_SHIFT) & 0x100) != 0 ) + fwKeys |= MK_SHIFT; + + // simulate right mouse button click + DWORD dwPos = ::GetMessagePos(); + int x = GET_X_LPARAM(dwPos), + y = GET_Y_LPARAM(dwPos); + + ScreenToClient(&x, &y); + processed = MSWOnMouseEvent(WM_RBUTTONDOWN, x, y, fwKeys); + } + break; +#endif // VK_APPS + + case VK_LEFT: + case VK_RIGHT: + case VK_DOWN: + case VK_UP: + default: + processed = MSWOnChar((WORD)wParam, lParam); + } break; - } - case WM_DESTROY: - { - if ( MSWOnDestroy() ) - return 0; - else return MSWDefWindowProc(message, wParam, lParam ); + + case WM_KEYUP: + processed = MSWOnKeyUp((WORD) wParam, lParam); break; - } - case WM_SYSCOMMAND: - { - return MSWOnSysCommand(wParam, lParam); + + case WM_CHAR: // Always an ASCII character + processed = MSWOnChar((WORD)wParam, lParam, TRUE); break; - } - case WM_COMMAND: - { + case WM_HSCROLL: + case WM_VSCROLL: + { #ifdef __WIN32__ - WORD id = LOWORD(wParam); - HWND hwnd = (HWND)lParam; - WORD cmd = HIWORD(wParam); + WORD code = LOWORD(wParam); + WORD pos = HIWORD(wParam); + HWND control = (HWND)lParam; #else - WORD id = (WORD)wParam; - HWND hwnd = (HWND)LOWORD(lParam) ; - WORD cmd = HIWORD(lParam); + WORD code = (WORD)wParam; + WORD pos = LOWORD(lParam); + HWND control = (HWND)HIWORD(lParam); #endif - if ( !MSWOnCommand(id, cmd, (WXHWND) hwnd) ) - return MSWDefWindowProc(message, wParam, lParam ); + processed = MSWOnScroll(message == WM_HSCROLL ? wxHORIZONTAL + : wxVERTICAL, + code, pos, (WXHWND)control); + } break; - } -#if defined(__WIN95__) - case WM_NOTIFY: - { - // for some messages (TVN_ITEMEXPANDING for example), the return - // value of WM_NOTIFY handler is important, so don't just return 0 - // if we processed the message - return MSWOnNotify(wParam, lParam); - } -#endif - case WM_MENUSELECT: - { + + // CTLCOLOR messages are sent by children to query the parent for their + // colors #ifdef __WIN32__ - WORD flags = HIWORD(wParam); - HMENU sysmenu = (HMENU)lParam; -#else - WORD flags = LOWORD(lParam); - HMENU sysmenu = (HMENU)HIWORD(lParam); -#endif - MSWOnMenuHighlight((WORD)wParam, flags, (WXHMENU) sysmenu); - break; - } - case WM_INITMENUPOPUP: - { - MSWOnInitMenuPopup((WXHMENU) (HMENU)wParam, (int)LOWORD(lParam), (HIWORD(lParam) != 0)); - break; - } - case WM_DRAWITEM: - { - return MSWOnDrawItem((int)wParam, (WXDRAWITEMSTRUCT *)lParam); - break; - } - case WM_MEASUREITEM: - { - return MSWOnMeasureItem((int)wParam, (WXMEASUREITEMSTRUCT *)lParam); - break; - } - case WM_KEYDOWN: - // If this has been processed by an event handler, - // return 0 now (we've handled it). - if ( MSWOnKeyDown((WORD) wParam, lParam) ) - break; + case WM_CTLCOLORMSGBOX: + case WM_CTLCOLOREDIT: + case WM_CTLCOLORLISTBOX: + case WM_CTLCOLORBTN: + case WM_CTLCOLORDLG: + case WM_CTLCOLORSCROLLBAR: + case WM_CTLCOLORSTATIC: + { + int nCtlColor = CTLCOLOR_BTN; + HWND control = (HWND)lParam; + HDC hdc = (HDC)wParam; - // we consider these message "not interesting" to OnChar - if ( wParam == VK_SHIFT || wParam == VK_CONTROL ) - { - return Default(); - } + processed = MSWOnCtlColor(&rc.hBrush, (WXHDC)hdc, (WXHWND)control, + nCtlColor, message, wParam, lParam); + break; + } +#else // Win16 + case WM_CTLCOLOR: + { + HWND control = (HWND)LOWORD(lParam); + int nCtlColor = (int)HIWORD(lParam); + HDC hdc = (HDC)wParam; - switch ( wParam ) - { - // avoid duplicate messages to OnChar for these ASCII keys: they - // will be translated by TranslateMessage() and received in WM_CHAR - case VK_ESCAPE: - case VK_SPACE: - case VK_RETURN: - case VK_BACK: - case VK_TAB: - return Default(); + processed = MSWOnCtlColor(&rc.hBrush, (WXHDC)hdc, (WXHWND)control, + nCtlColor, message, wParam, lParam); + } + break; +#endif // Win32/16 -#ifdef VK_APPS + // the return value for this message is ignored + case WM_SYSCOLORCHANGE: + { + wxSysColourChangedEvent event; + event.SetEventObject(this); - // normally these macros would be defined in windows.h -#ifndef GET_X_LPARAM - #define GET_X_LPARAM(lp) ((int)(short)LOWORD(lp)) - #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) -#endif + processed = GetEventHandler()->ProcessEvent(event); + } + break; - // special case of VK_APPS: treat it the same as right mouse click - // because both usually pop up a context menu - case VK_APPS: - { - // construct the key mask - WPARAM fwKeys = MK_RBUTTON; - if ( (::GetKeyState(VK_CONTROL) & 0x100) != 0 ) - fwKeys |= MK_CONTROL; - if ( (::GetKeyState(VK_SHIFT) & 0x100) != 0 ) - fwKeys |= MK_SHIFT; - - // simulate right mouse button click - DWORD dwPos = ::GetMessagePos(); - int x = GET_X_LPARAM(dwPos), - y = GET_Y_LPARAM(dwPos); - - ScreenToClient(&x, &y); - MSWOnRButtonDown(x, y, fwKeys); - } - break; -#endif // VK_APPS + case WM_PALETTECHANGED: + processed = MSWOnPaletteChanged((WXHWND) (HWND) wParam); + break; - case VK_LEFT: - case VK_RIGHT: - case VK_DOWN: - case VK_UP: - default: - if ( !MSWOnChar((WORD)wParam, lParam) ) - { - return Default(); - } - break; - } - break; + case WM_QUERYNEWPALETTE: + processed = MSWOnQueryNewPalette(); + break; - case WM_KEYUP: - if ( !MSWOnKeyUp((WORD) wParam, lParam) ) - return Default(); - break; + // return TRUE if we erase the background + case WM_ERASEBKGND: + // Prevents flicker when dragging + if ( IsIconic(hWnd) ) return 1; - case WM_CHAR: // Always an ASCII character - if ( !MSWOnChar((WORD)wParam, lParam, TRUE) ) - return Default(); - break; + if ( !MSWOnEraseBkgnd((WXHDC) (HDC)wParam) ) + return 0; + else return 1; + break; - case WM_HSCROLL: - { + case WM_MDIACTIVATE: + { #ifdef __WIN32__ - WORD code = LOWORD(wParam); - WORD pos = HIWORD(wParam); - HWND control = (HWND)lParam; + HWND hWndActivate = GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam,lParam); + HWND hWndDeactivate = GET_WM_MDIACTIVATE_HWNDDEACT(wParam,lParam); + BOOL activate = GET_WM_MDIACTIVATE_FACTIVATE(hWnd,wParam,lParam); + processed = MSWOnMDIActivate((long)activate, + (WXHWND)hWndActivate, + (WXHWND)hWndDeactivate); #else - WORD code = (WORD)wParam; - WORD pos = LOWORD(lParam); - HWND control = (HWND)HIWORD(lParam); + processed = MSWOnMDIActivate((BOOL)wParam, + (HWND)LOWORD(lParam), + (HWND)HIWORD(lParam)); #endif - MSWOnHScroll(code, pos, (WXHWND) control); + } break; - } - case WM_VSCROLL: - { -#ifdef __WIN32__ - WORD code = LOWORD(wParam); - WORD pos = HIWORD(wParam); - HWND control = (HWND)lParam; -#else - WORD code = (WORD)wParam; - WORD pos = LOWORD(lParam); - HWND control = (HWND)HIWORD(lParam); -#endif - MSWOnVScroll(code, pos, (WXHWND) control); - break; - } -#ifdef __WIN32__ - case WM_CTLCOLORBTN: - { - int nCtlColor = CTLCOLOR_BTN; - HWND control = (HWND)lParam; - HDC pDC = (HDC)wParam; - return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, - message, wParam, lParam); - break; - } - case WM_CTLCOLORDLG: - { - int nCtlColor = CTLCOLOR_DLG; - HWND control = (HWND)lParam; - HDC pDC = (HDC)wParam; - return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, - message, wParam, lParam);\ - break; - } - case WM_CTLCOLORLISTBOX: - { - int nCtlColor = CTLCOLOR_LISTBOX; - HWND control = (HWND)lParam; - HDC pDC = (HDC)wParam; - return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, - message, wParam, lParam); - break; - } - case WM_CTLCOLORMSGBOX: - { - int nCtlColor = CTLCOLOR_MSGBOX; - HWND control = (HWND)lParam; - HDC pDC = (HDC)wParam; - return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, - message, wParam, lParam); - break; - } - case WM_CTLCOLORSCROLLBAR: - { - int nCtlColor = CTLCOLOR_SCROLLBAR; - HWND control = (HWND)lParam; - HDC pDC = (HDC)wParam; - return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, - message, wParam, lParam); - break; - } - case WM_CTLCOLORSTATIC: - { - int nCtlColor = CTLCOLOR_STATIC; - HWND control = (HWND)lParam; - HDC pDC = (HDC)wParam; - return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, - message, wParam, lParam); - break; - } - case WM_CTLCOLOREDIT: - { - int nCtlColor = CTLCOLOR_EDIT; - HWND control = (HWND)lParam; - HDC pDC = (HDC)wParam; - return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, - message, wParam, lParam); - break; - } -#else - case WM_CTLCOLOR: - { - HWND control = (HWND)LOWORD(lParam); - int nCtlColor = (int)HIWORD(lParam); - HDC pDC = (HDC)wParam; - return (DWORD)MSWOnCtlColor((WXHDC) pDC, (WXHWND) control, nCtlColor, - message, wParam, lParam); - break; - } -#endif - case WM_SYSCOLORCHANGE: - { - // Return value of 0 means, we processed it. - if ( MSWOnColorChange((WXHWND) hWnd, message, wParam, lParam) == 0 ) - return 0; - else - return MSWDefWindowProc(message, wParam, lParam ); - break; - } - case WM_PALETTECHANGED: - { - return MSWOnPaletteChanged((WXHWND) (HWND) wParam); - break; - } - case WM_QUERYNEWPALETTE: - { - return MSWOnQueryNewPalette(); - break; - } - case WM_ERASEBKGND: - { - // Prevents flicker when dragging - if ( IsIconic(hWnd) ) return 1; - if ( !MSWOnEraseBkgnd((WXHDC) (HDC)wParam) ) - return 0; // Default(); MSWDefWindowProc(message, wParam, lParam ); - else return 1; + case WM_DROPFILES: + processed = MSWOnDropFiles(wParam); break; - } - case WM_MDIACTIVATE: - { -#ifdef __WIN32__ - HWND hWndActivate = GET_WM_MDIACTIVATE_HWNDACTIVATE(wParam,lParam); - HWND hWndDeactivate = GET_WM_MDIACTIVATE_HWNDDEACT(wParam,lParam); - BOOL activate = GET_WM_MDIACTIVATE_FACTIVATE(hWnd,wParam,lParam); - return MSWOnMDIActivate((long) activate, (WXHWND) hWndActivate, (WXHWND) hWndDeactivate); -#else - return MSWOnMDIActivate((BOOL)wParam, (HWND)LOWORD(lParam), - (HWND)HIWORD(lParam)); -#endif - } - case WM_DROPFILES: - { - MSWOnDropFiles(wParam); - break; - } - case WM_INITDIALOG: - { + + case WM_INITDIALOG: + wxFAIL_MSG("to fix"); + return 0; // MSWOnInitDialog((WXHWND)(HWND)wParam); - break; - } - case WM_QUERYENDSESSION: - { - // Same as WM_CLOSE, but inverted results. Thx Microsoft :-) - // return MSWOnClose(); - return MSWOnQueryEndSession(lParam); + // we never set focus from here + rc.result = FALSE; break; - } - case WM_ENDSESSION: - { - // Same as WM_CLOSE, but inverted results. Thx Microsoft :-) - MSWOnEndSession((wParam != 0), lParam); - return 0L; + + case WM_QUERYENDSESSION: + processed = MSWOnQueryEndSession(lParam, &rc.allow); break; - } - case WM_CLOSE: - { - if ( MSWOnClose() ) - return 0L; - else - return 1L; + + case WM_ENDSESSION: + processed = MSWOnEndSession(wParam != 0, lParam); break; - } - case WM_GETMINMAXINFO: - { - MINMAXINFO *info = (MINMAXINFO *)lParam; - if ( m_minWidth != -1 ) - info->ptMinTrackSize.x = m_minWidth; - if ( m_minHeight != -1 ) - info->ptMinTrackSize.y = m_minHeight; - if ( m_maxWidth != -1 ) - info->ptMaxTrackSize.x = m_maxWidth; - if ( m_maxHeight != -1 ) - info->ptMaxTrackSize.y = m_maxHeight; - return MSWDefWindowProc(message, wParam, lParam ); + + case WM_GETMINMAXINFO: + { + MINMAXINFO *info = (MINMAXINFO *)lParam; + if ( m_minWidth != -1 ) + info->ptMinTrackSize.x = m_minWidth; + if ( m_minHeight != -1 ) + info->ptMinTrackSize.y = m_minHeight; + if ( m_maxWidth != -1 ) + info->ptMaxTrackSize.x = m_maxWidth; + if ( m_maxHeight != -1 ) + info->ptMaxTrackSize.y = m_maxHeight; + } break; - } - case WM_GETDLGCODE: - { - return MSWGetDlgCode(); - } - case WM_SETCURSOR: - { + + case WM_SETCURSOR: // don't set cursor for other windows, only for this one: this - // prevents children of this window from getting the same cursor - // as the parent has (don't forget that this message is propagated - // by default up the window parent-child hierarchy) + // prevents children of this window from getting the same cursor as + // the parent has (don't forget that this message is propagated by + // default up the window parent-child hierarchy) if ( (HWND)wParam == hWnd ) { // don't set cursor when the mouse is not in the client part @@ -1376,18 +1233,23 @@ long wxWindow::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) // returning TRUE stops the DefWindowProc() from // further processing this message - exactly what we // need because we've just set the cursor. - return TRUE; + rc.result = TRUE; + processed = TRUE; } } } - } - return MSWDefWindowProc(message, wParam, lParam ); + } - default: - return MSWDefWindowProc(message, wParam, lParam ); + if ( !processed ) + { +#ifdef __WXDEBUG__ + wxLogTrace(wxTraceMessages, "Forwarding %s to DefWindowProc.", + wxGetMessageName(message)); +#endif // __WXDEBUG__ + rc.result = MSWDefWindowProc(message, wParam, lParam); } - return 0; // Success: we processed this command. + return rc.result; } // Dialog window proc @@ -1427,11 +1289,19 @@ void wxWindow::MSWDestroyWindow() { } -void wxWindow::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow *wx_win, const char *title, - int x, int y, int width, int height, - WXDWORD style, const char *dialog_template, WXDWORD extendedStyle) +bool wxWindow::MSWCreate(int id, + wxWindow *parent, + const char *wclass, + wxWindow *wx_win, + const char *title, + int x, + int y, + int width, + int height, + WXDWORD style, + const char *dialog_template, + WXDWORD extendedStyle) { - bool is_dialog = (dialog_template != NULL); int x1 = CW_USEDEFAULT; int y1 = 0; int width1 = CW_USEDEFAULT; @@ -1442,7 +1312,6 @@ void wxWindow::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow RECT parent_rect; if ( parent ) { - // Was GetWindowRect: JACS 5/5/95 ::GetClientRect((HWND) parent->GetHWND(), &parent_rect); width1 = parent_rect.right - parent_rect.left; @@ -1460,100 +1329,92 @@ void wxWindow::MSWCreate(int id, wxWindow *parent, const char *wclass, wxWindow wxWndHook = this; - if ( is_dialog ) + if ( dialog_template ) { - // MakeProcInstance doesn't seem to be needed in C7. Is it needed for - // other compilers??? - // VZ: it's always needed for Win16 and never for Win32 -#ifdef __WIN32__ - m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent, - (DLGPROC)wxDlgProc); -#else - // N.B.: if we _don't_ use this form, - // then with VC++ 1.5, it crashes horribly. -#if 1 - m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent, - (DLGPROC)wxDlgProc); -#else - // Crashes when we use this. - DLGPROC dlgproc = (DLGPROC)MakeProcInstance((DLGPROC)wxWndProc, wxGetInstance()); - - m_hWnd = (WXHWND) ::CreateDialog(wxGetInstance(), dialog_template, hParent, - (DLGPROC)dlgproc); -#endif -#endif + m_hWnd = (WXHWND)::CreateDialog(wxGetInstance(), + dialog_template, + hParent, + (DLGPROC)wxDlgProc); if ( m_hWnd == 0 ) - MessageBox(NULL, "Can't find dummy dialog template!\nCheck resource include path for finding wx.rc.", - "wxWindows Error", MB_ICONEXCLAMATION | MB_OK); - else MoveWindow((HWND) m_hWnd, x1, y1, width1, height1, FALSE); + { + wxLogError(_("Can't find dummy dialog template!\n" + "Check resource include path for finding wx.rc.")); + + return FALSE; + } + + ::MoveWindow(GetHwnd(), x1, y1, width1, height1, FALSE); } else { int controlId = 0; if ( style & WS_CHILD ) controlId = id; - if ( !title ) - title = ""; - - m_hWnd = (WXHWND)CreateWindowEx(extendedStyle, wclass, - title, - style, - x1, y1, - width1, height1, - hParent, (HMENU)controlId, wxGetInstance(), - NULL); - - if ( !m_hWnd ) { - wxLogError("Can't create window of class %s!\n" - "Possible Windows 3.x compatibility problem?", wclass); + + m_hWnd = (WXHWND)CreateWindowEx(extendedStyle, + wclass, + title ? title : "", + style, + x1, y1, + width1, height1, + hParent, (HMENU)controlId, + wxGetInstance(), + NULL); + + if ( !m_hWnd ) + { + wxLogError(_("Can't create window of class %s!\n" + "Possible Windows 3.x compatibility problem?"), + wclass); + + return FALSE; } } wxWndHook = NULL; wxWinHandleList->Append((long)m_hWnd, this); -} -void wxWindow::MSWOnCreate(WXLPCREATESTRUCT WXUNUSED(cs)) -{ + return TRUE; } -bool wxWindow::MSWOnClose() +bool wxWindow::MSWOnCreate(WXLPCREATESTRUCT WXUNUSED(cs), bool *mayCreate) { - return FALSE; -} + *mayCreate = TRUE; -// Some compilers don't define this -#ifndef ENDSESSION_LOGOFF -#define ENDSESSION_LOGOFF 0x80000000 -#endif + return TRUE; +} -// Return TRUE to end session, FALSE to veto end session. -bool wxWindow::MSWOnQueryEndSession(long logOff) +bool wxWindow::MSWOnQueryEndSession(long logOff, bool *mayEnd) { wxCloseEvent event(wxEVT_QUERY_END_SESSION, -1); event.SetEventObject(wxTheApp); event.SetCanVeto(TRUE); - event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) ); - if ( (this == wxTheApp->GetTopWindow() ) && // Only send once - wxTheApp->ProcessEvent(event) && event.GetVeto()) - { - return FALSE; // Veto! - } - else + event.SetLoggingOff(logOff == ENDSESSION_LOGOFF); + + bool rc = wxTheApp->ProcessEvent(event); + + if ( rc ) { - return TRUE; // Don't veto + // we may end only if the app didn't veto session closing (double + // negation...) + *mayEnd = !event.GetVeto(); } + + return rc; } bool wxWindow::MSWOnEndSession(bool endSession, long logOff) { + // do nothing if the session isn't ending + if ( !endSession ) + return FALSE; + wxCloseEvent event(wxEVT_END_SESSION, -1); event.SetEventObject(wxTheApp); event.SetCanVeto(FALSE); event.SetLoggingOff( (logOff == ENDSESSION_LOGOFF) ); - if (endSession && // No need to send if the session isn't ending - (this == wxTheApp->GetTopWindow()) && // Only send once + if ( (this == wxTheApp->GetTopWindow()) && // Only send once wxTheApp->ProcessEvent(event)) { } @@ -1575,72 +1436,21 @@ bool wxWindow::MSWOnDestroy() return TRUE; } -// Deal with child commands from buttons etc. - -long wxWindow::MSWOnNotify(WXWPARAM wParam, WXLPARAM lParam) -{ -#if defined(__WIN95__) - // Find a child window to send the notification to, e.g. a toolbar. - // There's a problem here. NMHDR::hwndFrom doesn't give us the - // handle of the toolbar; it's probably the handle of the tooltip - // window (anyway, it's parent is also the toolbar's parent). - // So, since we don't know which hWnd or wxWindow originated the - // WM_NOTIFY, we'll need to go through all the children of this window - // trying out MSWNotify. - // This won't work now, though, because any number of controls - // could respond to the same generic messages :-( - - /* This doesn't work for toolbars, but try for other controls first. - */ - NMHDR *hdr = (NMHDR *)lParam; - HWND hWnd = (HWND)hdr->hwndFrom; - wxWindow *win = wxFindWinFromHandle((WXHWND) hWnd); - - WXLPARAM result = 0; - - if ( win ) - { - if ( win->MSWNotify(wParam, lParam, &result) ) - return result; - } - else - { - // Rely on MSWNotify to check whether the message - // belongs to the window or not - wxNode *node = GetChildren().First(); - while (node) - { - wxWindow *child = (wxWindow *)node->Data(); - if ( child->MSWNotify(wParam, lParam, &result) ) - return result; - node = node->Next(); - } - - // finally try this window too (catches toolbar case) - if ( MSWNotify(wParam, lParam, &result) ) - return result; - } -#endif // Win95 - - // not processed - return Default(); -} - -void wxWindow::MSWOnMenuHighlight(WXWORD WXUNUSED(item), WXWORD WXUNUSED(flags), WXHMENU WXUNUSED(sysmenu)) -{ -} - -void wxWindow::MSWOnInitMenuPopup(WXHMENU menu, int pos, bool isSystem) +bool wxWindow::MSWOnMDIActivate(long WXUNUSED(flag), + WXHWND WXUNUSED(activate), + WXHWND WXUNUSED(deactivate)) { + return FALSE; } bool wxWindow::MSWOnActivate(int state, bool WXUNUSED(minimized), WXHWND WXUNUSED(activate)) { - wxActivateEvent event(wxEVT_ACTIVATE, ((state == WA_ACTIVE) || (state == WA_CLICKACTIVE)), - m_windowId); + wxActivateEvent event(wxEVT_ACTIVATE, + (state == WA_ACTIVE) || (state == WA_CLICKACTIVE), + m_windowId); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); - return 0; + + return GetEventHandler()->ProcessEvent(event); } bool wxWindow::MSWOnSetFocus(WXHWND WXUNUSED(hwnd)) @@ -1648,9 +1458,9 @@ bool wxWindow::MSWOnSetFocus(WXHWND WXUNUSED(hwnd)) // Deal with caret if ( m_caretEnabled && (m_caretWidth > 0) && (m_caretHeight > 0) ) { - ::CreateCaret((HWND) GetHWND(), NULL, m_caretWidth, m_caretHeight); + ::CreateCaret(GetHwnd(), NULL, m_caretWidth, m_caretHeight); if ( m_caretShown ) - ::ShowCaret((HWND) GetHWND()); + ::ShowCaret(GetHwnd()); } // panel wants to track the window which was the last to have focus in it @@ -1662,9 +1472,7 @@ bool wxWindow::MSWOnSetFocus(WXHWND WXUNUSED(hwnd)) wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId); event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); - return TRUE; + return GetEventHandler()->ProcessEvent(event); } bool wxWindow::MSWOnKillFocus(WXHWND WXUNUSED(hwnd)) @@ -1677,12 +1485,10 @@ bool wxWindow::MSWOnKillFocus(WXHWND WXUNUSED(hwnd)) wxFocusEvent event(wxEVT_KILL_FOCUS, m_windowId); event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); - return TRUE; + return GetEventHandler()->ProcessEvent(event); } -void wxWindow::MSWOnDropFiles(WXWPARAM wParam) +bool wxWindow::MSWOnDropFiles(WXWPARAM wParam) { HDROP hFilesInfo = (HDROP) wParam; @@ -1708,10 +1514,11 @@ void wxWindow::MSWOnDropFiles(WXWPARAM wParam) event.m_eventObject = this; event.m_pos.x = dropPoint.x; event.m_pos.x = dropPoint.y; - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); + bool rc = GetEventHandler()->ProcessEvent(event); delete[] files; + + return rc; } bool wxWindow::MSWOnDrawItem(int id, WXDRAWITEMSTRUCT *itemStruct) @@ -1771,68 +1578,59 @@ bool wxWindow::MSWOnMeasureItem(int id, WXMEASUREITEMSTRUCT *itemStruct) return FALSE; } -WXHBRUSH wxWindow::MSWOnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +bool wxWindow::MSWOnCtlColor(WXHBRUSH *brush, + WXHDC pDC, + WXHWND pWnd, + WXUINT nCtlColor, + WXUINT message, + WXWPARAM wParam, + WXLPARAM lParam) { + WXHBRUSH hBrush = 0; + if ( nCtlColor == CTLCOLOR_DLG ) { - return OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); + hBrush = OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); + } + else + { + wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE); + if ( item ) + hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); } - wxControl *item = (wxControl *)FindItemByHWND(pWnd, TRUE); - - WXHBRUSH hBrush = 0; - - if ( item ) - hBrush = item->OnCtlColor(pDC, pWnd, nCtlColor, message, wParam, lParam); - - // I think that even for dialogs, we may need to call DefWindowProc (?) - // Or maybe just rely on the usual default behaviour. - if ( !hBrush ) - hBrush = (WXHBRUSH) MSWDefWindowProc(message, wParam, lParam); + if ( hBrush ) + *brush = hBrush; - return hBrush ; + return hBrush != 0; } // Define for each class of dialog and control -WXHBRUSH wxWindow::OnCtlColor(WXHDC pDC, WXHWND pWnd, WXUINT nCtlColor, - WXUINT message, WXWPARAM wParam, WXLPARAM lParam) +WXHBRUSH wxWindow::OnCtlColor(WXHDC hDC, + WXHWND hWnd, + WXUINT nCtlColor, + WXUINT message, + WXWPARAM wParam, + WXLPARAM lParam) { - return (WXHBRUSH) MSWDefWindowProc(message, wParam, lParam); -} - -bool wxWindow::MSWOnColorChange(WXHWND hWnd, WXUINT message, WXWPARAM wParam, WXLPARAM lParam) -{ - wxSysColourChangedEvent event; - event.SetEventObject(this); - - // Check if app handles this. - if ( GetEventHandler()->ProcessEvent(event) ) - return 0; - - // We didn't process it - return 1; + return (WXHBRUSH)0; } -long wxWindow::MSWOnPaletteChanged(WXHWND hWndPalChange) +bool wxWindow::MSWOnPaletteChanged(WXHWND hWndPalChange) { wxPaletteChangedEvent event(GetId()); event.SetEventObject(this); event.SetChangedWindow(wxFindWinFromHandle(hWndPalChange)); - GetEventHandler()->ProcessEvent(event); - return 0; + + return GetEventHandler()->ProcessEvent(event); } -long wxWindow::MSWOnQueryNewPalette() +bool wxWindow::MSWOnQueryNewPalette() { wxQueryNewPaletteEvent event(GetId()); event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) || !event.GetPaletteRealized() ) - { - return (long) FALSE; - } - else - return (long) TRUE; + + return GetEventHandler()->ProcessEvent(event) && event.GetPaletteRealized(); } // Responds to colour changes: passes event on to children. @@ -1857,24 +1655,9 @@ void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event) long wxWindow::MSWDefWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) { if ( m_oldWndProc ) - return ::CallWindowProc(CASTWNDPROC m_oldWndProc, (HWND) GetHWND(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam); + return ::CallWindowProc(CASTWNDPROC m_oldWndProc, GetHwnd(), (UINT) nMsg, (WPARAM) wParam, (LPARAM) lParam); else - return ::DefWindowProc((HWND) GetHWND(), nMsg, wParam, lParam); -} - -long wxWindow::Default() -{ - // Ignore 'fake' events (perhaps generated as a result of a separate real - // event) - if ( m_lastMsg == 0 ) - return 0; - -#ifdef __WXDEBUG__ - wxLogTrace(wxTraceMessages, "Forwarding %s to DefWindowProc.", - wxGetMessageName(m_lastMsg)); -#endif // __WXDEBUG__ - - return MSWDefWindowProc(m_lastMsg, m_lastWParam, m_lastLParam); + return ::DefWindowProc(GetHwnd(), nMsg, wParam, lParam); } bool wxWindow::MSWProcessMessage(WXMSG* pMsg) @@ -1975,7 +1758,7 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) } } - if ( ::IsDialogMessage((HWND)GetHWND(), msg) ) + if ( ::IsDialogMessage(GetHwnd(), msg) ) return TRUE; } @@ -1998,7 +1781,7 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) if ( m_hWnd != 0 && (GetWindowStyleFlag() & wxTAB_TRAVERSAL) == 0 ) { MSG *msg = (MSG *)pMsg; - if ( ::IsDialogMessage((HWND)GetHWND(), msg) ) + if ( ::IsDialogMessage(GetHwnd(), msg) ) return TRUE; } */ @@ -2008,17 +1791,12 @@ bool wxWindow::MSWProcessMessage(WXMSG* pMsg) bool wxWindow::MSWTranslateMessage(WXMSG* pMsg) { if ( m_acceleratorTable.Ok( ) && - ::TranslateAccelerator((HWND) GetHWND(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg)) + ::TranslateAccelerator(GetHwnd(), (HACCEL) m_acceleratorTable.GetHACCEL(), (MSG *)pMsg)) return TRUE; else return FALSE; } -long wxWindow::MSWOnMDIActivate(long WXUNUSED(flag), WXHWND WXUNUSED(activate), WXHWND WXUNUSED(deactivate)) -{ - return 1; -} - void wxWindow::MSWDetachWindowMenu() { if ( m_hMenu ) @@ -2042,260 +1820,102 @@ bool wxWindow::MSWOnPaint() { #ifdef __WIN32__ HRGN hRegion = ::CreateRectRgn(0, 0, 0, 0); // Dummy call to get a handle - ::GetUpdateRgn((HWND) GetHWND(), hRegion, FALSE); + ::GetUpdateRgn(GetHwnd(), hRegion, FALSE); m_updateRegion = wxRegion((WXHRGN) hRegion); #else RECT updateRect; - ::GetUpdateRect((HWND) GetHWND(), & updateRect, FALSE); + ::GetUpdateRect(GetHwnd(), & updateRect, FALSE); m_updateRegion = wxRegion(updateRect.left, updateRect.top, - updateRect.right - updateRect.left, updateRect.bottom - updateRect.top); -#endif - - wxPaintEvent event(m_windowId); - event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); - return TRUE; -} - -void wxWindow::MSWOnSize(int w, int h, WXUINT WXUNUSED(flag)) -{ - if ( m_inOnSize ) - return; - - if ( !m_hWnd ) - return; - - m_inOnSize = TRUE; - - wxSizeEvent event(wxSize(w, h), m_windowId); - event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); - - m_inOnSize = FALSE; -} - -void wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos)) -{ - Default(); -} - -// Deal with child commands from buttons etc. -bool wxWindow::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) -{ - if ( wxCurrentPopupMenu ) - { - wxMenu *popupMenu = wxCurrentPopupMenu; - wxCurrentPopupMenu = NULL; - bool succ = popupMenu->MSWCommand(cmd, id); - return succ; - } - - wxWindow *item = FindItem(id); - if ( item ) - { - bool value = item->MSWCommand(cmd, id); - return value; - } - else - { - wxWindow *win = wxFindWinFromHandle(control); - if ( win ) - return win->MSWCommand(cmd, id); - } - return FALSE; -} - -long wxWindow::MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam) -{ - switch (wParam & 0xFFFFFFF0) - { - case SC_MAXIMIZE: - { - wxMaximizeEvent event(m_windowId); - event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) ) - return Default(); - else - return 0; - break; - } - case SC_MINIMIZE: - { - wxIconizeEvent event(m_windowId); - event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) ) - return Default(); - else - return 0; - break; - } - default: - return Default(); - } - return 0; -} - -void wxWindow::MSWOnLButtonDown(int x, int y, WXUINT flags) -{ - wxMouseEvent event(wxEVT_LEFT_DOWN); - - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.m_eventObject = this; - - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; m_lastMouseEvent = wxEVT_LEFT_DOWN; - - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); -} - -void wxWindow::MSWOnLButtonUp(int x, int y, WXUINT flags) -{ - wxMouseEvent event(wxEVT_LEFT_UP); - - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.m_eventObject = this; - - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; m_lastMouseEvent = wxEVT_LEFT_UP; - - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); -} - -void wxWindow::MSWOnLButtonDClick(int x, int y, WXUINT flags) -{ - wxMouseEvent event(wxEVT_LEFT_DCLICK); - - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.m_eventObject = this; - - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; m_lastMouseEvent = wxEVT_LEFT_DCLICK; - - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); -} - -void wxWindow::MSWOnMButtonDown(int x, int y, WXUINT flags) -{ - wxMouseEvent event(wxEVT_MIDDLE_DOWN); - - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.m_eventObject = this; - - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; m_lastMouseEvent = wxEVT_MIDDLE_DOWN; - - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); -} - -void wxWindow::MSWOnMButtonUp(int x, int y, WXUINT flags) -{ - wxMouseEvent event(wxEVT_MIDDLE_UP); - - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.m_eventObject = this; - - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; m_lastMouseEvent = wxEVT_MIDDLE_UP; + updateRect.right - updateRect.left, updateRect.bottom - updateRect.top); +#endif - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); + wxPaintEvent event(m_windowId); + event.SetEventObject(this); + return GetEventHandler()->ProcessEvent(event); } -void wxWindow::MSWOnMButtonDClick(int x, int y, WXUINT flags) +bool wxWindow::HandleMove(int x, int y) { - wxMouseEvent event(wxEVT_MIDDLE_DCLICK); + wxMoveEvent event(wxPoint(x, y), m_windowId); + event.SetEventObject(this); - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.m_eventObject = this; + return GetEventHandler()->ProcessEvent(event); +} - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; m_lastMouseEvent = wxEVT_MIDDLE_DCLICK; +bool wxWindow::MSWOnSize(int w, int h, WXUINT WXUNUSED(flag)) +{ + wxSizeEvent event(wxSize(w, h), m_windowId); + event.SetEventObject(this); - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); + return GetEventHandler()->ProcessEvent(event); } -void wxWindow::MSWOnRButtonDown(int x, int y, WXUINT flags) +bool wxWindow::MSWOnWindowPosChanging(void *WXUNUSED(lpPos)) { - wxMouseEvent event(wxEVT_RIGHT_DOWN); - - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.m_eventObject = this; + return FALSE; +} - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; m_lastMouseEvent = wxEVT_RIGHT_DOWN; +// Deal with child commands from buttons etc. +bool wxWindow::MSWOnCommand(WXWORD id, WXWORD cmd, WXHWND control) +{ + if ( wxCurrentPopupMenu ) + { + wxMenu *popupMenu = wxCurrentPopupMenu; + wxCurrentPopupMenu = NULL; + bool succ = popupMenu->MSWCommand(cmd, id); + return succ; + } - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); + wxWindow *item = FindItem(id); + if ( item ) + { + bool value = item->MSWCommand(cmd, id); + return value; + } + else + { + wxWindow *win = wxFindWinFromHandle(control); + if ( win ) + return win->MSWCommand(cmd, id); + } + return FALSE; } -void wxWindow::MSWOnRButtonUp(int x, int y, WXUINT flags) +bool wxWindow::MSWOnSysCommand(WXWPARAM wParam, WXLPARAM lParam) { - wxMouseEvent event(wxEVT_RIGHT_UP); + // 4 bits are reserved + switch (wParam & 0xFFFFFFF0) + { + case SC_MAXIMIZE: + { + wxMaximizeEvent event(m_windowId); + event.SetEventObject(this); - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.m_eventObject = this; - event.SetTimestamp(wxApp::sm_lastMessageTime); + return GetEventHandler()->ProcessEvent(event); + } + + case SC_MINIMIZE: + { + wxIconizeEvent event(m_windowId); + event.SetEventObject(this); - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; m_lastMouseEvent = wxEVT_RIGHT_UP; + return GetEventHandler()->ProcessEvent(event); + } + } - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); + return FALSE; } -void wxWindow::MSWOnRButtonDClick(int x, int y, WXUINT flags) -{ - wxMouseEvent event(wxEVT_RIGHT_DCLICK); +// --------------------------------------------------------------------------- +// mouse events +// --------------------------------------------------------------------------- - event.m_x = x; event.m_y = y; +void wxWindow::InitMouseEvent(wxMouseEvent& event, int x, int y, WXUINT flags) +{ + event.m_x = x; + event.m_y = y; event.m_shiftDown = ((flags & MK_SHIFT) != 0); event.m_controlDown = ((flags & MK_CONTROL) != 0); event.m_leftDown = ((flags & MK_LBUTTON) != 0); @@ -2304,92 +1924,74 @@ void wxWindow::MSWOnRButtonDClick(int x, int y, WXUINT flags) event.SetTimestamp(wxApp::sm_lastMessageTime); event.m_eventObject = this; - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; m_lastMouseEvent = wxEVT_RIGHT_DCLICK; +#if wxUSE_MOUSEEVENT_HACK + m_lastMouseX = x; + m_lastMouseY = y; + m_lastMouseEvent = event.GetEventType(); +#endif // wxUSE_MOUSEEVENT_HACK - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); } -void wxWindow::MSWOnMouseMove(int x, int y, WXUINT flags) +bool wxWindow::MSWOnMouseEvent(WXUINT msg, int x, int y, WXUINT flags) { - // 'normal' move event... + // the mouse events take consecutive IDs from WM_MOUSEFIRST to + // WM_MOUSELAST, so it's enough to substract WM_MOUSEMOVE == WM_MOUSEFIRST + // from the message id and take the value in the table to get wxWin event + // id + static const wxEventType eventsMouse[] = + { + wxEVT_MOTION, + wxEVT_LEFT_DOWN, + wxEVT_LEFT_UP, + wxEVT_LEFT_DCLICK, + wxEVT_RIGHT_DOWN, + wxEVT_RIGHT_UP, + wxEVT_RIGHT_DCLICK, + wxEVT_MIDDLE_DOWN, + wxEVT_MIDDLE_UP, + wxEVT_MIDDLE_DCLICK + }; + + wxMouseEvent event(eventsMouse[msg - WM_MOUSEMOVE]); + InitMouseEvent(event, x, y, flags); + + return GetEventHandler()->ProcessEvent(event); +} +bool wxWindow::MSWOnMouseMove(int x, int y, WXUINT flags) +{ if ( !m_mouseInWindow ) { // Generate an ENTER event m_mouseInWindow = TRUE; - MSWOnMouseEnter(x, y, flags); - } - wxMouseEvent event(wxEVT_MOTION); + wxMouseEvent event(wxEVT_ENTER_WINDOW); + InitMouseEvent(event, x, y, flags); - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.m_eventObject = this; + (void)GetEventHandler()->ProcessEvent(event); + } - // Window gets a click down message followed by a mouse move - // message even if position isn't changed! We want to discard - // the trailing move event if x and y are the same. - 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)) +#if wxUSE_MOUSEEVENT_HACK + // Window gets a click down message followed by a mouse move message even + // if position isn't changed! We want to discard the trailing move event + // if x and y are the same. + 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 = event.m_x; m_lastMouseY = event.m_y; m_lastMouseEvent = wxEVT_MOTION; - return; - } - - m_lastMouseEvent = wxEVT_MOTION; - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; - - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); -} -void wxWindow::MSWOnMouseEnter(int x, int y, WXUINT flags) -{ - wxMouseEvent event(wxEVT_ENTER_WINDOW); - - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.m_eventObject = this; + return FALSE; + } +#endif // wxUSE_MOUSEEVENT_HACK - m_lastMouseEvent = wxEVT_ENTER_WINDOW; - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; - // No message - ensure we don't try to call the default behaviour accidentally. - m_lastMsg = 0; - GetEventHandler()->ProcessEvent(event); + return MSWOnMouseEvent(WM_MOUSEMOVE, x, y, flags); } -void wxWindow::MSWOnMouseLeave(int x, int y, WXUINT flags) -{ - wxMouseEvent event(wxEVT_LEAVE_WINDOW); - - event.m_x = x; event.m_y = y; - event.m_shiftDown = ((flags & MK_SHIFT) != 0); - event.m_controlDown = ((flags & MK_CONTROL) != 0); - event.m_leftDown = ((flags & MK_LBUTTON) != 0); - event.m_middleDown = ((flags & MK_MBUTTON) != 0); - event.m_rightDown = ((flags & MK_RBUTTON) != 0); - event.SetTimestamp(wxApp::sm_lastMessageTime); - event.m_eventObject = this; - - m_lastMouseEvent = wxEVT_LEAVE_WINDOW; - m_lastMouseX = event.m_x; m_lastMouseY = event.m_y; - // No message - ensure we don't try to call the default behaviour accidentally. - m_lastMsg = 0; - GetEventHandler()->ProcessEvent(event); -} +// --------------------------------------------------------------------------- +// keyboard handling +// --------------------------------------------------------------------------- // isASCII is TRUE only when we're called from WM_CHAR handler and not from // WM_KEYDOWN one @@ -2449,7 +2051,7 @@ bool wxWindow::MSWOnChar(WXWORD wParam, WXLPARAM lParam, bool isASCII) POINT pt ; GetCursorPos(&pt) ; RECT rect ; - GetWindowRect((HWND) GetHWND(),&rect) ; + GetWindowRect(GetHwnd(),&rect) ; pt.x -= rect.left ; pt.y -= rect.top ; @@ -2487,7 +2089,7 @@ bool wxWindow::MSWOnKeyDown(WXWORD wParam, WXLPARAM lParam) POINT pt ; GetCursorPos(&pt) ; RECT rect ; - GetWindowRect((HWND) GetHWND(),&rect) ; + GetWindowRect(GetHwnd(),&rect) ; pt.x -= rect.left ; pt.y -= rect.top ; @@ -2528,7 +2130,7 @@ bool wxWindow::MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam) POINT pt ; GetCursorPos(&pt) ; RECT rect ; - GetWindowRect((HWND) GetHWND(),&rect) ; + GetWindowRect(GetHwnd(),&rect) ; pt.x -= rect.left ; pt.y -= rect.top ; @@ -2543,9 +2145,12 @@ bool wxWindow::MSWOnKeyUp(WXWORD wParam, WXLPARAM lParam) return FALSE; } -void wxWindow::MSWOnJoyDown(int joystick, int x, int y, WXUINT flags) +// --------------------------------------------------------------------------- +// joystick +// --------------------------------------------------------------------------- + +bool wxWindow::HandleJoystickEvent(WXUINT msg, int x, int y, WXUINT flags) { - int buttons = 0; int change = 0; if ( flags & JOY_BUTTON1CHG ) change = wxJOY_BUTTON1; @@ -2556,6 +2161,7 @@ void wxWindow::MSWOnJoyDown(int joystick, int x, int y, WXUINT flags) if ( flags & JOY_BUTTON4CHG ) change = wxJOY_BUTTON4; + int buttons = 0; if ( flags & JOY_BUTTON1 ) buttons |= wxJOY_BUTTON1; if ( flags & JOY_BUTTON2 ) @@ -2565,93 +2171,77 @@ void wxWindow::MSWOnJoyDown(int joystick, int x, int y, WXUINT flags) if ( flags & JOY_BUTTON4 ) buttons |= wxJOY_BUTTON4; - wxJoystickEvent event(wxEVT_JOY_BUTTON_DOWN, buttons, joystick, change); - event.SetPosition(wxPoint(x, y)); - event.SetEventObject(this); + // the event ids aren't consecutive so we can't use table based lookup + int joystick; + wxEventType eventType; + switch ( msg ) + { + case MM_JOY1MOVE: + joystick = 1; + eventType = wxEVT_JOY_MOVE; + break; - GetEventHandler()->ProcessEvent(event); -} + case MM_JOY2MOVE: + joystick = 2; + eventType = wxEVT_JOY_MOVE; + break; -void wxWindow::MSWOnJoyUp(int joystick, int x, int y, WXUINT flags) -{ - int buttons = 0; - int change = 0; - if ( flags & JOY_BUTTON1CHG ) - change = wxJOY_BUTTON1; - if ( flags & JOY_BUTTON2CHG ) - change = wxJOY_BUTTON2; - if ( flags & JOY_BUTTON3CHG ) - change = wxJOY_BUTTON3; - if ( flags & JOY_BUTTON4CHG ) - change = wxJOY_BUTTON4; + case MM_JOY1ZMOVE: + joystick = 1; + eventType = wxEVT_JOY_ZMOVE; + break; - if ( flags & JOY_BUTTON1 ) - buttons |= wxJOY_BUTTON1; - if ( flags & JOY_BUTTON2 ) - buttons |= wxJOY_BUTTON2; - if ( flags & JOY_BUTTON3 ) - buttons |= wxJOY_BUTTON3; - if ( flags & JOY_BUTTON4 ) - buttons |= wxJOY_BUTTON4; + case MM_JOY2ZMOVE: + joystick = 2; + eventType = wxEVT_JOY_ZMOVE; + break; - wxJoystickEvent event(wxEVT_JOY_BUTTON_UP, buttons, joystick, change); - event.SetPosition(wxPoint(x, y)); - event.SetEventObject(this); + case MM_JOY1BUTTONDOWN: + joystick = 1; + eventType = wxEVT_JOY_BUTTON_DOWN; + break; - GetEventHandler()->ProcessEvent(event); -} + case MM_JOY2BUTTONDOWN: + joystick = 2; + eventType = wxEVT_JOY_BUTTON_DOWN; + break; -void wxWindow::MSWOnJoyMove(int joystick, int x, int y, WXUINT flags) -{ - int buttons = 0; - if ( flags & JOY_BUTTON1 ) - buttons |= wxJOY_BUTTON1; - if ( flags & JOY_BUTTON2 ) - buttons |= wxJOY_BUTTON2; - if ( flags & JOY_BUTTON3 ) - buttons |= wxJOY_BUTTON3; - if ( flags & JOY_BUTTON4 ) - buttons |= wxJOY_BUTTON4; + case MM_JOY1BUTTONUP: + joystick = 1; + eventType = wxEVT_JOY_BUTTON_UP; + break; - wxJoystickEvent event(wxEVT_JOY_MOVE, buttons, joystick, 0); - event.SetPosition(wxPoint(x, y)); - event.SetEventObject(this); + case MM_JOY2BUTTONUP: + joystick = 2; + eventType = wxEVT_JOY_BUTTON_UP; + break; - GetEventHandler()->ProcessEvent(event); -} + default: + wxFAIL_MSG("no such joystick event"); -void wxWindow::MSWOnJoyZMove(int joystick, int z, WXUINT flags) -{ - int buttons = 0; - if ( flags & JOY_BUTTON1 ) - buttons |= wxJOY_BUTTON1; - if ( flags & JOY_BUTTON2 ) - buttons |= wxJOY_BUTTON2; - if ( flags & JOY_BUTTON3 ) - buttons |= wxJOY_BUTTON3; - if ( flags & JOY_BUTTON4 ) - buttons |= wxJOY_BUTTON4; + return FALSE; + } - wxJoystickEvent event(wxEVT_JOY_ZMOVE, buttons, joystick, 0); - event.SetZPosition(z); + wxJoystickEvent event(eventType, buttons, joystick, change); + event.SetPosition(wxPoint(x, y)); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + return GetEventHandler()->ProcessEvent(event); } -void wxWindow::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control) +bool wxWindow::MSWOnScroll(int orientation, WXWORD wParam, + WXWORD pos, WXHWND control) { if ( control ) { wxWindow *child = wxFindWinFromHandle(control); if ( child ) - child->MSWOnVScroll(wParam, pos, control); - return; + return child->MSWOnScroll(orientation, wParam, pos, control); } wxScrollEvent event; event.SetPosition(pos); - event.SetOrientation(wxVERTICAL); + event.SetOrientation(orientation); event.m_eventObject = this; switch ( wParam ) @@ -2686,88 +2276,26 @@ void wxWindow::MSWOnVScroll(WXWORD wParam, WXWORD pos, WXHWND control) break; default: - return; - break; - } - - if ( !GetEventHandler()->ProcessEvent(event) ) - Default(); -} - -void wxWindow::MSWOnHScroll( WXWORD wParam, WXWORD pos, WXHWND control) -{ - if ( control ) - { - wxWindow *child = wxFindWinFromHandle(control); - if ( child ) { - child->MSWOnHScroll(wParam, pos, control); - - return; - } - } - else { - wxScrollEvent event; - event.SetPosition(pos); - event.SetOrientation(wxHORIZONTAL); - event.m_eventObject = this; - - switch ( wParam ) - { - case SB_TOP: - event.m_eventType = wxEVT_SCROLL_TOP; - break; - - case SB_BOTTOM: - event.m_eventType = wxEVT_SCROLL_BOTTOM; - break; - - case SB_LINEUP: - event.m_eventType = wxEVT_SCROLL_LINEUP; - break; - - case SB_LINEDOWN: - event.m_eventType = wxEVT_SCROLL_LINEDOWN; - break; - - case SB_PAGEUP: - event.m_eventType = wxEVT_SCROLL_PAGEUP; - break; - - case SB_PAGEDOWN: - event.m_eventType = wxEVT_SCROLL_PAGEDOWN; - break; - - case SB_THUMBTRACK: - case SB_THUMBPOSITION: - event.m_eventType = wxEVT_SCROLL_THUMBTRACK; - break; - - default: - return; - } - - if ( GetEventHandler()->ProcessEvent(event) ) - return; + return FALSE; } - // call the default WM_HSCROLL handler: it's non trivial in some common - // controls (up-down control for example) - Default(); + return GetEventHandler()->ProcessEvent(event); } -void wxWindow::MSWOnShow(bool show, int status) +bool wxWindow::MSWOnShow(bool show, int status) { wxShowEvent event(GetId(), show); event.m_eventObject = this; - GetEventHandler()->ProcessEvent(event); + + return GetEventHandler()->ProcessEvent(event); } bool wxWindow::MSWOnInitDialog(WXHWND WXUNUSED(hWndFocus)) { wxInitDialogEvent event(GetId()); event.m_eventObject = this; - GetEventHandler()->ProcessEvent(event); - return TRUE; + + return GetEventHandler()->ProcessEvent(event); } void wxGetCharSize(WXHWND wnd, int *x, int *y,wxFont *the_font) @@ -2973,9 +2501,9 @@ void wxWindow::ShowCaret(bool show) if ( m_caretEnabled ) { if ( show ) - ::ShowCaret((HWND) GetHWND()); + ::ShowCaret(GetHwnd()); else - ::HideCaret((HWND) GetHWND()); + ::HideCaret(GetHwnd()); m_caretShown = show; } } @@ -3080,7 +2608,7 @@ void wxWindow::WarpPointer (int x_pos, int y_pos) int x = x_pos; int y = y_pos; RECT rect; - GetWindowRect ((HWND) GetHWND(), &rect); + GetWindowRect (GetHwnd(), &rect); x += rect.left; y += rect.top; @@ -3092,30 +2620,28 @@ void wxWindow::MSWDeviceToLogical (float *x, float *y) const { } -bool wxWindow::MSWOnEraseBkgnd (WXHDC pDC) +bool wxWindow::MSWOnQueryDragIcon(WXHICON * WXUNUSED(hIcon)) +{ + return FALSE; +} + +bool wxWindow::MSWOnEraseBkgnd(WXHDC hdc) { - wxDC dc ; + wxDC dc; - dc.SetHDC(pDC); + dc.SetHDC(hdc); dc.SetWindow(this); dc.BeginDrawing(); wxEraseEvent event(m_windowId, &dc); event.m_eventObject = this; - if ( !GetEventHandler()->ProcessEvent(event) ) - { - dc.EndDrawing(); - dc.SelectOldObjects(pDC); - return FALSE; - } - else - { - dc.EndDrawing(); - dc.SelectOldObjects(pDC); - } + bool rc = GetEventHandler()->ProcessEvent(event); + dc.EndDrawing(); + dc.SelectOldObjects(hdc); dc.SetHDC((WXHDC) NULL); - return TRUE; + + return rc; } void wxWindow::OnEraseBackground(wxEraseEvent& event) @@ -3124,7 +2650,7 @@ void wxWindow::OnEraseBackground(wxEraseEvent& event) return; RECT rect; - ::GetClientRect((HWND) GetHWND(), &rect); + ::GetClientRect(GetHwnd(), &rect); COLORREF ref = PALETTERGB(m_backgroundColour.Red(), m_backgroundColour.Green(), m_backgroundColour.Blue()) ; HBRUSH hBrush = ::CreateSolidBrush(ref); @@ -3177,7 +2703,7 @@ void wxWindow::SetScrollRange(int orient, int range, bool refresh) info.nPos = 0; info.fMask = SIF_RANGE | SIF_PAGE; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) ::SetScrollInfo(hWnd, dir, &info, refresh); #else @@ -3187,7 +2713,7 @@ void wxWindow::SetScrollRange(int orient, int range, bool refresh) else wOrient = SB_VERT; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) ::SetScrollRange(hWnd, wOrient, 0, range, refresh); #endif @@ -3212,7 +2738,7 @@ void wxWindow::SetScrollPage(int orient, int page, bool refresh) info.nMin = 0; info.fMask = SIF_PAGE ; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) ::SetScrollInfo(hWnd, dir, &info, refresh); #else @@ -3236,7 +2762,7 @@ int wxWindow::OldGetScrollRange(int orient) const #else int minPos, maxPos; #endif - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) { ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos); @@ -3271,7 +2797,7 @@ int wxWindow::GetScrollPos(int orient) const wOrient = SB_HORZ; else wOrient = SB_VERT; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) { return ::GetScrollPos(hWnd, wOrient); @@ -3295,7 +2821,7 @@ int wxWindow::GetScrollRange(int orient) const #else int minPos, maxPos; #endif - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) { ::GetScrollRange(hWnd, wOrient, &minPos, &maxPos); @@ -3343,7 +2869,7 @@ void wxWindow::SetScrollPos(int orient, int pos, bool refresh) info.nPos = pos; info.fMask = SIF_POS ; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) ::SetScrollInfo(hWnd, dir, &info, refresh); #else @@ -3353,7 +2879,7 @@ void wxWindow::SetScrollPos(int orient, int pos, bool refresh) else wOrient = SB_VERT; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) ::SetScrollPos(hWnd, wOrient, pos, refresh); #endif @@ -3400,7 +2926,7 @@ SetScrollPage(orient, thumbVisible, FALSE); info.nPos = pos; info.fMask = SIF_RANGE | SIF_PAGE | SIF_POS; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) ::SetScrollInfo(hWnd, dir, &info, refresh); #else @@ -3410,7 +2936,7 @@ SetScrollPage(orient, thumbVisible, FALSE); else wOrient = SB_VERT; - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd ) { ::SetScrollRange(hWnd, wOrient, 0, range, FALSE); @@ -3436,9 +2962,9 @@ void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) } if ( rect ) - ::ScrollWindow((HWND) GetHWND(), dx, dy, &rect2, NULL); + ::ScrollWindow(GetHwnd(), dx, dy, &rect2, NULL); else - ::ScrollWindow((HWND) GetHWND(), dx, dy, NULL, NULL); + ::ScrollWindow(GetHwnd(), dx, dy, NULL, NULL); } bool wxWindow::SetFont(const wxFont& font) @@ -3449,7 +2975,7 @@ bool wxWindow::SetFont(const wxFont& font) return FALSE; } - HWND hWnd = (HWND) GetHWND(); + HWND hWnd = GetHwnd(); if ( hWnd != 0 ) { WXHANDLE hFont = m_font.GetResourceHandle(); @@ -3477,12 +3003,12 @@ void wxWindow::UnsubclassWin() wxRemoveHandleAssociation(this); // Restore old Window proc - if ( (HWND) GetHWND() ) + if ( GetHwnd() ) { - FARPROC farProc = (FARPROC) GetWindowLong((HWND) GetHWND(), GWL_WNDPROC); + FARPROC farProc = (FARPROC) GetWindowLong(GetHwnd(), GWL_WNDPROC); if ( (m_oldWndProc != 0) && (farProc != (FARPROC) m_oldWndProc) ) { - SetWindowLong((HWND) GetHWND(), GWL_WNDPROC, (LONG) m_oldWndProc); + SetWindowLong(GetHwnd(), GWL_WNDPROC, (LONG) m_oldWndProc); m_oldWndProc = 0; } } @@ -3569,26 +3095,6 @@ WXDWORD wxWindow::Determine3DEffects(WXDWORD defaultBorderStyle, bool *want3D) return exStyle; } -void wxWindow::OnChar(wxKeyEvent& event) -{ - event.Skip(); -} - -void wxWindow::OnKeyDown(wxKeyEvent& event) -{ - Default(); -} - -void wxWindow::OnKeyUp(wxKeyEvent& event) -{ - Default(); -} - -void wxWindow::OnPaint(wxPaintEvent& event) -{ - Default(); -} - // Get the window with the focus wxWindow *wxWindowBase::FindFocus() { @@ -3789,43 +3295,40 @@ void wxWindow::OnIdle(wxIdleEvent& event) { POINT pt; ::GetCursorPos(&pt); - if ( ::WindowFromPoint(pt) != (HWND) GetHWND() ) + if ( ::WindowFromPoint(pt) != GetHwnd() ) { // Generate a LEAVE event m_mouseInWindow = FALSE; + // Unfortunately the mouse button and keyboard state may have changed + // by the time the OnIdle function is called, so 'state' may be + // meaningless. int state = 0; if ( ::GetKeyState(VK_SHIFT) != 0 ) state |= MK_SHIFT; if ( ::GetKeyState(VK_CONTROL) != 0 ) state |= MK_CONTROL; - // Unfortunately the mouse button and keyboard state may have changed - // by the time the OnIdle function is called, so 'state' may be - // meaningless. + wxMouseEvent event(wxEVT_LEAVE_WINDOW); + InitMouseEvent(event, pt.x, pt.y, state); - MSWOnMouseLeave(pt.x, pt.y, state); + (void)GetEventHandler()->ProcessEvent(event); } } + UpdateWindowUI(); } // Raise the window to the top of the Z order void wxWindow::Raise() { - ::BringWindowToTop((HWND) GetHWND()); + ::BringWindowToTop(GetHwnd()); } // Lower the window to the bottom of the Z order void wxWindow::Lower() { - ::SetWindowPos((HWND) GetHWND(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); -} - -long wxWindow::MSWGetDlgCode() -{ - // default: just forward to def window proc (the msg has no parameters) - return MSWDefWindowProc(WM_GETDLGCODE, 0, 0); + ::SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOACTIVATE); } // Set this window to be the child of 'parent'. @@ -3834,8 +3337,8 @@ bool wxWindow::Reparent(wxWindow *parent) if ( !wxWindowBase::Reparent(parent) ) return FALSE; - HWND hWndChild = (HWND)GetHWND(); - HWND hWndParent = (HWND)(GetParent() ? GetParent()->GetHWND() : NULL); + HWND hWndChild = GetHwnd(); + HWND hWndParent = GetParent() ? GetWinHwnd(GetParent()) : (HWND)0; ::SetParent(hWndChild, hWndParent); -- 2.45.2