* ImageList.cs: When the image stream is set pull all the images
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / FileDialog.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //
24 //  Alexander Olk       xenomorph2@onlinehome.de
25 //
26
27 // NOT COMPLETE - work in progress
28
29 using System;
30 using System.Drawing;
31 using System.ComponentModel;
32 using System.Resources;
33 using System.IO;
34 using System.Collections;
35 using System.Collections.Specialized;
36
37 namespace System.Windows.Forms
38 {
39         public abstract class FileDialog : CommonDialog
40         {
41                 internal FileDialogPanel fileDialogPanel;
42                 
43                 private bool addExtension = true;
44                 private bool checkFileExists = false;
45                 private bool checkPathExists = true;
46                 private string defaultExt = "";
47                 private bool dereferenceLinks = true;
48                 private string fileName = "";
49                 private string[] fileNames;
50                 private string filter;
51                 private int filterIndex = 1;
52                 private string initialDirectory = "";
53                 private bool restoreDirectory = false;
54                 private bool showHelp = false;
55                 private string title = "";
56                 private bool validateNames = true;
57                 
58                 internal string openSaveButtonText;
59                 internal string searchSaveLabelText;
60                 internal bool fileDialogShowReadOnly;
61                 
62                 public bool AddExtension
63                 {
64                         get
65                         {
66                                 return addExtension;
67                         }
68                         
69                         set
70                         {
71                                 addExtension = value;
72                         }
73                 }
74                 
75                 public virtual bool CheckFileExists
76                 {
77                         get
78                         {
79                                 return checkFileExists;
80                         }
81                         
82                         set
83                         {
84                                 checkFileExists = value;
85                         }
86                 }
87                 
88                 public bool CheckPathExists
89                 {
90                         get
91                         {
92                                 return checkPathExists;
93                         }
94                         
95                         set
96                         {
97                                 checkPathExists = value;
98                         }
99                 }
100                 
101                 public string DefaultExt
102                 {
103                         get
104                         {
105                                 return defaultExt;
106                         }
107                         
108                         set
109                         {
110                                 defaultExt = value;
111                         }
112                 }
113                 
114                 public bool DereferenceLinks
115                 {
116                         get
117                         {
118                                 return dereferenceLinks;
119                         }
120                         
121                         set
122                         {
123                                 dereferenceLinks = value;
124                         }
125                 }
126                 
127                 public string FileName
128                 {
129                         get
130                         {
131                                 return fileName;
132                         }
133                         
134                         set
135                         {
136                                 fileName = value;
137                         }
138                 }
139                 
140                 public string[] FileNames
141                 {
142                         get
143                         {
144                                 return fileNames;
145                         }
146                 }
147                 
148                 public string Filter
149                 {
150                         get
151                         {
152                                 return filter;
153                         }
154                         
155                         set
156                         {
157                                 if ( value == null )
158                                         throw new NullReferenceException( "Filter" );
159                                 
160                                 filter = value;
161                                 
162                                 SplitFilter( );
163                                 
164                                 fileDialogPanel.UpdateFilters( filterArrayList );
165                         }
166                 }
167                 
168                 public int FilterIndex
169                 {
170                         get
171                         {
172                                 return filterIndex;
173                         }
174                         
175                         set
176                         {
177                                 filterIndex = value;
178                         }
179                 }
180                 
181                 public string InitialDirectory
182                 {
183                         get
184                         {
185                                 return initialDirectory;
186                         }
187                         
188                         set
189                         {
190                                 initialDirectory = value;
191                         }
192                 }
193                 
194                 public bool RestoreDirectory
195                 {
196                         get
197                         {
198                                 return restoreDirectory;
199                         }
200                         
201                         set
202                         {
203                                 restoreDirectory = value;
204                         }
205                 }
206                 
207                 public bool ShowHelp
208                 {
209                         get
210                         {
211                                 return showHelp;
212                         }
213                         
214                         set
215                         {
216                                 showHelp = value;
217                                 fileDialogPanel.ResizeAndRelocateForHelpOrReadOnly( );
218                         }
219                 }
220                 
221                 public string Title
222                 {
223                         get
224                         {
225                                 return title;
226                         }
227                         
228                         set
229                         {
230                                 title = value;
231                                 
232                                 form.Text = title;
233                         }
234                 }
235                 
236                 public bool ValidateNames
237                 {
238                         get
239                         {
240                                 return validateNames;
241                         }
242                         
243                         set
244                         {
245                                 validateNames = value;
246                         }
247                 }
248                 
249                 internal string OpenSaveButtonText
250                 {
251                         set
252                         {
253                                 openSaveButtonText = value;
254                         }
255                         
256                         get
257                         {
258                                 return openSaveButtonText;
259                         }
260                 }
261                 
262                 public string SearchSaveLabelText
263                 {
264                         set
265                         {
266                                 searchSaveLabelText = value;
267                         }
268                         
269                         get
270                         {
271                                 return searchSaveLabelText;
272                         }
273                 }
274                 
275                 public bool FileDialogShowReadOnly
276                 {
277                         set
278                         {
279                                 fileDialogShowReadOnly = value;
280                         }
281                         
282                         get
283                         {
284                                 return fileDialogShowReadOnly;
285                         }
286                 }
287                 
288                 public override void Reset( )
289                 {
290                         addExtension = true;
291                         checkFileExists = false;
292                         checkPathExists = true;
293                         defaultExt = "";
294                         dereferenceLinks = true;
295                         fileName = "";
296                         fileNames = null;
297                         filter = "";
298                         filterIndex = 1;
299                         initialDirectory = "";
300                         restoreDirectory = false;
301                         showHelp = false;
302                         title = "";
303                         validateNames = true;
304                 }
305                 
306                 public override string ToString( )
307                 {
308                         return base.ToString( );
309                 }
310                 
311                 public event CancelEventHandler FileOk;
312                 
313                 protected  override IntPtr HookProc( IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam )
314                 {
315                         throw new NotImplementedException( );
316                 }
317                 
318                 protected void OnFileOk( CancelEventArgs e )
319                 {
320                         if ( FileOk != null ) FileOk( this, e );
321                 }
322                 
323                 [MonoTODO]
324                 protected  override bool RunDialog( IntPtr hWndOwner )
325                 {
326                         form.Controls.Add( fileDialogPanel );
327                         
328                         return true;
329                 }
330                 
331                 private void SplitFilter( )
332                 {
333                         filterArrayList.Clear( );
334                         
335                         if ( filter == null )
336                                 throw new NullReferenceException( "Filter" );
337                         
338                         // FIXME: default, MS default is nothing, nada...
339                         if ( filter.Length == 0 )
340                                 filter = "All Files (*.*)|*.*";
341                         
342                         string[] filters = filter.Split( new Char[] {'|'} );
343                         
344                         if ( ( filters.Length % 2 ) != 0 )
345                                 throw new ArgumentException( "Filter" );
346                         
347                         for ( int i = 0; i < filters.Length; i += 2 )
348                         {
349                                 FilterStruct filterStruct = new FilterStruct( filters[ i ], filters[ i + 1 ] );
350                                 
351                                 filterArrayList.Add( filterStruct );
352                         }
353                         
354 //                      if ( filterAL.Count > 1 )
355 //                              filterAL.Sort();
356                 }
357                 
358                 internal void SendHelpRequest( EventArgs e )
359                 {
360                         OnHelpRequest( e );
361                 }
362                 
363                 internal struct FilterStruct
364                 {
365                         public string filterName;
366                         public StringCollection filters;
367                         
368                         public FilterStruct( string filterName, string filter )
369                         {
370                                 this.filterName = filterName;
371                                 
372                                 filters =  new StringCollection( );
373                                 
374                                 SplitFilters( filter );
375                         }
376                         
377                         private void SplitFilters( string filter )
378                         {
379                                 string[] split = filter.Split( new Char[] {';'} );
380                                 
381                                 filters.AddRange( split );
382                         }
383                 }
384                 
385                 internal ArrayList filterArrayList = new ArrayList();
386                 
387                 internal class FileDialogPanel : Panel
388                 {
389                         internal struct FileStruct
390                         {
391                                 public FileStruct( string fullname, FileAttributes attributes )
392                                 {
393                                         this.fullname = fullname;
394                                         this.attributes = attributes;
395                                 }
396                                 
397                                 public string fullname;
398                                 public FileAttributes attributes;
399                         }
400                         
401                         private Button cancelButton;
402                         private ToolBarButton upToolBarButton;
403 //                      private ToolBar bigButtonToolBar;
404                         private ButtonPanel buttonPanel;
405                         private Button openSaveButton;
406                         private Button helpButton;
407                         private Label fileTypeLabel;
408                         private ToolBarButton menueToolBarButton;
409                         private ContextMenu menueToolBarButtonContextMenu;
410                         private ToolBarButton desktopToolBarButton;
411                         private ToolBar smallButtonToolBar;
412                         private ComboBox dirComboBox;
413                         private ToolBarButton lastUsedToolBarButton;
414                         private ComboBox fileNameComboBox;
415                         private ToolBarButton networkToolBarButton;
416                         private Label fileNameLabel;
417                         private FileListView fileListView;
418                         private Label searchSaveLabel;
419                         private ToolBarButton newdirToolBarButton;
420                         private ToolBarButton backToolBarButton;
421                         private ToolBarButton homeToolBarButton;
422                         private ToolBarButton workplaceToolBarButton;
423                         private ComboBox fileTypeComboBox;
424 //                      private ImageList imageListLeftToolbar;
425                         private ImageList imageListTopToolbar;
426                         
427                         private FileDialog fileDialog;
428                         
429                         private string currentDirectoryName;
430                         
431                         // store current directoryInfo
432                         private DirectoryInfo directoryInfo;
433                         
434                         // store the FileStruct of all files in the current directory
435                         internal Hashtable fileHashtable = new Hashtable();
436                         
437                         // store DirectoryInfo for backButton
438                         internal Stack directoryStack = new Stack();
439                         
440                         internal string currentFileName = "";
441                         
442                         private MenuItem previousCheckedMenuItem;
443                         
444                         public FileDialogPanel( FileDialog fileDialog )
445                         {
446                                 this.fileDialog = fileDialog;
447                                 
448                                 fileTypeComboBox = new ComboBox( );
449                                 workplaceToolBarButton = new ToolBarButton( );
450                                 homeToolBarButton = new ToolBarButton( );
451                                 backToolBarButton = new ToolBarButton( );
452                                 newdirToolBarButton = new ToolBarButton( );
453                                 searchSaveLabel = new Label( );
454                                 fileListView = new FileListView( this );
455                                 fileNameLabel = new Label( );
456                                 networkToolBarButton = new ToolBarButton( );
457                                 fileNameComboBox = new ComboBox( );
458                                 lastUsedToolBarButton = new ToolBarButton( );
459                                 dirComboBox = new ComboBox( );
460                                 smallButtonToolBar = new ToolBar( );
461                                 desktopToolBarButton = new ToolBarButton( );
462                                 menueToolBarButton = new ToolBarButton( );
463                                 fileTypeLabel = new Label( );
464                                 openSaveButton = new Button( );
465                                 fileDialog.form.AcceptButton = openSaveButton;
466                                 helpButton = new Button( );
467 //                              bigButtonToolBar = new ToolBar( );
468                                 buttonPanel = new ButtonPanel( this );
469                                 upToolBarButton = new ToolBarButton( );
470                                 cancelButton = new Button( );
471                                 fileDialog.form.CancelButton = cancelButton;
472                                 imageListTopToolbar = new ImageList( );
473 //                              imageListLeftToolbar = new ImageList( );
474                                 menueToolBarButtonContextMenu = new ContextMenu( );
475                                 
476                                 SuspendLayout( );
477                                 
478                                 // imageListLeftToolbar
479 //                              imageListLeftToolbar.ColorDepth = ColorDepth.Depth32Bit;
480 //                              imageListLeftToolbar.ImageSize = new Size( 48, 48 );
481 //                              imageListLeftToolbar.Images.Add( (Image)Locale.GetResource( "last_open" ) );
482 //                              imageListLeftToolbar.Images.Add( (Image)Locale.GetResource( "desktop" ) );
483 //                              imageListLeftToolbar.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
484 //                              imageListLeftToolbar.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
485 //                              imageListLeftToolbar.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
486 //                              imageListLeftToolbar.TransparentColor = Color.Transparent;
487                                 
488                                 //imageListTopToolbar
489                                 imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
490                                 imageListTopToolbar.ImageSize = new Size( 16, 16 ); // 16, 16
491                                 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "back_arrow" ) );
492                                 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_arrow_up" ) );
493                                 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_star" ) );
494                                 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "window" ) );
495                                 imageListTopToolbar.TransparentColor = Color.Transparent;
496                                 
497                                 // searchLabel
498                                 searchSaveLabel.FlatStyle = FlatStyle.System;
499                                 searchSaveLabel.Location = new Point( 7, 8 );
500                                 searchSaveLabel.Size = new Size( 72, 21 );
501                                 searchSaveLabel.TabIndex = 0;
502                                 searchSaveLabel.Text = fileDialog.SearchSaveLabelText;
503                                 searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
504                                 
505                                 // dirComboBox
506                                 dirComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Top | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
507                                 dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
508                                 dirComboBox.Location = new Point( 99, 8 );
509                                 dirComboBox.Size = new Size( 260, 21 );
510                                 dirComboBox.TabIndex = 1;
511                                 
512                                 // fileListView
513                                 fileListView.Anchor = ( (AnchorStyles)( ( ( ( AnchorStyles.Top | AnchorStyles.Bottom ) | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
514                                 fileListView.Location = new Point( 99, 37 );
515                                 fileListView.Size = new Size( 449, 282 );
516                                 fileListView.Columns.Add( " Name", 170, HorizontalAlignment.Left );
517                                 fileListView.Columns.Add( "Size ", 80, HorizontalAlignment.Right );
518                                 fileListView.Columns.Add( " Type", 100, HorizontalAlignment.Left );
519                                 fileListView.Columns.Add( " Last Access", 150, HorizontalAlignment.Left );
520                                 fileListView.AllowColumnReorder = true;
521                                 fileListView.TabIndex = 2;
522                                 
523                                 // fileNameLabel
524                                 fileNameLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
525                                 fileNameLabel.FlatStyle = FlatStyle.System;
526                                 fileNameLabel.Location = new Point( 102, 330 );
527                                 fileNameLabel.Size = new Size( 70, 21 );
528                                 fileNameLabel.TabIndex = 6;
529                                 fileNameLabel.Text = "Filename:";
530                                 fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
531                                 
532                                 // fileNameComboBox
533                                 fileNameComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
534                                 fileNameComboBox.Location = new Point( 195, 330 );
535                                 fileNameComboBox.Size = new Size( 245, 21 );
536                                 fileNameComboBox.TabIndex = 4;
537                                 
538                                 // fileTypeLabel
539                                 fileTypeLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
540                                 fileTypeLabel.FlatStyle = FlatStyle.System;
541                                 fileTypeLabel.Location = new Point( 102, 356 );
542                                 fileTypeLabel.Size = new Size( 70, 21 );
543                                 fileTypeLabel.TabIndex = 5;
544                                 fileTypeLabel.Text = "Filetype:";
545                                 fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
546                                 
547                                 // fileTypeComboBox
548                                 fileTypeComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
549                                 fileTypeComboBox.Location = new Point( 195, 356 );
550                                 fileTypeComboBox.Size = new Size( 245, 21 );
551                                 fileTypeComboBox.TabIndex = 6;
552                                 
553                                 // smallButtonToolBar
554                                 smallButtonToolBar.Anchor = ( (AnchorStyles)( ( AnchorStyles.Top | AnchorStyles.Right ) ) );
555                                 smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
556                                 smallButtonToolBar.AutoSize = false;
557                                 smallButtonToolBar.Buttons.AddRange( new ToolBarButton[] {
558                                                                                                                 backToolBarButton,
559                                                                                                                 upToolBarButton,
560                                                                                                                 newdirToolBarButton,
561                                                                                                                 menueToolBarButton} );
562                                 smallButtonToolBar.ButtonSize = new Size( 21, 16 ); // 21, 16
563                                 smallButtonToolBar.Divider = false;
564                                 smallButtonToolBar.Dock = DockStyle.None;
565                                 smallButtonToolBar.DropDownArrows = true;
566                                 smallButtonToolBar.ImageList = imageListTopToolbar;
567                                 smallButtonToolBar.Location = new Point( 372, 8 );
568                                 smallButtonToolBar.ShowToolTips = true;
569                                 smallButtonToolBar.Size = new Size( 110, 20 );
570                                 smallButtonToolBar.TabIndex = 10;
571                                 smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
572                                 
573                                 // backToolBarButton
574                                 backToolBarButton.ImageIndex = 0;
575                                 backToolBarButton.Enabled = false;
576                                 backToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
577                                 
578                                 // upToolBarButton
579                                 upToolBarButton.ImageIndex = 1;
580                                 upToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
581                                 
582                                 // newdirToolBarButton
583                                 newdirToolBarButton.ImageIndex = 2;
584                                 newdirToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
585                                 
586                                 // menueToolBarButton
587                                 menueToolBarButton.ImageIndex = 3;
588                                 menueToolBarButton.DropDownMenu = menueToolBarButtonContextMenu;
589                                 menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
590                                 
591 //                              // bigButtonToolBar
592 //                              bigButtonToolBar.Appearance = ToolBarAppearance.Flat;
593 //                              bigButtonToolBar.AutoSize = false;
594 //                              bigButtonToolBar.Buttons.AddRange( new ToolBarButton[] {
595 //                                                                                                        lastUsedToolBarButton,
596 //                                                                                                        desktopToolBarButton,
597 //                                                                                                        homeToolBarButton,
598 //                                                                                                        workplaceToolBarButton,
599 //                                                                                                        networkToolBarButton} );
600 //                              bigButtonToolBar.ButtonSize = new Size( 82, 68 );
601 //                              bigButtonToolBar.Dock = DockStyle.None;
602 //                              bigButtonToolBar.Location = new Point( 7, 37 );
603 //                              bigButtonToolBar.ShowToolTips = true;
604 //                              bigButtonToolBar.Size = new Size( 85, 412 ); // 85, 412
605 //                              bigButtonToolBar.ImageList = imageListLeftToolbar;
606 //                              bigButtonToolBar.BackColor = Color.FromArgb( 128, 128, 128 );
607 //                              bigButtonToolBar.TabIndex = 3;
608                                 
609                                 buttonPanel.Dock = DockStyle.None;
610                                 buttonPanel.Location = new Point( 7, 37 );
611                                 buttonPanel.TabIndex = 3;
612                                 
613                                 // lastUsedToolBarButton
614 //                              lastUsedToolBarButton.ImageIndex = 0;
615 //                              lastUsedToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
616 //                              lastUsedToolBarButton.Text = "Last files";
617                                 
618                                 // desktopToolBarButton
619 //                              desktopToolBarButton.ImageIndex = 1;
620 //                              desktopToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
621 //                              desktopToolBarButton.Text = "Desktop";
622                                 
623                                 // homeToolBarButton
624 //                              homeToolBarButton.ImageIndex = 2;
625 //                              homeToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
626 //                              homeToolBarButton.Text = "Home";
627                                 
628                                 // workplaceToolBarButton
629 //                              workplaceToolBarButton.ImageIndex = 3;
630 //                              workplaceToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
631 //                              workplaceToolBarButton.Text = "Workplace";
632                                 
633                                 // networkToolBarButton
634 //                              networkToolBarButton.ImageIndex = 4;
635 //                              networkToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
636 //                              networkToolBarButton.Text = "Network";
637                                 
638                                 // menueToolBarButtonContextMenu
639                                 MenuItem mi = new MenuItem( "Small Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
640                                 menueToolBarButtonContextMenu.MenuItems.Add( mi );
641                                 mi = new MenuItem( "Tiles", new EventHandler( OnClickMenuToolBarContextMenu ) );
642                                 menueToolBarButtonContextMenu.MenuItems.Add( mi );
643                                 mi = new MenuItem( "Large Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
644                                 menueToolBarButtonContextMenu.MenuItems.Add( mi );
645                                 mi = new MenuItem( "List", new EventHandler( OnClickMenuToolBarContextMenu ) );
646                                 mi.Checked = true;
647                                 previousCheckedMenuItem = mi;
648                                 menueToolBarButtonContextMenu.MenuItems.Add( mi );
649                                 mi = new MenuItem( "Details", new EventHandler( OnClickMenuToolBarContextMenu ) );
650                                 menueToolBarButtonContextMenu.MenuItems.Add( mi );
651                                 
652                                 // openButton
653                                 openSaveButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
654                                 openSaveButton.FlatStyle = FlatStyle.System;
655                                 openSaveButton.Location = new Point( 475, 330 );
656                                 openSaveButton.Size = new Size( 72, 21 );
657                                 openSaveButton.TabIndex = 8;
658                                 openSaveButton.Text = fileDialog.OpenSaveButtonText;
659                                 
660                                 // cancelButton
661                                 cancelButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
662                                 cancelButton.FlatStyle = FlatStyle.System;
663                                 cancelButton.Location = new Point( 475, 356 );
664                                 cancelButton.Size = new Size( 72, 21 );
665                                 cancelButton.TabIndex = 9;
666                                 cancelButton.Text = "Cancel";
667                                 
668                                 // helpButton
669                                 helpButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
670                                 helpButton.FlatStyle = FlatStyle.System;
671                                 helpButton.Location = new Point( 475, 350 );
672                                 helpButton.Size = new Size( 72, 21 );
673                                 helpButton.TabIndex = 10;
674                                 helpButton.Text = "Help";
675                                 helpButton.Hide( );
676                                 
677                                 ClientSize = new Size( 554, 405 ); // 384
678                                 
679                                 Controls.Add( smallButtonToolBar );
680                                 Controls.Add( cancelButton );
681                                 Controls.Add( openSaveButton );
682                                 Controls.Add( helpButton );
683                                 Controls.Add( fileTypeLabel );
684                                 Controls.Add( fileNameLabel );
685                                 Controls.Add( fileTypeComboBox );
686                                 Controls.Add( fileNameComboBox );
687                                 Controls.Add( dirComboBox );
688                                 Controls.Add( searchSaveLabel );
689                                 Controls.Add( fileListView );
690 //                              Controls.Add( bigButtonToolBar );
691                                 Controls.Add( buttonPanel );
692                                 
693                                 ResumeLayout( false );
694                                 
695                                 if ( fileDialog.InitialDirectory == String.Empty )
696                                         currentDirectoryName = Environment.CurrentDirectory;
697                                 
698                                 directoryInfo = new DirectoryInfo( currentDirectoryName );
699                                 
700                                 fileListView.UpdateFileListView( );
701                                 
702                                 openSaveButton.Click += new EventHandler( OnClickOpenButton );
703                                 cancelButton.Click += new EventHandler( OnClickCancelButton );
704                                 helpButton.Click += new EventHandler( OnClickHelpButton );
705                                 
706                                 smallButtonToolBar.ButtonClick += new ToolBarButtonClickEventHandler( OnClickSmallButtonToolBar );
707                                 
708                                 // Key events DONT'T work
709                                 fileNameComboBox.KeyUp += new KeyEventHandler( OnKeyUpFileNameComboBox );
710                                 
711                                 // FIXME: Default for Filter is "", aka nothing, nada...
712                                 // which means, show all files
713                                 FilterStruct fs = new FilterStruct( "All Files (*.*)", "*.*" ); // set default filter;
714                                 
715                                 fileDialog.filterArrayList.Add( fs );
716                                 
717                                 UpdateFilters( fileDialog.filterArrayList );
718                         }
719                         
720                         public ComboBox FileNameComboBox
721                         {
722                                 set
723                                 {
724                                         fileNameComboBox = value;
725                                 }
726                                 
727                                 get
728                                 {
729                                         return fileNameComboBox;
730                                 }
731                         }
732                         
733                         public string CurrentFileName
734                         {
735                                 set
736                                 {
737                                         currentFileName = value;
738                                 }
739                                 
740                                 get
741                                 {
742                                         return currentFileName;
743                                 }
744                         }
745                         
746                         public DirectoryInfo DirectoryInfo
747                         {
748                                 set
749                                 {
750                                         directoryInfo = value;
751                                 }
752                                 
753                                 get
754                                 {
755                                         return directoryInfo;
756                                 }
757                         }
758                         
759                         void OnClickOpenButton( object sender, EventArgs e )
760                         {
761                                 currentFileName = Path.Combine(currentDirectoryName, fileNameComboBox.Text.Trim());
762                                 Console.WriteLine( "OnClickOpenButton currentFileName: " + currentFileName );
763                                 
764                                 if ( currentFileName.Length == 0 )
765                                         return;
766                                 
767                                 if ( fileDialog.CheckFileExists )
768                                 {
769                                         if ( !File.Exists( currentFileName ) )
770                                         {
771                                                 string message = currentFileName + " doesn't exist. Please verify that you have entered the correct file name.";
772                                                 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
773                                                 
774                                                 currentFileName = "";
775                                                 
776                                                 return;
777                                         }
778                                 }
779                                 
780                                 if ( fileDialog.CheckPathExists )
781                                 {
782                                         if ( !Directory.Exists( currentDirectoryName ) )
783                                         {
784                                                 string message = currentDirectoryName + " doesn't exist. Please verify that you have entered the correct directory name.";
785                                                 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
786                                                 
787                                                 currentDirectoryName = Environment.CurrentDirectory;
788                                                 
789                                                 return;
790                                         }
791                                 }
792                                 
793                                 fileDialog.FileName = currentFileName;
794                                 
795                                 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
796                                 
797                                 cancelEventArgs.Cancel = false;
798                                 
799                                 fileDialog.OnFileOk( cancelEventArgs );
800                                 
801                                 fileDialog.form.Controls.Remove( this );
802                                 fileDialog.form.DialogResult = DialogResult.OK;
803                         }
804                         
805                         void OnClickCancelButton( object sender, EventArgs e )
806                         {
807                                 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
808                                 
809                                 cancelEventArgs.Cancel = true;
810                                 
811                                 fileDialog.OnFileOk( cancelEventArgs );
812                                 
813                                 fileDialog.form.Controls.Remove( this );
814                                 fileDialog.form.DialogResult = DialogResult.Cancel;
815                         }
816                         
817                         void OnClickHelpButton( object sender, EventArgs e )
818                         {
819                                 fileDialog.SendHelpRequest( e );
820                         }
821                         
822                         void OnClickSmallButtonToolBar( object sender, ToolBarButtonClickEventArgs e )
823                         {
824                                 if ( e.Button == upToolBarButton )
825                                 {
826                                         if ( directoryInfo.Parent != null )
827                                         {
828                                                 PushDirectory( directoryInfo );
829                                                 
830                                                 directoryInfo = directoryInfo.Parent;
831                                                 
832                                                 currentDirectoryName = directoryInfo.FullName;
833                                                 
834                                                 fileListView.UpdateFileListView( );
835                                         }
836                                 }
837                                 else
838                                 if ( e.Button == backToolBarButton )
839                                 {
840                                         if ( directoryStack.Count != 0 )
841                                         {
842                                                 PopDirectory( );
843                                                 
844                                                 fileListView.UpdateFileListView( );
845                                         }
846                                 }
847                         }
848                         
849                         void OnClickMenuToolBarContextMenu( object sender, EventArgs e )
850                         {
851                                 MenuItem senderMenuItem = (MenuItem)sender;
852                                 
853                                 previousCheckedMenuItem.Checked = false;
854                                 senderMenuItem.Checked = true;
855                                 previousCheckedMenuItem = senderMenuItem;
856                                 
857                                 // FIXME...
858                                 
859                                 switch ( senderMenuItem.Index  )
860                                 {
861                                         case 0:
862                                                 fileListView.View = View.SmallIcon;
863                                                 break;
864                                         case 1:
865                                                 fileListView.View = View.LargeIcon;
866                                                 break;
867                                         case 2:
868                                                 fileListView.View = View.LargeIcon;
869                                                 break;
870                                         case 3:
871                                                 fileListView.View = View.List;
872                                                 break;
873                                         case 4:
874                                                 fileListView.View = View.Details;
875                                                 break;
876                                         default:
877                                                 break;
878                                 }
879                                 
880                         }
881                         
882                         void OnKeyUpFileNameComboBox( object sender, KeyEventArgs e )
883                         {
884                                 Console.WriteLine( "OnKeyUpFileNameComboBox" );
885                                 
886                                 if ( e.KeyCode == Keys.Enter )
887                                 {
888                                         Console.WriteLine( "OnKeyUpFileNameComboBox e.KeyCode =..." );
889                                         currentFileName = currentDirectoryName + fileNameComboBox.Text;
890                                         ForceDialogEnd( );
891                                 }
892                         }
893                         
894                         public void UpdateFilters( ArrayList filters )
895                         {
896                                 fileTypeComboBox.Items.Clear( );
897                                 
898                                 fileTypeComboBox.BeginUpdate( );
899                                 
900                                 foreach ( FilterStruct fs in filters )
901                                 {
902                                         fileTypeComboBox.Items.Add( fs.filterName );
903                                 }
904                                 
905                                 fileTypeComboBox.SelectedIndex = fileDialog.FilterIndex - 1;
906                                 
907                                 fileTypeComboBox.EndUpdate( );
908                                 
909                                 // TODO: Update the fileListView also...
910                         }
911                         
912                         public void ChangeDirectory( string path )
913                         {
914                                 currentDirectoryName = path;
915                                 
916                                 PushDirectory( directoryInfo );
917                                 
918                                 directoryInfo = new DirectoryInfo( path );
919                                 
920                                 fileListView.UpdateFileListView( );
921                         }
922                         
923                         public void ForceDialogEnd( )
924                         {
925                                 OnClickOpenButton( this, EventArgs.Empty );
926                         }
927                         
928                         private void PushDirectory( DirectoryInfo di )
929                         {
930                                 directoryStack.Push( directoryInfo );
931                                 backToolBarButton.Enabled = true;
932                         }
933                         
934                         private void PopDirectory( )
935                         {
936                                 directoryInfo = (DirectoryInfo)directoryStack.Pop( );
937                                 
938                                 currentDirectoryName = directoryInfo.FullName;
939                                 
940                                 if ( directoryStack.Count == 0 )
941                                         backToolBarButton.Enabled = false;
942                         }
943                         
944                         public void ResizeAndRelocateForHelpOrReadOnly( )
945                         {
946                                 if ( fileDialog.ShowHelp || fileDialog.FileDialogShowReadOnly )
947                                 {
948                                         fileListView.Size = new Size( 449, 250 );
949                                         fileNameLabel.Location = new Point( 102, 298 );
950                                         fileNameComboBox.Location = new Point( 195, 298 );
951                                         fileTypeLabel.Location = new Point( 102, 324 );
952                                         fileTypeComboBox.Location = new Point( 195, 324 );
953                                         openSaveButton.Location = new Point( 475, 298 );
954                                         cancelButton.Location = new Point( 475, 324 );
955                                 }
956                                 else
957                                 {
958                                         fileListView.Size = new Size( 449, 282 );
959                                         fileNameLabel.Location = new Point( 102, 330 );
960                                         fileNameComboBox.Location = new Point( 195, 330 );
961                                         fileTypeLabel.Location = new Point( 102, 356 );
962                                         fileTypeComboBox.Location = new Point( 195, 356 );
963                                         openSaveButton.Location = new Point( 475, 330 );
964                                         cancelButton.Location = new Point( 475, 356 );
965                                 }
966                                 
967                                 if ( fileDialog.ShowHelp )
968                                         helpButton.Show( );
969                         }
970                         
971                         // FileListView
972                         internal class FileListView : ListView
973                         {
974                                 private ImageList fileListViewSmallImageList = new ImageList();
975                                 private ImageList fileListViewBigImageList = new ImageList();
976                                 
977                                 private FileDialogPanel fileDialogPanel;
978                                 
979                                 public FileListView( FileDialogPanel fileDialogPanel )
980                                 {
981                                         this.fileDialogPanel = fileDialogPanel;
982                                         
983                                         fileListViewSmallImageList.ColorDepth = ColorDepth.Depth32Bit;
984                                         fileListViewSmallImageList.ImageSize = new Size( 16, 16 );
985                                         fileListViewSmallImageList.Images.Add( (Image)Locale.GetResource( "paper" ) );
986                                         fileListViewSmallImageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
987                                         fileListViewSmallImageList.TransparentColor = Color.Transparent;
988                                         
989                                         fileListViewBigImageList.ColorDepth = ColorDepth.Depth32Bit;
990                                         fileListViewBigImageList.ImageSize = new Size( 48, 48 );
991                                         fileListViewBigImageList.Images.Add( (Image)Locale.GetResource( "paper" ) );
992                                         fileListViewBigImageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
993                                         fileListViewBigImageList.TransparentColor = Color.Transparent;
994                                         
995                                         SmallImageList = fileListViewSmallImageList;
996                                         LargeImageList = fileListViewBigImageList;
997                                         
998                                         View = View.List;
999                                 }
1000                                 
1001                                 public void UpdateFileListView( )
1002                                 {
1003                                         DirectoryInfo directoryInfo = fileDialogPanel.DirectoryInfo;
1004                                         
1005                                         DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories( );
1006                                         FileInfo[] fileInfoArray = directoryInfo.GetFiles( );
1007                                         
1008                                         fileDialogPanel.fileHashtable.Clear( );
1009                                         
1010                                         BeginUpdate( );
1011                                         
1012                                         Items.Clear( );
1013                                         
1014                                         foreach ( DirectoryInfo directoryInfoi in directoryInfoArray )
1015                                         {
1016                                                 FileStruct fileStruct = new FileStruct( );
1017                                                 
1018                                                 fileStruct.fullname = directoryInfoi.FullName;
1019                                                 
1020                                                 ListViewItem listViewItem = new ListViewItem( directoryInfoi.Name );
1021                                                 
1022                                                 listViewItem.ImageIndex = 1;
1023                                                 
1024                                                 listViewItem.SubItems.Add( "" );
1025                                                 listViewItem.SubItems.Add( "Directory" );
1026                                                 listViewItem.SubItems.Add( directoryInfoi.LastAccessTime.ToShortDateString( ) + " " + directoryInfoi.LastAccessTime.ToShortTimeString( ) );
1027                                                 
1028                                                 fileStruct.attributes = FileAttributes.Directory;
1029                                                 
1030                                                 fileDialogPanel.fileHashtable.Add( directoryInfoi.Name, fileStruct );
1031                                                 
1032                                                 Items.Add( listViewItem );
1033                                         }
1034                                         
1035                                         foreach ( FileInfo fileInfo in fileInfoArray )
1036                                         {
1037                                                 FileStruct fileStruct = new FileStruct( );
1038                                                 
1039                                                 fileStruct.fullname = fileInfo.FullName;
1040                                                 
1041                                                 ListViewItem listViewItem = new ListViewItem( fileInfo.Name );
1042                                                 
1043                                                 listViewItem.ImageIndex = 0;
1044                                                 
1045                                                 long fileLen = 1;
1046                                                 if ( fileInfo.Length > 1024 )
1047                                                         fileLen = fileInfo.Length / 1024;
1048                                                 
1049                                                 listViewItem.SubItems.Add( fileLen.ToString( ) + " KB" );
1050                                                 listViewItem.SubItems.Add( "File" );
1051                                                 listViewItem.SubItems.Add( fileInfo.LastAccessTime.ToShortDateString( ) + " " + fileInfo.LastAccessTime.ToShortTimeString( ) );
1052                                                 
1053                                                 fileStruct.attributes = FileAttributes.Normal;
1054                                                 
1055                                                 fileDialogPanel.fileHashtable.Add( fileInfo.Name, fileStruct );
1056                                                 
1057                                                 Items.Add( listViewItem );
1058                                         }
1059                                         
1060                                         Console.WriteLine( "Items.Count: " + Items.Count );
1061                                         
1062                                         EndUpdate( );
1063                                 }
1064                                 
1065                                 protected override void OnClick( EventArgs e )
1066                                 {
1067                                         ListViewItem listViewItem;
1068
1069                                         if (SelectedItems.Count > 0) {
1070                                                 listViewItem = SelectedItems[ 0 ];
1071
1072                                                 FileStruct fileStruct = (FileStruct)fileDialogPanel.fileHashtable[ listViewItem.Text ];
1073                                         
1074                                                 if ( fileStruct.attributes != FileAttributes.Directory )
1075                                                 {
1076                                                         fileDialogPanel.FileNameComboBox.Text = listViewItem.Text;
1077                                                         fileDialogPanel.CurrentFileName = fileStruct.fullname;
1078                                                 }
1079                                         }
1080                                         
1081                                         base.OnClick( e );
1082                                 }
1083                                 
1084                                 protected override void OnDoubleClick( EventArgs e )
1085                                 {
1086                                         ListViewItem listViewItem = SelectedItems[ 0 ];
1087                                         
1088                                         FileStruct fileStruct = (FileStruct)fileDialogPanel.fileHashtable[ listViewItem.Text ];
1089                                         
1090                                         if ( fileStruct.attributes == FileAttributes.Directory )
1091                                         {
1092                                                 fileDialogPanel.ChangeDirectory( fileStruct.fullname );
1093                                         }
1094                                         else
1095                                         {
1096                                                 fileDialogPanel.FileNameComboBox.Text =  listViewItem.Text;
1097                                                 fileDialogPanel.CurrentFileName = fileStruct.fullname;
1098                                                 fileDialogPanel.ForceDialogEnd( );
1099                                                 return;
1100                                         }
1101                                         
1102                                         base.OnDoubleClick( e );
1103                                 }
1104                         }
1105                         
1106                         // helper class until ToolBar is working correctly
1107                         internal class ButtonPanel : Panel
1108                         {
1109                                 private FileDialogPanel fileDialogPanel;
1110                                 
1111                                 private Button lastOpenButton;
1112                                 private Button desktopButton;
1113                                 private Button homeButton;
1114                                 private Button workplaceButton;
1115                                 private Button networkButton;
1116                                 
1117                                 private ImageList imageList = new ImageList();
1118                                 
1119                                 public ButtonPanel( FileDialogPanel fileDialogPanel )
1120                                 {
1121                                         this.fileDialogPanel = fileDialogPanel;
1122                                         
1123                                         BorderStyle = BorderStyle.Fixed3D;
1124                                         BackColor = Color.FromArgb( 128, 128, 128 );
1125                                         Size = new Size( 85, 336 );
1126                                         
1127                                         // use ImageList to scale the bitmaps
1128                                         imageList.ColorDepth = ColorDepth.Depth32Bit;
1129                                         imageList.ImageSize = new Size( 38, 38 );
1130                                         imageList.Images.Add( (Image)Locale.GetResource( "last_open" ) );
1131                                         imageList.Images.Add( (Image)Locale.GetResource( "desktop" ) );
1132                                         imageList.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
1133                                         imageList.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
1134                                         imageList.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
1135                                         imageList.TransparentColor = Color.Transparent;
1136                                         
1137                                         lastOpenButton = new Button( );
1138                                         desktopButton = new Button( );
1139                                         homeButton = new Button( );
1140                                         workplaceButton = new Button( );
1141                                         networkButton = new Button( );
1142                                         
1143                                         lastOpenButton.Image = imageList.Images[ 0 ];
1144                                         lastOpenButton.ImageAlign = ContentAlignment.TopCenter;
1145                                         lastOpenButton.TextAlign = ContentAlignment.BottomCenter;
1146                                         lastOpenButton.ForeColor = Color.White;
1147                                         lastOpenButton.FlatStyle = FlatStyle.Popup;
1148                                         lastOpenButton.Size = new Size( 82, 64 );
1149                                         lastOpenButton.Location = new Point( 0, 2 );
1150                                         lastOpenButton.Text = "Last Open";
1151                                         lastOpenButton.Click += new EventHandler( OnClickButton );
1152                                         
1153                                         desktopButton.Image = imageList.Images[ 1 ];
1154                                         desktopButton.ImageAlign = ContentAlignment.TopCenter;
1155                                         desktopButton.TextAlign = ContentAlignment.BottomCenter;
1156                                         desktopButton.ForeColor = Color.White;
1157                                         desktopButton.FlatStyle = FlatStyle.Popup;
1158                                         desktopButton.Size = new Size( 82, 64 );
1159                                         desktopButton.Location = new Point( 0, 66 );
1160                                         desktopButton.Text = "Desktop";
1161                                         desktopButton.Click += new EventHandler( OnClickButton );
1162                                         
1163                                         homeButton.Image = imageList.Images[ 2 ];
1164                                         homeButton.ImageAlign = ContentAlignment.TopCenter;
1165                                         homeButton.TextAlign = ContentAlignment.BottomCenter;
1166                                         homeButton.ForeColor = Color.White;
1167                                         homeButton.FlatStyle = FlatStyle.Popup;
1168                                         homeButton.Size = new Size( 82, 64 );
1169                                         homeButton.Location = new Point( 0, 130 );
1170                                         homeButton.Text = "Home";
1171                                         homeButton.Click += new EventHandler( OnClickButton );
1172                                         
1173                                         workplaceButton.Image = imageList.Images[ 3 ];
1174                                         workplaceButton.ImageAlign = ContentAlignment.TopCenter;
1175                                         workplaceButton.TextAlign = ContentAlignment.BottomCenter;
1176                                         workplaceButton.ForeColor = Color.White;
1177                                         workplaceButton.FlatStyle = FlatStyle.Popup;
1178                                         workplaceButton.Size = new Size( 82, 64 );
1179                                         workplaceButton.Location = new Point( 0, 194 );
1180                                         workplaceButton.Text = "Workplace";
1181                                         workplaceButton.Click += new EventHandler( OnClickButton );
1182                                         
1183                                         networkButton.Image = imageList.Images[ 4 ];
1184                                         networkButton.ImageAlign = ContentAlignment.TopCenter;
1185                                         networkButton.TextAlign = ContentAlignment.BottomCenter;
1186                                         networkButton.ForeColor = Color.White;
1187                                         networkButton.FlatStyle = FlatStyle.Popup;
1188                                         networkButton.Size = new Size( 82, 64 );
1189                                         networkButton.Location = new Point( 0, 258 );
1190                                         networkButton.Text = "Network";
1191                                         networkButton.Click += new EventHandler( OnClickButton );
1192                                         
1193                                         Controls.Add( lastOpenButton );
1194                                         Controls.Add( desktopButton );
1195                                         Controls.Add( homeButton );
1196                                         Controls.Add( workplaceButton );
1197                                         Controls.Add( networkButton );
1198                                 }
1199                                 
1200                                 void OnClickButton( object sender, EventArgs e )
1201                                 {
1202                                         if ( sender == lastOpenButton )
1203                                         {
1204                                                 
1205                                         }
1206                                         else
1207                                         if ( sender == desktopButton )
1208                                         {
1209                                                 fileDialogPanel.ChangeDirectory( Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) );
1210                                         }
1211                                         else
1212                                         if ( sender == homeButton )
1213                                         {
1214                                                 fileDialogPanel.ChangeDirectory( Environment.GetFolderPath( Environment.SpecialFolder.Personal ) );
1215                                         }
1216                                         else
1217                                         if ( sender == workplaceButton )
1218                                         {
1219 //                                              fileDialogPanel.ChangeDirectory( Environment.GetFolderPath( Environment.SpecialFolder.MyComputer ) );
1220                                         }
1221                                         else
1222                                         if ( sender == networkButton )
1223                                         {
1224                                                 
1225                                         }
1226                                 }
1227                         }
1228                 }
1229         }
1230 }
1231
1232