From d78e4460727c348fb5a5a62b774797c4374a1190 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Tue, 19 Apr 2022 04:39:37 +0000 Subject: [PATCH] Minor cleanups to Haiku menu code * src/haiku_draw_support.cc (BView_SetHighColorForVisibleBell): Delete function. * src/haiku_font_support.cc (BFont_dat): Rename to `BFont_metrics'. * src/haiku_support.cc (DrawContent): Use correct UI color for control text. * src/haiku_support.h (HAIKU_MODIFIER_ALT): Turn into enum. (enum haiku_modifier_specification): New enum. * src/haikufont.c (haikufont_open, haikufont_close): Fix coding style. --- src/haiku_draw_support.cc | 10 ---------- src/haiku_font_support.cc | 6 +++--- src/haiku_support.cc | 2 +- src/haiku_support.h | 19 ++++++++++--------- src/haikufont.c | 31 ++++++++++++++++++++----------- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/haiku_draw_support.cc b/src/haiku_draw_support.cc index f8df298958f..a8d46d000a3 100644 --- a/src/haiku_draw_support.cc +++ b/src/haiku_draw_support.cc @@ -468,16 +468,6 @@ BView_FillTriangle (void *view, int x1, int y1, BPoint (x3, y3)); } -void -BView_SetHighColorForVisibleBell (void *view, uint32_t color) -{ - BView *vw = (BView *) view; - rgb_color col; - rgb32_to_rgb_color (color, &col); - - vw->SetHighColor (col); -} - void BView_InvertRect (void *view, int x, int y, int width, int height) { diff --git a/src/haiku_font_support.cc b/src/haiku_font_support.cc index d3e1128e091..6bb934af5f4 100644 --- a/src/haiku_font_support.cc +++ b/src/haiku_font_support.cc @@ -85,9 +85,9 @@ BFont_close (void *font) } void -BFont_dat (void *font, int *px_size, int *min_width, int *max_width, - int *avg_width, int *height, int *space_width, int *ascent, - int *descent, int *underline_position, int *underline_thickness) +BFont_metrics (void *font, int *px_size, int *min_width, int *max_width, + int *avg_width, int *height, int *space_width, int *ascent, + int *descent, int *underline_position, int *underline_thickness) { BFont *ft = (BFont *) font; struct font_height fheight; diff --git a/src/haiku_support.cc b/src/haiku_support.cc index 1feea6c4502..290b2541f4c 100644 --- a/src/haiku_support.cc +++ b/src/haiku_support.cc @@ -2263,7 +2263,7 @@ public: menu->PushState (); menu->SetFont (be_bold_font); - BView_SetHighColorForVisibleBell (menu, 0); + menu->SetHighColor (ui_color (B_CONTROL_TEXT_COLOR)); BMenuItem::DrawContent (); menu->PopState (); } diff --git a/src/haiku_support.h b/src/haiku_support.h index 4718be4f84a..7f6f6e9b0d7 100644 --- a/src/haiku_support.h +++ b/src/haiku_support.h @@ -131,10 +131,13 @@ struct haiku_dummy_event char dummy; }; -#define HAIKU_MODIFIER_ALT (1) -#define HAIKU_MODIFIER_CTRL (1 << 1) -#define HAIKU_MODIFIER_SHIFT (1 << 2) -#define HAIKU_MODIFIER_SUPER (1 << 3) +enum haiku_modifier_specification + { + HAIKU_MODIFIER_ALT = 1, + HAIKU_MODIFIER_CTRL = (1 << 1), + HAIKU_MODIFIER_SHIFT = (1 << 2), + HAIKU_MODIFIER_SUPER = (1 << 3), + }; struct haiku_key_event { @@ -459,8 +462,8 @@ extern void BWindow_dimensions (void *, int *, int *); extern void BWindow_Flush (void *); extern void BFont_close (void *); -extern void BFont_dat (void *, int *, int *, int *, int *, - int *, int *, int *, int *, int *, int *); +extern void BFont_metrics (void *, int *, int *, int *, int *, + int *, int *, int *, int *, int *, int *); extern int BFont_have_char_p (void *, int32_t); extern int BFont_have_char_block (void *, int32_t, int32_t); extern void BFont_char_bounds (void *, const char *, int *, int *, int *); @@ -468,11 +471,9 @@ extern void BFont_nchar_bounds (void *, const char *, int *, int *, int *, int32_t); extern struct haiku_font_pattern *BFont_find (struct haiku_font_pattern *); - extern void BView_StartClip (void *); extern void BView_EndClip (void *); extern void BView_SetHighColor (void *, uint32_t); -extern void BView_SetHighColorForVisibleBell (void *, uint32_t); extern void BView_SetLowColor (void *, uint32_t); extern void BView_SetPenSize (void *, int); extern void BView_SetFont (void *, void *); @@ -639,10 +640,10 @@ extern bool be_drag_and_drop_in_progress (void); extern bool be_replay_menu_bar_event (void *, struct haiku_menu_bar_click_event *); #ifdef __cplusplus -extern void *find_appropriate_view_for_draw (void *); } extern _Noreturn void gui_abort (const char *); +extern void *find_appropriate_view_for_draw (void *); #endif /* _cplusplus */ #endif /* _HAIKU_SUPPORT_H_ */ diff --git a/src/haikufont.c b/src/haikufont.c index 4e81e577039..960ca466bc0 100644 --- a/src/haikufont.c +++ b/src/haikufont.c @@ -727,10 +727,10 @@ haikufont_open (struct frame *f, Lisp_Object font_entity, int x) avg_width, height, space_width, ascent, descent, underline_pos, underline_thickness; - BFont_dat (be_font, &px_size, &min_width, - &max_width, &avg_width, &height, - &space_width, &ascent, &descent, - &underline_pos, &underline_thickness); + BFont_metrics (be_font, &px_size, &min_width, + &max_width, &avg_width, &height, + &space_width, &ascent, &descent, + &underline_pos, &underline_thickness); font->pixel_size = px_size; font->min_width = min_width; @@ -757,22 +757,31 @@ haikufont_open (struct frame *f, Lisp_Object font_entity, int x) static void haikufont_close (struct font *font) { + struct haikufont_info *info = (struct haikufont_info *) font; + int i; + if (font_data_structures_may_be_ill_formed ()) return; - struct haikufont_info *info = (struct haikufont_info *) font; block_input (); if (info && info->be_font) BFont_close (info->be_font); - for (int i = 0; i < info->metrics_nrows; i++) - if (info->metrics[i]) - xfree (info->metrics[i]); + for (i = 0; i < info->metrics_nrows; i++) + { + if (info->metrics[i]) + xfree (info->metrics[i]); + } + if (info->metrics) xfree (info->metrics); - for (int i = 0; i < 0x100; ++i) - if (info->glyphs[i]) - xfree (info->glyphs[i]); + + for (i = 0; i < 0x100; ++i) + { + if (info->glyphs[i]) + xfree (info->glyphs[i]); + } + xfree (info->glyphs); unblock_input (); } -- 2.39.2