void abiSetupModalDialog(GtkDialog * dialog, XAP_Frame *pFrame, XAP_Dialog * pDlg, gint defaultResponse)
{
	GtkWidget *popup = GTK_WIDGET (dialog);
	gtk_dialog_set_default_response (GTK_DIALOG (popup), defaultResponse);
	gtk_window_set_modal (GTK_WINDOW(popup), TRUE);

	// To center the dialog, we need the frame of its parent.
	if (pFrame)
	{
		XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(pFrame->getFrameImpl());
		GtkWidget * parentWindow = pUnixFrameImpl->getTopLevelWindow();
		if (GTK_IS_WINDOW(parentWindow) != TRUE)
			parentWindow  = gtk_widget_get_parent(parentWindow);
		centerDialog (parentWindow, GTK_WIDGET(popup));
	}
	connectFocus (GTK_WIDGET(popup), pFrame);

	// connect F1 to the help subsystem
	g_signal_connect (G_OBJECT(popup), "key-press-event",
					  G_CALLBACK(modal_keypress_cb), pDlg);
	
	// set the default response
	sAddHelpButton (GTK_DIALOG (popup), pDlg);

	// show the window
	gtk_widget_show (GTK_WIDGET (popup));
}
Example #2
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;
}
Example #3
0
void XAP_UnixDialog_Print::runModal(XAP_Frame * pFrame) 
{
	m_pFrame = pFrame;
	setupPrint();
    gtk_print_operation_set_show_progress(m_pPO, TRUE);

	XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(m_pFrame->getFrameImpl());
	
	// Get the GtkWindow of the parent frame
	GtkWidget * parent = pUnixFrameImpl->getTopLevelWindow();
	GtkWindow * pPWindow = GTK_WINDOW(parent);
	//	const XAP_StringSet * pSS = XAP_App::getApp()->getStringSet();
	//	const gchar * szDialogName = einterpret_cast<const gchar *>(pSS->getValue(XAP_STRING_ID_DLG_UP_PrintTitle);

	gtk_print_operation_run (m_pPO,
							 (m_bIsPreview)? GTK_PRINT_OPERATION_ACTION_PREVIEW:
							 GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
							 pPWindow, NULL);

	cleanup();
}
/*!
 * Sets up the dialog \me as a modeless dialog
 * 1) Connect focus to toplevel frame
 * 2) Centers dialog over toplevel window
 * 3) Makes the App remember this modeless dialog
 * 4) Connects F1 to help system
 * 5) Makes dialog non-modal (modeless)
 * 
6) Sets the default button to defaultResponse, sets ESC to close
 */
