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