Exemplo n.º 1
0
//
// AbiGOComponent_Create
// -------------------
//   This is the function that we actually call to insert a new intially empty component.
bool 
AbiGOComponent_Create (G_GNUC_UNUSED AV_View* v, G_GNUC_UNUSED EV_EditMethodCallData *d)
{
    XAP_Frame *pFrame = XAP_App::getApp()->getLastFocussedFrame();
	XAP_UnixFrameImpl *pFrameImpl = static_cast<XAP_UnixFrameImpl*>(pFrame->getFrameImpl());
	std::string cancel, ok;
	const XAP_StringSet *pSS = XAP_App::getApp()->getStringSet();
	pSS->getValueUTF8(XAP_STRING_ID_DLG_Cancel, cancel);
	pSS->getValueUTF8(XAP_STRING_ID_DLG_OK, ok);
	GtkDialog *dialog = GTK_DIALOG (gtk_dialog_new_with_buttons ("New Object",
		GTK_WINDOW(pFrameImpl->getTopLevelWindow()),
		(GtkDialogFlags) (GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT),
		convertMnemonics(cancel).c_str(), GTK_RESPONSE_CANCEL,
		convertMnemonics(ok).c_str(), GTK_RESPONSE_OK, NULL));
	GtkListStore *list = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
	GtkWidget *w = gtk_tree_view_new_with_model (GTK_TREE_MODEL (list));
	g_signal_connect_swapped(w, "button-press-event", G_CALLBACK(button_press_cb), dialog);
	GtkCellRenderer *renderer;
	GtkTreeViewColumn *column;
	renderer = gtk_cell_renderer_text_new ();
	column = gtk_tree_view_column_new_with_attributes ("Object type:", renderer, "text", 0, NULL);
	gtk_tree_view_append_column (GTK_TREE_VIEW (w), column);
	GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW (w));
	gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE);
	GtkTreeIter iter;
	GSList *l = mime_types;
	gchar const *mime_type;
	while (l) {
		mime_type = (gchar const *) l->data;
		if (strcmp(mime_type, "application/mathml+xml")
		    && go_components_get_priority(mime_type) >= GO_MIME_PRIORITY_PARTIAL)
		{
			gtk_list_store_append (list, &iter);
			gtk_list_store_set (list, &iter,
					  0, go_mime_type_get_description (mime_type),
					  1, mime_type,
					  -1);
		}
		l = l->next;
	}
	gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area(dialog)), w, false, false, 0);
	gtk_widget_show_all (GTK_WIDGET(dialog));
	gint result = gtk_dialog_run (dialog);
	if (result == GTK_RESPONSE_OK &&
		gtk_tree_selection_get_selected (sel, NULL, &iter)) {
		gtk_tree_model_get (GTK_TREE_MODEL (list), &iter, 1, &mime_type, -1);
		GOComponent *component = go_component_new_by_mime_type (mime_type);
		go_component_set_inline (component, true);
		go_component_set_use_font_from_app (component, true);
		g_signal_connect (G_OBJECT (component), "changed",
								G_CALLBACK (changed_cb), NULL);
		GtkWindow *win = go_component_edit(component);
		gtk_window_set_transient_for(win, GTK_WINDOW(pFrameImpl->getTopLevelWindow()));
	}
	gtk_widget_destroy (GTK_WIDGET (dialog));
	return result == GTK_RESPONSE_OK;
}
Exemplo n.º 2
0
GR_Graphics * AP_Win32App::newDefaultScreenGraphics() const
{
	XAP_Frame * pFrame = findValidFrame();
	UT_return_val_if_fail( pFrame, NULL );
	
	AP_Win32FrameImpl * pFI = (AP_Win32FrameImpl *) pFrame->getFrameImpl();
	UT_return_val_if_fail( pFI, NULL );

	return pFI->createDocWndGraphics();
}
Exemplo n.º 3
0
GR_Graphics * AP_UnixApp::newDefaultScreenGraphics() const
{
	XAP_Frame * pFrame = findValidFrame();
	UT_return_val_if_fail( pFrame, NULL );
	UT_DEBUGMSG(("AP_UnixApp::newDefaultScreenGraphics() \n"));
	AP_UnixFrameImpl * pFI = static_cast<AP_UnixFrameImpl *>(pFrame->getFrameImpl());
	UT_return_val_if_fail( pFI, NULL );

	GtkWidget * da = pFI->getDrawingArea();
	UT_return_val_if_fail( da, NULL );
	
	GR_UnixCairoAllocInfo ai(da);
	return XAP_App::getApp()->newGraphics(ai);
}
bool XAP_Win32AppImpl::openURL(const char * szURL)
{
	// NOTE: could get finer control over browser window via DDE 
	// NOTE: may need to fallback to WinExec for old NSCP versions

	UT_String sURL = szURL;

	// If this is a file:// URL, strip off file:// and make it backslashed
	if (sURL.substr(0, 7) == "file://")
	{
		sURL = sURL.substr(7, sURL.size() - 7);

		// View as WebPage likes to throw in an extra /\ just for fun, strip it off
		if (sURL.substr(0, 2) == "/\\")
			sURL = sURL.substr(2, sURL.size() - 2);

		if (sURL.substr(0, 1) == "/")
			sURL = sURL.substr(1, sURL.size() - 1);
		
		// Convert all forwardslashes to backslashes
		for (unsigned int i=0; i<sURL.length();i++)	
			if (sURL[i]=='/')	
                sURL[i]='\\';

		// Convert from longpath to 8.3 shortpath, in case of spaces in the path
		char* longpath = NULL;
		char* shortpath = NULL;
		longpath = new char[PATH_MAX];
		shortpath = new char[PATH_MAX];
		strcpy(longpath, sURL.c_str());
		DWORD retval = GetShortPathName(longpath, shortpath, PATH_MAX);
		if((retval == 0) || (retval > PATH_MAX))
		{
			UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN);
			DELETEP(longpath);
			DELETEP(shortpath);
			return false;
		}
		sURL = shortpath;
		DELETEP(longpath);
		DELETEP(shortpath);
	}

	// Query the registry for the default browser so we can directly invoke it
	UT_String sBrowser;
	HKEY hKey;
	unsigned long lType;
	DWORD dwSize;
	unsigned char* szValue = NULL;

	if (RegOpenKeyEx(HKEY_CLASSES_ROOT, "http\\shell\\open\\command", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
	{
		if(RegQueryValueEx(hKey, NULL, NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS)
		{
			szValue = new unsigned char[dwSize + 1];
			RegQueryValueEx(hKey, NULL, NULL, &lType, szValue, &dwSize);
			sBrowser = (char*) szValue;
			DELETEP(szValue);
		}
		RegCloseKey(hKey);
	}

	/* Now that we have sBrowser from the registry, we need to parse it out.
	 * If the first character is a double-quote, everything up to and including
	 * the next double-quote is the sBrowser command. Everything after the
	 * double-quote is appended to the parameters.
	 * If the first character is NOT a double-quote, we assume
	 * everything up to the first whitespace is the command and anything after
	 * is appended to the parameters.
	 */

	int iDelimiter;
	if (sBrowser.substr(0, 1) == "\"")
		iDelimiter = UT_String_findCh(sBrowser.substr(1, sBrowser.length()-1), '"')+2;
	else
		iDelimiter = UT_String_findCh(sBrowser.substr(0, sBrowser.length()), ' ');

	// Store params into a separate UT_String before we butcher sBrowser
	UT_String sParams = sBrowser.substr(iDelimiter+1, sBrowser.length()-iDelimiter+1);
	// Cut params off of sBrowser so all we're left with is the broweser path & executable
	sBrowser = sBrowser.substr(0, iDelimiter);

	// Check for a %1 passed in from the registry.  If we find it,
	// substitute our URL for %1.  Otherwise, just append sURL to params.
	const char *pdest = strstr(sParams.c_str(), "%1");
	if (pdest != NULL)
	{
		int i = pdest - sParams.c_str() + 1;
		sParams = sParams.substr(0, i-1) + sURL + sParams.substr(i+1, sParams.length()-i+1);
	}
	else
	{
		sParams = sParams + " " + sURL;
	}

	// Win95 doesn't like the Browser command to be quoted, so strip em off.
	if (sBrowser.substr(0, 1) == "\"")
		sBrowser = sBrowser.substr(1, sBrowser.length() - 1);
	if (sBrowser.substr(sBrowser.length()-1, 1) == "\"")
		sBrowser = sBrowser.substr(0, sBrowser.length() - 1);

	XAP_Frame * pFrame = XAP_App::getApp()->getLastFocussedFrame();
	UT_return_val_if_fail(pFrame, false);
	XAP_Win32FrameImpl *pFImp =  (XAP_Win32FrameImpl *) pFrame->getFrameImpl();
	UT_return_val_if_fail(pFImp, false);

	intptr_t res = (intptr_t) ShellExecuteA(pFImp->getTopLevelWindow() /*(HWND)*/,
								 "open", sBrowser.c_str(), sParams.c_str(), NULL, SW_SHOW );

	// TODO: localized error messages
	// added more specific error messages as documented in http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes.asp
	if (res <= 32)
	{
		UT_String errMsg;
		switch (res)
		{
			case ERROR_FILE_NOT_FOUND:
				{
					errMsg = "Error ("; 
					errMsg += UT_String_sprintf("%d", res);
					errMsg += ") displaying URL: The system cannot find the file specified.\n";
					errMsg += " [ ";  errMsg += sURL;  errMsg += " ] ";
					MessageBoxA(pFImp->getTopLevelWindow(), errMsg.c_str(), "Error displaying URL", MB_OK|MB_ICONEXCLAMATION);
				}
				break;

			case ERROR_PATH_NOT_FOUND:
				{
					errMsg = "Error ("; 
					errMsg += UT_String_sprintf("%d", res);
					errMsg += ") displaying URL: The system cannot find the path specified.\n";
					errMsg += " [ ";  errMsg += sURL;  errMsg += " ] ";
					MessageBoxA(pFImp->getTopLevelWindow(), errMsg.c_str(), "Error displaying URL", MB_OK|MB_ICONEXCLAMATION);
				}
				break;

			case SE_ERR_ACCESSDENIED:
				{
					errMsg = "Error ("; 
					errMsg += UT_String_sprintf("%d", res);
					errMsg += ") displaying URL: Access is denied.\n";
					errMsg += " [ ";  errMsg += sURL;  errMsg += " ] ";
					MessageBoxA(pFImp->getTopLevelWindow(), errMsg.c_str(), "Error displaying URL", MB_OK|MB_ICONEXCLAMATION);
				}
				break;

			default:
				{
					errMsg = "Error ("; 
					errMsg += UT_String_sprintf("%d", res);
					errMsg += ") displaying URL: \n";
					errMsg += " [ ";  errMsg += sURL;  errMsg += " ] ";
					MessageBoxA(pFImp->getTopLevelWindow(), errMsg.c_str(), "Error displaying URL", MB_OK|MB_ICONEXCLAMATION);
				}
				break;
		} /* switch (res) */
	} /* if (res <= 32) */

	return (res>32);
}
Exemplo n.º 5
0
void FV_UnixFrameEdit::mouseDrag(UT_sint32 x, UT_sint32 y)
{
    UT_DEBUGMSG(("Mouse drag x=%d y=%d \n",x,y));
    bool bYOK = ( (y > 0) && (y < getView()->getWindowHeight()));
    if(!bYOK || (x> 0 && x < getView()->getWindowWidth()))
     {
         m_bDragOut = false;
	 _mouseDrag(x,y);
	 return;
     }
     if(FV_DragWhole != getDragWhat())
     {
         m_bDragOut = false;
	 _mouseDrag(x,y);
	 return;
     }
     if(FV_FrameEdit_DRAG_EXISTING != getFrameEditMode())
     {
         m_bDragOut = false;
	 _mouseDrag(x,y);
	 return;
     }
     if(!isImageWrapper())
     {
         m_bDragOut = false;
	 _mouseDrag(x,y);
	 return;
     }
     if(!m_bDragOut)
     {
	 const UT_ByteBuf * pBuf = NULL;
	 const char * pszData = getPNGImage(&pBuf);
	 UT_DEBUGMSG(("Got image buffer %p pszData %p \n",pBuf,pszData));
	 if(pBuf)
	 {
       //
       // write the image to a temperary file
       //
	     XAP_UnixApp * pXApp = static_cast<XAP_UnixApp *>(XAP_App::getApp());
	     pXApp->removeTmpFile();
	     char ** pszTmpName = pXApp->getTmpFile();
	     UT_UTF8String sTmpF = g_get_tmp_dir();
	     sTmpF += "/";
	     sTmpF += pszData;
	     sTmpF += ".png";
	     //
	     // Now write the contents of the buffer to a temp file.
	     //
	     FILE * fd = fopen(sTmpF.utf8_str(),"w");
	     fwrite(pBuf->getPointer(0),sizeof(UT_Byte),pBuf->getLength(),fd);
	     fclose(fd);

       //
       // OK set up the gtk drag and drop code to andle this
       //
	     XAP_Frame * pFrame = static_cast<XAP_Frame*>(getView()->getParentData());
	     XAP_UnixFrameImpl * pFrameImpl =static_cast<XAP_UnixFrameImpl *>( pFrame->getFrameImpl());
	     GtkWidget * pWindow = pFrameImpl->getTopLevelWindow();
	     GtkTargetList *target_list = gtk_target_list_new(targets, G_N_ELEMENTS(targets));
	     GdkDragContext *context = gtk_drag_begin(pWindow, target_list,
						(GdkDragAction)(GDK_ACTION_COPY ), 1, NULL);

	     gdk_drag_status(context, GDK_ACTION_COPY, 0);
	     gtk_target_list_unref(target_list);
	     *pszTmpName = g_strdup(sTmpF.utf8_str());  
	     UT_DEBUGMSG(("Created Tmp File %s XApp %s \n",sTmpF.utf8_str(),*pXApp->getTmpFile()));

	 }
	 //
	 // OK quit dragging the image and return to the previous state
	 //
	 m_bDragOut = true;
	 abortDrag();
     }
     m_bDragOut = true;
}