X64 transport [Part 5] (Update plugins.cpp)
[xy_vsfilter.git] / src / apps / mplayerc / LineNumberEdit.cpp
blob563bd4a155a517d74c48a3bf05633da49ef61c03
1 /* ==========================================================================
2 CLineNumberEdit
3 Author : Johan Rosengren, Abstrakt Mekanik AB
4 Date : 2004-03-09
5 Purpose : CLineNumberEdit is a CEdit-derived class that displays
6 line numbers to the left of the text.
7 Description : The class uses the edit rect to make space for the line
8 numbers. The line numbers are relized through a special
9 CStatic-derived class, CLineNumberStatic. As soon as the
10 text is updated, the CLineNumberStatic is updated as
11 well.
12 Usage : The control can be dynamically created, or created from
13 a dialog template. The formatting string for the line
14 numbers can be set by calling SetLineNumberFormat (the
15 same format string as for CString::Format). By calling
16 SetMarginForegroundColor or SetMarginBackgroundColor
17 the fore- and background colors for the line number
18 display is set.
19 ========================================================================
20 Update : Keith Bowes
21 Date : 2004-04-13
22 Purpose : 1. To allow CLineNumberEdit to properly change colour when
23 Enabled/Disabled or when system colours change.
24 Changing system colours only has a noticable effect when
25 a scheme such as Marine or Plum is chosen.
26 2. To allow a line number delta to be applied to the first
27 line number so the index does not have to start at zero.
28 3. To allow a max value to be specified to stop the line
29 count and to allow smarter size formatting.
30 Description : 1. Added OnEnable and OnSysColorChange to detect when
31 a colour change is required. This allows the line number
32 area and CEdit area to update colours properly.
33 Added colour ref variables to hold enabled/disabled states
34 of the background/foreground colours.
35 In an attempt to allow previous functionality to take
36 precedence, if the colours are changed explicitly, the
37 system colours are no longer queried.
38 2. Added m_LineDelta, applied when line numbers are formatted.
39 3. Using m_maxval when > 0 to limit the max values and when
40 formatting colomn width.
41 JRO: Added m_lineDelta as well.
42 Usage : 1. Default behaviour is to change colours to reflect CEdit.
43 manually changing the colour will cause the colours to
44 only change to the specified colours.
45 2. SetLineNumberRange sets both min and max values.
46 3. SetLineNumberRange sets both min and max values.
48 Comments : - Perhaps line values should be stored as UINT's as negative
49 values may have unexpected results.
50 - CLineNumberEdit::m_format creates a duplicate of
51 CLineNumberStatic::m_format, is this needed?
52 JRO: Even though the the two classes are thightly coupled,
53 this duplication of data makes it easier to decouple them.
54 A small matter, but code reuse is Politically Correct,
55 and as such A Desirable Feature.
56 - Added options could allow different system colours to be
57 chosen and updated as system attributes are changed.
58 - if m_maxval is exceeded in the edit box, new lines
59 are added without line numbers. This might not be the
60 desired behaviour.
61 JRO: I think this is rather nifty, actually. If I, as a
62 developer, sets the max number of lines to be numbered,
63 I also expect this to be the case :-)))
64 - It's not spelled wrong, just differently. ;0)
65 ========================================================================
66 Update : Johan Rosengren
67 Date : 2004-04-14
68 Purpose : 1. Allow deriving of CLineNumberEdit.
69 Description : 1. Made the message handlers virtual.
70 Usage : 1. Declare message handlers as virtual in derived
71 classes. Note that CLineNumberEdit is not built to
72 be derived from, however.
73 ========================================================================
74 Update : Keith Bowes
75 Date : 2004-04-22
76 Purpose : To allow processing of WM_LINESCROLL messages.
77 Description : Added OnLineScroll to handle the message.
78 Usage : Now will call UpdateTopAndBottom if the message is
79 received.
80 ========================================================================
81 Update : Johan Rosengren
82 Date : 2004-05-02
83 Purpose : Select complete line when a line-number is clicked
84 Description : Added registered user message, sent when the line-
85 number static is clicked.
86 Usage : See urm_SELECTLINE in the code.
87 ========================================================================*/
89 #include "stdafx.h"
90 #include "LineNumberEdit.h"
92 #ifdef _DEBUG
93 #define new DEBUG_NEW
94 #undef THIS_FILE
95 static char THIS_FILE[] = __FILE__;
96 #endif
98 // Registered message to allow selection of complete
99 // lines by clicking the line number
100 UINT urm_SELECTLINE = ::RegisterWindowMessage( _T("_LINE_NUMBER_EDIT_SELECTLINE_") );
102 /////////////////////////////////////////////////////////////////////////////
103 // CLineNumberEdit
104 CLineNumberEdit::CLineNumberEdit()
105 /* ============================================================
106 Function : CLineNumberEdit::CLineNumberEdit
107 Description : constructor
109 Return : void
110 Parameters : none
112 Usage :
114 ============================================================*/
117 m_hWnd = NULL;
118 m_line.m_hWnd = NULL;
119 m_zero.cx = 0;
120 m_zero.cy = 0;
121 m_format = _T( "%03i" );
122 m_LineDelta = 1;
124 // Could default m_maxval to 99,999, but may cause problems
125 // if m_format is changed and m_maxval is not...
126 m_maxval = 998;
128 // Setting up so by defult the original hard-coded colour
129 // scheme is used when enabled and the system colours are
130 // used when disabled.
131 m_bUseEnabledSystemColours = FALSE;
132 m_bUseDisabledSystemColours = TRUE;
133 m_EnabledFgCol = RGB( 0, 0, 0 );
134 m_EnabledBgCol = RGB( 200, 200, 200 );
135 m_DisabledFgCol = GetSysColor( COLOR_GRAYTEXT );
136 m_DisabledBgCol = GetSysColor( COLOR_3DFACE );
138 SetWindowColour();
142 CLineNumberEdit::~CLineNumberEdit()
143 /* ============================================================
144 Function : CLineNumberEdit::~CLineNumberEdit
145 Description : destructor
147 Return : void
148 Parameters : none
150 Usage :
152 ============================================================*/
156 BEGIN_MESSAGE_MAP(CLineNumberEdit, CEdit)
157 ON_CONTROL_REFLECT(EN_CHANGE, OnChange)
158 ON_WM_VSCROLL()
159 ON_CONTROL_REFLECT(EN_VSCROLL, OnVscroll)
160 ON_MESSAGE(WM_SETFONT, OnSetFont)
161 ON_WM_SIZE()
162 ON_MESSAGE(WM_SETTEXT, OnSetText)
163 ON_WM_SYSCOLORCHANGE()
164 ON_WM_ENABLE()
165 ON_MESSAGE(EM_LINESCROLL, OnLineScroll)
166 ON_REGISTERED_MESSAGE(urm_SELECTLINE, OnSelectLine)
167 END_MESSAGE_MAP()
169 void CLineNumberEdit::PreSubclassWindow()
170 /* ============================================================
171 Function : CLineNumberEdit::PreSubclassWindow
172 Description : This function is called before the control
173 is subclassed for a control on a dialog
174 template, and during creation for
175 dynamically created controls.
177 Return : void
178 Parameters : none
180 Usage : Called from MFC
182 ============================================================*/
185 // Unfortunately, we can't change to ES_MULTILINE
186 // during run-time.
187 ASSERT( GetStyle() & ES_MULTILINE );
189 // Creating the line number control
190 SetLineNumberFormat( m_format );
194 /////////////////////////////////////////////////////////////////////////////
195 // CLineNumberEdit message handlers
197 void CLineNumberEdit::OnSysColorChange()
198 /* ============================================================
199 Function : CLineNumberEdit::OnSysColorChange
200 Description : Handles WM_SYSCOLORCHANGE. User has changed
201 the system colours, want to refresh.
203 Return : void
204 Parameters : void
206 Usage : Called from Windows
208 ============================================================*/
211 CEdit::OnSysColorChange();
213 // update the CStatic with the new colours
214 SetWindowColour( IsWindowEnabled() );
218 LRESULT CLineNumberEdit::OnSetText( WPARAM wParam, LPARAM lParam )
219 /* ============================================================
220 Function : CLineNumberEdit::OnSetText
221 Description : Handles WM_SETTEXT. We must update the line
222 numbers in the line number control as well.
224 Return : LRESULT - From Def proc
225 Parameters : WPARAM wParam - From Windows
226 LPARAM lParam - From Windows
228 Usage : Called from Windows
230 ============================================================*/
233 // Default processing
234 LRESULT retval = DefWindowProc( WM_SETTEXT, wParam, lParam );
235 UpdateTopAndBottom();
236 return retval;
240 void CLineNumberEdit::OnChange()
241 /* ============================================================
242 Function : CLineNumberEdit::OnChange
243 Description : Mapped to EN_CHANGE. We must handle
244 EN_CHANGE to let the line-number control
245 reflect changes to the edit box content.
247 Return : void
248 Parameters : none
250 Usage : Called from Windows
252 ============================================================*/
255 UpdateTopAndBottom();
259 void CLineNumberEdit::OnVscroll()
260 /* ============================================================
261 Function : CLineNumberEdit::OnVscroll
262 Description : Mapped to EN_VSCROLL. We update the line
263 numbers in the line number control
265 Return : void
266 Parameters : none
268 Usage : Called from Windows
270 ============================================================*/
273 UpdateTopAndBottom();
277 void CLineNumberEdit::OnVScroll( UINT nSBCode, UINT nPos, CScrollBar* pScrollBar )
278 /* ============================================================
279 Function : CLineNumberEdit::OnVScroll
280 Description : Handles WM_VSCROLL. We handle WM_VSCROLL
281 in addition to the notification EN_VSCROLL,
282 to handle scrollbar dragging as well
284 Return : void
285 Parameters : UINT nSBCode - From Windows
286 UINT nPos - From Windows
287 CScrollBar* pScrollBar - From Windows
289 Usage : Called from Windows
291 ============================================================*/
294 CEdit::OnVScroll( nSBCode, nPos, pScrollBar );
295 UpdateTopAndBottom();
299 LRESULT CLineNumberEdit::OnLineScroll( WPARAM wParam, LPARAM lParam )
300 /* ============================================================
301 Function : CLineNumberEdit::OnLineScroll
302 Description : Mapped to EM_LINESCROLL. We update the line
303 numbers in the line number control.
305 Return : void
306 Parameters : none
307 Usage : Called from Windows
308 ============================================================*/
311 // Default processing
312 LRESULT retval = DefWindowProc( EM_LINESCROLL, wParam, lParam );
313 UpdateTopAndBottom();
314 return retval;
318 LRESULT CLineNumberEdit::OnSetFont( WPARAM wParam, LPARAM lParam )
319 /* ============================================================
320 Function : CLineNumberEdit::OnSetFont
321 Description : Mapped to WM_SETFONT. We must recalculate
322 the line number control size as well.
324 Return : LRESULT - Always 0
325 Parameters : WPARAM wParam - From Windows
326 LPARAM lParam - From Windows
328 Usage : Called from Windows
330 ============================================================*/
333 DefWindowProc( WM_SETFONT, wParam, lParam );
334 // We resize the line-number
335 // field
336 Prepare();
337 return 0;
341 void CLineNumberEdit::OnSize( UINT nType, int cx, int cy )
342 /* ============================================================
343 Function : CLineNumberEdit::OnSize
344 Description : Handles WM_SIZE. Recalculates the line
345 number control size as well.
347 Return : void
348 Parameters : UINT nType - From Windows
349 int cx - From Windows
350 int cy - From Windows
352 Usage : Called from Windows
354 ============================================================*/
357 CEdit::OnSize( nType, cx, cy );
359 // If we have the line-number
360 // control, it must be resized
361 // as well.
362 if( m_line.m_hWnd )
363 Prepare();
367 void CLineNumberEdit::OnEnable( BOOL bEnable )
368 /* ============================================================
369 Function : CLineNumberEdit::OnEnable
370 Description : Handles WM_ENABLE. Calls to set colours.
372 Return : void
373 Parameters : BOOL bEnable - From Windows
375 Usage : Called from Windows.
377 ============================================================*/
380 CEdit::OnEnable( bEnable );
381 SetWindowColour( bEnable );
385 LRESULT CLineNumberEdit::OnSelectLine(WPARAM wParam, LPARAM /*lParam*/ )
386 /* ============================================================
387 Function : CLineNumberEdit::OnSelectLine
388 Description : Handler for the urm_SELECTLINE registered
389 message. Will select the line in wParam.
391 Return : LRESULT - Not used
392 Parameters : WPARAM wParam - The line to select
393 LPARAM lParam - Not used
395 Usage : Called from MFC. Use
396 SendMessage( urm_SELECTLINE, line ) from
397 code.
399 ============================================================*/
402 // Calc start and end position of the line
403 int lineno = wParam + GetScrollPos( SB_VERT );
404 int start = LineIndex( lineno );
405 int end = LineIndex( lineno + 1 );
406 SetSel( start, end - 1 );
407 return 0;
411 void CLineNumberEdit::SetWindowColour( BOOL bEnable /*= TRUE*/ )
412 /* ============================================================
413 Function : CLineNumberEdit::SetWindowColour
414 Description : Handles changing window colours.
416 Return : void
417 Parameters : BOOL bEnable - flag if set enabled/disabled
418 colours
420 Usage : Called to change colours in the edit box.
422 ============================================================*/
425 if (m_bUseEnabledSystemColours)
427 // re-query the system colours in case they have changed.
428 m_EnabledFgCol = GetSysColor( COLOR_WINDOWTEXT );
429 m_EnabledBgCol = GetSysColor( COLOR_WINDOW );
432 if (m_bUseDisabledSystemColours)
434 // re-query the system colours in case they have changed.
435 m_DisabledFgCol = GetSysColor( COLOR_GRAYTEXT );
436 m_DisabledBgCol = GetSysColor( COLOR_3DFACE );
439 // change the colour based on bEnable
440 if (bEnable)
442 m_line.SetFgColor( m_EnabledFgCol, TRUE );
443 m_line.SetBgColor( m_EnabledBgCol, TRUE );
444 } else {
445 m_line.SetFgColor( m_DisabledFgCol, TRUE );
446 m_line.SetBgColor( m_DisabledBgCol, TRUE );
451 void CLineNumberEdit::UseSystemColours( BOOL bUseEnabled /*= TRUE*/, BOOL bUseDisabled /*= TRUE*/ )
452 /* ============================================================
453 Function : CLineNumberEdit::UseSystemColours
454 Description : Sets the Use*SystemColours flags.
456 Return : void
457 Parameters : BOOL bEnabled - flag if to use enabled
458 system colours
459 BOOL bDisabled - flag if to use disabled
460 system colours
462 Usage : Called to change colours in the edit box
464 ============================================================*/
467 m_bUseEnabledSystemColours = bUseEnabled;
468 m_bUseDisabledSystemColours = bUseDisabled;
469 BOOL bEnable = TRUE;
470 if (::IsWindow(m_hWnd))
471 bEnable = IsWindowEnabled();
473 SetWindowColour( bEnable );
477 /////////////////////////////////////////////////////////////////////////////
478 // CLineNumberEdit private implementation
480 void CLineNumberEdit::Prepare()
481 /* ============================================================
482 Function : CLineNumberEdit::Prepare
483 Description : Setting the edit rect for the control and
484 either create or move the line number
485 control. Also sets the top- and bottom
486 line numbers.
488 Return : void
489 Parameters : none
491 Usage : Must be called to (re)establish the edit
492 rect, must also be called as soon as the
493 control changes size.
495 ============================================================*/
498 // Calc sizes
499 int width = CalcLineNumberWidth();
500 CRect rect;
501 GetClientRect( &rect );
502 CRect rectEdit( rect );
503 rect.right = width;
504 rectEdit.left = rect.right + 3;
506 // Setting the edit rect and
507 // creating or moving child control
508 SetRect( &rectEdit );
509 if( m_line.m_hWnd )
510 m_line.MoveWindow( 0, 0, width, rect.Height() );
511 else
512 m_line.Create(NULL,WS_CHILD | WS_VISIBLE | SS_NOTIFY, rect, this, 1 );
514 GetRect( &rectEdit );
516 // Update line number control data
517 m_line.SetTopMargin( rectEdit.top );
518 UpdateTopAndBottom();
522 int CLineNumberEdit::CalcLineNumberWidth()
523 /* ============================================================
524 Function : CLineNumberEdit::CalcLineNumberWidth
525 Description : Calculates the desired width of the line
526 number control, using the current format
527 string and the max number of chars allowed
528 (pessimistic - assumes one character per
529 line).
531 Return : int - The width in pixels
532 Parameters : none
534 Usage : Called as soon as the format string is
535 changed.
537 ============================================================*/
540 CClientDC dc( this );
542 // If a new font is set during runtime,
543 // we must explicitly select the font into
544 // the CClientDC to measure it.
545 CFont* font = GetFont();
546 CFont* oldFont = dc.SelectObject( font );
548 m_zero=dc.GetTextExtent( _T( "0" ) );
549 CString format;
551 // GetLimitText returns the number of bytes the edit box may contain,
552 // not the max number of lines...
553 //... which is the max number of lines, given one character per d:o :-)
554 int maxval = GetLimitText();
555 if (m_maxval > 0)
556 maxval = m_maxval + m_LineDelta;
558 format.Format( m_format, maxval );
559 CSize fmt = dc.GetTextExtent( format );
560 dc.SelectObject( oldFont );
562 // Calculate the size of the line-
563 // number field. We add a 5 pixel margin
564 // to the max size of the format string
565 return fmt.cx + 5;
569 void CLineNumberEdit::UpdateTopAndBottom()
570 /* ============================================================
571 Function : CLineNumberEdit::UpdateTopAndBottom
572 Description : Updates the top- and bottom line number
573 for the line number control.
575 Return : void
576 Parameters : none
577 Usage : Should be called as soon as the contents of
578 the control is changed.
580 ============================================================*/
583 CRect rect;
584 GetClientRect( &rect );
585 int maxline = GetLineCount() + m_LineDelta;
587 // Height for individual lines
588 int lineheight = m_zero.cy;
590 // Calculate the number of lines to draw
591 int topline = GetFirstVisibleLine() + m_LineDelta;
592 if( ( topline + ( rect.Height() / lineheight ) ) < maxline )
593 maxline = topline + ( rect.Height() / lineheight );
595 if ( m_maxval > 0 && maxline > m_maxval + m_LineDelta )
596 maxline = m_maxval + m_LineDelta;
598 m_line.SetTopAndBottom( topline, maxline );
602 /////////////////////////////////////////////////////////////////////////////
603 // CLineNumberEdit public implementation
605 void CLineNumberEdit::SetMarginForegroundColor( COLORREF col, BOOL redraw, BOOL bEnabled /*= TRUE*/ )
606 /* ============================================================
607 Function : CLineNumberEdit::SetMarginForegroundColor
608 Description : Sets the text color for the number
609 margin.
611 Return : void
612 Parameters : COLORREF col - The new text color
613 BOOL redraw - TRUE if the control
614 should be redrawn
615 (default)
617 Usage : Call to set a new text color for the line
618 number margin. The control will be redrawn
619 if it exists.
621 ============================================================*/
624 m_line.SetFgColor( col, redraw );
625 if (bEnabled)
627 m_bUseEnabledSystemColours = FALSE;
628 m_EnabledFgCol = col;
629 } else {
630 m_bUseDisabledSystemColours = FALSE;
631 m_DisabledFgCol = col;
636 void CLineNumberEdit::SetMarginBackgroundColor( COLORREF col, BOOL redraw, BOOL bEnabled /*= TRUE*/ )
637 /* ============================================================
638 Function : CLineNumberEdit::SetMarginBackgroundColor
639 Description : Sets the background color for the number
640 margin.
642 Return : void
643 Parameters : COLORREF col - The new background color
644 BOOL redraw - TRUE if the control
645 should be redrawn
646 (default)
648 Usage : Call to set a new background color for the
649 line number margin. The control will be
650 redrawn if it exists.
652 ============================================================*/
655 m_line.SetBgColor( col, redraw );
656 if (bEnabled)
658 m_bUseEnabledSystemColours = FALSE;
659 m_EnabledBgCol = col;
660 } else {
661 m_bUseDisabledSystemColours = FALSE;
662 m_DisabledBgCol = col;
667 void CLineNumberEdit::SetLineNumberFormat( CString format )
668 /* ============================================================
669 Function : CLineNumberEdit::SetLineNumberFormat
670 Description : Changes the way line numbers are presented
671 on screen.
673 Return : void
674 Parameters : CString format - The new format string
676 Usage : Call with a format string using the same
677 format as CString::Format. It should contain
678 one and only one numeric type.
680 ============================================================*/
683 m_format = format;
684 m_line.SetLineNumberFormat( format );
685 if( m_hWnd )
686 Prepare();
690 void CLineNumberEdit::SetLineNumberRange( UINT nMin, UINT nMax /*= 0*/ )
691 /* ============================================================
692 Function : CLineNumberEdit::SetLineNumberRange
693 Description : Changes the default min and max line numbers.
695 Return : void
696 Parameters : int nMin - changes the line offset
697 int nMax - changes the max line number
699 Usage : Call to set up the min and max line numbers.
701 ============================================================*/
704 m_LineDelta = ( int ) nMin;
705 m_maxval = ( int ) nMax;
709 /////////////////////////////////////////////////////////////////////////////
710 // CLineNumberStatic
712 CLineNumberStatic::CLineNumberStatic()
713 /* ============================================================
714 Function : CLineNumberStatic::CLineNumberStatic
715 Description : constructor
717 Return : void
718 Parameters : none
720 Usage :
722 ============================================================*/
725 m_bgcol = RGB( 255, 255, 248 );
726 m_fgcol = RGB( 0, 0, 0 );
727 m_format = _T( "%05i" );
728 m_topline = 0;
729 m_bottomline = 0;
732 CLineNumberStatic::~CLineNumberStatic()
733 /* ============================================================
734 Function : CLineNumberStatic::~CLineNumberStatic
735 Description : destructor
737 Return : void
738 Parameters : none
740 Usage :
742 ============================================================*/
746 BEGIN_MESSAGE_MAP(CLineNumberStatic, CStatic)
747 ON_WM_PAINT()
748 ON_WM_ERASEBKGND()
749 ON_WM_LBUTTONDOWN()
750 END_MESSAGE_MAP()
752 /////////////////////////////////////////////////////////////////////////////
753 // CLineNumberStatic message handlers
755 void CLineNumberStatic::OnPaint()
756 /* ============================================================
757 Function : CLineNumberStatic::OnPaint
758 Description : Handler for WM_PAINT.
760 Return : void
761 Parameters : none
763 Usage : Called from Windows.
765 ============================================================*/
768 CPaintDC dcPaint( this );
770 CRect rect;
771 GetClientRect( &rect );
773 // We double buffer the drawing -
774 // preparing the memory CDC
775 CDC dc;
776 dc.CreateCompatibleDC( &dcPaint );
777 int saved = dc.SaveDC();
779 // Create GDI and select objects
780 CBitmap bmp;
781 CPen pen;
782 bmp.CreateCompatibleBitmap( &dcPaint, rect.Width(), rect.Height() );
783 pen.CreatePen( PS_SOLID, 1, m_fgcol );
784 dc.SelectObject( &bmp );
785 dc.SelectObject( &pen );
787 // Painting the background
788 dc.FillSolidRect( &rect, m_bgcol );
789 dc.MoveTo( rect.right - 1, 0 );
790 dc.LineTo( rect.right - 1, rect.bottom );
792 // Setting other attributes
793 dc.SetTextColor( m_fgcol );
794 dc.SetBkColor( m_bgcol );
795 dc.SelectObject( GetParent()->GetFont() );
797 // Output the line numbers
798 if( m_bottomline )
800 int lineheight = dc.GetTextExtent( _T( "0" ) ).cy;
801 for( int t = m_topline ; t < m_bottomline ; t++ )
803 CString output;
804 output.Format( m_format, t );
805 int topposition = m_topmargin + lineheight * ( t - m_topline );
806 dc.TextOut( 2, topposition, output );
810 dcPaint.BitBlt( 0, 0, rect. right, rect.bottom, &dc, 0, 0, SRCCOPY );
811 dc.RestoreDC( saved );
815 BOOL CLineNumberStatic::OnEraseBkgnd( CDC* )
816 /* ============================================================
817 Function : CLineNumberStatic::OnEraseBkgnd
818 Description : Mapped to WM_ERASEBKGND. Handled to avoid
819 flicker, as we redraw the complete control
820 in OnPaint
822 Return : BOOL - Always TRUE
823 Parameters : CDC* - From Windows
825 Usage : Called from Windows.
827 ============================================================*/
830 return TRUE;
834 void CLineNumberStatic::OnLButtonDown( UINT nFlags, CPoint point )
835 /* ============================================================
836 Function : CLineNumberStatic::OnLButtonDown
837 Description : Called when the control is clicked. Will
838 send the urm_SELECTLINE registered message
839 to the parent to select the line clicked on.
841 Return : void
842 Parameters : UINT nFlags - Not used
843 CPoint point - Position of cursor
845 Usage : Called from Windows.
847 ============================================================*/
850 // Find the line clicked on
851 CClientDC dc( this );
852 dc.SelectObject( GetParent()->GetFont() );
853 int lineheight = dc.GetTextExtent( _T( "0" ) ).cy;
854 int lineno = ( int ) ( ( double ) point.y / ( double ) lineheight );
856 // Select this line in the edit control
857 GetParent()->SendMessage( urm_SELECTLINE, lineno );
859 CStatic::OnLButtonDown( nFlags, point );
863 /////////////////////////////////////////////////////////////////////////////
864 // CLineNumberStatic public implementation
866 void CLineNumberStatic::SetBgColor( COLORREF col, BOOL redraw )
867 /* ============================================================
868 Function : CLineNumberStatic::SetBgColor
869 Description : This function sets the panel background
870 color
872 Return : void
873 Parameters : COLORREF col - New background color
874 BOOL redraw - TRUE if the control
875 should be redrawn
876 (default)
878 Usage : Called from the parent.
880 ============================================================*/
883 m_bgcol = col;
884 if( m_hWnd && redraw )
885 RedrawWindow();
889 void CLineNumberStatic::SetFgColor( COLORREF col, BOOL redraw )
890 /* ============================================================
891 Function : CLineNumberStatic::SetFgColor
892 Description : This function sets the panel foreground
893 color
895 Return : void
896 Parameters : COLORREF col - New text color
897 BOOL redraw - TRUE if the control
898 should be redrawn
899 (default)
901 Usage : Called from the parent.
903 ============================================================*/
906 m_fgcol = col;
907 if( m_hWnd && redraw )
908 RedrawWindow();
912 void CLineNumberStatic::SetTopAndBottom( int topline, int bottomline )
913 /* ============================================================
914 Function : CLineNumberStatic::SetTopAndBottom
915 Description : Sets the top- and bottom line and redraw
916 the control (if it exists)
918 Return : void
919 Parameters : int topline - The top line number
920 int bottomline - The bottom line number
922 Usage : Called when the top and bottom line is
923 changed in the parent.
925 ============================================================*/
928 m_topline = topline;
929 m_bottomline = bottomline;
930 if( m_hWnd )
931 RedrawWindow();
935 void CLineNumberStatic::SetTopMargin( int topmargin )
936 /* ============================================================
937 Function : CLineNumberStatic::SetTopMargin
938 Description : Sets the top margin for painting.
940 Return : void
941 Parameters : int topmargin - The top margin to set
943 Usage : Will be called with the value of GetRect
944 from the parent.
946 ============================================================*/
949 m_topmargin = topmargin;
953 void CLineNumberStatic::SetLineNumberFormat( CString format )
954 /* ============================================================
955 Function : CLineNumberStatic::SetLineNumberFormat
956 Description : Sets the format string of the control
958 Return : void
959 Parameters : CString format - Format string to use
961 Usage : Called from the parent when the format
962 string is changed.
964 ============================================================*/
967 m_format = format;
968 if( m_hWnd )
969 RedrawWindow();