Ticket #7340: showimage-new-from-clipboard-001.diff
File showimage-new-from-clipboard-001.diff, 4.3 KB (added by , 13 years ago) |
---|
-
src/apps/showimage/ShowImageWindow.cpp
118 118 119 119 120 120 ShowImageWindow::ShowImageWindow(BRect frame, const entry_ref& ref, 121 const BMessenger& trackerMessenger )121 const BMessenger& trackerMessenger, bool fromClipboard) 122 122 : 123 123 BWindow(frame, "", B_DOCUMENT_WINDOW, 0), 124 124 fNavigator(ref, trackerMessenger), … … 187 187 188 188 SetSizeLimits(250, 100000, 100, 100000); 189 189 190 // finish creating the window 191 if (_LoadImage() != B_OK) { 190 if (fromClipboard) { 191 printf("fromClipboard\n"); 192 status_t status = B_ERROR; 193 //XXX: needs cleanup 194 BBitmap *bitmap = NULL; 195 if (be_clipboard->Lock()) { 196 BMessage *clip = be_clipboard->Data(); 197 BMessage archivedBitmap; 198 if (clip->FindMessage("image/bitmap", &archivedBitmap) == B_OK 199 || clip->FindMessage("image/bitmap", &archivedBitmap) == B_OK) { 200 bitmap = new(std::nothrow) BBitmap(&archivedBitmap); 201 printf("bitmap %p\n", bitmap); 202 } 203 be_clipboard->Unlock(); 204 } 205 if (bitmap) 206 status = fImageView->SetImage(NULL, bitmap); 207 printf("error 0x%08lx\n", status); 208 if (status != B_OK) { 209 //XXX 210 entry_ref ref; 211 _LoadError(ref); 212 Quit(); 213 return; 214 } 215 fImageView->FitToBounds(); 216 fImageView->MakeFocus(true); 217 SetTitle("Untitled"); 218 Show(); 219 } else if (_LoadImage() != B_OK) { // finish creating the window 192 220 _LoadError(ref); 193 221 Quit(); 194 222 return; 195 223 } 224 printf("done\n"); 196 225 197 226 // add View menu here so it can access ShowImageView methods 198 227 BMenu* menu = new BMenu(B_TRANSLATE_WITH_CONTEXT("View", "Menus")); … … 211 240 // and tell this window if it contains interesting data or not 212 241 be_app_messenger.SendMessage(B_CLIPBOARD_CHANGED); 213 242 243 printf("Run()\n"); 214 244 // The window will be shown on screen automatically 215 245 Run(); 216 246 } … … 320 350 { 321 351 BMenu* menu = new BMenu(B_TRANSLATE("File")); 322 352 353 _AddItemMenu(menu, B_TRANSLATE("New from clipboard"), B_PASTE, 'N', 0, this); 323 354 // Add recent files to "Open File" entry as sub-menu. 324 355 BMenuItem* item = new BMenuItem(BRecentFilesList::NewFileListMenu( 325 356 B_TRANSLATE("Open"B_UTF8_ELLIPSIS), NULL, NULL, be_app, 10, true, … … 711 742 fImageView->CopySelectionToClipboard(); 712 743 break; 713 744 745 case B_PASTE: 746 be_app->PostMessage(message); 747 break; 748 714 749 case MSG_SELECTION_MODE: 715 750 fImageView->SetSelectionMode(_ToggleMenuItem(MSG_SELECTION_MODE)); 716 751 break; -
src/apps/showimage/ShowImageWindow.h
47 47 public: 48 48 ShowImageWindow(BRect frame, 49 49 const entry_ref& ref, 50 const BMessenger& trackerMessenger); 50 const BMessenger& trackerMessenger, 51 bool fromClipboard=false); 51 52 virtual ~ShowImageWindow(); 52 53 53 54 void BuildContextMenu(BMenu* menu); -
src/apps/showimage/ShowImageApp.cpp
125 125 _StartPulse(); 126 126 break; 127 127 128 case B_PASTE: 129 _CreateFromClipboard(); 130 break; 131 128 132 case B_CLIPBOARD_CHANGED: 129 133 _CheckClipboard(); 130 134 break; … … 237 241 238 242 239 243 void 244 ShowImageApp::_CreateFromClipboard() 245 { 246 fLastWindowFrame.OffsetBy(20, 20); 247 if (!BScreen(B_MAIN_SCREEN_ID).Frame().Contains(fLastWindowFrame)) 248 fLastWindowFrame.OffsetTo(50, 50); 249 250 entry_ref ref; 251 BMessenger messenger; 252 new ShowImageWindow(fLastWindowFrame, ref, messenger, true); 253 } 254 255 256 void 240 257 ShowImageApp::_CheckClipboard() 241 258 { 242 259 // Determines if the contents of the clipboard contain -
src/apps/showimage/ShowImageApp.h
43 43 void _Open(const entry_ref& ref, 44 44 const BMessenger& trackerMessenger); 45 45 void _BroadcastToWindows(BMessage* message); 46 void _CreateFromClipboard(); 46 47 void _CheckClipboard(); 47 48 void _UpdateLastWindowFrame(); 48 49