This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 50
/
NewPartDialog.cs
144 lines (120 loc) · 5.78 KB
/
NewPartDialog.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/****************************************************************************
NewPartDialog.cs
Dialog for creating a new part.
------------------------------------------------------------- LICENSE BEGINS HERE--------------------------------------------------------------------------------------
Copyright (c) Microsoft Corporation
All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions and limitations under the License.
-------------------------------------------------------------- LICENSE ENDS HERE -----------------------------------------------------------------------------------------
****************************************************************************/
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Microsoft.OpenXMLEditor
{
public partial class NewPartDialog : Form
{
public NewPartDialog(bool disableImport)
{
InitializeComponent();
this.comboBoxContentType.Items.Clear();
ContentTypeInfo[] types = KnownPackageInfo.GetContentTypes();
foreach (ContentTypeInfo cti in types)
{
this.comboBoxContentType.Items.Add(cti.m_mime);
}
if (disableImport)
{
this.labelImport.Enabled = false;
this.textBoxExternalFilename.Enabled = false;
this.buttonBrowse.Enabled = false;
}
}
public string ImportFile
{
get
{
return textBoxExternalFilename.Text;
}
}
public string PartName
{
get
{
return textBoxName.Text;
}
}
public string ContentType
{
get
{
return this.comboBoxContentType.Text;
}
}
public System.IO.Packaging.CompressionOption Compress
{
get
{
return (System.IO.Packaging.CompressionOption)this.comboBoxCompression.SelectedItem;
}
}
private void buttonBrowse_Click(object sender, EventArgs e)
{
ArrayList imageTypes = new ArrayList();
imageTypes.Add(new string[] { "*.jpg;*.jpeg", "JPEG File Interchange Format" });
imageTypes.Add(new string[] { "*.gif", "Graphics Interchange Format" });
imageTypes.Add(new string[] { "*.png", "Portable Network Graphics" });
imageTypes.Add(new string[] { "*.bmp", "Windows Bitmap" });
imageTypes.Add(new string[] { "*.ico", "Windows Icon" });
imageTypes.Add(new string[] { "*.emf", "Windows Enhanced Metafile" });
imageTypes.Add(new string[] { "*.wmf", "Windows Metafile" });
imageTypes.Add(new string[] { "*.emz", "Compressed Windows Enhanced Metafile" });
imageTypes.Add(new string[] { "*.wmz", "Compressed Windows Metafile" });
imageTypes.Add(new string[] { "*.pcz", "Compressed Macintosh PICT" });
imageTypes.Add(new string[] { "*.tif;*.tiff", "Tag Image File Format" });
imageTypes.Add(new string[] { "*.xbm", "X Bitmap Graphic" });
imageTypes.Add(new string[] { "*.pcx", "PC Paintbrush Bitmap Graphic" });
string filter = "", allFilters = "";
foreach (string[] imageType in imageTypes)
{
if (filter.Length > 0)
filter += "|";
filter += imageType[1] + " (" + imageType[0] + ")|" + imageType[0];
if (allFilters.Length > 0)
allFilters += ";";
allFilters += imageType[0];
}
openFileDialog.Filter = "All Files (*.*)|*.*|All Pictures (" + allFilters + ")|" + allFilters + "|" + filter;
openFileDialog.FilterIndex = 2;
if (openFileDialog.ShowDialog(this) != DialogResult.OK || string.IsNullOrEmpty(openFileDialog.FileName))
return;
textBoxExternalFilename.Text = openFileDialog.FileName;
textBoxName.Text = System.IO.Path.GetFileName(textBoxExternalFilename.Text).ToLower();
string ext = System.IO.Path.GetExtension(textBoxName.Text);
if (ext == ".jpg")
ext = ".jpeg";
else if (ext == ".tif")
ext = ".tiff";
List<ContentTypeInfo> contentTypes = KnownPackageInfo.GetContentTypesForExt(ext);
if (contentTypes != null && contentTypes.Count > 0)
{
comboBoxContentType.Text = contentTypes[0].m_mime;
comboBoxCompression.SelectedItem = contentTypes[0].m_comp == Comp.CD ? System.IO.Packaging.CompressionOption.SuperFast : System.IO.Packaging.CompressionOption.NotCompressed;
}
}
private void NewPartDialog_Load(object sender, EventArgs e)
{
Array names = System.Enum.GetValues(typeof(System.IO.Packaging.CompressionOption));
foreach (System.IO.Packaging.CompressionOption name in names)
comboBoxCompression.Items.Add(name);
comboBoxCompression.SelectedItem = System.IO.Packaging.CompressionOption.SuperFast;
}
}
}