00001 // $Id: bblwnd.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 00099 // A class to implement the bubble help window. 00100 00101 00102 #include "camtypes.h" 00103 00104 #include "bblwnd.h" 00105 00106 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00107 //#include "resource.h" 00108 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00109 #include "fonts.h" 00110 #include "camelot.h" // IsWin32s 00111 00112 #include <multimon.h> 00113 00114 char *BubbleHelpWnd::BubbleClass = NULL; 00115 00116 #define TEXT_NOBUBBLEHELP "NO bubble help!" 00117 00118 // The new COLOR variables are only defined on VC4/MFC4, so only do this on this version or later 00119 // Use the same criteria that winuser.h uses to define them. We will only define them when it 00120 // doesn't 00121 #if (WINVER < 0x0400) 00122 #define COLOR_INFOTEXT 23 00123 #define COLOR_INFOBK 24 00124 #endif 00125 00126 /******************************************************************************************** 00127 00128 > BubbleHelpWnd::BubbleHelpWnd() 00129 00130 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00131 Created: 28/04/94 00132 Purpose: Construct a bubble help window. This gets a handle to the font that the 00133 window will use (this handle is released when the window is destroyed). 00134 SeeAlso: BubbleHelpWnd::Init 00135 00136 ********************************************************************************************/ 00137 00138 BubbleHelpWnd::BubbleHelpWnd() 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 } 00145 00146 /******************************************************************************************** 00147 00148 > BubbleHelpWnd::~BubbleHelpWnd() 00149 00150 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00151 Created: 28/04/94 00152 Purpose: Deletes a bubble help window - frees up any buffers used to remember the 00153 bubble help text, and gives the font handle back to Windows. 00154 SeeAlso: BubbleHelpWnd::Init 00155 00156 ********************************************************************************************/ 00157 00158 BubbleHelpWnd::~BubbleHelpWnd() 00159 { 00160 free(BubbleText); 00161 00162 // Call this here to prevent MFC giving us an annoying warning... 00163 DestroyWindow(); 00164 } 00165 00166 // Usual MFC message map affair: 00167 00168 BEGIN_MESSAGE_MAP(BubbleHelpWnd, CWnd) 00169 //{{AFX_MSG_MAP(BubbleHelpWnd) 00170 ON_WM_CREATE() 00171 ON_WM_NCPAINT() 00172 ON_WM_PAINT() 00173 ON_WM_NCCALCSIZE() 00174 //}}AFX_MSG_MAP 00175 END_MESSAGE_MAP() 00176 00177 00179 // BubbleHelpWnd message handlers 00180 00181 00182 /******************************************************************************************** 00183 00184 > void BubbleHelpWnd::OnNcPaint() 00185 00186 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00187 Created: 29/04/94 00188 Purpose: We override this even though we have no client area just in case... 00189 SeeAlso: BubbleHelpWnd::OnPaint 00190 00191 ********************************************************************************************/ 00192 00193 void BubbleHelpWnd::OnNcPaint() 00194 { 00195 // Do not call CWnd::OnNcPaint() for painting messages 00196 } 00197 00198 /******************************************************************************************** 00199 00200 > void BubbleHelpWnd::OnPaint() 00201 00202 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00203 Created: 29/04/94 00204 Purpose: Paint the bubble help window's client area. i.e. draw the rounded 00205 rectangle and paint the bubble help text into it. 00206 00207 ********************************************************************************************/ 00208 00209 void BubbleHelpWnd::OnPaint() 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 } 00313 00314 /******************************************************************************************** 00315 00316 > void BubbleHelpWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 00317 00318 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00319 Created: 29/04/94 00320 Inputs: See CWnd::OnNcCalcSize 00321 Outputs: See CWnd::OnNcCalcSize 00322 Purpose: Inform Windows that we have no non-client area - we actually do nothing 00323 in this function, but if we don't override it, MFC/Windows will give us 00324 a non-client area, which we don't want. 00325 00326 ********************************************************************************************/ 00327 00328 void BubbleHelpWnd::OnNcCalcSize(BOOL bCalcValidRects, NCCALCSIZE_PARAMS FAR* lpncsp) 00329 { 00330 // Do nothing - we have no non-client area! 00331 } 00332 00333 00334 /******************************************************************************************** 00335 00336 > BOOL BubbleHelpWnd::Init() 00337 00338 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00339 Created: 29/04/94 00340 Returns: TRUE if the bubble help system intialised ok; 00341 FALSE if not. 00342 Purpose: Initialise the bubble help system. This should be done once and only once 00343 before using a BubbleHelpWnd object. 00344 This function registers the special window class we use for the bubble help. 00345 Errors: Out of memory. 00346 SeeAlso: BubbleHelpWnd::Create 00347 Scope: Static 00348 00349 ********************************************************************************************/ 00350 00351 BOOL BubbleHelpWnd::Init() 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 } 00363 00364 00365 00366 /******************************************************************************************** 00367 00368 > BOOL BubbleHelpWnd::DeInit() 00369 00370 Author: Karim_MacDonald (Xara Group Ltd) <camelotdev@xara.com> 00371 Created: 28 September 2000 00372 Purpose: Deinitialises the bubble help system. 00373 Actually this consists of freeing the BubbleClass static string, 00374 as otherwise it leaks memory. 00375 00376 ********************************************************************************************/ 00377 BOOL BubbleHelpWnd::DeInit() 00378 { 00379 free(BubbleClass); 00380 return TRUE; 00381 } 00382 00383 00384 00385 /******************************************************************************************** 00386 00387 > BOOL BubbleHelpWnd::Create() 00388 00389 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00390 Created: 29/04/94 00391 Returns: TRUE if the window was created ok; 00392 FALSE if not. 00393 Purpose: Create a window and associate it with this BubbleHelpWnd object. 00394 This will fail if BubbleHelpWnd::Init has not been called. 00395 Errors: Bubble help system not initialised; Unable to create the window. 00396 SeeAlso: BubbleHelpWnd::Init 00397 00398 ********************************************************************************************/ 00399 00400 BOOL BubbleHelpWnd::Create() 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 } 00418 00419 /******************************************************************************************** 00420 00421 > BOOL BubbleHelpWnd::SetText(UINT32 ResID, UINT32 ModuleID = 0) 00422 00423 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00424 Created: 29/04/94 00425 Inputs: ResID - a resource ID to use 00426 ModuleID - the module ID (used to locate the string resource). 00427 Returns: TRUE if the text was found and set ok; 00428 FALSE if not. 00429 Purpose: Set the text string to be used in the bubble help window. 00430 Errors: Unable to find resource; Out of memory 00431 00432 ********************************************************************************************/ 00433 00434 BOOL BubbleHelpWnd::SetText(UINT32 ResID, UINT32 ModuleID) 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 } 00451 00452 /******************************************************************************************** 00453 00454 > BOOL BubbleHelpWnd::SetText(TCHAR *Text) 00455 00456 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00457 Created: 05/05/94 00458 Inputs: ResID - a resource ID to use 00459 ModuleID - the module ID (used to locate the string resource). 00460 Returns: TRUE if the text was found and set ok; 00461 FALSE if not. 00462 Purpose: Set the text string to be used in the bubble help window. 00463 (This is used by the overloaded version of SetText, but can be used by 00464 other clients, e.g. ControlHelper uses it to do ad-hoc help). 00465 Errors: Out of memory 00466 00467 ********************************************************************************************/ 00468 00469 BOOL BubbleHelpWnd::SetText(TCHAR *Text) 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 } 00520 00521 /******************************************************************************************** 00522 00523 > void BubbleHelpWnd::Show() 00524 00525 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00526 Created: 05/05/94 00527 Purpose: Shows the bubble help window - it is sized and positioned automatically. 00528 SeeAlso: BubbleHelpWnd::Hide 00529 00530 ********************************************************************************************/ 00531 00532 void BubbleHelpWnd::Show() 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 } 00577 00578 /******************************************************************************************** 00579 00580 > void BubbleHelpWnd::Hide() 00581 00582 Author: Tim_Browse (Xara Group Ltd) <camelotdev@xara.com> 00583 Created: 05/05/94 00584 Purpose: Hides the bubble help window but does not destroy it. 00585 SeeAlso: BubbleHelpWnd::Show 00586 00587 ********************************************************************************************/ 00588 00589 void BubbleHelpWnd::Hide() 00590 { 00591 ShowWindow(SW_HIDE); 00592 } 00593 00594