~ubuntu-branches/ubuntu/quantal/texmacs/quantal

« back to all changes in this revision

Viewing changes to src/Plugins/Cocoa/aqua_widget.mm

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA, Kamaraju Kusumanchi, kohda
  • Date: 2009-04-26 19:35:14 UTC
  • mfrom: (1.1.10 upstream) (4.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090426193514-9yo3oggdslgdls4b
Tags: 1:1.0.7.2-1
[Kamaraju Kusumanchi <kamaraju@gmail.com>]
* New upstream release
* texmacs crashes if /usr/share/texmacs/TeXmacs/misc/pixmaps/unknown.ps
  is not present. Do not remove it. (Closes: #484073, #497021)
* update patches 03_mupad.dpatch, 04_axiom.dpatch, 11-desktop-file.dpatch
* fix the mime problem in gnome. Thanks to Andrea Gamba for the fix.
[kohda]
* Refined a fix for the mime problem in gnome a bit.
* Try to fix /bin/sh problem (debian/fixsh) but it is not complete fix yet.
* Try to fix hard coded settings for ipa fonts(patches/09_ipa.dpatch), 
  especially for Debian where no ipa fonts exist yet.
* Fixed obsolete Build-Depends: changed libltdl3-dev to 
  libltdl-dev | libltdl7-dev (the latter for Ubuntu?)

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
* DESCRIPTION: Aqua widget class
5
5
* COPYRIGHT  : (C) 2007  Massimiliano Gubinelli
6
6
*******************************************************************************
7
 
* This software falls under the GNU general public license and comes WITHOUT
8
 
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
9
 
* If you don't have this file, write to the Free Software Foundation, Inc.,
10
 
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
7
* This software falls under the GNU general public license version 3 or later.
 
8
* It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE
 
9
* in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>.
11
10
******************************************************************************/
12
11
 
13
12
#include "mac_cocoa.h" 
30
29
#import "TMView.h"
31
30
#import "TMButtonsController.h"
32
31
 
 
32
#define TYPE_CHECK(b) ASSERT (b, "type mismatch")
 
33
#define NOT_IMPLEMENTED \
 
34
  { if (DEBUG_EVENTS) cout << "STILL NOT IMPLEMENTED\n"; }
 
35
 
33
36
widget the_keyboard_focus(NULL);
34
37
 
35
38
@interface TMWindowController : NSWindowController
41
44
@end
42
45
 
43
46
 
44
 
/******************************************************************************
45
 
 * main renderer
46
 
 ******************************************************************************/
47
 
aqua_renderer_rep *the_renderer = NULL;
48
 
aqua_renderer_rep *the_aqua_renderer() 
49
 
{
50
 
        if (!the_renderer) the_renderer = new aqua_renderer_rep (the_gui);
51
 
        return the_renderer;
52
 
}
53
 
 
54
 
 
55
 
widget aqua_widget_rep::plain_window_widget (string s)
56
 
{
57
 
        return widget ();
58
 
}
59
 
 
60
 
widget aqua_widget_rep::make_popup_widget ()
61
 
{
62
 
        return this;
63
 
}
64
 
 
65
 
widget aqua_widget_rep::popup_window_widget (string s)
66
 
{
67
 
        return widget();
68
 
}
69
 
 
70
 
 
71
 
/******************************************************************************
72
 
 * aqua_view_widget_rep
73
 
 ******************************************************************************/
 
47
 
 
48
widget 
 
49
aqua_widget_rep::plain_window_widget (string s) {
 
50
  (void) s;
 
51
  return widget ();
 
52
}
 
53
 
 
54
widget 
 
55
aqua_widget_rep::make_popup_widget () {
 
56
  return this;
 
57
}
 
58
 
 
59
widget 
 
60
aqua_widget_rep::popup_window_widget (string s) {
 
61
  (void) s;
 
62
  return widget();
 
63
}
 
64
 
 
65
 
 
66
/******************************************************************************
 
67
* aqua_view_widget_rep
 
68
******************************************************************************/
 
69
 
74
70
#pragma mark aqua_view_widget_rep
75
71
 
76
 
aqua_view_widget_rep::aqua_view_widget_rep(NSView *v) : aqua_widget_rep(), view(v) { [v retain]; }
77
 
aqua_view_widget_rep::~aqua_view_widget_rep()  { [view release]; }
 
72
aqua_view_widget_rep::aqua_view_widget_rep(NSView *v) : 
 
73
  aqua_widget_rep(), view(v) { 
 
74
  [v retain]; 
 
75
}
 
76
 
 
77
aqua_view_widget_rep::~aqua_view_widget_rep()  { 
 
78
  [view release]; 
 
79
}
78
80
 
79
81
 
80
82
 
81
83
void
82
84
aqua_view_widget_rep::send (slot s, blackbox val) {
83
85
  switch (s) {
84
 
                case SLOT_NAME:
85
 
                {       
86
 
                        check_type<string> (val, "SLOT_NAME");
87
 
                        string name = open_box<string> (val);
88
 
                        NSWindow *win = [view window];
89
 
                        if (win) {
90
 
                                [win setTitle:to_nsstring(name)];
91
 
                        }
92
 
                }
93
 
                        break;
94
 
                case SLOT_SCROLLBARS_VISIBILITY:
95
 
                        // ignore this: cocoa handles scrollbars independently
96
 
//                      send_int (THIS, "scrollbars", val);
97
 
                        break;
98
 
                case SLOT_INVALIDATE:
99
 
                {
100
 
                        if (type_box (val) != type_helper<coord4>::id)
101
 
                                fatal_error ("type mismatch", "SLOT_INVALIDATE");
102
 
                        coord4 p= open_box<coord4> (val);
103
 
                        NSRect rect = to_nsrect(p);
104
 
                        NSLog(@"invalidating %@",NSStringFromRect(rect));
105
 
                        [view setNeedsDisplayInRect:rect];
106
 
                }
107
 
                        break;
108
 
                case SLOT_EXTENTS:
109
 
                {
110
 
                        if (type_box (val) != type_helper<coord4>::id)
111
 
                                fatal_error ("type mismatch", "SLOT_INVALIDATE");
112
 
                        coord4 p= open_box<coord4> (val);
113
 
                        NSRect rect = to_nsrect(p);
114
 
//                      [[view window] setContentSize:rect.size];
115
 
                        [[(NSScrollView*)view documentView] setFrameSize: rect.size];
116
 
                }
117
 
                        break;
118
 
                case SLOT_INVALIDATE_ALL:
119
 
                {
120
 
                        if (!is_nil (val))
121
 
                                fatal_error ("type mismatch", "SLOT_INVALIDATE_ALL");
122
 
                        [view setNeedsDisplay:YES];
123
 
                }
124
 
                        break;
125
 
 
126
 
                case SLOT_HEADER_VISIBILITY:
127
 
//                      send_bool (THIS, "header", val);
128
 
                        break;
129
 
                case SLOT_MAIN_ICONS_VISIBILITY:
130
 
//                      send_bool (THIS, "main icons", val);
131
 
                        break;
132
 
                case SLOT_CONTEXT_ICONS_VISIBILITY:
133
 
//                      send_bool (THIS, "context icons", val);
134
 
                        break;
135
 
                case SLOT_USER_ICONS_VISIBILITY:
136
 
//                      send_bool (THIS, "user icons", val);
137
 
                        break;
138
 
                case SLOT_FOOTER_VISIBILITY:
139
 
//                      send_bool (THIS, "footer flag", val);
140
 
                        break;
141
 
                
142
 
                case SLOT_MOUSE_GRAB:
143
 
//                      send_mouse_grab (THIS, val);
144
 
                        break;
145
 
                case SLOT_MOUSE_POINTER:
146
 
//                      send_mouse_pointer (THIS, val);
147
 
                        break;
148
 
                case SLOT_SCROLL_POSITION:
149
 
                {
150
 
                        if (type_box (val) != type_helper<coord2>::id)
151
 
                                fatal_error ("type mismatch", "SLOT_SCROLL_POSITION");
152
 
                        coord2 p= open_box<coord2> (val);
153
 
                        NSPoint pt = to_nspoint(p);
154
 
                        [[(NSScrollView*)view documentView] scrollPoint:pt];
155
 
//                      [[(NSScrollView*)view documentView] scrollRectToVisible:NSMakeRect(pt.x,pt.y,1.0,1.0)];
156
 
                }
157
 
                        break;
158
 
                case SLOT_SHRINKING_FACTOR:
159
 
                {
160
 
                        if (type_box (val) != type_helper<int>::id)
161
 
                                fatal_error ("type mismatch", "SLOT_SHRINKING_FACTOR");
162
 
                        //w << set_integer (key, open_box<int> (val));
163
 
                        //FIXME: handle sf
164
 
                }
165
 
                        break;
166
 
                case SLOT_KEYBOARD_FOCUS:
167
 
//                      send_keyboard_focus (THIS, val);
168
 
                {
169
 
                        if (type_box (val) != type_helper<bool>::id)
170
 
                                fatal_error ("type mismatch", "SLOT_KEYBOARD_FOCUS");
171
 
                        if (open_box<bool>(val)) the_keyboard_focus = this;
172
 
                }
173
 
                        break;
174
 
                        
 
86
  case SLOT_NAME:
 
87
    {   
 
88
      check_type<string> (val, "SLOT_NAME");
 
89
      string name = open_box<string> (val);
 
90
      NSWindow *win = [view window];
 
91
      if (win) {
 
92
        [win setTitle:to_nsstring(name)];
 
93
      }
 
94
    }
 
95
    break;
 
96
  case SLOT_INVALIDATE:
 
97
    {
 
98
      TYPE_CHECK (type_box (val) == type_helper<coord4>::id);
 
99
      coord4 p= open_box<coord4> (val);
 
100
      NSRect rect = to_nsrect(p);
 
101
      if (DEBUG_EVENTS) NSLog(@"invalidating %@",NSStringFromRect(rect));
 
102
      [view setNeedsDisplayInRect:rect];
 
103
    }
 
104
    break;
 
105
  case SLOT_INVALIDATE_ALL:
 
106
    {
 
107
      if (!is_nil (val));
 
108
      [view setNeedsDisplay:YES];
 
109
    }
 
110
    break;
 
111
  case SLOT_MOUSE_GRAB:
 
112
    NOT_IMPLEMENTED;
 
113
    //                  send_mouse_grab (THIS, val);
 
114
    break;
 
115
  case SLOT_MOUSE_POINTER:
 
116
    NOT_IMPLEMENTED;
 
117
    //                  send_mouse_pointer (THIS, val);
 
118
    break;
 
119
    
 
120
  case SLOT_KEYBOARD_FOCUS:
 
121
    //                  send_keyboard_focus (THIS, val);
 
122
    {
 
123
      TYPE_CHECK (type_box (val) == type_helper<bool>::id);
 
124
      if (open_box<bool>(val)) the_keyboard_focus = this;
 
125
    }
 
126
    break;
175
127
#if 0
176
 
                case SLOT_SIZE:
177
 
                {
178
 
                        if (type_box (val) != type_helper<coord2>::id)
179
 
                                fatal_error ("type mismatch", "SLOT_SIZE");
180
 
                        coord2 p= open_box<coord2> (val);
181
 
                        NSWindow *win = [view window];
182
 
                        if (win) {
183
 
                                NSRect frame = [win frame];
184
 
                                NSSize s = to_nssize(p);
185
 
                                frame.size = s;
186
 
                                [win setFrame:frame display:YES];
187
 
                        }
188
 
                }
189
 
                        break;
190
 
                case SLOT_POSITION:
191
 
                {
192
 
                        if (type_box (val) != type_helper<coord2>::id)
193
 
                                fatal_error ("type mismatch", "SLOT_POSITION");
194
 
                        coord2 p= open_box<coord2> (val);
195
 
                        NSWindow *win = [view window];
196
 
                        if (win) {
197
 
                                [win setFrameTopLeftPoint:to_nspoint(p)];
198
 
                        }
199
 
                }
200
 
                        break;
201
 
                case SLOT_VISIBILITY:
202
 
                {       
203
 
                        check_type<bool> (val, "SLOT_VISIBILITY");
204
 
                        bool flag = open_box<bool> (val);
205
 
                        NSWindow *win = [view window];
206
 
                        if (win) {
207
 
                                if (flag)
208
 
                                        [win makeKeyAndOrderFront:nil] ;
209
 
                                else 
210
 
                                        [win orderOut:nil]  ;
211
 
                        }
212
 
                }       
213
 
                        break;
214
 
                case SLOT_IDENTIFIER:
215
 
                        check_type<int> (val, "SLOT_IDENTIFIER");
216
 
                        THIS << emit_attach_window (get_window (open_box<int> (val)));
217
 
                        break;
218
 
                case SLOT_FULL_SCREEN:
219
 
                        check_type<bool> (val, "SLOT_FULL_SCREEN");
220
 
                        win->set_full_screen (open_box<bool> (val));
221
 
                        break;
222
 
                case SLOT_UPDATE:
223
 
                        send_update (THIS, val);
224
 
                        break;
225
 
                case SLOT_KEYBOARD:
226
 
                        send_keyboard (THIS, val);
227
 
                        break;
228
 
                case SLOT_MOUSE:
229
 
                        send_mouse (THIS, val);
230
 
                        break;
231
 
                case SLOT_REPAINT:
232
 
                        send_repaint (THIS, val);
233
 
                        break;
234
 
                case SLOT_DELAYED_MESSAGE:
235
 
                        send_delayed_message (THIS, val);
236
 
                        break;
237
 
                case SLOT_DESTROY:
238
 
                        send_destroy (THIS, val);
239
 
                        break;
240
 
                        
241
 
                case SLOT_EXTENTS:
242
 
                        send_coord4 (THIS, "extents", val);
243
 
                        break;
244
 
                case SLOT_SCROLLBARS_VISIBILITY:
245
 
                        send_int (THIS, "scrollbars", val);
246
 
                        break;
247
 
                        
248
 
                case SLOT_INTERACTIVE_MODE:
249
 
                        send_bool (THIS, "interactive mode", val);
250
 
                        break;
251
 
                        
252
 
                case SLOT_STRING_INPUT:
253
 
                        send_string (THIS, "input", val);
254
 
                        break;
255
 
                case SLOT_INPUT_TYPE:
256
 
                        send_string (THIS, "type", val);
257
 
                        break;
258
 
                case SLOT_INPUT_PROPOSAL:
259
 
                        send_string (THIS, "default", val);
260
 
                        break;
261
 
                case SLOT_FILE:
262
 
                        send_string (THIS, "file", val);
263
 
                        break;
264
 
                case SLOT_DIRECTORY:
265
 
                        send_string (THIS, "directory", val);
266
 
                        break;
 
128
  case SLOT_EXTENTS:
 
129
    {
 
130
      TYPE_CHECK (type_box (val) == type_helper<coord4>::id);
 
131
      coord4 p= open_box<coord4> (val);
 
132
      NSRect rect = to_nsrect(p);
 
133
      //                        [[view window] setContentSize:rect.size];
 
134
      [[(NSScrollView*)view documentView] setFrameSize: rect.size];
 
135
    }
 
136
    break;
 
137
    
 
138
  case SLOT_HEADER_VISIBILITY:
 
139
    //                  send_bool (THIS, "header", val);
 
140
    break;
 
141
  case SLOT_MAIN_ICONS_VISIBILITY:
 
142
    //                  send_bool (THIS, "main icons", val);
 
143
    break;
 
144
  case SLOT_CONTEXT_ICONS_VISIBILITY:
 
145
    //                  send_bool (THIS, "context icons", val);
 
146
    break;
 
147
  case SLOT_USER_ICONS_VISIBILITY:
 
148
    //                  send_bool (THIS, "user icons", val);
 
149
    break;
 
150
  case SLOT_FOOTER_VISIBILITY:
 
151
    //                  send_bool (THIS, "footer flag", val);
 
152
    break;
 
153
    
 
154
  case SLOT_SCROLL_POSITION:
 
155
    {
 
156
      TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
 
157
      coord2 p= open_box<coord2> (val);
 
158
      NSPoint pt = to_nspoint(p);
 
159
      [[(NSScrollView*)view documentView] scrollPoint:pt];
 
160
      //                        [[(NSScrollView*)view documentView] scrollRectToVisible:NSMakeRect(pt.x,pt.y,1.0,1.0)];
 
161
    }
 
162
    break;
 
163
  case SLOT_SHRINKING_FACTOR:
 
164
    {
 
165
      TYPE_CHECK (type_box (val) == type_helper<int>::id);
 
166
      //w << set_integer (key, open_box<int> (val));
 
167
      //FIXME: handle sf
 
168
    }
 
169
    break;
 
170
    
 
171
  case SLOT_SIZE:
 
172
    {
 
173
      TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
 
174
      coord2 p= open_box<coord2> (val);
 
175
      NSWindow *win = [view window];
 
176
      if (win) {
 
177
        NSRect frame = [win frame];
 
178
        NSSize s = to_nssize(p);
 
179
        frame.size = s;
 
180
        [win setFrame:frame display:YES];
 
181
      }
 
182
    }
 
183
    break;
 
184
  case SLOT_POSITION:
 
185
    {
 
186
      TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
 
187
      coord2 p= open_box<coord2> (val);
 
188
      NSWindow *win = [view window];
 
189
      if (win) {
 
190
        [win setFrameTopLeftPoint:to_nspoint(p)];
 
191
      }
 
192
    }
 
193
    break;
 
194
  case SLOT_VISIBILITY:
 
195
    {   
 
196
      check_type<bool> (val, "SLOT_VISIBILITY");
 
197
      bool flag = open_box<bool> (val);
 
198
      NSWindow *win = [view window];
 
199
      if (win) {
 
200
        if (flag)
 
201
          [win makeKeyAndOrderFront:nil] ;
 
202
        else 
 
203
          [win orderOut:nil]  ;
 
204
      }
 
205
    }   
 
206
    break;
 
207
  case SLOT_IDENTIFIER:
 
208
    check_type<int> (val, "SLOT_IDENTIFIER");
 
209
    THIS << emit_attach_window (get_window (open_box<int> (val)));
 
210
    break;
 
211
  case SLOT_FULL_SCREEN:
 
212
    check_type<bool> (val, "SLOT_FULL_SCREEN");
 
213
    win->set_full_screen (open_box<bool> (val));
 
214
    break;
 
215
  case SLOT_UPDATE:
 
216
    send_update (THIS, val);
 
217
    break;
 
218
  case SLOT_KEYBOARD:
 
219
    send_keyboard (THIS, val);
 
220
    break;
 
221
  case SLOT_MOUSE:
 
222
    send_mouse (THIS, val);
 
223
    break;
 
224
  case SLOT_REPAINT:
 
225
    send_repaint (THIS, val);
 
226
    break;
 
227
  case SLOT_DELAYED_MESSAGE:
 
228
    send_delayed_message (THIS, val);
 
229
    break;
 
230
  case SLOT_DESTROY:
 
231
    send_destroy (THIS, val);
 
232
    break;
 
233
    
 
234
  case SLOT_EXTENTS:
 
235
    send_coord4 (THIS, "extents", val);
 
236
    break;
 
237
  case SLOT_SCROLLBARS_VISIBILITY:
 
238
    send_int (THIS, "scrollbars", val);
 
239
    break;
 
240
    
 
241
  case SLOT_INTERACTIVE_MODE:
 
242
    send_bool (THIS, "interactive mode", val);
 
243
    break;
 
244
    
 
245
  case SLOT_STRING_INPUT:
 
246
    send_string (THIS, "input", val);
 
247
    break;
 
248
  case SLOT_INPUT_TYPE:
 
249
    send_string (THIS, "type", val);
 
250
    break;
 
251
  case SLOT_INPUT_PROPOSAL:
 
252
    send_string (THIS, "default", val);
 
253
    break;
 
254
  case SLOT_FILE:
 
255
    send_string (THIS, "file", val);
 
256
    break;
 
257
  case SLOT_DIRECTORY:
 
258
    send_string (THIS, "directory", val);
 
259
    break;
267
260
#endif                  
268
 
                default:
269
 
                        fatal_error ("cannot handle slot type", "aqua_view_widget_rep::send");
 
261
  default:
 
262
    FAILED ("cannot handle slot type");
270
263
  }
271
264
}
272
265
 
273
266
/******************************************************************************
274
 
 * Querying
275
 
 ******************************************************************************/
 
267
* Querying
 
268
******************************************************************************/
276
269
 
277
270
blackbox
278
271
aqua_view_widget_rep::query (slot s, int type_id) {
279
272
  switch (s) {
280
 
                case SLOT_IDENTIFIER:
281
 
                        if (type_id != type_helper<int>::id)
282
 
                                fatal_error ("int expected (SLOT_IDENTIFIER)", "aqua_view_widget_rep::query");
283
 
                        return close_box<int> ((int)[view window]);
284
 
                        case SLOT_RENDERER:
285
 
                        if (type_id != type_helper<renderer>::id)
286
 
                                fatal_error ("renderer expected (SLOT_RENDERER)",
287
 
                                                                                 "aqua_view_widget_rep::query");
288
 
                        return close_box<renderer> ((renderer) the_aqua_renderer());
289
 
                        case SLOT_VISIBLE_PART:
290
 
                {
291
 
                        if (type_id != type_helper<coord4>::id)
292
 
                                fatal_error ("type mismatch", "SLOT_VISIBLE_PART");
293
 
                        NSRect rect = [view visibleRect];
294
 
                        coord4 c = from_nsrect(rect);
295
 
                        return close_box<coord4> (c);
296
 
                }
297
 
 
298
 
                        case SLOT_SCROLL_POSITION:
299
 
                {
300
 
                        if (type_id != type_helper<coord2>::id)
301
 
                                fatal_error ("type mismatch", "SLOT_SCROLL_POSITION");
302
 
                        NSPoint pt = [[(NSScrollView *)view contentView] bounds].origin;
303
 
                        return close_box<coord2> (from_nspoint(pt));
304
 
                }
305
 
                        
306
 
                        case SLOT_POSITION:  
307
 
                {
308
 
                        typedef pair<SI,SI> coord2;
309
 
                        if (type_id != type_helper<coord2>::id)
310
 
                                fatal_error ("type mismatch (SLOT_POSITION)", "aqua_view_widget_rep::query");
311
 
                        return close_box<coord2> (coord2(0,0)); //FIXME: fake position
312
 
                }
313
 
                        
 
273
  case SLOT_IDENTIFIER:
 
274
    TYPE_CHECK (type_id == type_helper<int>::id);
 
275
    return close_box<int> ((int)[view window] ? 1 : 0);
 
276
  case SLOT_RENDERER:
 
277
    TYPE_CHECK (type_id == type_helper<renderer>::id);
 
278
    return close_box<renderer> ((renderer) the_aqua_renderer());
314
279
#if 0
315
 
 
316
 
                        case SLOT_SIZE:
317
 
                        return query_size (THIS, type_id);
318
 
                        case SLOT_POSITION:
319
 
                        return query_position (THIS, type_id);
320
 
                        case SLOT_KEYBOARD_FOCUS:
321
 
                        return query_keyboard_focus (THIS, type_id);
322
 
                        case SLOT_MOUSE_GRAB:
323
 
                        return query_mouse_grab (THIS, type_id);
324
 
                        
325
 
                        case SLOT_EXTENTS:
326
 
                        return query_coord4 (THIS, "extents", type_id);
327
 
                        case SLOT_SCROLLBARS_VISIBILITY:
328
 
                        return query_int (THIS, "scrollbars", type_id);
329
 
                        
330
 
                        case SLOT_INTERACTIVE_MODE:
331
 
                        return query_bool (THIS, "interactive mode", type_id);
332
 
                        case SLOT_INTERACTIVE_INPUT:
333
 
                        return query_string (THIS, "interactive input", type_id);
334
 
                        
335
 
                        case SLOT_STRING_INPUT:
336
 
                        return query_string (THIS, "input", type_id);
 
280
  case SLOT_VISIBLE_PART:
 
281
    {
 
282
      TYPE_CHECK (type_id == type_helper<coord4>::id);
 
283
      NSRect rect = [view visibleRect];
 
284
      coord4 c = from_nsrect(rect);
 
285
      return close_box<coord4> (c);
 
286
    }
337
287
#endif
338
 
                        default:
339
 
                        fatal_error ("cannot handle slot type", "aqua_view_widget_rep::query");
340
 
                        return blackbox ();
 
288
  case SLOT_POSITION:  
 
289
    {
 
290
      typedef pair<SI,SI> coord2;
 
291
      TYPE_CHECK (type_id == type_helper<coord2>::id);
 
292
      NSPoint pos = [view frame].origin;
 
293
      return close_box<coord2> (from_nspoint(pos));
 
294
    }
 
295
    
 
296
  default:
 
297
    FAILED ("cannot handle slot type");
 
298
    return blackbox ();
341
299
  }
342
300
}
343
301
 
347
305
 
348
306
void
349
307
aqua_view_widget_rep::notify (slot s, blackbox new_val) {
350
 
  switch (s) {
351
 
#if 0
352
 
                case SLOT_SIZE:
353
 
                        check_type<SI,SI> (new_val, "SLOT_SIZE");
354
 
                        THIS << emit_resize ();
355
 
                        if (is_window_widget ())
356
 
                                send_size (THIS [0], new_val);
357
 
                        break;
358
 
                        case SLOT_POSITION:
359
 
                        check_type<SI,SI> (new_val, "SLOT_POSITION");
360
 
                        THIS << emit_move ();
361
 
                        break;
362
 
                        case SLOT_KEYBOARD_FOCUS:
363
 
                        notify_keyboard_focus (THIS, new_val);
364
 
                        break;
365
 
                        case SLOT_MOUSE_GRAB:
366
 
                        notify_mouse_grab (THIS, new_val);
367
 
                        break;
368
 
#endif
369
 
                        default: ;
370
 
  }
371
308
  aqua_widget_rep::notify (s, new_val);
372
309
}
373
310
 
378
315
widget
379
316
aqua_view_widget_rep::read (slot s, blackbox index) {
380
317
  switch (s) {
381
 
                case SLOT_WINDOW:
382
 
                        check_type_void (index, "SLOT_WINDOW");
383
 
                        return [(TMWindowController*)[[view window] windowController] widget];
384
 
#if 0
385
 
                case SLOT_WINDOW:
386
 
                        check_type_void (index, "SLOT_WINDOW");
387
 
                        return win -> get_widget ();
388
 
                case SLOT_FORM_FIELD:
389
 
                        check_type<int> (index, "SLOT_FORM_FIELD");
390
 
                        return abstract (THIS [0] ["inputs"] [open_box<int> (index)] ["input"]);
391
 
                case SLOT_FILE:
392
 
                        check_type_void (index, "SLOT_FILE");
393
 
                        return abstract (THIS [0] ["file"] ["input"]);
394
 
                case SLOT_DIRECTORY:
395
 
                        check_type_void (index, "SLOT_DIRECTORY");
396
 
                        return abstract (THIS [0] ["directory"] ["input"]);
397
 
#endif
398
 
                default:
399
 
                        fatal_error ("cannot handle slot type", "aqua_view_widget_rep::read");
400
 
                        return widget();
 
318
  case SLOT_WINDOW:
 
319
    check_type_void (index, "SLOT_WINDOW");
 
320
    return [(TMWindowController*)[[view window] windowController] widget];
 
321
  default:
 
322
    FAILED ("cannot handle slot type");
 
323
    return widget();
401
324
  }
402
325
}
403
326
 
404
327
void
405
328
aqua_view_widget_rep::write (slot s, blackbox index, widget w) {
406
329
  switch (s) {
407
 
#if 0
408
 
                case SLOT_CANVAS: 
409
 
                {
410
 
                        check_type_void (index, "SLOT_CANVAS");
411
 
                        NSView *v = concrete (w)->get_nsview();
412
 
                        NSScrollView *sv = (NSScrollView*) view;
413
 
                        [sv setDocumentView: v];
414
 
                        [[sv window] makeFirstResponder:v];
415
 
                }
416
 
                        break;
417
 
                case SLOT_MAIN_MENU:
418
 
                        check_type_void (index, "SLOT_MAIN_MENU");
419
 
                        [NSApp setMainMenu: to_nsmenu(w)];
420
 
//                      THIS << set_widget ("menu bar", concrete (w));
421
 
                        break;
422
 
                case SLOT_MAIN_ICONS:
423
 
                        check_type_void (index, "SLOT_MAIN_ICONS");
424
 
//                      THIS << set_widget ("main icons bar", concrete (w));
425
 
                        break;
426
 
                case SLOT_CONTEXT_ICONS:
427
 
                        check_type_void (index, "SLOT_CONTEXT_ICONS");
428
 
//                      THIS << set_widget ("context icons bar", concrete (w));
429
 
                        break;
430
 
                case SLOT_USER_ICONS:
431
 
                        check_type_void (index, "SLOT_USER_ICONS");
432
 
//                      THIS << set_widget ("user icons bar", concrete (w));
433
 
                        break;
434
 
#endif
435
 
                default:
436
 
                        fatal_error ("cannot handle slot type", "aqua_view_widget_rep::write");
 
330
  default:
 
331
    FAILED ("cannot handle slot type");
437
332
  }
438
333
}
439
334
 
440
335
 
441
 
widget aqua_view_widget_rep::plain_window_widget (string s)
 
336
widget 
 
337
aqua_view_widget_rep::plain_window_widget (string s)
442
338
// creates a decorated window with name s and contents w
443
339
{
444
 
        NSRect screen_frame = [[NSScreen mainScreen] visibleFrame];
 
340
  NSRect screen_frame = [[NSScreen mainScreen] visibleFrame];
445
341
        
446
342
  NSWindow *nsw = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,100,100) 
447
 
                                                                                                                                                                                         styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
448
 
                                                                                                                                                                                                 backing:NSBackingStoreBuffered
449
 
                                                                                                                                                                                                         defer:NO] autorelease];
