Skip to content

Commit b58bc87

Browse files
committed
Aga.Controls code cleanup & fixes
1 parent 564197f commit b58bc87

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+626
-1036
lines changed

Aga.Controls/BitmapHelper.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42
using System.Drawing;
53
using System.Runtime.InteropServices;
64
using System.Drawing.Imaging;
@@ -37,7 +35,7 @@ public static void SetAlphaChanelValue(Bitmap image, byte value)
3735
pPixel->A = value;
3836
pPixel++;
3937
}
40-
pPixel += bitmapData.Stride - (bitmapData.Width * 4);
38+
pPixel += bitmapData.Stride - bitmapData.Width * 4;
4139
}
4240
}
4341
image.UnlockBits(bitmapData);

Aga.Controls/GifDecoder.cs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
using System;
2828
using System.Collections;
2929
using System.Drawing;
30-
using System.Drawing.Imaging;
3130
using System.IO;
3231

3332
namespace Aga.Controls
@@ -88,14 +87,14 @@ public class GifDecoder
8887
private Image lastImage; // previous frame
8988

9089
private byte[] block = new byte[256]; // current data block
91-
private int blockSize = 0; // block size
90+
private int blockSize; // block size
9291

9392
// last graphic control extension info
94-
private int dispose = 0;
93+
private int dispose;
9594
// 0=no action; 1=leave in place; 2=restore to bg; 3=restore to prev
96-
private int lastDispose = 0;
97-
private bool transparency = false; // use transparent color
98-
private int delay = 0; // delay in milliseconds
95+
private int lastDispose;
96+
private bool transparency; // use transparent color
97+
private int delay; // delay in milliseconds
9998
private int transIndex; // transparent color index
10099

