]>
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 #if !defined(__WXPM__)
76 SetBackgroundColour(wxColour(0xc3ffff));
78 // What is 0xc3ffff, try some legable documentation for those of us who don't memorize hex codes??
79 SetBackgroundColour(wxColour(*wxWHITE
));
81 // set position and size
83 wxGetMousePosition(&x
, &y
);
86 Adjust(text
, maxLength
);
93 void wxTipWindow::Adjust(const wxString
& text
, wxCoord maxLength
)
96 dc
.SetFont(GetFont());
98 // calculate the length: we want each line be no longer than maxLength
99 // pixels and we only break lines at words boundary
101 wxCoord height
, width
,
105 bool breakLine
= FALSE
;
106 for ( const wxChar
*p
= text
.c_str(); ; p
++ )
108 if ( *p
== _T('\n') || *p
== _T('\0') )
110 dc
.GetTextExtent(current
, &width
, &height
);
111 if ( width
> widthMax
)
114 if ( height
> m_heightLine
)
115 m_heightLine
= height
;
117 m_textLines
.Add(current
);
128 else if ( breakLine
&& (*p
== _T(' ') || *p
== _T('\t')) )
130 // word boundary - break the line here
131 m_textLines
.Add(current
);
138 dc
.GetTextExtent(current
, &width
, &height
);
139 if ( width
> maxLength
)
142 if ( width
> widthMax
)
145 if ( height
> m_heightLine
)
146 m_heightLine
= height
;
150 // take into account the border size and the margins
151 SetClientSize(2*(TEXT_MARGIN_X
+ 1) + widthMax
,
152 2*(TEXT_MARGIN_Y
+ 1) + m_textLines
.GetCount()*m_heightLine
);
155 void wxTipWindow::OnPaint(wxPaintEvent
& event
)
160 wxSize size
= GetClientSize();
162 rect
.height
= size
.y
;
164 // first filll the background
165 dc
.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID
));
167 // Under Windows, you apparently get a thin black border whether you like it or not :-(
169 dc
.SetPen( * wxTRANSPARENT_PEN
);
171 dc
.SetPen( * wxBLACK_PEN
);
173 dc
.DrawRectangle(rect
);
175 // and then draw the text line by line
176 dc
.SetFont(GetFont());
179 pt
.x
= TEXT_MARGIN_X
;
180 pt
.y
= TEXT_MARGIN_Y
;
181 size_t count
= m_textLines
.GetCount();
182 for ( size_t n
= 0; n
< count
; n
++ )
184 dc
.DrawText(m_textLines
[n
], pt
);
186 pt
.y
+= m_heightLine
;
190 void wxTipWindow::OnMouseClick(wxMouseEvent
& event
)
195 void wxTipWindow::OnActivate(wxActivateEvent
& event
)
197 if (!event
.GetActive())
201 void wxTipWindow::OnKillFocus(wxFocusEvent
& event
)