BOOL AP_Win32Dialog_Styles::_onInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam) { XAP_Win32App * app = static_cast<XAP_Win32App *> (m_pApp); UT_return_val_if_fail (app,0); const XAP_StringSet * pSS = m_pApp->getStringSet(); WCHAR szTemp[20]; GetWindowTextW(hWnd, szTemp, 20 ); m_hDlg=hWnd; // Regular dialog box if( lstrcmpW(szTemp, L"Styles") == 0 ) { setDialogTitle (pSS->getValue(AP_STRING_ID_DLG_Styles_StylesTitle)); // localize controls _DS(STYLES_TOP_TEXT_LIST, DLG_Styles_List); _DS(STYLES_TOP_TEXT_PARAGRAPH_PREVIEW, DLG_Styles_ParaPrev); _DS(STYLES_TOP_TEXT_CHARACTER_PREVIEW, DLG_Styles_CharPrev); _DS(STYLES_TOP_TEXT_DESCRIPTION, DLG_Styles_Description); _DS(STYLES_TOP_BUTTON_DELETE, DLG_Styles_Delete); _DS(STYLES_TOP_BUTTON_MODIFY, DLG_Styles_Modify); _DS(STYLES_TOP_BUTTON_NEW, DLG_Styles_New); _DS(STYLES_TOP_TEXT_AVAILABLE, DLG_Styles_Available); // "Available Styles" GROUPBOX _DSX(STYLES_TOP_BUTTON_APPLY, DLG_Apply); _DSX(STYLES_TOP_BUTTON_CLOSE, DLG_Close); // Set the list combo. _win32Dialog.addItemToCombo(AP_RID_DIALOG_STYLES_TOP_COMBO_LIST, pSS->getValue (AP_STRING_ID_DLG_Styles_LBL_InUse)); _win32Dialog.addItemToCombo(AP_RID_DIALOG_STYLES_TOP_COMBO_LIST, pSS->getValue(AP_STRING_ID_DLG_Styles_LBL_All)); _win32Dialog.addItemToCombo(AP_RID_DIALOG_STYLES_TOP_COMBO_LIST, pSS->getValue(AP_STRING_ID_DLG_Styles_LBL_UserDefined)); _win32Dialog.selectComboItem(AP_RID_DIALOG_STYLES_TOP_COMBO_LIST, (int)m_whichType); // Create a preview windows. HWND hwndChild = GetDlgItem(hWnd, AP_RID_DIALOG_STYLES_TOP_TEXT_PARAGRAPH_PREVIEW); m_pParaPreviewWidget = new XAP_Win32PreviewWidget(static_cast<XAP_Win32App *>(m_pApp), hwndChild, 0); UT_uint32 w,h; m_pParaPreviewWidget->getWindowSize(&w,&h); _createParaPreviewFromGC(m_pParaPreviewWidget->getGraphics(), w, h); m_pParaPreviewWidget->setPreview(m_pParaPreview); hwndChild = GetDlgItem(hWnd, AP_RID_DIALOG_STYLES_TOP_TEXT_CHARACTER_PREVIEW); m_pCharPreviewWidget = new XAP_Win32PreviewWidget(static_cast<XAP_Win32App *>(m_pApp), hwndChild, 0); m_pCharPreviewWidget->getWindowSize(&w,&h); _createCharPreviewFromGC(m_pCharPreviewWidget->getGraphics(), w, h); m_pCharPreviewWidget->setPreview(m_pCharPreview); _populateWindowData(); } // This is either the new or Modify sub dialog of styles else { _win32DialogNewModify.setHandle(hWnd); // Localize the controls Labels etc... setWindowText(hWnd, pSS->getValue( (m_bisNewStyle) ? AP_STRING_ID_DLG_Styles_NewTitle : AP_STRING_ID_DLG_Styles_ModifyTitle )); #define _DS(c,s) setDlgItemText(hWnd, AP_RID_DIALOG_##c,pSS->getValue(AP_STRING_ID_##s)) #define _DSX(c,s) setDlgItemText(hWnd, AP_RID_DIALOG_##c,pSS->getValue(XAP_STRING_ID_##s)) _DS(STYLES_NEWMODIFY_LBL_NAME, DLG_Styles_ModifyName); _DS(STYLES_NEWMODIFY_LBL_BASEDON, DLG_Styles_ModifyBasedOn); _DS(STYLES_NEWMODIFY_LBL_TYPE, DLG_Styles_ModifyType); _DS(STYLES_NEWMODIFY_LBL_FOLLOWPARA, DLG_Styles_ModifyFollowing); _DS(STYLES_NEWMODIFY_LBL_REMOVE, DLG_Styles_RemoveLab); _DS(STYLES_NEWMODIFY_GBX_PREVIEW, DLG_Styles_ModifyPreview); _DS(STYLES_NEWMODIFY_GBX_DESC, DLG_Styles_ModifyDescription); _DS(STYLES_NEWMODIFY_BTN_REMOVE, DLG_Styles_RemoveButton); _DS(STYLES_NEWMODIFY_BTN_SHORTCUT, DLG_Styles_ModifyShortCut); _DSX(STYLES_NEWMODIFY_BTN_OK, DLG_OK); _DSX(STYLES_NEWMODIFY_BTN_CANCEL, DLG_Cancel); #undef _DSX #undef _DS // Changes basic controls based upon either New or Modify Dialog _win32DialogNewModify.showControl( AP_RID_DIALOG_STYLES_NEWMODIFY_EBX_TYPE , (m_bisNewStyle) ? SW_HIDE : SW_SHOW ); _win32DialogNewModify.showControl( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_TYPE , (m_bisNewStyle) ? SW_SHOW : SW_HIDE ); // Initialize the controls with appropriate data size_t nStyles = getDoc()->getStyleCount(); const char * name = NULL; const char * pLocalised = NULL; const PD_Style * pcStyle = NULL; int nIndex; UT_Win32LocaleString str; UT_UTF8String utf8; UT_GenericVector<PD_Style*> * pStyles = NULL; getDoc()->enumStyles(pStyles); UT_return_val_if_fail( pStyles, FALSE ); for (UT_uint32 i = 0; i < nStyles; i++) { pcStyle = pStyles->getNthItem(i); UT_return_val_if_fail( pcStyle, FALSE ); name = pcStyle->getName(); pt_PieceTable::s_getLocalisedStyleName(name, utf8); pLocalised = utf8.utf8_str(); nIndex = _win32DialogNewModify.addItemToCombo(AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON, pLocalised); _win32DialogNewModify.setComboDataItem(AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON, nIndex, i); nIndex = _win32DialogNewModify.addItemToCombo(AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA, pLocalised); _win32DialogNewModify.setComboDataItem(AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA, nIndex, i); } delete pStyles; // Strings (not styles names) const char* pDefCurrent = pSS->getValue(AP_STRING_ID_DLG_Styles_DefCurrent); const char* pDefNone = pSS->getValue(AP_STRING_ID_DLG_Styles_DefNone); nIndex = _win32DialogNewModify.addItemToCombo( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA, pDefCurrent ); _win32DialogNewModify.setComboDataItem(AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA, nIndex, (DWORD)-1); nIndex = _win32DialogNewModify.addItemToCombo( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON, pDefNone); _win32DialogNewModify.setComboDataItem(AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON, nIndex, (DWORD)-1); if( m_bisNewStyle ) { const char* p = pSS->getValue(AP_STRING_ID_DLG_Styles_ModifyParagraph); _win32DialogNewModify.addItemToCombo( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_TYPE, p ); p = pSS->getValue(AP_STRING_ID_DLG_Styles_ModifyCharacter); _win32DialogNewModify.addItemToCombo( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_TYPE, p); // Set the Default syltes: none, default current UT_sint32 result; str.fromUTF8(pSS->getValue(AP_STRING_ID_DLG_Styles_DefNone)); result = SendDlgItemMessageW(hWnd, AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON, CB_FINDSTRING, -1, (LPARAM) str.c_str()); _win32DialogNewModify.selectComboItem( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON, result ); str.fromUTF8(pSS->getValue(AP_STRING_ID_DLG_Styles_DefCurrent)); result = SendDlgItemMessageW(hWnd, AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA, CB_FINDSTRING, -1, (LPARAM) str.c_str()); _win32DialogNewModify.selectComboItem( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA, result ); str.fromUTF8(pSS->getValue(AP_STRING_ID_DLG_Styles_ModifyParagraph)); result = SendDlgItemMessageW(hWnd, AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_TYPE, CB_FINDSTRING, -1, (LPARAM) str.c_str()); _win32DialogNewModify.selectComboItem( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_TYPE, result ); eventBasedOn(); eventFollowedBy(); eventStyleType(); fillVecFromCurrentPoint(); } else { const char * szCurrentStyle = NULL; const char * szBasedOn = NULL; const char * szFollowedBy = NULL; const char * pLocalised = NULL; PD_Style * pStyle = NULL; PD_Style * pBasedOnStyle = NULL; PD_Style * pFollowedByStyle = NULL; szCurrentStyle = m_selectedStyle.c_str(); pt_PieceTable::s_getLocalisedStyleName(szCurrentStyle, utf8); pLocalised = utf8.utf8_str(); _win32DialogNewModify.setControlText( AP_RID_DIALOG_STYLES_NEWMODIFY_EBX_NAME, pLocalised); if(szCurrentStyle) getDoc()->getStyle(szCurrentStyle,&pStyle); if(!pStyle) { XAP_Frame * pFrame = getFrame(); pFrame->showMessageBox( pSS->getValue(AP_STRING_ID_DLG_Styles_ErrNoStyle), XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK); m_answer = AP_Dialog_Styles::a_CANCEL; return false; } // // Valid style get the Based On and followed by values // pBasedOnStyle = pStyle->getBasedOn(); pFollowedByStyle = pStyle->getFollowedBy(); size_t nStyles = getDoc()->getStyleCount(); const char * name = NULL; const PD_Style * pcStyle = NULL; UT_GenericVector<PD_Style*> * pStyles = NULL; getDoc()->enumStyles(pStyles); UT_return_val_if_fail( pStyles, FALSE ); for (UT_uint32 i = 0; i < nStyles; i++) { pcStyle = pStyles->getNthItem(i); UT_return_val_if_fail( pcStyle, FALSE ); name = pcStyle->getName(); if(pBasedOnStyle && pcStyle == pBasedOnStyle) { szBasedOn = name; } if(pFollowedByStyle && pcStyle == pFollowedByStyle) { szFollowedBy = name; } } delete pStyles; if(pBasedOnStyle != NULL) { pt_PieceTable::s_getLocalisedStyleName(szBasedOn, utf8); pLocalised = utf8.utf8_str(); str = AP_Win32App::s_fromUTF8ToWinLocale(pLocalised); UT_uint32 result = SendDlgItemMessageW(hWnd, AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON, CB_FINDSTRING, -1, (LPARAM)str.c_str()); _win32DialogNewModify.selectComboItem( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON, result ); } else { // Not a style name str.fromUTF8(pSS->getValue(AP_STRING_ID_DLG_Styles_DefNone)); UT_uint32 result = SendDlgItemMessageW(hWnd, AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON, CB_FINDSTRING, -1, (LPARAM) str.c_str()); _win32DialogNewModify.selectComboItem( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON, result ); } if(pFollowedByStyle != NULL) { pt_PieceTable::s_getLocalisedStyleName(szFollowedBy, utf8); pLocalised = utf8.utf8_str(); str = AP_Win32App::s_fromUTF8ToWinLocale(pLocalised); UT_uint32 result = SendDlgItemMessageW(hWnd, AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA, CB_FINDSTRING, -1, (LPARAM)str.c_str()); _win32DialogNewModify.selectComboItem( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA, result ); } else { pt_PieceTable::s_getLocalisedStyleName(pSS->getValue(AP_STRING_ID_DLG_Styles_DefCurrent), utf8); pLocalised = utf8.utf8_str(); str = AP_Win32App::s_fromUTF8ToWinLocale(pLocalised); UT_uint32 result = SendDlgItemMessageW(hWnd, AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA, CB_FINDSTRING, -1, (LPARAM) str.c_str()); _win32DialogNewModify.selectComboItem( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA, result ); } if(strstr(getAttsVal("type"),"P") != 0) { _win32DialogNewModify.setControlText( AP_RID_DIALOG_STYLES_NEWMODIFY_EBX_TYPE, pSS->getValue(AP_STRING_ID_DLG_Styles_ModifyParagraph) ); } else { _win32DialogNewModify.setControlText( AP_RID_DIALOG_STYLES_NEWMODIFY_EBX_TYPE, pSS->getValue(AP_STRING_ID_DLG_Styles_ModifyCharacter) ); } // Disable for editing top controls in Modify Dialog _win32DialogNewModify.enableControl( AP_RID_DIALOG_STYLES_NEWMODIFY_EBX_NAME, false ); _win32DialogNewModify.enableControl( AP_RID_DIALOG_STYLES_NEWMODIFY_EBX_TYPE, false ); fillVecWithProps(szCurrentStyle,true); } // Generate the Preview class HWND hwndChild = GetDlgItem( hWnd, AP_RID_DIALOG_STYLES_NEWMODIFY_CTL_PREVIEW ); m_pAbiPreviewWidget = new XAP_Win32PreviewWidget(static_cast<XAP_Win32App *>(m_pApp), hwndChild, 0); UT_uint32 w,h; m_pAbiPreviewWidget->getWindowSize(&w,&h); _createAbiPreviewFromGC(m_pAbiPreviewWidget->getGraphics(), w, h); _populateAbiPreview(m_bisNewStyle); m_pAbiPreviewWidget->setPreview(m_pAbiPreview); rebuildDeleteProps(); _populatePreviews(true); } XAP_Win32DialogHelper::s_centerDialog(hWnd); return 1; // 1 == we did not call SetFocus() }
bool AP_UnixDialog_Styles::_populateModify(void) { const XAP_StringSet * pSS = m_pApp->getStringSet(); // // Don't do any callback while setting up stuff here. // setModifySignalBlocked(true); setModifyDescription( m_curStyleDesc.c_str()); // // Get Style name and put in in the text entry // const char * szCurrentStyle = NULL; UT_UTF8String s; if(!isNew()) { szCurrentStyle= getCurrentStyle(); if(!szCurrentStyle) { // TODO: change me to use a real messagebox pSS->getValueUTF8(AP_STRING_ID_DLG_Styles_ErrNoStyle,s); messageBoxOK( s.utf8_str()); m_answer = AP_Dialog_Styles::a_CANCEL; return false; } gtk_entry_set_text (GTK_ENTRY(m_wStyleNameEntry), getCurrentStyle()); gtk_editable_set_editable(GTK_EDITABLE(m_wStyleNameEntry),FALSE ); } else { gtk_editable_set_editable(GTK_EDITABLE(m_wStyleNameEntry),TRUE ); } // // Next interogate the current style and find the based on and followed by // Styles // const char * szBasedOn = NULL; const char * szFollowedBy = NULL; PD_Style * pBasedOnStyle = NULL; PD_Style * pFollowedByStyle = NULL; if(!isNew()) { PD_Style * pStyle = NULL; if(szCurrentStyle) getDoc()->getStyle(szCurrentStyle,&pStyle); if(!pStyle) { // TODO: do a real error dialog pSS->getValueUTF8(AP_STRING_ID_DLG_Styles_ErrStyleNot,s); messageBoxOK( s.utf8_str()); m_answer = AP_Dialog_Styles::a_CANCEL; return false; } // // Valid style get the Based On and followed by values // pBasedOnStyle = pStyle->getBasedOn(); pFollowedByStyle = pStyle->getFollowedBy(); } // // Next make a glists of all styles and attach them to the BasedOn and FollowedBy // UT_GenericVector<PD_Style*> * pStyles = NULL; getDoc()->enumStyles(pStyles); UT_sint32 nStyles = pStyles->getItemCount(); for (UT_sint32 i = 0; i < nStyles; i++) { const PD_Style * pcStyle = pStyles->getNthItem(i); const char * name = pcStyle->getName(); if(pBasedOnStyle && pcStyle == pBasedOnStyle) { szBasedOn = name; } if(pFollowedByStyle && pcStyle == pFollowedByStyle) szFollowedBy = name; if(szCurrentStyle && strcmp(name,szCurrentStyle) != 0) m_gbasedOnStyles.push_back(name); else if(szCurrentStyle == NULL) m_gbasedOnStyles.push_back(name); m_gfollowedByStyles.push_back(name); } DELETEP(pStyles); m_gfollowedByStyles.sort(); m_gfollowedByStyles.push_back(pSS->getValue(AP_STRING_ID_DLG_Styles_DefCurrent)); m_gbasedOnStyles.sort(); m_gbasedOnStyles.push_back(pSS->getValue(AP_STRING_ID_DLG_Styles_DefNone)); m_gStyleType.push_back(pSS->getValue(AP_STRING_ID_DLG_Styles_ModifyParagraph)); m_gStyleType.push_back(pSS->getValue(AP_STRING_ID_DLG_Styles_ModifyCharacter)); // // Set the popdown list // setComboContent(GTK_COMBO_BOX_TEXT(m_wBasedOnCombo),m_gbasedOnStyles); setComboContent(GTK_COMBO_BOX_TEXT(m_wFollowingCombo),m_gfollowedByStyles); if(isNew()) { setComboContent(GTK_COMBO_BOX_TEXT(m_wStyleTypeCombo),m_gStyleType); } // // OK here we set intial values for the basedOn and followedBy // if(!isNew()) { if(pBasedOnStyle != NULL) gtk_entry_set_text (GTK_ENTRY(m_wBasedOnEntry),szBasedOn); else { pSS->getValueUTF8(AP_STRING_ID_DLG_Styles_DefNone,s); gtk_entry_set_text (GTK_ENTRY(m_wBasedOnEntry), s.utf8_str()); } if(pFollowedByStyle != NULL) gtk_entry_set_text (GTK_ENTRY(m_wFollowingEntry),szFollowedBy); else { pSS->getValueUTF8(AP_STRING_ID_DLG_Styles_DefCurrent,s); gtk_entry_set_text (GTK_ENTRY(m_wFollowingEntry), s.utf8_str()); } const char * pszType = getAttsVal(PT_TYPE_ATTRIBUTE_NAME); if(pszType && strstr(pszType,"P") != 0) { pSS->getValueUTF8(AP_STRING_ID_DLG_Styles_ModifyParagraph,s); gtk_entry_set_text (GTK_ENTRY(m_wStyleTypeEntry),s.utf8_str()); } else { pSS->getValueUTF8(AP_STRING_ID_DLG_Styles_ModifyCharacter,s); gtk_entry_set_text (GTK_ENTRY(m_wStyleTypeEntry),s.utf8_str()); } } else { // // Hardwire defaults for "new" // pSS->getValueUTF8(AP_STRING_ID_DLG_Styles_DefNone,s); gtk_entry_set_text (GTK_ENTRY(m_wBasedOnEntry), s.utf8_str()); pSS->getValueUTF8(AP_STRING_ID_DLG_Styles_DefCurrent,s); gtk_entry_set_text (GTK_ENTRY(m_wFollowingEntry), s.utf8_str()); pSS->getValueUTF8(AP_STRING_ID_DLG_Styles_ModifyParagraph,s); gtk_entry_set_text (GTK_ENTRY(m_wStyleTypeEntry),s.utf8_str()); } gtk_editable_set_editable(GTK_EDITABLE(m_wFollowingEntry),FALSE ); gtk_editable_set_editable(GTK_EDITABLE(m_wBasedOnEntry),FALSE ); gtk_editable_set_editable(GTK_EDITABLE(m_wStyleTypeEntry),FALSE ); // // Set these in our attributes vector // event_basedOn(); event_followedBy(); event_styleType(); if(isNew()) { fillVecFromCurrentPoint(); } else { fillVecWithProps(szCurrentStyle,true); } // // Allow callback's now. // setModifySignalBlocked(false); // // Now set the list of properties which can be deleted. // rebuildDeleteProps(); gtk_entry_set_text(GTK_ENTRY(m_wDeletePropEntry),""); return true; }