From 3ea1a6672b1cc8c7ea505585e8687500014e524b Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 2 May 2022 05:48:48 +0000 Subject: Default to currently selected font in Haiku font dialogs * src/haiku_font_support.cc (be_find_font_indices): New function. * src/haiku_support.cc (class EmacsFontSelectionDialog) (UpdateStylesForIndex, EmacsFontSelectionDialog): Allow specifying an initial font family and style. (be_select_font): New parameters `initial_family' and `initial_style'. * src/haiku_support.h: Update prototypes. * src/haikufont.c (haikufont_lisp_to_weight) (haikufont_lisp_to_slant, haikufont_lisp_to_width): Handle `regular'. (haikufont_pattern_from_object): New function. (haikufont_spec_or_entity_to_pattern): Fix coding style. (Fx_select_font): Compute indices based on currently selected font. (syms_of_haikufont): New defsyms. --- src/haiku_support.cc | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'src/haiku_support.cc') diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 9e31e1b870f..12934faa1c8 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -2448,6 +2448,7 @@ class EmacsFontSelectionDialog : public BWindow BTextControl size_entry; port_id comm_port; bool allow_monospace_only; + int pending_selection_idx; void UpdateStylesForIndex (int idx) @@ -2479,6 +2480,13 @@ class EmacsFontSelectionDialog : public BWindow } } + if (pending_selection_idx >= 0) + { + font_style_pane.Select (pending_selection_idx); + font_style_pane.ScrollToSelection (); + } + + pending_selection_idx = -1; UpdateForSelectedStyle (); } @@ -2559,7 +2567,9 @@ public: delete_port (comm_port); } - EmacsFontSelectionDialog (bool monospace_only) + EmacsFontSelectionDialog (bool monospace_only, + int initial_family_idx, + int initial_style_idx) : BWindow (BRect (0, 0, 500, 500), "Select font from list", B_TITLED_WINDOW_LOOK, @@ -2583,7 +2593,8 @@ public: new BMessage (B_CANCEL)), ok_button ("OK", "OK", new BMessage (B_OK)), size_entry (NULL, "Size:", NULL, NULL), - allow_monospace_only (monospace_only) + allow_monospace_only (monospace_only), + pending_selection_idx (initial_style_idx) { BStringItem *family_item; int i, n_families; @@ -2638,6 +2649,12 @@ public: } } + if (initial_family_idx >= 0) + { + font_family_pane.Select (initial_family_idx); + font_family_pane.ScrollToSelection (); + } + size_text = size_entry.TextView (); for (c = 0; c <= 47; ++c) @@ -4701,7 +4718,8 @@ be_select_font (void (*process_pending_signals_function) (void), bool (*should_quit_function) (void), haiku_font_family_or_style *family, haiku_font_family_or_style *style, - int *size, bool allow_monospace_only) + int *size, bool allow_monospace_only, + int initial_family, int initial_style) { EmacsFontSelectionDialog *dialog; struct font_selection_dialog_message msg; @@ -4709,7 +4727,8 @@ be_select_font (void (*process_pending_signals_function) (void), font_family family_buffer; font_style style_buffer; - dialog = new EmacsFontSelectionDialog (allow_monospace_only); + dialog = new EmacsFontSelectionDialog (allow_monospace_only, + initial_family, initial_style); dialog->CenterOnScreen (); if (dialog->InitCheck () < B_OK) -- cgit v1.2.3