File: NSHelpPanel.m

package info (click to toggle)
gnustep-gui 0.32.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 15,348 kB
  • sloc: objc: 178,763; ansic: 24,089; cpp: 664; yacc: 464; sh: 90; makefile: 72
file content (220 lines) | stat: -rw-r--r-- 5,419 bytes parent folder | download | duplicates (2)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/** <title>NSHelpPanel</title>

   Copyright (C) 1996 Free Software Foundation, Inc.

   Author: Scott Christley <scottc@net-community.com>
   Date: 1996
   
   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.
*/ 

#include "config.h"
#import "AppKit/NSHelpPanel.h"
#import "AppKit/NSHelpManager.h"
#import "AppKit/NSScrollView.h"
#import "AppKit/NSTextView.h"
#import "AppKit/NSTextContainer.h"
#import "GSGuiPrivate.h" 


@implementation NSApplication (NSHelpPanel)

- (void) orderFrontHelpPanel: sender
{
  // This is implemented in NSHelpManager.m
  [self showHelp: sender];
}

@end

@implementation NSHelpPanel

static NSString	*_helpDirectory = nil;
static NSString	*_helpFile = nil;
static NSHelpPanel	*_sharedPanel = nil;

//
// Class methods
//
+ (void) initialize
{
  if (self == [NSHelpPanel class])
    {
      // Initial version
      [self setVersion: 1];
    }
}

//
// Accessing the Help Panel
//
+ (NSHelpPanel*) sharedHelpPanel
{
  if (_sharedPanel == nil)
    {
      return [self new];
    }
  return _sharedPanel;
}

+ (NSHelpPanel *) sharedHelpPanelWithDirectory: (NSString *)helpDirectory
{
  [self setHelpDirectory: helpDirectory];
  return [self sharedHelpPanel];
}

//
// Managing the Contents
//
+ (void) setHelpDirectory: (NSString *)helpDirectory
{
  ASSIGN(_helpDirectory, helpDirectory);
}

//
// Attaching Help to Objects 
//
+ (void) attachHelpFile: (NSString *)filename
	     markerName: (NSString *)markerName
		     to: (id)anObject
{
  if ([filename isAbsolutePath] == NO)
    {
      filename = [[[NSHelpPanel sharedHelpPanel] helpDirectory]
        stringByAppendingPathComponent: filename];
    }
  [[NSHelpManager sharedHelpManager] setContextHelp: (id)filename
					  forObject: anObject];
}

+ (void) detachHelpFrom: (id)anObject
{
  [[NSHelpManager sharedHelpManager] removeContextHelpForObject: anObject];
}

//
// Instance methods
//
//
// Managing the Contents
//
- (void) addSupplement: (NSString *)helpDirectory
	        inPath: (NSString *)supplementPath
{
}

- (NSString *) helpDirectory
{
  return _helpDirectory;
}

- (NSString *) helpFile
{
  return _helpFile;
}

- (id) initWithContentRect: (NSRect)contentRect
		 styleMask: (NSUInteger)aStyle
		   backing: (NSBackingStoreType)bufferingType
		     defer: (BOOL)flag
{
  if (_sharedPanel == nil)
    {
      NSScrollView	*s;
      NSTextView	*v;
      NSSize		size;

      /* We have a standard start size.
       */
      contentRect = NSMakeRect(100,100,400,500);
      self = [super initWithContentRect: contentRect
	styleMask: NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask
	backing: NSBackingStoreBuffered
	defer: NO];
      if (nil == self)
        return nil;

      [self setReleasedWhenClosed: NO];
      [self setTitle: _(@"Help")];
      s = [[NSScrollView alloc] initWithFrame: contentRect];
      [s setHasHorizontalScroller: YES];
      [s setHasVerticalScroller: YES];
      [s setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
      [self setContentView: s];
      RELEASE(s);

      size = [NSScrollView contentSizeForFrameSize: contentRect.size
                             hasHorizontalScroller: YES
                               hasVerticalScroller: YES
                                        borderType: NSNoBorder];
      v = [[NSTextView alloc] initWithFrame: NSMakeRect(0, 0, size.width, size.height)];
      [v setHorizontallyResizable: YES];
      [v setVerticallyResizable: YES];
      [v setEditable: NO];
      [v setRichText: YES];
      [v setMinSize: NSMakeSize (0, 0)];
      [v setMaxSize: NSMakeSize (1E7, 1E7)];
      [v setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
      [[v textContainer] setContainerSize:
	NSMakeSize (MAX(size.width, 0.0), 1e7)];
      [[v textContainer] setWidthTracksTextView: YES];

      [s setDocumentView: v];
      RELEASE(v);

      _sharedPanel = self;
    }
  else
    {
      RELEASE(self);
      RETAIN(_sharedPanel);
    }
  return _sharedPanel;
}

//
// Showing Help 
//
- (void) showFile: (NSString *)filename
	 atMarker: (NSString *)markerName
{
  if ([filename isAbsolutePath] == NO)
    {
      filename = [[[NSHelpPanel sharedHelpPanel] helpDirectory]
        stringByAppendingPathComponent: filename];
    }
  [[NSHelpManager sharedHelpManager] setContextHelp: (id)filename
                                          forObject: self];
  [self showHelpAttachedTo: self];
}

- (BOOL) showHelpAttachedTo: (id)anObject
{
  return [[NSHelpManager sharedHelpManager]
    showContextHelpForObject: anObject locationHint: NSZeroPoint];
}

//
// Printing 
//
- (void) print: (id)sender
{
}

@end