bool gui_commit_clipboard(void) { BMessage *clip; if (current_selection.Length() == 0) return true; if (be_clipboard->Lock()) { be_clipboard->Clear(); clip = be_clipboard->Data(); if (clip) { clip->AddData("text/plain", B_MIME_TYPE, current_selection.String(), current_selection.Length()); int arraySize = sizeof(text_run_array) + current_selection_textruns.CountItems() * sizeof(text_run); text_run_array *array = (text_run_array *)malloc(arraySize); array->count = current_selection_textruns.CountItems(); for (int i = 0; i < array->count; i++) memcpy(&array->runs[i], current_selection_textruns.ItemAt(i), sizeof(text_run)); clip->AddData("application/x-vnd.Be-text_run_array", B_MIME_TYPE, array, arraySize); free(array); gui_empty_clipboard(); be_clipboard->Commit(); } be_clipboard->Unlock(); } return true; }
bool ami_easy_clipboard(char *text) { if(!gui_empty_clipboard()) return false; if(!gui_add_to_clipboard(text,strlen(text),false)) return false; if(!gui_commit_clipboard()) return false; return true; }
bool gui_copy_to_clipboard(struct selection *s) { bool success; if(s->defined == false) return false; if(!gui_empty_clipboard()) return false; success = selection_traverse(s, ami_clipboard_copy, NULL); /* commit regardless, otherwise we leave the clipboard in an unusable state */ gui_commit_clipboard(); return success; }