void abiSetupModelessDialog(GtkDialog * me, XAP_Frame * pFrame, XAP_Dialog * pDlg,
							gint defaultResponse, bool abi_modeless, AtkRole /*role*/ )
{
	if (abi_modeless)
	{
		// remember the modeless id
		XAP_App::getApp()->rememberModelessId( pDlg->getDialogId(), static_cast<XAP_Dialog_Modeless *>(pDlg));

		// connect focus to our parent frame
		connectFocusModeless(GTK_WIDGET(me), XAP_App::getApp());
	}

	// To center the dialog, we need the frame of its parent.
	if (pFrame)
	{
		XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(pFrame->getFrameImpl());
		GtkWidget * parentWindow = gtk_widget_get_toplevel (pUnixFrameImpl->getTopLevelWindow());
		centerDialog ( parentWindow, GTK_WIDGET(me), false ) ;
	}
	
	// connect F1 to the help subsystem
	g_signal_connect (G_OBJECT(me), "key-press-event",
					  G_CALLBACK(nonmodal_keypress_cb), pDlg);
	
	// set the default response
	gtk_dialog_set_default_response ( me, defaultResponse ) ;
	sAddHelpButton (me, pDlg);

	// and mark it as modeless
	gtk_window_set_modal ( GTK_WINDOW(me), FALSE ) ;
	// FIXME: shouldn't we pass role here?
	atk_object_set_role (gtk_widget_get_accessible (GTK_WIDGET (me)), ATK_ROLE_ALERT);
	
	// show the window
	gtk_widget_show ( GTK_WIDGET(me) ) ;
}
void XAP_UnixDialog_MessageBox::runModal(XAP_Frame * pFrame)
{
    XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(pFrame->getFrameImpl());
    UT_return_if_fail(pUnixFrameImpl);

    XAP_UnixApp * pApp = static_cast<XAP_UnixApp *>(XAP_App::getApp());
    UT_return_if_fail(pApp);

    GtkWidget * message = 0;	// initialize to prevent compiler warning
    GtkWindow * toplevel;

    toplevel = GTK_WINDOW(pUnixFrameImpl->getTopLevelWindow());

    int dflFlags = GTK_DIALOG_MODAL;
    int dflResponse = GTK_RESPONSE_OK;

    switch (m_buttons)
    {
    case b_O:
	// just put up an information box
	message = gtk_message_dialog_new ( toplevel, GTK_DIALOG_MODAL,
					   GTK_MESSAGE_INFO,
					   GTK_BUTTONS_OK,
					   "%s",
					   m_szMessage ) ;

	break;

    case b_YN:
	// YES - NO - most certainly a question
	message = gtk_message_dialog_new ( toplevel, GTK_DIALOG_MODAL,
					   GTK_MESSAGE_QUESTION,
					   GTK_BUTTONS_YES_NO,
					   "%s",
					   m_szMessage ) ;
	if(m_defaultAnswer == XAP_Dialog_MessageBox::a_YES)
	{
	    gtk_dialog_set_default_response (GTK_DIALOG(message),
					     GTK_RESPONSE_YES);
	}
	else
	{
	    gtk_dialog_set_default_response (GTK_DIALOG(message),
					     GTK_RESPONSE_NO);
	}
	break;

    case b_YNC:
    {
	// YES - NO - CANCEL
	// this is only used for saving files.
#ifndef EMBEDDED_TARGET
	std::string no, cancel, save;
	std::string labelText;
	const XAP_StringSet * pSS = pApp->getStringSet ();

	message = gtk_dialog_new_with_buttons("",
					      toplevel,
					      static_cast<GtkDialogFlags>(dflFlags),
					      NULL, NULL);
	pSS->getValueUTF8(XAP_STRING_ID_DLG_Exit_CloseWithoutSaving, no);
	pSS->getValueUTF8(XAP_STRING_ID_DLG_Cancel, cancel);
	pSS->getValueUTF8(XAP_STRING_ID_DLG_Save, save);
	gtk_dialog_add_buttons(GTK_DIALOG(message),
			       convertMnemonics(no).c_str(),
			       GTK_RESPONSE_NO,
			       convertMnemonics(cancel).c_str(),
			       GTK_RESPONSE_CANCEL,
			       convertMnemonics(save).c_str(),
			       GTK_RESPONSE_YES,
			       NULL);

	dflResponse = GTK_RESPONSE_YES;

	GtkWidget * label = gtk_label_new(NULL);
	const char * separator;
	separator = m_szSecondaryMessage ? "\n\n" : "";

	gchar     * msg = g_markup_escape_text (m_szMessage, -1);
	labelText = UT_std_string_sprintf(
	    "<span weight=\"bold\" size=\"larger\">%s</span>%s%s",
	    msg, separator, m_szSecondaryMessage);
	g_free (msg); msg = NULL;

	gtk_label_set_markup(GTK_LABEL(label), labelText.c_str());

	GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);

	gtk_box_pack_start (GTK_BOX (hbox),
			    gtk_image_new_from_icon_name("dialog-warning",
							 GTK_ICON_SIZE_DIALOG),
			    FALSE, FALSE, 0);

	gtk_box_pack_start (GTK_BOX (hbox), label,
			    TRUE, TRUE, 0);

	GtkBox *content_area = GTK_BOX (gtk_dialog_get_content_area(GTK_DIALOG(message)));
	gtk_box_pack_start (content_area, hbox, FALSE, FALSE, 0);

	gtk_box_set_spacing(content_area, 12);
	gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
	gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);

	gtk_widget_show_all (hbox);

#else
	message = gtk_message_dialog_new (toplevel,
					  static_cast<GtkDialogFlags>(dflFlags),
					  GTK_MESSAGE_QUESTION,
					  GTK_BUTTONS_NONE,
					  "%s",
					  m_szMessage);

	gtk_dialog_add_buttons(GTK_DIALOG(message),
			       GTK_STOCK_NO,
			       GTK_RESPONSE_NO,
			       GTK_STOCK_CANCEL,
			       GTK_RESPONSE_CANCEL,
			       GTK_STOCK_YES,
			       GTK_RESPONSE_YES,
			       NULL);
#endif
	gtk_dialog_set_default_response (GTK_DIALOG(message),
					 GTK_RESPONSE_CANCEL);

	break;
    }
    default:
	UT_ASSERT_NOT_REACHED();
    }

    // set the title to '', as per GNOME HIG, Section 3, Alerts
    gtk_window_set_title (GTK_WINDOW(message), "");

    UT_ASSERT(message);

    switch ( abiRunModalDialog ( GTK_DIALOG(message), pFrame,
				 this, dflResponse, true, ATK_ROLE_ALERT ) )
    {
    case GTK_RESPONSE_OK:
	m_answer = XAP_Dialog_MessageBox::a_OK;
	break;
    case GTK_RESPONSE_YES:
	m_answer = XAP_Dialog_MessageBox::a_YES;
	break;
    case GTK_RESPONSE_NO:
	m_answer = XAP_Dialog_MessageBox::a_NO;
	break;
    case GTK_RESPONSE_CANCEL:
    default:
	m_answer = XAP_Dialog_MessageBox::a_CANCEL; break;
    }
}
void XAP_UnixDialog_FileOpenSaveAs::runModal(XAP_Frame * pFrame)
{
    const XAP_StringSet * pSS = m_pApp->getStringSet();
    std::string szTitle;
    std::string szFileTypeLabel;

    switch (m_id)
    {
    case XAP_DIALOG_ID_INSERT_PICTURE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_IP_Title, szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel, szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_FILE_OPEN:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_OpenTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_FILE_IMPORT:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ImportTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_INSERTMATHML:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_InsertMath,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileInsertMath,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_INSERTOBJECT:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_InsertObject,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileInsertObject,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_INSERT_FILE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_InsertTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileOpenTypeLabel,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    case XAP_DIALOG_ID_FILE_SAVEAS:
    case XAP_DIALOG_ID_FILE_SAVE_IMAGE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_SaveAsTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileSaveTypeLabel,szFileTypeLabel);
        m_bSave = true;
        break;
    }
    case XAP_DIALOG_ID_FILE_EXPORT:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ExportTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileSaveTypeLabel,szFileTypeLabel);
        m_bSave = true;
        break;
    }
    case XAP_DIALOG_ID_PRINTTOFILE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_PrintToFileTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FilePrintTypeLabel,szFileTypeLabel);
        m_bSave = true;
        break;
    }
    case XAP_DIALOG_ID_RECORDTOFILE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_RecordToFileTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_RecordToFileLabel,szFileTypeLabel);
        m_bSave = true;
        break;
    }
    case XAP_DIALOG_ID_REPLAYFROMFILE:
    {
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ReplayFromFileTitle,szTitle);
        pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_ReplayFromFileLabel,szFileTypeLabel);
        m_bSave = false;
        break;
    }
    default:
        UT_ASSERT(UT_SHOULD_NOT_HAPPEN);
        m_bSave = false;
        break;
    }

    // NOTE: we use our string mechanism to localize the dialog's
    // NOTE: title and the error/confirmation message boxes.  we
    // NOTE: let GTK take care of the localization of the actual
    // NOTE: buttons and labels on the FileSelection dialog.

    // Get the GtkWindow of the parent frame
    XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(pFrame->getFrameImpl());
    GtkWidget * parent = pUnixFrameImpl->getTopLevelWindow();

    if(parent && (GTK_WIDGET_TOPLEVEL(parent) != TRUE))
    {
        parent = gtk_widget_get_toplevel (parent);
    }

