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