View | Details | Raw Unified | Return to bug 322421
Collapse All | Expand All

(-)System.Windows.Forms/TrackBar.cs (-15 / +37 lines)
Lines 64-69 Link Here
64
		internal int thumb_mouseclick;		
64
		internal int thumb_mouseclick;		
65
		private bool mouse_clickmove;
65
		private bool mouse_clickmove;
66
		private bool is_moving_right; // which way the thumb should move when mouse is down (right=up, left=down) 
66
		private bool is_moving_right; // which way the thumb should move when mouse is down (right=up, left=down) 
67
		internal int mouse_down_x_offset; // how far from left side of thumb was the mouse clicked.
68
		internal bool mouse_moved; // has the mouse moved since it was clicked?
69
		private const int size_of_autosize = 45;
67
	
70
	
68
		#region events
71
		#region events
69
		[Browsable (false)]
72
		[Browsable (false)]
Lines 143-148 Link Here
143
			MouseUp += new MouseEventHandler (OnMouseUpTB); 
146
			MouseUp += new MouseEventHandler (OnMouseUpTB); 
144
			MouseMove += new MouseEventHandler (OnMouseMoveTB);
147
			MouseMove += new MouseEventHandler (OnMouseMoveTB);
145
			KeyDown += new KeyEventHandler (OnKeyDownTB);
148
			KeyDown += new KeyEventHandler (OnKeyDownTB);
149
			LostFocus += new EventHandler (OnLostFocusTB);
150
			GotFocus += new EventHandler (OnGotFocusTB);
146
			holdclick_timer.Elapsed += new ElapsedEventHandler (OnFirstClickTimer);
151
			holdclick_timer.Elapsed += new ElapsedEventHandler (OnFirstClickTimer);
147
152
148
			SetStyle (ControlStyles.UserPaint | ControlStyles.Opaque, false);
153
			SetStyle (ControlStyles.UserPaint | ControlStyles.Opaque, false);
Lines 227-233 Link Here
227
			set {
232
			set {
228
				if (value < 0)
233
				if (value < 0)
229
					throw new ArgumentException( string.Format("Value '{0}' must be greater than or equal to 0.", value));
234
					throw new ArgumentException( string.Format("Value '{0}' must be greater than or equal to 0.", value));
230
235
				
231
				largeChange = value;				
236
				largeChange = value;				
232
			}
237
			}
233
		}
238
		}
Lines 278-286 Link Here
278
					orientation = value;
283
					orientation = value;
279
					
284
					
280
					if (this.IsHandleCreated) {
285
					if (this.IsHandleCreated) {
281
						int old_witdh = Width;
286
						Size = new Size (Height, Width);
282
						Width = Height;
283
						Height = old_witdh;
284
						Refresh (); 
287
						Refresh (); 
285
					}
288
					}
286
				}
289
				}
Lines 367-372 Link Here
367
			base.CreateHandle ();
370
			base.CreateHandle ();
368
		}
371
		}
369
372
373
		protected override void SetBoundsCore (int x, int y,int width, int height, BoundsSpecified specified)
374
		{
375
			if (AutoSize) {
376
				if (orientation == Orientation.Vertical) {
377
					width = size_of_autosize;
378
				} else {
379
					height = size_of_autosize;
380
				}
381
			}
382
			base.SetBoundsCore (x, y, width, height, specified);
383
		}
370
384
371
		public void EndInit ()		
385
		public void EndInit ()		
372
		{
386
		{
Lines 515-520 Link Here
515
    		{
529
    		{
516
    			if (!Enabled) return;			    			
530
    			if (!Enabled) return;			    			
517
531
532
			mouse_moved = false;
533
518
			bool fire_timer = false;
534
			bool fire_timer = false;
519
    			
535
    			
520
    			Point point = new Point (e.X, e.Y);
536
    			Point point = new Point (e.X, e.Y);
Lines 525-530 Link Here
525
					this.Capture = true;
541
					this.Capture = true;
526
					thumb_pressed = true;
542
					thumb_pressed = true;
527
					thumb_mouseclick = e.X;
543
					thumb_mouseclick = e.X;
544
					mouse_down_x_offset = e.X - thumb_pos.X;
528
					Invalidate (thumb_area);
545
					Invalidate (thumb_area);
529
				}
546
				}
530
				else {
547
				else {
Lines 542-551 Link Here
542
				}
559
				}
543
			}
560
			}
