1 /* 2 * Copyright 2003-2015, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _MENU_BAR_H 6 #define _MENU_BAR_H 7 8 9 #include <InterfaceDefs.h> 10 #include <Menu.h> 11 #include <OS.h> 12 13 14 enum menu_bar_border { 15 B_BORDER_FRAME, 16 B_BORDER_CONTENTS, 17 B_BORDER_EACH_ITEM 18 }; 19 20 class BMenu; 21 class BWindow; 22 class BMenuItem; 23 class BMenuField; 24 25 26 class BMenuBar : public BMenu { 27 public: 28 BMenuBar(BRect frame, const char* name, 29 uint32 resizingMode = B_FOLLOW_LEFT_RIGHT 30 | B_FOLLOW_TOP, 31 menu_layout layout = B_ITEMS_IN_ROW, 32 bool resizeToFit = true); 33 BMenuBar(const char* name, 34 menu_layout layout = B_ITEMS_IN_ROW, 35 uint32 flags = B_WILL_DRAW 36 | B_FRAME_EVENTS); 37 BMenuBar(BMessage* archive); 38 virtual ~BMenuBar(); 39 40 static BArchivable* Instantiate(BMessage* archive); 41 virtual status_t Archive(BMessage* archive, 42 bool deep = true) const; 43 44 virtual void AttachedToWindow(); 45 virtual void DetachedFromWindow(); 46 virtual void AllAttached(); 47 virtual void AllDetached(); 48 49 virtual void WindowActivated(bool state); 50 virtual void MakeFocus(bool state = true); 51 52 virtual void ResizeToPreferred(); 53 virtual void GetPreferredSize(float* _width, 54 float* _height); 55 virtual BSize MinSize(); 56 virtual BSize MaxSize(); 57 virtual BSize PreferredSize(); 58 virtual void FrameMoved(BPoint newPosition); 59 virtual void FrameResized(float newWidth, float newHeight); 60 61 virtual void Show(); 62 virtual void Hide(); 63 64 virtual void Draw(BRect updateRect); 65 66 virtual void MessageReceived(BMessage* message); 67 virtual void MouseDown(BPoint where); 68 virtual void MouseUp(BPoint where); 69 70 virtual BHandler* ResolveSpecifier(BMessage* message, 71 int32 index, BMessage* specifier, 72 int32 form, const char* property); 73 virtual status_t GetSupportedSuites(BMessage* data); 74 75 virtual void SetBorder(menu_bar_border border); 76 menu_bar_border Border() const; 77 void SetBorders(uint32 borders); 78 uint32 Borders() const; 79 80 virtual status_t Perform(perform_code code, void* data); 81 82 protected: 83 void StartMenuBar(int32 menuIndex, 84 bool sticky = true, bool showMenu = false, 85 BRect* special_rect = NULL); 86 87 private: 88 friend class BWindow; 89 friend class BMenuField; 90 friend class BMenu; 91 92 virtual void _ReservedMenuBar1(); 93 virtual void _ReservedMenuBar2(); 94 virtual void _ReservedMenuBar3(); 95 virtual void _ReservedMenuBar4(); 96 97 BMenuBar &operator=(const BMenuBar &); 98 99 static int32 _TrackTask(void *arg); 100 BMenuItem* _Track(int32 *action, int32 startIndex = -1, 101 bool showMenu = false); 102 void _StealFocus(); 103 void _RestoreFocus(); 104 void _InitData(menu_layout layout); 105 106 menu_bar_border fBorder; 107 thread_id fTrackingPID; 108 int32 fPrevFocusToken; 109 sem_id fMenuSem; 110 BRect* fLastBounds; 111 uint32 fBorders; 112 uint32 _reserved[1]; 113 114 bool fTracking; 115 }; 116 117 118 #endif /* _MENU_BAR_H */ 119