Bugfix : Zooming works correct, no more errors on screen.
[xara-cairo.git] / wxOil / scrlthmb.cpp
blob6aa33a7d440de7b14d98d2d1b93fa99a5c7cd90a
1 // $Id: scrlthmb.cpp 751 2006-03-31 15:43:49Z alex $
2 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
3 ================================XARAHEADERSTART===========================
5 Xara LX, a vector drawing and manipulation program.
6 Copyright (C) 1993-2006 Xara Group Ltd.
7 Copyright on certain contributions may be held in joint with their
8 respective authors. See AUTHORS file for details.
10 LICENSE TO USE AND MODIFY SOFTWARE
11 ----------------------------------
13 This file is part of Xara LX.
15 Xara LX is free software; you can redistribute it and/or modify it
16 under the terms of the GNU General Public License version 2 as published
17 by the Free Software Foundation.
19 Xara LX and its component source files are distributed in the hope
20 that it will be useful, but WITHOUT ANY WARRANTY; without even the
21 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 See the GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License along
25 with Xara LX (see the file GPL in the root directory of the
26 distribution); if not, write to the Free Software Foundation, Inc., 51
27 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 ADDITIONAL RIGHTS
31 -----------------
33 Conditional upon your continuing compliance with the GNU General Public
34 License described above, Xara Group Ltd grants to you certain additional
35 rights.
37 The additional rights are to use, modify, and distribute the software
38 together with the wxWidgets library, the wxXtra library, and the "CDraw"
39 library and any other such library that any version of Xara LX relased
40 by Xara Group Ltd requires in order to compile and execute, including
41 the static linking of that library to XaraLX. In the case of the
42 "CDraw" library, you may satisfy obligation under the GNU General Public
43 License to provide source code by providing a binary copy of the library
44 concerned and a copy of the license accompanying it.
46 Nothing in this section restricts any of the rights you have under
47 the GNU General Public License.
50 SCOPE OF LICENSE
51 ----------------
53 This license applies to this program (XaraLX) and its constituent source
54 files only, and does not necessarily apply to other Xara products which may
55 in part share the same code base, and are subject to their own licensing
56 terms.
58 This license does not apply to files in the wxXtra directory, which
59 are built into a separate library, and are subject to the wxWindows
60 license contained within that directory in the file "WXXTRA-LICENSE".
62 This license does not apply to the binary libraries (if any) within
63 the "libs" directory, which are subject to a separate license contained
64 within that directory in the file "LIBS-LICENSE".
67 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
68 ----------------------------------------------
70 Subject to the terms of the GNU Public License (see above), you are
71 free to do whatever you like with your modifications. However, you may
72 (at your option) wish contribute them to Xara's source tree. You can
73 find details of how to do this at:
74 http://www.xaraxtreme.org/developers/
76 Prior to contributing your modifications, you will need to complete our
77 contributor agreement. This can be found at:
78 http://www.xaraxtreme.org/developers/contribute/
80 Please note that Xara will not accept modifications which modify any of
81 the text between the start and end of this header (marked
82 XARAHEADERSTART and XARAHEADEREND).
85 MARKS
86 -----
88 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
89 designs are registered or unregistered trademarks, design-marks, and/or
90 service marks of Xara Group Ltd. All rights in these marks are reserved.
93 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
94 http://www.xara.com/
96 =================================XARAHEADEREND============================
99 The proportional scroller thumb window.
105 #include "camtypes.h"
107 #include "scroller.h"
108 #include "scrlthmb.h"
109 #include "csrstack.h"
110 //#include "colordlg.h" // For cursor resources, 'cos I don't like changing camelot.h!
112 #include "brushmsg.h" // for the screenchange message
114 #ifdef _DEBUG
115 #undef THIS_FILE
116 static char BASED_CODE THIS_FILE[] = __FILE__;
117 #endif
119 // Version information.
120 DECLARE_SOURCE("$Revision: 751 $");
124 /********************************************************************************************
125 > void PatB(CDC* hDC, INT32 x, INT32 y, INT32 dx, INT32 dy, COLORREF rgb)
127 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com> (Some MFC dude, actually)
128 Created: 14/3/94
129 Inputs: hDC - destination DC
130 x,y,dx,dy - rectangle to fill
131 rgb - colour to fill with
132 Purpose: Paints a rectangle in the given (dithered) colour
133 It looks pretty hideous, but this is how the MFC buttonbar does it...
134 The conclusions that this leads to are left as an exercise for the reader.
135 (OK, so they're not. It suggest that either MFC sux, or plotting text is
136 easier/faster than creating a brush, in which case Windoze sux)
137 ********************************************************************************************/
139 static void NEAR PASCAL PatB(CDC* cDC, INT32 x, INT32 y, INT32 dx, INT32 dy, COLORREF rgb)
141 RECT rect;
142 rect.left = x;
143 rect.top = y;
144 rect.right = x + dx;
145 rect.bottom = y + dy;
147 cDC->SetBkColor(rgb);
148 cDC->ExtTextOut(0, 0, ETO_OPAQUE, &rect, NULL, 0, NULL);
151 static Cursor *AdjustDragCursor = NULL;
152 static INT32 DragCursorID = 0;
154 /*********************************************************************************************
155 > CScrollerThumb::CScrollerThumb()
157 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
158 Created: ages ago
159 Inputs: -
160 Outputs: -
161 Returns: -
162 Purpose: Constructs a CScrollerThumb C++ object. Sets an internal variable to
163 indicate that the thumb is currently NOT in dragging mode.
164 Errors: -
165 Scope: Public
166 SeeAlso: CScrollerThumb::Create(); CScroller::ConstructThumb()
168 **********************************************************************************************/
170 CScrollerThumb::CScrollerThumb() : Dragging(FALSE)
172 // Nothing to do.
178 /********************************************************************************************
180 > CScrollerThumb::~CScrollerThumb()
182 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
183 Created: 17/11/93
184 Inputs: -
185 Outputs: -
186 Returns: -
187 Purpose: Destructor for class CScrollerThumb. Doesn't precisely nothing.
188 Errors: -
189 SeeAlso: -
191 ********************************************************************************************/
193 CScrollerThumb::~CScrollerThumb()
195 // Nothing to do.
196 // if (Dragging) ::ReleaseCapture();
203 /*********************************************************************************************
204 > virtual BOOL CScrollerThumb::Create(LPCTSTR, LPCTSTR, DWORD style, const RECT& rect,
205 CWnd* parent, UINT32 id, CCreateContext* ctxt = 0)
206 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
207 Created: ages ago
208 Inputs: Two dummy long pointers, not used; the window-instance style flags; the size
209 and position of the window; the parent; the numeric ID, the creation context.
210 Outputs: -
211 Returns: TRUE if the CScrollerThumb is successfully created (attached to a Windows
212 interface element).
213 Purpose: Sets the class cursor used for the thumb window.
214 Errors: -
215 Scope: Public
216 SeeAlso: CScrollerThumb::CScrollerThumb(); CScroller::OnCreate()
217 **********************************************************************************************/
219 BOOL CScrollerThumb::Create(LPCTSTR, LPCTSTR, DWORD style, const RECT& rect,
220 CWnd* parent, UINT32 id, CCreateContext* ctxt)
222 return CWnd::Create(AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT,
223 Cursor::Arrow->Handle(),
227 style | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS,
228 rect,
229 parent,
231 ctxt);
236 /////////////////////////////////////////////////////////////////////////////
237 // CScrollerThumb implementation.
240 /*********************************************************************************************
241 > void CScrollerThumb::PostMsgToScroller(UINT32 msg, CPoint pt) const
243 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
244 Created: ages ago
245 Inputs: The message ID to posted; the (mouse) coordinates, relative to the thumb's
246 client area, to be posted along with the message.
247 Outputs: -
248 Returns: -
249 Purpose: Posts a private message to the parent CScroller window. Converts the
250 coordinates passed in so that they are relative to the CScroller's client
251 area.
252 Errors: -
253 Scope: Private
254 SeeAlso: CScrollerThumb::OnLButtonDown(); CScrollerThumb::OnMouseMove();
255 CScrollerThumb::OnLButtonUp()
256 **********************************************************************************************/
258 void CScrollerThumb::PostMsgToScroller(UINT32 msg, CPoint pt) const
260 ClientToScreen(&pt);
261 GetParent()->ScreenToClient(&pt);
262 GetParent()->PostMessage(msg, pt.x, pt.y);
268 /////////////////////////////////////////////////////////////////////////////
269 // CScrollerThumb message handlers
272 /*********************************************************************************************
273 > afx_msg void CScrollerThumb::OnWin95Paint()
275 Author: Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
276 Created: 4/10/95
277 Inputs: -
278 Outputs: -
279 Returns: -
280 Purpose: Responds to a WM_PAINT message sent by Windows. Paints the light and dark
281 shading around the edge of the thumb, so it looks like the genuine Windows
282 95 article.
283 Errors: -
284 Scope: Protected
285 SeeAlso: -
286 **********************************************************************************************/
287 void CScrollerThumb::OnWin95Paint()
289 // Create a device context to paint on, and find out the extent of this window.
290 CPaintDC dc(this);
291 dc.SetROP2(R2_COPYPEN);
292 CRect rect;
293 GetClientRect(&rect);
295 // Fill the inside of the thumb, drawing a thin black border around it.
296 CBrush interior(::GetSysColor(COLOR_BTNFACE));
297 CBrush* oldbrush = dc.SelectObject(&interior);
299 // Draw the shade inside the bottom and right edges.
300 CPen shade(PS_SOLID, 1,RGB(255,0,0));// ::GetSysColor(COLOR_BTNSHADOW));
301 CPen* oldpen = dc.SelectObject(&shade);
303 dc.Rectangle(&rect);
305 COLORREF TopLeft = GetSysColor(COLOR_BTNFACE);
306 COLORREF BotRight = GetSysColor(COLOR_WINDOWFRAME);
307 COLORREF TopLeftInside = GetSysColor(COLOR_BTNHIGHLIGHT);
308 COLORREF BotRightInside = GetSysColor(COLOR_BTNSHADOW);
310 INT32 x = rect.left;
311 INT32 y = rect.top;
312 INT32 dx = rect.Width();
313 INT32 dy = rect.Height();
315 // The plinth is always made up of 4 right-angle elements
316 // When indented, the colours are swapped, but the elements retain position
317 PatB(&dc, x, y, 1, dy-1, TopLeft);
318 PatB(&dc, x, y, dx-1, 1, TopLeft);
320 PatB(&dc, x+dx-1, y, 1, dy, BotRight);
321 PatB(&dc, x, y+dy-1, dx, 1, BotRight);
323 PatB(&dc, x+1, y+1, 1, dy-2, TopLeftInside);
324 PatB(&dc, x+1, y+1, dx-2, 1, TopLeftInside);
326 PatB(&dc, x+dx-2, y+1, 1, dy-2, BotRightInside);
327 PatB(&dc, x+1, y+dy-2, dx-2, 1, BotRightInside);
329 dc.SelectObject(oldbrush);
330 dc.SelectObject(oldpen);
333 /*********************************************************************************************
334 > afx_msg void CScrollerThumb::OnPaint()
336 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
337 Created: ages ago
338 Inputs: -
339 Outputs: -
340 Returns: -
341 Purpose: Responds to a WM_PAINT message sent by Windows. Paints the light and dark
342 shading around the edge of the thumb, so it looks like the genuine Windows
343 article.
344 Errors: -
345 Scope: Protected
346 SeeAlso: -
347 **********************************************************************************************/
349 void CScrollerThumb::OnPaint()
351 if(CScroller::IsChicago())
353 OnWin95Paint();
354 return;
356 // Create a device context to paint on, and find out the extent of this window.
357 CPaintDC dc(this);
358 dc.SetROP2(R2_COPYPEN);
359 CRect rect;
360 GetClientRect(&rect);
362 // Fill the inside of the thumb, drawing a thin black border around it.
363 CBrush interior(::GetSysColor(COLOR_BTNFACE));
364 CBrush* oldbrush = dc.SelectObject(&interior);
365 dc.Rectangle(&rect);
367 // Draw the shade inside the bottom and right edges.
368 CPen shade(PS_SOLID, 2, ::GetSysColor(COLOR_BTNSHADOW));
369 CPen* oldpen = dc.SelectObject(&shade);
371 dc.MoveTo(rect.left + 2, rect.bottom - 2);
372 dc.LineTo(rect.right - 2, rect.bottom - 2);
373 dc.LineTo(rect.right - 2, rect.top + 2);
375 // Draw the highlight, half as wide, inside the left and top edges.
376 CPen highlight(PS_SOLID, 1, ::GetSysColor(COLOR_BTNHIGHLIGHT));
377 dc.SelectObject(&highlight);
378 dc.MoveTo(rect.left + 1, rect.bottom - 3);
379 dc.LineTo(rect.left + 1, rect.top + 1);
380 dc.LineTo(rect.right - 2, rect.top + 1);
382 // For some reason Windows sometimes refuses to draw the first pixel of the highlight,
383 // so draw that one ourselves. I'm not wasting any more time debugging the display
384 // driver!!
385 dc.SetPixel(rect.left + 1, rect.bottom - 3, ::GetSysColor(COLOR_BTNHIGHLIGHT));
387 // Deselect our drawing tools before they are destroyed.
388 dc.SelectObject(oldbrush);
389 dc.SelectObject(oldpen);
394 /*********************************************************************************************
395 > afx_msg void CScrollerThumb::OnLButtonDown(UINT32 nFlags, CPoint point)
397 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
398 Created: ages ago
399 Inputs: Some flags detailing which buttons and keys were down when the mouse message
400 was generated; the coordinates of the mouse cursor.
401 Outputs: -
402 Returns: -
403 Purpose: Captures the mouse and sends a WM_GRABTHUMB message to the parent CScroller.
404 Errors: -
405 Scope: Protected
406 SeeAlso: CScrollerThumb::PostMsgToScroller(); CScroller::OnGrabThumb();
407 CScrollerThumb::OnMouseMove(); CScrollerThumb::OnLButtonUp()
408 **********************************************************************************************/
410 void CScrollerThumb::OnLButtonDown(UINT32 nFlags, CPoint point)
412 CWnd::OnLButtonDown(nFlags, point);
413 if (!Dragging)
415 Dragging = TRUE;
416 DragIsAdjust = FALSE;
417 SetCapture();
418 PostMsgToScroller(WM_GRABTHUMB, point);
424 /*********************************************************************************************
425 > afx_msg void CScrollerThumb::OnRButtonDown(UINT32 nFlags, CPoint point)
427 Author: Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
428 Created: 16/11/94
429 Inputs: Some flags detailing which buttons and keys were down when the mouse message
430 was generated; the coordinates of the mouse cursor.
431 Outputs: -
432 Returns: -
433 Purpose: Captures the mouse and sends a WM_GRABTHUMBADJ message to the parent CScroller
434 Errors: -
435 Scope: Protected
436 SeeAlso: CScrollerThumb::PostMsgToScroller(); CScroller::OnGrabThumb();
437 CScrollerThumb::OnMouseMove(); CScrollerThumb::OnLButtonUp()
438 **********************************************************************************************/
440 void CScrollerThumb::OnRButtonDown(UINT32 nFlags, CPoint point)
442 CWnd::OnRButtonDown(nFlags, point);
443 if (!Dragging)
445 Dragging = TRUE;
446 DragIsAdjust = TRUE;
447 SetCapture();
449 if (((CScroller *)GetParent())->LinkedScroller != NULL) // If adjust-drag is enabled...
451 // Try to set new pointer shape for the drag
452 if (AdjustDragCursor == NULL)
453 AdjustDragCursor = new Cursor(_R(IDC_ADJUSTSCROLL));
454 if (AdjustDragCursor != NULL)
455 DragCursorID = CursorStack::GPush(AdjustDragCursor);
458 PostMsgToScroller(WM_GRABTHUMBADJ, point);
464 /*********************************************************************************************
465 > afx_msg void CScrollerThumb::OnMouseMove(UINT32 nFlags, CPoint point)
467 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
468 Created: ages ago
469 Inputs: Some flags detailing which buttons and keys were down when the mouse message
470 was generated; the coordinates of the mouse cursor.
471 Outputs: -
472 Returns: -
473 Purpose: Sends a WM_DRAGTHUMB message to the parent CScroller.
474 Errors: -
475 Scope: Protected
476 SeeAlso: CScrollerThumb::PostMsgToScroller(); CScroller::OnDragThumb();
477 CScrollerThumb::OnLButtonDown(); CScrollerThumb::OnLButtonUp()
478 **********************************************************************************************/
480 void CScrollerThumb::OnMouseMove(UINT32 nFlags, CPoint point)
482 CWnd::OnMouseMove(nFlags, point);
483 if (Dragging) PostMsgToScroller((DragIsAdjust) ? WM_DRAGTHUMBADJ : WM_DRAGTHUMB, point);
488 /*********************************************************************************************
489 > afx_msg void CScrollerThumb::OnLButtonUp(UINT32 nFlags, CPoint point)
491 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
492 Created: ages ago
493 Inputs: Some flags detailing which buttons and keys were down when the mouse message
494 was generated; the coordinates of the mouse cursor.
495 Outputs: -
496 Returns: -
497 Purpose: Releases the captured mouse and sends a WM_RELEASETHUMB message to the parent
498 CScroller.
499 Errors: -
500 Scope: Protected
501 SeeAlso: CScrollerThumb::PostMsgToScroller(); CScroller::OnDragThumb();
502 CScrollerThumb::OnLButtonDown(); CScrollerThumb::OnMouseMove()
503 **********************************************************************************************/
505 void CScrollerThumb::OnLButtonUp(UINT32 nFlags, CPoint point)
507 CWnd::OnLButtonUp(nFlags, point);
508 if (Dragging)
510 Dragging = FALSE;
511 ::ReleaseCapture();
512 PostMsgToScroller((DragIsAdjust) ? WM_RELEASETHUMBADJ : WM_RELEASETHUMB, point);
514 // tell people the screen has changed
515 BROADCAST_TO_ALL(ScreenChangeMsg(TRUE));
520 /*********************************************************************************************
521 > afx_msg void CScrollerThumb::OnRButtonUp(UINT32 nFlags, CPoint point)
523 Author: Justin_Flude (Xara Group Ltd) <camelotdev@xara.com> (Jason copied OnLButtonUp, 16/11/94)
524 Created: ages ago
525 Inputs: Some flags detailing which buttons and keys were down when the mouse message
526 was generated; the coordinates of the mouse cursor.
527 Outputs: -
528 Returns: -
529 Purpose: Releases the captured mouse and sends a WM_RELEASETHUMB message to the parent
530 CScroller.
531 Errors: -
532 Scope: Protected
533 SeeAlso: CScrollerThumb::PostMsgToScroller(); CScroller::OnDragThumb();
534 CScrollerThumb::OnLButtonDown(); CScrollerThumb::OnMouseMove()
535 **********************************************************************************************/
537 void CScrollerThumb::OnRButtonUp(UINT32 nFlags, CPoint point)
539 CWnd::OnRButtonUp(nFlags, point);
540 if (Dragging)
542 Dragging = FALSE;
543 ::ReleaseCapture();
545 // Restore old pointer shape after the drag
546 if (AdjustDragCursor != NULL)
548 CursorStack::GPop(DragCursorID);
549 delete AdjustDragCursor;
550 AdjustDragCursor = NULL;
551 DragCursorID = 0;
554 PostMsgToScroller((DragIsAdjust) ? WM_RELEASETHUMBADJ : WM_RELEASETHUMB, point);
556 // tell people things have changed on screen
557 BROADCAST_TO_ALL(ScreenChangeMsg(TRUE));
562 /////////////////////////////////////////////////////////////////////////////
563 // CScrollThumb message map.
565 BEGIN_MESSAGE_MAP(CScrollerThumb, CWnd)
566 //{{AFX_MSG_MAP(CScrollerThumb)
567 ON_WM_PAINT()
568 ON_WM_LBUTTONDOWN()
569 ON_WM_RBUTTONDOWN()
570 ON_WM_MOUSEMOVE()
571 ON_WM_LBUTTONUP()
572 ON_WM_RBUTTONUP()
573 //}}AFX_MSG_MAP
574 END_MESSAGE_MAP()