#if defined(EMBEDDED_TARGET) && EMBEDDED_TARGET == EMBEDDED_TARGET_HILDON
    m_FC = GTK_FILE_CHOOSER( hildon_file_chooser_dialog_new(GTK_WINDOW(parent),
                             (!m_bSave ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE))
                           );
#else
    m_FC = GTK_FILE_CHOOSER( gtk_file_chooser_dialog_new (szTitle.c_str(),
                             GTK_WINDOW(parent),
                             (!m_bSave ? GTK_FILE_CHOOSER_ACTION_OPEN : GTK_FILE_CHOOSER_ACTION_SAVE),
                             GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                             (m_bSave ? GTK_STOCK_SAVE : GTK_STOCK_OPEN), GTK_RESPONSE_ACCEPT,
                             (gchar*)NULL)
                           );
#endif

    gtk_file_chooser_set_local_only(m_FC, FALSE);

    abiSetupModalDialog(GTK_DIALOG(m_FC), pFrame, this, GTK_RESPONSE_ACCEPT);
    GtkWidget * filetypes_pulldown = NULL;

    std::string s;

    /*
      Add a drop-down list of known types to facilitate a file-types selection.
      We store an indexer in the user data for each menu item in the popup, so
      we can read the type we need to return.
    */

    if (m_id == XAP_DIALOG_ID_INSERT_PICTURE)
    {
        GtkWidget * preview = createDrawingArea ();
        gtk_widget_show (preview);
        m_preview = preview;
        gtk_widget_set_size_request (preview, PREVIEW_WIDTH, PREVIEW_HEIGHT);

        // place the preview area inside a container to get a nice border
        GtkWidget * preview_hbox = gtk_hbox_new(FALSE, 0);
        gtk_container_set_border_width  (GTK_CONTAINER(preview_hbox), 4);
        gtk_box_pack_start(GTK_BOX(preview_hbox), preview, TRUE, TRUE, 0);

        // attach the preview area to the dialog
        gtk_file_chooser_set_preview_widget (m_FC, preview_hbox);
        gtk_file_chooser_set_preview_widget_active (m_FC, true);

        // connect some signals
        g_signal_connect (m_FC, "update_preview",
                          G_CALLBACK (file_selection_changed), static_cast<gpointer>(this));

        g_signal_connect (preview, "expose_event",
                          G_CALLBACK (s_preview_exposed), static_cast<gpointer>(this));
    }

