]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/tipwin.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/tipwin.cpp
3 // Purpose: implementation of wxTipWindow
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2000 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "tipwin.h"
24 // For compilers that support precompilatixon, includes "wx/wx.h".
25 #include "wx/wxprec.h"
32 #include "wx/dcclient.h"
35 #include "wx/tipwin.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 static const wxCoord TEXT_MARGIN_X
= 3;
42 static const wxCoord TEXT_MARGIN_Y
= 3;
44 // ============================================================================
46 // ============================================================================
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 BEGIN_EVENT_TABLE(wxTipWindow
, wxFrame
)
53 EVT_PAINT(wxTipWindow::OnPaint
)
55 EVT_LEFT_DOWN(wxTipWindow::OnMouseClick
)
56 EVT_RIGHT_DOWN(wxTipWindow::OnMouseClick
)
57 EVT_MIDDLE_DOWN(wxTipWindow::OnMouseClick
)
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 wxTipWindow::wxTipWindow(wxWindow
*parent
,
67 : wxFrame(parent
, -1, _T(""),
68 wxDefaultPosition
, wxDefaultSize
,
69 wxNO_BORDER
| wxFRAME_FLOAT_ON_PARENT
)
72 SetForegroundColour(*wxBLACK
);
73 SetBackgroundColour(wxColour(0xc3ffff));
75 // set position and size
77 wxGetMousePosition(&x
, &y
);
80 Adjust(text
, maxLength
);
82 // capture mouse as we want to dismiss the window when it is clicked
88 void wxTipWindow::Adjust(const wxString
& text
, wxCoord maxLength
)
91 dc
.SetFont(GetFont());
93 // calculate the length: we want each line be no longer than maxLength
94 // pixels and we only break lines at words boundary
96 wxCoord height
, width
,
100 bool breakLine
= FALSE
;
101 for ( const wxChar
*p
= text
.c_str(); ; p
++ )
103 if ( *p
== _T('\n') || *p
== _T('\0') )
105 dc
.GetTextExtent(current
, &width
, &height
);
106 if ( width
> widthMax
)
109 if ( height
> m_heightLine
)
110 m_heightLine
= height
;
112 m_textLines
.Add(current
);
123 else if ( breakLine
&& (*p
== _T(' ') || *p
== _T('\t')) )
125 // word boundary - break the line here
126 m_textLines
.Add(current
);
133 dc
.GetTextExtent(current
, &width
, &height
);
134 if ( width
> maxLength
)
137 if ( width
> widthMax
)
140 if ( height
> m_heightLine
)
141 m_heightLine
= height
;
145 // take into account the border size and the margins
146 SetClientSize(2*(TEXT_MARGIN_X
+ 1) + widthMax
,
147 2*(TEXT_MARGIN_Y
+ 1) + m_textLines
.GetCount()*m_heightLine
);
150 void wxTipWindow::OnPaint(wxPaintEvent
& event
)
155 wxSize size
= GetClientSize();
157 rect
.height
= size
.y
;
159 // first filll the background
160 dc
.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID
));
161 dc
.SetPen(*wxBLACK_PEN
);
162 dc
.DrawRectangle(rect
);
164 // and then draw the text line by line
165 dc
.SetFont(GetFont());
168 pt
.x
= TEXT_MARGIN_X
;
169 pt
.y
= TEXT_MARGIN_Y
;
170 size_t count
= m_textLines
.GetCount();
171 for ( size_t n
= 0; n
< count
; n
++ )
173 dc
.DrawText(m_textLines
[n
], pt
);
175 pt
.y
+= m_heightLine
;
179 void wxTipWindow::OnMouseClick(wxMouseEvent
& event
)