Ticket #7002: ClipboardMenu.diff
File ClipboardMenu.diff, 4.6 KB (added by , 14 years ago) |
---|
-
src/kits/locale/Jamfile
67 67 SEARCH on [ FGristFiles StringForSize.cpp ] += [ FDirName $(HAIKU_TOP) src kits shared ] ; 68 68 SEARCH on [ FGristFiles AboutWindow.cpp ] += [ FDirName $(HAIKU_TOP) src kits shared ] ; 69 69 SEARCH on [ FGristFiles ColorControl.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; 70 SEARCH on [ FGristFiles TextInput.cpp ] += [ FDirName $(HAIKU_TOP) src kits interface ] ; 70 71 71 72 DoCatalogs liblocale.so 72 73 : system … … 74 75 AboutWindow.cpp 75 76 ColorControl.cpp 76 77 StringForSize.cpp 78 TextInput.cpp 77 79 ; -
src/kits/interface/TextInput.h
46 46 virtual void InsertText(const char *inText, int32 inLength, 47 47 int32 inOffset, const text_run_array *inRuns); 48 48 virtual void DeleteText(int32 fromOffset, int32 toOffset); 49 virtual void MessageReceived(BMessage* message); 49 50 50 51 private: 52 void _Init(); 51 53 52 54 BTextControl *TextControl(); 53 55 -
src/kits/interface/TextInput.cpp
14 14 #include <stdlib.h> 15 15 #include <string.h> 16 16 17 #include <Clipboard.h> 17 18 #include <ControlLook.h> 18 19 #include <InterfaceDefs.h> 20 #include <LayoutBuilder.h> 19 21 #include <LayoutUtils.h> 22 #include <Menu.h> 23 #include <MenuItem.h> 20 24 #include <Message.h> 25 #include <PopUpMenu.h> 21 26 #include <String.h> 22 27 #include <TextControl.h> 23 28 #include <TextView.h> 24 29 #include <Window.h> 25 30 31 #include <Catalog.h> 32 #include <LocaleBackend.h> 26 33 34 35 using BPrivate::gLocaleBackend; 36 using BPrivate::LocaleBackend; 37 38 39 #undef B_TRANSLATE_CONTEXT 40 #define B_TRANSLATE_CONTEXT "TextInput" 41 42 43 #define TRANSLATE(str) gLocaleBackend->GetString(B_TRANSLATE_MARK(str), \ 44 "TextInput") 45 46 27 47 namespace BPrivate { 28 48 49 const uint32 kMsgClearInput = 'CLER'; 29 50 30 51 _BTextInput_::_BTextInput_(BRect frame, BRect textRect, uint32 resizeMask, 31 52 uint32 flags) 32 53 : BTextView(frame, "_input_", textRect, resizeMask, flags), 33 54 fPreviousText(NULL) 34 55 { 35 MakeResizable(true);56 _Init(); 36 57 } 37 58 38 59 … … 40 61 : BTextView(archive), 41 62 fPreviousText(NULL) 42 63 { 43 MakeResizable(true);64 _Init(); 44 65 } 45 66 46 67 … … 75 96 return; 76 97 } 77 98 78 // only pass through to base class if we already have focus 79 BTextView::MouseDown(where); 99 int32 buttons = B_SECONDARY_MOUSE_BUTTON; 100 if (Looper() != NULL && Looper()->CurrentMessage() != NULL) 101 Looper()->CurrentMessage()->FindInt32("buttons", &buttons); 102 103 if (buttons == B_SECONDARY_MOUSE_BUTTON) { 104 bool isRedo; 105 undo_state state = UndoState(&isRedo); 106 bool isUndo = state != B_UNDO_UNAVAILABLE && !isRedo; 107 108 int32 start; 109 int32 finish; 110 GetSelection(&start, &finish); 111 112 bool canEdit = IsEditable(); 113 int32 length = TextLength(); 114 115 BPopUpMenu *menu = new BPopUpMenu(B_EMPTY_STRING, false, false); 116 117 BLayoutBuilder::Menu<>(menu) 118 .AddItem(TRANSLATE("Undo"), B_UNDO/*, 'Z'*/) 119 .SetEnabled(canEdit && isUndo) 120 .AddItem(TRANSLATE("Redo"), B_UNDO/*, 'Z', B_SHIFT_KEY*/) 121 .SetEnabled(canEdit && isRedo) 122 .AddSeparator() 123 .AddItem(TRANSLATE("Cut"), B_CUT, 'X') 124 .SetEnabled(canEdit && start != finish) 125 .AddItem(TRANSLATE("Copy"), B_COPY, 'C') 126 .SetEnabled(start != finish) 127 .AddItem(TRANSLATE("Paste"), B_PASTE, 'V') 128 .SetEnabled(canEdit && be_clipboard->SystemCount() > 0) 129 .AddSeparator() 130 .AddItem(TRANSLATE("Select All"), B_SELECT_ALL, 'A') 131 .SetEnabled(!(start == 0 && finish == length)) 132 .AddItem(TRANSLATE("Clear"), kMsgClearInput) 133 .SetEnabled(canEdit && length > 0) 134 ; 135 136 menu->SetTargetForItems(this); 137 ConvertToScreen(&where); 138 menu->Go(where, true, true, true); 139 } else { 140 // only pass through to base class if we already have focus 141 BTextView::MouseDown(where); 142 } 80 143 } 81 144 82 145 … … 118 181 } 119 182 } 120 183 184 121 185 void 122 186 _BTextInput_::MakeFocus(bool state) 123 187 { … … 249 313 } 250 314 251 315 316 void 317 _BTextInput_::MessageReceived(BMessage* message) 318 { 319 switch(message->what) { 320 case kMsgClearInput: 321 SelectAll(); 322 Clear(); 323 break; 324 325 default: 326 BTextView::MessageReceived(message); 327 break; 328 } 329 } 330 331 332 void 333 _BTextInput_::_Init() 334 { 335 // we need to translate some strings, and in order to do so, we need 336 // to use the LocaleBackend to reache liblocale.so 337 if (gLocaleBackend == NULL) 338 LocaleBackend::LoadBackend(); 339 340 MakeResizable(true); 341 } 342 343 252 344 } // namespace BPrivate 253 345