1/*
2   NSTextAlternatives.m
3
4   Select an alternative for a given text.
5
6   Copyright (C) 2017 Free Software Foundation, Inc.
7
8   Author: Daniel Ferreira <dtf@stanford.edu>
9   Date: 2017
10
11   This file is part of the GNUstep GUI Library.
12
13   This library is free software; you can redistribute it and/or
14   modify it under the terms of the GNU Lesser General Public
15   License as published by the Free Software Foundation; either
16   version 2 of the License, or (at your option) any later version.
17
18   This library is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
21   Lesser General Public License for more details.
22
23   You should have received a copy of the GNU Lesser General Public
24   License along with this library; see the file COPYING.LIB.
25   If not, see <http://www.gnu.org/licenses/> or write to the
26   Free Software Foundation, 51 Franklin Street, Fifth Floor,
27   Boston, MA 02110-1301, USA.
28*/
29
30#import <AppKit/NSTextAlternatives.h>
31#import <Foundation/Foundation.h>
32
33NSString *NSTextAlternativesSelectedAlternativeStringNotification =
34  @"NSTextAlternativesSelectedAlternativeStringNotification";
35
36@implementation NSTextAlternatives
37- (id)initWithPrimaryString:(NSString *)primaryString
38         alternativeStrings:(NSArray *)alternativeStrings
39{
40  if ((self = [super init]))
41    {
42      _primaryString = RETAIN(primaryString);
43      _alternativeStrings = RETAIN(alternativeStrings);
44    }
45
46  return self;
47}
48
49- (NSString *)primaryString
50{
51  return [_primaryString copy];
52}
53
54- (NSArray *)alternativeStrings
55{
56  return [_alternativeStrings copy];
57}
58
59- (void)noteSelectedAlternativeString:(NSString *)alternativeString
60{
61  NSDictionary *dict =
62    [NSDictionary dictionaryWithObject: alternativeString
63                                forKey: @"NSAlternativeString"];
64
65  [[NSNotificationCenter defaultCenter]
66  postNotificationName: NSTextAlternativesSelectedAlternativeStringNotification
67                object: self
68              userInfo: dict];
69}
70- (void)dealloc
71{
72  RELEASE(_primaryString);
73  RELEASE(_alternativeStrings);
74
75  [super dealloc];
76}
77@end
78