b2e802cbed86387c4c626e4e7c61aa519a837917
[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 // TODO:
30 // file/path security stuff ???
31
32 using System;
33 using System.Drawing;
34 using System.ComponentModel;
35 using System.Resources;
36 using System.IO;
37 using System.Collections;
38 using System.Collections.Specialized;
39
40 namespace System.Windows.Forms
41 {
42         public abstract class FileDialog : CommonDialog
43         {
44                 internal enum FileDialogType
45                 {
46                         OpenFileDialog,
47                         SaveFileDialog
48                 }
49                 
50                 internal FileDialogPanel fileDialogPanel;
51                 
52                 private bool addExtension = true;
53                 internal bool checkFileExists = false;
54                 private bool checkPathExists = true;
55                 private string defaultExt = "";
56                 private bool dereferenceLinks = true;
57                 private string fileName = "";
58                 private string[] fileNames;
59                 private string filter;
60                 private int filterIndex = 1;
61                 private string initialDirectory = "";
62                 private bool restoreDirectory = false;
63                 private bool showHelp = false;
64                 private string title = "";
65                 private bool validateNames = true;
66                 
67                 //protected bool readOnlyChecked = false;
68                 
69                 internal string openSaveButtonText;
70                 internal string searchSaveLabelText;
71                 internal bool showReadOnly = false;
72                 internal bool readOnlyChecked = false;
73                 internal bool multiSelect = false;
74                 internal bool createPrompt = false;
75                 internal bool overwritePrompt = true;
76                 
77                 private bool showHiddenFiles = false;
78                 
79                 internal FileDialogType fileDialogType;
80                 
81                 public bool AddExtension
82                 {
83                         get
84                         {
85                                 return addExtension;
86                         }
87                         
88                         set
89                         {
90                                 addExtension = value;
91                         }
92                 }
93                 
94                 public virtual bool CheckFileExists
95                 {
96                         get
97                         {
98                                 return checkFileExists;
99                         }
100                         
101                         set
102                         {
103                                 checkFileExists = value;
104                         }
105                 }
106                 
107                 public bool CheckPathExists
108                 {
109                         get
110                         {
111                                 return checkPathExists;
112                         }
113                         
114                         set
115                         {
116                                 checkPathExists = value;
117                         }
118                 }
119                 
120                 public string DefaultExt
121                 {
122                         get
123                         {
124                                 return defaultExt;
125                         }
126                         
127                         set
128                         {
129                                 defaultExt = value;
130                                 
131                                 // if there is a dot remove it and everything before it
132                                 if ( defaultExt.LastIndexOf( '.' ) != - 1 )
133                                 {
134                                         string[] split = defaultExt.Split( new char[] { '.' } );
135                                         defaultExt = split[ split.Length - 1 ];
136                                 }
137                         }
138                 }
139                 
140                 // in MS.NET it doesn't make a difference if
141                 // DerefenceLinks is true or false
142                 // if the selected file is a link FileDialog
143                 // always returns the link
144                 public bool DereferenceLinks
145                 {
146                         get
147                         {
148                                 return dereferenceLinks;
149                         }
150                         
151                         set
152                         {
153                                 dereferenceLinks = value;
154                         }
155                 }
156                 
157                 public string FileName
158                 {
159                         get
160                         {
161                                 return fileName;
162                         }
163                         
164                         set
165                         {
166                                 fileName = value;
167                         }
168                 }
169                 
170                 public string[] FileNames
171                 {
172                         get
173                         {
174                                 if ( multiSelect )
175                                         return fileNames;
176                                 
177                                 return null;
178                         }
179                 }
180                 
181                 public string Filter
182                 {
183                         get
184                         {
185                                 return filter;
186                         }
187                         
188                         set
189                         {
190                                 if ( value == null )
191                                         throw new NullReferenceException( "Filter" );
192                                 
193                                 filter = value;
194                                 
195                                 fileFilter = new FileFilter( filter );
196                                 
197                                 fileDialogPanel.UpdateFilters( );
198                         }
199                 }
200                 
201                 public int FilterIndex
202                 {
203                         get
204                         {
205                                 return filterIndex;
206                         }
207                         
208                         set
209                         {
210                                 filterIndex = value;
211                         }
212                 }
213                 
214                 public string InitialDirectory
215                 {
216                         get
217                         {
218                                 return initialDirectory;
219                         }
220                         
221                         set
222                         {
223                                 initialDirectory = value;
224                         }
225                 }
226                 
227                 public bool RestoreDirectory
228                 {
229                         get
230                         {
231                                 return restoreDirectory;
232                         }
233                         
234                         set
235                         {
236                                 restoreDirectory = value;
237                         }
238                 }
239                 
240                 public bool ShowHelp
241                 {
242                         get
243                         {
244                                 return showHelp;
245                         }
246                         
247                         set
248                         {
249                                 showHelp = value;
250                                 fileDialogPanel.ResizeAndRelocateForHelpOrReadOnly( );
251                         }
252                 }
253                 
254                 public string Title
255                 {
256                         get
257                         {
258                                 return title;
259                         }
260                         
261                         set
262                         {
263                                 title = value;
264                                 
265                                 form.Text = title;
266                         }
267                 }
268                 
269                 // this one is a hard one ;)
270                 // Win32 filename:
271                 // - up to MAX_PATH characters (windef.h) = 260
272                 // - no trailing dots or spaces
273                 // - case preserving
274                 // - etc...
275                 // NTFS/Posix filename:
276                 // - up to 32,768 Unicode characters
277                 // - trailing periods or spaces
278                 // - case sensitive
279                 // - etc...
280                 public bool ValidateNames
281                 {
282                         get
283                         {
284                                 return validateNames;
285                         }
286                         
287                         set
288                         {
289                                 validateNames = value;
290                         }
291                 }
292                 
293                 internal string OpenSaveButtonText
294                 {
295                         set
296                         {
297                                 openSaveButtonText = value;
298                         }
299                         
300                         get
301                         {
302                                 return openSaveButtonText;
303                         }
304                 }
305                 
306                 internal string SearchSaveLabelText
307                 {
308                         set
309                         {
310                                 searchSaveLabelText = value;
311                         }
312                         
313                         get
314                         {
315                                 return searchSaveLabelText;
316                         }
317                 }
318                 
319                 internal virtual bool ShowReadOnly
320                 {
321                         set
322                         {
323                                 showReadOnly = value;
324                                 fileDialogPanel.ResizeAndRelocateForHelpOrReadOnly( );
325                         }
326                         
327                         get
328                         {
329                                 return showReadOnly;
330                         }
331                 }
332                 
333                 internal virtual bool ReadOnlyChecked
334                 {
335                         set
336                         {
337                                 readOnlyChecked = value;
338                                 fileDialogPanel.CheckBox.Checked = value;
339                         }
340                         
341                         get
342                         {
343                                 return readOnlyChecked;
344                         }
345                 }
346                 
347                 internal virtual bool Multiselect
348                 {
349                         set
350                         {
351                                 multiSelect = value;
352                                 fileDialogPanel.MultiSelect = value;
353                         }
354                         
355                         get
356                         {
357                                 return multiSelect;
358                         }
359                 }
360                 
361                 // extension to MS.NET framework...
362                 public bool ShowHiddenFiles
363                 {
364                         set
365                         {
366                                 showHiddenFiles = value;
367                         }
368                         
369                         get
370                         {
371                                 return showHiddenFiles;
372                         }
373                 }
374                 
375                 internal virtual bool CreatePrompt
376                 {
377                         set
378                         {
379                                 createPrompt = value;
380                         }
381                         
382                         get
383                         {
384                                 return createPrompt;
385                         }
386                 }
387                 
388                 internal virtual bool OverwritePrompt
389                 {
390                         set
391                         {
392                                 overwritePrompt = value;
393                         }
394                         
395                         get
396                         {
397                                 return overwritePrompt;
398                         }
399                 }
400                 
401                 internal FileFilter FileFilter
402                 {
403                         set
404                         {
405                                 fileFilter = value;
406                         }
407                         
408                         get
409                         {
410                                 return fileFilter;
411                         }
412                 }
413                 
414                 public override void Reset( )
415                 {
416                         addExtension = true;
417                         checkFileExists = false;
418                         checkPathExists = true;
419                         defaultExt = "";
420                         dereferenceLinks = true;
421                         fileName = "";
422                         fileNames = null;
423                         Filter = "";
424                         filterIndex = 1;
425                         initialDirectory = "";
426                         restoreDirectory = false;
427                         ShowHelp = false;
428                         Title = "";
429                         validateNames = true;
430                         
431                         fileDialogPanel.UpdateFilters( );
432                 }
433                 
434                 public override string ToString( )
435                 {
436                         return base.ToString( );
437                 }
438                 
439                 public event CancelEventHandler FileOk;
440                 
441                 protected  override IntPtr HookProc( IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam )
442                 {
443                         throw new NotImplementedException( );
444                 }
445                 
446                 protected void OnFileOk( CancelEventArgs e )
447                 {
448                         if ( FileOk != null ) FileOk( this, e );
449                 }
450                 
451                 [MonoTODO]
452                 protected  override bool RunDialog( IntPtr hWndOwner )
453                 {
454                         form.Controls.Add( fileDialogPanel );
455                         
456                         return true;
457                 }
458                 
459                 internal void SendHelpRequest( EventArgs e )
460                 {
461                         OnHelpRequest( e );
462                 }
463                 
464                 internal void SetFilenames( string[] filenames )
465                 {
466                         fileNames = filenames;
467                 }
468                 
469                 internal FileFilter fileFilter;
470                 
471                 internal class FileDialogPanel : Panel
472                 {
473                         private Button cancelButton;
474                         private ToolBarButton upToolBarButton;
475                         private PopupButtonPanel popupButtonPanel;
476                         private Button openSaveButton;
477                         private Button helpButton;
478                         private Label fileTypeLabel;
479                         private ToolBarButton menueToolBarButton;
480                         private ContextMenu menueToolBarButtonContextMenu;
481                         private ToolBarButton desktopToolBarButton;
482                         private ToolBar smallButtonToolBar;
483                         private DirComboBox dirComboBox;
484                         private ToolBarButton lastUsedToolBarButton;
485                         private ComboBox fileNameComboBox;
486                         private ToolBarButton networkToolBarButton;
487                         private Label fileNameLabel;
488                         private MWFFileView mwfFileView;
489                         private Label searchSaveLabel;
490                         private ToolBarButton newdirToolBarButton;
491                         private ToolBarButton backToolBarButton;
492                         private ToolBarButton homeToolBarButton;
493                         private ToolBarButton workplaceToolBarButton;
494                         private ComboBox fileTypeComboBox;
495                         private ImageList imageListTopToolbar;
496                         private ContextMenu contextMenu;
497                         private CheckBox checkBox;
498                         
499                         internal FileDialog fileDialog;
500                         
501                         private string currentDirectoryName;
502                         
503                         internal string currentFileName = "";
504                         
505                         // store current directoryInfo
506                         private DirectoryInfo directoryInfo;
507                         
508                         // store DirectoryInfo for backButton
509                         internal Stack directoryStack = new Stack();
510                         
511                         private MenuItem previousCheckedMenuItem;
512                         
513                         private bool multiSelect = false;
514                         
515                         private string restoreDirectory = "";
516                         
517                         public FileDialogPanel( FileDialog fileDialog )
518                         {
519                                 this.fileDialog = fileDialog;
520                                 
521                                 fileTypeComboBox = new ComboBox( );
522                                 workplaceToolBarButton = new ToolBarButton( );
523                                 homeToolBarButton = new ToolBarButton( );
524                                 backToolBarButton = new ToolBarButton( );
525                                 newdirToolBarButton = new ToolBarButton( );
526                                 searchSaveLabel = new Label( );
527                                 mwfFileView = new MWFFileView( );
528                                 fileNameLabel = new Label( );
529                                 networkToolBarButton = new ToolBarButton( );
530                                 fileNameComboBox = new ComboBox( );
531                                 lastUsedToolBarButton = new ToolBarButton( );
532                                 dirComboBox = new DirComboBox( );
533                                 smallButtonToolBar = new ToolBar( );
534                                 desktopToolBarButton = new ToolBarButton( );
535                                 menueToolBarButton = new ToolBarButton( );
536                                 fileTypeLabel = new Label( );
537                                 openSaveButton = new Button( );
538                                 fileDialog.form.AcceptButton = openSaveButton;
539                                 helpButton = new Button( );
540                                 popupButtonPanel = new PopupButtonPanel( this );
541                                 upToolBarButton = new ToolBarButton( );
542                                 cancelButton = new Button( );
543                                 fileDialog.form.CancelButton = cancelButton;
544                                 imageListTopToolbar = new ImageList( );
545                                 menueToolBarButtonContextMenu = new ContextMenu( );
546                                 contextMenu = new ContextMenu( );
547                                 checkBox = new CheckBox( );
548                                 
549                                 SuspendLayout( );
550                                 
551                                 //imageListTopToolbar
552                                 imageListTopToolbar.ColorDepth = ColorDepth.Depth32Bit;
553                                 imageListTopToolbar.ImageSize = new Size( 16, 16 ); // 16, 16
554                                 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "back_arrow" ) );
555                                 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_arrow_up" ) );
556                                 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "folder_star" ) );
557                                 imageListTopToolbar.Images.Add( (Image)Locale.GetResource( "window" ) );
558                                 imageListTopToolbar.TransparentColor = Color.Transparent;
559                                 
560                                 // searchLabel
561                                 searchSaveLabel.FlatStyle = FlatStyle.System;
562                                 searchSaveLabel.Location = new Point( 7, 8 );
563                                 searchSaveLabel.Size = new Size( 72, 21 );
564                                 searchSaveLabel.TabIndex = 0;
565                                 searchSaveLabel.Text = fileDialog.SearchSaveLabelText;
566                                 searchSaveLabel.TextAlign = ContentAlignment.MiddleRight;
567                                 
568                                 // dirComboBox
569                                 dirComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Top | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
570                                 dirComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
571                                 dirComboBox.Location = new Point( 99, 8 );
572                                 dirComboBox.Size = new Size( 260, 21 );
573                                 dirComboBox.TabIndex = 1;
574                                 
575                                 // smallButtonToolBar
576                                 smallButtonToolBar.Anchor = ( (AnchorStyles)( ( AnchorStyles.Top | AnchorStyles.Right ) ) );
577                                 smallButtonToolBar.Appearance = ToolBarAppearance.Flat;
578                                 smallButtonToolBar.AutoSize = false;
579                                 smallButtonToolBar.Buttons.AddRange( new ToolBarButton[] {
580                                                                             backToolBarButton,
581                                                                             upToolBarButton,
582                                                                             newdirToolBarButton,
583                                                                             menueToolBarButton} );
584                                 smallButtonToolBar.ButtonSize = new Size( 21, 16 ); // 21, 16
585                                 smallButtonToolBar.Divider = false;
586                                 smallButtonToolBar.Dock = DockStyle.None;
587                                 smallButtonToolBar.DropDownArrows = true;
588                                 smallButtonToolBar.ImageList = imageListTopToolbar;
589                                 smallButtonToolBar.Location = new Point( 372, 8 );
590                                 smallButtonToolBar.ShowToolTips = true;
591                                 smallButtonToolBar.Size = new Size( 110, 20 );
592                                 smallButtonToolBar.TabIndex = 2;
593                                 smallButtonToolBar.TextAlign = ToolBarTextAlign.Right;
594                                 
595                                 // buttonPanel
596                                 popupButtonPanel.Dock = DockStyle.None;
597                                 popupButtonPanel.Location = new Point( 7, 37 );
598                                 popupButtonPanel.TabIndex = 3;
599                                 
600                                 // mwfFileView
601                                 mwfFileView.Anchor = ( (AnchorStyles)( ( ( ( AnchorStyles.Top | AnchorStyles.Bottom ) | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
602                                 mwfFileView.Location = new Point( 99, 37 );
603                                 mwfFileView.Size = new Size( 449, 282 );
604                                 mwfFileView.Columns.Add( " Name", 170, HorizontalAlignment.Left );
605                                 mwfFileView.Columns.Add( "Size ", 80, HorizontalAlignment.Right );
606                                 mwfFileView.Columns.Add( " Type", 100, HorizontalAlignment.Left );
607                                 mwfFileView.Columns.Add( " Last Access", 150, HorizontalAlignment.Left );
608                                 mwfFileView.AllowColumnReorder = true;
609                                 mwfFileView.MultiSelect = false;
610                                 mwfFileView.TabIndex = 4;
611                                 mwfFileView.FilterIndex = fileDialog.FilterIndex;
612                                 
613                                 // fileNameLabel
614                                 fileNameLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
615                                 fileNameLabel.FlatStyle = FlatStyle.System;
616                                 fileNameLabel.Location = new Point( 102, 330 );
617                                 fileNameLabel.Size = new Size( 70, 21 );
618                                 fileNameLabel.TabIndex = 5;
619                                 fileNameLabel.Text = "Filename:";
620                                 fileNameLabel.TextAlign = ContentAlignment.MiddleLeft;
621                                 
622                                 // fileNameComboBox
623                                 fileNameComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
624                                 fileNameComboBox.Location = new Point( 195, 330 );
625                                 fileNameComboBox.Size = new Size( 245, 21 );
626                                 fileNameComboBox.TabIndex = 6;
627                                 
628                                 // fileTypeLabel
629                                 fileTypeLabel.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Left ) ) );
630                                 fileTypeLabel.FlatStyle = FlatStyle.System;
631                                 fileTypeLabel.Location = new Point( 102, 356 );
632                                 fileTypeLabel.Size = new Size( 70, 21 );
633                                 fileTypeLabel.TabIndex = 7;
634                                 fileTypeLabel.Text = "Filetype:";
635                                 fileTypeLabel.TextAlign = ContentAlignment.MiddleLeft;
636                                 
637                                 // fileTypeComboBox
638                                 fileTypeComboBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
639                                 fileTypeComboBox.Location = new Point( 195, 356 );
640                                 fileTypeComboBox.Size = new Size( 245, 21 );
641                                 fileTypeComboBox.TabIndex = 8;
642                                 
643                                 // backToolBarButton
644                                 backToolBarButton.ImageIndex = 0;
645                                 backToolBarButton.Enabled = false;
646                                 backToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
647                                 
648                                 // upToolBarButton
649                                 upToolBarButton.ImageIndex = 1;
650                                 upToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
651                                 
652                                 // newdirToolBarButton
653                                 newdirToolBarButton.ImageIndex = 2;
654                                 newdirToolBarButton.Style = ToolBarButtonStyle.ToggleButton;
655                                 
656                                 // menueToolBarButton
657                                 menueToolBarButton.ImageIndex = 3;
658                                 menueToolBarButton.DropDownMenu = menueToolBarButtonContextMenu;
659                                 menueToolBarButton.Style = ToolBarButtonStyle.DropDownButton;
660                                 
661                                 // menueToolBarButtonContextMenu
662                                 MenuItem mi = new MenuItem( "Small Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
663                                 menueToolBarButtonContextMenu.MenuItems.Add( mi );
664                                 mi = new MenuItem( "Tiles", new EventHandler( OnClickMenuToolBarContextMenu ) );
665                                 menueToolBarButtonContextMenu.MenuItems.Add( mi );
666                                 mi = new MenuItem( "Large Icon", new EventHandler( OnClickMenuToolBarContextMenu ) );
667                                 menueToolBarButtonContextMenu.MenuItems.Add( mi );
668                                 mi = new MenuItem( "List", new EventHandler( OnClickMenuToolBarContextMenu ) );
669                                 mi.Checked = true;
670                                 previousCheckedMenuItem = mi;
671                                 menueToolBarButtonContextMenu.MenuItems.Add( mi );
672                                 mi = new MenuItem( "Details", new EventHandler( OnClickMenuToolBarContextMenu ) );
673                                 menueToolBarButtonContextMenu.MenuItems.Add( mi );
674                                 
675                                 // contextMenu
676                                 mi = new MenuItem( "Show hidden files", new EventHandler( OnClickContextMenu ) );
677                                 mi.Checked = fileDialog.ShowHiddenFiles;
678                                 mwfFileView.ShowHiddenFiles = fileDialog.ShowHiddenFiles;
679                                 contextMenu.MenuItems.Add( mi );
680                                 
681                                 // openSaveButton
682                                 openSaveButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
683                                 openSaveButton.FlatStyle = FlatStyle.System;
684                                 openSaveButton.Location = new Point( 475, 330 );
685                                 openSaveButton.Size = new Size( 72, 21 );
686                                 openSaveButton.TabIndex = 9;
687                                 openSaveButton.Text = fileDialog.OpenSaveButtonText;
688                                 openSaveButton.FlatStyle = FlatStyle.System;
689                                 
690                                 // cancelButton
691                                 cancelButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
692                                 cancelButton.FlatStyle = FlatStyle.System;
693                                 cancelButton.Location = new Point( 475, 356 );
694                                 cancelButton.Size = new Size( 72, 21 );
695                                 cancelButton.TabIndex = 10;
696                                 cancelButton.Text = "Cancel";
697                                 cancelButton.FlatStyle = FlatStyle.System;
698                                 
699                                 // helpButton
700                                 helpButton.Anchor = ( (AnchorStyles)( ( AnchorStyles.Bottom | AnchorStyles.Right ) ) );
701                                 helpButton.FlatStyle = FlatStyle.System;
702                                 helpButton.Location = new Point( 475, 350 );
703                                 helpButton.Size = new Size( 72, 21 );
704                                 helpButton.TabIndex = 11;
705                                 helpButton.Text = "Help";
706                                 helpButton.FlatStyle = FlatStyle.System;
707                                 helpButton.Hide( );
708                                 
709                                 // checkBox
710                                 checkBox.Anchor = ( (AnchorStyles)( ( ( AnchorStyles.Bottom | AnchorStyles.Left ) | AnchorStyles.Right ) ) );
711                                 checkBox.Text = "Open Readonly";
712                                 checkBox.Location = new Point( 195, 350 );
713                                 checkBox.Size = new Size( 245, 21 );
714                                 checkBox.FlatStyle = FlatStyle.System;
715                                 checkBox.TabIndex = 12;
716                                 checkBox.Hide( );
717                                 
718                                 ClientSize = new Size( 554, 405 ); // 384
719                                 
720                                 ContextMenu = contextMenu;
721                                 
722                                 Controls.Add( smallButtonToolBar );
723                                 Controls.Add( cancelButton );
724                                 Controls.Add( openSaveButton );
725                                 Controls.Add( helpButton );
726                                 Controls.Add( mwfFileView );
727                                 Controls.Add( fileTypeLabel );
728                                 Controls.Add( fileNameLabel );
729                                 Controls.Add( fileTypeComboBox );
730                                 Controls.Add( fileNameComboBox );
731                                 Controls.Add( dirComboBox );
732                                 Controls.Add( searchSaveLabel );
733                                 Controls.Add( popupButtonPanel );
734                                 Controls.Add( checkBox );
735                                 
736                                 ResumeLayout( false );
737                                 
738                                 if ( fileDialog.InitialDirectory == String.Empty )
739                                         currentDirectoryName = Environment.CurrentDirectory;
740                                 else
741                                         currentDirectoryName = fileDialog.InitialDirectory;
742                                 
743                                 directoryInfo = new DirectoryInfo( currentDirectoryName );
744                                 
745                                 dirComboBox.CurrentPath = currentDirectoryName;
746                                 
747                                 if ( fileDialog.RestoreDirectory )
748                                         restoreDirectory = currentDirectoryName;
749                                 
750                                 mwfFileView.UpdateFileView( directoryInfo );
751                                 
752                                 openSaveButton.Click += new EventHandler( OnClickOpenSaveButton );
753                                 cancelButton.Click += new EventHandler( OnClickCancelButton );
754                                 helpButton.Click += new EventHandler( OnClickHelpButton );
755                                 
756                                 smallButtonToolBar.ButtonClick += new ToolBarButtonClickEventHandler( OnClickSmallButtonToolBar );
757                                 
758                                 // Key events DONT'T work
759                                 fileNameComboBox.KeyUp += new KeyEventHandler( OnKeyUpFileNameComboBox );
760                                 
761                                 fileTypeComboBox.SelectedIndexChanged += new EventHandler( OnSelectedIndexChangedFileTypeComboBox );
762                                 
763                                 mwfFileView.SelectedFileChanged += new EventHandler( OnSelectedFileChangedFileView );
764                                 mwfFileView.DirectoryChanged += new EventHandler( OnDirectoryChangedFileView );
765                                 mwfFileView.ForceDialogEnd += new EventHandler( OnForceDialogEndFileView );
766                                 mwfFileView.SelectedFilesChanged += new EventHandler( OnSelectedFilesChangedFileView );
767                                 
768                                 dirComboBox.DirectoryChanged += new EventHandler( OnDirectoryChangedDirComboBox );
769                                 
770                                 checkBox.CheckedChanged += new EventHandler( OnCheckCheckChanged );
771                         }
772                         
773                         public ComboBox FileNameComboBox
774                         {
775                                 set
776                                 {
777                                         fileNameComboBox = value;
778                                 }
779                                 
780                                 get
781                                 {
782                                         return fileNameComboBox;
783                                 }
784                         }
785                         
786                         public string CurrentFileName
787                         {
788                                 set
789                                 {
790                                         currentFileName = value;
791                                 }
792                                 
793                                 get
794                                 {
795                                         return currentFileName;
796                                 }
797                         }
798                         
799                         public DirectoryInfo DirectoryInfo
800                         {
801                                 set
802                                 {
803                                         directoryInfo = value;
804                                 }
805                                 
806                                 get
807                                 {
808                                         return directoryInfo;
809                                 }
810                         }
811                         
812                         public bool MultiSelect
813                         {
814                                 set
815                                 {
816                                         multiSelect = value;
817                                         mwfFileView.MultiSelect = value;
818                                 }
819                                 
820                                 get
821                                 {
822                                         return multiSelect;
823                                 }
824                         }
825                         
826                         public CheckBox CheckBox
827                         {
828                                 set
829                                 {
830                                         checkBox = value;
831                                 }
832                                 
833                                 get
834                                 {
835                                         return checkBox;
836                                 }
837                         }
838                         
839                         void OnClickContextMenu( object sender, EventArgs e )
840                         {
841                                 MenuItem senderMenuItem = sender as MenuItem;
842                                 
843                                 if ( senderMenuItem.Index == 0 )
844                                 {
845                                         senderMenuItem.Checked = !senderMenuItem.Checked;
846                                         fileDialog.ShowHiddenFiles = senderMenuItem.Checked;
847                                         mwfFileView.ShowHiddenFiles = fileDialog.ShowHiddenFiles;
848                                         mwfFileView.UpdateFileView( directoryInfo );
849                                 }
850                         }
851                         
852                         void OnClickOpenSaveButton( object sender, EventArgs e )
853                         {
854                                 if ( !multiSelect )
855                                 {
856                                         string fileFromComboBox = fileNameComboBox.Text.Trim( );
857                                         
858                                         if ( fileFromComboBox.Length > 0 )
859                                                 fileFromComboBox = Path.Combine( currentDirectoryName, fileFromComboBox );
860                                         
861                                         if ( currentFileName != fileFromComboBox )
862                                                 currentFileName = fileFromComboBox;
863                                         
864                                         if ( currentFileName.Length == 0 )
865                                                 return;
866                                         
867                                         
868                                         if ( fileDialog.fileDialogType == FileDialogType.OpenFileDialog )
869                                         {
870                                                 if ( fileDialog.CheckFileExists )
871                                                 {
872                                                         if ( !File.Exists( currentFileName ) )
873                                                         {
874                                                                 string message = currentFileName + " doesn't exist. Please verify that you have entered the correct file name.";
875                                                                 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
876                                                                 
877                                                                 currentFileName = "";
878                                                                 
879                                                                 return;
880                                                         }
881                                                 }
882                                         }
883                                         else // FileDialogType == SaveFileDialog
884                                         {
885                                                 if ( fileDialog.OverwritePrompt )
886                                                 {
887                                                         if ( File.Exists( currentFileName ) )
888                                                         {
889                                                                 string message = currentFileName + " exists. Overwrite ?";
890                                                                 DialogResult dr = MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
891                                                                 
892                                                                 if ( dr == DialogResult.Cancel )
893                                                                 {
894                                                                         currentFileName = "";
895                                                                         
896                                                                         return;
897                                                                 }
898                                                         }
899                                                 }
900                                                 
901                                                 if ( fileDialog.CreatePrompt )
902                                                 {
903                                                         if ( !File.Exists( currentFileName ) )
904                                                         {
905                                                                 string message = currentFileName + " doesn't exist. Create ?";
906                                                                 DialogResult dr = MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning );
907                                                                 
908                                                                 if ( dr == DialogResult.Cancel )
909                                                                 {
910                                                                         currentFileName = "";
911                                                                         
912                                                                         return;
913                                                                 }
914                                                         }
915                                                 }
916                                         }
917                                         
918                                         if ( fileDialog.fileDialogType == FileDialogType.SaveFileDialog )
919                                         {
920                                                 if ( fileDialog.AddExtension && fileDialog.DefaultExt.Length > 0 )
921                                                 {
922                                                         if ( !currentFileName.EndsWith( fileDialog.DefaultExt ) )
923                                                         {
924                                                                 currentFileName += "." + fileDialog.DefaultExt;
925                                                         }
926                                                 }
927                                         }
928                                         
929                                         fileDialog.FileName = currentFileName;
930                                 }
931                                 else // multiSelect = true
932                                 if ( fileDialog.fileDialogType != FileDialogType.SaveFileDialog )
933                                 {
934                                         if ( mwfFileView.SelectedItems.Count > 0 )
935                                         {
936                                                 // first remove all selected directories
937                                                 ArrayList al = new ArrayList( );
938                                                 
939                                                 foreach ( ListViewItem lvi in mwfFileView.SelectedItems )
940                                                 {
941                                                         FileStruct fileStruct = (FileStruct)mwfFileView.FileHashtable[ lvi.Text ];
942                                                         
943                                                         if ( fileStruct.attributes != FileAttributes.Directory )
944                                                         {
945                                                                 al.Add( fileStruct );
946                                                         }
947                                                 }
948                                                 
949                                                 fileDialog.FileName = ( (FileStruct)al[ 0 ] ).fullname;
950                                                 
951                                                 string[] filenames = new string[ al.Count ];
952                                                 
953                                                 for ( int i = 0; i < al.Count; i++ )
954                                                 {
955                                                         filenames[ i ] = ( (FileStruct)al[ i ] ).fullname;
956                                                 }
957                                                 
958                                                 fileDialog.SetFilenames( filenames );
959                                         }
960                                 }
961                                 
962                                 if ( fileDialog.CheckPathExists )
963                                 {
964                                         if ( !Directory.Exists( currentDirectoryName ) )
965                                         {
966                                                 string message = currentDirectoryName + " doesn't exist. Please verify that you have entered the correct directory name.";
967                                                 MessageBox.Show( message, fileDialog.OpenSaveButtonText, MessageBoxButtons.OK, MessageBoxIcon.Warning );
968                                                 
969                                                 if ( fileDialog.InitialDirectory == String.Empty )
970                                                         currentDirectoryName = Environment.CurrentDirectory;
971                                                 else
972                                                         currentDirectoryName = fileDialog.InitialDirectory;
973                                                 
974                                                 return;
975                                         }
976                                 }
977                                 
978                                 if ( fileDialog.RestoreDirectory )
979                                         currentDirectoryName = restoreDirectory;
980                                 
981                                 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
982                                 
983                                 cancelEventArgs.Cancel = false;
984                                 
985                                 fileDialog.OnFileOk( cancelEventArgs );
986                                 
987                                 fileDialog.form.Controls.Remove( this );
988                                 fileDialog.form.DialogResult = DialogResult.OK;
989                         }
990                         
991                         void OnClickCancelButton( object sender, EventArgs e )
992                         {
993                                 if ( fileDialog.RestoreDirectory )
994                                         currentDirectoryName = restoreDirectory;
995                                 
996                                 CancelEventArgs cancelEventArgs = new CancelEventArgs( );
997                                 
998                                 cancelEventArgs.Cancel = true;
999                                 
1000                                 fileDialog.OnFileOk( cancelEventArgs );
1001                                 
1002                                 fileDialog.form.Controls.Remove( this );
1003                                 fileDialog.form.DialogResult = DialogResult.Cancel;
1004                         }
1005                         
1006                         void OnClickHelpButton( object sender, EventArgs e )
1007                         {
1008                                 fileDialog.SendHelpRequest( e );
1009                         }
1010                         
1011                         void OnClickSmallButtonToolBar( object sender, ToolBarButtonClickEventArgs e )
1012                         {
1013                                 if ( e.Button == upToolBarButton )
1014                                 {
1015                                         if ( directoryInfo.Parent != null )
1016                                         {
1017                                                 PushDirectory( directoryInfo );
1018                                                 
1019                                                 directoryInfo = directoryInfo.Parent;
1020                                                 
1021                                                 currentDirectoryName = directoryInfo.FullName;
1022                                                 
1023                                                 dirComboBox.CurrentPath = currentDirectoryName;
1024                                                 
1025                                                 mwfFileView.UpdateFileView( directoryInfo );
1026                                         }
1027                                 }
1028                                 else
1029                                 if ( e.Button == backToolBarButton )
1030                                 {
1031                                         if ( directoryStack.Count != 0 )
1032                                         {
1033                                                 PopDirectory( );
1034                                                 
1035                                                 dirComboBox.CurrentPath = currentDirectoryName;
1036                                                 
1037                                                 mwfFileView.UpdateFileView( directoryInfo );
1038                                         }
1039                                 }
1040                                 else
1041                                 if ( e.Button == newdirToolBarButton )
1042                                 {
1043                                         
1044                                 }
1045                         }
1046                         
1047                         void OnClickMenuToolBarContextMenu( object sender, EventArgs e )
1048                         {
1049                                 MenuItem senderMenuItem = (MenuItem)sender;
1050                                 
1051                                 previousCheckedMenuItem.Checked = false;
1052                                 senderMenuItem.Checked = true;
1053                                 previousCheckedMenuItem = senderMenuItem;
1054                                 
1055                                 // FIXME...
1056                                 
1057                                 switch ( senderMenuItem.Index  )
1058                                 {
1059                                         case 0:
1060                                                 mwfFileView.View = View.SmallIcon;
1061                                                 break;
1062                                         case 1:
1063                                                 mwfFileView.View = View.LargeIcon;
1064                                                 break;
1065                                         case 2:
1066                                                 mwfFileView.View = View.LargeIcon;
1067                                                 break;
1068                                         case 3:
1069                                                 mwfFileView.View = View.List;
1070                                                 break;
1071                                         case 4:
1072                                                 mwfFileView.View = View.Details;
1073                                                 break;
1074                                         default:
1075                                                 break;
1076                                 }
1077                                 
1078                         }
1079                         
1080                         void OnKeyUpFileNameComboBox( object sender, KeyEventArgs e )
1081                         {
1082                                 if ( e.KeyCode == Keys.Enter )
1083                                 {
1084                                         currentFileName = currentDirectoryName + fileNameComboBox.Text;
1085                                         ForceDialogEnd( );
1086                                 }
1087                         }
1088                         
1089                         void OnSelectedIndexChangedFileTypeComboBox( object sender, EventArgs e )
1090                         {
1091                                 fileDialog.FilterIndex = fileTypeComboBox.SelectedIndex + 1;
1092                                 
1093                                 mwfFileView.FilterIndex = fileDialog.FilterIndex;
1094                                 
1095                                 mwfFileView.UpdateFileView( directoryInfo );
1096                         }
1097                         
1098                         void OnSelectedFileChangedFileView( object sender, EventArgs e )
1099                         {
1100                                 fileNameComboBox.Text = mwfFileView.FileName;
1101                                 currentFileName = mwfFileView.FullFileName;
1102                         }
1103                         
1104                         void OnDirectoryChangedFileView( object sender, EventArgs e )
1105                         {
1106                                 ChangeDirectory( sender, mwfFileView.FullFileName );
1107                         }
1108                         
1109                         void OnForceDialogEndFileView( object sender, EventArgs e )
1110                         {
1111                                 ForceDialogEnd( );
1112                         }
1113                         
1114                         void OnSelectedFilesChangedFileView( object sender, EventArgs e )
1115                         {
1116                                 fileNameComboBox.Text = mwfFileView.SelectedFilesString;
1117                         }
1118                         
1119                         void OnDirectoryChangedDirComboBox( object sender, EventArgs e )
1120                         {
1121                                 ChangeDirectory( sender, dirComboBox.CurrentPath );
1122                         }
1123                         
1124                         void OnCheckCheckChanged( object sender, EventArgs e )
1125                         {
1126                                 fileDialog.ReadOnlyChecked = checkBox.Checked;
1127                         }
1128                         
1129                         public void UpdateFilters( )
1130                         {
1131                                 ArrayList filters = fileDialog.FileFilter.FilterArrayList;
1132                                 
1133                                 fileTypeComboBox.Items.Clear( );
1134                                 
1135                                 fileTypeComboBox.BeginUpdate( );
1136                                 
1137                                 foreach ( FilterStruct fs in filters )
1138                                 {
1139                                         fileTypeComboBox.Items.Add( fs.filterName );
1140                                 }
1141                                 
1142                                 fileTypeComboBox.SelectedIndex = fileDialog.FilterIndex - 1;
1143                                 
1144                                 fileTypeComboBox.EndUpdate( );
1145                                 
1146                                 mwfFileView.FilterArrayList = filters;
1147                                 
1148                                 mwfFileView.FilterIndex = fileDialog.FilterIndex;
1149                                 
1150                                 mwfFileView.UpdateFileView( directoryInfo );
1151                         }
1152                         
1153                         public void ChangeDirectory( object sender, string path )
1154                         {
1155                                 currentDirectoryName = path;
1156                                 
1157                                 PushDirectory( directoryInfo );
1158                                 
1159                                 directoryInfo = new DirectoryInfo( path );
1160                                 
1161                                 if ( sender != dirComboBox )
1162                                         dirComboBox.CurrentPath = path;
1163                                 
1164                                 mwfFileView.UpdateFileView( directoryInfo );
1165                         }
1166                         
1167                         public void ForceDialogEnd( )
1168                         {
1169                                 OnClickOpenSaveButton( this, EventArgs.Empty );
1170                         }
1171                         
1172                         private void PushDirectory( DirectoryInfo di )
1173                         {
1174                                 directoryStack.Push( directoryInfo );
1175                                 backToolBarButton.Enabled = true;
1176                         }
1177                         
1178                         private void PopDirectory( )
1179                         {
1180                                 directoryInfo = (DirectoryInfo)directoryStack.Pop( );
1181                                 
1182                                 currentDirectoryName = directoryInfo.FullName;
1183                                 
1184                                 if ( directoryStack.Count == 0 )
1185                                         backToolBarButton.Enabled = false;
1186                         }
1187                         
1188                         public void ResizeAndRelocateForHelpOrReadOnly( )
1189                         {
1190                                 if ( fileDialog.ShowHelp || fileDialog.ShowReadOnly )
1191                                 {
1192                                         mwfFileView.Size = new Size( 449, 250 );
1193                                         fileNameLabel.Location = new Point( 102, 298 );
1194                                         fileNameComboBox.Location = new Point( 195, 298 );
1195                                         fileTypeLabel.Location = new Point( 102, 324 );
1196                                         fileTypeComboBox.Location = new Point( 195, 324 );
1197                                         openSaveButton.Location = new Point( 475, 298 );
1198                                         cancelButton.Location = new Point( 475, 324 );
1199                                 }
1200                                 else
1201                                 {
1202                                         mwfFileView.Size = new Size( 449, 282 );
1203                                         fileNameLabel.Location = new Point( 102, 330 );
1204                                         fileNameComboBox.Location = new Point( 195, 330 );
1205                                         fileTypeLabel.Location = new Point( 102, 356 );
1206                                         fileTypeComboBox.Location = new Point( 195, 356 );
1207                                         openSaveButton.Location = new Point( 475, 330 );
1208                                         cancelButton.Location = new Point( 475, 356 );
1209                                 }
1210                                 
1211                                 if ( fileDialog.ShowHelp )
1212                                         helpButton.Show( );
1213                                 
1214                                 if ( fileDialog.ShowReadOnly )
1215                                         checkBox.Show( );
1216                         }
1217                         
1218                         internal class PopupButtonPanel : Panel
1219                         {
1220                                 internal class PopupButton : Control
1221                                 {
1222                                         internal enum PopupButtonState
1223                                         { Normal, Down, Up}
1224                                         
1225                                         private Image image = null;
1226                                         private PopupButtonState popupButtonState = PopupButtonState.Normal;
1227                                         private StringFormat text_format = new StringFormat();
1228                                         
1229                                         public PopupButton( )
1230                                         {
1231                                                 text_format.Alignment = StringAlignment.Center;
1232                                                 text_format.LineAlignment = StringAlignment.Far;
1233                                                 
1234                                                 SetStyle( ControlStyles.DoubleBuffer, true );
1235                                                 SetStyle( ControlStyles.AllPaintingInWmPaint, true );
1236                                                 SetStyle( ControlStyles.UserPaint, true );
1237                                         }
1238                                         
1239                                         public Image Image
1240                                         {
1241                                                 set
1242                                                 {
1243                                                         image = value;
1244                                                         Refresh( );
1245                                                 }
1246                                                 
1247                                                 get
1248                                                 {
1249                                                         return image;
1250                                                 }
1251                                         }
1252                                         
1253                                         public PopupButtonState ButtonState
1254                                         {
1255                                                 set
1256                                                 {
1257                                                         popupButtonState = value;
1258                                                         Refresh( );
1259                                                 }
1260                                                 
1261                                                 get
1262                                                 {
1263                                                         return popupButtonState;
1264                                                 }
1265                                         }
1266                                         
1267                                         protected override void OnPaint( PaintEventArgs pe )
1268                                         {
1269                                                 Draw( pe );
1270                                                 
1271                                                 base.OnPaint( pe );
1272                                         }
1273                                         
1274                                         private void Draw( PaintEventArgs pe )
1275                                         {
1276                                                 Graphics gr = pe.Graphics;
1277                                                 
1278                                                 gr.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush ( BackColor ), ClientRectangle );
1279                                                 
1280                                                 // draw image
1281                                                 if ( image != null )
1282                                                 {
1283                                                         int i_x = ( ClientSize.Width - image.Width ) / 2;
1284                                                         int i_y = 4;
1285                                                         gr.DrawImage( image, i_x, i_y );
1286                                                 }
1287                                                 
1288                                                 if ( Text != String.Empty )
1289                                                 {
1290                                                         Rectangle text_rect = Rectangle.Inflate( ClientRectangle, -4, -4 );
1291                                                         
1292                                                         gr.DrawString( Text, Font, ThemeEngine.Current.ResPool.GetSolidBrush (ForeColor ), text_rect, text_format );
1293                                                 }
1294                                                 
1295                                                 switch ( popupButtonState )
1296                                                 {
1297                                                         case PopupButtonState.Up:
1298                                                                 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, 0, ClientSize.Width - 1, 0 );
1299                                                                 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, 0, 0, ClientSize.Height - 1 );
1300                                                                 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1 );
1301                                                                 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1 );
1302                                                                 break;
1303                                                                 
1304                                                         case PopupButtonState.Down:
1305                                                                 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, 0, ClientSize.Width - 1, 0 );
1306                                                                 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.Black ), 0, 0, 0, ClientSize.Height - 1 );
1307                                                                 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), ClientSize.Width - 1, 0, ClientSize.Width - 1, ClientSize.Height - 1 );
1308                                                                 gr.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ), 0, ClientSize.Height - 1, ClientSize.Width - 1, ClientSize.Height - 1 );
1309                                                                 break;
1310                                                 }
1311                                         }
1312                                         
1313                                         protected override void OnMouseEnter( EventArgs e )
1314                                         {
1315                                                 if ( popupButtonState != PopupButtonState.Down )
1316                                                         popupButtonState = PopupButtonState.Up;
1317                                                 Refresh( );
1318                                                 base.OnMouseEnter( e );
1319                                         }
1320                                         
1321                                         protected override void OnMouseLeave( EventArgs e )
1322                                         {
1323                                                 if ( popupButtonState != PopupButtonState.Down )
1324                                                         popupButtonState = PopupButtonState.Normal;
1325                                                 Refresh( );
1326                                                 base.OnMouseLeave( e );
1327                                         }
1328                                         
1329                                         protected override void OnClick( EventArgs e )
1330                                         {
1331                                                 popupButtonState = PopupButtonState.Down;
1332                                                 Refresh( );
1333                                                 base.OnClick( e );
1334                                         }
1335                                 }
1336                                 
1337                                 private FileDialogPanel fileDialogPanel;
1338                                 
1339                                 private PopupButton lastOpenButton;
1340                                 private PopupButton desktopButton;
1341                                 private PopupButton homeButton;
1342                                 private PopupButton workplaceButton;
1343                                 private PopupButton networkButton;
1344                                 
1345                                 private PopupButton lastPopupButton = null;
1346                                 
1347                                 private ImageList imageList = new ImageList();
1348                                 
1349                                 public PopupButtonPanel( FileDialogPanel fileDialogPanel )
1350                                 {
1351                                         this.fileDialogPanel = fileDialogPanel;
1352                                         
1353                                         BorderStyle = BorderStyle.Fixed3D;
1354                                         BackColor = Color.FromArgb( 128, 128, 128 );
1355                                         Size = new Size( 85, 336 );
1356                                         
1357                                         // use ImageList to scale the bitmaps
1358                                         imageList.ColorDepth = ColorDepth.Depth32Bit;
1359                                         imageList.ImageSize = new Size( 38, 38 );
1360                                         imageList.Images.Add( (Image)Locale.GetResource( "last_open" ) );
1361                                         imageList.Images.Add( (Image)Locale.GetResource( "desktop" ) );
1362                                         imageList.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
1363                                         imageList.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
1364                                         imageList.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
1365                                         imageList.TransparentColor = Color.Transparent;
1366                                         
1367                                         lastOpenButton = new PopupButton( );
1368                                         desktopButton = new PopupButton( );
1369                                         homeButton = new PopupButton( );
1370                                         workplaceButton = new PopupButton( );
1371                                         networkButton = new PopupButton( );
1372                                         
1373                                         lastOpenButton.Size = new Size( 82, 64 );
1374                                         lastOpenButton.Image = imageList.Images[ 0 ];
1375                                         lastOpenButton.BackColor = BackColor;
1376                                         lastOpenButton.ForeColor = Color.White;
1377                                         lastOpenButton.Location = new Point( 2, 2 );
1378                                         lastOpenButton.Text = "Last Open";
1379                                         lastOpenButton.Click += new EventHandler( OnClickButton );
1380                                         
1381                                         desktopButton.Image = imageList.Images[ 1 ];
1382                                         desktopButton.BackColor = BackColor;
1383                                         desktopButton.ForeColor = Color.White;
1384                                         desktopButton.Size = new Size( 82, 64 );
1385                                         desktopButton.Location = new Point( 2, 66 );
1386                                         desktopButton.Text = "Desktop";
1387                                         desktopButton.Click += new EventHandler( OnClickButton );
1388                                         
1389                                         homeButton.Image = imageList.Images[ 2 ];
1390                                         homeButton.BackColor = BackColor;
1391                                         homeButton.ForeColor = Color.White;
1392                                         homeButton.Size = new Size( 82, 64 );
1393                                         homeButton.Location = new Point( 2, 130 );
1394                                         homeButton.Text = "Home";
1395                                         homeButton.Click += new EventHandler( OnClickButton );
1396                                         
1397                                         workplaceButton.Image = imageList.Images[ 3 ];
1398                                         workplaceButton.BackColor = BackColor;
1399                                         workplaceButton.ForeColor = Color.White;
1400                                         workplaceButton.Size = new Size( 82, 64 );
1401                                         workplaceButton.Location = new Point( 2, 194 );
1402                                         workplaceButton.Text = "Workplace";
1403                                         workplaceButton.Click += new EventHandler( OnClickButton );
1404                                         
1405                                         networkButton.Image = imageList.Images[ 4 ];
1406                                         networkButton.BackColor = BackColor;
1407                                         networkButton.ForeColor = Color.White;
1408                                         networkButton.Size = new Size( 82, 64 );
1409                                         networkButton.Location = new Point( 2, 258 );
1410                                         networkButton.Text = "Network";
1411                                         networkButton.Click += new EventHandler( OnClickButton );
1412                                         
1413                                         Controls.Add( lastOpenButton );
1414                                         Controls.Add( desktopButton );
1415                                         Controls.Add( homeButton );
1416                                         Controls.Add( workplaceButton );
1417                                         Controls.Add( networkButton );
1418                                 }
1419                                 
1420                                 void OnClickButton( object sender, EventArgs e )
1421                                 {
1422                                         if ( lastPopupButton != null && (PopupButton)sender != lastPopupButton )
1423                                                 lastPopupButton.ButtonState = PopupButton.PopupButtonState.Normal;
1424                                         lastPopupButton = sender as PopupButton;
1425                                         
1426                                         if ( sender == lastOpenButton )
1427                                         {
1428                                                 
1429                                         }
1430                                         else
1431                                         if ( sender == desktopButton )
1432                                         {
1433                                                 fileDialogPanel.ChangeDirectory( this, Environment.GetFolderPath( Environment.SpecialFolder.Desktop ) );
1434                                         }
1435                                         else
1436                                         if ( sender == homeButton )
1437                                         {
1438                                                 fileDialogPanel.ChangeDirectory( this, Environment.GetFolderPath( Environment.SpecialFolder.Personal ) );
1439                                         }
1440                                         else
1441                                         if ( sender == workplaceButton )
1442                                         {
1443 //                                              fileDialogPanel.ChangeDirectory(this, Environment.GetFolderPath( Environment.SpecialFolder.MyComputer ) );
1444                                         }
1445                                         else
1446                                         if ( sender == networkButton )
1447                                         {
1448                                                 
1449                                         }
1450                                 }
1451                         }
1452                 }
1453         }
1454         
1455         internal struct FilterStruct
1456         {
1457                 public string filterName;
1458                 public StringCollection filters;
1459                 
1460                 public FilterStruct( string filterName, string filter )
1461                 {
1462                         this.filterName = filterName;
1463                         
1464                         filters =  new StringCollection( );
1465                         
1466                         SplitFilters( filter );
1467                 }
1468                 
1469                 private void SplitFilters( string filter )
1470                 {
1471                         string[] split = filter.Split( new Char[] {';'} );
1472                         
1473                         filters.AddRange( split );
1474                 }
1475         }
1476         
1477         internal struct FileStruct
1478         {
1479                 public FileStruct( string fullname, FileAttributes attributes )
1480                 {
1481                         this.fullname = fullname;
1482                         this.attributes = attributes;
1483                 }
1484                 
1485                 public string fullname;
1486                 public FileAttributes attributes;
1487         }
1488         
1489         // MWFFileView
1490         internal class MWFFileView : ListView
1491         {
1492                 private ImageList fileViewSmallImageList = new ImageList();
1493                 private ImageList fileViewBigImageList = new ImageList();
1494                 
1495                 private ArrayList filterArrayList;
1496                 // store the FileStruct of all files in the current directory
1497                 private Hashtable fileHashtable = new Hashtable();
1498                 
1499                 private bool showHiddenFiles = false;
1500                 
1501                 private EventHandler on_selected_file_changed;
1502                 private EventHandler on_selected_files_changed;
1503                 private EventHandler on_directory_changed;
1504                 private EventHandler on_force_dialog_end;
1505                 
1506                 private string fileName;
1507                 private string fullFileName;
1508                 private string selectedFilesString;
1509                 
1510                 private int filterIndex;
1511                 
1512                 public MWFFileView( )
1513                 {
1514                         fileViewSmallImageList.ColorDepth = ColorDepth.Depth32Bit;
1515                         fileViewSmallImageList.ImageSize = new Size( 16, 16 );
1516                         fileViewSmallImageList.Images.Add( (Image)Locale.GetResource( "paper" ) );
1517                         fileViewSmallImageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
1518                         fileViewSmallImageList.TransparentColor = Color.Transparent;
1519                         
1520                         fileViewBigImageList.ColorDepth = ColorDepth.Depth32Bit;
1521                         fileViewBigImageList.ImageSize = new Size( 48, 48 );
1522                         fileViewBigImageList.Images.Add( (Image)Locale.GetResource( "paper" ) );
1523                         fileViewBigImageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
1524                         fileViewBigImageList.TransparentColor = Color.Transparent;
1525                         
1526                         SmallImageList = fileViewSmallImageList;
1527                         LargeImageList = fileViewBigImageList;
1528                         
1529                         View = View.List;
1530                 }
1531                 
1532                 public ArrayList FilterArrayList
1533                 {
1534                         set
1535                         {
1536                                 filterArrayList = value;
1537                         }
1538                         
1539                         get
1540                         {
1541                                 return filterArrayList;
1542                         }
1543                 }
1544                 
1545                 public Hashtable FileHashtable
1546                 {
1547                         set
1548                         {
1549                                 fileHashtable = value;
1550                         }
1551                         
1552                         get
1553                         {
1554                                 return fileHashtable;
1555                         }
1556                 }
1557                 
1558                 public bool ShowHiddenFiles
1559                 {
1560                         set
1561                         {
1562                                 showHiddenFiles = value;
1563                         }
1564                         
1565                         get
1566                         {
1567                                 return showHiddenFiles;
1568                         }
1569                 }
1570                 
1571                 public string FileName
1572                 {
1573                         set
1574                         {
1575                                 fileName = value;
1576                         }
1577                         
1578                         get
1579                         {
1580                                 return fileName;
1581                         }
1582                 }
1583                 
1584                 public string FullFileName
1585                 {
1586                         set
1587                         {
1588                                 fullFileName = value;
1589                         }
1590                         
1591                         get
1592                         {
1593                                 return fullFileName;
1594                         }
1595                 }
1596                 
1597                 public int FilterIndex
1598                 {
1599                         set
1600                         {
1601                                 filterIndex = value;
1602                         }
1603                         
1604                         get
1605                         {
1606                                 return filterIndex;
1607                         }
1608                 }
1609                 
1610                 public string SelectedFilesString
1611                 {
1612                         set
1613                         {
1614                                 selectedFilesString = value;
1615                         }
1616                         
1617                         get
1618                         {
1619                                 return selectedFilesString;
1620                         }
1621                 }
1622                 
1623                 private ArrayList GetFileInfoArrayList( DirectoryInfo directoryInfo )
1624                 {
1625                         ArrayList arrayList = new ArrayList( );
1626                         
1627                         if ( filterArrayList != null && filterArrayList.Count != 0 )
1628                         {
1629                                 FilterStruct fs = (FilterStruct)filterArrayList[ filterIndex - 1 ];
1630                                 
1631                                 foreach ( string s in fs.filters )
1632                                         arrayList.AddRange( directoryInfo.GetFiles( s ) );
1633                         }
1634                         else
1635                                 arrayList.AddRange( directoryInfo.GetFiles( ) );
1636                         
1637                         return arrayList;
1638                 }
1639                 
1640                 public void UpdateFileView( DirectoryInfo inputDirectoryInfo )
1641                 {
1642                         DirectoryInfo directoryInfo = inputDirectoryInfo;
1643                         
1644                         DirectoryInfo[] directoryInfoArray = directoryInfo.GetDirectories( );
1645                         
1646                         ArrayList fileInfoArrayList = GetFileInfoArrayList( directoryInfo );
1647                         
1648                         fileHashtable.Clear( );
1649                         
1650                         BeginUpdate( );
1651                         
1652                         Items.Clear( );
1653                         SelectedItems.Clear( );
1654                         
1655                         foreach ( DirectoryInfo directoryInfoi in directoryInfoArray )
1656                         {
1657                                 if ( !ShowHiddenFiles )
1658                                         if ( directoryInfoi.Name.StartsWith( "." ) || directoryInfoi.Attributes == FileAttributes.Hidden )
1659                                                 continue;
1660                                 
1661                                 FileStruct fileStruct = new FileStruct( );
1662                                 
1663                                 fileStruct.fullname = directoryInfoi.FullName;
1664                                 
1665                                 ListViewItem listViewItem = new ListViewItem( directoryInfoi.Name );
1666                                 
1667                                 listViewItem.ImageIndex = 1;
1668                                 
1669                                 listViewItem.SubItems.Add( "" );
1670                                 listViewItem.SubItems.Add( "Directory" );
1671                                 listViewItem.SubItems.Add( directoryInfoi.LastAccessTime.ToShortDateString( ) + " " + directoryInfoi.LastAccessTime.ToShortTimeString( ) );
1672                                 
1673                                 fileStruct.attributes = FileAttributes.Directory;
1674                                 
1675                                 fileHashtable.Add( directoryInfoi.Name, fileStruct );
1676                                 
1677                                 Items.Add( listViewItem );
1678                         }
1679                         
1680                         foreach ( FileInfo fileInfo in fileInfoArrayList )
1681                         {
1682                                 if ( !ShowHiddenFiles )
1683                                         if ( fileInfo.Name.StartsWith( "." )  || fileInfo.Attributes == FileAttributes.Hidden )
1684                                                 continue;
1685                                 
1686                                 FileStruct fileStruct = new FileStruct( );
1687                                 
1688                                 fileStruct.fullname = fileInfo.FullName;
1689                                 
1690                                 ListViewItem listViewItem = new ListViewItem( fileInfo.Name );
1691                                 
1692                                 listViewItem.ImageIndex = 0;
1693                                 
1694                                 long fileLen = 1;
1695                                 if ( fileInfo.Length > 1024 )
1696                                         fileLen = fileInfo.Length / 1024;
1697                                 
1698                                 listViewItem.SubItems.Add( fileLen.ToString( ) + " KB" );
1699                                 listViewItem.SubItems.Add( "File" );
1700                                 listViewItem.SubItems.Add( fileInfo.LastAccessTime.ToShortDateString( ) + " " + fileInfo.LastAccessTime.ToShortTimeString( ) );
1701                                 
1702                                 fileStruct.attributes = FileAttributes.Normal;
1703                                 
1704                                 fileHashtable.Add( fileInfo.Name, fileStruct );
1705                                 
1706                                 Items.Add( listViewItem );
1707                         }
1708                         
1709                         EndUpdate( );
1710                 }
1711                 
1712                 protected override void OnClick( EventArgs e )
1713                 {
1714                         if ( !MultiSelect )
1715                         {
1716                                 if ( SelectedItems.Count > 0 )
1717                                 {
1718                                         ListViewItem listViewItem = SelectedItems[ 0 ];
1719                                         
1720                                         FileStruct fileStruct = (FileStruct)fileHashtable[ listViewItem.Text ];
1721                                         
1722                                         if ( fileStruct.attributes != FileAttributes.Directory )
1723                                         {
1724                                                 fileName = listViewItem.Text;
1725                                                 fullFileName = fileStruct.fullname;
1726                                                 
1727                                                 if ( on_selected_file_changed != null )
1728                                                         on_selected_file_changed( this, EventArgs.Empty );
1729                                         }
1730                                 }
1731                         }
1732                         
1733                         base.OnClick( e );
1734                 }
1735                 
1736                 protected override void OnDoubleClick( EventArgs e )
1737                 {
1738                         if ( SelectedItems.Count > 0 )
1739                         {
1740                                 ListViewItem listViewItem = SelectedItems[ 0 ];
1741                                 
1742                                 FileStruct fileStruct = (FileStruct)fileHashtable[ listViewItem.Text ];
1743                                 
1744                                 if ( fileStruct.attributes == FileAttributes.Directory )
1745                                 {
1746                                         fullFileName = fileStruct.fullname;
1747                                         
1748                                         if ( on_directory_changed != null )
1749                                                 on_directory_changed( this, EventArgs.Empty );
1750                                 }
1751                                 else
1752                                 {
1753                                         fileName = listViewItem.Text;
1754                                         fullFileName = fileStruct.fullname;
1755                                         
1756                                         if ( on_selected_file_changed != null )
1757                                                 on_selected_file_changed( this, EventArgs.Empty );
1758                                         
1759                                         if ( on_force_dialog_end != null )
1760                                                 on_force_dialog_end( this, EventArgs.Empty );
1761                                         
1762                                         return;
1763                                 }
1764                         }
1765                         
1766                         base.OnDoubleClick( e );
1767                 }
1768                 
1769                 protected override void OnSelectedIndexChanged( EventArgs e )
1770                 {
1771                         if ( MultiSelect )
1772                         {
1773                                 if ( SelectedItems.Count > 0 )
1774                                 {
1775                                         selectedFilesString = "";
1776                                         
1777                                         if ( SelectedItems.Count == 1 )
1778                                         {
1779                                                 FileStruct fileStruct = (FileStruct)fileHashtable[ SelectedItems[ 0 ].Text ];
1780                                                 
1781                                                 if ( fileStruct.attributes != FileAttributes.Directory )
1782                                                         selectedFilesString = SelectedItems[ 0 ].Text;
1783                                         }
1784                                         else
1785                                         {
1786                                                 foreach ( ListViewItem lvi in SelectedItems )
1787                                                 {
1788                                                         FileStruct fileStruct = (FileStruct)fileHashtable[ lvi.Text ];
1789                                                         
1790                                                         if ( fileStruct.attributes != FileAttributes.Directory )
1791                                                                 selectedFilesString += "\"" + lvi.Text + "\" ";
1792                                                 }
1793                                         }
1794                                         
1795                                         if ( on_selected_files_changed != null )
1796                                                 on_selected_files_changed( this, EventArgs.Empty );
1797                                 }
1798                         }
1799                         
1800                         base.OnSelectedIndexChanged( e );
1801                 }
1802                 
1803                 public event EventHandler SelectedFileChanged
1804                 {
1805                         add
1806                         { on_selected_file_changed += value; }
1807                         remove
1808                         { on_selected_file_changed -= value; }
1809                 }
1810                 
1811                 public event EventHandler SelectedFilesChanged
1812                 {
1813                         add
1814                         { on_selected_files_changed += value; }
1815                         remove
1816                         { on_selected_files_changed -= value; }
1817                 }
1818                 
1819                 public event EventHandler DirectoryChanged
1820                 {
1821                         add
1822                         { on_directory_changed += value; }
1823                         remove
1824                         { on_directory_changed -= value; }
1825                 }
1826                 
1827                 public event EventHandler ForceDialogEnd
1828                 {
1829                         add
1830                         { on_force_dialog_end += value; }
1831                         remove
1832                         { on_force_dialog_end -= value; }
1833                 }
1834         }
1835         
1836         internal class FileFilter
1837         {
1838                 private ArrayList filterArrayList = new ArrayList();
1839                 
1840                 private string filter;
1841                 
1842                 public FileFilter( )
1843                 {}
1844                 
1845                 public FileFilter( string filter )
1846                 {
1847                         this.filter = filter;
1848                         
1849                         SplitFilter( );
1850                 }
1851                 
1852                 public ArrayList FilterArrayList
1853                 {
1854                         set
1855                         {
1856                                 filterArrayList = value;
1857                         }
1858                         
1859                         get
1860                         {
1861                                 return filterArrayList;
1862                         }
1863                 }
1864                 
1865                 public string Filter
1866                 {
1867                         set
1868                         {
1869                                 filter = value;
1870                                 
1871                                 SplitFilter( );
1872                         }
1873                         
1874                         get
1875                         {
1876                                 return filter;
1877                         }
1878                 }
1879                 
1880                 private void SplitFilter( )
1881                 {
1882                         filterArrayList.Clear( );
1883                         
1884                         if ( filter == null )
1885                                 throw new NullReferenceException( "Filter" );
1886                         
1887                         if ( filter.Length == 0 )
1888                                 return;
1889                         
1890                         string[] filters = filter.Split( new Char[] {'|'} );
1891                         
1892                         if ( ( filters.Length % 2 ) != 0 )
1893                                 throw new ArgumentException( "Filter" );
1894                         
1895                         for ( int i = 0; i < filters.Length; i += 2 )
1896                         {
1897                                 FilterStruct filterStruct = new FilterStruct( filters[ i ], filters[ i + 1 ] );
1898                                 
1899                                 filterArrayList.Add( filterStruct );
1900                         }
1901                 }
1902         }
1903         
1904         internal class DirComboBox : ComboBox
1905         {
1906                 internal class DirComboBoxItem
1907                 {
1908                         private int imageIndex;
1909                         private string name;
1910                         private string path;
1911                         private int xPos;
1912                         
1913                         public DirComboBoxItem( int imageIndex, string name, string path, int xPos )
1914                         {
1915                                 this.imageIndex = imageIndex;
1916                                 this.name = name;
1917                                 this.path = path;
1918                                 this.XPos = xPos;
1919                         }
1920                         
1921                         public int ImageIndex
1922                         {
1923                                 set
1924                                 {
1925                                         imageIndex = value;
1926                                 }
1927                                 
1928                                 get
1929                                 {
1930                                         return imageIndex;
1931                                 }
1932                         }
1933                         
1934                         public string Name
1935                         {
1936                                 set
1937                                 {
1938                                         name = value;
1939                                 }
1940                                 
1941                                 get
1942                                 {
1943                                         return name;
1944                                 }
1945                         }
1946                         
1947                         public string Path
1948                         {
1949                                 set
1950                                 {
1951                                         path = value;
1952                                 }
1953                                 
1954                                 get
1955                                 {
1956                                         return path;
1957                                 }
1958                         }
1959                         
1960                         public int XPos
1961                         {
1962                                 set
1963                                 {
1964                                         xPos = value;
1965                                 }
1966                                 
1967                                 get
1968                                 {
1969                                         return xPos;
1970                                 }
1971                         }
1972                 }
1973                 
1974                 private ImageList imageList = new ImageList();
1975                 
1976                 private string currentPath;
1977                 
1978                 private bool firstTime = true;
1979                 
1980                 private EventHandler on_directory_changed;
1981                 
1982                 public DirComboBox( )
1983                 {
1984                         DrawMode = DrawMode.OwnerDrawFixed;
1985                         
1986                         imageList.ColorDepth = ColorDepth.Depth32Bit;
1987                         imageList.ImageSize = new Size( 16, 16 );
1988                         imageList.Images.Add( (Image)Locale.GetResource( "last_open" ) );
1989                         imageList.Images.Add( (Image)Locale.GetResource( "desktop" ) );
1990                         imageList.Images.Add( (Image)Locale.GetResource( "folder_with_paper" ) );
1991                         imageList.Images.Add( (Image)Locale.GetResource( "folder" ) );
1992                         imageList.Images.Add( (Image)Locale.GetResource( "monitor-computer" ) );
1993                         imageList.Images.Add( (Image)Locale.GetResource( "monitor-planet" ) );
1994                         imageList.TransparentColor = Color.Transparent;
1995                         
1996                         Items.AddRange( new object[] {
1997                                                new DirComboBoxItem( 1, "Desktop", Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), 0 ),
1998                                                new DirComboBoxItem( 2, "Home", Environment.GetFolderPath( Environment.SpecialFolder.Personal ), 0 )
1999                                        }
2000                                        );
2001                 }
2002                 
2003                 public string CurrentPath
2004                 {
2005                         set
2006                         {
2007                                 currentPath = value;
2008                                 
2009                                 ShowPath( );
2010                         }
2011                         get
2012                         {
2013                                 return currentPath;
2014                         }
2015                 }
2016                 
2017                 private void ShowPath( )
2018                 {
2019                         DirectoryInfo di = new DirectoryInfo( currentPath );
2020                         
2021                         Stack dirStack = new Stack( );
2022                         
2023                         dirStack.Push( di );
2024                         
2025                         while ( di.Parent != null )
2026                         {
2027                                 di = di.Parent;
2028                                 dirStack.Push( di );
2029                         }
2030                         
2031                         BeginUpdate( );
2032                         
2033                         Items.Clear( );
2034                         
2035                         Items.AddRange( new object[] {
2036                                                new DirComboBoxItem( 1, "Desktop", Environment.GetFolderPath( Environment.SpecialFolder.Desktop ), 0 ),
2037                                                new DirComboBoxItem( 2, "Home", Environment.GetFolderPath( Environment.SpecialFolder.Personal ), 0 )
2038                                        }
2039                                        );
2040                         
2041                         int sel = -1;
2042                         
2043                         int xPos = -4;
2044                         
2045                         while ( dirStack.Count != 0 )
2046                         {
2047                                 DirectoryInfo dii = (DirectoryInfo)dirStack.Pop( );
2048                                 sel = Items.Add( new DirComboBoxItem( 3, dii.Name, dii.FullName, xPos + 4 ) );
2049                                 xPos += 4;
2050                         }
2051                         
2052                         if ( sel != -1 )
2053                                 SelectedIndex = sel;
2054                         
2055                         EndUpdate( );
2056                 }
2057                 
2058                 protected override void OnDrawItem( DrawItemEventArgs e )
2059                 {
2060                         if ( e.Index == -1 )
2061                                 return;
2062                         
2063                         Bitmap bmp = new Bitmap( e.Bounds.Width, e.Bounds.Height, e.Graphics );
2064                         Graphics gr = Graphics.FromImage( bmp );
2065                         
2066                         DirComboBoxItem dcbi = Items[ e.Index ] as DirComboBoxItem;
2067                         
2068                         Color backColor = e.BackColor;
2069                         Color foreColor = e.ForeColor;
2070                         
2071                         int xPos = dcbi.XPos;
2072                         
2073                         // Bug in ComboBox !!!!!
2074                         // we never receive DrawItemState.ComboBoxEdit
2075                         if ( ( e.State & DrawItemState.ComboBoxEdit ) != 0 )
2076                                 xPos = 0;
2077                         else
2078                         if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
2079                         {
2080                                 backColor = Color.Blue;
2081                                 foreColor = Color.White;
2082                         }
2083                         
2084                         gr.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush (backColor ), new Rectangle( 0, 0, bmp.Width, bmp.Height ) );
2085                         
2086                         gr.DrawString( dcbi.Name, e.Font , ThemeEngine.Current.ResPool.GetSolidBrush (foreColor ), new Point( 24 + xPos, ( bmp.Height - e.Font.Height ) / 2 ) );
2087                         gr.DrawImage( imageList.Images[ dcbi.ImageIndex ], new Rectangle( new Point( xPos + 2, 0 ), new Size( 16, 16 ) ) );
2088                         
2089                         e.Graphics.DrawImage( bmp, e.Bounds.X, e.Bounds.Y );
2090                 }
2091                 
2092                 protected override void OnSelectedIndexChanged( EventArgs e )
2093                 {
2094                         // do not call ChangeDirectory when invoked from FileDialogPanel ctor...
2095                         if ( firstTime )
2096                         {
2097                                 firstTime = false;
2098                                 return;
2099                         }
2100                         
2101                         if ( Items.Count > 0 )
2102                         {
2103                                 DirComboBoxItem dcbi = Items[ SelectedIndex ] as DirComboBoxItem;
2104                                 
2105                                 currentPath = dcbi.Path;
2106                                 
2107                                 if ( on_directory_changed != null )
2108                                         on_directory_changed( this, EventArgs.Empty );
2109                         }
2110                 }
2111                 
2112                 public event EventHandler DirectoryChanged
2113                 {
2114                         add
2115                         { on_directory_changed += value; }
2116                         remove
2117                         { on_directory_changed -= value; }
2118                 }
2119         }
2120 }
2121
2122