1*323de322SAndrew Rist/**************************************************************
2cdf0e10cSrcweir *
3*323de322SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*323de322SAndrew Rist * or more contributor license agreements.  See the NOTICE file
5*323de322SAndrew Rist * distributed with this work for additional information
6*323de322SAndrew Rist * regarding copyright ownership.  The ASF licenses this file
7*323de322SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*323de322SAndrew Rist * "License"); you may not use this file except in compliance
9*323de322SAndrew Rist * with the License.  You may obtain a copy of the License at
10*323de322SAndrew Rist *
11*323de322SAndrew Rist *   http://www.apache.org/licenses/LICENSE-2.0
12*323de322SAndrew Rist *
13*323de322SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*323de322SAndrew Rist * software distributed under the License is distributed on an
15*323de322SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*323de322SAndrew Rist * KIND, either express or implied.  See the License for the
17*323de322SAndrew Rist * specific language governing permissions and limitations
18*323de322SAndrew Rist * under the License.
19*323de322SAndrew Rist *
20*323de322SAndrew Rist *************************************************************/
21*323de322SAndrew Rist
22*323de322SAndrew Rist
23cdf0e10cSrcweir#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
24cdf0e10cSrcweir#include <com/sun/star/uno/Any.hxx>
25cdf0e10cSrcweir
26cdf0e10cSrcweir#ifndef _SALAQUAFILEPICKER_HXX_
27cdf0e10cSrcweir#include "SalAquaFilePicker.hxx"
28cdf0e10cSrcweir#endif
29cdf0e10cSrcweir
30cdf0e10cSrcweir#ifndef _FILTERHELPER_HXX_
31cdf0e10cSrcweir#include "FilterHelper.hxx"
32cdf0e10cSrcweir#endif
33cdf0e10cSrcweir
34cdf0e10cSrcweir#include "AquaFilePickerDelegate.hxx"
35cdf0e10cSrcweir
36cdf0e10cSrcweir@implementation AquaFilePickerDelegate
37cdf0e10cSrcweir
38cdf0e10cSrcweir- (id)initWithFilePicker:(SalAquaFilePicker*)fPicker
39cdf0e10cSrcweir{
40cdf0e10cSrcweir    if ((self = [super init])) {
41cdf0e10cSrcweir        filePicker = fPicker;
42cdf0e10cSrcweir        filterHelper = NULL;
43cdf0e10cSrcweir        return self;
44cdf0e10cSrcweir    }
45cdf0e10cSrcweir    return nil;
46cdf0e10cSrcweir}
47cdf0e10cSrcweir
48cdf0e10cSrcweir- (void)setFilterHelper:(FilterHelper*)helper
49cdf0e10cSrcweir{
50cdf0e10cSrcweir    filterHelper = helper;
51cdf0e10cSrcweir}
52cdf0e10cSrcweir
53cdf0e10cSrcweir#pragma mark NSSavePanel delegate methods
54cdf0e10cSrcweir
55cdf0e10cSrcweir- (BOOL)panel:(id)sender shouldShowFilename:(NSString *)filename
56cdf0e10cSrcweir{
57cdf0e10cSrcweir    if( filterHelper == NULL )
58cdf0e10cSrcweir        return true;
59cdf0e10cSrcweir    if( filename == nil )
60cdf0e10cSrcweir        return false;
61cdf0e10cSrcweir    return filterHelper->filenameMatchesFilter(filename);
62cdf0e10cSrcweir}
63cdf0e10cSrcweir
64cdf0e10cSrcweir- (void)panelSelectionDidChange:(id)sender
65cdf0e10cSrcweir{
66cdf0e10cSrcweir    if (filePicker != NULL) {
67cdf0e10cSrcweir        ::com::sun::star::ui::dialogs::FilePickerEvent evt;
68cdf0e10cSrcweir        filePicker->fileSelectionChanged(evt);
69cdf0e10cSrcweir    }
70cdf0e10cSrcweir}
71cdf0e10cSrcweir
72cdf0e10cSrcweir- (void)panel:(id)sender directoryDidChange:(NSString *)path
73cdf0e10cSrcweir{
74cdf0e10cSrcweir    if (filePicker != NULL) {
75cdf0e10cSrcweir        ::com::sun::star::ui::dialogs::FilePickerEvent evt;
76cdf0e10cSrcweir        filePicker->directoryChanged(evt);
77cdf0e10cSrcweir    }
78cdf0e10cSrcweir}
79cdf0e10cSrcweir
80cdf0e10cSrcweir
81cdf0e10cSrcweir#pragma mark UIActions
82cdf0e10cSrcweir- (void)filterSelectedAtIndex:(id)sender
83cdf0e10cSrcweir{
84cdf0e10cSrcweir    if (sender == nil) {
85cdf0e10cSrcweir        return;
86cdf0e10cSrcweir    }
87cdf0e10cSrcweir
88cdf0e10cSrcweir    if ([sender class] != [NSPopUpButton class]) {
89cdf0e10cSrcweir        return;
90cdf0e10cSrcweir    }
91cdf0e10cSrcweir
92cdf0e10cSrcweir    if (filterHelper == NULL) {
93cdf0e10cSrcweir        return;
94cdf0e10cSrcweir    }
95cdf0e10cSrcweir
96cdf0e10cSrcweir    NSPopUpButton *popup = (NSPopUpButton*)sender;
97cdf0e10cSrcweir    unsigned int selectedIndex = [popup indexOfSelectedItem];
98cdf0e10cSrcweir
99cdf0e10cSrcweir    filterHelper->SetFilterAtIndex(selectedIndex);
100cdf0e10cSrcweir
101cdf0e10cSrcweir    filePicker->filterControlChanged();
102cdf0e10cSrcweir}
103cdf0e10cSrcweir
104cdf0e10cSrcweir- (void)autoextensionChanged:(id)sender
105cdf0e10cSrcweir{
106cdf0e10cSrcweir    if (sender == nil) {
107cdf0e10cSrcweir        return;
108cdf0e10cSrcweir    }
109cdf0e10cSrcweir
110cdf0e10cSrcweir    if ([sender class] != [NSButton class]) {
111cdf0e10cSrcweir        return;
112cdf0e10cSrcweir    }
113cdf0e10cSrcweir    uno::Any aValue;
114cdf0e10cSrcweir    aValue <<= ([((NSButton*)sender) state] == NSOnState);
115cdf0e10cSrcweir
116cdf0e10cSrcweir    filePicker->setValue(::com::sun::star::ui::dialogs::ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
117cdf0e10cSrcweir}
118cdf0e10cSrcweir
119cdf0e10cSrcweir@end
120