1 /* 2 Open Tracker License 3 4 Terms and Conditions 5 6 Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8 Permission is hereby granted, free of charge, to any person obtaining a copy of 9 this software and associated documentation files (the "Software"), to deal in 10 the Software without restriction, including without limitation the rights to 11 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12 of the Software, and to permit persons to whom the Software is furnished to do 13 so, subject to the following conditions: 14 15 The above copyright notice and this permission notice applies to all licensees 16 and shall be included in all copies or substantial portions of the Software. 17 18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25 Except as contained in this notice, the name of Be Incorporated shall not be 26 used in advertising or otherwise to promote the sale, use or other dealings in 27 this Software without prior written authorization from Be Incorporated. 28 29 Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30 of Be Incorporated in the United States and other countries. Other brand product 31 names are registered trademarks or trademarks of their respective holders. 32 All rights reserved. 33 */ 34 35 // defines the status area drawn in the bottom left corner of a Tracker window 36 37 38 #include <Button.h> 39 #include <Screen.h> 40 41 #include "OverrideAlert.h" 42 43 44 OverrideAlert::OverrideAlert(const char* title, const char* text, 45 const char* button1, uint32 modifiers1, 46 const char* button2, uint32 modifiers2, 47 const char* button3, uint32 modifiers3, 48 button_width width, alert_type type) 49 : 50 BAlert(title, text, button1, button2, button3, width, type), 51 fCurModifiers(0) 52 { 53 fButtonModifiers[0] = modifiers1; 54 fButtonModifiers[1] = modifiers2; 55 fButtonModifiers[2] = modifiers3; 56 UpdateButtons(modifiers(), true); 57 58 BPoint where = OverPosition(Frame().Width(), Frame().Height()); 59 MoveTo(where.x, where.y); 60 } 61 62 63 OverrideAlert::OverrideAlert(const char* title, const char* text, 64 const char* button1, uint32 modifiers1, 65 const char* button2, uint32 modifiers2, 66 const char* button3, uint32 modifiers3, 67 button_width width, button_spacing spacing, alert_type type) 68 : 69 BAlert(title, text, button1, button2, button3, width, spacing, type), 70 fCurModifiers(0) 71 { 72 fButtonModifiers[0] = modifiers1; 73 fButtonModifiers[1] = modifiers2; 74 fButtonModifiers[2] = modifiers3; 75 UpdateButtons(modifiers(), true); 76 77 BPoint where = OverPosition(Frame().Width(), Frame().Height()); 78 MoveTo(where.x, where.y); 79 } 80 81 82 OverrideAlert::~OverrideAlert() 83 { 84 } 85 86 87 void 88 OverrideAlert::DispatchMessage(BMessage* message, BHandler* handler) 89 { 90 if (message->what == B_KEY_DOWN || message->what == B_KEY_UP 91 || message->what == B_UNMAPPED_KEY_DOWN 92 || message->what == B_UNMAPPED_KEY_UP) { 93 uint32 modifiers; 94 if (message->FindInt32("modifiers", (int32*)&modifiers) == B_OK) 95 UpdateButtons(modifiers); 96 } 97 BAlert::DispatchMessage(message, handler); 98 } 99 100 101 BPoint 102 OverrideAlert::OverPosition(float width, float height) 103 { 104 // This positions the alert window like a normal alert, put 105 // places it on top of the calling window if possible. 106 107 BWindow* window 108 = dynamic_cast<BWindow*>(BLooper::LooperForThread(find_thread(NULL))); 109 BRect desirableRect; 110 111 if (window != NULL) { 112 // If we found a window associated with this calling thread, 113 // place alert over that window so that the first button is 114 // on top of it. This allows name editing confirmations to 115 // work with focus follows mouse -- when the alert goes away, 116 // the underlying window will still have focus. 117 118 desirableRect = window->Frame(); 119 float midX = (desirableRect.left + desirableRect.right) / 2.0f; 120 float midY = (desirableRect.top * 3.0f + desirableRect.bottom) / 4.0f; 121 122 desirableRect.left = midX - ceilf(width / 2.0f); 123 desirableRect.right = desirableRect.left+width; 124 desirableRect.top = midY - ceilf(height / 3.0f); 125 desirableRect.bottom = desirableRect.top + height; 126 } else { 127 // Otherwise, place alert in center of (main) screen. 128 129 desirableRect = BScreen().Frame(); 130 float midX = (desirableRect.left + desirableRect.right) / 2.0f; 131 float midY = (desirableRect.top * 3.0f + desirableRect.bottom) / 4.0f; 132 133 desirableRect.left = midX - ceilf(width / 2.0f); 134 desirableRect.right = desirableRect.left + width; 135 desirableRect.top = midY - ceilf(height / 3.0f); 136 desirableRect.bottom = desirableRect.top + height; 137 } 138 139 return desirableRect.LeftTop(); 140 } 141 142 143 void 144 OverrideAlert::UpdateButtons(uint32 modifiers, bool force) 145 { 146 if (modifiers == fCurModifiers && !force) 147 return; 148 149 fCurModifiers = modifiers; 150 for (int32 i = 0; i < 3; i++) { 151 BButton* button = ButtonAt(i); 152 if (button != NULL) { 153 button->SetEnabled(((fButtonModifiers[i] & fCurModifiers) 154 == fButtonModifiers[i])); 155 } 156 } 157 } 158