]>
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
)
58 EVT_KILL_FOCUS(wxTipWindow::OnKillFocus
)
59 EVT_ACTIVATE(wxTipWindow::OnActivate
)
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 wxTipWindow::wxTipWindow(wxWindow
*parent
,
69 : wxFrame(parent
, -1, _T(""),
70 wxDefaultPosition
, wxDefaultSize
,
71 wxNO_BORDER
| wxFRAME_FLOAT_ON_PARENT
)
74 SetForegroundColour(*wxBLACK
);
75 SetBackgroundColour(wxColour(0xc3ffff));
77 // set position and size
79 wxGetMousePosition(&x
, &y
);
82 Adjust(text
, maxLength
);
89 void wxTipWindow::Adjust(const wxString
& text
, wxCoord maxLength
)
92 dc
.SetFont(GetFont());
94 // calculate the length: we want each line be no longer than maxLength
95 // pixels and we only break lines at words boundary
97 wxCoord height
, width
,
101 bool breakLine
= FALSE
;
102 for ( const wxChar
*p
= text
.c_str(); ; p
++ )
104 if ( *p
== _T('\n') || *p
== _T('\0') )
106 dc
.GetTextExtent(current
, &width
, &height
);
107 if ( width
> widthMax
)
110 if ( height
> m_heightLine
)
111 m_heightLine
= height
;
113 m_textLines
.Add(current
);
124 else if ( breakLine
&& (*p
== _T(' ') || *p
== _T('\t')) )
126 // word boundary - break the line here
127 m_textLines
.Add(current
);
134 dc
.GetTextExtent(current
, &width
, &height
);
135 if ( width
> maxLength
)
138 if ( width
> widthMax
)
141 if ( height
> m_heightLine
)
142 m_heightLine
= height
;
146 // take into account the border size and the margins
147 SetClientSize(2*(TEXT_MARGIN_X
+ 1) + widthMax
,
148 2*(TEXT_MARGIN_Y
+ 1) + m_textLines
.GetCount()*m_heightLine
);
151 void wxTipWindow::OnPaint(wxPaintEvent
& event
)
156 wxSize size
= GetClientSize();
158 rect
.height
= size
.y
;
160 // first filll the background
161 dc
.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID
));
163 // Under Windows, you apparently get a thin black border whether you like it or not :-(
165 dc
.SetPen( * wxTRANSPARENT_PEN
);
167 dc
.SetPen( * wxBLACK_PEN
);
169 dc
.DrawRectangle(rect
);
171 // and then draw the text line by line
172 dc
.SetFont(GetFont());
175 pt
.x
= TEXT_MARGIN_X
;
176 pt
.y
= TEXT_MARGIN_Y
;
177 size_t count
= m_textLines
.GetCount();
178 for ( size_t n
= 0; n
< count
; n
++ )
180 dc
.DrawText(m_textLines
[n
], pt
);
182 pt
.y
+= m_heightLine
;
186 void wxTipWindow::OnMouseClick(wxMouseEvent
& event
)
191 void wxTipWindow::OnActivate(wxActivateEvent
& event
)
193 if (!event
.GetActive())
197 void wxTipWindow::OnKillFocus(wxFocusEvent
& event
)