1 /* 2 * Copyright 2006-2009, Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef _MENU_FIELD_H 6 #define _MENU_FIELD_H 7 8 9 #include <Menu.h> 10 11 12 class BMenuBar; 13 14 15 class BMenuField : public BView { 16 public: 17 BMenuField(BRect frame, const char* name, 18 const char* label, BMenu* menu, 19 uint32 resize = B_FOLLOW_LEFT|B_FOLLOW_TOP, 20 uint32 flags = B_WILL_DRAW | B_NAVIGABLE); 21 BMenuField(BRect frame, const char* name, 22 const char* label, BMenu* menu, 23 bool fixed_size, 24 uint32 resize = B_FOLLOW_LEFT|B_FOLLOW_TOP, 25 uint32 flags = B_WILL_DRAW | B_NAVIGABLE); 26 BMenuField(const char* name, 27 const char* label, BMenu* menu, 28 BMessage* message = NULL, 29 uint32 flags = B_WILL_DRAW | B_NAVIGABLE); 30 BMenuField(const char* label, 31 BMenu* menu, BMessage* message = NULL); 32 BMenuField(BMessage* data); 33 virtual ~BMenuField(); 34 35 static BArchivable* Instantiate(BMessage* archive); 36 virtual status_t Archive(BMessage* archive, 37 bool deep = true) const; 38 39 virtual void Draw(BRect update); 40 virtual void AttachedToWindow(); 41 virtual void AllAttached(); 42 virtual void MouseDown(BPoint where); 43 virtual void KeyDown(const char* bytes, int32 numBytes); 44 virtual void MakeFocus(bool state); 45 virtual void MessageReceived(BMessage* message); 46 virtual void WindowActivated(bool state); 47 virtual void MouseUp(BPoint where); 48 virtual void MouseMoved(BPoint where, uint32 transit, 49 const BMessage* dragMessage); 50 virtual void DetachedFromWindow(); 51 virtual void AllDetached(); 52 virtual void FrameMoved(BPoint where); 53 virtual void FrameResized(float width, float height); 54 55 BMenu* Menu() const; 56 BMenuBar* MenuBar() const; 57 BMenuItem* MenuItem() const; 58 59 virtual void SetLabel(const char* label); 60 const char* Label() const; 61 62 virtual void SetEnabled(bool on); 63 bool IsEnabled() const; 64 65 virtual void SetAlignment(alignment label); 66 alignment Alignment() const; 67 virtual void SetDivider(float dividing_line); 68 float Divider() const; 69 70 void ShowPopUpMarker(); 71 void HidePopUpMarker(); 72 73 virtual BHandler* ResolveSpecifier(BMessage* message, 74 int32 index, BMessage* specifier, 75 int32 form, const char* property); 76 virtual status_t GetSupportedSuites(BMessage* data); 77 78 virtual void ResizeToPreferred(); 79 virtual void GetPreferredSize(float* width, float* height); 80 81 virtual BSize MinSize(); 82 virtual BSize MaxSize(); 83 virtual BSize PreferredSize(); 84 85 virtual void InvalidateLayout(bool descendants = false); 86 87 BLayoutItem* CreateLabelLayoutItem(); 88 BLayoutItem* CreateMenuBarLayoutItem(); 89 90 virtual status_t Perform(perform_code d, void* arg); 91 92 protected: 93 virtual void DoLayout(); 94 95 private: 96 // FBC padding 97 virtual void _ReservedMenuField1(); 98 virtual void _ReservedMenuField2(); 99 virtual void _ReservedMenuField3(); 100 101 // Forbidden 102 BMenuField& operator=(const BMenuField& other); 103 104 private: 105 class LabelLayoutItem; 106 class MenuBarLayoutItem; 107 struct LayoutData; 108 109 friend class _BMCMenuBar_; 110 friend class LabelLayoutItem; 111 friend class MenuBarLayoutItem; 112 friend class LayoutData; 113 114 void InitObject(const char* label); 115 void InitObject2(); 116 void DrawLabel(BRect bounds, BRect update); 117 static void InitMenu(BMenu* menu); 118 119 int32 _MenuTask(); 120 static int32 _thread_entry(void *arg); 121 122 void _UpdateFrame(); 123 void _InitMenuBar(BMenu* menu, 124 BRect frame, bool fixedSize); 125 126 void _ValidateLayoutData(); 127 float _MenuBarOffset() const; 128 float _MenuBarWidth() const; 129 130 private: 131 char* fLabel; 132 BMenu* fMenu; 133 BMenuBar* fMenuBar; 134 alignment fAlign; 135 float fDivider; 136 bool fEnabled; 137 bool fSelected; 138 bool fTransition; 139 bool fFixedSizeMB; 140 thread_id fMenuTaskID; 141 142 LayoutData* fLayoutData; 143 144 uint32 _reserved[3]; 145 }; 146 147 #endif // _MENU_FIELD_H 148