Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

svn path=/trunk/winforms-tools/; revision=52028

  • Loading branch information...
commit e81387f8832204aacc4d263b838caa86d39c94ed 1 parent a940533
Alexander Olk authored
View
92 MWFResourceEditor/ByteArrayPanel.cs
@@ -5,20 +5,21 @@
using System.Drawing;
using System.Windows.Forms;
using System.Text;
+using System.Collections.Specialized;
namespace MWFResourceEditor
{
- public class ByteArrayPanel : Panel
+ public class ByteArrayPanel : Panel, IPanel
{
private Byte[] byteArray;
private CheckBox textHexCheckBox;
private TextBox textBox;
- private StringBuilder sb_text;
- private StringBuilder sb_hex;
+ private StringCollection sc_text = new StringCollection();
+ private StringCollection sc_hex = new StringCollection();
- public ByteArrayPanel( MainForm parentForm )
+ public ByteArrayPanel( ResourceContentControl parentControl )
{
textHexCheckBox = new CheckBox( );
textBox = new TextBox( );
@@ -38,18 +39,14 @@ public ByteArrayPanel( MainForm parentForm )
textBox.Location = new Point( 3, 30 );
textBox.Multiline = true;
textBox.ReadOnly = true;
- textBox.Anchor = ( (System.Windows.Forms.AnchorStyles)( ( ( ( System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom )
- | System.Windows.Forms.AnchorStyles.Left )
- | System.Windows.Forms.AnchorStyles.Right ) ) );
- textBox.Size = new Size( 586, 180 );
-// textBox.ScrollBars = ScrollBars.Vertical;
+ textBox.ScrollBars = ScrollBars.Vertical;
textBox.Font = new Font( FontFamily.GenericMonospace, 8 );
+ textBox.WordWrap = true;
Controls.Add( textBox );
Controls.Add( textHexCheckBox );
ResumeLayout( false );
-
}
public Byte[] ByteArray
@@ -57,12 +54,12 @@ public Byte[] ByteArray
set {
byteArray = value;
- sb_text = new StringBuilder( byteArray.Length );
- sb_hex = new StringBuilder( byteArray.Length * 4 );
+ sc_text.Clear( );
+ sc_hex.Clear( );
GenerateTextAndHexOutput( );
- textBox.Text = sb_text.ToString( );
+ textBox.Lines = GetLines( textHexCheckBox.Checked ? sc_hex : sc_text );
}
get {
@@ -70,59 +67,90 @@ public Byte[] ByteArray
}
}
+ public void ClearResource( )
+ {
+ byteArray = null;
+ sc_text.Clear( );
+ sc_hex.Clear( );
+ textBox.Clear( );
+ }
+
void OnCheckedChangedTextCheckBox( object sender, EventArgs e )
{
if ( textHexCheckBox.Checked )
- textBox.Text = sb_hex.ToString( );
+ textBox.Lines = GetLines( sc_hex );
else
- textBox.Text = sb_text.ToString( );
+ textBox.Lines = GetLines( sc_text );
textBox.Invalidate( );
}
+ private string[] GetLines( StringCollection sc )
+ {
+ string[] tmp = new string[ sc.Count ];
+
+ sc.CopyTo( tmp, 0 );
+
+ return tmp;
+ }
+
private void GenerateTextAndHexOutput( )
{
- bool new_line = false;
+ StringBuilder sb_text = new StringBuilder( );
+ StringBuilder sb_hex = new StringBuilder( );
int show_how_many_bytes = byteArray.Length > 1024 ? 1024 : byteArray.Length;
StringBuilder back_string = back_string = new StringBuilder( 19 );
+ back_string.Append( " " );
sb_hex.Append( "00000000 " );
+ int counter = 0;
+
for ( int i = 0; i < show_how_many_bytes; i++ )
{
+ counter++;
+
char c = Convert.ToChar( byteArray[ i ] );
- sb_text.Append( c );
+ sb_hex.Append( byteArray[ i ].ToString( "X2" ) + " " );
+
+ if ( Char.IsLetterOrDigit( c ) )
+ back_string.Append( c );
+ else
+ back_string.Append( "." );
- if ( new_line )
+ if ( i > 0 && ( counter % 16 ) == 0 )
{
- new_line = false;
-
- back_string.Append( "\n" );
-
sb_hex.Append( back_string );
- sb_hex.Append( i.ToString( "X8" ) + " " );
-
back_string = new StringBuilder( 19 );
back_string.Append( " " );
+
+ sc_hex.Add( sb_hex.ToString( ) );
+ sb_hex = new StringBuilder( );
+
+ sb_hex.Append( i.ToString( "X8" ) + " " );
}
- sb_hex.Append( byteArray[ i ].ToString( "X2" ) + " " );
-
- if ( Char.IsLetterOrDigit( c ) )
- back_string.Append( c );
+ if ( c != '\n' && c != '\r' )
+ sb_text.Append( c );
else
- back_string.Append( "." );
-
- if ( i > 0 && ( i % 16 ) == 0 )
+ if ( c == '\n' )
{
- new_line = true;
+ sc_text.Add( sb_text.ToString( ) );
+ sb_text = new StringBuilder( );
}
}
}
+
+ protected override void OnSizeChanged( EventArgs e )
+ {
+ textBox.Size = new Size( Width - 10, Height - 40 );
+ base.OnSizeChanged( e );
+ }
}
}
+
View
7 MWFResourceEditor/Changelog
@@ -1,3 +1,10 @@
+2005-10-21 Alexander Olk <alex.olk@googlemail.com>
+
+ * ResourceContentControl.cs, ResourceControl.cs, ResourceList.cs,
+ ResourceSelectionControl.cs: Added
+
+ * Many bug fixes, refactoring and make the application work on MS.NET
+
2005-10-10 Alexander Olk <alex.olk@googlemail.com>
* MainForm.cs: Rename ResourceTreeView Clear to ClearResources
View
14 MWFResourceEditor/ColorPanel.cs
@@ -14,11 +14,11 @@ public class ColorPanel : Panel, IPanel
private Panel panel;
private Label label;
- private MainForm parentForm;
+ private ResourceContentControl parentControl;
- public ColorPanel( MainForm parentForm )
+ public ColorPanel( ResourceContentControl parentControl )
{
- this.parentForm = parentForm;
+ this.parentControl = parentControl;
button = new Button( );
panel = new Panel( );
@@ -65,11 +65,9 @@ public Color Color
}
}
- public object Value
+ public void ClearResource( )
{
- get {
- return color;
- }
+ Color = Color.Empty;
}
void OnClickButton( object sender, EventArgs e )
@@ -81,7 +79,7 @@ void OnClickButton( object sender, EventArgs e )
{
color = cd.Color;
- parentForm.ChangeResourceContent( );
+ parentControl.Change_Resource_Content( color );
Invalidate( );
Update( );
View
3  MWFResourceEditor/IPanel.cs
@@ -5,8 +5,7 @@ namespace MWFResourceEditor
{
public interface IPanel
{
- object Value
- { get; }
+ void ClearResource();
}
}
View
74 MWFResourceEditor/ImagePanel.cs
@@ -12,25 +12,21 @@ public class ImagePanel : Panel, IPanel
{
private Image image;
private Icon icon;
- private Icon old_icon;
- private string imageOrIconName;
+ private Cursor cursor;
private PictureBox pictureBox;
private Button button;
- private object value_internal = null;
+ private Bitmap old_bmp;
- private MainForm parentForm;
+ private ResourceContentControl parentControl;
- public ImagePanel( MainForm parentForm )
+ public ImagePanel( ResourceContentControl parentControl )
{
- this.parentForm = parentForm;
+ this.parentControl = parentControl;
button = new Button( );
pictureBox = new PictureBox( );
SuspendLayout( );
- BackColor = Color.LightSlateGray;
- pictureBox.BackColor = Color.LightSlateGray;
-
button.Location = new Point( 10, 10 );
button.Size = new Size( 120, 21 );
button.Text = "Change Image";
@@ -49,7 +45,6 @@ public Image Image
{
set {
image = value;
- value_internal = image;
pictureBox.Image = value;
pictureBox.Size = image.Size;
@@ -61,43 +56,48 @@ public Image Image
}
}
- public string ImageOrIconName
+ public Icon Icon
{
set {
- imageOrIconName = value;
+ icon = value;
+
+ pictureBox.Image = icon.ToBitmap( );
+ pictureBox.Size = pictureBox.Image.Size;
+ pictureBox.Location = new Point( ( Width / 2 ) - ( icon.Width / 2 ), ( Height / 2 ) - ( icon.Height / 2 ) );
}
get {
- return imageOrIconName;
+ return icon;
}
}
- public Icon Icon
+ public new Cursor Cursor
{
set {
- icon = value;
- value_internal = icon;
+ cursor = value;
- if ( old_icon != null )
- old_icon.Dispose( );
+ if ( old_bmp != null )
+ old_bmp.Dispose( );
- old_icon = icon;
+ Bitmap bmp = new Bitmap( cursor.Size.Width, cursor.Size.Height );
- pictureBox.Image = icon.ToBitmap( );
+ using ( Graphics gr = Graphics.FromImage( bmp ) )
+ cursor.Draw( gr, new Rectangle( 0, 0, bmp.Width, bmp.Height ) );
+
+ old_bmp = bmp;
+
+ pictureBox.Image = bmp;
pictureBox.Size = pictureBox.Image.Size;
- pictureBox.Location = new Point( ( Width / 2 ) - ( icon.Width / 2 ), ( Height / 2 ) - ( icon.Height / 2 ) );
- }
-
- get {
- return icon;
+ pictureBox.Location = new Point( ( Width / 2 ) - ( cursor.Size.Width / 2 ), ( Height / 2 ) - ( cursor.Size.Height / 2 ) );
}
}
- public object Value
+ public void ClearResource( )
{
- get {
- return value_internal;
- }
+ image = null;
+ icon = null;
+ cursor = null;
+ pictureBox.Image = null;
}
protected override void OnSizeChanged( EventArgs e )
@@ -113,7 +113,7 @@ void OnClickButton( object sender, EventArgs e )
OpenFileDialog ofd = new OpenFileDialog( );
ofd.CheckFileExists = true;
- ofd.Filter = "Images (*.png;*.jpg;*.gif;*.bmp)|*.png;*.jpg;*.gif;*.bmp|Icons (*.ico)|*.ico|All files (*.*)|*.*";
+ ofd.Filter = "Images (*.png;*.jpg;*.gif;*.bmp)|*.png;*.jpg;*.gif;*.bmp|Icons (*.ico)|*.ico|Cursors (*.cur)|*.cur|All files (*.*)|*.*";
if ( DialogResult.OK == ofd.ShowDialog( ) )
{
@@ -126,22 +126,26 @@ void OnClickButton( object sender, EventArgs e )
{
Icon = new Icon( ofd.FileName );
- imageOrIconName = Path.GetFileName( ofd.FileName );
+ parentControl.Change_Resource_Content( icon );
+ }
+ else
+ if ( upper_file_name.EndsWith( ".CUR" ) )
+ {
+ Cursor = new Cursor( ofd.FileName );
- parentForm.ChangeResourceContent( );
+ parentControl.Change_Resource_Content( cursor );
}
else
{
Image = Image.FromFile( ofd.FileName );
- imageOrIconName = Path.GetFileName( ofd.FileName );
-
- parentForm.ChangeResourceContent( );
+ parentControl.Change_Resource_Content( image );
}
}
catch (Exception ex)
{
Console.WriteLine( "File {0} not found.", ofd.FileName );
+ Console.WriteLine( ex );
}
}
}
View
731 MWFResourceEditor/MainForm.cs
@@ -32,32 +32,9 @@ public class MainForm : Form
private MenuItem menuItemHelp;
private MenuItem menuItemAbout;
private MenuItem menuItemDash2;
- private Panel resourcePanel;
- private Control contentControl;
- private ImagePanel imagePanel;
- private TextPanel textPanel;
- private ColorPanel colorPanel;
- private ByteArrayPanel byteArrayPanel;
- private ResourceListBox resourceListBox;
- private ContextMenu contextMenu;
- private Splitter mainSplitter;
- private Splitter resourceSplitter;
- private ResourceTreeView resourceTreeView;
+ private StatusBar statusBar;
- private ResXResourceReader resXResourceReader;
-
- private Panel activePanel;
-
- private IResource resourceCopy = null;
-
- private string fullFileName = "New Resource.resx";
-
- private string last_load_resx_directory = String.Empty;
- private string last_add_files_directory = String.Empty;
- private string last_save_as_directory = String.Empty;
-
- private bool fileSaved = true;
- private bool first_time_saved = false;
+ private ResourceControl resourceControl;
public MainForm( )
{
@@ -66,9 +43,6 @@ public MainForm( )
private void InitializeComponent( )
{
- mainSplitter = new Splitter( );
- resourceSplitter = new Splitter( );
-
menuItemFile = new MenuItem( );
menuItemNew = new MenuItem( );
menuItemLoad = new MenuItem( );
@@ -93,21 +67,10 @@ private void InitializeComponent( )
mainMenu = new MainMenu( );
- contextMenu = new ContextMenu( );
-
- imagePanel = new ImagePanel( this );
- textPanel = new TextPanel( this );
- colorPanel = new ColorPanel( this );
- byteArrayPanel = new ByteArrayPanel( this );
- resourcePanel = new Panel( );
+ resourceControl = new ResourceControl( );
- resourceListBox = new ResourceListBox( );
- resourceTreeView = new ResourceTreeView( resourceListBox );
- resourceListBox.ResourceTreeView = resourceTreeView;
+ statusBar = new StatusBar( );
- contentControl = new Control( );
- contentControl.SuspendLayout( );
- resourcePanel.SuspendLayout( );
SuspendLayout( );
// menuItemFile
@@ -122,36 +85,36 @@ private void InitializeComponent( )
menuItemFile.Text = "&File";
// menuItemNew
- menuItemNew.Index = 1;
+ menuItemNew.Index = 0;
menuItemNew.Text = "&New";
menuItemNew.Click += new EventHandler( OnMenuItemNewClick );
// menuItemLoad
- menuItemLoad.Index = 2;
+ menuItemLoad.Index = 1;
menuItemLoad.Text = "L&oad";
menuItemLoad.Click += new EventHandler( OnMenuItemLoadClick );
// menuItemSave
- menuItemSave.Index = 3;
+ menuItemSave.Index = 2;
menuItemSave.Text = "&Save";
menuItemSave.Click += new EventHandler( OnMenuItemSaveClick );
// menuItemSaveAs
- menuItemSaveAs.Index = 4;
+ menuItemSaveAs.Index = 3;
menuItemSaveAs.Text = "S&ave as";
menuItemSaveAs.Click += new EventHandler( OnMenuItemSaveAsClick );
// menuItemDash
- menuItemDash1.Index = 5;
+ menuItemDash1.Index = 4;
menuItemDash1.Text = "-";
// menuItemExit
- menuItemExit.Index = 6;
+ menuItemExit.Index = 5;
menuItemExit.Text = "E&xit";
menuItemExit.Click += new EventHandler( OnMenuItemExitClick );
// menuItemResources
- menuItemResources.Index = 7;
+ menuItemResources.Index = 1;
menuItemResources.MenuItems.AddRange( new MenuItem[] {
menuItemAddString,
menuItemAddFiles,
@@ -160,58 +123,59 @@ private void InitializeComponent( )
menuItemDelete,
menuItemCopy,
menuItemPaste,
+ menuItemDash3,
menuItemRename } );
menuItemResources.Text = "Resources";
// menuItemAddString
- menuItemAddString.Index = 8;
+ menuItemAddString.Index = 0;
menuItemAddString.Text = "Add S&tring";
menuItemAddString.Click += new EventHandler( OnMenuItemAddStringClick );
// menuItemAddFiles
- menuItemAddFiles.Index = 9;
+ menuItemAddFiles.Index = 1;
menuItemAddFiles.Text = "Add Fi&le(s)";
menuItemAddFiles.Click += new EventHandler( OnMenuItemAddFilesClick );
// menuItemAddColor
- menuItemAddColor.Index = 10;
+ menuItemAddColor.Index = 2;
menuItemAddColor.Text = "Add Colo&r";
menuItemAddColor.Click += new EventHandler( OnMenuItemAddColorClick );
// menuItemDash2
- menuItemDash2.Index = 12;
+ menuItemDash2.Index = 3;
menuItemDash2.Text = "-";
// menuItemDelete
- menuItemDelete.Index = 13;
+ menuItemDelete.Index = 4;
menuItemDelete.Text = "&Delete";
menuItemDelete.Click += new EventHandler( OnMenuItemDeleteClick );
// menuItemCopy
- menuItemCopy.Index = 14;
+ menuItemCopy.Index = 5;
menuItemCopy.Text = "&Copy";
menuItemCopy.Click += new EventHandler( OnMenuItemCopyClick );
// menuItemPaste
- menuItemPaste.Index = 15;
+ menuItemPaste.Index = 6;
menuItemPaste.Text = "Paste";
menuItemPaste.Click += new EventHandler( OnMenuItemPasteClick );
- menuItemDash3.Index = 16;
+ menuItemDash3.Index = 7;
menuItemDash3.Text = "-";
- menuItemRename.Index = 17;
+ menuItemRename.Index = 8;
menuItemRename.Text = "Rename";
menuItemRename.Click += new EventHandler( OnMenuItemRenameClick );
// menuItemHelp
- menuItemHelp.Index = 18;
+ menuItemHelp.Index = 2;
menuItemHelp.MenuItems.AddRange( new MenuItem[] {
menuItemAbout} );
menuItemHelp.Text = "&Help";
// menuItemAbout
- menuItemAbout.Index = 19;
+ menuItemAbout.Index = 0;
menuItemAbout.Text = "A&bout";
menuItemAbout.Click += new EventHandler( OnMenuItemAboutClick );
@@ -221,60 +185,32 @@ private void InitializeComponent( )
menuItemResources,
menuItemHelp} );
- activePanel = textPanel;
-
- // textPanel
-// textPanel.Location = new Point( 0, 0 );
-// textPanel.Size = new Size( 592, 213 );
-
- // resourceListBox
- resourceListBox.Size = new Size( 592, 328 );
- resourceListBox.Dock = DockStyle.Fill;
- resourceListBox.TabIndex = 0;
- resourceListBox.ContextMenu = contextMenu;
-
- // resourceTreeView
- resourceTreeView.Dock = DockStyle.Left;
- resourceTreeView.Size = new Size( 150, 328 );
-
- // resourcePanel
- resourcePanel.Controls.Add( resourceListBox );
- resourcePanel.Controls.Add( resourceSplitter );
- resourcePanel.Controls.Add( resourceTreeView );
- resourcePanel.Dock = DockStyle.Top;
- resourcePanel.Location = new Point( 0, 0 );
- resourcePanel.Size = new Size( 592, 328 );
- resourcePanel.TabIndex = 0;
- resourcePanel.DockPadding.All = 5;
-
- // mainSplitter
- mainSplitter.Dock = DockStyle.Top;
- mainSplitter.MinExtra = 213;
- mainSplitter.MinSize = 328;
-
- // resourceSplitter
- resourceSplitter.Dock = DockStyle.Left;
- resourceSplitter.MinExtra = 150;
- resourceSplitter.MinSize = 150;
-
- // contentControl
- contentControl.Location = new Point( 0, 328 );
- contentControl.Size = new Size( 592, 213 );
- contentControl.Dock = DockStyle.Fill;
- contentControl.TabIndex = 3;
- contentControl.Controls.Add( textPanel );
-
- // contextMenu
- contextMenu.MenuItems.AddRange( new MenuItem[] {
- menuItemAddString.CloneMenu( ),
- menuItemAddFiles.CloneMenu( ),
- menuItemAddColor.CloneMenu( ),
- menuItemDash2.CloneMenu( ),
- menuItemDelete.CloneMenu( ),
- menuItemCopy.CloneMenu( ),
- menuItemPaste.CloneMenu( ),
- menuItemRename.CloneMenu( )
- } );
+ // resourceControl
+ resourceControl.Dock = DockStyle.Fill;
+ resourceControl.InternalContextMenu.MenuItems.AddRange( new MenuItem[] {
+ menuItemAddString.CloneMenu( ),
+ menuItemAddFiles.CloneMenu( ),
+ menuItemAddColor.CloneMenu( ),
+ menuItemDash2.CloneMenu( ),
+ menuItemDelete.CloneMenu( ),
+ menuItemCopy.CloneMenu( ),
+ menuItemPaste.CloneMenu( ),
+ menuItemRename.CloneMenu( )
+ } );
+
+ // statusBar
+ StatusBarPanel panel1 = new StatusBarPanel( );
+ StatusBarPanel panel2 = new StatusBarPanel( );
+
+ panel1.BorderStyle = StatusBarPanelBorderStyle.Sunken;
+ panel1.AutoSize = StatusBarPanelAutoSize.Spring;
+ panel2.BorderStyle = StatusBarPanelBorderStyle.Sunken;
+ panel2.AutoSize = StatusBarPanelAutoSize.Spring;
+ statusBar.ShowPanels = true;
+ statusBar.Panels.Add( panel1 );
+ statusBar.Panels.Add( panel2 );
+
+ resourceControl.ParentStatusBar = statusBar;
// MainForm
// AutoScaleBaseSize = new Size( 5, 14 );
@@ -283,551 +219,72 @@ private void InitializeComponent( )
Menu = mainMenu;
Text = "New Resource.resx";
- Controls.Add( contentControl );
- Controls.Add( mainSplitter );
- Controls.Add( resourcePanel );
-
- contentControl.ResumeLayout( false );
- resourcePanel.ResumeLayout( false );
-
ResumeLayout( false );
- resourceListBox.SelectedIndexChanged += new EventHandler( OnResourceListBoxSelectedIndexChanged );
- }
-
- public bool FileSaved
- {
- set {
- fileSaved = value;
-
- if ( !fileSaved )
- {
- string title = Text;
-
- if ( !title.EndsWith( " *" ) )
- {
- title += " *";
-
- Text = title;
- }
- }
- else
- {
- string title = Text;
-
- if ( title.EndsWith( " *" ) )
- {
- title = title.Replace( " *", "" );
-
- Text = title;
- }
- }
- }
-
- get {
- return fileSaved;
- }
+ Controls.Add( resourceControl );
+ Controls.Add( statusBar );
}
void OnMenuItemNewClick( object sender, EventArgs e )
{
- fullFileName = "New Resource.resx";
-
- Text = fullFileName;
-
- FileSaved = false;
-
- first_time_saved = false;
-
- ResetListBoxAndTreeView( );
+ resourceControl.NewResource( );
}
- private void ResetListBoxAndTreeView( )
- {
- resourceTreeView.ClearResources( );
-
- if ( resourceListBox.Items.Count > 0 )
- resourceListBox.ClearResources( );
-
- if ( activePanel != textPanel )
- {
- activePanel.Hide( );
- contentControl.Controls.Remove( activePanel );
- contentControl.Controls.Add( textPanel );
-
- activePanel = textPanel;
- textPanel.ContentTextBox.Clear( );
- textPanel.Show( );
- }
- }
void OnMenuItemLoadClick( object sender, EventArgs e )
{
- OpenFileDialog ofd = new OpenFileDialog( );
- ofd.CheckFileExists = true;
- ofd.Filter = "resx files (*.resx)|*.resx|All files (*.*)|*.*";
-
- if ( last_load_resx_directory != String.Empty )
- if ( Directory.Exists( last_load_resx_directory ) )
- ofd.InitialDirectory = last_load_resx_directory;
-
- if ( DialogResult.OK == ofd.ShowDialog( ) )
- {
- ResetListBoxAndTreeView( );
-
- resXResourceReader = new ResXResourceReader( ofd.FileName );
-
- Text = Path.GetFileName( ofd.FileName );
-
- fullFileName = ofd.FileName;
-
- last_load_resx_directory = Path.GetDirectoryName( ofd.FileName );
-
- FillListBoxAndTreeView( );
-
- resXResourceReader.Close( );
- }
+ resourceControl.LoadResource( );
}
void OnMenuItemSaveClick( object sender, EventArgs e )
{
- if ( resourceListBox.Items.Count == 0 )
- return;
-
- if ( !first_time_saved )
- {
- OnMenuItemSaveAsClick( sender, e );
- return;
- }
-
- File.Delete( fullFileName );
-
- WriteResourceFile( );
-
- FileSaved = true;
+ resourceControl.SaveResource( );
}
void OnMenuItemSaveAsClick( object sender, EventArgs e )
{
- if ( resourceListBox.Items.Count == 0 )
- return;
-
- SaveFileDialog sfd = new SaveFileDialog( );
- sfd.CheckFileExists = true;
- sfd.DefaultExt = "resx";
- sfd.Filter = "resx files (*.resx)|*.resx|All files (*.*)|*.*";
-
- if ( last_save_as_directory == String.Empty )
- if ( last_load_resx_directory != String.Empty )
- last_save_as_directory = last_load_resx_directory;
-
- if ( last_save_as_directory != String.Empty )
- if ( Directory.Exists( last_save_as_directory ) )
- sfd.InitialDirectory = last_save_as_directory;
-
- if ( DialogResult.OK == sfd.ShowDialog( ) )
- {
- fullFileName = sfd.FileName;
-
- Text = Path.GetFileName( fullFileName );
-
- last_save_as_directory = Path.GetDirectoryName( sfd.FileName );
-
- if ( File.Exists( fullFileName ) )
- File.Delete( fullFileName );
-
- WriteResourceFile( );
-
- FileSaved = true;
-
- first_time_saved = true;
- }
- }
-
- private void WriteResourceFile( )
- {
- ResXResourceWriter rxrw = new ResXResourceWriter( fullFileName );
-
- foreach ( IResource res_abstract in resourceListBox.AllItems )
- {
- switch ( res_abstract.ResourceType )
- {
- case ResourceType.TypeImage:
- ResourceImage resImage = res_abstract as ResourceImage;
-
- if ( resImage.Image == null )
- continue;
-
- rxrw.AddResource( resImage.ResourceName, resImage.Image );
- break;
-
- case ResourceType.TypeString:
- ResourceString resStr = res_abstract as ResourceString;
-
- if ( resStr == null )
- continue;
-
- rxrw.AddResource( resStr.ResourceName, resStr.Text );
- break;
-
- case ResourceType.TypeCursor:
- ResourceCursor resCursor = res_abstract as ResourceCursor;
-
- if ( resCursor == null )
- continue;
-
- rxrw.AddResource( resCursor.ResourceName, resCursor.Cursor );
- break;
-
- case ResourceType.TypeIcon:
- ResourceIcon resIcon = res_abstract as ResourceIcon;
-
- if ( resIcon == null )
- continue;
-
- rxrw.AddResource( resIcon.ResourceName, resIcon.Icon );
- break;
-
- case ResourceType.TypeColor:
- ResourceColor resColor = res_abstract as ResourceColor;
-
- if ( resColor == null )
- continue;
-
- rxrw.AddResource( resColor.ResourceName, resColor.Color );
- break;
-
- case ResourceType.TypeByteArray:
- ResourceByteArray resByteArray = res_abstract as ResourceByteArray;
-
- if ( resByteArray == null )
- continue;
-
- rxrw.AddResource( resByteArray.ResourceName, resByteArray.ByteArray );
- break;
-
- default:
- break;
- }
- }
-
- rxrw.Close( );
+ resourceControl.SaveResourceAs( );
}
void OnMenuItemExitClick( object sender, EventArgs e )
{
- if ( resourceListBox.Items.Count == 0 || FileSaved )
+ if ( resourceControl.CanExit( ) )
Close( );
- else
- {
- string filename_short = Path.GetFileName( fullFileName );
-
- DialogResult result = MessageBox.Show( "File " + filename_short + " not saved.\n\n" + "Save ?",
- "Exit...",
- MessageBoxButtons.YesNoCancel,
- MessageBoxIcon.Question );
-
- switch ( result )
- {
- case DialogResult.Yes:
- OnMenuItemSaveClick( null, EventArgs.Empty );
- if ( FileSaved )
- Close( );
- break;
- case DialogResult.No:
- Close( );
- break;
- default:
- break;
- }
- }
}
void OnMenuItemAddStringClick( object sender, EventArgs e )
{
- string new_item_string = TextEntryDialog.Show( "New String", "Enter new string:" );
-
- if ( new_item_string.Length != 0 )
- {
- IResource resource = CreateNewResource( new_item_string, new_item_string );
-
- if ( resourceListBox.Items.Count == 0 )
- resourceListBox.AddResourceDirect( resource );
- else
- resourceListBox.InsertResourceDirect( 0, resource );
-
- resourceListBox.SelectedIndex = 0;
-
- // FIXME: TopIndex has not the effect that is wanted here
- // bug in ListBox ???
- resourceListBox.TopIndex = 0;
-
- resourceListBox.Invalidate( );
-
- FileSaved = false;
- }
+ resourceControl.AddString( );
}
void OnMenuItemAddFilesClick( object sender, EventArgs e )
{
- OpenFileDialog ofd = new OpenFileDialog( );
- ofd.CheckFileExists = true;
- ofd.Multiselect = true;
-
- ofd.Filter = "Images (*.png;*.jpg;*.gif;*.bmp)|*.png;*.jpg;*.gif;*.bmp|Icons (*.ico)|*.ico|Cursors (*.cur)|*.cur|All files (*.*)|*.*";
-
- if ( last_add_files_directory != String.Empty )
- if ( Directory.Exists( last_add_files_directory ) )
- ofd.InitialDirectory = last_add_files_directory;
-
- if ( DialogResult.OK == ofd.ShowDialog( ) )
- {
- foreach ( string file_name in ofd.FileNames )
- {
- try
- {
- string upper_file_name = file_name.ToUpper( );
-
- // icon
- if ( upper_file_name.EndsWith( ".ICO" ) )
- {
- IResource resIcon = CreateNewResource( Path.GetFileName( file_name ), new Icon( file_name ) );
-
- resourceListBox.AddResourceDirect( resIcon );
- }
- else if ( upper_file_name.EndsWith( ".CUR" ) )
- {
- IResource resCursor = CreateNewResource( Path.GetFileName( file_name ), new Cursor( file_name ) );
-
- resourceListBox.AddResourceDirect( resCursor );
- }
- else
- // images
- if ( upper_file_name.EndsWith( ".PNG" ) || upper_file_name.EndsWith( ".JPG" ) ||
- upper_file_name.EndsWith( ".GIF" ) || upper_file_name.EndsWith( ".BMP" ) )
- {
- IResource resImage = CreateNewResource( Path.GetFileName( file_name ), Image.FromFile( file_name ) );
-
- resourceListBox.AddResourceDirect( resImage );
- }
- else
- // byte array
- {
- byte[] bytes = null;
-
- using ( FileStream fs = File.OpenRead( file_name ) )
- {
- bytes = new byte[ fs.Length ];
-
- fs.Read( bytes, 0, bytes.Length );
- }
-
- IResource resByteArray = CreateNewResource( Path.GetFileName( file_name ), bytes );
-
- resourceListBox.AddResourceDirect( resByteArray );
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine( "File {0} not found.", file_name );
- }
- }
-
- if ( ofd.FileNames.Length > 0 )
- {
- last_add_files_directory = Path.GetDirectoryName( ofd.FileNames[ 0 ] );
-
- if ( resourceListBox.Items.Count > 0 )
- {
- resourceListBox.SelectedIndex = 0;
-
- // FIXME: TopIndex has not the effect that is wanted
- // bug in ListBox ???
- resourceListBox.TopIndex = 0;
-
- resourceListBox.Invalidate( );
- }
-
- FileSaved = false;
- }
- }
+ resourceControl.AddFiles( );
}
void OnMenuItemAddColorClick( object sender, EventArgs e )
{
- ColorDialog cd = new ColorDialog( );
-
- if ( DialogResult.OK == cd.ShowDialog( ) )
- {
- string resource_name = resourceListBox.UniqueResourceName( "Color" );
-
- IResource res_color = CreateNewResource( resource_name, cd.Color );
-
- resourceListBox.AddResourceDirect( res_color );
-
- resourceListBox.Invalidate( );
-
- FileSaved = false;
- }
+ resourceControl.AddColor( );
}
void OnMenuItemDeleteClick( object sender, EventArgs e )
{
- if ( resourceListBox.SelectedItems.Count == 0 )
- return;
-
- resourceListBox.RemoveResource( (IResource)resourceListBox.SelectedItems[ 0 ] );
-
- resourceListBox.Invalidate( );
-
- FileSaved = false;
+ resourceControl.DeleteResource( );
}
void OnMenuItemCopyClick( object sender, EventArgs e )
{
- if ( resourceListBox.SelectedItems.Count == 0 )
- return;
-
- IResource res_abstract = (IResource)resourceListBox.SelectedItems[ 0 ];
-
- resourceCopy = CreateNewResource( resourceListBox.UniqueResourceName( res_abstract.ResourceName ), res_abstract.Value );
+ resourceControl.CopyResource( );
}
void OnMenuItemPasteClick( object sender, EventArgs e )
{
- if ( resourceCopy == null )
- return;
-
- resourceListBox.AddResourceDirect( resourceCopy );
-
- resourceListBox.Invalidate( );
-
- FileSaved = false;
+ resourceControl.PasteResource( );
}
void OnMenuItemRenameClick( object sender, EventArgs e )
{
- if ( resourceListBox.SelectedItems.Count == 0 )
- return;
-
- IResource resource = (IResource)resourceListBox.SelectedItems[ 0 ];
- string resource_name = resource.ResourceName;
-
- string new_resource_name = TextEntryDialog.Show( "Rename", "Enter new name for \"" + resource_name + "\":" );
-
- if ( new_resource_name.Length != 0 )
- {
- resourceListBox.RenameResource( resource, new_resource_name );
-
- resourceListBox.Invalidate( );
-
- FileSaved = false;
- }
- }
-
- void OnResourceListBoxSelectedIndexChanged( object sender, EventArgs e )
- {
- if ( resourceListBox.SelectedItems.Count == 0 )
- return;
-
- IResource resource = (IResource)resourceListBox.SelectedItems[ 0 ];
-
- switch ( resource.ResourceType )
- {
- case ResourceType.TypeImage:
- if ( activePanel != imagePanel )
- {
- activePanel.Hide( );
- contentControl.Controls.Remove( activePanel );
- contentControl.Controls.Add( imagePanel );
-
- activePanel = imagePanel;
- imagePanel.Show( );
- }
-
- ResourceImage resImage = (ResourceImage)resource;
- imagePanel.Image = resImage.Image;
- break;
-
- case ResourceType.TypeString:
- if ( activePanel != textPanel )
- {
- activePanel.Hide( );
- contentControl.Controls.Remove( activePanel );
- contentControl.Controls.Add( textPanel );
-
- activePanel = textPanel;
- textPanel.Show( );
- }
-
- ResourceString resString = (ResourceString)resource;
- textPanel.ContentTextBox.Text = resString.Text;
- break;
-
- case ResourceType.TypeCursor:
- if ( activePanel != imagePanel )
- {
- activePanel.Hide( );
- contentControl.Controls.Remove( activePanel );
- contentControl.Controls.Add( imagePanel );
-
- activePanel = imagePanel;
- imagePanel.Show( );
- }
-
- ResourceCursor resCursor = (ResourceCursor)resource;
- imagePanel.Image = resCursor.RenderContent;
- break;
-
-
- case ResourceType.TypeIcon:
- if ( activePanel != imagePanel )
- {
- activePanel.Hide( );
- contentControl.Controls.Remove( activePanel );
- contentControl.Controls.Add( imagePanel );
-
- activePanel = imagePanel;
- imagePanel.Show( );
- }
-
- ResourceIcon resIcon = (ResourceIcon)resource;
- imagePanel.Icon = resIcon.Icon;
- break;
-
- case ResourceType.TypeColor:
- if ( activePanel != colorPanel )
- {
- activePanel.Hide( );
- contentControl.Controls.Remove( activePanel );
- contentControl.Controls.Add( colorPanel );
-
- activePanel = colorPanel;
- colorPanel.Show( );
- }
-
- ResourceColor resColor = (ResourceColor)resource;
- colorPanel.Color = resColor.Color;
- break;
-
- case ResourceType.TypeByteArray:
- if ( activePanel != byteArrayPanel )
- {
- activePanel.Hide( );
- contentControl.Controls.Remove( activePanel );
- contentControl.Controls.Add( byteArrayPanel );
-
- activePanel = byteArrayPanel;
- byteArrayPanel.Show( );
- }
-
- ResourceByteArray resByteArray = (ResourceByteArray)resource;
- byteArrayPanel.ByteArray = resByteArray.ByteArray;
- break;
-
- default:
- break;
- }
+ resourceControl.RenameResource( );
}
void OnMenuItemAboutClick( object sender, EventArgs e )
@@ -836,68 +293,6 @@ void OnMenuItemAboutClick( object sender, EventArgs e )
ad.ShowDialog( );
}
- void FillListBoxAndTreeView( )
- {
- resourceListBox.BeginUpdate( );
-
- foreach ( DictionaryEntry de in resXResourceReader )
- resourceListBox.AddResource( de.Key.ToString( ), de.Value );
-
- resourceListBox.EndUpdate( );
-
- resourceTreeView.Fill( );
-
- resourceListBox.ShowNode( ResourceType.All );
-
- if ( resourceListBox.Items.Count > 0 )
- resourceListBox.SelectedIndex = 0;
- }
-
- public void ChangeResourceContent( )
- {
- if ( resourceListBox.SelectedItems.Count != 0 )
- {
- resourceListBox.BeginUpdate( );
-
- IResource oldRes = (IResource)resourceListBox.SelectedItems[ 0 ];
- IResource newRes = CreateNewResource( oldRes.ResourceName, ( (IPanel)activePanel ).Value );
-
- resourceListBox.ReplaceResource( oldRes, newRes );
-
- resourceListBox.EndUpdate( );
-
- resourceListBox.Invalidate( );
-
- FileSaved = false;
- }
- }
-
- private IResource CreateNewResource( string name, object content )
- {
- Type new_type;
-
- if ( content is Bitmap )
- new_type = typeof( ResourceImage );
- else
- if ( content is String )
- new_type = typeof( ResourceString );
- else
- if ( content is Icon )
- new_type = typeof( ResourceIcon );
- else
- if ( content is Cursor )
- new_type = typeof( ResourceCursor );
- else
- if ( content is Color )
- new_type = typeof( ResourceColor );
- else
- new_type = typeof( ResourceByteArray );
-
- IResource resource = Activator.CreateInstance( new_type, new object[] { name, content } ) as IResource;
-
- return resource;
- }
-
[STAThread]
static void Main( )
{
View
4 MWFResourceEditor/Makefile
@@ -1,10 +1,10 @@
all: mono
mono:
- mcs -out:resedit.exe AboutDialog.cs ByteArrayPanel.cs ColorPanel.cs ImagePanel.cs IResource.cs IResourceRenderer.cs MainForm.cs ResourceBase.cs ResourceByteArray.cs ResourceColor.cs ResourceCursor.cs ResourceIcon.cs ResourceImage.cs ResourceListBox.cs ResourceString.cs ResourceType.cs TextEntryDialog.cs TextPanel.cs ResourceTreeView.cs ResourceTreeNode.cs IPanel.cs /r:System.Windows.Forms.dll /r:System.Drawing.dll
+ mcs -out:resedit.exe AboutDialog.cs ByteArrayPanel.cs ColorPanel.cs ImagePanel.cs IResource.cs IResourceRenderer.cs MainForm.cs ResourceBase.cs ResourceByteArray.cs ResourceColor.cs ResourceContentControl.cs ResourceControl.cs ResourceCursor.cs ResourceIcon.cs ResourceImage.cs ResourceList.cs ResourceListBox.cs ResourceSelectionControl.cs ResourceString.cs ResourceType.cs TextEntryDialog.cs TextPanel.cs ResourceTreeView.cs ResourceTreeNode.cs IPanel.cs /r:System.Windows.Forms.dll /r:System.Drawing.dll
dotnet:
- csc -out:resedit.exe AboutDialog.cs ByteArrayPanel.cs ColorPanel.cs ImagePanel.cs IResource.cs IResourceRenderer.cs MainForm.cs ResourceBase.cs ResourceByteArray.cs ResourceColor.cs ResourceCursor.cs ResourceIcon.cs ResourceImage.cs ResourceListBox.cs ResourceString.cs ResourceType.cs TextEntryDialog.cs TextPanel.cs ResourceTreeView.cs ResourceTreeNode.cs IPanel.cs /r:System.Windows.Forms.dll /r:System.Drawing.dll
+ csc -out:resedit.exe AboutDialog.cs ByteArrayPanel.cs ColorPanel.cs ImagePanel.cs IResource.cs IResourceRenderer.cs MainForm.cs ResourceBase.cs ResourceByteArray.cs ResourceColor.cs ResourceContentControl.cs ResourceControl.cs ResourceCursor.cs ResourceIcon.cs ResourceImage.cs ResourceList.cs ResourceListBox.cs ResourceSelectionControl.cs ResourceString.cs ResourceType.cs TextEntryDialog.cs TextPanel.cs ResourceTreeView.cs ResourceTreeNode.cs IPanel.cs /r:System.Windows.Forms.dll /r:System.Drawing.dll
clean:
rm resedit.exe -r -f
View
184 MWFResourceEditor/ResourceBase.cs
@@ -1,92 +1,92 @@
-// Authors:
-// Alexander Olk, <xenomorph2@onlinehome.de>
-
-using System;
-using System.Drawing;
-
-namespace MWFResourceEditor
-{
- public abstract class ResourceBase : IResourceRenderer
- {
- protected string resource_name = null;
-
- protected static int content_text_x_pos = 60;
- protected static int content_name_y_pos = 3;
- protected static int content_type_y_pos = 16;
- protected static int content_content_y_pos = 29;
-
- protected static Point thumb_location = new Point( 3, 3 );
- protected static Size thumb_size = new Size( 42, 42 );
- protected static Size renderBitmap_size = new Size( 300, 50 );
-
- protected static SolidBrush solidBrushBlack = new SolidBrush( Color.Black );
- protected static SolidBrush solidBrushTransparent = new SolidBrush( Color.Transparent );
- protected static SolidBrush solidBrushWhite = new SolidBrush( Color.White );
- protected static SolidBrush solidBrushAqua = new SolidBrush( Color.Aqua );
-
- protected static Font smallFont = new Font ("Arial", 8);
-
- protected Bitmap renderBitmap;
-
- protected int all_data_for_rendering_available = 0;
-
- public Bitmap RenderContent
- {
- get {
- return renderBitmap;
- }
- }
-
- public string ResourceName
- {
- get {
- return resource_name;
- }
- set {
- if ( resource_name != null )
- all_data_for_rendering_available = 1;
-
- resource_name = value;
-
- all_data_for_rendering_available++;
-
- if ( all_data_for_rendering_available == 2 )
- CreateRenderBitmap( );
- }
- }
-
- protected Graphics CreateNewRenderBitmap( )
- {
- if ( renderBitmap != null )
- renderBitmap.Dispose( );
-
- renderBitmap = new Bitmap( renderBitmap_size.Width, renderBitmap_size.Height );
-
- Graphics gr = Graphics.FromImage( renderBitmap );
-
- gr.FillRectangle( solidBrushTransparent, gr.ClipBounds );
-
- gr.FillRectangle( solidBrushWhite, new Rectangle( thumb_location.X - 2, thumb_location.Y - 2, thumb_size.Width + 4, thumb_size.Height + 4 ) );
- gr.DrawRectangle( Pens.Black, new Rectangle( thumb_location.X - 2, thumb_location.Y - 2, thumb_size.Width + 4, thumb_size.Height + 4 ) );
-
- return gr;
- }
-
- protected abstract void CreateRenderBitmap( );
-
- public bool DummyThumbnailCallback( )
- {
- return false;
- }
-
- public Image GetThumbNail( Image image, int new_width, int new_height )
- {
- Image.GetThumbnailImageAbort thumbnailCallback = new Image.GetThumbnailImageAbort( DummyThumbnailCallback );
-
- Image thumbnail = image.GetThumbnailImage( new_width, new_height, thumbnailCallback, IntPtr.Zero );
-
- return thumbnail;
- }
- }
-}
-
+// Authors:
+// Alexander Olk, <xenomorph2@onlinehome.de>
+
+using System;
+using System.Drawing;
+
+namespace MWFResourceEditor
+{
+ public abstract class ResourceBase : IResourceRenderer
+ {
+ protected string resource_name = null;
+
+ protected static int content_text_x_pos = 60;
+ protected static int content_name_y_pos = 3;
+ protected static int content_type_y_pos = 16;
+ protected static int content_content_y_pos = 29;
+
+ protected static Point thumb_location = new Point( 3, 5 );
+ protected static Size thumb_size = new Size( 42, 42 );
+ protected static Size renderBitmap_size = new Size( 300, 50 );
+
+ protected static SolidBrush solidBrushBlack = new SolidBrush( Color.Black );
+ protected static SolidBrush solidBrushTransparent = new SolidBrush( Color.Transparent );
+ protected static SolidBrush solidBrushWhite = new SolidBrush( Color.White );
+ protected static SolidBrush solidBrushAqua = new SolidBrush( Color.Aqua );
+
+ protected static Font smallFont = new Font ("Arial", 8);
+
+ protected Bitmap renderBitmap;
+
+ protected int all_data_for_rendering_available = 0;
+
+ public Bitmap RenderContent
+ {
+ get {
+ return renderBitmap;
+ }
+ }
+
+ public string ResourceName
+ {
+ get {
+ return resource_name;
+ }
+ set {
+ if ( resource_name != null )
+ all_data_for_rendering_available = 1;
+
+ resource_name = value;
+
+ all_data_for_rendering_available++;
+
+ if ( all_data_for_rendering_available == 2 )
+ CreateRenderBitmap( );
+ }
+ }
+
+ protected Graphics CreateNewRenderBitmap( )
+ {
+ if ( renderBitmap != null )
+ renderBitmap.Dispose( );
+
+ renderBitmap = new Bitmap( renderBitmap_size.Width, renderBitmap_size.Height );
+
+ Graphics gr = Graphics.FromImage( renderBitmap );
+
+ gr.FillRectangle( solidBrushTransparent, gr.ClipBounds );
+
+ gr.FillRectangle( solidBrushWhite, new Rectangle( thumb_location.X - 2, thumb_location.Y - 2, thumb_size.Width + 4, thumb_size.Height + 4 ) );
+ gr.DrawRectangle( Pens.Black, new Rectangle( thumb_location.X - 2, thumb_location.Y - 2, thumb_size.Width + 4, thumb_size.Height + 4 ) );
+
+ return gr;
+ }
+
+ protected abstract void CreateRenderBitmap( );
+
+ public bool DummyThumbnailCallback( )
+ {
+ return false;
+ }
+
+ public Image GetThumbNail( Image image, int new_width, int new_height )
+ {
+ Image.GetThumbnailImageAbort thumbnailCallback = new Image.GetThumbnailImageAbort( DummyThumbnailCallback );
+
+ Image thumbnail = image.GetThumbnailImage( new_width, new_height, thumbnailCallback, IntPtr.Zero );
+
+ return thumbnail;
+ }
+ }
+}
+
View
216 MWFResourceEditor/ResourceByteArray.cs
@@ -1,108 +1,108 @@
-// Authors:
-// Alexander Olk, <xenomorph2@onlinehome.de>
-
-using System;
-using System.Drawing;
-
-namespace MWFResourceEditor
-{
- public class ResourceByteArray : ResourceBase, IResource
- {
- private byte[] byteArray = null;
-
- private static Bitmap one_and_zero;
-
- static ResourceByteArray( )
- {
- one_and_zero = new Bitmap( ResourceBase.thumb_size.Width, ResourceBase.thumb_size.Height );
-
- using ( Graphics gr = Graphics.FromImage( one_and_zero ) )
- {
- Font font = new Font( FontFamily.GenericMonospace, 5 );
-
- SizeF zero_size = gr.MeasureString( "0", font );
- SizeF one_size = gr.MeasureString( "1", font );
-
- int y_counter = 0;
-
- while ( y_counter < thumb_size.Height )
- {
- int x_counter = 0;
-
- while ( x_counter < thumb_size.Width )
- {
- Random random = new Random( );
-
- string what = random.Next( 2 ) == 1 ? "1" : "0";
-
- gr.DrawString( what, font, solidBrushBlack, x_counter, y_counter );
-
- x_counter += what == "1" ? (int)one_size.Width : (int)zero_size.Width;
- }
-
- y_counter += (int)zero_size.Height;
- }
- }
- }
-
- public ResourceByteArray( string name, byte[] byteArray )
- {
- ResourceName = name;
- ByteArray = byteArray;
- }
-
- public byte[] ByteArray
- {
- set {
- if ( byteArray != null )
- all_data_for_rendering_available = 1;
-
- byteArray = value;
-
- all_data_for_rendering_available++;
-
- if ( all_data_for_rendering_available == 2 )
- CreateRenderBitmap( );
- }
-
- get {
- return byteArray;
- }
- }
-
- public ResourceType ResourceType
- {
- get {
- return ResourceType.TypeByteArray;
- }
- }
-
- public string ContentString( )
- {
- return byteArray.ToString( );
- }
-
- public Object Value
- {
- get {
-
- return byteArray;
- }
- }
-
- protected override void CreateRenderBitmap( )
- {
- using ( Graphics gr = CreateNewRenderBitmap( ) )
- {
- gr.DrawImage( one_and_zero, thumb_location.X, thumb_location.Y, thumb_size.Width, thumb_size.Height );
-
- gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
-
- gr.DrawString( "Type: " + byteArray.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
-
- gr.DrawString( "Size: " + byteArray.Length, smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
- }
- }
- }
-}
-
+// Authors:
+// Alexander Olk, <xenomorph2@onlinehome.de>
+
+using System;
+using System.Drawing;
+
+namespace MWFResourceEditor
+{
+ public class ResourceByteArray : ResourceBase, IResource
+ {
+ private byte[] byteArray = null;
+
+ private static Bitmap one_and_zero;
+
+ static ResourceByteArray( )
+ {
+ one_and_zero = new Bitmap( ResourceBase.thumb_size.Width, ResourceBase.thumb_size.Height );
+
+ using ( Graphics gr = Graphics.FromImage( one_and_zero ) )
+ {
+ Font font = new Font( FontFamily.GenericMonospace, 5 );
+
+ SizeF zero_size = gr.MeasureString( "0", font );
+ SizeF one_size = gr.MeasureString( "1", font );
+
+ int y_counter = 0;
+
+ while ( y_counter < thumb_size.Height )
+ {
+ int x_counter = 0;
+
+ Random random = new Random( );
+
+ while ( x_counter < thumb_size.Width )
+ {
+ string what = random.Next( 2 ) == 1 ? "1" : "0";
+
+ gr.DrawString( what, font, solidBrushBlack, x_counter, y_counter );
+
+ x_counter += what == "1" ? (int)one_size.Width : (int)zero_size.Width;
+ }
+
+ y_counter += (int)zero_size.Height;
+ }
+ }
+ }
+
+ public ResourceByteArray( string name, byte[] byteArray )
+ {
+ ResourceName = name;
+ ByteArray = byteArray;
+ }
+
+ public byte[] ByteArray
+ {
+ set {
+ if ( byteArray != null )
+ all_data_for_rendering_available = 1;
+
+ byteArray = value;
+
+ all_data_for_rendering_available++;
+
+ if ( all_data_for_rendering_available == 2 )
+ CreateRenderBitmap( );
+ }
+
+ get {
+ return byteArray;
+ }
+ }
+
+ public ResourceType ResourceType
+ {
+ get {
+ return ResourceType.TypeByteArray;
+ }
+ }
+
+ public string ContentString( )
+ {
+ return byteArray.ToString( );
+ }
+
+ public Object Value
+ {
+ get {
+
+ return byteArray;
+ }
+ }
+
+ protected override void CreateRenderBitmap( )
+ {
+ using ( Graphics gr = CreateNewRenderBitmap( ) )
+ {
+ gr.DrawImage( one_and_zero, thumb_location.X, thumb_location.Y, thumb_size.Width, thumb_size.Height );
+
+ gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
+
+ gr.DrawString( "Type: " + byteArray.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
+
+ gr.DrawString( "Size: " + byteArray.Length, smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
+ }
+ }
+ }
+}
+
View
156 MWFResourceEditor/ResourceContentControl.cs
@@ -0,0 +1,156 @@
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+
+namespace MWFResourceEditor
+{
+ public class ResourceContentControl : Control
+ {
+// delegate void ActivePanelChangedDelegate( IPanel panel );
+// ActivePanelChangedDelegate activePanelChanged;
+
+ private ImagePanel imagePanel;
+ private TextPanel textPanel;
+ private ColorPanel colorPanel;
+ private ByteArrayPanel byteArrayPanel;
+
+ private Panel activePanel;
+
+ public ResourceControl.ChangeResourceContentDelegate change_Resource_Content;
+
+ public ResourceContentControl( ResourceControl resourceControl )
+ {
+ imagePanel = new ImagePanel( this );
+ textPanel = new TextPanel( this );
+ colorPanel = new ColorPanel( this );
+ byteArrayPanel = new ByteArrayPanel( this );
+
+ SuspendLayout( );
+
+ activePanel = textPanel;
+
+ Controls.Add( textPanel );
+
+ ResumeLayout( false );
+
+ change_Resource_Content = new ResourceControl.ChangeResourceContentDelegate( resourceControl.ChangeResourceContent );
+ }
+
+ public Panel ActivePanel
+ {
+ set {
+ activePanel = value;
+ }
+ get {
+ return activePanel;
+ }
+ }
+
+
+ public TextPanel TextPanel
+ {
+ get {
+ return textPanel;
+ }
+ }
+
+ public ImagePanel ImagePanel
+ {
+ get {
+ return imagePanel;
+ }
+ }
+
+ public ColorPanel ColorPanel
+ {
+ get {
+ return colorPanel;
+ }
+ }
+
+ public ByteArrayPanel ByteArrayPanel
+ {
+ get {
+ return byteArrayPanel;
+ }
+ }
+
+ public ResourceControl.ChangeResourceContentDelegate Change_Resource_Content
+ {
+ get {
+ return change_Resource_Content;
+ }
+ }
+
+ public void ActivateTextPanel( )
+ {
+ if ( activePanel != textPanel )
+ {
+ activePanel.Hide( );
+ Controls.Remove( activePanel );
+ Controls.Add( textPanel );
+
+ activePanel = textPanel;
+ textPanel.Show( );
+ }
+ }
+
+ public void ActivateImagePanel( )
+ {
+ if ( activePanel != imagePanel )
+ {
+ activePanel.Hide( );
+ Controls.Remove( activePanel );
+ Controls.Add( imagePanel );
+
+ ActivePanel = imagePanel;
+ imagePanel.Show( );
+ }
+ }
+
+ public void ActivateColorPanel( )
+ {
+ if ( activePanel != colorPanel )
+ {
+ activePanel.Hide( );
+ Controls.Remove( activePanel );
+ Controls.Add( colorPanel );
+
+ ActivePanel = colorPanel;
+ colorPanel.Show( );
+ }
+ }
+
+ public void ActivateByteArrayPanel( )
+ {
+ if ( activePanel != byteArrayPanel )
+ {
+ activePanel.Hide( );
+ Controls.Remove( activePanel );
+ Controls.Add( byteArrayPanel );
+
+ ActivePanel = byteArrayPanel;
+ byteArrayPanel.Show( );
+ }
+ }
+
+ public void ClearActivePanel( )
+ {
+ IPanel ipanel = activePanel as IPanel;
+ ipanel.ClearResource( );
+ }
+
+ public void ClearResources( )
+ {
+ foreach ( Control control in Controls )
+ {
+ if ( control is IPanel )
+ {
+ ( (IPanel)control ).ClearResource( );
+ }
+ }
+ }
+ }
+}
+
+
View
613 MWFResourceEditor/ResourceControl.cs
@@ -0,0 +1,613 @@
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+using System.Resources;
+using System.IO;
+using System.Collections;
+
+namespace MWFResourceEditor
+{
+ public class ResourceControl : Control
+ {
+ public delegate void ChangeResourceContentDelegate( object new_resource_content );
+
+ private ResourceSelectionControl resourceSelectionControl;
+ private ResourceContentControl resourceContentControl;
+ private Splitter mainSplitter;
+
+ private ContextMenu contextMenu;
+
+ private string fullFileName = "New Resource.resx";
+
+ private bool fileSaved = true;
+
+ private ResXResourceReader resXResourceReader;
+
+ private string last_load_resx_directory = String.Empty;
+ private string last_add_files_directory = String.Empty;
+ private string last_save_as_directory = String.Empty;
+
+ private bool first_time_saved = false;
+
+ private IResource resourceCopy = null;
+
+ private ResourceList resourceList = ResourceList.Instance;
+
+ private StatusBar parentStatusBar;
+
+ private int number_resources = 0;
+ private string statusbar_file_name = "New Resource.resx";
+
+ public ResourceControl( )
+ {
+ mainSplitter = new Splitter( );
+
+ contextMenu = new ContextMenu( );
+
+ resourceSelectionControl = new ResourceSelectionControl( this );
+
+ resourceContentControl = new ResourceContentControl( this );
+
+ SuspendLayout( );
+
+ // resourceSelectionControl
+ resourceSelectionControl.Dock = DockStyle.Top;
+ resourceSelectionControl.Location = new Point( 0, 0 );
+ resourceSelectionControl.Size = new Size( 592, 328 );
+ resourceSelectionControl.TabIndex = 0;
+// resourceSelectionPanel.DockPadding.All = 5;
+
+ // mainSplitter
+ mainSplitter.Dock = DockStyle.Top;
+ mainSplitter.MinExtra = 213;
+ mainSplitter.MinSize = 328;
+
+ // contentControl
+ resourceContentControl.Location = new Point( 0, 328 );
+ resourceContentControl.Size = new Size( 592, 213 );
+ resourceContentControl.Dock = DockStyle.Fill;
+ resourceContentControl.TabIndex = 3;
+
+ Controls.Add( resourceContentControl );
+ Controls.Add( mainSplitter );
+ Controls.Add( resourceSelectionControl );
+
+ ResumeLayout( false );
+
+ resourceSelectionControl.ResourceListBox.SelectedIndexChanged += new EventHandler( OnResourceListBoxSelectedIndexChanged );
+ }
+
+ public bool FileSaved
+ {
+ set {
+ fileSaved = value;
+
+ string title = Parent.Text;
+
+ if ( !fileSaved )
+ {
+ if ( !title.EndsWith( " *" ) )
+ {
+ title += " *";
+
+ Parent.Text = title;
+ }
+ }
+ else
+ {
+ if ( title.EndsWith( " *" ) )
+ {
+ title = title.Replace( " *", "" );
+
+ Parent.Text = title;
+ }
+ }
+
+ statusbar_file_name = title;
+ UpdateStatusBar( );
+ }
+
+ get {
+ return fileSaved;
+ }
+ }
+
+ public ContextMenu InternalContextMenu
+ {
+ set {
+ contextMenu = value;
+ }
+
+ get {
+ return contextMenu;
+ }
+ }
+
+
+ public StatusBar ParentStatusBar
+ {
+ set {
+ parentStatusBar = value;
+ UpdateStatusBar( );
+ }
+
+ get {
+ return parentStatusBar;
+ }
+ }
+
+ public void NewResource( )
+ {
+ fullFileName = "New Resource.resx";
+
+ Text = fullFileName;
+
+ FileSaved = false;
+
+ first_time_saved = false;
+
+ ClearResources( );
+ }
+
+ public void LoadResource( )
+ {
+ OpenFileDialog ofd = new OpenFileDialog( );
+ ofd.CheckFileExists = true;
+ ofd.Filter = "resx files (*.resx)|*.resx|All files (*.*)|*.*";
+
+ if ( last_load_resx_directory != String.Empty )
+ if ( Directory.Exists( last_load_resx_directory ) )
+ ofd.InitialDirectory = last_load_resx_directory;
+
+ if ( DialogResult.OK == ofd.ShowDialog( ) )
+ {
+ ClearResources( );
+
+ resXResourceReader = new ResXResourceReader( ofd.FileName );
+
+ Text = Path.GetFileName( ofd.FileName );
+
+ fullFileName = ofd.FileName;
+
+ last_load_resx_directory = Path.GetDirectoryName( ofd.FileName );
+
+ number_resources = resourceSelectionControl.LoadResource( resXResourceReader );
+
+ resXResourceReader.Close( );
+
+ UpdateStatusBar( );
+ }
+ }
+
+ public void SaveResource( )
+ {
+ if ( resourceList.Count == 0 )
+ return;
+
+ if ( !first_time_saved )
+ {
+ SaveResourceAs( );
+ return;
+ }
+
+ File.Delete( fullFileName );
+
+ WriteResourceFile( );
+
+ FileSaved = true;
+ }
+
+ public void SaveResourceAs( )
+ {
+ if ( resourceList.Count == 0 )
+ return;
+
+ SaveFileDialog sfd = new SaveFileDialog( );
+ sfd.CheckFileExists = true;
+ sfd.DefaultExt = "resx";
+ sfd.Filter = "resx files (*.resx)|*.resx|All files (*.*)|*.*";
+
+ if ( last_save_as_directory == String.Empty )
+ if ( last_load_resx_directory != String.Empty )
+ last_save_as_directory = last_load_resx_directory;
+
+ if ( last_save_as_directory != String.Empty )
+ if ( Directory.Exists( last_save_as_directory ) )
+ sfd.InitialDirectory = last_save_as_directory;
+
+ if ( DialogResult.OK == sfd.ShowDialog( ) )
+ {
+ fullFileName = sfd.FileName;
+
+ Text = Path.GetFileName( fullFileName );
+
+ last_save_as_directory = Path.GetDirectoryName( sfd.FileName );
+
+ if ( File.Exists( fullFileName ) )
+ File.Delete( fullFileName );
+
+ WriteResourceFile( );
+
+ FileSaved = true;
+
+ first_time_saved = true;
+ }
+ }
+
+ public bool CanExit( )
+ {
+ if ( resourceList.Count == 0 || FileSaved )
+ return true;
+ else
+ {
+ string filename_short = Path.GetFileName( fullFileName );
+
+ DialogResult result = MessageBox.Show( "File " + filename_short + " not saved.\n\n" + "Save ?",
+ "Exit...",
+ MessageBoxButtons.YesNoCancel,
+ MessageBoxIcon.Question );
+
+ switch ( result )
+ {
+ case DialogResult.Yes:
+ SaveResource( );
+ if ( FileSaved )
+ return true;
+ break;
+ case DialogResult.No:
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public void AddString( )
+ {
+ string new_item_string = TextEntryDialog.Show( "New String", "Enter new string:" );
+
+ if ( new_item_string.Length != 0 )
+ {
+ IResource resource = CreateNewResource( new_item_string, new_item_string );
+
+ resourceSelectionControl.AddString( resource );
+
+ number_resources++;
+ FileSaved = false;
+ }
+ }
+
+ public void AddFiles( )
+ {
+ OpenFileDialog ofd = new OpenFileDialog( );
+ ofd.CheckFileExists = true;
+ ofd.Multiselect = true;
+
+ ofd.Filter = "Images (*.png;*.jpg;*.gif;*.bmp)|*.png;*.jpg;*.gif;*.bmp|Icons (*.ico)|*.ico|Cursors (*.cur)|*.cur|All files (*.*)|*.*";
+
+ if ( last_add_files_directory != String.Empty )
+ if ( Directory.Exists( last_add_files_directory ) )
+ ofd.InitialDirectory = last_add_files_directory;
+
+ if ( DialogResult.OK == ofd.ShowDialog( ) )
+ {
+ foreach ( string file_name in ofd.FileNames )
+ {
+ try
+ {
+ string upper_file_name = file_name.ToUpper( );
+
+ // icon
+ if ( upper_file_name.EndsWith( ".ICO" ) )
+ {
+ IResource resIcon = CreateNewResource( Path.GetFileName( file_name ), new Icon( file_name ) );
+
+ resourceSelectionControl.AddResourceDirect( resIcon );
+ }
+ else if ( upper_file_name.EndsWith( ".CUR" ) )
+ {
+ IResource resCursor = CreateNewResource( Path.GetFileName( file_name ), new Cursor( file_name ) );
+
+ resourceSelectionControl.AddResourceDirect( resCursor );
+ }
+ else
+ // images
+ if ( upper_file_name.EndsWith( ".PNG" ) || upper_file_name.EndsWith( ".JPG" ) ||
+ upper_file_name.EndsWith( ".GIF" ) || upper_file_name.EndsWith( ".BMP" ) )
+ {
+ IResource resImage = CreateNewResource( Path.GetFileName( file_name ), Image.FromFile( file_name ) );
+
+ resourceSelectionControl.AddResourceDirect( resImage );
+ }
+ else
+ // byte array
+ {
+ byte[] bytes = null;
+
+ using ( FileStream fs = File.OpenRead( file_name ) )
+ {
+ bytes = new byte[ fs.Length ];
+
+ fs.Read( bytes, 0, bytes.Length );
+ }
+
+ IResource resByteArray = CreateNewResource( Path.GetFileName( file_name ), bytes );
+
+ resourceSelectionControl.AddResourceDirect( resByteArray );
+ }
+
+ number_resources++;
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine( "File {0} not found.", file_name );
+ Console.WriteLine( ex );
+ }
+ }
+
+ if ( ofd.FileNames.Length > 0 )
+ {
+ last_add_files_directory = Path.GetDirectoryName( ofd.FileNames[ 0 ] );
+
+ resourceSelectionControl.EnsureVisible( );
+
+ FileSaved = false;
+ }
+ }
+ }
+
+ public void AddColor( )
+ {
+ ColorDialog cd = new ColorDialog( );
+
+ if ( DialogResult.OK == cd.ShowDialog( ) )
+ {
+ string resource_name = resourceList.UniqueResourceName( "Color" );
+
+ IResource res_color = CreateNewResource( resource_name, cd.Color );
+
+ resourceSelectionControl.AddResourceDirect( res_color );
+
+ number_resources++;
+ FileSaved = false;
+ }
+ }
+
+ public void DeleteResource( )
+ {
+ resourceSelectionControl.RemoveResource( );
+
+ number_resources--;
+ FileSaved = false;
+ }
+
+ public void CopyResource( )
+ {
+ IResource resource = resourceSelectionControl.SelectedResourceListBoxItem;
+
+ if ( resource != null )
+ resourceCopy = CreateNewResource( resourceList.UniqueResourceName( resource.ResourceName ), resource.Value );
+ }
+
+ public void PasteResource( )
+ {
+ if ( resourceCopy == null )
+ return;
+
+ resourceSelectionControl.AddResourceDirect( resourceCopy );
+
+ number_resources++;
+ FileSaved = false;
+ }
+
+ public void RenameResource( )
+ {
+ IResource resource = resourceSelectionControl.SelectedResourceListBoxItem;
+
+ if ( resource == null )
+ return;
+
+ string resource_name = resource.ResourceName;
+
+ string new_resource_name = TextEntryDialog.Show( "Rename", "Enter new name for \"" + resource_name + "\":" );
+
+ if ( new_resource_name.Length != 0 )
+ {
+ resourceSelectionControl.RenameResource( resource, new_resource_name );
+
+ FileSaved = false;
+ }
+ }
+
+ public void UpdateStatusBar( )
+ {
+ if ( parentStatusBar == null )
+ return;
+
+ parentStatusBar.Panels[ 0 ].Text = statusbar_file_name;
+ parentStatusBar.Panels[ 1 ].Text = " Resource items: " + number_resources.ToString( );
+ }
+
+ void ClearResources( )
+ {
+ if ( resourceList.Count > 0 )
+ resourceSelectionControl.ClearResources( );
+
+ resourceContentControl.ClearResources( );
+ resourceContentControl.ActivateTextPanel( );
+
+ fullFileName = "New Resource.resx";
+ statusbar_file_name = fullFileName;
+ number_resources = 0;
+ UpdateStatusBar( );
+ }
+
+ void WriteResourceFile( )
+ {
+ ResXResourceWriter rxrw = new ResXResourceWriter( fullFileName );
+
+ foreach ( IResource res_abstract in resourceList.Items )
+ {
+ switch ( res_abstract.ResourceType )
+ {
+ case ResourceType.TypeImage:
+ ResourceImage resImage = res_abstract as ResourceImage;
+
+ if ( resImage.Image == null )
+ continue;
+
+ rxrw.AddResource( resImage.ResourceName, resImage.Image );
+ break;
+
+ case ResourceType.TypeString:
+ ResourceString resStr = res_abstract as ResourceString;
+
+ if ( resStr == null )
+ continue;
+
+ rxrw.AddResource( resStr.ResourceName, resStr.Text );
+ break;
+
+ case ResourceType.TypeCursor:
+ ResourceCursor resCursor = res_abstract as ResourceCursor;
+
+ if ( resCursor == null )
+ continue;
+
+ rxrw.AddResource( resCursor.ResourceName, resCursor.Cursor );
+ break;
+
+ case ResourceType.TypeIcon:
+ ResourceIcon resIcon = res_abstract as ResourceIcon;
+
+ if ( resIcon == null )
+ continue;
+
+ rxrw.AddResource( resIcon.ResourceName, resIcon.Icon );
+ break;
+
+ case ResourceType.TypeColor:
+ ResourceColor resColor = res_abstract as ResourceColor;
+
+ if ( resColor == null )
+ continue;
+
+ rxrw.AddResource( resColor.ResourceName, resColor.Color );
+ break;
+
+ case ResourceType.TypeByteArray:
+ ResourceByteArray resByteArray = res_abstract as ResourceByteArray;
+
+ if ( resByteArray == null )
+ continue;
+
+ rxrw.AddResource( resByteArray.ResourceName, resByteArray.ByteArray );
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ rxrw.Close( );
+ }
+
+ void OnResourceListBoxSelectedIndexChanged( object sender, EventArgs e )
+ {
+ resourceContentControl.ClearActivePanel( );
+
+ IResource resource = resourceSelectionControl.SelectedResourceListBoxItem;
+
+ if ( resource == null )
+ return;
+
+ switch ( resource.ResourceType )
+ {
+ case ResourceType.TypeImage:
+ resourceContentControl.ActivateImagePanel( );
+
+ ResourceImage resImage = resource as ResourceImage;
+ resourceContentControl.ImagePanel.Image = resImage.Image;
+ break;
+
+ case ResourceType.TypeString:
+ resourceContentControl.ActivateTextPanel( );
+
+ ResourceString resString = resource as ResourceString;
+ resourceContentControl.TextPanel.ResourceText = resString.Text;
+ break;
+
+ case ResourceType.TypeCursor:
+ resourceContentControl.ActivateImagePanel( );
+
+ ResourceCursor resCursor = resource as ResourceCursor;
+ resourceContentControl.ImagePanel.Cursor = resCursor.Cursor;
+ break;
+
+ case ResourceType.TypeIcon:
+ resourceContentControl.ActivateImagePanel( );
+
+ ResourceIcon resIcon = resource as ResourceIcon;
+ resourceContentControl.ImagePanel.Icon = resIcon.Icon;
+ break;
+
+ case ResourceType.TypeColor:
+ resourceContentControl.ActivateColorPanel( );
+
+ ResourceColor resColor = (ResourceColor)resource;
+ resourceContentControl.ColorPanel.Color = resColor.Color;
+ break;
+
+ case ResourceType.TypeByteArray:
+ resourceContentControl.ActivateByteArrayPanel( );
+
+ ResourceByteArray resByteArray = (ResourceByteArray)resource;
+ resourceContentControl.ByteArrayPanel.ByteArray = resByteArray.ByteArray;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ public void ChangeResourceContent( object new_resource_value )
+ {
+ IResource oldRes = resourceSelectionControl.SelectedResourceListBoxItem;
+
+ if ( oldRes == null )
+ return;
+
+ IResource newRes = CreateNewResource( oldRes.ResourceName, new_resource_value );
+
+ resourceSelectionControl.ReplaceResource( oldRes, newRes );
+
+ FileSaved = false;
+ }
+
+ private IResource CreateNewResource( string name, object content )
+ {
+ Type new_type;
+
+ if ( content is Bitmap )
+ new_type = typeof( ResourceImage );
+ else
+ if ( content is String )
+ new_type = typeof( ResourceString );
+ else
+ if ( content is Icon )
+ new_type = typeof( ResourceIcon );
+ else
+ if ( content is Cursor )
+ new_type = typeof( ResourceCursor );
+ else
+ if ( content is Color )
+ new_type = typeof( ResourceColor );
+ else
+ new_type = typeof( ResourceByteArray );
+
+ IResource resource = Activator.CreateInstance( new_type, new object[] { name, content } ) as IResource;
+
+ return resource;
+ }
+ }
+}
View
5 MWFResourceEditor/ResourceCursor.cs
@@ -11,6 +11,7 @@ namespace MWFResourceEditor
public class ResourceCursor : ResourceBase, IResource
{
private Cursor cursor = null;
+ private Cursor old_cursor = null;
public ResourceCursor( string name, Cursor cursor )
{
@@ -28,10 +29,14 @@ public ResourceType ResourceType
public Cursor Cursor
{
set {
+ if ( old_cursor != null )
+ old_cursor.Dispose( );
+
if ( cursor != null )
all_data_for_rendering_available = 1;
cursor = value;
+ old_cursor = cursor;
all_data_for_rendering_available++;
View
197 MWFResourceEditor/ResourceIcon.cs
@@ -1,96 +1,101 @@
-// Authors:
-// Alexander Olk, <xenomorph2@onlinehome.de>
-
-using System;
-using System.Drawing;
-
-namespace MWFResourceEditor
-{
- public class ResourceIcon : ResourceBase, IResource
- {
- private Icon icon = null;
-
- public ResourceIcon( string name, Icon icon )
- {
- ResourceName = name;
- Icon = icon;
- }
-
- public ResourceType ResourceType
- {
- get {
- return ResourceType.TypeIcon;
- }
- }
-
- public Icon Icon
- {
- set {
- if ( icon != null )
- all_data_for_rendering_available = 1;
-
- icon = value;
-
- all_data_for_rendering_available++;
-
- if ( all_data_for_rendering_available == 2 )
- CreateRenderBitmap( );
- }
-
- get {
- return icon;
- }
- }
-
- public string ContentString( )
- {
- string imagesize = "Width = ";
-
- imagesize += icon.Width + ", Height = ";
- imagesize += icon.Height;
-
- return imagesize;
- }
-
- public Object Value
- {
- get {
- return icon;
- }
- }
-
- protected override void CreateRenderBitmap( )
- {
- using ( Graphics gr = CreateNewRenderBitmap( ) )
- {
- if ( icon.Width >= thumb_size.Width || icon.Height >= thumb_size.Height )
- {
- int new_width = icon.Width < thumb_size.Width - 1 ? icon.Width : thumb_size.Width - 1;
- int new_height = icon.Height < thumb_size.Height - 1 ? icon.Height : thumb_size.Height - 1;
-
- using ( Image thumbnail = GetThumbNail( icon.ToBitmap( ) , new_width, new_height ) )
- {
- int x = ( thumb_size.Width / 2 ) - ( thumbnail.Width / 2 ) - 1;
- int y = ( thumb_size.Height / 2 ) - ( thumbnail.Height / 2 );
-
- gr.DrawImage( thumbnail, thumb_location.X + x, thumb_location.Y + y );
- }
- }
- else
- {
- int x = ( thumb_size.Width / 2 ) - ( icon.Width / 2 );
- int y = ( thumb_size.Height / 2 ) - ( icon.Height / 2 );
-
- gr.DrawImage( icon.ToBitmap( ), thumb_location.X + x, thumb_location.Y + y );
- }
-
- gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
-
- gr.DrawString( "Type: " + icon.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
-
- gr.DrawString( "Size: " + ContentString( ), smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
- }
- }
- }
-}
-
+// Authors:
+// Alexander Olk, <xenomorph2@onlinehome.de>
+
+using System;
+using System.Drawing;
+
+namespace MWFResourceEditor
+{
+ public class ResourceIcon : ResourceBase, IResource
+ {
+ private Icon icon = null;
+ private Icon old_icon = null;
+
+ public ResourceIcon( string name, Icon icon )
+ {
+ ResourceName = name;
+ Icon = icon;
+ }
+
+ public ResourceType ResourceType
+ {
+ get {
+ return ResourceType.TypeIcon;
+ }
+ }
+
+ public Icon Icon
+ {
+ set {
+ if ( old_icon != null )
+ old_icon.Dispose( );
+
+ if ( icon != null )
+ all_data_for_rendering_available = 1;
+
+ icon = value;
+ old_icon = icon;
+
+ all_data_for_rendering_available++;
+
+ if ( all_data_for_rendering_available == 2 )
+ CreateRenderBitmap( );
+ }
+
+ get {
+ return icon;
+ }
+ }
+
+ public string ContentString( )
+ {
+ string imagesize = "Width = ";
+
+ imagesize += icon.Width + ", Height = ";
+ imagesize += icon.Height;
+
+ return imagesize;
+ }
+
+ public Object Value
+ {
+ get {
+ return icon;
+ }
+ }
+
+ protected override void CreateRenderBitmap( )
+ {
+ using ( Graphics gr = CreateNewRenderBitmap( ) )
+ {
+ if ( icon.Width >= thumb_size.Width || icon.Height >= thumb_size.Height )
+ {
+ int new_width = icon.Width < thumb_size.Width - 1 ? icon.Width : thumb_size.Width - 1;
+ int new_height = icon.Height < thumb_size.Height - 1 ? icon.Height : thumb_size.Height - 1;
+
+ using ( Image thumbnail = GetThumbNail( icon.ToBitmap( ) , new_width, new_height ) )
+ {
+ int x = ( thumb_size.Width / 2 ) - ( thumbnail.Width / 2 ) - 1;
+ int y = ( thumb_size.Height / 2 ) - ( thumbnail.Height / 2 );
+
+ gr.DrawImage( thumbnail, thumb_location.X + x, thumb_location.Y + y );
+ }
+ }
+ else
+ {
+ int x = ( thumb_size.Width / 2 ) - ( icon.Width / 2 );
+ int y = ( thumb_size.Height / 2 ) - ( icon.Height / 2 );
+
+ gr.DrawImage( icon.ToBitmap( ), thumb_location.X + x, thumb_location.Y + y );
+ }
+
+ gr.DrawString( "Name: " + resource_name, smallFont, solidBrushBlack, content_text_x_pos, content_name_y_pos );
+
+ gr.DrawString( "Type: " + icon.GetType( ), smallFont, solidBrushBlack, content_text_x_pos, content_type_y_pos );
+
+ gr.DrawString( "Size: " + ContentString( ), smallFont, solidBrushBlack, content_text_x_pos, content_content_y_pos );
+ }
+ }
+ }
+}
+
View
202 MWFResourceEditor/ResourceImage.cs
@@ -1,101 +1,101 @@
-// Authors:
-// Alexander Olk, <xenomorph2@onlinehome.de>
-
-using System;
-using System.Drawing;
-
-namespace MWFResourceEditor
-{
- public class ResourceImage : ResourceBase, IResource
- {
- private Image image = null;
- private Image old_image = null;
-
- public ResourceImage( string name, Image image )
- {
- ResourceName = name;
- Image = image;
- }
-
- public ResourceType ResourceType
- {
- get {
- return ResourceType.TypeImage;
- }
- }
-
- public Image Image
- {
- set {
- if ( old_image != null )
- old_image.Dispose( );