void AP_UnixDialog_ListRevisions::runModal(XAP_Frame * pFrame) { m_mainWindow = constructWindow(); UT_return_if_fail(m_mainWindow); switch ( abiRunModalDialog ( GTK_DIALOG(m_mainWindow), pFrame, this, BUTTON_OK, false ) ) { case BUTTON_OK: event_OK () ; break ; default: event_Cancel () ; break ; } abiDestroyWidget ( m_mainWindow ) ; }
void XAP_UnixDialog_Language::runModal(XAP_Frame * pFrame) { // build the dialog GtkWidget * cf = constructWindow(); UT_return_if_fail(cf); _populateWindowData(); // connect a dbl-clicked signal to the column g_signal_connect_after(G_OBJECT(m_pLanguageList), "row-activated", G_CALLBACK(s_lang_dblclicked), static_cast<gpointer>(this)); abiRunModalDialog ( GTK_DIALOG(cf), pFrame, this, GTK_RESPONSE_CLOSE, false ); event_setLang(); abiDestroyWidget(cf); }
void AP_UnixDialog_MarkRevisions::runModal(XAP_Frame * pFrame) { GtkWidget * mainWindow = constructWindow(); UT_return_if_fail(mainWindow); // toggle what should be grayed and what shouldn't be event_FocusToggled () ; gint rc = abiRunModalDialog ( GTK_DIALOG(mainWindow), pFrame, this, BUTTON_CANCEL, false ); UT_DEBUGMSG(("AP_UnixDialog_MarkRevisions::runModal() rc:%d\n", rc )); switch ( rc ) { case BUTTON_OK: event_OK () ; break ; default: event_Cancel () ; break ; } /*if(mainWindow && GTK_IS_WIDGET(mainWindow)) gtk_widget_destroy(mainWindow);*/ abiDestroyWidget ( mainWindow ) ; }
void XAP_UnixDialog_FontChooser::runModal(XAP_Frame * pFrame) { m_pFrame = static_cast<XAP_Frame *>(pFrame); // used similarly to convert between text and numeric arguments static char sizeString[50]; // build the dialog GtkWidget * cf = constructWindow(); // freeze updates of the preview m_blockUpdate = true; // to sort out dupes std::set<std::string> fontSet; GtkTreeModel* model; GtkTreeIter iter; model = gtk_tree_view_get_model(GTK_TREE_VIEW(m_fontList)); gtk_list_store_clear(GTK_LIST_STORE(model)); GR_GraphicsFactory * pGF = XAP_App::getApp()->getGraphicsFactory(); if(!pGF) { return; } const std::vector<std::string> & names = GR_CairoGraphics::getAllFontNames(); for (std::vector<std::string>::const_iterator i = names.begin(); i != names.end(); ++i) { const std::string & fName = *i; if (fontSet.find(fName) == fontSet.end()) { fontSet.insert(fName); gtk_list_store_append(GTK_LIST_STORE(model), &iter); gtk_list_store_set(GTK_LIST_STORE(model), &iter, TEXT_COLUMN, fName.c_str(), -1); } } // Set the defaults in the list boxes according to dialog data gint foundAt = 0; const std::string sFontFamily = getVal("font-family"); foundAt = searchTreeView(GTK_TREE_VIEW(m_fontList), sFontFamily.c_str()); // select and scroll to font name if (foundAt >= 0) { GtkTreePath* path = gtk_tree_path_new_from_indices(foundAt, -1); gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_fontList), path, NULL, FALSE); gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_fontList), path, NULL, TRUE, 0.5 , 0.0); gtk_tree_path_free(path); } // this is pretty messy listStyle st = LIST_STYLE_NORMAL; const std::string sWeight = getVal("font-weight"); const std::string sStyle = getVal("font-style"); if (sStyle.empty() || sWeight.empty()) st = LIST_STYLE_NONE; else { bool isBold = !g_ascii_strcasecmp(sWeight.c_str(), "bold"); bool isItalic = !g_ascii_strcasecmp(sStyle.c_str(), "italic"); if (!isBold && !isItalic) { st = LIST_STYLE_NORMAL; } else if (!isItalic && isBold) { st = LIST_STYLE_BOLD; } else if (isItalic && !isBold) { st = LIST_STYLE_ITALIC; } else if (isItalic && isBold) { st = LIST_STYLE_BOLD_ITALIC; } else { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); } } // select and scroll to style name if (st != LIST_STYLE_NONE) { GtkTreePath* path = gtk_tree_path_new_from_indices(st, -1); gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_styleList), path, NULL, FALSE); gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_styleList), path, NULL, TRUE, 0.5 , 0.0); gtk_tree_path_free(path); } g_snprintf(sizeString, 60, "%s", std_size_string(UT_convertToPoints(getVal("font-size").c_str()))); foundAt = searchTreeView(GTK_TREE_VIEW(m_sizeList), XAP_EncodingManager::fontsizes_mapping.lookupBySource(sizeString)); // select and scroll to size name if (foundAt >= 0) { GtkTreePath* path = gtk_tree_path_new_from_indices(foundAt, -1); gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_sizeList), path, NULL, FALSE); gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_sizeList), path, NULL, TRUE, 0.5 , 0.0); gtk_tree_path_free(path); } // Set color in the color selector const std::string sColor = getVal("color"); if (!sColor.empty()) { UT_RGBColor c; UT_parseColor(sColor.c_str(), c); GdkRGBA *color = UT_UnixRGBColorToGdkRGBA(c); m_currentFGColor = *color; gdk_rgba_free(color); gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_colorSelector), &m_currentFGColor); } else { // if we have no color, use a placeholder of funky values // the user can't pick interactively. This catches ALL // the cases except where the user specifically enters -1 for // all Red, Green and Blue attributes manually. This user // should expect it not to touch the color. :) gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_colorSelector), &m_funkyColor); } // Set color in the color selector const std::string sBGCol = getVal("bgcolor"); if (!sBGCol.empty() && strcmp(sBGCol.c_str(),"transparent") != 0) { UT_RGBColor c; UT_parseColor(sBGCol.c_str(), c); GdkRGBA *color = UT_UnixRGBColorToGdkRGBA(c); m_currentBGColor = *color; gdk_rgba_free(color); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkTransparency), FALSE); gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_bgcolorSelector), &m_currentBGColor); } else gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkTransparency), TRUE); // fix for GTK's questionable gtk_toggle_set_active behaviour (emits when setting TRUE) m_bChangedStrikeOut = m_bStrikeout; m_bChangedUnderline = m_bUnderline; m_bChangedOverline = m_bOverline; m_bChangedHidden = m_bHidden; m_bChangedSubScript = m_bSubScript; m_bChangedSuperScript = m_bSuperScript; // set the strikeout, underline, overline, and hidden check buttons gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkStrikeOut), m_bStrikeout); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkUnderline), m_bUnderline); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkOverline), m_bOverline); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkHidden), m_bHidden); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkSubScript), m_bSubScript); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_checkSuperScript), m_bSuperScript); m_doneFirstFont = true; // attach a new graphics context gtk_widget_show ( cf ) ; GR_UnixCairoAllocInfo ai(m_preview); m_gc = (GR_CairoGraphics*) XAP_App::getApp()->newGraphics(ai); GtkAllocation alloc; gtk_widget_get_allocation(m_preview, &alloc); _createFontPreviewFromGC(m_gc,alloc.width,alloc.height); // // This enables callbacks on the preview area with a widget pointer to // access this dialog. // g_object_set_data(G_OBJECT(m_preview), "user-data", this); // unfreeze updates of the preview m_blockUpdate = false; // manually trigger an update updatePreview(); switch ( abiRunModalDialog ( GTK_DIALOG(cf), pFrame, this, BUTTON_CANCEL, true ) ) { case BUTTON_OK: { m_answer = a_OK; break ; } default: { m_answer = a_CANCEL; break; } } // these dialogs are cached around through the dialog framework, // and this variable needs to get set back m_doneFirstFont = false; UT_DEBUGMSG(("FontChooserEnd: Family[%s%s] Size[%s%s] Weight[%s%s] Style[%s%s] Color[%s%s] Underline[%d%s] StrikeOut[%d%s] SubScript[%d%s] SuperScript[%d%s]\n", getVal("font-family").c_str(), ((m_bChangedFontFamily) ? "(chg)" : ""), getVal("font-size").c_str(), ((m_bChangedFontSize) ? "(chg)" : ""), getVal("font-weight").c_str(), ((m_bChangedFontWeight) ? "(chg)" : ""), getVal("font-style").c_str(), ((m_bChangedFontStyle) ? "(chg)" : ""), getVal("color").c_str(), ((m_bChangedColor) ? "(chg)" : ""), m_bUnderline, ((m_bChangedUnderline) ? "(chg)" : ""), m_bStrikeout, ((m_bChangedStrikeOut) ? "(chg)" : ""), m_bSubScript, ((m_bChangedSubScript) ? "(chg)" : ""), m_bSuperScript, ((m_bChangedSuperScript) ? "(chg)" : "") )); // answer should be set by the appropriate callback // the caller can get the answer from getAnswer(). m_pFrame = NULL; }
int main(int argc, char *argv[]) { int status = 0; int print = 0; char *mapName = NULL; char *saveName = NULL; char *dirName = NULL; char opt; int count; setlocale(LC_ALL, getenv(ENV_LANG)); textdomain("keymap"); // Graphics enabled? graphics = graphicsAreEnabled(); // Check options while (strchr("psT:?", (opt = getopt(argc, argv, "ps:T")))) { switch (opt) { case 'p': // Just print out the map, if we're in text mode print = 1; break; case 's': // Save the map to a file if (!optarg) { fprintf(stderr, "%s", _("Missing filename argument for -s " "option\n")); usage(argv[0]); return (status = ERR_NULLPARAMETER); } saveName = optarg; break; case 'T': // Force text mode graphics = 0; break; case ':': fprintf(stderr, _("Missing parameter for %s option\n"), argv[optind - 1]); usage(argv[0]); return (status = ERR_NULLPARAMETER); default: fprintf(stderr, _("Unknown option '%c'\n"), optopt); usage(argv[0]); return (status = ERR_INVALID); } } cwd = malloc(MAX_PATH_LENGTH); selectedMap = malloc(sizeof(keyMap)); if (!cwd || !selectedMap) { status = ERR_MEMORY; goto out; } strncpy(cwd, PATH_SYSTEM_KEYMAPS, MAX_PATH_LENGTH); // Get the current map status = keyboardGetMap(selectedMap); if (status < 0) goto out; strncpy(currentName, selectedMap->name, KEYMAP_NAMELEN); mapName = selectedMap->name; // Did the user supply either a map name or a key map file name? if ((argc > 1) && (optind < argc)) { // Is it a file name? status = fileFind(argv[optind], NULL); if (status >= 0) { status = readMap(argv[optind], selectedMap); if (status < 0) goto out; mapName = selectedMap->name; dirName = dirname(argv[optind]); if (dirName) { strncpy(cwd, dirName, MAX_PATH_LENGTH); free(dirName); } } else { // Assume we've been given a map name. mapName = argv[optind]; } if (!graphics && !saveName && !print) { // The user wants to set the current keyboard map to the supplied // name. status = setMap(mapName); goto out; } // Load the supplied map name status = loadMap(mapName); if (status < 0) goto out; } keyArray = malloc(KEYBOARD_SCAN_CODES * sizeof(scanKey)); if (!keyArray) { status = ERR_MEMORY; goto out; } // Make the initial key array based on the current map. makeKeyArray(selectedMap); if (saveName) { // The user wants to save the current keyboard map to the supplied // file name. status = saveMap(saveName); goto out; } status = getMapNameParams(); if (status < 0) goto out; if (graphics) { // Make our window constructWindow(); // Run the GUI windowGuiRun(); // ...and when we come back... windowDestroy(window); } else { if (print) { // Print out the whole keyboard for the selected map printKeyboard(); } else { // Just print the list of map names printf("\n"); for (count = 0; count < numMapNames; count ++) printf("%s%s\n", mapListParams[count].text, (!strcmp(mapListParams[count].text, selectedMap->name)? _(" (current)") : "")); } } status = 0; out: if (cwd) free(cwd); if (selectedMap) free(selectedMap); if (mapListParams) free(mapListParams); if (keyArray) free(keyArray); return (status); }