450
 
 // NSView *view = ((aqua_view_widget_rep*)w.rep)->get_nsview();
451
 
        //      NSRect frame = [[nsw contentView] frame];
452
 
        //      [view setFrame:frame];
 
343
                                     styleMask:NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask
 
344
                                     backing:NSBackingStoreBuffered
 
345
                                     defer:NO] autorelease];
 
346
  // NSView *view = ((aqua_view_widget_rep*)w.rep)->get_nsview();
 
347
  //    NSRect frame = [[nsw contentView] frame];
 
348
  //    [view setFrame:frame];
453
349
  [nsw setContentView:view];
454
 
        [nsw setTitle:to_nsstring(s)];
455
 
        //      [[nsw contentView] addSubview:view];
456
 
//      [nsw setToolbar:((aqua_tm_widget_rep*)w.rep)->toolbar];
457
 
        widget wid =  new aqua_window_widget_rep(nsw);
458
 
        return wid; 
 
350
  [nsw setTitle:to_nsstring(s)];
 
351
  [nsw setAcceptsMouseMovedEvents:YES];
 
352
  //    [[nsw contentView] addSubview:view];
 
353
  //    [nsw setToolbar:((aqua_tm_widget_rep*)w.rep)->toolbar];
 
354
  widget wid =  tm_new <aqua_window_widget_rep> (nsw);
 