#if defined(EMBEDDED_TARGET) && EMBEDDED_TARGET == EMBEDDED_TARGET_HILDON
    filetypes_pulldown = gtk_combo_box_new();
    gtk_widget_show(filetypes_pulldown);
    GtkWidget * pulldown_hbox = filetypes_pulldown;
#else
    // hbox for our pulldown menu (GTK does its pulldown this way */
    GtkWidget * pulldown_hbox = gtk_hbox_new(FALSE, 15);
    gtk_widget_show(pulldown_hbox);

    // pulldown label
    GtkWidget * filetypes_label = gtk_label_new_with_mnemonic(convertMnemonics(szFileTypeLabel).c_str());
    gtk_label_set_justify(GTK_LABEL(filetypes_label), GTK_JUSTIFY_RIGHT);
    gtk_misc_set_alignment(GTK_MISC(filetypes_label), 1.0, 0.5);
    gtk_widget_show(filetypes_label);
    gtk_box_pack_start(GTK_BOX(pulldown_hbox), filetypes_label, TRUE, TRUE, 0);

    // pulldown menu
    filetypes_pulldown = gtk_combo_box_new();
    gtk_widget_show(filetypes_pulldown);
    gtk_box_pack_end(GTK_BOX(pulldown_hbox), filetypes_pulldown, TRUE, TRUE, 0);
    gtk_label_set_mnemonic_widget(GTK_LABEL(filetypes_label), filetypes_pulldown);
