/*! * Fill the GUI tree with the styles as defined in the XP tree. */ void AP_UnixDialog_Stylist::_fillTree(void) { Stylist_tree * pStyleTree = getStyleTree(); if(pStyleTree == NULL) { updateDialog(); pStyleTree = getStyleTree(); } if(pStyleTree->getNumRows() == 0) { updateDialog(); pStyleTree = getStyleTree(); } UT_DEBUGMSG(("Number of rows of styles in document %d \n",pStyleTree->getNumRows())); if(m_wRenderer) { // g_object_unref (G_OBJECT (m_wRenderer)); gtk_widget_destroy (m_wStyleList); } GtkTreeIter iter; GtkTreeIter child_iter; GtkTreeSelection *sel; UT_sint32 row,col, page; m_wModel = gtk_tree_store_new (3, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT); page = 0; UT_UTF8String sTmp(""); for(row= 0; row < pStyleTree->getNumRows();row++) { gtk_tree_store_append (m_wModel, &iter, NULL); if(!pStyleTree->getNameOfRow(sTmp,row)) { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); break; } if(pStyleTree->getNumCols(row) > 0) { xxx_UT_DEBUGMSG(("Adding Heading %s at row %d \n",sTmp.utf8_str(),row)); gtk_tree_store_set (m_wModel, &iter, 0, sTmp.utf8_str(), 1, row,2,0, -1); for(col =0 ; col < pStyleTree->getNumCols(row); col++) { gtk_tree_store_append (m_wModel, &child_iter, &iter); if(!pStyleTree->getStyleAtRowCol(sTmp,row,col)) { UT_ASSERT(UT_SHOULD_NOT_HAPPEN); break; } gtk_tree_store_set (m_wModel, &child_iter, 0, sTmp.utf8_str(), 1, row,2,col+1, -1); xxx_UT_DEBUGMSG(("Adding style %s at row %d col %d \n",sTmp.utf8_str(),row,col+1)); page++; } } else { xxx_UT_DEBUGMSG(("Adding style %s at row %d \n",sTmp.utf8_str(),row)); gtk_tree_store_set (m_wModel, &iter, 0, sTmp.utf8_str(), 1,row,2,0,-1); page++; } } // create a new treeview m_wStyleList = gtk_tree_view_new_with_model (GTK_TREE_MODEL (m_wModel)); g_object_unref (G_OBJECT (m_wModel)); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (m_wStyleList), true); // get the current selection sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (m_wStyleList)); gtk_tree_selection_set_mode (sel, GTK_SELECTION_BROWSE); gtk_tree_selection_set_select_function (sel, tree_select_filter, NULL, NULL); const XAP_StringSet * pSS = m_pApp->getStringSet (); m_wRenderer = gtk_cell_renderer_text_new (); UT_UTF8String s; pSS->getValueUTF8(AP_STRING_ID_DLG_Stylist_Styles,s); gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (m_wStyleList), -1, s.utf8_str(), m_wRenderer, "text", 0, NULL); gtk_tree_view_collapse_all (GTK_TREE_VIEW (m_wStyleList)); gtk_container_add (GTK_CONTAINER (m_wStyleListContainer), m_wStyleList); g_signal_connect_after(G_OBJECT(m_wStyleList), "cursor-changed", G_CALLBACK(s_types_clicked), static_cast<gpointer>(this)); g_signal_connect_after(G_OBJECT(m_wStyleList), "row-activated", G_CALLBACK(s_types_dblclicked), static_cast<gpointer>(this)); gtk_widget_show_all(m_wStyleList); setStyleTreeChanged(false); }
/*! * Fill the GUI tree with the styles as defined in the XP tree. */ void AP_Win32Dialog_Stylist::_fillTree(void) { Stylist_tree * pStyleTree = getStyleTree(); if(pStyleTree == NULL) { updateDialog(); pStyleTree = getStyleTree(); } if(pStyleTree->getNumRows() == 0) { updateDialog(); pStyleTree = getStyleTree(); } UT_DEBUGMSG(("Number of rows of styles in document %d \n",pStyleTree->getNumRows())); HWND hTree = GetDlgItem(m_hWnd, AP_RID_DIALOG_STYLIST_TREE_STYLIST); // Purge any existing TreeView items TreeView_DeleteAllItems(hTree); TV_ITEM tvi; TV_INSERTSTRUCT tvins; HTREEITEM hParentItem; // Parent handle to link Styles to their Heading tvi.mask = TVIF_TEXT | TVIF_PARAM | TVIF_CHILDREN; tvi.stateMask =0; UT_sint32 row, col; UT_UTF8String sTmp(""), str_loc; UT_String str; //int iter = 0; // Unique key for each item in the treeview for(row= 0; row < pStyleTree->getNumRows(); row++) { if(!pStyleTree->getNameOfRow(sTmp,row)) { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); break; } pt_PieceTable::s_getLocalisedStyleName (sTmp.utf8_str(), str_loc); str = AP_Win32App::s_fromUTF8ToWinLocale (str_loc.utf8_str()); xxx_UT_DEBUGMSG(("Adding Heading %s at row %d \n",sTmp.utf8_str(),row)); // Insert the item into the treeview tvi.pszText = (LPTSTR)str.c_str(); tvi.cchTextMax = str.length() + 1; tvi.lParam = row; if (pStyleTree->getNumCols(row) > 0) tvi.cChildren = 1; else tvi.cChildren = 0; tvins.item = tvi; tvins.hParent = TVI_ROOT; tvins.hInsertAfter = TVI_LAST; hParentItem = TreeView_InsertItem(hTree, &tvins); // Add any children (columns) this row contains to be added if (pStyleTree->getNumCols(row) > 0) { for(col = 0; col < pStyleTree->getNumCols(row); col++) { if(!pStyleTree->getStyleAtRowCol(sTmp,row,col)) { UT_ASSERT_HARMLESS(UT_SHOULD_NOT_HAPPEN); break; } xxx_UT_DEBUGMSG(("Adding style %s at row %d col %d \n",sTmp.utf8_str(),row,col+1)); pt_PieceTable::s_getLocalisedStyleName (sTmp.utf8_str(), str_loc); str = AP_Win32App::s_fromUTF8ToWinLocale (str_loc.utf8_str()); // Insert the item into the treeview tvi.pszText = (LPTSTR)str.c_str(); tvi.cchTextMax = str.length() + 1; tvi.cChildren = 0; tvi.lParam = col; tvins.item = tvi; tvins.hParent = hParentItem; tvins.hInsertAfter = TVI_LAST; TreeView_InsertItem(hTree, &tvins); } } } setStyleTreeChanged(false); }