1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2002, OpenBeOS 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: BMCPrivate.cpp 23 // Author: Marc Flerackers (mflerackers@androme.be) 24 // Description: The BMCPrivate classes are used by BMenuField. 25 //------------------------------------------------------------------------------ 26 27 // Standard Includes ----------------------------------------------------------- 28 29 // System Includes ------------------------------------------------------------- 30 #include <BMCPrivate.h> 31 #include <MenuField.h> 32 #include <MenuItem.h> 33 #include <Message.h> 34 #include <Window.h> 35 36 // Project Includes ------------------------------------------------------------ 37 38 // Local Includes -------------------------------------------------------------- 39 40 // Local Defines --------------------------------------------------------------- 41 42 // Globals --------------------------------------------------------------------- 43 44 //------------------------------------------------------------------------------ 45 _BMCItem_::_BMCItem_(BMenu *menu) 46 : BMenuItem(menu), 47 fShowPopUpMarker(true) 48 { 49 } 50 //------------------------------------------------------------------------------ 51 _BMCItem_::_BMCItem_(BMessage *message) 52 : BMenuItem(message), 53 fShowPopUpMarker(true) 54 { 55 } 56 //------------------------------------------------------------------------------ 57 _BMCItem_::~_BMCItem_() 58 { 59 } 60 //------------------------------------------------------------------------------ 61 BArchivable *_BMCItem_::Instantiate(BMessage *data) 62 { 63 if (validate_instantiation(data, "_BMCItem_")) 64 return new _BMCItem_(data); 65 else 66 return NULL; 67 } 68 //------------------------------------------------------------------------------ 69 void _BMCItem_::Draw() 70 { 71 BMenuItem::Draw(); 72 73 if (!fShowPopUpMarker) 74 return; 75 76 BMenu *menu = Menu(); 77 BRect rect(menu->Bounds()); 78 79 rect.right -= 4; 80 rect.bottom -= 5; 81 rect.left = rect.right - 4; 82 rect.top = rect.bottom - 2; 83 84 if (IsEnabled()) 85 menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 86 B_DARKEN_4_TINT)); 87 else 88 menu->SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), 89 B_DARKEN_4_TINT)); 90 91 menu->StrokeLine(BPoint(rect.left, rect.top), BPoint(rect.right, rect.top)); 92 menu->StrokeLine(BPoint(rect.left + 1.0f, rect.top + 1.0f), 93 BPoint(rect.right - 1.0f, rect.top + 1.0f)); 94 menu->StrokeLine(BPoint(rect.left + 2.0f, rect.bottom), 95 BPoint(rect.left + 2.0f, rect.bottom)); 96 } 97 //------------------------------------------------------------------------------ 98 void _BMCItem_::GetContentSize(float *width, float *height) 99 { 100 BMenuItem::GetContentSize(width, height); 101 } 102 //------------------------------------------------------------------------------ 103 /*_BMCFilter_::_BMCFilter_(BMenuField *menuField, uint32) 104 { 105 } 106 //------------------------------------------------------------------------------ 107 _BMCFilter_::~_BMCFilter_() 108 { 109 } 110 //------------------------------------------------------------------------------ 111 filter_result _BMCFilter_::Filter(BMessage *message, BHandler **handler) 112 { 113 } 114 //------------------------------------------------------------------------------ 115 _BMCFilter_ &_BMCFilter_::operator=(const _BMCFilter_ &) 116 { 117 return *this; 118 }*/ 119 //------------------------------------------------------------------------------ 120 _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField) 121 : BMenuBar(frame, "_mc_mb_", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_ITEMS_IN_ROW, 122 !fixed_size) 123 { 124 SetFlags(Flags() | B_FRAME_EVENTS); 125 SetBorder(B_BORDER_CONTENTS); 126 127 128 fMenuField = menuField; 129 fFixedSize = fixed_size; 130 fRunner = NULL; 131 132 float left, top, right, bottom; 133 134 GetItemMargins(&left, &top, &right, &bottom); 135 SetItemMargins(left, top, right, bottom); // TODO: 136 137 SetMaxContentWidth(frame.Width() - (left + right)); 138 } 139 //------------------------------------------------------------------------------ 140 _BMCMenuBar_::_BMCMenuBar_(BMessage *data) 141 : BMenuBar(data) 142 { 143 SetFlags(Flags() | B_FRAME_EVENTS); 144 145 bool rsize_to_fit; 146 147 if (data->FindBool("_rsize_to_fit", &rsize_to_fit) == B_OK) 148 fFixedSize = !rsize_to_fit; 149 else 150 fFixedSize = true; 151 } 152 //------------------------------------------------------------------------------ 153 _BMCMenuBar_::~_BMCMenuBar_() 154 { 155 } 156 //------------------------------------------------------------------------------ 157 BArchivable *_BMCMenuBar_::Instantiate(BMessage *data) 158 { 159 if (validate_instantiation(data, "_BMCMenuBar_")) 160 return new _BMCMenuBar_(data); 161 else 162 return NULL; 163 } 164 //------------------------------------------------------------------------------ 165 void _BMCMenuBar_::AttachedToWindow() 166 { 167 fMenuField = (BMenuField*)Parent(); 168 169 BMenuBar *menuBar = Window()->KeyMenuBar(); 170 BMenuBar::AttachedToWindow(); 171 Window()->SetKeyMenuBar(menuBar); 172 } 173 //------------------------------------------------------------------------------ 174 void _BMCMenuBar_::FrameResized(float width, float height) 175 { 176 // TODO: 177 BMenuBar::FrameResized(width, height); 178 } 179 //------------------------------------------------------------------------------ 180 void _BMCMenuBar_::MessageReceived(BMessage *msg) 181 { 182 if (msg->what == 'TICK') 183 { 184 BMenuItem *item = ItemAt(0); 185 186 if (item && item->Submenu() && item->Submenu()->Window()) 187 { 188 BMessage message(B_KEY_DOWN); 189 190 message.AddInt8("byte", B_ESCAPE); 191 message.AddInt8("key", B_ESCAPE); 192 message.AddInt32("modifiers", 0); 193 message.AddInt8("raw_char", B_ESCAPE); 194 195 Window()->PostMessage(&message, this, NULL); 196 } 197 } 198 199 BMenuBar::MessageReceived(msg); 200 } 201 //------------------------------------------------------------------------------ 202 void _BMCMenuBar_::MakeFocus(bool focused) 203 { 204 if (IsFocus() == focused) 205 return; 206 207 BMenuBar::MakeFocus(focused); 208 209 if (focused) 210 { 211 BMessage message('TICK'); 212 //fRunner = new BMessageRunner(BMessenger(this, NULL, NULL), &message, 213 // 50000, -1); 214 } 215 else if (fRunner) 216 { 217 //delete fRunner; 218 fRunner = NULL; 219 } 220 221 if (focused) 222 return; 223 224 fMenuField->fSelected = false; 225 fMenuField->fTransition = true; 226 227 BRect bounds(fMenuField->Bounds()); 228 229 fMenuField->Draw(BRect(bounds.left, bounds.top, fMenuField->fDivider, 230 bounds.bottom)); 231 } 232 //------------------------------------------------------------------------------ 233 _BMCMenuBar_ &_BMCMenuBar_::operator=(const _BMCMenuBar_ &) 234 { 235 return *this; 236 } 237 //------------------------------------------------------------------------------ 238