544
			else {
561
			else {
545
				if (thumb_pos.Contains (point)) {
562
				Rectangle vertical_thumb_pos = thumb_pos;
563
				vertical_thumb_pos.Width = thumb_pos.Height;
564
				vertical_thumb_pos.Height = thumb_pos.Width;
565
				if (vertical_thumb_pos.Contains (point)) {
546
					this.Capture = true;
566
					this.Capture = true;
547
					thumb_pressed = true;
567
					thumb_pressed = true;
548
					thumb_mouseclick = e.Y;
568
					thumb_mouseclick = e.Y;
569
					mouse_down_x_offset = e.Y - thumb_pos.Y;
549
					Invalidate (thumb_area);
570
					Invalidate (thumb_area);
550
				}
571
				}
551
				else {
572
				else {
Lines 573-578 Link Here
573
    		{    			
594
    		{    			
574
    			if (!Enabled) return;
595
    			if (!Enabled) return;
575
    		
596
    		
597
    			mouse_moved = true;
598
576
    			/* Moving the thumb */
599
    			/* Moving the thumb */
577
    			if (thumb_pressed) {
600
    			if (thumb_pressed) {
578
								 				
601
								 				
Lines 595-600 Link Here
595
			ThemeEngine.Current.DrawTrackBar (pevent.Graphics, pevent.ClipRectangle, this);
618
			ThemeEngine.Current.DrawTrackBar (pevent.Graphics, pevent.ClipRectangle, this);
596
		}
619
		}
597
620
621
		private void OnLostFocusTB (object sender, EventArgs e)
622
		{
623
			Invalidate();
624
		}
625
626
		private void OnGotFocusTB (object sender, EventArgs e)
627
		{
628
			Invalidate();
629
		}
598
		private void OnKeyDownTB (object sender, KeyEventArgs e) 
630
		private void OnKeyDownTB (object sender, KeyEventArgs e) 
599
		{
631
		{
600
			switch (e.KeyCode) {
632
			switch (e.KeyCode) {
Lines 666-681 Link Here
666
 					Refresh();
698
 					Refresh();
667
			}			
699
			}			
668
		}					
700
		}					
669
670
		protected override void SetBoundsCore (int x, int y,int width, int height, BoundsSpecified specified)
671
		{
672
			if (orientation == Orientation.Vertical) {
673
				width = DefaultSize.Height;
674
			} else {
675
				height = DefaultSize.Height;
676
			}
677
			base.SetBoundsCore (x, y,width, height, specified);
678
		}
679
    		#endregion // Private Methods
701
    		#endregion // Private Methods
680
	}
702
	}
681
}
703
}
(-)System.Windows.Forms/ThemeWin32Classic.cs (-23 / +33 lines)
Lines 4222-4236 Link Here
4222
			
4222
			
4223
			/* Convert thumb position from mouse position to value*/
4223
			/* Convert thumb position from mouse position to value*/
4224
			if (mouse_value) {
4224
			if (mouse_value) {
4225
				if (value_pos < thumb_area.Bottom)
4225
				if (tb.mouse_moved) {
4226
					value_pos = (int) ((thumb_area.Bottom - value_pos) / pixels_betweenticks);
4226
					value_pos += (int) pixels_betweenticks / 2;
4227
				else
4227
					if (value_pos < thumb_area.Bottom) {
4228
					value_pos = 0;			
4228
						value_pos = (int) ((thumb_area.Bottom - value_pos - (int)(thumb_pos.Width / 2)) / pixels_betweenticks);
4229
					} else {
4230
						value_pos = 0;			
4231
					}
4232
	
4233
					if (value_pos + tb.Minimum > tb.Maximum)
4234
						value_pos = tb.Maximum - tb.Minimum;
4235
					else if (value_pos + tb.Minimum < tb.Minimum)
4236
						value_pos = 0;
4229
4237
4230
				if (value_pos + tb.Minimum > tb.Maximum)
4238
					tb.Value = value_pos + tb.Minimum;	
4231
					value_pos = tb.Maximum - tb.Minimum;
4239
				} else {
4232
4240
					value_pos = tb.Value - tb.Minimum;
4233
				tb.Value = value_pos + tb.Minimum;
4241
				}
4234
			}			
4242
			}			
4235
4243
4236
			// thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
4244
			// thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
Lines 4366-4372 Link Here
4366
			Does not matter the size of the control, Win32 always draws:
4374
			Does not matter the size of the control, Win32 always draws:
4367
				- Ticks starting from pixel 13, 8
4375
				- Ticks starting from pixel 13, 8
4368
				- Channel starting at pos 8, 19 and ends at Width - 8
4376
				- Channel starting at pos 8, 19 and ends at Width - 8
4369
				- Autosize makes always the control 40 pixels height
4377
				- Autosize makes always the control 45 pixels high
4370
				- Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
4378
				- Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
4371
				
4379
				
4372
		*/
4380
		*/
Lines 4428-4442 Link Here
4428
4436
4429
			/* Convert thumb position from mouse position to value*/
4437
			/* Convert thumb position from mouse position to value*/
4430
			if (mouse_value) {			
4438
			if (mouse_value) {			
4431
				if (value_pos >= channel_startpoint.X)
4439
				if (tb.mouse_moved) {
4432
					value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
4440
					value_pos += (int) pixels_betweenticks / 2;
4433
				else
4441
					if (value_pos >= channel_startpoint.X) {
4434
					value_pos = 0;				
4442
						value_pos = (int)(((float) (value_pos - channel_startpoint.X - (int)(thumb_pos.Width / 2))) / pixels_betweenticks);
4443
					} else
4444
						value_pos = 0;				
4445
	
4446
					if (value_pos + tb.Minimum > tb.Maximum)
4447
						value_pos = tb.Maximum - tb.Minimum;
4448
					else if(value_pos + tb.Minimum < tb.Minimum)
4449
						value_pos = 0;
4435
4450
4436
				if (value_pos + tb.Minimum > tb.Maximum)
4451
					tb.Value = value_pos + tb.Minimum;
4437
					value_pos = tb.Maximum - tb.Minimum;
4452
				} else {
4438
                                
4453
					value_pos = tb.Value - tb.Minimum;
4439
				tb.Value = value_pos + tb.Minimum;
4454
				}
4440
			}			
4455
			}			
4441
			
4456
			
4442
			thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
4457
			thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
Lines 4594-4606 Link Here
4594
				dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
4609
				dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
4595
			}
4610
			}
