From 3cb845283eb430c9b905dc0b17d83e5ff8f0c0de Mon Sep 17 00:00:00 2001 From: Trung Nguyen Date: Sun, 9 Jul 2023 23:33:32 +1000 Subject: [PATCH] headers/os: Make headers generator-friendly Make Haiku headers a bit more friendly to binding generators by: - Giving some `enum`s names (especially those that appear in default arguments). - Converting an internal `inline` function into a macro so that the result could be evaluated in compile time. Change-Id: I770674ad8fa7b24ac30b6b447d52a4b4c2530b8a Reviewed-on: https://review.haiku-os.org/c/haiku/+/6716 Tested-by: Commit checker robot Reviewed-by: waddlesplash --- headers/os/SupportKit.h | 1 + headers/os/app/AppDefs.h | 4 +-- headers/os/app/Roster.h | 2 +- headers/os/interface/PictureButton.h | 2 +- headers/os/interface/View.h | 33 +++++++++++------------ src/bin/screen_blanker/PasswordWindow.cpp | 2 +- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/headers/os/SupportKit.h b/headers/os/SupportKit.h index 63240dd820..d08ebf5fcd 100644 --- a/headers/os/SupportKit.h +++ b/headers/os/SupportKit.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/headers/os/app/AppDefs.h b/headers/os/app/AppDefs.h index d8624b7e93..7787fe219d 100644 --- a/headers/os/app/AppDefs.h +++ b/headers/os/app/AppDefs.h @@ -25,7 +25,7 @@ extern const BCursor *B_CURSOR_I_BEAM; // System Message Codes -enum { +enum system_message_code { B_ABOUT_REQUESTED = '_ABR', B_WINDOW_ACTIVATED = '_ACT', B_APP_ACTIVATED = '_ACT', // Same as B_WINDOW_ACTIVATED @@ -93,7 +93,7 @@ enum { // Other Commands -enum { +enum command_code { B_SET_PROPERTY = 'PSET', B_GET_PROPERTY = 'PGET', B_CREATE_PROPERTY = 'PCRT', diff --git a/headers/os/app/Roster.h b/headers/os/app/Roster.h index 6d08702ad2..e2e72dcff4 100644 --- a/headers/os/app/Roster.h +++ b/headers/os/app/Roster.h @@ -37,7 +37,7 @@ struct app_info { #define _B_APP_INFO_RESERVED1_ (0x10000000) // watching request flags -enum { +enum watching_request_flags { B_REQUEST_LAUNCHED = 0x00000001, B_REQUEST_QUIT = 0x00000002, B_REQUEST_ACTIVATED = 0x00000004, diff --git a/headers/os/interface/PictureButton.h b/headers/os/interface/PictureButton.h index 0a21ea94d2..0f8bda90ba 100644 --- a/headers/os/interface/PictureButton.h +++ b/headers/os/interface/PictureButton.h @@ -10,7 +10,7 @@ #include -enum { +enum picture_button_behavior { B_ONE_STATE_BUTTON, B_TWO_STATE_BUTTON }; diff --git a/headers/os/interface/View.h b/headers/os/interface/View.h index e8859c6ff9..690c9c8314 100644 --- a/headers/os/interface/View.h +++ b/headers/os/interface/View.h @@ -51,13 +51,13 @@ enum { // will filter out older mouse moved messages) }; -enum { +enum rect_tracking_style { B_TRACK_WHOLE_RECT, B_TRACK_RECT_CORNER }; // set font mask -enum { +enum set_font_mask { B_FONT_FAMILY_AND_STYLE = 0x00000001, B_FONT_SIZE = 0x00000002, B_FONT_SHEAR = 0x00000004, @@ -104,25 +104,24 @@ const uint32 _VIEW_BOTTOM_ = 3UL; const uint32 _VIEW_RIGHT_ = 4UL; const uint32 _VIEW_CENTER_ = 5UL; -inline uint32 _rule_(uint32 r1, uint32 r2, uint32 r3, uint32 r4) - { return ((r1 << 12) | (r2 << 8) | (r3 << 4) | r4); } +#define _rule_(r1, r2, r3, r4) (((r1) << 12) | ((r2) << 8) | ((r3) << 4) | (r4)) -#define B_FOLLOW_NONE 0 -#define B_FOLLOW_ALL_SIDES _rule_(_VIEW_TOP_, _VIEW_LEFT_, _VIEW_BOTTOM_, \ - _VIEW_RIGHT_) -#define B_FOLLOW_ALL B_FOLLOW_ALL_SIDES +const uint32 B_FOLLOW_NONE = 0; +const uint32 B_FOLLOW_ALL_SIDES = _rule_(_VIEW_TOP_, _VIEW_LEFT_, + _VIEW_BOTTOM_, _VIEW_RIGHT_); +const uint32 B_FOLLOW_ALL = B_FOLLOW_ALL_SIDES; -#define B_FOLLOW_LEFT _rule_(0, _VIEW_LEFT_, 0, _VIEW_LEFT_) -#define B_FOLLOW_RIGHT _rule_(0, _VIEW_RIGHT_, 0, _VIEW_RIGHT_) -#define B_FOLLOW_LEFT_RIGHT _rule_(0, _VIEW_LEFT_, 0, _VIEW_RIGHT_) -#define B_FOLLOW_H_CENTER _rule_(0, _VIEW_CENTER_, 0, _VIEW_CENTER_) +const uint32 B_FOLLOW_LEFT = _rule_(0, _VIEW_LEFT_, 0, _VIEW_LEFT_); +const uint32 B_FOLLOW_RIGHT = _rule_(0, _VIEW_RIGHT_, 0, _VIEW_RIGHT_); +const uint32 B_FOLLOW_LEFT_RIGHT = _rule_(0, _VIEW_LEFT_, 0, _VIEW_RIGHT_); +const uint32 B_FOLLOW_H_CENTER = _rule_(0, _VIEW_CENTER_, 0, _VIEW_CENTER_); -#define B_FOLLOW_TOP _rule_(_VIEW_TOP_, 0, _VIEW_TOP_, 0) -#define B_FOLLOW_BOTTOM _rule_(_VIEW_BOTTOM_, 0, _VIEW_BOTTOM_, 0) -#define B_FOLLOW_TOP_BOTTOM _rule_(_VIEW_TOP_, 0, _VIEW_BOTTOM_, 0) -#define B_FOLLOW_V_CENTER _rule_(_VIEW_CENTER_, 0, _VIEW_CENTER_, 0) +const uint32 B_FOLLOW_TOP = _rule_(_VIEW_TOP_, 0, _VIEW_TOP_, 0); +const uint32 B_FOLLOW_BOTTOM = _rule_(_VIEW_BOTTOM_, 0, _VIEW_BOTTOM_, 0); +const uint32 B_FOLLOW_TOP_BOTTOM = _rule_(_VIEW_TOP_, 0, _VIEW_BOTTOM_, 0); +const uint32 B_FOLLOW_V_CENTER = _rule_(_VIEW_CENTER_, 0, _VIEW_CENTER_, 0); -#define B_FOLLOW_LEFT_TOP B_FOLLOW_TOP | B_FOLLOW_LEFT +const uint32 B_FOLLOW_LEFT_TOP = B_FOLLOW_TOP | B_FOLLOW_LEFT; class BBitmap; class BCursor; diff --git a/src/bin/screen_blanker/PasswordWindow.cpp b/src/bin/screen_blanker/PasswordWindow.cpp index b69cb39b1b..5149924f37 100644 --- a/src/bin/screen_blanker/PasswordWindow.cpp +++ b/src/bin/screen_blanker/PasswordWindow.cpp @@ -46,7 +46,7 @@ PasswordWindow::PasswordWindow() bounds.top += 10.0; fPassword = new BTextControl(bounds, "password", B_TRANSLATE("Enter password:"), "VeryLongPasswordPossible", - B_FOLLOW_NONE); + NULL, B_FOLLOW_NONE); customBox->AddChild(fPassword); fPassword->MakeFocus(true); fPassword->ResizeToPreferred();