From cd9da200285e3c625be91768c9ca61dc218c94d0 Mon Sep 17 00:00:00 2001
From: Vadim Zeitlin <vadim@wxwidgets.org>
Date: Thu, 17 Feb 2000 12:53:36 +0000
Subject: [PATCH] added and documented wxDC::DrawCheckMark()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6109 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/dc.tex        |  8 ++++++++
 include/wx/dc.h             | 27 +++++++++++++++++----------
 include/wx/gtk/dcclient.h   |  7 ++++---
 include/wx/gtk1/dcclient.h  |  7 ++++---
 include/wx/msw/dc.h         |  2 ++
 samples/drawing/drawing.cpp | 23 ++++++++++++++++-------
 src/common/dcbase.cpp       | 21 +++++++++++++++++++++
 src/msw/dc.cpp              | 35 +++++++++++++++++++++++++++++++++++
 8 files changed, 107 insertions(+), 23 deletions(-)

diff --git a/docs/latex/wx/dc.tex b/docs/latex/wx/dc.tex
index b704196331..ea39bed045 100644
--- a/docs/latex/wx/dc.tex
+++ b/docs/latex/wx/dc.tex
@@ -179,6 +179,14 @@ of the bitmap (all bits set to 1), and the current text background colour to dra
 (all bits set to 0). See also \helpref{SetTextForeground}{wxdcsettextforeground},
 \helpref{SetTextBackground}{wxdcsettextbackground} and \helpref{wxMemoryDC}{wxmemorydc}.
 
+\membersection{wxDC::DrawCheckMark}\label{wxdcdrawcheckmark}
+
+\func{void}{DrawCheckMark}{\param{wxCoord}{ x}, \param{wxCoord}{ y}, \param{wxCoord}{ width}, \param{wxCoord}{ height}}
+
+\func{void}{DrawCheckMark}{\param{const wxRect \&}{rect}}
+
+Draws a check mark inside the given rectangle.
+
 \membersection{wxDC::DrawEllipse}\label{wxdcdrawellipse}
 
 \func{void}{DrawEllipse}{\param{wxCoord}{ x}, \param{wxCoord}{ y}, \param{wxCoord}{ width}, \param{wxCoord}{ height}}
diff --git a/include/wx/dc.h b/include/wx/dc.h
index b49bbaacca..1c2ddf548f 100644
--- a/include/wx/dc.h
+++ b/include/wx/dc.h
@@ -43,8 +43,6 @@ WXDLLEXPORT_DATA(extern int) wxPageNumber;
 
 class WXDLLEXPORT wxDCBase : public wxObject
 {
-    DECLARE_ABSTRACT_CLASS(wxDCBase)
-
 public:
     wxDCBase()
     {
@@ -112,6 +110,12 @@ public:
     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 DrawCheckMark(wxCoord x, wxCoord y,
+                       wxCoord width, wxCoord height)
+        { DoDrawCheckMark(x, y, width, height); }
+    void DrawCheckMark(const wxRect& rect)
+        { DoDrawCheckMark(rect.x, rect.y, rect.width, rect.height); }
+
     void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
                          double sa, double ea)
         { DoDrawEllipticArc(x, y, w, h, sa, ea); }
@@ -261,7 +265,7 @@ public:
 
     virtual wxCoord GetCharHeight() const = 0;
     virtual wxCoord GetCharWidth() const = 0;
-    
+
     void GetTextExtent(const wxString& string,
                        wxCoord *x, wxCoord *y,
                        wxCoord *descent = NULL,
@@ -453,13 +457,13 @@ public:
             *y = y2;
     }
     void GetClippingBox(long *x, long *y, long *w, long *h) const
-    { 
-	wxCoord xx,yy,ww,hh;
-	DoGetClippingBox(&xx, &yy, &ww, &hh);
-	if (x) *x = xx;
-	if (y) *y = yy;
-	if (w) *w = ww;
-	if (h) *h = hh;
+    {
+        wxCoord xx,yy,ww,hh;
+        DoGetClippingBox(&xx, &yy, &ww, &hh);
+        if (x) *x = xx;
+        if (y) *y = yy;
+        if (w) *w = ww;
+        if (h) *h = hh;
     }
 #endif // !Win16
 
@@ -485,6 +489,8 @@ protected:
     virtual void DoDrawArc(wxCoord x1, wxCoord y1,
                            wxCoord x2, wxCoord y2,
                            wxCoord xc, wxCoord yc) = 0;
+    virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
+                                 wxCoord width, wxCoord height);
     virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
                                    double sa, double ea) = 0;
 
