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