4596
			
4611
			
4597
4598
			if (tb.Focused) {
4612
			if (tb.Focused) {
4599
				Brush brush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black);
4613
				CPDrawFocusRectangle(dc, area, tb.ForeColor, tb.BackColor);
4600
				dc.FillRectangle (brush, area.X, area.Y, area.Width - 1, 1);
4601
				dc.FillRectangle (brush, area.X, area.Y + area.Height - 1, area.Width - 1, 1);
4602
				dc.FillRectangle (brush, area.X, area.Y, 1, area.Height - 1);
4603
				dc.FillRectangle (brush, area.X + area.Width - 1, area.Y, 1, area.Height - 1);
4604
			}
4614
			}
4605
4615
4606
			if (tb.Orientation == Orientation.Vertical) {
4616
			if (tb.Orientation == Orientation.Vertical) {
(-)System.Windows.Forms/ChangeLog (+15 lines)
Lines 1-3 Link Here
1
2006-11-07  Rolf Bjarne Kvinge  <RKvinge@novell.com>
2
3
	* TrackBar.cs: 
4
	- The control is completely invalidated on 
5
+	Got/LostFocus to draw the focus rectangle correctly.
6
	- When AutoSize then height is always 45 (width for 
7
	vertical controls).
8
	
9
	* ThemeWin32Classic.cs: The TrackBar thumb is now centered
10
	on the mouse when moved and it doesn't move when grabbed
11
	until the mouse moves as well. Also fixed some wrong 
12
	calculations when clicking on the thumb (control thought
13
	click was outside of thumb and didn't grab it).
14
	Fixes some of the issues in #79718.
15
	
1
2006-11-06  Chris Toshok  <toshok@ximian.com>
16
2006-11-06  Chris Toshok  <toshok@ximian.com>
2
17
3
	* TabControl.cs: in OnGotFocusInternal/OnLostFocusInternal don't
18
	* TabControl.cs: in OnGotFocusInternal/OnLostFocusInternal don't
(-)Test/System.Windows.Forms/TrackBarTest.cs (-4 / +136 lines)
Lines 94-99 Link Here
94
		[Test]
94
		[Test]
95
		public void OrientationSizeTest ()
95
		public void OrientationSizeTest ()
96
		{	
96
		{	
97
			IntPtr handle;
97
			int width;
98
			int width;
98
			int height ;
99
			int height ;
99
			using (TrackBar myTrackBar = new TrackBar()) {
100
			using (TrackBar myTrackBar = new TrackBar()) {
Lines 109-117 Link Here
109
					width = myTrackBar.Width;
110
					width = myTrackBar.Width;
110
					height = myTrackBar.Height;
111
					height = myTrackBar.Height;
111
					myForm.Controls.Add(myTrackBar);
112
					myForm.Controls.Add(myTrackBar);
112
					IntPtr handle = myTrackBar.Handle; // causes the handle to be created.
113
					handle = myTrackBar.Handle; // causes the handle to be created.
113
					myTrackBar.Orientation = Orientation.Vertical;
114
					myTrackBar.Orientation = Orientation.Vertical;
114
					Assert.AreEqual(height, myTrackBar.Width,  "#OS3");
115
					Assert.AreEqual(45, myTrackBar.Width,  "#OS3");
115
					Assert.AreEqual(width, myTrackBar.Height, "#OS4");
116
					Assert.AreEqual(width, myTrackBar.Height, "#OS4");
116
				}
117
				}
117
			}
118
			}
Lines 119-131 Link Here
119
			using (Form myForm = new Form()) {
120
			using (Form myForm = new Form()) {
120
				using ( TrackBar myTrackBar = new TrackBar()) {
121
				using ( TrackBar myTrackBar = new TrackBar()) {
121
					myForm.Controls.Add(myTrackBar);
122
					myForm.Controls.Add(myTrackBar);
122
					IntPtr handle = myTrackBar.Handle; // causes the handle to be created.
123
					handle = myTrackBar.Handle; // causes the handle to be created.
123
					myTrackBar.Width = 200;
124
					myTrackBar.Width = 200;
124
					myTrackBar.Orientation = Orientation.Vertical;
125
					myTrackBar.Orientation = Orientation.Vertical;
125
					Assert.AreEqual(200, myTrackBar.Height, "#OS5");
126
					Assert.AreEqual(200, myTrackBar.Height, "#OS5");
126
				}
127
				}
127
			}
128
			}
129
			Assert.AreEqual(handle, handle, "Removes warning");
128
		}
130
		}
131
			
132
		[Test]
133
		public void SizeTest ()
134
		{
135
			IntPtr handle;
136
			
137
			using (TrackBar myTrackBar = new TrackBar()) {
138
				myTrackBar.Width = 200;
139
				myTrackBar.Height = 250;
140
				Assert.AreEqual(200, myTrackBar.Width, "#SIZE01");
141
				Assert.AreEqual(45, myTrackBar.Height, "#SIZE02");
142
			}
143
			
144
			using (TrackBar myTrackBar = new TrackBar()) {
145
				myTrackBar.Width = 200;
146
				myTrackBar.Height = 250;
147
				myTrackBar.Orientation = Orientation.Vertical;
148
				Assert.AreEqual(200, myTrackBar.Width, "#SIZE03");
149
				Assert.AreEqual(45, myTrackBar.Height, "#SIZE04");
150
			}
151
152
			using (TrackBar myTrackBar = new TrackBar()) {
153
				myTrackBar.AutoSize = false;
154
				myTrackBar.Width = 200;
155
				myTrackBar.Height = 250;
156
				Assert.AreEqual(200, myTrackBar.Width, "#SIZE05");
157
				Assert.AreEqual(250, myTrackBar.Height, "#SIZE06");
158
			}
159
160
			using (TrackBar myTrackBar = new TrackBar()) {
161
				myTrackBar.AutoSize = false;
162
				myTrackBar.Width = 200;
163
				myTrackBar.Height = 250;
164
				myTrackBar.Orientation = Orientation.Vertical;
165
				Assert.AreEqual(200, myTrackBar.Width, "#SIZE07");
166
				Assert.AreEqual(250, myTrackBar.Height, "#SIZE08");
167
			}
168
169
			using (TrackBar myTrackBar = new TrackBar()) {
170
				myTrackBar.Width = 200;
171
				myTrackBar.Height = 250;
172
				myTrackBar.AutoSize = false;
173
				Assert.AreEqual(200, myTrackBar.Width, "#SIZE09");
174
				Assert.AreEqual(45, myTrackBar.Height, "#SIZE10");
175
			}
176
177
			using (TrackBar myTrackBar = new TrackBar()) {
178
				myTrackBar.Width = 200;
179
				myTrackBar.Height = 250;
180
				myTrackBar.AutoSize = false;
181
				myTrackBar.Orientation = Orientation.Vertical;
182
				Assert.AreEqual(200, myTrackBar.Width, "#SIZE11");
183
				Assert.AreEqual(45, myTrackBar.Height, "#SIZE12");
184
			}
185
	
186
			using (TrackBar myTrackBar = new TrackBar()) {
187
				using (Form myForm = new Form()) {
188
					myForm.Controls.Add(myTrackBar);
189
					myTrackBar.Width = 200;
190
					myTrackBar.Height = 250;
191
					myTrackBar.Orientation = Orientation.Vertical;
192
					handle = myTrackBar.Handle;
193
					
194
					Assert.AreEqual(45, myTrackBar.Width, "#SIZE17");
195
					Assert.AreEqual(45, myTrackBar.Height, "#SIZE18");
196
				}
197
			}
198
199
			using (TrackBar myTrackBar = new TrackBar()) {
200
				using (Form myForm = new Form()) {
201
					myForm.Controls.Add(myTrackBar);
202
					myTrackBar.Width = 200;
203
					myTrackBar.Height = 250;
204
					myTrackBar.Orientation = Orientation.Vertical;
205
					handle = myTrackBar.Handle;
206
					
207
					Assert.AreEqual(45, myTrackBar.Width, "#SIZE19");
208
					Assert.AreEqual(45, myTrackBar.Height, "#SIZE20");
209
				}
210
			}
211
212
			using (TrackBar myTrackBar = new TrackBar()) {
213
				using (Form myForm = new Form()) {
214
					myForm.Controls.Add(myTrackBar);
215
					myTrackBar.Width = 200;
216
					myTrackBar.Height = 250;
217
					myTrackBar.Orientation = Orientation.Vertical;
218
					myTrackBar.Orientation = Orientation.Horizontal;
219
					handle = myTrackBar.Handle;
220
					
221
					Assert.AreEqual(200, myTrackBar.Width, "#SIZE21");
222
					Assert.AreEqual(45, myTrackBar.Height, "#SIZE22");
223
				}
224
			}
225
226
			using (TrackBar myTrackBar = new TrackBar()) {
227
				using (Form myForm = new Form()) {
228
					myForm.Controls.Add(myTrackBar);
229
					myTrackBar.Width = 200;
230
					myTrackBar.Height = 250;
231
					myTrackBar.Orientation = Orientation.Vertical;
232
					handle = myTrackBar.Handle;
233
					
234
					myTrackBar.Orientation = Orientation.Horizontal;
235
					
236
					Assert.AreEqual(45, myTrackBar.Width, "#SIZE23");
237
					Assert.AreEqual(45, myTrackBar.Height, "#SIZE24");
238
				}
239
			}
240
			
241
			using (TrackBar myTrackBar = new TrackBar()) {
242
				myTrackBar.AutoSize = false;
243
				myTrackBar.Height = 50;
244
				myTrackBar.Width = 80;
245
				myTrackBar.Orientation = Orientation.Vertical;
246
				myTrackBar.Width = 100;
247
				
248
				Assert.AreEqual(50, myTrackBar.Height, "#SIZE2_1");
249
				Assert.AreEqual(100, myTrackBar.Width, "#SIZE2_2");
250
				
251
				using (Form myForm = new Form()){
252
					myForm.Controls.Add(myTrackBar);
253
					myForm.Show();
254
					
255
					Assert.AreEqual(50, myTrackBar.Height, "#SIZE2_3");
256
					Assert.AreEqual(100, myTrackBar.Width, "#SIZE2_4");
257
				}
258
			}
259
			Assert.AreEqual(handle, handle, "Removes warning");
260
		}
261
	}
129
}
262
}
130
}
131
263

Return to bug 322421