]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/tipwin.cpp
fc18fbff7bf706f9f71985348f697fdcc04ca8b0
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 #include "wx/settings.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 static const wxCoord TEXT_MARGIN_X
= 3;
44 static const wxCoord TEXT_MARGIN_Y
= 3;
46 // ============================================================================
48 // ============================================================================
50 // ----------------------------------------------------------------------------
52 // ----------------------------------------------------------------------------
54 BEGIN_EVENT_TABLE(wxTipWindow
, wxPopupTransientWindow
)
55 EVT_LEFT_DOWN(wxTipWindow::OnMouseClick
)
56 EVT_RIGHT_DOWN(wxTipWindow::OnMouseClick
)
57 EVT_MIDDLE_DOWN(wxTipWindow::OnMouseClick
)
58 EVT_PAINT(wxTipWindow::OnPaint
)
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 wxTipWindow::wxTipWindow(wxWindow
*parent
,
68 wxCoord maxLength
, wxTipWindow
** windowPtr
)
69 : wxPopupTransientWindow(parent
)
71 m_windowPtr
= windowPtr
;
74 SetForegroundColour(*wxBLACK
);
77 wxColour
bkCol(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_INFOBK
));
79 wxColour
bkCol(wxColour(255, 255, 225));
81 SetBackgroundColour(bkCol
);
83 // set size and position
84 Adjust(text
, maxLength
);
86 wxGetMousePosition(&x
, &y
);
87 Position(wxPoint(x
, y
+10), wxSize(0,0));
94 wxTipWindow::~wxTipWindow()
102 void wxTipWindow::OnMouseClick(wxMouseEvent
& WXUNUSED(event
))
108 void wxTipWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
113 wxSize size
= GetClientSize();
115 rect
.height
= size
.y
;
117 // first filll the background
118 dc
.SetBrush(wxBrush(GetBackgroundColour(), wxSOLID
));
120 dc
.SetPen( * wxBLACK_PEN
);
121 dc
.DrawRectangle(rect
);
123 // and then draw the text line by line
124 dc
.SetFont(GetFont());
127 pt
.x
= TEXT_MARGIN_X
;
128 pt
.y
= TEXT_MARGIN_Y
;
129 size_t count
= m_textLines
.GetCount();
130 for ( size_t n
= 0; n
< count
; n
++ )
132 dc
.DrawText(m_textLines
[n
], pt
);
134 pt
.y
+= m_heightLine
;
139 void wxTipWindow::Adjust(const wxString
& text
, wxCoord maxLength
)
142 dc
.SetFont(GetFont());
144 // calculate the length: we want each line be no longer than maxLength
145 // pixels and we only break lines at words boundary
147 wxCoord height
, width
,
151 bool breakLine
= FALSE
;
152 for ( const wxChar
*p
= text
.c_str(); ; p
++ )
154 if ( *p
== _T('\n') || *p
== _T('\0') )
156 dc
.GetTextExtent(current
, &width
, &height
);
157 if ( width
> widthMax
)
160 if ( height
> m_heightLine
)
161 m_heightLine
= height
;
163 m_textLines
.Add(current
);
174 else if ( breakLine
&& (*p
== _T(' ') || *p
== _T('\t')) )
176 // word boundary - break the line here
177 m_textLines
.Add(current
);
184 dc
.GetTextExtent(current
, &width
, &height
);
185 if ( width
> maxLength
)
188 if ( width
> widthMax
)
191 if ( height
> m_heightLine
)
192 m_heightLine
= height
;
196 // take into account the border size and the margins
197 SetClientSize(2*(TEXT_MARGIN_X
+ 1) + widthMax
,
198 2*(TEXT_MARGIN_Y
+ 1) + m_textLines
.GetCount() * m_heightLine
);
202 void wxTipWindow::Close()