#include <bblwnd.h>
Public Member Functions | |
BubbleHelpWnd () | |
Construct a bubble help window. This gets a handle to the font that the window will use (this handle is released when the window is destroyed). | |
BOOL | Create () |
Create a window and associate it with this BubbleHelpWnd object. This will fail if BubbleHelpWnd::Init has not been called. | |
BOOL | SetText (UINT32 ResID, UINT32 ModuleID=0) |
Set the text string to be used in the bubble help window. | |
BOOL | SetText (TCHAR *) |
Set the text string to be used in the bubble help window. (This is used by the overloaded version of SetText, but can be used by other clients, e.g. ControlHelper uses it to do ad-hoc help). | |
void | Show () |
Shows the bubble help window - it is sized and positioned automatically. | |
void | Hide () |
Hides the bubble help window but does not destroy it. | |
void | MoveTo (INT32 x, INT32 y) |
virtual | ~BubbleHelpWnd () |
Deletes a bubble help window - frees up any buffers used to remember the bubble help text, and gives the font handle back to Windows. | |
Static Public Member Functions | |
static BOOL | Init () |
Initialise the bubble help system. This should be done once and only once before using a BubbleHelpWnd object. This function registers the special window class we use for the bubble help. | |
static BOOL | DeInit () |
Deinitialises the bubble help system. Actually this consists of freeing the BubbleClass static string, as otherwise it leaks memory. | |
Protected Member Functions | |
afx_msg void | OnNcPaint () |
We override this even though we have no client area just in case... | |
afx_msg void | OnPaint () |
Paint the bubble help window's client area. i.e. draw the rounded rectangle and paint the bubble help text into it. | |
afx_msg void | OnNcCalcSize (BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR *lpncsp) |
Inform Windows that we have no non-client area - we actually do nothing in this function, but if we don't override it, MFC/Windows will give us a non-client area, which we don't want. | |
Protected Attributes | |
TCHAR * | BubbleText |
wxFont * | BubbleFont |
POINT | BubbleSize |
Static Protected Attributes | |
static char * | BubbleClass = NULL |
Definition at line 120 of file bblwnd.h.
|
Construct a bubble help window. This gets a handle to the font that the window will use (this handle is released when the window is destroyed).
Definition at line 138 of file bblwnd.cpp. 00139 { 00140 BubbleText = NULL; 00141 00142 // Get the font we want to use for this bubble help window. 00143 BubbleFont = FontFactory::GetCFont(STOCKFONT_BUBBLEHELP); 00144 }
|
|
Deletes a bubble help window - frees up any buffers used to remember the bubble help text, and gives the font handle back to Windows.
Definition at line 158 of file bblwnd.cpp. 00159 { 00160 free(BubbleText); 00161 00162 // Call this here to prevent MFC giving us an annoying warning... 00163 DestroyWindow(); 00164 }
|
|
Create a window and associate it with this BubbleHelpWnd object. This will fail if BubbleHelpWnd::Init has not been called.
Definition at line 400 of file bblwnd.cpp. 00401 { 00402 ENSURE(BubbleClass != NULL, "Bubble help window class has not been registered!"); 00403 00404 if (BubbleClass == NULL) 00405 // System has not initialised so don't create a window. 00406 return FALSE; 00407 00408 // Create the window (but ensure it is not visible) 00409 // WS_CHILD is needed to prevent MFC asserting because we're using the default 00410 // window class (I don't know why they enforce this...) 00411 return CreateEx(0, BubbleClass, NULL, 00412 (WS_POPUP & (~WS_VISIBLE)) // | WS_CHILD | WS_CLIPCHILDREN 00413 , 00414 CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 00415 AfxGetMainWnd()->GetSafeHwnd(), 00416 NULL); 00417 }
|
|
Deinitialises the bubble help system. Actually this consists of freeing the BubbleClass static string, as otherwise it leaks memory.
Definition at line 377 of file bblwnd.cpp. 00378 { 00379 free(BubbleClass); 00380 return TRUE; 00381 }
|
|
Hides the bubble help window but does not destroy it.
Definition at line 589 of file bblwnd.cpp.
|
|
Initialise the bubble help system. This should be done once and only once before using a BubbleHelpWnd object. This function registers the special window class we use for the bubble help.
Definition at line 351 of file bblwnd.cpp. 00352 { 00353 // Register our special window class. 00354 // Text returned by AfxRegisterWndClass is only a static buffer, so we take a copy of 00355 // it for our own use. 00356 BubbleClass = camStrdup(AfxRegisterWndClass(CS_SAVEBITS)); 00357 ENSURE(BubbleClass != NULL, "Bubble help window class could not be registered!"); 00358 ERRORIF(BubbleClass == NULL, _R(IDS_OUT_OF_MEMORY), FALSE); 00359 00360 // All ok 00361 return TRUE; 00362 }
|
|
|
|
Inform Windows that we have no non-client area - we actually do nothing in this function, but if we don't override it, MFC/Windows will give us a non-client area, which we don't want.
Definition at line 328 of file bblwnd.cpp.
|
|
We override this even though we have no client area just in case...
Definition at line 193 of file bblwnd.cpp.
|
|
Paint the bubble help window's client area. i.e. draw the rounded rectangle and paint the bubble help text into it.
Definition at line 209 of file bblwnd.cpp. 00210 { 00211 CPaintDC dc(this); // device context for painting 00212 00213 // In debug builds, if no bubble help exists we show the "No Bubble Help!!" message 00214 // in yellow on red. In retail builds we just don't do anything if there is no 00215 // bubble help. 00216 #if _DEBUG 00217 BOOL NoBubbleHelp = (camStrcmp(BubbleText, TEXT_NOBUBBLEHELP) == 0); 00218 #endif 00219 00220 // Create the yellow brush to paint the client area (unless we have no bubble help 00221 // and it's a debug build) 00222 // Instead of yellow use the new Tool tip system colours that are new in Windows 95 00223 // and in NT 3.51 00224 CBrush Brush; 00225 00226 COLORREF BubbleBorderColour = GetSysColor(COLOR_WINDOWFRAME); 00227 COLORREF BubbleTextColour = RGB(0,0,0); // Black 00228 COLORREF BubbleBackgroundColour = RGB(255,255,100); // Yellow 00229 00230 #if _DEBUG 00231 // If no bubble help and on debug versions then use special colours 00232 if (NoBubbleHelp) 00233 { 00234 BubbleBorderColour = RGB(255,0,0); // Red 00235 BubbleTextColour = RGB(255,0,0); // Red 00236 BubbleBackgroundColour = RGB(0,255,0); // Blue 00237 } 00238 else 00239 #endif 00240 { 00241 // Use the proper Windows 95 bubble help text and background colour if 00242 // we are not on Win32s, as this doesn't support it, and as a double check 00243 // see if the bubble help foreground and background colours are different. This 00244 // should stop NT3.5 being wrong as these colours are unlikely to be defined. On 00245 // NT3.51 they are defined. 00246 if ( 00247 //( IsWindows95() || IsWindowsNT() ) && 00248 CCamApp::IsPartialNewWindowsUI() && 00249 ( GetSysColor(COLOR_INFOTEXT) != GetSysColor(COLOR_INFOBK) ) 00250 ) 00251 { 00252 BubbleTextColour = GetSysColor(COLOR_INFOTEXT); 00253 BubbleBackgroundColour = GetSysColor(COLOR_INFOBK); 00254 } 00255 } 00256 00257 // Create the brush for the background colour 00258 Brush.CreateSolidBrush(BubbleBackgroundColour); 00259 00260 // Get the size of the window 00261 RECT rect; 00262 GetClientRect(&rect); 00263 00264 // Create the pen and select into the DC. 00265 CPen Pen; 00266 Pen.CreatePen(PS_SOLID, 0, BubbleBorderColour); 00267 CPen *OldPen = dc.SelectObject(&Pen); 00268 00269 // Fill in the background colour 00270 InflateRect(&rect, -1, -1); 00271 dc.FillRect(&rect, &Brush); 00272 InflateRect(&rect, 1, 1); 00273 00274 // Paint the rounded border 00275 POINT Points[9]; 00276 00277 Points[0].x = rect.left + 2; Points[0].y = rect.top; 00278 Points[1].x = rect.right - 3; Points[1].y = rect.top; 00279 Points[2].x = rect.right - 1; Points[2].y = rect.top + 2; 00280 Points[3].x = rect.right - 1; Points[3].y = rect.bottom - 3; 00281 Points[4].x = rect.right - 3; Points[4].y = rect.bottom - 1; 00282 Points[5].x = rect.left + 2; Points[5].y = rect.bottom - 1; 00283 Points[6].x = rect.left; Points[6].y = rect.bottom - 3; 00284 Points[7].x = rect.left; Points[7].y = rect.top + 2; 00285 Points[8].x = rect.left + 2; Points[8].y = rect.top; 00286 00287 dc.Polyline(Points, 9); 00288 00289 // Use a nice small font 00290 CFont *OldFont = dc.SelectObject(BubbleFont); 00291 00292 CString BubbleString(BubbleText); 00293 00294 dc.SetBkMode(TRANSPARENT); 00295 00296 // If it has no bubble help then do the text in red (only in debug builds) 00297 // else do it in the proper text colour 00298 #if _DEBUG 00299 if (NoBubbleHelp) 00300 dc.SetTextColor(RGB(255,0,0)); // Red 00301 else 00302 #endif 00303 dc.SetTextColor(BubbleTextColour); 00304 00305 dc.TextOut(3, 1, BubbleString); 00306 00307 // Clean up 00308 dc.SelectObject(OldFont); 00309 dc.SelectObject(OldPen); 00310 00311 // Do not call CWnd::OnPaint() for painting messages 00312 }
|
|
Set the text string to be used in the bubble help window. (This is used by the overloaded version of SetText, but can be used by other clients, e.g. ControlHelper uses it to do ad-hoc help).
Definition at line 469 of file bblwnd.cpp. 00470 { 00471 if (BubbleText != NULL) 00472 // Delete previous text 00473 free(BubbleText); 00474 00475 #if _DEBUG 00476 00477 if ((Text == NULL) || (Text[0] == 0)) 00478 BubbleText = camStrdup(TEXT_NOBUBBLEHELP); 00479 else 00480 BubbleText = camStrdup(Text); 00481 00482 #else 00483 00484 if ((Text == NULL) || (Text[0] == 0)) 00485 // No text! 00486 return FALSE; 00487 00488 BubbleText = camStrdup(Text); 00489 00490 #endif 00491 00492 if (BubbleText == NULL) 00493 // Out of memory 00494 return FALSE; 00495 00496 // Work out how big the window should be. 00497 00498 // Get a context 00499 CDC *dc = GetWindowDC(); 00500 00501 // Get a nice small font 00502 CFont *OldFont = dc->SelectObject(BubbleFont); 00503 00504 // Find out how big this text is. 00505 CSize TextSize = dc->GetTextExtent(BubbleText, camStrclen(BubbleText)); 00506 00507 // Clean up and release the DC 00508 dc->SelectObject(OldFont); 00509 ReleaseDC(dc); 00510 00511 // Set the window size according to the text size 00512 BubbleSize.x = TextSize.cx + 5; 00513 BubbleSize.y = TextSize.cy + 3; 00514 SetWindowPos(NULL, 0, 0, BubbleSize.x, BubbleSize.y, 00515 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE); 00516 00517 // All worked ok 00518 return TRUE; 00519 }
|
|
Set the text string to be used in the bubble help window.
Definition at line 434 of file bblwnd.cpp. 00435 { 00436 if (ResID == 0) 00437 { 00438 #if _DEBUG 00439 return SetText(""); 00440 #else 00441 // Duff string resource ID - ignore it. 00442 return FALSE; 00443 #endif 00444 } 00445 00446 // Make a string out of it 00447 String_64 BubbleString; 00448 BubbleString.Load(ResID, ModuleID); 00449 return SetText((TCHAR *)BubbleString); 00450 }
|
|
Shows the bubble help window - it is sized and positioned automatically.
Definition at line 532 of file bblwnd.cpp. 00533 { 00534 // Work out where to put window based on cursor position 00535 POINT CursorPos; 00536 ::GetCursorPos(&CursorPos); 00537 00538 // Centre the window under the cursor. 00539 POINT Pos; 00540 Pos.x = CursorPos.x - (BubbleSize.x / 2) + 10; 00541 Pos.y = CursorPos.y + 16; 00542 00543 RECT PossibleBubbleWin; 00544 PossibleBubbleWin.left = Pos.x; 00545 PossibleBubbleWin.right = Pos.x + BubbleSize.x; 00546 PossibleBubbleWin.top = Pos.y; 00547 PossibleBubbleWin.bottom = Pos.y + BubbleSize.y; 00548 00549 MONITORINFO mi; 00550 mi.cbSize = sizeof(MONITORINFO); 00551 if (GetMonitorInfo(MonitorFromRect(&PossibleBubbleWin, MONITOR_DEFAULTTONEAREST), &mi) == 0) 00552 { 00553 SetWindowPos(NULL, Pos.x, Pos.y, 0, 0, 00554 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE); 00555 TRACE( _T("Could not find a monitor to display bubble help on\n")); 00556 return; 00557 } 00558 00559 // Make sure the window stays on a screen 00560 RECT Rect = mi.rcMonitor; 00561 if (Pos.x < Rect.left) 00562 Pos.x = Rect.left; 00563 if (Pos.x + BubbleSize.x > Rect.right) 00564 Pos.x = Rect.right - BubbleSize.x; 00565 if (Pos.y < Rect.top) 00566 Pos.y = Rect.top; 00567 00568 if (Pos.y + BubbleSize.y > Rect.bottom) 00569 { 00570 // If we move up we'll probably cover the cursor, so make sure it's above the cursor 00571 Pos.y = CursorPos.y - 20; 00572 } 00573 00574 SetWindowPos(NULL, Pos.x, Pos.y, 0, 0, 00575 SWP_SHOWWINDOW | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE); 00576 }
|
|
|
|
|
|
|
|
|