@@ -605,6 +611,7 @@ protected:
 
 private:
     DECLARE_NO_COPY_CLASS(wxDCBase);
+    DECLARE_ABSTRACT_CLASS(wxDCBase)
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/wx/gtk/dcclient.h b/include/wx/gtk/dcclient.h
index 0142e694c7..acc3896336 100644
--- a/include/wx/gtk/dcclient.h
+++ b/include/wx/gtk/dcclient.h
@@ -40,6 +40,7 @@ public:
     virtual bool CanDrawBitmap() const { return TRUE; }
     virtual bool CanGetTextExtent() const { return TRUE; }
 
+//protected:
     virtual void DoFloodFill( wxCoord x, wxCoord y, const wxColour& col, int style=wxFLOOD_SURFACE );
     virtual bool DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const;
 
@@ -121,7 +122,7 @@ public:
     void ComputeScaleAndOrigin();
 
     GdkWindow *GetWindow() { return m_window; }
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxWindowDC)
 };
@@ -135,7 +136,7 @@ class wxPaintDC : public wxWindowDC
 public:
     wxPaintDC();
     wxPaintDC( wxWindow *win );
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxPaintDC)
 };
@@ -149,7 +150,7 @@ class wxClientDC : public wxWindowDC
 public:
     wxClientDC();
     wxClientDC( wxWindow *win );
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxClientDC)
 };
diff --git a/include/wx/gtk1/dcclient.h b/include/wx/gtk1/dcclient.h
index 0142e694c7..acc3896336 100644
--- a/include/wx/gtk1/dcclient.h
+++ b/include/wx/gtk1/dcclient.h
@@ -40,6 +40,7 @@ public:
     virtual bool CanDrawBitmap() const { return TRUE; }
     virtual bool CanGetTextExtent() const { return TRUE; }
 
+//protected:
     virtual void DoFloodFill( wxCoord x, wxCoord y, const wxColour& col, int style=wxFLOOD_SURFACE );
     virtual bool DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const;
 
@@ -121,7 +122,7 @@ public:
     void ComputeScaleAndOrigin();
 
     GdkWindow *GetWindow() { return m_window; }
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxWindowDC)
 };
@@ -135,7 +136,7 @@ class wxPaintDC : public wxWindowDC
 public:
     wxPaintDC();
     wxPaintDC( wxWindow *win );
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxPaintDC)
 };
@@ -149,7 +150,7 @@ class wxClientDC : public wxWindowDC
 public:
     wxClientDC();
     wxClientDC( wxWindow *win );
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxClientDC)
 };
diff --git a/include/wx/msw/dc.h b/include/wx/msw/dc.h
index d9479093ea..2bf3643789 100644
--- a/include/wx/msw/dc.h
+++ b/include/wx/msw/dc.h
@@ -153,6 +153,8 @@ protected:
     virtual void DoDrawArc(wxCoord x1, wxCoord y1,
                            wxCoord x2, wxCoord y2,
                            wxCoord xc, wxCoord yc);
+    virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
+                                 wxCoord width, wxCoord height);
     virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
                                    double sa, double ea);
 
diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp
index 47a069d5d0..06f587a9a3 100644
--- a/samples/drawing/drawing.cpp
+++ b/samples/drawing/drawing.cpp
@@ -574,22 +574,31 @@ void MyCanvas::DrawDefault(wxDC& dc)
 
     dc.DrawIcon( wxICON(mondrian), 40, 40 );
 
+    dc.DrawCheckMark(5, 80, 15, 15);
+    dc.DrawCheckMark(25, 80, 30, 30);
+    dc.DrawCheckMark(60, 80, 60, 60);
+
     // this is the test for "blitting bitmap into DC damages selected brush"
     // bug
+    wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION);
+    wxCoord rectSize = icon.GetWidth() + 10;
+    wxCoord x = 100;
     dc.SetPen(*wxTRANSPARENT_PEN);
     dc.SetBrush( *wxGREEN_BRUSH );
-    dc.DrawRectangle(100, 10, 40, 40);
-    dc.DrawBitmap(wxTheApp->GetStdIcon(wxICON_INFORMATION), 102, 12, TRUE);
-    dc.DrawRectangle(150, 10, 40, 40);
-    dc.DrawIcon(wxTheApp->GetStdIcon(wxICON_INFORMATION), 152, 12);
-    dc.DrawRectangle(200, 10, 40, 40);
+    dc.DrawRectangle(x, 10, rectSize, rectSize);
+    dc.DrawBitmap(icon, x + 5, 15, TRUE);
+    x += rectSize + 10;
+    dc.DrawRectangle(x, 10, rectSize, rectSize);
+    dc.DrawIcon(wxTheApp->GetStdIcon(wxICON_INFORMATION), x + 5, 15);
+    x += rectSize + 10;
+    dc.DrawRectangle(x, 10, rectSize, rectSize);
 
     // test for "transparent" bitmap drawing (it intersects with the last
     // rectangle above)
     //dc.SetBrush( *wxTRANSPARENT_BRUSH );
     #include "../image/smile.xpm"
     wxBitmap bmp(smile_xpm);