#endif
    //
    // add the filters to the dropdown list
    //
    GtkComboBox* combo = GTK_COMBO_BOX(filetypes_pulldown);
    XAP_makeGtkComboBoxText(combo, G_TYPE_INT);

    // Auto-detect is always an option, but a special one, so we use
    // a pre-defined constant for the type, and don't use the user-supplied
    // types yet.
    pSS->getValueUTF8(XAP_STRING_ID_DLG_FOSA_FileTypeAutoDetect,s);
    XAP_appendComboBoxTextAndInt(combo, s.c_str(), XAP_DIALOG_FILEOPENSAVEAS_FILE_TYPE_AUTO);

    UT_sint32 activeItemIndex = -1;

    // add list items
    {
        UT_ASSERT(g_strv_length((gchar **) m_szSuffixes) == g_strv_length((gchar **) m_szDescriptions));

        // measure one list, they should all be the same length
        UT_uint32 end = g_strv_length((gchar **) m_szDescriptions);

        for (UT_uint32 i = 0; i < end; i++)
        {
            // If this type is default, save its index (i) for later use
            if (m_nTypeList[i] == m_nDefaultFileType)
                activeItemIndex = i;

            XAP_appendComboBoxTextAndInt(combo, m_szDescriptions[i], m_nTypeList[i]);
//
// Attach a callback when it is activated to change the file suffix
//
//			g_signal_connect(G_OBJECT(thismenuitem), "activate",
//							 G_CALLBACK(s_filetypechanged),
//							 reinterpret_cast<gpointer>(this));
        }
    }

    m_wFileTypes_PullDown = filetypes_pulldown;
    // dialog; open dialog always does auto-detect
    // TODO: should this also apply to the open dialog?
    if (m_id == XAP_DIALOG_ID_FILE_SAVEAS || m_id == XAP_DIALOG_ID_FILE_SAVE_IMAGE)
    {
        gtk_combo_box_set_active(combo, activeItemIndex + 1);
    }
    else
    {
        gtk_combo_box_set_active(combo, 0);
    }

#if defined(EMBEDDED_TARGET) && EMBEDDED_TARGET == EMBEDDED_TARGET_HILDON
    hildon_file_chooser_dialog_add_extra ((HildonFileChooserDialog*)m_FC,
                                          pulldown_hbox);
#else
    gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER(m_FC), pulldown_hbox);