355
  return wid; 
459
356
}
460
357
 
461
358
 
462
359
#pragma mark aqua_tm_widget_rep
463
360
 
464
 
 
465
361
NSString *TMToolbarIdentifier = @"TMToolbarIdentifier";
466
362
NSString *TMButtonsIdentifier = @"TMButtonsIdentifier";
467
363
 
470
366
@implementation TMToolbarItem
471
367
- (void)validate
472
368
{
473
 
        NSSize s = [[self view] frame].size;
474
 
        NSSize s2 = [self minSize];
475
 
        if ((s.width != s2.width)||(s.height!=s2.height)) {
476
 
                [self setMinSize:s];
477
 
                [self setMaxSize:s];
478
 
        }
479
 
//      NSLog(@"validate\n");
 
369
  NSSize s = [[self view] frame].size;
 
370
  NSSize s2 = [self minSize];
 
371
  if ((s.width != s2.width)||(s.height!=s2.height)) {
 
372
    [self setMinSize:s];
 
373
    [self setMaxSize:s];
 
374
  }
 
375
  //    NSLog(@"validate\n");
480
376
}
481
377
@end
482
378
 
484
380
 
485
381
@interface TMWidgetHelper : NSObject
486
382
{
487
 
        @public
488
 
        aqua_tm_widget_rep *wid;
489
 
        NSToolbarItem *ti;
 
383
@public
 
384
  aqua_tm_widget_rep *wid;
 
385
  NSToolbarItem *ti;
490
386
}
491
387
- (void)notify:(NSNotification*)obj;
492
388
@end
494
390
@implementation TMWidgetHelper
495
391
-(void)dealloc
496
392
{
497
 
        [ti release]; [super dealloc];
 
393
  [ti release]; [super dealloc];
498
394
}
499
395
- (void)notify:(NSNotification*)n
500
396
{
501
 
        wid->layout();
 
397
  wid->layout();
502
398
}
503
399
- (NSToolbarItem *)toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier willBeInsertedIntoToolbar:(BOOL)flag
504
400
{
505
 
        if (itemIdentifier == TMButtonsIdentifier) {
506
 
                if (!ti) {
507
 
                        ti = [[TMToolbarItem alloc] initWithItemIdentifier:TMButtonsIdentifier];
508
 
                        [ti setView:[wid->bc bar]];
509
 
                        NSRect f = [[wid->bc bar] frame];
510
 
                //      NSSize s = NSMakeSize(900,70);
511
 
                        NSSize s = f.size;
512
 
                        [ti setMinSize:s];
513
 
                        [ti setMaxSize:s];
514
 
                        
515
 
                }
516
 
                return ti;
517
 
        }
518
 
        return nil;
 
401
  if (itemIdentifier == TMButtonsIdentifier) {
 
402
    if (!ti) {
 
403
      ti = [[TMToolbarItem alloc] initWithItemIdentifier:TMButtonsIdentifier];
 
404
      [ti setView:[wid->bc bar]];
 
405
      NSRect f = [[wid->bc bar] frame];
 
406
      //        NSSize s = NSMakeSize(900,70);
 
407
      NSSize s = f.size;
 
408
      [ti setMinSize:s];
 
409
      [ti setMaxSize:s];
 
410
      
 
411
    }
 
412
    return ti;
 
413
  }
 
414
  return nil;
519
415
}
520
416
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
521
417
{
522
 
        return [NSArray arrayWithObjects:TMButtonsIdentifier,nil];
 
418
  return [NSArray arrayWithObjects:TMButtonsIdentifier,nil];
523
419
}
524
420
- (NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar
525
421
{
526
 
        return [NSArray arrayWithObjects:TMButtonsIdentifier,nil];
 
422
  return [NSArray arrayWithObjects:TMButtonsIdentifier,nil];
527
423
}
528
424
@end
529
425
 
530
426
 
531
 
aqua_tm_widget_rep::aqua_tm_widget_rep() : aqua_view_widget_rep([[[NSView alloc] initWithFrame:NSMakeRect(0,0,100,100)] autorelease]), 
532
 
                sv(nil), leftField(nil), rightField(nil), bc(nil), toolbar(nil) 
 
427
aqua_tm_widget_rep::aqua_tm_widget_rep(int mask) : aqua_view_widget_rep([[[NSView alloc] initWithFrame:NSMakeRect(0,0,100,100)] autorelease]), 
 
428
  sv(nil), leftField(nil), rightField(nil), bc(nil), toolbar(nil) 
533
429
{
534
 
        NSSize s = NSMakeSize(100,20); // size of the right footer;
535
 
        NSRect r = [view bounds];
536
 
        NSRect r0 = r;
537
 
//      r.size.height -= 100;
538
 
//      r0.origin.y =+ r.size.height; r0.size.height = 100;
539
 
        NSRect r1 = r; r1.origin.y += s.height; r1.size.height -= s.height;
540
 
        NSRect r2 = r; r2.size.height = s.height;
541
 
        NSRect r3 = r2; 
542
 
        r2.size.width -= s.width; r3.origin.x =+ r2.size.width;
543
 
        sv = [[[NSScrollView alloc] initWithFrame:r1] autorelease];
544
 
        [sv setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
545
 
        [sv setHasVerticalScroller:YES];
546
 
        [sv setHasHorizontalScroller:YES];
547
 
        [sv setBorderType:NSNoBorder];
548
 
  [sv setBackgroundColor:[NSColor redColor]];
549
 
        [sv setDocumentView:[[[NSView alloc] initWithFrame: NSMakeRect(0,0,100,100)] autorelease]];
550
 
        [view addSubview:sv];
551
 
        
552
 
        leftField = [[[NSTextField alloc] initWithFrame:r2] autorelease];
553
 
        rightField = [[[NSTextField alloc] initWithFrame:r3] autorelease];
554
 
        [leftField setAutoresizingMask:NSViewWidthSizable|NSViewMaxYMargin];
555
 
        [rightField setAutoresizingMask:NSViewMinXMargin|NSViewMaxYMargin];
556
 
        [leftField setEditable: NO];
557
 
        [rightField setEditable: NO];
558
 
        [leftField setBackgroundColor:[NSColor windowFrameColor]];
559
 
        [rightField setBackgroundColor:[NSColor windowFrameColor]];
560
 
        [leftField setBezeled:NO];
561
 
        [rightField setBezeled:NO];
562
 
        [rightField setAlignment:NSRightTextAlignment];
563
 
        [view addSubview:leftField];
564
 
        [view addSubview:rightField];
565
 
        
566
 
        bc = [[TMButtonsController alloc] init];
567
 
        //NSView *mt = [bc bar];
568
 
        //[mt setFrame:r0];
569
 
        //[mt setAutoresizingMask:NSViewMaxXMargin|NSViewMinYMargin];
570
 
        //[view addSubview:mt];
571
 
//      [mt setPostsFrameChangedNotifications:YES];
572
 
        wh = [[TMWidgetHelper alloc] init];
573
 
        wh->wid = this;
 
430
  // decode mask
 
431
  visibility[0] = (mask & 1)  == 1;  // header
 
432
  visibility[1] = (mask & 2)  == 2;  // main
 
433
  visibility[2] = (mask & 4)  == 4;  // context
 
434
  visibility[3] = (mask & 8)  == 8;  // user
 
435
  visibility[4] = (mask & 16) == 16; // footer
 
436
  
 
437
  
 
438
  NSSize s = NSMakeSize(100,20); // size of the right footer;
 
439
  NSRect r = [view bounds];
 
440
  NSRect r0 = r;
 
441
  //    r.size.height -= 100;
 
442
  //    r0.origin.y =+ r.size.height; r0.size.height = 100;
 
443
  NSRect r1 = r; r1.origin.y += s.height; r1.size.height -= s.height;
 
444
  NSRect r2 = r; r2.size.height = s.height;
 
445
  NSRect r3 = r2; 
 
446
  r2.size.width -= s.width; r3.origin.x =+ r2.size.width;
 
447
  sv = [[[NSScrollView alloc] initWithFrame:r1] autorelease];
 
448
  [sv setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
 
449
  [sv setHasVerticalScroller:YES];
 
450
  [sv setHasHorizontalScroller:YES];
 
451
  [sv setBorderType:NSNoBorder];
 
452
  //  [sv setBackgroundColor:[NSColor redColor]];
 
453
  [sv setBackgroundColor:[NSColor grayColor]];
 
454
  [sv setDocumentView:[[[NSView alloc] initWithFrame: NSMakeRect(0,0,100,100)] autorelease]];
 
455
  [view addSubview:sv];
 
456
  
 
457
  leftField = [[[NSTextField alloc] initWithFrame:r2] autorelease];
 
458
  rightField = [[[NSTextField alloc] initWithFrame:r3] autorelease];
 
459
  [leftField setAutoresizingMask:NSViewWidthSizable|NSViewMaxYMargin];
 
460
  [rightField setAutoresizingMask:NSViewMinXMargin|NSViewMaxYMargin];
 
461
  [leftField setEditable: NO];
 
462
  [rightField setEditable: NO];
 
463
  [leftField setBackgroundColor:[NSColor windowFrameColor]];
 
464
  [rightField setBackgroundColor:[NSColor windowFrameColor]];
 
465
  [leftField setBezeled:NO];
 
466
  [rightField setBezeled:NO];
 
467
  [rightField setAlignment:NSRightTextAlignment];
 
468
  [view addSubview:leftField];
 
469
  [view addSubview:rightField];
 
470
  
 
471
  bc = [[TMButtonsController alloc] init];
 
472
  //NSView *mt = [bc bar];
 
473
  //[mt setFrame:r0];
 
474
  //[mt setAutoresizingMask:NSViewMaxXMargin|NSViewMinYMargin];
 
475
  //[view addSubview:mt];
 
476
  //    [mt setPostsFrameChangedNotifications:YES];
 
477
  wh = [[TMWidgetHelper alloc] init];
 
478
  wh->wid = this;
574
479
#if 0
575
 
        [(NSNotificationCenter*)[NSNotificationCenter defaultCenter] addObserver:wh
576
 
         selector:@selector(notify:)
577
 
         name:NSViewFrameDidChangeNotification 
578
 
         object:mt];
 
480
  [(NSNotificationCenter*)[NSNotificationCenter defaultCenter] addObserver:wh
 
481
                          selector:@selector(notify:)
 
482
                          name:NSViewFrameDidChangeNotification 
 
483
                          object:mt];
579
484
#endif
580
485
        
581
 
        toolbar = [[NSToolbar alloc] initWithIdentifier:TMToolbarIdentifier ];
582
 
        [toolbar setDelegate:wh];
 
486
  toolbar = [[NSToolbar alloc] initWithIdentifier:TMToolbarIdentifier ];
 
487
  [toolbar setDelegate:wh];
 
488
  
 
489
  updateVisibility();
 
490
  
583
491
}
584
492
 
585
493
aqua_tm_widget_rep::~aqua_tm_widget_rep() 
586
494
587
 
//      [(NSNotificationCenter*)[NSNotificationCenter defaultCenter] removeObserver:wh];
 
495
  //    [(NSNotificationCenter*)[NSNotificationCenter defaultCenter] removeObserver:wh];
588
496
  [wh release]; 
589
497
  [bc release]; 
590
498
}
592
500
 
593
501
void aqua_tm_widget_rep::layout()
594
502
{
595
 
        NSSize s = NSMakeSize(100,20); // size of the right footer;
596
 
        NSRect r = [view bounds];
597
 
        NSRect r0 = r;
598
 
//      NSRect rh = [[bc bar] frame];
599
 
        NSRect rh = NSMakeRect(0,0,0,0);
600
 
        r.size.height -= rh.size.height;
601
 
        r0.origin.y =+ r.size.height; r0.size.height = rh.size.height;
602
 
        NSRect r1 = r; r1.origin.y += s.height; r1.size.height -= s.height;
603
 
        NSRect r2 = r; r2.size.height = s.height;
604
 
        NSRect r3 = r2; 
605
 
        r2.size.width -= s.width; r3.origin.x =+ r2.size.width;
606
 
        r3.size.width -= r2.size.width + 15.0;
607
 
        [sv setFrame:r1];
608
 
        [leftField setFrame:r2];
609
 
        [rightField setFrame:r3];
610
 
        //[[bc bar] setFrame:r0];
 
503
  NSSize s = NSMakeSize(100,20); // size of the right footer;
 
504
  NSRect r = [view bounds];
 
505
  NSRect r0 = r;
 
506
  //    NSRect rh = [[bc bar] frame];
 
507
  NSRect rh = NSMakeRect(0,0,0,0);
 
508
  r.size.height -= rh.size.height;
 
509
  r0.origin.y =+ r.size.height; r0.size.height = rh.size.height;
 
510
  NSRect r1 = r; r1.origin.y += s.height; r1.size.height -= s.height;
 
511
  NSRect r2 = r; r2.size.height = s.height;
 
512
  NSRect r3 = r2; 
 
513
  r2.size.width -= s.width; r3.origin.x =+ r2.size.width;
 
514
  r3.size.width -= r2.size.width + 15.0;
 
515
  [sv setFrame:r1];
 
516
  [leftField setFrame:r2];
 
517
  [rightField setFrame:r3];
 
518
  //[[bc bar] setFrame:r0];
611
519
  [NSApp setWindowsNeedUpdate:YES];
612
520
}
613
521
 
614
522
 
 
523
void aqua_tm_widget_rep::updateVisibility()
 
524
{
 
525
#if 0
 
526
  mainToolBar->setVisible (visibility[1] && visibility[0]);
 
527
  contextToolBar->setVisible (visibility[2] && visibility[0]);
 
528
  userToolBar->setVisible (visibility[3] && visibility[0]);
 
529
  tm_mainwindow()->statusBar()->setVisible (visibility[4]);
 
530
#ifndef Q_WS_MAC
 
531
  tm_mainwindow()->menuBar()->setVisible (visibility[0]);
 
532
#endif
 
533
#endif
 
534
}
 
535
 
 
536
 
 
537
 
615
538
void
616
539
aqua_tm_widget_rep::send (slot s, blackbox val) {
617
540
  switch (s) {
618
 
                case SLOT_EXTENTS:
619
 
                {
620
 
                        if (type_box (val) != type_helper<coord4>::id)
621
 
                                fatal_error ("type mismatch", "SLOT_INVALIDATE");
622
 
                        coord4 p= open_box<coord4> (val);
623
 
                        NSRect rect = to_nsrect(p);
624
 
                        //                      [[view window] setContentSize:rect.size];
625
 
                        [[sv documentView] setFrameSize: rect.size];
626
 
                }
627
 
                        break;
628
 
                case SLOT_INVALIDATE_ALL:
629
 
                {
630
 
                        if (!is_nil (val))
631
 
                                fatal_error ("type mismatch", "SLOT_INVALIDATE_ALL");
632
 
                        [view setNeedsDisplay:YES];
633
 
                }
634
 
                        break;
635
 
                        
636
 
                case SLOT_HEADER_VISIBILITY:
637
 
                        //                      send_bool (THIS, "header", val);
638
 
                        break;
639
 
                case SLOT_MAIN_ICONS_VISIBILITY:
640
 
                        //                      send_bool (THIS, "main icons", val);
641
 
                        break;
642
 
                case SLOT_CONTEXT_ICONS_VISIBILITY:
643
 
                        //                      send_bool (THIS, "context icons", val);
644
 
                        break;
645
 
                case SLOT_USER_ICONS_VISIBILITY:
646
 
                        //                      send_bool (THIS, "user icons", val);
647
 
                        break;
648
 
                case SLOT_FOOTER_VISIBILITY:
649
 
                        //                      send_bool (THIS, "footer flag", val);
650
 
                        break;
651
 
                case SLOT_LEFT_FOOTER:
652
 
                {
653
 
                        if (type_box (val) != type_helper<string>::id)
654
 
                                fatal_error ("type mismatch", "SLOT_LEFT_FOOTER");
655
 
                        string msg = open_box<string> (val);
656
 
                        [leftField setStringValue:to_nsstring(msg)];
657
 
                        [leftField displayIfNeeded];
658
 
                }
659
 
                        
660
 
                        cout << "letf footer\n";
661
 
                        //                      send_string (THIS, "left footer", val);
662
 
                        break;
663
 
                case SLOT_RIGHT_FOOTER:
664
 
                {
665
 
                        if (type_box (val) != type_helper<string>::id)
666
 
                                fatal_error ("type mismatch", "SLOT_RIGHT_FOOTER");
667
 
                        string msg = open_box<string> (val);
668
 
                        [rightField setStringValue:to_nsstring(msg)];
669
 
                        [rightField displayIfNeeded];
670
 
                }
671
 
                        
672
 
                        cout << "right footer\n";
673
 
                        //                      send_string (THIS, "right footer", val);
674
 
                        break;
675
 
                        
676
 
                case SLOT_SCROLL_POSITION:
677
 
                {
678
 
                        if (type_box (val) != type_helper<coord2>::id)
679
 
                                fatal_error ("type mismatch", "SLOT_SCROLL_POSITION");
680
 
                        coord2 p= open_box<coord2> (val);
681
 
                        NSPoint pt = to_nspoint(p);
682
 
                        [[sv documentView] scrollPoint:pt];
683
 
                        //                      [[(NSScrollView*)view documentView] scrollRectToVisible:NSMakeRect(pt.x,pt.y,1.0,1.0)];
684
 
                }
685
 
                        break;
686
 
        case SLOT_INTERACTIVE_MODE:
687
 
       {
688
 
         if (type_box (val) != type_helper<bool>::id)
689
 
           fatal_error ("type mismatch", "SLOT_INTERACTIVE_MODE");
690
 
       }
 
541
  case SLOT_EXTENTS:
 
542
    {
 
543
      TYPE_CHECK (type_box (val) == type_helper<coord4>::id);
 
544
      coord4 p= open_box<coord4> (val);
 
545
      NSRect rect = to_nsrect(p);
 
546
      NSSize ws = [sv contentSize];
 
547
      NSSize sz = rect.size;
 
548
      sz.height = max (sz.height, 7.0 * ws.height / 8.0);
 
549
      //                        [[view window] setContentSize:rect.size];
 
550
      [[sv documentView] setFrameSize: sz];
 
551
    }
 
552
    break;
 
553
  case SLOT_HEADER_VISIBILITY:
 
554
    {
 
555
      TYPE_CHECK (type_box (val) == type_helper<bool>::id);
 
556
      bool f= open_box<bool> (val);
 
557
      visibility[0] = f;
 
558
      updateVisibility();
 
559
    }
 
560
    break;
 
561
  case SLOT_MAIN_ICONS_VISIBILITY:
 
562
    {
 
563
      TYPE_CHECK (type_box (val) == type_helper<bool>::id);
 
564
      bool f= open_box<bool> (val);
 
565
      visibility[1] = f;
 
566
      updateVisibility();
 
567
    }
 
568
    break;
 
569
  case SLOT_CONTEXT_ICONS_VISIBILITY:
 
570
    {
 
571
      TYPE_CHECK (type_box (val) == type_helper<bool>::id);
 
572
      bool f= open_box<bool> (val);
 
573
      visibility[2] = f;
 
574
      updateVisibility();
 
575
    }
 
576
    break;
 
577
  case SLOT_USER_ICONS_VISIBILITY:
 
578
    {
 
579
      TYPE_CHECK (type_box (val) == type_helper<bool>::id);
 
580
      bool f= open_box<bool> (val);
 
581
      visibility[3] = f;
 
582
      updateVisibility();
 
583
    }
 
584
    break;
 
585
  case SLOT_FOOTER_VISIBILITY:
 
586
    {
 
587
      TYPE_CHECK (type_box (val) == type_helper<bool>::id);
 
588
      bool f= open_box<bool> (val);
 
589
      visibility[4] = f;
 
590
      updateVisibility();
 
591
    }
 
592
    break;
 
593
    
 
594
  case SLOT_LEFT_FOOTER:
 
595
    {
 
596
      TYPE_CHECK (type_box (val) == type_helper<string>::id);
 
597
      string msg = open_box<string> (val);
 
598
      [leftField setStringValue:to_nsstring_utf8(aqua_translate(msg))];
 
599
      [leftField displayIfNeeded];
 
600
    }
 
601
    break;
 
602
  case SLOT_RIGHT_FOOTER:
 
603
    {
 
604
      TYPE_CHECK (type_box (val) == type_helper<string>::id);
 
605
      string msg = open_box<string> (val);
 
606
      [rightField setStringValue:to_nsstring_utf8(aqua_translate(msg))];
 
607
      [rightField displayIfNeeded];
 
608
    }
 
609
    break;
 
610
    
 
611
  case SLOT_SCROLL_POSITION:
 
612
    {
 
613
      TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
 
614
      coord2 p= open_box<coord2> (val);
 
615
      NSPoint pt = to_nspoint(p);
 
616
      NSSize sz = [[sv contentView] bounds].size;
 
617
      pt.x += sz.width/2;
 
618
      pt.y += sz.height/2;
 
619
      //cout << "scroll position :" << pt.x << "," << pt.y << LF;
 
620
      
 
621
      [[sv documentView] scrollPoint:pt];
 
622
      //                        [[(NSScrollView*)view documentView] scrollRectToVisible:NSMakeRect(pt.x,pt.y,1.0,1.0)];
 
623
    }
 
624
    break;
 
625
    
 
626
  case SLOT_SCROLLBARS_VISIBILITY:
 
627
    // ignore this: cocoa handles scrollbars independently
 
628
    //                  send_int (THIS, "scrollbars", val);
 
629
    break;
 
630
    
 
631
  case SLOT_INTERACTIVE_MODE:
 
632
    {
 
633
      TYPE_CHECK (type_box (val) == type_helper<bool>::id);
691
634
      if (open_box<bool>(val) == true) {
692
 
        do_interactive_prompt();
 
635
        do_interactive_prompt();
693
636
      }
694
 
            break;
695
 
      
696
 
 
697
 
                default:
698
 
                        aqua_view_widget_rep::send(s,val);
 
637
    }
 
638
    break;
 
639
    
 
640
  case SLOT_SHRINKING_FACTOR:
 
641
    TYPE_CHECK (type_box (val) == type_helper<int>::id);
 
642
    simple_widget_rep *w = (simple_widget_rep *)[(TMView*)[sv documentView] widget];
 
643
    if (w) {
 
644
      int new_sf = open_box<int> (val);
 
645
      if (DEBUG_EVENTS) cout << "New shrinking factor :" << new_sf << LF;
 
646
      w->handle_set_shrinking_factor (new_sf);
 
647
    }
 
648
#if 0        
 
649
    if (QTMWidget* tmw= qobject_cast<QTMWidget*> (tm_canvas())) {
 
650
      int new_sf = open_box<int> (val);
 
651
      if (DEBUG_EVENTS) cout << "New shrinking factor :" << new_sf << LF;
 
652
      tmw->tm_widget()->handle_set_shrinking_factor (new_sf);
 
653
    }
 
654
#endif
 
655
    break;
 
656
        
 
657
  default:
 
658
    aqua_view_widget_rep::send(s,val);
699
659
  }
700
660
}
701
661
 
702
662
blackbox
703
663
aqua_tm_widget_rep::query (slot s, int type_id) {
704
664
  switch (s) {
705
 
                        case SLOT_SCROLL_POSITION:
706
 
                {
707
 
                        if (type_id != type_helper<coord2>::id)
708
 
                                fatal_error ("type mismatch", "SLOT_SCROLL_POSITION");
709
 
                        NSPoint pt = [[sv contentView] bounds].origin;
710
 
                        return close_box<coord2> (from_nspoint(pt));
711
 
                }
712
 
                case SLOT_USER_ICONS_VISIBILITY:
713
 
                {
714
 
                        if (type_id != type_helper<bool>::id)
715
 
                                fatal_error ("type mismatch", "SLOT_HEADER_VISIBILITY");
716
 
                        return close_box<bool> (false);
717
 
                }
 
665
  case SLOT_SCROLL_POSITION:
 
666
    {
 
667
      TYPE_CHECK (type_id == type_helper<coord2>::id);
 
668
      NSPoint pt = [[sv contentView] frame].origin;
 
669
      return close_box<coord2> (from_nspoint(pt));
 
670
    }
 
671
        
 
672
  case SLOT_EXTENTS:
 
673
    {
 
674
      TYPE_CHECK (type_id == type_helper<coord4>::id);
 
675
      NSRect rect= [[sv documentView] frame];
 
676
      coord4 c= from_nsrect (rect);
 
677
      //     if (DEBUG_EVENTS) cout << "Canvas geometry " << rect << LF;
 
678
      return close_box<coord4> (c);
 
679
    }
 
680
        
 
681
        
 
682
  case SLOT_VISIBLE_PART:
 
683
    {
 
684
      TYPE_CHECK (type_id == type_helper<coord4>::id);
 
685
      NSRect rect= [sv documentVisibleRect];
 
686
      coord4 c= from_nsrect (rect);
 
687
      //    if (DEBUG_EVENTS) cout << "Visible Region " << rect << LF;
 
688
      return close_box<coord4> (c);
 
689
    }
718
690
 
719
 
                case SLOT_CONTEXT_ICONS_VISIBILITY:
720
 
                case SLOT_MAIN_ICONS_VISIBILITY:
721
 
                case SLOT_HEADER_VISIBILITY:
722
 
                case SLOT_FOOTER_VISIBILITY:
723
 
                {
724
 
                        if (type_id != type_helper<bool>::id)
725
 
                                fatal_error ("type mismatch", "SLOT_HEADER_VISIBILITY");
726
 
                        return close_box<bool> (true);
727
 
                }
728
 
        case SLOT_INTERACTIVE_INPUT:
729
 
        {
730
 
          if (type_id != type_helper<string>::id)
731
 
            fatal_error ("type mismatch", "SLOT_INTERACTIVE_INPUT");
732
 
          return close_box<string> ( ((aqua_input_text_widget_rep*) int_input.rep)->text );
733
 
            
734
 
        }
735
 
    case SLOT_INTERACTIVE_MODE:
736
 
    {
737
 
      if (type_id != type_helper<bool>::id)
738
 
        fatal_error ("type mismatch", "SLOT_INTERACTIVE_MODE");
 
691
        
 
692
  case SLOT_USER_ICONS_VISIBILITY:
 
693
    TYPE_CHECK (type_id == type_helper<bool>::id);
 
694
    return close_box<bool> (visibility[3]);
 
695
        
 
696
  case SLOT_CONTEXT_ICONS_VISIBILITY:
 
697
    TYPE_CHECK (type_id == type_helper<bool>::id);
 
698
    return close_box<bool> (visibility[2]);
 
699
    
 
700
  case SLOT_MAIN_ICONS_VISIBILITY:
 
701
    TYPE_CHECK (type_id == type_helper<bool>::id);
 
702
    return close_box<bool> (visibility[1]);
 
703
    
 
704
  case SLOT_HEADER_VISIBILITY:
 
705
    TYPE_CHECK (type_id == type_helper<bool>::id);
 
706
    return close_box<bool> (visibility[0]);
 
707
    
 
708
  case SLOT_FOOTER_VISIBILITY:
 
709
    TYPE_CHECK (type_id == type_helper<bool>::id);
 
710
    return close_box<bool> (visibility[4]);
 
711
    
 
712
  case SLOT_INTERACTIVE_INPUT:
 
713
    {
 
714
      TYPE_CHECK (type_id == type_helper<string>::id);
 
715
      return close_box<string> ( ((aqua_input_text_widget_rep*) int_input.rep)->text );
 
716
      
 
717
    }
 
718
  case SLOT_INTERACTIVE_MODE:
 
719
    {
 
720
      TYPE_CHECK (type_id == type_helper<bool>::id);
739
721
      return close_box<bool> (false);
740
722
    }
741
 
      
742
 
    
743
 
    default:
744
 
                        return aqua_view_widget_rep::query(s,type_id);
745
 
  }
746
 
}
747
 
#if 0
748
 
void
749
 
aqua_tm_widget_rep::notify (slot s, blackbox new_val) {
750
 
  switch (s) {
751
 
                        default: ;
752
 
  }
753
 
  aqua_view_widget_rep::notify (s, new_val);
754
 
}
755
 
#endif
 
723
    
 
724
    
 
725
  default:
 
726
    return aqua_view_widget_rep::query(s,type_id);
 
727
  }
 
728
}
756
729
 
757
730
widget
758
731
aqua_tm_widget_rep::read (slot s, blackbox index) {
759
732
  switch (s) {
760
 
                default:
761
 
                        return aqua_view_widget_rep::read(s,index);
 
733
  default:
 
734
    return aqua_view_widget_rep::read(s,index);
762
735
  }
763
736
}
764
737
 
767
740
@interface TMMenuHelper : NSObject
768
741
{
769
742
@public
770
 
        NSMenuItem *mi;
771
 
        NSMenu *menu;
 
743
  NSMenuItem *mi;
 
744
  NSMenu *menu;
772
745
}
773
746
+ (TMMenuHelper *)sharedHelper;
774
747
- init;
779
752
 
780
753
@implementation TMMenuHelper
781
754
- init { 
782
 
        [super init]; mi = nil; menu = nil; 
783
 
 
784
 
        mi = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Menu" action:NULL keyEquivalent:@""];
785
 
        NSMenu *sm = [[[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Menu"] autorelease];
 
755
  [super init]; mi = nil; menu = nil; 
 
756
  
 
757
  mi = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Menu" action:NULL keyEquivalent:@""];
 
758
  NSMenu *sm = [[[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:@"Menu"] autorelease];
786
759
  [mi  setSubmenu:sm];
787
760
  //[[NSApp mainMenu] removeItem: [[NSApp mainMenu] itemWithTitle:@"Help"]]; //FIXME: Help menu causes problems (crash)
788
 
        
789
 
        [[NSApp mainMenu] insertItem: mi atIndex:1];    
790
 
//      [sm setDelegate: self];
791
 
        
792
 
        return self; 
 
761
  
 
762
  [[NSApp mainMenu] insertItem: mi atIndex:1];  
 
763
  //    [sm setDelegate: self];
 
764
  
 
765
  return self; 
793
766
}
794
767
- (void)setMenu:(NSMenu *)_m  
795
768
796
 
        if (menu) [menu release];  menu = _m; [menu retain];
 
769
  if (menu) [menu release];  menu = _m; [menu retain];
797
770
  [mi  setSubmenu:menu];
798
 
        [menu setTitle:@"Menu"];        
 
771
  [menu setTitle:@"Menu"];      
799
772
};
800
773
- (void)dealloc { [mi release]; [menu release]; [super dealloc]; }
801
774
+ (TMMenuHelper *)sharedHelper 
802
775
803
 
        if (!the_menu_helper) 
804
 
        {
805
 
                the_menu_helper = [[TMMenuHelper alloc] init];
806
 
        }
807
 
        return the_menu_helper; 
 
776
  if (!the_menu_helper) 
 
777
    {
 
778
      the_menu_helper = [[TMMenuHelper alloc] init];
 
779
    }
 
780
  return the_menu_helper; 
808
781
}
809
782
 
810
783
#if 0
811
784
- (BOOL)menu:(NSMenu *)menu updateItem:(NSMenuItem *)item atIndex:(int)index shouldCancel:(BOOL)shouldCancel
812
785
{
813
 
        return NO;
 
786
  return NO;
814
787
}
815
788
#endif
816
789
@end
821
794
void
822
795
aqua_tm_widget_rep::write (slot s, blackbox index, widget w) {
823
796
  switch (s) {
824
 
                case SLOT_CANVAS: 
825
 
                {
826
 
                        check_type_void (index, "SLOT_CANVAS");
827
 
                        NSView *v = ((aqua_view_widget_rep*) w.rep)->view;
828
 
                        [sv setDocumentView: v];
829
 
                        [[sv window] makeFirstResponder:v];
830
 
                }
831
 
                        break;
832
 
                case SLOT_MAIN_MENU:
833
 
                        check_type_void (index, "SLOT_MAIN_MENU");
834
 
                        [[TMMenuHelper sharedHelper] setMenu:to_nsmenu(w)];
835
 
                        break;
836
 
                case SLOT_MAIN_ICONS:
837
 
                        check_type_void (index, "SLOT_MAIN_ICONS");
838
 
                        [bc setMenu:to_nsmenu(w) forRow:0];
839
 
                        layout();
840
 
                        break;
841
 
                case SLOT_CONTEXT_ICONS:
842
 
                        check_type_void (index, "SLOT_CONTEXT_ICONS");
843
 
                        [bc setMenu:to_nsmenu(w) forRow:1];
844
 
                        layout();
845
 
                        break;
846
 
                case SLOT_USER_ICONS:
847
 
                        check_type_void (index, "SLOT_USER_ICONS");
848
 
                        [bc setMenu:to_nsmenu(w) forRow:2];
849
 
                        layout();
850
 
                        break;
851
 
                case SLOT_INTERACTIVE_PROMPT:
852
 
                        check_type_void (index, "SLOT_INTERACTIVE_PROMPT");
853
 
            int_prompt = concrete(w); 
854
 
                        //                      THIS << set_widget ("interactive prompt", concrete (w));
855
 
                        break;
856
 
                case SLOT_INTERACTIVE_INPUT:
857
 
                        check_type_void (index, "SLOT_INTERACTIVE_INPUT");
858
 
            int_input = concrete(w);
859
 
                        //                      THIS << set_widget ("interactive input", concrete (w));
860
 
                        break;
861
 
                default:
862
 
                        aqua_view_widget_rep::write(s,index,w);
 
797
  case SLOT_CANVAS: 
 
798
    {
 
799
      check_type_void (index, "SLOT_CANVAS");
 
800
      NSView *v = ((aqua_view_widget_rep*) w.rep)->view;
 
801
      [sv setDocumentView: v];
 
802
      [[sv window] makeFirstResponder:v];
 
803
    }
 
804
    break;
 
805
  case SLOT_MAIN_MENU:
 
806
    check_type_void (index, "SLOT_MAIN_MENU");
 
807
    [[TMMenuHelper sharedHelper] setMenu:to_nsmenu(w)];
 
808
    break;
 
809
  case SLOT_MAIN_ICONS:
 
810
    check_type_void (index, "SLOT_MAIN_ICONS");
 
811
    [bc setMenu:to_nsmenu(w) forRow:0];
 
812
    layout();
 
813
    break;
 
814
  case SLOT_CONTEXT_ICONS:
 
815
    check_type_void (index, "SLOT_CONTEXT_ICONS");
 
816
    [bc setMenu:to_nsmenu(w) forRow:1];
 
817
    layout();
 
818
    break;
 
819
  case SLOT_USER_ICONS:
 
820
    check_type_void (index, "SLOT_USER_ICONS");
 
821
    [bc setMenu:to_nsmenu(w) forRow:2];
 
822
    layout();
 
823
    break;
 
824
  case SLOT_INTERACTIVE_PROMPT:
 
825
    check_type_void (index, "SLOT_INTERACTIVE_PROMPT");
 
826
    int_prompt = concrete(w); 
 
827
    //                  THIS << set_widget ("interactive prompt", concrete (w));
 
828
    break;
 
829
  case SLOT_INTERACTIVE_INPUT:
 
830
    check_type_void (index, "SLOT_INTERACTIVE_INPUT");
 
831
    int_input = concrete(w);
 
832
    //                  THIS << set_widget ("interactive input", concrete (w));
 
833
    break;
 
834
  default:
 
835
    aqua_view_widget_rep::write(s,index,w);
863
836
  }
864
837
}
865
838
 
866
 
widget aqua_tm_widget_rep::plain_window_widget (string s)
867
 
// creates a decorated window with name s and contents w
868
 
{
869
 
        widget w = aqua_view_widget_rep::plain_window_widget(s); // to manage correctly retain counts
870
 
        aqua_window_widget_rep * wid = (aqua_window_widget_rep *)(w.rep);
871
 
        [[wid->get_windowcontroller() window] setToolbar:toolbar];
872
 
        return wid;
 
839
widget
 
840
aqua_tm_widget_rep::plain_window_widget (string s) {
 
841
  // creates a decorated window with name s and contents w
 
842
  widget w = aqua_view_widget_rep::plain_window_widget(s);
 
843
  // to manage correctly retain counts
 
844
  aqua_window_widget_rep * wid = (aqua_window_widget_rep *)(w.rep);
 
845
  [[wid->get_windowcontroller() window] setToolbar:toolbar];
 
846
  return wid;
873
847
}
874
848
 
875
849
 
881
855
@implementation TMWindowController
882
856
- (void)setWidget:(widget_rep*) w
883
857
{
884
 
        wid = (aqua_window_widget_rep*)w;
 
858
  wid = (aqua_window_widget_rep*)w;
885
859
}
886
860
 
887
861
- (widget_rep*)widget
888
862
{
889
 
        return (aqua_widget_rep*)wid;
 
863
  return (aqua_widget_rep*)wid;
890
864
}
891
865
 
892
866
@end
893
867
 
894
868
aqua_window_widget_rep::aqua_window_widget_rep(NSWindow *win) 
895
 
  : widget_rep(), wc([[[TMWindowController alloc] initWithWindow:win] autorelease]) 
 
869
: widget_rep(), wc([[[TMWindowController alloc] initWithWindow:win] autorelease]) 
896
870
{ [wc retain]; [wc setWidget:this]; }
897
871
 
898
872
aqua_window_widget_rep::~aqua_window_widget_rep()  { [wc release]; }
904
878
void
905
879
aqua_window_widget_rep::send (slot s, blackbox val) {
906
880
  switch (s) {
907
 
                case SLOT_SIZE:
908
 
                {
909
 
                        if (type_box (val) != type_helper<coord2>::id)
910
 
                                fatal_error ("type mismatch", "SLOT_SIZE");
911
 
                        coord2 p= open_box<coord2> (val);
912
 
                        NSWindow *win = [wc window];
913
 
                        if (win) {
914
 
                                NSSize size = to_nssize(p);
915
 
                                [win setContentSize:size];
916
 
                        }
917
 
                }
918
 
                        break;
919
 
                case SLOT_POSITION:
920
 
                {
921
 
                        if (type_box (val) != type_helper<coord2>::id)
922
 
                                fatal_error ("type mismatch", "SLOT_POSITION");
923
 
                        coord2 p= open_box<coord2> (val);
924
 
                        NSWindow *win = [wc window];
925
 
                        if (win) { 
926
 
                                [win setFrameOrigin:to_nspoint(p)];
927
 
                        }
928
 
                }
929
 
                        break;
930
 
                case SLOT_VISIBILITY:
931
 
                {       
932
 
                        check_type<bool> (val, "SLOT_VISIBILITY");
933
 
                        bool flag = open_box<bool> (val);
934
 
                        NSWindow *win = [wc window];
935
 
                        if (win) {
936
 
                                if (flag) [win makeKeyAndOrderFront:nil] ;
937
 
                                else [win orderOut:nil]  ;
938
 
                        }
939
 
                }       
940
 
                        break;
941
 
                case SLOT_NAME:
942
 
                {       
943
 
                        check_type<string> (val, "SLOT_NAME");
944
 
                        string name = open_box<string> (val);
945
 
                        NSWindow *win = [wc window];
946
 
                        if (win) {
947
 
                                NSString *title = to_nsstring(name);
948
 
                                [win setTitle:title];
949
 
                        }
950
 
                }
951
 
                        break;
952
 
#if 0
953
 
                case SLOT_IDENTIFIER:
954
 
                        check_type<int> (val, "SLOT_IDENTIFIER");
955
 
                        THIS << emit_attach_window (get_window (open_box<int> (val)));
956
 
                        break;
957
 
                case SLOT_FULL_SCREEN:
958
 
                        check_type<bool> (val, "SLOT_FULL_SCREEN");
959
 
                        win->set_full_screen (open_box<bool> (val));
960
 
                        break;
961
 
                case SLOT_UPDATE:
962
 
                        send_update (THIS, val);
963
 
                        break;
964
 
                case SLOT_KEYBOARD:
965
 
                        send_keyboard (THIS, val);
966
 
                        break;
967
 
                case SLOT_KEYBOARD_FOCUS:
968
 
                        send_keyboard_focus (THIS, val);
969
 
                        break;
970
 
                case SLOT_MOUSE:
971
 
                        send_mouse (THIS, val);
972
 
                        break;
973
 
                case SLOT_MOUSE_GRAB:
974
 
                        send_mouse_grab (THIS, val);
975
 
                        break;
976
 
                case SLOT_MOUSE_POINTER:
977
 
                        send_mouse_pointer (THIS, val);
978
 
                        break;
979
 
                case SLOT_INVALIDATE:
980
 
                        send_invalidate (THIS, val);
981
 
                        break;
982
 
                case SLOT_INVALIDATE_ALL:
983
 
                        send_invalidate_all (THIS, val);
984
 
                        break;
985
 
                case SLOT_REPAINT:
986
 
                        send_repaint (THIS, val);
987
 
                        break;
988
 
                case SLOT_DELAYED_MESSAGE:
989
 
                        send_delayed_message (THIS, val);
990
 
                        break;
991
 
                case SLOT_DESTROY:
992
 
                        send_destroy (THIS, val);
993
 
                        break;
994
 
                        
995
 
                case SLOT_SHRINKING_FACTOR:
996
 
                        send_int (THIS, "shrinking factor", val);
997
 
                        break;
998
 
                case SLOT_EXTENTS:
999
 
                        send_coord4 (THIS, "extents", val);
1000
 
                        break;
1001
 
                case SLOT_SCROLLBARS_VISIBILITY:
1002
 
                        send_int (THIS, "scrollbars", val);
1003
 
                        break;
1004
 
                case SLOT_SCROLL_POSITION:
1005
 
                        send_coord2 (THIS, "scroll position", val);
1006
 
                        break;
1007
 
                        
1008
 
                case SLOT_HEADER_VISIBILITY:
1009
 
                        send_bool (THIS, "header", val);
1010
 
                        break;
1011
 
                case SLOT_MAIN_ICONS_VISIBILITY:
1012
 
                        send_bool (THIS, "main icons", val);
1013
 
                        break;
1014
 
                case SLOT_CONTEXT_ICONS_VISIBILITY:
1015
 
                        send_bool (THIS, "context icons", val);
1016
 
                        break;
1017
 
                case SLOT_USER_ICONS_VISIBILITY:
1018
 
                        send_bool (THIS, "user icons", val);
1019
 
                        break;
1020
 
                case SLOT_FOOTER_VISIBILITY:
1021
 
                        send_bool (THIS, "footer flag", val);
1022
 
                        break;
1023
 
                case SLOT_LEFT_FOOTER:
1024
 
                        send_string (THIS, "left footer", val);
1025
 
                        break;
1026
 
                case SLOT_RIGHT_FOOTER:
1027
 
                        send_string (THIS, "right footer", val);
1028
 
                        break;
1029
 
                case SLOT_INTERACTIVE_MODE:
1030
 
                        send_bool (THIS, "interactive mode", val);
1031
 
                        break;
1032
 
                        
1033
 
                case SLOT_STRING_INPUT:
1034
 
                        send_string (THIS, "input", val);
1035
 
                        break;
1036
 
                case SLOT_INPUT_TYPE:
1037
 
                        send_string (THIS, "type", val);
1038
 
                        break;
1039
 
                case SLOT_INPUT_PROPOSAL:
1040
 
                        send_string (THIS, "default", val);
1041
 
                        break;
1042
 
                case SLOT_FILE:
1043
 
                        send_string (THIS, "file", val);
1044
 
                        break;
1045
 
                case SLOT_DIRECTORY:
1046
 
                        send_string (THIS, "directory", val);
1047
 
                        break;
1048
 
#endif                  
1049
 
                default:
1050
 
                        fatal_error ("cannot handle slot type", "aqua_view_widget_rep::send");
 
881
  case SLOT_SIZE:
 
882
    {
 
883
      TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
 
884
      coord2 p= open_box<coord2> (val);
 
885
      NSWindow *win = [wc window];
 
886
      if (win) {
 
887
        NSSize size = to_nssize(p);
 
888
        [win setContentSize:size];
 
889
      }
 
890
    }
 
891
    break;
 
892
  case SLOT_POSITION:
 
893
    {
 
894
      TYPE_CHECK (type_box (val) == type_helper<coord2>::id);
 
895
      coord2 p= open_box<coord2> (val);
 
896
      NSWindow *win = [wc window];
 
897
      if (win) { 
 
898
        [win setFrameOrigin:to_nspoint(p)];
 
899
      }
 
900
    }
 
901
    break;
 
902
  case SLOT_VISIBILITY:
 
903
    {   
 
904
      check_type<bool> (val, "SLOT_VISIBILITY");
 
905
      bool flag = open_box<bool> (val);
 
906
      NSWindow *win = [wc window];
 
907
      if (win) {
 
908
        if (flag) [win makeKeyAndOrderFront:nil] ;
 
909
        else [win orderOut:nil]  ;
 
910
      }
 
911
    }   
 
912
    break;
 
913
  case SLOT_NAME:
 
914
    {   
 
915
      check_type<string> (val, "SLOT_NAME");
 
916
      string name = open_box<string> (val);
 
917
      NSWindow *win = [wc window];
 
918
      if (win) {
 
919
        NSString *title = to_nsstring(name);
 
920
        [win setTitle:title];
 
921
      }
 
922
    }
 
923
    break;
 
924
  case SLOT_FULL_SCREEN:
 
925
    check_type<bool> (val, "SLOT_FULL_SCREEN");
 
926
    // win->set_full_screen (open_box<bool> (val));
 
927
    break;
 
928
  case SLOT_UPDATE:
 
929
    NOT_IMPLEMENTED ;
 
930
    // send_update (THIS, val);
 
931
    break;
 
932
    
 
933
  default:
 
934
    FAILED ("cannot handle slot type");
1051
935
  }
1052
936
}
1053
937
 
1055
939
blackbox
1056
940
aqua_window_widget_rep::query (slot s, int type_id) {
1057
941
  switch (s) {
1058
 
                case SLOT_IDENTIFIER:
1059
 
                        if (type_id != type_helper<int>::id)
1060
 
                                fatal_error ("int expected (SLOT_IDENTIFIER)", "aqua_window_widget_rep::query");
1061
 
                        return close_box<int> ((int)[wc window]);
1062
 
                        case SLOT_POSITION:  
1063
 
                  {
1064
 
                                typedef pair<SI,SI> coord2;
1065
 
                                if (type_id != type_helper<coord2>::id)
1066
 
                                        fatal_error ("type mismatch (SLOT_POSITION)", "aqua_window_widget_rep::query");
1067
 
                                NSRect frame = [[wc window] frame];
1068
 
                                return close_box<coord2> (from_nspoint(frame.origin));
1069
 
                        }
1070
 
                        case SLOT_SIZE:
1071
 
                {
1072
 
                        typedef pair<SI,SI> coord2;
1073
 
                        if (type_id != type_helper<coord2>::id)
1074
 
                                fatal_error ("type mismatch (SLOT_SIZE)", "aqua_window_widget_rep::query");
1075
 
                        NSRect frame = [[wc window] frame];
1076
 
                        return close_box<coord2> (from_nssize(frame.size));
1077
 
                }
1078
 
#if 0
1079
 
                        case SLOT_RENDERER:
1080
 
                        if (type_id != type_helper<renderer>::id)
1081
 
                                fatal_error ("renderer expected (SLOT_RENDERER)",
1082
 
                                                                                 "aqua_window_widget_rep::query");
1083
 
                        return close_box<renderer> ((renderer) win);
1084
 
                        
1085
 
                        case SLOT_KEYBOARD_FOCUS:
1086
 
                        return query_keyboard_focus (THIS, type_id);
1087
 
                        case SLOT_MOUSE_GRAB:
1088
 
                        return query_mouse_grab (THIS, type_id);
1089
 
                        
1090
 
                        case SLOT_EXTENTS:
1091
 
                        return query_coord4 (THIS, "extents", type_id);
1092
 
                        case SLOT_VISIBLE_PART:
1093
 
                        return query_coord4 (THIS, "visible", type_id);
1094
 
                        case SLOT_SCROLLBARS_VISIBILITY:
1095
 
                        return query_int (THIS, "scrollbars", type_id);
1096
 
                        case SLOT_SCROLL_POSITION:
1097
 
                        return query_coord2 (THIS, "scroll position", type_id);
1098
 
                        
1099
 
                        case SLOT_HEADER_VISIBILITY:
1100
 
                        return query_bool (THIS, "header", type_id);
1101
 
                        case SLOT_MAIN_ICONS_VISIBILITY:
1102
 
                        return query_bool (THIS, "main icons", type_id);
1103
 
                        case SLOT_CONTEXT_ICONS_VISIBILITY:
1104
 
                        return query_bool (THIS, "context icons", type_id);
1105
 
                        case SLOT_USER_ICONS_VISIBILITY:
1106
 
                        return query_bool (THIS, "user icons", type_id);
1107
 
                        case SLOT_FOOTER_VISIBILITY:
1108
 
                        return query_bool (THIS, "footer flag", type_id);
1109
 
                        case SLOT_INTERACTIVE_MODE:
1110
 
                        return query_bool (THIS, "interactive mode", type_id);
1111
 
                        case SLOT_INTERACTIVE_INPUT:
1112
 
                        return query_string (THIS, "interactive input", type_id);
1113
 
                        
1114
 
                        case SLOT_STRING_INPUT:
1115
 
                        return query_string (THIS, "input", type_id);
1116
 
#endif
1117
 
                        default:
1118
 
                        fatal_error ("cannot handle slot type", "aqua_widow_widget_rep::query");
1119
 
                        return blackbox ();
 
942
  case SLOT_IDENTIFIER:
 
943
    TYPE_CHECK (type_id == type_helper<int>::id);
 
944
    return close_box<int> ((int)[wc window] ? 1 : 0);
 
945
  case SLOT_POSITION:  
 
946
    {
 
947
      typedef pair<SI,SI> coord2;
 
948
      TYPE_CHECK (type_id == type_helper<coord2>::id);
 
949
      NSRect frame = [[wc window] frame];
 
950
      return close_box<coord2> (from_nspoint(frame.origin));
 
951
    }
 
952
  case SLOT_SIZE:
 
953
    {
 
954
      typedef pair<SI,SI> coord2;
 
955
      TYPE_CHECK (type_id == type_helper<coord2>::id);
 
956
      NSRect frame = [[wc window] frame];
 
957
      return close_box<coord2> (from_nssize(frame.size));
 
958
    }
 
959
  default:
 
960
    FAILED ("cannot handle slot type");
 
961
    return blackbox ();
1120
962
  }
1121
963
}
1122
964
 
1126
968
 
1127
969
void
1128
970
aqua_window_widget_rep::notify (slot s, blackbox new_val) {
1129
 
  switch (s) {
1130
 
#if 0
1131
 
                case SLOT_SIZE:
1132
 
                        check_type<SI,SI> (new_val, "SLOT_SIZE");
1133
 
                        THIS << emit_resize ();
1134
 
                        if (is_window_widget ())
1135
 
                                send_size (THIS [0], new_val);
1136
 
                        break;
1137
 
                        case SLOT_POSITION:
1138
 
                        check_type<SI,SI> (new_val, "SLOT_POSITION");
1139
 
                        THIS << emit_move ();
1140
 
                        break;
1141
 
                        case SLOT_KEYBOARD_FOCUS:
1142
 
                        notify_keyboard_focus (THIS, new_val);
1143
 
                        break;
1144
 
                        case SLOT_MOUSE_GRAB:
1145
 
                        notify_mouse_grab (THIS, new_val);
1146
 
                        break;
1147
 
#endif
1148
 
                        default: ;
1149
 
  }
1150
971
  widget_rep::notify (s, new_val);
1151
972
}
1152
973
 
1153
974
widget
1154
975
aqua_window_widget_rep::read (slot s, blackbox index) {
1155
976
  switch (s) {
1156
 
#if 0
1157
 
                case SLOT_WINDOW:
1158
 
                        check_type_void (index, "SLOT_WINDOW");
1159
 
                        return win -> get_widget ();
1160
 
                case SLOT_FORM_FIELD:
1161
 
                        check_type<int> (index, "SLOT_FORM_FIELD");
1162
 
                        return abstract (THIS [0] ["inputs"] [open_box<int> (index)] ["input"]);
1163
 
                case SLOT_FILE:
1164
 
                        check_type_void (index, "SLOT_FILE");
1165
 
                        return abstract (THIS [0] ["file"] ["input"]);
1166
 
                case SLOT_DIRECTORY:
1167
 
                        check_type_void (index, "SLOT_DIRECTORY");
1168
 
                        return abstract (THIS [0] ["directory"] ["input"]);
1169
 
#endif
1170
 
                default:
1171
 
                        fatal_error ("cannot handle slot type", "aqua_window_widget_rep::read");
1172
 
                        return widget();
 
977
  default:
 
978
    FAILED ("cannot handle slot type");
 
979
    return widget();
1173
980
  }
1174
981
}
1175
982
 
1176
983
void
1177
984
aqua_window_widget_rep::write (slot s, blackbox index, widget w) {
1178
985
  switch (s) {
1179
 
                case SLOT_CANVAS:
1180
 
                        check_type_void (index, "SLOT_CANVAS");
1181
 
//                      [(NSScrollView*)view setDocumentView: concrete (w)->get_nsview()];
1182
 
                        break;
1183
 
                case SLOT_MAIN_MENU:
1184
 
                        check_type_void (index, "SLOT_MAIN_MENU");
1185
 
                        //                      THIS << set_widget ("menu bar", concrete (w));
1186
 
                        break;
1187
 
                case SLOT_MAIN_ICONS:
1188
 
                        check_type_void (index, "SLOT_MAIN_ICONS");
1189
 
                        //                      THIS << set_widget ("main icons bar", concrete (w));
1190
 
                        break;
1191
 
                case SLOT_CONTEXT_ICONS:
1192
 
                        check_type_void (index, "SLOT_CONTEXT_ICONS");
1193
 
                        //                      THIS << set_widget ("context icons bar", concrete (w));
1194
 
                        break;
1195
 
                case SLOT_USER_ICONS:
1196
 
                        check_type_void (index, "SLOT_USER_ICONS");
1197
 
                        //                      THIS << set_widget ("user icons bar", concrete (w));
1198
 
                        break;
1199
 
                case SLOT_INTERACTIVE_PROMPT:
1200
 
                        check_type_void (index, "SLOT_INTERACTIVE_PROMPT");
1201
 
                        //                      THIS << set_widget ("interactive prompt", concrete (w));
1202
 
                        break;
1203
 
                case SLOT_INTERACTIVE_INPUT:
1204
 
                        check_type_void (index, "SLOT_INTERACTIVE_INPUT");
1205
 
                        //                      THIS << set_widget ("interactive input", concrete (w));
1206
 
                        break;
1207
 
                default:
1208
 
                        fatal_error ("cannot handle slot type", "aqua_window_widget_rep::write");
 
986
#if 0
 
987
  case SLOT_CANVAS:
 
988
    check_type_void (index, "SLOT_CANVAS");
 
989
    //                  [(NSScrollView*)view setDocumentView: concrete (w)->get_nsview()];
 
990
    break;
 
991
  case SLOT_MAIN_MENU:
 
992
    check_type_void (index, "SLOT_MAIN_MENU");
 
993
    //                  THIS << set_widget ("menu bar", concrete (w));
 
994
    break;
 
995
  case SLOT_MAIN_ICONS:
 
996
    check_type_void (index, "SLOT_MAIN_ICONS");
 
997
    //                  THIS << set_widget ("main icons bar", concrete (w));
 
998
    break;
 
999
  case SLOT_CONTEXT_ICONS:
 
1000
    check_type_void (index, "SLOT_CONTEXT_ICONS");
 
1001
    //                  THIS << set_widget ("context icons bar", concrete (w));
 
1002
    break;
 
1003
  case SLOT_USER_ICONS:
 
1004
    check_type_void (index, "SLOT_USER_ICONS");
 
1005
    //                  THIS << set_widget ("user icons bar", concrete (w));
 
1006
    break;
 
1007
  case SLOT_INTERACTIVE_PROMPT:
 
1008
    check_type_void (index, "SLOT_INTERACTIVE_PROMPT");
 
1009
    //                  THIS << set_widget ("interactive prompt", concrete (w));
 
1010
    break;
 
1011
  case SLOT_INTERACTIVE_INPUT:
 
1012
    check_type_void (index, "SLOT_INTERACTIVE_INPUT");
 
1013
    //                  THIS << set_widget ("interactive input", concrete (w));
 
1014
    break;
 
1015
#endif
 
1016
  default:
 
1017
    FAILED ("cannot handle slot type");
1209
1018
  }
1210
1019
}
1211
1020
 
1212
1021
 
1213
1022
/******************************************************************************
1214
 
 * simple_widget_rep
1215
 
 ******************************************************************************/
 
1023
* simple_widget_rep
 
1024
******************************************************************************/
1216
1025
#pragma mark simple_widget_rep
1217
1026
 
1218
1027
/******************************************************************************
1273
1082
 
1274
1083
void
1275
1084
simple_widget_rep::send (slot s, blackbox val) {
1276
 
 aqua_view_widget_rep::send(s, val);
 
1085
  aqua_view_widget_rep::send(s, val);
1277
1086
}
1278
1087
 
1279
1088
 
1280
1089
blackbox
1281
1090
simple_widget_rep::query (slot s, int type_id) {
1282
 
        return aqua_view_widget_rep::query(s,type_id);
 
1091
  return aqua_view_widget_rep::query(s,type_id);
1283
1092
}
1284
1093
 
1285
1094
void
1286
 
simple_widget_rep::notify (slot s, blackbox new_val) 
1287
 
1288
 
        aqua_view_widget_rep::notify (s, new_val);
 
1095
simple_widget_rep::notify (slot s, blackbox new_val) {
 
1096
  aqua_view_widget_rep::notify (s, new_val);
1289
1097
}
1290
1098
 
1291
1099
/******************************************************************************
1293
1101
 ******************************************************************************/
1294
1102
 
1295
1103
widget
1296
 
simple_widget_rep::read (slot s, blackbox index) 
1297
 
{
1298
 
        return aqua_view_widget_rep::read(s,index);
 
1104
simple_widget_rep::read (slot s, blackbox index) {
 
1105
  return aqua_view_widget_rep::read(s,index);
1299
1106
}
1300
1107
 
1301
1108
void
1302
 
simple_widget_rep::write (slot s, blackbox index, widget w) 
1303
 
{
1304
 
        aqua_view_widget_rep::write(s,index,w);
 
1109
simple_widget_rep::write (slot s, blackbox index, widget w) {
 
1110
  aqua_view_widget_rep::write(s,index,w);
1305
1111
}
1306
1112
 
1307
1113
 
1308
1114
 
1309
1115
 
1310
1116
/******************************************************************************
1311
 
 * Window widgets
1312
 
 ******************************************************************************/
 
1117
* Window widgets
 
1118
******************************************************************************/
 
1119
 
1313
1120
#pragma mark Widget interface
1314
1121
 
1315
1122
 
1316
1123
widget plain_window_widget (widget w, string s) 
1317
1124
// creates a decorated window with name s and contents w
1318
1125
{
1319
 
        return concrete(w)->plain_window_widget(s);
 
1126
  return concrete(w)->plain_window_widget(s);
1320
1127
}
1321
1128
 
1322
1129
widget popup_window_widget (widget w, string s) 
1323
1130
// creates an undecorated window with name s and contents w
1324
1131
{
1325
 
        return concrete(w)->popup_window_widget(s);
 
1132
  return concrete(w)->popup_window_widget(s);
1326
1133
}
1327
1134
 
1328
 
void   destroy_window_widget (widget w) {  }
 
1135
void   destroy_window_widget (widget w) {  
1329
1136
// destroys a window as created by the above routines
 
1137
  (void) w;
 
1138
}
1330
1139
 
1331
1140
/******************************************************************************
1332
1141
 * Top-level widgets, typically given as an argument to plain_window_widget
1338
1147
// the mask variable indicates whether the menu, icon bars, status bar, etc.
1339
1148
// are visible or not
1340
1149
{
1341
 
        widget w = new aqua_tm_widget_rep();
1342
 
        return w; 
 
1150
  (void) mask; (void) quit; // FIXME: handle correctly mask and quit
 
1151
 
 
1152
  widget w = tm_new <aqua_tm_widget_rep> (mask);
 
1153
  return w; 
1343
1154
}
1344
1155
 
1345
1156
 
1351
1162
// the pointer quits the widget
1352
1163
// used in edit_mouse.cpp to implement a contextual menu in the canvas
1353
1164
{
1354
 
        return concrete(w)->make_popup_widget();
 
1165
  return concrete(w)->make_popup_widget();
1355
1166
}
1356
1167
 
1357
1168
 
1360
1171
 *  their implementation is void
1361
1172
 ******************************************************************************/
1362
1173
 
1363
 
widget empty_widget () { return widget(); }
1364
 
// an empty widget of size zero
1365
 
widget glue_widget (bool hx, bool vx, SI w, SI h) 
1366
 
//{ return widget(); }
1367
 
// an empty widget of minimal width w and height h and which is horizontally
1368
 
// resp. vertically extensible if hx resp. vx is true
1369
 
{
1370
 
        return new aqua_view_widget_rep ([[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 50, 50)] autorelease]);
1371
 
}
1372
 
widget wait_widget (SI width, SI height, string message) { return widget(); }
1373
 
// a widget of a specified width and height, displaying a wait message
1374
 
// this widget is only needed when using the X11 plugin
 
1174
widget
 
1175
empty_widget () {
 
1176
  // an empty widget of size zero
 
1177
  NOT_IMPLEMENTED;
 
1178
  return widget();
 
1179
}
 
1180
 
 
1181
widget
 
1182
glue_widget (bool hx, bool vx, SI w, SI h) {
 
1183
  //{ return widget(); }
 
1184
  // an empty widget of minimal width w and height h and which is horizontally
 
1185
  // resp. vertically extensible if hx resp. vx is true
 
1186
  NOT_IMPLEMENTED;
 
1187
  (void) hx; (void) vx; (void) w; (void) h;
 
1188
  return tm_new <aqua_view_widget_rep> ([[[NSView alloc] initWithFrame:NSMakeRect(0, 0, 50, 50)] autorelease]);
 
1189
}
 
1190
 
 
1191
widget
 
1192
wait_widget (SI width, SI height, string message) { 
 
1193
  // a widget of a specified width and height, displaying a wait message
 
1194
  // this widget is only needed when using the X11 plugin
 
1195
  (void) width; (void) height; (void) message;
 
1196
  return widget(); 
 
1197
}