void AP_UnixDialog_Stylist::setStyleInGUI(void) { UT_sint32 row,col; UT_UTF8String sCurStyle = *getCurStyle(); if((getStyleTree() == NULL) || (sCurStyle.size() == 0)) updateDialog(); if(m_wStyleList == NULL) return; if(isStyleTreeChanged()) _fillTree(); getStyleTree()->findStyle(sCurStyle,row,col); UT_DEBUGMSG(("After findStyle row %d col %d col \n",row,col)); UT_UTF8String sPathFull = UT_UTF8String_sprintf("%d:%d",row,col); UT_UTF8String sPathRow = UT_UTF8String_sprintf("%d",row); UT_DEBUGMSG(("Full Path string is %s \n",sPathFull.utf8_str())); GtkTreePath * gPathRow = gtk_tree_path_new_from_string (sPathRow.utf8_str()); GtkTreePath * gPathFull = gtk_tree_path_new_from_string (sPathFull.utf8_str()); gtk_tree_view_expand_row( GTK_TREE_VIEW(m_wStyleList),gPathRow,TRUE); gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(m_wStyleList),gPathFull,NULL,TRUE,0.5,0.5); gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_wStyleList),gPathFull,NULL,TRUE); setStyleChanged(false); gtk_tree_path_free(gPathRow); gtk_tree_path_free(gPathFull); }
void AP_Win32Dialog_Stylist::setStyleInGUI(void) { UT_sint32 row,col; UT_UTF8String sCurStyle = *getCurStyle(); if((getStyleTree() == NULL) || (sCurStyle.size() == 0)) updateDialog(); if(isStyleTreeChanged()) _fillTree(); getStyleTree()->findStyle(sCurStyle,row,col); UT_DEBUGMSG(("After findStyle row %d col %d col \n",row,col)); UT_UTF8String sPathFull = UT_UTF8String_sprintf("%d:%d",row,col); UT_UTF8String sPathRow = UT_UTF8String_sprintf("%d",row); UT_DEBUGMSG(("Full Path string is %s \n",sPathFull.utf8_str())); HWND hTree = GetDlgItem(m_hWnd, AP_RID_DIALOG_STYLIST_TREE_STYLIST); HTREEITEM hitem = NULL; hitem = TreeView_GetRoot(hTree); UT_sint32 i; // Go through each row until we've found ours for (i = 0; i < row; i++) hitem = TreeView_GetNextItem(hTree, hitem, TVGN_NEXT); hitem = TreeView_GetNextItem(hTree, hitem, TVGN_CHILD); for (i = 0; i < col; i++) hitem = TreeView_GetNextItem(hTree, hitem, TVGN_NEXT); TreeView_SelectItem(hTree, hitem); setStyleChanged(false); }
/*! * Set the style in the XP layer from the selection in the GUI. */ void AP_UnixDialog_Stylist::styleClicked(UT_sint32 row, UT_sint32 col) { UT_UTF8String sStyle; UT_DEBUGMSG(("row %d col %d clicked \n",row,col)); if((col == 0) && (getStyleTree()->getNumCols(row) == 1)) return; else if(col == 0) getStyleTree()->getStyleAtRowCol(sStyle,row,col); else getStyleTree()->getStyleAtRowCol(sStyle,row,col-1); UT_DEBUGMSG(("StyleClicked row %d col %d style %s \n",row,col,sStyle.utf8_str())); setCurStyle(sStyle); }
BOOL AP_Win32Dialog_Stylist::_styleClicked(void) { UT_sint32 row, col; TVITEM tvi; HWND hTree = GetDlgItem(m_hWnd, AP_RID_DIALOG_STYLIST_TREE_STYLIST); // Selected item tvi.hItem = TreeView_GetSelection(hTree); if (!tvi.hItem) return 0; // Associated data tvi.mask = TVIF_HANDLE | TVIF_CHILDREN; TreeView_GetItem(hTree, &tvi); // Retrieve the row/column information from the treeview // This maps back to the pStyleList's row&column identifiers if (TreeView_GetParent(hTree, tvi.hItem) == NULL) { if (tvi.cChildren == 1) return 0; // we've clicked on a style category, not a style row = tvi.lParam; col = 0; } else { col = tvi.lParam; // Get parent node for row information tvi.mask = TVIF_HANDLE; tvi.hItem = TreeView_GetParent(hTree, tvi.hItem); TreeView_GetItem(hTree, &tvi); row = tvi.lParam; } UT_UTF8String sStyle; getStyleTree()->getStyleAtRowCol(sStyle,row,col); UT_DEBUGMSG(("StyleClicked row %d col %d style %s \n",row,col,sStyle.utf8_str())); setCurStyle(sStyle); return 1; }
/*! * 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); }