#endif

    // connect the signals for OK and CANCEL and the requisite clean-close signals
    g_signal_connect(G_OBJECT(m_FC),
                     "delete-event",
                     G_CALLBACK(s_delete_clicked),
                     this);

    g_signal_connect(G_OBJECT(m_FC),
                     "key_press_event",
                     G_CALLBACK(fsel_key_event), &m_answer);

    g_signal_connect (G_OBJECT (m_FC),
                      "response",
                      G_CALLBACK(dialog_response), &m_answer);

    g_signal_connect (G_OBJECT (m_FC),
                      "file-activated",
                      G_CALLBACK(s_file_activated), &m_answer);

    g_signal_connect(G_OBJECT(filetypes_pulldown), "changed",
                     G_CALLBACK(s_filetypechanged),
                     reinterpret_cast<gpointer>(this));

    // use the persistence info and/or the suggested filename
    // to properly seed the dialog.

    gchar * szPersistDirectory = NULL;	// we must g_free this

    if (!m_szInitialPathname || !*m_szInitialPathname)
    {
        // the caller did not supply initial pathname
        // (or supplied an empty one).  see if we have
        // some persistent info.

        UT_ASSERT(!m_bSuggestName);
        if (m_szPersistPathname)
        {
            // we have a pathname from a previous use,
            // extract the directory portion and start
            // the dialog there (but without a filename).

            szPersistDirectory = UT_go_dirname_from_uri(m_szPersistPathname, FALSE);
            gtk_file_chooser_set_current_folder_uri(m_FC, szPersistDirectory);
        }
        else
        {
            // no initial pathname given and we don't have
            // a pathname from a previous use, so just let
            // it come up in the current working directory.
        }
    }
    else
    {
        // we have an initial pathname (the name of the document
        // in the frame that we were invoked on).  if the caller
        // wanted us to suggest a filename, use the initial
        // pathname as is.  if not, use the directory portion of
        // it.

        if (m_bSuggestName)
        {
            xxx_UT_DEBUGMSG(("Iniitial filename is %s \n",m_szInitialPathname));
#if 0
            if (!g_path_is_absolute (m_szInitialPathname)) { // DAL: todo: is this correct?
                gchar *dir = g_get_current_dir ();
                gchar *file = m_szInitialPathname;
                gchar *filename = g_build_filename (dir, file, (gchar *)NULL);
                m_szInitialPathname = UT_go_filename_to_uri(filename);
                g_free(filename);
                g_free (dir);
                g_free (file);
            }
#endif
            if(m_id == XAP_DIALOG_ID_FILE_SAVEAS)
            {
                std::string szInitialSuffix = UT_pathSuffix(m_szInitialPathname);
                std::string szSaveTypeSuffix = IE_Exp::preferredSuffixForFileType(m_nDefaultFileType).utf8_str();
                if(!szInitialSuffix.empty() && !szSaveTypeSuffix.empty()
                        && (szSaveTypeSuffix != szInitialSuffix))
                {
                    std::string sFileName = m_szInitialPathname;
                    std::string::size_type i = sFileName.find_last_of('.');

                    if(i != std::string::npos)
                    {
                        // erase to the end()
                        sFileName.erase(i);
                        sFileName += szSaveTypeSuffix;
                        FREEP(m_szInitialPathname);
                        m_szInitialPathname = g_strdup(sFileName.c_str());
                    }
                }
            }
            if (UT_go_path_is_uri(m_szInitialPathname) || UT_go_path_is_path(m_szInitialPathname))
            {
                gtk_file_chooser_set_uri(m_FC, m_szInitialPathname);
            }
        }
        else
        {
            if (UT_go_path_is_uri(m_szInitialPathname) || UT_go_path_is_path(m_szInitialPathname))
            {
                szPersistDirectory = UT_go_dirname_from_uri(m_szInitialPathname, FALSE);
                gtk_file_chooser_set_current_folder_uri(m_FC, szPersistDirectory);
            }
            else
            {
                // we are dealing with a plain filename, not an URI or path, so
                // just let it come up in the current working directory.
            }
        }
    }

    // center the dialog
    xxx_UT_DEBUGMSG(("before center IS WIDGET_TOP_LEVL %d \n",(GTK_WIDGET_TOPLEVEL(parent))));
    xxx_UT_DEBUGMSG(("before center IS WIDGET WINDOW %d \n",(GTK_IS_WINDOW(parent))));
    centerDialog(parent, GTK_WIDGET(m_FC));
    xxx_UT_DEBUGMSG(("After center IS WIDGET WINDOW %d \n",(GTK_IS_WINDOW(parent))));

    gtk_widget_show(GTK_WIDGET(m_FC));
    gtk_grab_add(GTK_WIDGET(m_FC));

    bool bResult = _run_gtk_main(pFrame,filetypes_pulldown);

    if (bResult)
    {
        UT_ASSERT(m_szFinalPathnameCandidate);

        // store final path name and file type
        m_szFinalPathname = g_strdup(m_szFinalPathnameCandidate);

        FREEP(m_szFinalPathnameCandidate);

        // what a long ugly line of code
        m_nFileType = XAP_comboBoxGetActiveInt(GTK_COMBO_BOX(filetypes_pulldown));
    }

    if (m_FC != NULL) {
        gtk_grab_remove (GTK_WIDGET(m_FC));
        gtk_widget_destroy (GTK_WIDGET(m_FC));
        m_FC = NULL;
        FREEP(szPersistDirectory);
    }

    return;
}
Example #7
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;
}