101100
private const int MaxStackSize = 4096;
@@ -286,15 +285,15 @@ private void SetPixels()
286285
int k = line * width;
287286
int dx = k + ix; // start of line in dest
288287
int dlim = dx + iw; // end of dest line
289-
if ((k + width) < dlim)
288+
if (k + width < dlim)
290289
{
291290
dlim = k + width; // past dest edge
292291
}
293292
int sx = i * iw; // start of line in source
294293
while (dx < dlim)
295294
{
296295
// map color and insert in destination
297-
int index = ((int) pixels[sx++]) & 0xff;
296+
int index = (int) pixels[sx++] & 0xff;
298297
int c = act[index];
299298
if (c != 0)
300299
{
@@ -312,13 +311,12 @@ private void SetPixels()
312311
*
313312
* @return BufferedImage representation of frame.
314313
*/
315-
public GifFrame GetFrame(int n)
316-
{
317-
if ((n >= 0) && (n < frameCount))
314+
public GifFrame GetFrame(int n)
315+
{
316+
if (n >= 0 && n < frameCount)
318317
return (GifFrame)frames[n];
319-
else
320-
throw new ArgumentOutOfRangeException();
321-
}
318+
throw new ArgumentOutOfRangeException();
319+
}
322320

323321
/**
324322
* Gets image size.
@@ -390,7 +388,7 @@ private void DecodeImageData()
390388
bi,
391389
pi;
392390

393-
if ((pixels == null) || (pixels.Length < npix))
391+
if (pixels == null || pixels.Length < npix)
394392
{
395393
pixels = new byte[npix]; // allocate new pixel array
396394
}
@@ -432,7 +430,7 @@ private void DecodeImageData()
432430
break;
433431
bi = 0;
434432
}
435-
datum += (((int) block[bi]) & 0xff) << bits;
433+
datum += ((int) block[bi] & 0xff) << bits;
436434
bits += 8;
437435
bi++;
438436
count--;
@@ -447,7 +445,7 @@ private void DecodeImageData()
447445

448446
// Interpret the code
449447

450-
if ((code > available) || (code == end_of_information))
448+
if (code > available || code == end_of_information)
451449
break;
452450
if (code == clear)
453451
{
@@ -476,7 +474,7 @@ private void DecodeImageData()
476474
pixelStack[top++] = suffix[code];
477475
code = prefix[code];
478476
}
479-
first = ((int) suffix[code]) & 0xff;
477+
first = (int) suffix[code] & 0xff;
480478

481479
// Add a new string to the string table,
482480

@@ -486,8 +484,8 @@ private void DecodeImageData()
486484
prefix[available] = (short) old_code;
487485
suffix[available] = (byte) first;
488486
available++;
489-
if (((available & code_mask) == 0)
490-
&& (available < MaxStackSize))
487+
if ((available & code_mask) == 0
488+
&& available < MaxStackSize)
491489
{
492490
code_size++;
493491
code_mask += available;
@@ -610,9 +608,9 @@ private int[] ReadColorTable(int ncolors)
610608
int j = 0;
611609
while (i < ncolors)
612610
{
613-
int r = ((int) c[j++]) & 0xff;
614-
int g = ((int) c[j++]) & 0xff;
615-
int b = ((int) c[j++]) & 0xff;
611+
int r = (int) c[j++] & 0xff;
612+
int g = (int) c[j++] & 0xff;
613+
int b = (int) c[j++] & 0xff;
616614
tab[i++] = ( int ) ( 0xff000000 | (r << 16) | (g << 8) | b );
617615
}
618616
}
@@ -820,11 +818,11 @@ private void ReadNetscapeExt()
820818
if (block[0] == 1)
821819
{
822820
// loop count sub-block
823-
int b1 = ((int) block[1]) & 0xff;
824-
int b2 = ((int) block[2]) & 0xff;
821+
int b1 = (int) block[1] & 0xff;
822+
int b2 = (int) block[2] & 0xff;
825823
loopCount = (b2 << 8) | b1;
826824
}
827-
} while ((blockSize > 0) && !Error());
825+
} while (blockSize > 0 && !Error());
828826
}
829827

830828
/**
@@ -858,7 +856,7 @@ private void Skip()
858856
do
859857
{
860858
ReadBlock();
861-
} while ((blockSize > 0) && !Error());
859+
} while (blockSize > 0 && !Error());
862860
}
863861
}
864862
}

Aga.Controls/NumericTextBox.cs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ private bool invalidNumeric(char key)
6969
{
7070
// Backspace key is OK
7171
}
72-
else if ((ModifierKeys & (Keys.Control)) != 0)
72+
else if ((ModifierKeys & Keys.Control) != 0)
7373
{
7474
// Let the edit control handle control and alt key combinations
7575
}
@@ -116,23 +116,25 @@ protected override void WndProc(ref Message m)
116116
{
117117
break;
118118
}
119-
else if (selectionLength != 0)
120-
{
121-
base.Text = base.Text.Remove(SelectionStart, selectionLength);
122-
}
123119

124-
bool containsInvalidChars = false;
120+
if (selectionLength != 0)
121+
{
122+
base.Text = base.Text.Remove(SelectionStart, selectionLength);
123+
}
124+
125+
bool containsInvalidChars = false;
125126
foreach (char c in pasteText)
126-
{
127-
if (containsInvalidChars)
127+
{
128+
if (containsInvalidChars)
128129
{
129130
break;
130131
}
131-
else if (invalidNumeric(c))
132-
{
133-
containsInvalidChars = true;
134-
}
135-
}
132+
133+
if (invalidNumeric(c))
134+
{
135+
containsInvalidChars = true;
136+
}
137+
}
136138

137139
if (!containsInvalidChars)
138140
{
@@ -152,7 +154,7 @@ public int IntValue
152154
get
153155
{
154156
int intValue;
155-
Int32.TryParse(this.Text, numberStyle, CultureInfo.CurrentCulture.NumberFormat, out intValue);
157+
Int32.TryParse(Text, numberStyle, CultureInfo.CurrentCulture.NumberFormat, out intValue);
156158
return intValue;
157159
}
158160
}
@@ -162,7 +164,7 @@ public decimal DecimalValue
162164
get
163165
{
164166
decimal decimalValue;
165-
Decimal.TryParse(this.Text, numberStyle, CultureInfo.CurrentCulture.NumberFormat, out decimalValue);
167+
Decimal.TryParse(Text, numberStyle, CultureInfo.CurrentCulture.NumberFormat, out decimalValue);
166168
return decimalValue;
167169
}
168170
}

Aga.Controls/PerformanceAnalyzer.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ public string Name
1818
get { return _name; }
1919
}
2020

21-
private int _count = 0;
21+
private int _count;
2222
public int Count
2323
{
2424
get { return _count; }
2525
set { _count = value; }
2626
}
2727

28-
private double _totalTime = 0;
28+
private double _totalTime;
2929
public double TotalTime
3030
{
3131
get { return _totalTime; }
@@ -99,12 +99,11 @@ public static string GenerateReport()
9999
}
100100

101101
public static string GenerateReport(string mainPieceOfCode)
102-
{
103-
if (_performances.ContainsKey(mainPieceOfCode))
102+
{
103+
if (_performances.ContainsKey(mainPieceOfCode))
104104
return GenerateReport(_performances[mainPieceOfCode].TotalTime);
105-
else
106-
return GenerateReport(0);
107-
}
105+
return GenerateReport(0);
106+
}
108107

109108
public static string GenerateReport(double totalTime)
110109
{

Aga.Controls/ResourceHelper.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
using System;
21
using System.IO;
3-
using System.Reflection;
42
using System.Windows.Forms;
5-
using System.Collections.Generic;
6-
using System.Text;
73

84
namespace Aga.Controls
95
{

Aga.Controls/StringCollectionEditor.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42
using System.ComponentModel.Design;
53

64
namespace Aga.Controls

Aga.Controls/TextHelper.cs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
41
using System.Windows.Forms;
52
using System.Drawing;
63

@@ -9,37 +6,34 @@ namespace Aga.Controls
96
public static class TextHelper
107
{
118
public static StringAlignment TranslateAligment(HorizontalAlignment alignment)
12-
{
13-
if (alignment == HorizontalAlignment.Left)
9+
{
10+
if (alignment == HorizontalAlignment.Left)
1411
return StringAlignment.Near;
15-
else if (alignment == HorizontalAlignment.Right)
16-
return StringAlignment.Far;
17-
else
18-
return StringAlignment.Center;
19-
}
12+
if (alignment == HorizontalAlignment.Right)
13+
return StringAlignment.Far;
14+
return StringAlignment.Center;
15+
}
2016

2117
public static TextFormatFlags TranslateAligmentToFlag(HorizontalAlignment alignment)
2218
{
2319
if (alignment == HorizontalAlignment.Left)
2420
return TextFormatFlags.Left;
25-
else if (alignment == HorizontalAlignment.Right)
21+
if (alignment == HorizontalAlignment.Right)
2622
return TextFormatFlags.Right;
27-
else
28-
return TextFormatFlags.HorizontalCenter;
23+
return TextFormatFlags.HorizontalCenter;
2924
}
3025

3126
public static TextFormatFlags TranslateTrimmingToFlag(StringTrimming trimming)
3227
{
3328
if (trimming == StringTrimming.EllipsisCharacter)
3429
return TextFormatFlags.EndEllipsis;
35-
else if (trimming == StringTrimming.EllipsisPath)
36-
return TextFormatFlags.PathEllipsis;
37-
if (trimming == StringTrimming.EllipsisWord)
30+
if (trimming == StringTrimming.EllipsisPath)
31+
return TextFormatFlags.PathEllipsis;
32+
if (trimming == StringTrimming.EllipsisWord)
3833
return TextFormatFlags.WordEllipsis;
3934
if (trimming == StringTrimming.Word)
4035
return TextFormatFlags.WordBreak;
41-
else
42-
return TextFormatFlags.Default;
43-
}
36+
return TextFormatFlags.Default;
37+
}
4438
}
4539
}

Aga.Controls/Threading/AbortableThreadPool.cs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
using System;
55
using System.Collections.Generic;
6-
using System.Text;
76
using System.Threading;
87

98
namespace Aga.Controls.Threading
@@ -27,7 +26,7 @@ public WorkItem QueueUserWorkItem(WaitCallback callback, object state)
2726
{
2827
_callbacks.AddLast(item);
2928
}
30-
ThreadPool.QueueUserWorkItem(new WaitCallback(HandleItem));
29+
ThreadPool.QueueUserWorkItem(HandleItem);
3130
return item;
3231
}
3332

@@ -86,20 +85,20 @@ public WorkItemStatus Cancel(WorkItem item, bool allowAbort)
8685
_callbacks.Remove(node);
8786
return WorkItemStatus.Queued;
8887
}
89-
else if (_threads.ContainsKey(item))
90-
{
91-
if (allowAbort)
92-
{
93-
_threads[item].Abort();
94-
_threads.Remove(item);
95-
return WorkItemStatus.Aborted;
96-
}
97-
else
98-
return WorkItemStatus.Executing;
99-
}
100-
else
101-
return WorkItemStatus.Completed;
102-
}
88+
89+
if (_threads.ContainsKey(item))
90+
{
91+
if (allowAbort)
92+
{
93+
_threads[item].Abort();
94+
_threads.Remove(item);
95+
return WorkItemStatus.Aborted;
96+
}
97+
98+
return WorkItemStatus.Executing;
99+
}
100+
return WorkItemStatus.Completed;
101+
}
103102
}
104103

105104
public void CancelAll(bool allowAbort)

Aga.Controls/Threading/WorkItem.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
41
using System.Threading;
52

63
namespace Aga.Controls.Threading

0 commit comments

Comments
 (0)