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 virtual status_t AllArchived(BMessage* into) const; 39 virtual status_t AllUnarchived(const BMessage* from); 40 41 virtual void Draw(BRect update); 42 virtual void AttachedToWindow(); 43 virtual void AllAttached(); 44 virtual void MouseDown(BPoint where); 45 virtual void KeyDown(const char* bytes, int32 numBytes); 46 virtual void MakeFocus(bool state); 47 virtual void MessageReceived(BMessage* message); 48 virtual void WindowActivated(bool state); 49 virtual void MouseUp(BPoint where); 50 virtual void MouseMoved(BPoint where, uint32 transit, 51 const BMessage* dragMessage); 52 virtual void DetachedFromWindow(); 53 virtual void AllDetached(); 54 virtual void FrameMoved(BPoint where); 55 virtual void FrameResized(float width, float height); 56 57 BMenu* Menu() const; 58 BMenuBar* MenuBar() const; 59 BMenuItem* MenuItem() const; 60 61 virtual void SetLabel(const char* label); 62 const char* Label() const; 63 64 virtual void SetEnabled(bool on); 65 bool IsEnabled() const; 66 67 virtual void SetAlignment(alignment label); 68 alignment Alignment() const; 69 virtual void SetDivider(float dividing_line); 70 float Divider() const; 71 72 void ShowPopUpMarker(); 73 void HidePopUpMarker(); 74 75 virtual BHandler* ResolveSpecifier(BMessage* message, 76 int32 index, BMessage* specifier, 77 int32 form, const char* property); 78 virtual status_t GetSupportedSuites(BMessage* data); 79 80 virtual void ResizeToPreferred(); 81 virtual void GetPreferredSize(float* width, float* height); 82 83 virtual BSize MinSize(); 84 virtual BSize MaxSize(); 85 virtual BSize PreferredSize(); 86 87 virtual void InvalidateLayout(bool descendants = false); 88 89 BLayoutItem* CreateLabelLayoutItem(); 90 BLayoutItem* CreateMenuBarLayoutItem(); 91 92 virtual status_t Perform(perform_code d, void* arg); 93 94 protected: 95 virtual void DoLayout(); 96 97 private: 98 // FBC padding 99 virtual void _ReservedMenuField1(); 100 virtual void _ReservedMenuField2(); 101 virtual void _ReservedMenuField3(); 102 103 // Forbidden 104 BMenuField& operator=(const BMenuField& other); 105 106 private: 107 class LabelLayoutItem; 108 class MenuBarLayoutItem; 109 struct LayoutData; 110 111 friend class _BMCMenuBar_; 112 friend class LabelLayoutItem; 113 friend class MenuBarLayoutItem; 114 friend class LayoutData; 115 116 void InitObject(const char* label); 117 void InitObject2(); 118 void DrawLabel(BRect bounds, BRect update); 119 static void InitMenu(BMenu* menu); 120 121 int32 _MenuTask(); 122 static int32 _thread_entry(void *arg); 123 124 void _UpdateFrame(); 125 void _InitMenuBar(BMenu* menu, 126 BRect frame, bool fixedSize); 127 void _InitMenuBar(const BMessage* archive); 128 129 void _ValidateLayoutData(); 130 float _MenuBarOffset() const; 131 float _MenuBarWidth() const; 132 133 private: 134 char* fLabel; 135 BMenu* fMenu; 136 BMenuBar* fMenuBar; 137 alignment fAlign; 138 float fDivider; 139 bool fEnabled; 140 bool fSelected; 141 bool fTransition; 142 bool fFixedSizeMB; 143 thread_id fMenuTaskID; 144 145 LayoutData* fLayoutData; 146 147 uint32 _reserved[3]; 148 }; 149 150 #endif // _MENU_FIELD_H 151