]>
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"
40 #include "wx/settings.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 static const wxCoord TEXT_MARGIN_X
= 3;
47 static const wxCoord TEXT_MARGIN_Y
= 3;
49 // ============================================================================
51 // ============================================================================
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
57 BEGIN_EVENT_TABLE(wxTipWindow
, wxPopupTransientWindow
)
58 EVT_LEFT_DOWN(wxTipWindow::OnMouseClick
)
59 EVT_RIGHT_DOWN(wxTipWindow::OnMouseClick
)
60 EVT_MIDDLE_DOWN(wxTipWindow::OnMouseClick
)
61 EVT_PAINT(wxTipWindow::OnPaint
)
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 wxTipWindow::wxTipWindow(wxWindow
*parent
,
71 wxCoord maxLength
, wxTipWindow
** windowPtr
)
72 : wxPopupTransientWindow(parent
)
74 m_windowPtr
= windowPtr
;
77 SetForegroundColour(*wxBLACK
);
80 wxColour
bkCol(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_INFOBK
));
82 wxColour
bkCol(wxColour(255, 255, 225));
84 SetBackgroundColour(bkCol
);
86 // set size and position
87 Adjust(text
, maxLength
);
89 wxGetMousePosition(&x
, &y
);
90 Position(wxPoint(x
, y
+10), wxSize(0,0));
97 wxTipWindow::~wxTipWindow()
105 void wxTipWindow::OnMouseClick(wxMouseEvent
& WXUNUSED(event
))
111 void wxTipWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
116 wxSize size
= GetClientSize();
118 rect
.height
= size
.y
;
120 // first filll the background
121 dc
.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID
));
123 dc
.SetPen( * wxBLACK_PEN
);
124 dc
.DrawRectangle(rect
);
126 // and then draw the text line by line
127 dc
.SetFont(GetFont());
130 pt
.x
= TEXT_MARGIN_X
;
131 pt
.y
= TEXT_MARGIN_Y
;
132 size_t count
= m_textLines
.GetCount();
133 for ( size_t n
= 0; n
< count
; n
++ )
135 dc
.DrawText(m_textLines
[n
], pt
);
137 pt
.y
+= m_heightLine
;
142 void wxTipWindow::Adjust(const wxString
& text
, wxCoord maxLength
)
145 dc
.SetFont(GetFont());
147 // calculate the length: we want each line be no longer than maxLength
148 // pixels and we only break lines at words boundary
150 wxCoord height
, width
,
154 bool breakLine
= FALSE
;
155 for ( const wxChar
*p
= text
.c_str(); ; p
++ )
157 if ( *p
== _T('\n') || *p
== _T('\0') )
159 dc
.GetTextExtent(current
, &width
, &height
);
160 if ( width
> widthMax
)
163 if ( height
> m_heightLine
)
164 m_heightLine
= height
;
166 m_textLines
.Add(current
);
177 else if ( breakLine
&& (*p
== _T(' ') || *p
== _T('\t')) )
179 // word boundary - break the line here
180 m_textLines
.Add(current
);
187 dc
.GetTextExtent(current
, &width
, &height
);
188 if ( width
> maxLength
)
191 if ( width
> widthMax
)
194 if ( height
> m_heightLine
)
195 m_heightLine
= height
;
199 // take into account the border size and the margins
200 SetClientSize(2*(TEXT_MARGIN_X
+ 1) + widthMax
,
201 2*(TEXT_MARGIN_Y
+ 1) + m_textLines
.GetCount() * m_heightLine
);
205 void wxTipWindow::Close()
211 #endif // wxUSE_TIPWINDOW