File: GSHelpManagerPanel.m

package info (click to toggle)
gnustep-gui 0.25.0-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 13,088 kB
  • ctags: 3,417
  • sloc: objc: 153,800; ansic: 18,239; cpp: 579; yacc: 462; makefile: 143; sh: 5
file content (137 lines) | stat: -rw-r--r-- 4,320 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/** <title>GSHelpManagerPanel.m</title>

   <abstract>GSHelpManagerPanel displays a help message for an item.</abstract>

   Copyright (C) 1999 Free Software Foundation, Inc.

   Author:  Pedro Ivo Andrade Tavares <ptavares@iname.com>
   Date: September 1999
   
   This file is part of the GNUstep GUI Library.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with this library; see the file COPYING.LIB.
   If not, see <http://www.gnu.org/licenses/> or write to the 
   Free Software Foundation, 51 Franklin Street, Fifth Floor, 
   Boston, MA 02110-1301, USA.
*/ 

#import "AppKit/NSApplication.h"
#import "AppKit/NSAttributedString.h"
#import "AppKit/NSTextView.h"
#import "AppKit/NSTextContainer.h"
#import "AppKit/NSTextStorage.h"
#import "AppKit/NSScrollView.h"
#import "AppKit/NSButton.h"
#import "AppKit/NSClipView.h"
#import "AppKit/NSColor.h"
#import "AppKit/NSImage.h"
#import "GNUstepGUI/GSHelpManagerPanel.h"
#import "GSGuiPrivate.h"

@implementation GSHelpManagerPanel

static GSHelpManagerPanel* _GSsharedGSHelpPanel;

+ (id) sharedHelpManagerPanel
{
  if (!_GSsharedGSHelpPanel)
    _GSsharedGSHelpPanel = [[GSHelpManagerPanel alloc] init];

  return _GSsharedGSHelpPanel;
}

- (id)init
{
  self = [super initWithContentRect: NSMakeRect(100, 100, 470, 200)
		                      styleMask: NSTitledWindowMask | NSResizableWindowMask
		                        backing: NSBackingStoreRetained
		                          defer: NO];
  
  if (self) {
    NSRect scrollViewRect = {{8, 40}, {454, 152}};
    NSRect buttonRect = {{390, 6}, {72, 27}};
    NSRect r;
    NSScrollView *scrollView;
    NSButton *button;
    
    [self setReleasedWhenClosed: NO]; 
    [self setFloatingPanel: YES];
    [self setTitle: NSLocalizedString(@"Help", @"")];

    scrollView = [[NSScrollView alloc] initWithFrame: scrollViewRect];
    [scrollView setBorderType: NSBezelBorder];
    [scrollView setHasHorizontalScroller: NO];
    [scrollView setHasVerticalScroller: YES]; 
    [scrollView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];

    r = [[scrollView contentView] frame];
    textView = [[NSTextView alloc] initWithFrame: r];
    [textView setRichText: YES];
    [textView setEditable: NO];
    [textView setSelectable: NO];
    [textView setHorizontallyResizable: NO];
    [textView setVerticallyResizable: YES];
    [textView setMinSize: NSMakeSize (0, 0)];
    [textView setMaxSize: NSMakeSize (1E7, 1E7)];
    [textView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
    [[textView textContainer] setContainerSize: NSMakeSize(r.size.width, 1e7)];
    [[textView textContainer] setWidthTracksTextView: YES];
    [textView setUsesRuler: NO];
    
    [scrollView setDocumentView: textView];
    RELEASE (textView);
    
    [[self contentView] addSubview: scrollView];
    RELEASE (scrollView);
    
    button = [[NSButton alloc] initWithFrame: buttonRect];
    [button setAutoresizingMask: NSViewMinXMargin | NSViewMaxYMargin];
    [button setButtonType: NSMomentaryLight];
    [button setTitle: NSLocalizedString(@"OK", @"")];
    [button setKeyEquivalent: @"\r"];
    [button setImagePosition: NSImageRight];
    [button setImage: [NSImage imageNamed: @"common_ret"]];
    [button setAlternateImage: [NSImage imageNamed: @"common_retH"]];
	  [button setTarget: self];
	  [button setAction: @selector(buttonAction:)];		

    [[self contentView] addSubview: button];
    RELEASE (button);

    [self makeFirstResponder: button];
  }

  return self;
}

- (void)setHelpText:(NSAttributedString *)helpText
{
  [[textView textStorage] setAttributedString: helpText];
}

- (void)buttonAction:(id)sender
{
  [self close];
}

- (void) close
{
  if ([self isVisible])
    {
      [NSApp stopModal];
    }
  [super close];
}

@end