-    dc.DrawBitmap(bmp, 210, 30, TRUE);
+    dc.DrawBitmap(bmp, x + rectSize - 20, rectSize - 10, TRUE);
 
     dc.SetBrush( *wxBLACK_BRUSH );
     dc.DrawRectangle( 0, 160, 1000, 300 );
@@ -722,9 +731,9 @@ void MyCanvas::DrawDefault(wxDC& dc)
 
     memdc2.DrawRectangle(0, 0, totalWidth, totalHeight);
 
-    memdc2.SelectObject(wxNullBitmap);
     memdc2.SetPen(wxNullPen);
     memdc2.SetBrush(wxNullBrush);
+    memdc2.SelectObject(wxNullBitmap);
 
     dc.DrawBitmap(bitmap2, 500, 270);
 }
diff --git a/src/common/dcbase.cpp b/src/common/dcbase.cpp
index a95db6adcc..e625e91d07 100644
--- a/src/common/dcbase.cpp
+++ b/src/common/dcbase.cpp
@@ -30,6 +30,27 @@
 
 #include "wx/dc.h"
 
+void wxDCBase::DoDrawCheckMark(wxCoord x1, wxCoord y1,
+                               wxCoord width, wxCoord height)
+{
+    wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+    wxCoord x2 = x1 + width,
+            y2 = y1 + height;
+
+    // this is to yield width of 3 for width == height == 10
+    SetPen(wxPen(GetTextForeground(), (width + height + 1) / 7, wxSOLID));
+
+    // we're drawing a scaled version of wx/generic/tick.xpm here
+    wxCoord x3 = x1 + (4*width) / 10,   // x of the tick bottom
+            y3 = y1 + height / 2;       // y of the left tick branch
+    DoDrawLine(x1, y3, x3, y2);
+    DoDrawLine(x3, y2, x2, y1);
+
+    CalcBoundingBox(x1, y1);
+    CalcBoundingBox(x2, y2);
+}
+
 void wxDCBase::DrawLines(const wxList *list, wxCoord xoffset, wxCoord yoffset)
 {
     int n = list->Number();
diff --git a/src/msw/dc.cpp b/src/msw/dc.cpp
index a3bbadbeec..f339b4dafe 100644
--- a/src/msw/dc.cpp
+++ b/src/msw/dc.cpp
@@ -409,6 +409,41 @@ void wxDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2, wxCoord xc, wx
     CalcBoundingBox((wxCoord)(xc+radius), (wxCoord)(yc+radius));
 }
 
+void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1,
+                           wxCoord width, wxCoord height)
+{
+    wxCoord x2 = x1 + width,
+            y2 = y1 + height;
+
+#if defined(__WIN32__) && !defined(__SC__)
+    RECT rect;
+    rect.left   = x1;
+    rect.top    = y1;
+    rect.right  = x2;
+    rect.bottom = y2;
+
+    DrawFrameControl(GetHdc(), &rect, DFC_MENU, DFCS_MENUCHECK);
+#else // Win16
+    // In WIN16, draw a cross
+    HPEN blackPen = ::CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
+    HPEN whiteBrush = (HPEN)::GetStockObject(WHITE_BRUSH);
+    HPEN hPenOld = (HPEN)::SelectObject(hdcMem, blackPen);
+    HPEN hBrushOld = (HPEN)::SelectObject(hdcMem, whiteBrush);
+    ::SetROP2(GetHdc(), R2_COPYPEN);
+    Rectangle(GetHdc(), x1, y1, x2, y2);
+    MoveTo(GetHdc(), x1, y1);
+    LineTo(GetHdc(), x2, y2);
+    MoveTo(GetHdc(), x2, y1);
+    LineTo(GetHdc(), x1, y2);
+    ::SelectObject(GetHdc(), hPenOld);
+    ::SelectObject(GetHdc(), hBrushOld);
+    ::DeleteObject(blackPen);
+#endif // Win32/16
+
+    CalcBoundingBox(x1, y1);
+    CalcBoundingBox(x2, y2);
+}
+
 void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
 {
     COLORREF color = 0x00ffffff;
-- 
2.50.0

