-/* ==========================================================================
-
- EmacsPrefsController implementation
-
- ========================================================================== */
-
-
-@implementation EmacsPrefsController
-
-/* in Tiger+, can just do [popup selectItemWithTag: tag]; */
-static void selectItemWithTag (NSPopUpButton *popup, int tag)
-{
- NSEnumerator *items = [[popup itemArray] objectEnumerator];
- NSMenuItem *item;
- while (item = [items nextObject])
- {
- if ([item tag] == tag)
- {
- [popup selectItem: item];
- return;
- }
- }
-}
-
-- init
-{
- [NSBundle loadNibNamed: @"preferences" owner: self];
- return self;
-}
-
-
-- (void) showForFrame: (struct frame *)f
-{
- frame = f;
- [self setPanelFromValues];
- [prefsWindow makeKeyAndOrderFront: self];
- [prefsWindow display];
-}
-
-
-/* If you change this, change setPanelFromDefaultValues too. */
-- (void) setPanelFromValues
-{
- int cursorType
- = ns_lisp_to_cursor_type (get_frame_param (frame, Qcursor_type));
- prevExpandSpace = XFLOATINT (ns_expand_space);
-
-#ifdef NS_IMPL_COCOA
- prevUseHighlightColor = ns_use_system_highlight_color;
-#endif
-
- [expandSpaceSlider setFloatValue: prevExpandSpace];
- [cursorTypeMatrix selectCellWithTag: (cursorType == FILLED_BOX_CURSOR ? 1 :
- (cursorType == BAR_CURSOR ? 2 :
- (cursorType == HBAR_CURSOR ? 3 : 4)))];
- selectItemWithTag (alternateModMenu,
- parse_solitary_modifier (ns_alternate_modifier));
- selectItemWithTag (commandModMenu,
- parse_solitary_modifier (ns_command_modifier));
-#ifdef NS_IMPL_COCOA
- selectItemWithTag (controlModMenu,
- parse_solitary_modifier (ns_control_modifier));
- selectItemWithTag (functionModMenu,
- parse_solitary_modifier (ns_function_modifier));
- [smoothFontsCheck setState: (NILP (ns_antialias_text) ? NO : YES)];
- [useQuickdrawCheck setState: (NILP (ns_use_qd_smoothing) ? NO : YES)];
- [useSysHiliteCheck setState: (NILP (prevUseHighlightColor) ? NO : YES)];
-#endif
-}
-
-
-/* This and ns_set_default_prefs should be changed together. */
-- (void) setPanelFromDefaultValues
-{
- [expandSpaceSlider setFloatValue: 0.0];
- [cursorTypeMatrix selectCellWithTag: 1]; /* filled box */
- selectItemWithTag (alternateModMenu, meta_modifier);
- selectItemWithTag (commandModMenu, super_modifier);
-#ifdef NS_IMPL_COCOA
- selectItemWithTag (controlModMenu, ctrl_modifier);
- selectItemWithTag (functionModMenu, 0); /* none */
- [smoothFontsCheck setState: YES];
- [useQuickdrawCheck setState: NO];
- [useSysHiliteCheck setState: YES];
-#endif
-}
-
-
-- (void) setValuesFromPanel
-{
- int altTag = [[alternateModMenu selectedItem] tag];
- int cmdTag = [[commandModMenu selectedItem] tag];
-#ifdef NS_IMPL_COCOA
- int ctrlTag = [[controlModMenu selectedItem] tag];
- int fnTag = [[functionModMenu selectedItem] tag];
-#endif
- float expandSpace = [expandSpaceSlider floatValue];
- int cursorTag = [[cursorTypeMatrix selectedCell] tag];
- Lisp_Object cursor_type = ns_cursor_type_to_lisp
- ( cursorTag == 1 ? FILLED_BOX_CURSOR
- : cursorTag == 2 ? BAR_CURSOR
- : cursorTag == 3 ? HBAR_CURSOR : HOLLOW_BOX_CURSOR);
-
- if (expandSpace != prevExpandSpace)
- {
- ns_expand_space = make_float (expandSpace);
- /* TODO: more needed: store needed metrics in nsfont_info, update
- frame default font max_bounds and fontp, recompute faces */
-/* FRAME_LINE_HEIGHT (frame) *= (expandSpace / prevExpandSpace);
- x_set_window_size (frame, 0, frame->text_cols, frame->text_lines); */
- prevExpandSpace = expandSpace;
- }
-
- store_frame_param (frame, Qcursor_type, cursor_type);
- x_set_cursor_type (frame, cursor_type, Qnil); /* FIXME: do only if changed */
-
- ns_alternate_modifier = ns_mod_to_lisp (altTag);
- ns_command_modifier = ns_mod_to_lisp (cmdTag);
-#ifdef NS_IMPL_COCOA
- ns_control_modifier = ns_mod_to_lisp (ctrlTag);
- ns_function_modifier = ns_mod_to_lisp (fnTag);
- ns_antialias_text = [smoothFontsCheck state] ? Qt : Qnil;
- ns_use_qd_smoothing = [useQuickdrawCheck state] ? Qt : Qnil;
- ns_use_system_highlight_color = [useSysHiliteCheck state] ? Qt : Qnil;
- if (! EQ (ns_use_system_highlight_color, prevUseHighlightColor))
- {
- prevUseHighlightColor = ns_use_system_highlight_color;
- if (EQ (ns_use_system_highlight_color, Qt))
- {
- ns_selection_color = [[NSUserDefaults standardUserDefaults]
- stringForKey: @"AppleHighlightColor"];
- if (ns_selection_color == nil)
- ns_selection_color = NS_SELECTION_COLOR_DEFAULT;
- }
- else
- ns_selection_color = NS_SELECTION_COLOR_DEFAULT;
- }
-#endif /* NS_IMPL_COCOA */
- Fcall_interactively (intern ("ns-save-preferences"), Qnil, Qnil);
-}
-
-
-/* buttons */
-- (IBAction)cancel: (id)sender
-{
- [prefsWindow close];
-}
-
-
-- (IBAction)ok: (id)sender
-{
- [self setValuesFromPanel];
- [prefsWindow close];
-}
-
-
-- (IBAction)resetToDefaults: (id)sender
-{
- [self setPanelFromDefaultValues];
-}
-
-
-- (IBAction)runHelp: (id)sender
-{
- Feval (Fcons (intern ("info"),
- Fcons (build_string ("(emacs)Mac / GNUstep Customization"),
- Qnil)));
- SET_FRAME_GARBAGED (frame);
- ns_send_appdefined (-1);
-}
-
-
-- (IBAction)setColors: (id)sender
-{
- Lisp_Object lispFrame;
- XSETFRAME (lispFrame, frame);
- ns_raise_frame(frame);
- Fns_popup_color_panel (lispFrame);
-}
-
-
-- (IBAction)setDefaultFont: (id)sender
-{
- Lisp_Object lispFrame;
- XSETFRAME (lispFrame, frame);
- ns_raise_frame(frame);
- Fns_popup_font_panel (lispFrame);
-}
-
-@end /* EmacsPrefsController */
-
-
-