]>
Commit | Line | Data |
---|---|---|
d90895ac DW |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/tooltip.cpp | |
3 | // Purpose: wxToolTip class implementation for MSW | |
4 | // Author: David Webster | |
5 | // Modified by: | |
6 | // Created: 10/17/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) David Webster | |
6aa89a22 | 9 | // Licence: wxWindows licence |
d90895ac DW |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | #include "wx/wxprec.h" | |
21 | ||
22 | #ifndef WX_PRECOMP | |
23 | #include "wx/wx.h" | |
24 | #endif | |
25 | ||
26 | #if wxUSE_TOOLTIPS | |
27 | ||
28 | #include "wx/tooltip.h" | |
29 | #include "wx/os2/private.h" | |
30 | ||
31 | // ---------------------------------------------------------------------------- | |
32 | // global variables | |
33 | // ---------------------------------------------------------------------------- | |
34 | ||
d90895ac DW |
35 | // ---------------------------------------------------------------------------- |
36 | // ctor & dtor | |
37 | // ---------------------------------------------------------------------------- | |
38 | ||
05facebb DW |
39 | wxToolTip::wxToolTip( |
40 | const wxString& rsTip | |
41 | ) | |
42 | : m_sText(rsTip) | |
43 | , m_pWindow(NULL) | |
d90895ac | 44 | { |
05facebb DW |
45 | Create(rsTip); |
46 | } // end of wxToolTip::wxToolTip | |
d90895ac DW |
47 | |
48 | wxToolTip::~wxToolTip() | |
49 | { | |
05facebb DW |
50 | if (m_hWnd) |
51 | ::WinDestroyWindow(m_hWnd); | |
52 | } // end of wxToolTip::~wxToolTip | |
d90895ac | 53 | |
05facebb DW |
54 | void wxToolTip::Create( |
55 | const wxString& rsTip | |
56 | ) | |
d90895ac | 57 | { |
05facebb DW |
58 | ULONG lStyle = ES_READONLY | ES_MARGIN | ES_CENTER; |
59 | wxColour vColor; | |
60 | LONG lColor; | |
61 | char zFont[128]; | |
62 | ||
63 | m_hWnd = ::WinCreateWindow( HWND_DESKTOP | |
64 | ,WC_ENTRYFIELD | |
65 | ,rsTip.c_str() | |
66 | ,lStyle | |
67 | ,0, 0, 0, 0 | |
68 | ,NULLHANDLE | |
69 | ,HWND_TOP | |
70 | ,1 | |
71 | ,NULL | |
72 | ,NULL | |
73 | ); | |
74 | if (!m_hWnd) | |
75 | wxLogError("Unable to create tooltip window"); | |
76 | ||
77 | vColor.InitFromName("YELLOW"); | |
78 | lColor = (LONG)vColor.GetPixel(); | |
79 | ::WinSetPresParam( m_hWnd | |
80 | ,PP_BACKGROUNDCOLOR | |
81 | ,sizeof(LONG) | |
82 | ,(PVOID)&lColor | |
83 | ); | |
ff5802f3 | 84 | strcpy(zFont, "8.Helv"); |
05facebb DW |
85 | ::WinSetPresParam( m_hWnd |
86 | ,PP_FONTNAMESIZE | |
87 | ,strlen(zFont) + 1 | |
88 | ,(PVOID)zFont | |
89 | ); | |
90 | } // end of wxToolTip::Create | |
91 | ||
92 | void wxToolTip::DisplayToolTipWindow( | |
93 | const wxPoint& rPoint | |
94 | ) | |
d90895ac | 95 | { |
05facebb DW |
96 | LONG lX = rPoint.x; |
97 | LONG lY = rPoint.y - 30; | |
98 | LONG lWidth = 0L; | |
99 | LONG lHeight = 0L; | |
100 | ||
5d644707 | 101 | lWidth = m_sText.Length() * 8; |
05facebb DW |
102 | lHeight = 15; |
103 | ::WinSetWindowPos( m_hWnd | |
104 | ,HWND_TOP | |
105 | ,lX | |
106 | ,lY | |
107 | ,lWidth | |
108 | ,lHeight | |
109 | ,SWP_MOVE | SWP_SIZE | SWP_SHOW | |
110 | ); | |
111 | } // end of wxToolTip::DisplayToolTipWindow | |
112 | ||
113 | void wxToolTip::HideToolTipWindow() | |
d90895ac | 114 | { |
05facebb DW |
115 | ::WinShowWindow(m_hWnd, FALSE); |
116 | } // end of wxToolTip::HideToolTipWindow | |
d90895ac | 117 | |
05facebb DW |
118 | void wxToolTip::SetTip( |
119 | const wxString& rsTip | |
120 | ) | |
121 | { | |
122 | SWP vSwp; | |
123 | LONG lWidth = 0L; | |
124 | LONG lHeight = 0L; | |
125 | ||
126 | ::WinQueryWindowPos(m_hWnd, &vSwp); | |
127 | m_sText = rsTip; | |
ff5802f3 | 128 | lWidth = rsTip.Length() * 8; |
05facebb DW |
129 | lHeight = 15; |
130 | ::WinSetWindowPos( m_hWnd | |
131 | ,HWND_TOP | |
132 | ,vSwp.cx | |
133 | ,vSwp.cy | |
134 | ,lWidth | |
135 | ,lHeight | |
136 | ,SWP_MOVE | SWP_SIZE | SWP_SHOW | |
137 | ); | |
138 | } // end of wxToolTip::SetTip | |
d90895ac DW |
139 | |
140 | #endif // wxUSE_TOOLTIPS |