int XAP_Win32DialogBase::addItemToCombo(UT_sint32 controlId, LPCSTR p_str) { UT_return_val_if_fail(IsWindow(m_hDlg), CB_ERR); UT_Win32LocaleString str; str.fromUTF8 (p_str); return SendDlgItemMessageW(m_hDlg, controlId, CB_ADDSTRING, 0, (LPARAM)str.c_str()); }
/* From UCS4 To WinLocale */ UT_Win32LocaleString AP_Win32App::s_fromUCS4ToWinLocale(const UT_UCS4Char * szIn) { UT_Win32LocaleString sRslt; sRslt.fromUCS4(szIn); //UT_ASSERT(UT_SHOULD_NOT_HAPPEN); return sRslt; }
void XAP_Win32DialogBase::setDialogTitle(const char* uft8_str) { UT_return_if_fail(IsWindow(m_hDlg)); UT_Win32LocaleString str; str.fromUTF8 (uft8_str); SetWindowTextW (m_hDlg, str.c_str()); }
void AP_Win32Dialog_Field::SetFieldsList(void) { fp_FieldTypesEnum FType = fp_FieldTypes[m_iTypeIndex].m_Type; SendMessageW(m_hwndFormats, LB_RESETCONTENT, 0, 0); int i; for (i = 0;fp_FieldFmts[i].m_Tag != NULL;i++) { if( fp_FieldFmts[i].m_Type == FType ) break; } UT_Win32LocaleString str; for (;fp_FieldFmts[i].m_Tag != NULL && fp_FieldFmts[i].m_Type == FType;i++) { if((fp_FieldFmts[i].m_Num != FPFIELD_endnote_anch) && (fp_FieldFmts[i].m_Num != FPFIELD_endnote_ref) && (fp_FieldFmts[i].m_Num != FPFIELD_footnote_anch) && (fp_FieldFmts[i].m_Num != FPFIELD_footnote_ref)) { str.fromUTF8(fp_FieldFmts[i].m_Desc); UT_sint32 index = SendMessageW(m_hwndFormats, LB_ADDSTRING, 0, (LPARAM)str.c_str()); if (index != LB_ERR && index != LB_ERRSPACE) { SendMessageW(m_hwndFormats, LB_SETITEMDATA, (WPARAM)index, (LPARAM)i); } } } SendMessageW(m_hwndFormats, LB_SETCURSEL, 0, 0); _FormatListBoxChange(); }
bool XAP_Win32DialogBase::setDlgItemText(HWND hWnd, int nIDDlgItem, const char* uft8_str) { UT_return_val_if_fail(IsWindow(hWnd), false); UT_Win32LocaleString str; str.fromUTF8 (uft8_str); return (bool) SetDlgItemTextW (hWnd, nIDDlgItem, str.c_str()); }
/* Draws the Format button with an arrow */ void AP_Win32Dialog_Styles::_onDrawButton(LPDRAWITEMSTRUCT lpDrawItemStruct, HWND hWnd) { UINT uiState = lpDrawItemStruct->itemState; HPEN hPen; HPEN pOldPen; HDC hdc = lpDrawItemStruct->hDC; int nWidth; int nHeight; int x, xEnd, xStart; int y; POINT p; const char* pText; HWND hParent; LONG lData; UT_Win32LocaleString str; const XAP_StringSet * pSS = m_pApp->getStringSet(); pText= pSS->getValue(AP_STRING_ID_DLG_Styles_ModifyFormat); nWidth = lpDrawItemStruct->rcItem.right - lpDrawItemStruct->rcItem.left; nHeight = lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top; // set the pen color if (uiState&ODS_DISABLED) hPen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_GRAYTEXT)); else hPen = CreatePen(PS_SOLID, 0, GetSysColor(COLOR_BTNTEXT)); pOldPen = (HPEN) SelectObject(hdc, hPen); // draw the border of the button if(uiState&ODS_SELECTED) DrawFrameControl(hdc, &lpDrawItemStruct->rcItem, DFC_BUTTON, DFCS_BUTTONPUSH|DFCS_PUSHED); else DrawFrameControl(hdc, &lpDrawItemStruct->rcItem, DFC_BUTTON, DFCS_BUTTONPUSH); // Draw arrow y = nHeight/2; xStart = (nWidth/6)*5; for (int i=0; i<4; i++) { x = xStart + i; xEnd = xStart + 7 - i; ::MoveToEx(hdc, x, y, &p); ::LineTo(hdc, xEnd, y); y++; } str.fromUTF8(pText); ExtTextOutW(hdc, (nWidth/6)*1, ((nHeight/4)), 0, NULL, str.c_str(), str.length(), NULL); // Clean Up SelectObject(hdc, pOldPen); DeleteObject(hPen); }
// cmdline processing call back I reckon void AP_Win32App::errorMsgBadArg(const char *msg) { char *pszMessage; UT_Win32LocaleString str; pszMessage = g_strdup_printf ("%s\nRun with --help' to see a full list of available command line options.\n", msg); str.fromUTF8(pszMessage); MessageBoxW(NULL, str.c_str(), L"Command Line Option Error", MB_OK|MB_ICONERROR); g_free( pszMessage ); }
void XAP_Win32DialogBase::getComboTextItem(UT_sint32 controlId, int index, UT_Win32LocaleString& str) { UT_return_if_fail(IsWindow(m_hDlg)); wchar_t szBuff[1024]; if (SendDlgItemMessageW(m_hDlg, controlId, CB_GETLBTEXT, index, (LPARAM)szBuff) != CB_ERR) str.fromLocale(szBuff); else str.clear(); }
BOOL AP_Win32Dialog_Columns::_onDeltaPos(NM_UPDOWN * pnmud) { wchar_t buf[BUFSIZE]; UT_Win32LocaleString str; switch( pnmud->hdr.idFrom ) { case AP_RID_DIALOG_COLUMN_SPIN_NUMCOLUMNS: if( pnmud->iDelta < 0 ) { setColumns( getColumns() + 1 ); } else { if( getColumns() > 1 ) { setColumns( getColumns() - 1 ); } } SetDlgItemTextW(m_hDlg, AP_RID_DIALOG_COLUMN_EDIT_NUMCOLUMNS, _itow(getColumns(),buf,10)); checkButton(AP_RID_DIALOG_COLUMN_RADIO_ONE, (getColumns()==1)); checkButton(AP_RID_DIALOG_COLUMN_RADIO_TWO, (getColumns()==2)); checkButton(AP_RID_DIALOG_COLUMN_RADIO_THREE, (getColumns()==3)); return 1; case AP_RID_DIALOG_COLUMN_SPIN_SPACEAFTER: if( pnmud->iDelta < 0 ) { incrementSpaceAfter( true ); } else { incrementSpaceAfter( false ); } str.fromUTF8 (getSpaceAfterString()); SetDlgItemTextW(m_hDlg, AP_RID_DIALOG_COLUMN_EDIT_SPACEAFTER, str.c_str ()); return 1; case AP_RID_DIALOG_COLUMN_SPIN_MAXSIZE: if( pnmud->iDelta < 0 ) { incrementMaxHeight( true ); } else { incrementMaxHeight( false ); } str.fromUTF8 (getHeightString()); SetDlgItemTextW(m_hDlg, AP_RID_DIALOG_COLUMN_EDIT_MAXSIZE, str.c_str ()); return 1; default: return 0; } }
void AP_Win32Dialog_Field::SetTypesList(void) { UT_Win32LocaleString str; for (int i = 0;fp_FieldTypes[i].m_Desc != NULL;i++) { str.fromUTF8(fp_FieldTypes[i].m_Desc); SendMessageW(m_hwndTypes, LB_ADDSTRING, (WPARAM)0, (LPARAM)str.c_str()); } SendMessageW(m_hwndTypes, LB_SETCURSEL, (WPARAM)0, (LPARAM)0); m_iTypeIndex = 0; }
bool XAP_Win32DialogBase::getDlgItemText(int nIDDlgItem, UT_Win32LocaleString& str) { wchar_t szBuff [1024]; bool rslt; rslt = (bool) GetDlgItemTextW(m_hDlg, nIDDlgItem, szBuff, 1024); if (rslt == true) str.fromLocale(szBuff); else str.clear(); return rslt; }
bool XAP_Win32DialogBase::getDlgItemText(HWND hWnd, int nIDDlgItem, UT_Win32LocaleString& str) { UT_return_val_if_fail(IsWindow(hWnd), false); wchar_t szBuff [1024]; bool rslt; rslt = (bool) GetDlgItemTextW(hWnd, nIDDlgItem, szBuff, 1024); if (rslt == true) str.fromLocale(szBuff); else str.clear(); return rslt; }
bool AP_Win32LeftRuler::registerClass(XAP_Win32App * app) { ATOM a; UT_Win32LocaleString str; str.fromASCII (app->getApplicationName()); // register class for the left ruler swprintf(s_LeftRulerWndClassName, L"%sLeftRuler", str.c_str()); a = UT_RegisterClassEx(CS_DBLCLKS | CS_OWNDC, AP_Win32LeftRuler::_LeftRulerWndProc, app->getInstance(), NULL, LoadCursor(NULL, IDC_ARROW), GetSysColorBrush(COLOR_BTNFACE), NULL, NULL, s_LeftRulerWndClassName); UT_ASSERT_HARMLESS(a); return true; }
int CALLBACK AP_Win32Toolbar_FontCombo::_EnumFontsProc(LPLOGFONTW lplf, LPTEXTMETRICW lptm, DWORD dwStyle, LONG lParam) { AP_Win32Toolbar_FontCombo * ctl = (AP_Win32Toolbar_FontCombo *) lParam; UT_return_val_if_fail (ctl, 0); /* WARNING: any changes to this function should be closely coordinated with the equivalent logic in Win32Graphics::FindFont() */ // filter out fonts we don't use if (dwStyle & RASTER_FONTTYPE) return 1 ; #if 0 // This is too restrictive. Since EnumFontFamilies chooses at random // the character set for the chosen font family, we were missing things // here. Perhaps use EnumFontFamiliesEx instead? if (lplf->lfCharSet != ANSI_CHARSET) return 1 ; #endif // filter out vertical fonts which aren't supported if (lplf->lfFaceName[0]=='@') return 1; UT_Win32LocaleString str; str.fromLocale (lplf->lfFaceName); char * p = g_strdup((str.utf8_str().utf8_str())); if (seenFonts.find(p)!=seenFonts.end()) { FREEP(p); return 1; } ctl->m_vecContents.addItem(p); ctl->m_vecFontCharSet.addItem((void*)lplf->lfCharSet); seenFonts.insert(p); return 1; }
void AP_Win32Dialog_MailMerge::setFieldList() { if (!m_vecFields.size()) return; resetContent(AP_RID_DIALOG_MAILMERGE_LISTBOX); // build a list of all items for (UT_sint32 i = 0; i < m_vecFields.size(); i++) { UT_continue_if_fail(m_vecFields[i]); UT_Win32LocaleString str; str.fromUTF8(((UT_UTF8String*)m_vecFields[i])->utf8_str()); SendMessageW(GetDlgItem(m_hDlg, AP_RID_DIALOG_MAILMERGE_LISTBOX), LB_ADDSTRING, 0, (LPARAM)str.ucs2_str()); } }
static bool s_createDirectoryIfNecessary(const char * szDir) { struct _stat statbuf; UT_Win32LocaleString str; str.fromUTF8(szDir); if (_wstat(str.c_str(),&statbuf) == 0) // if it exists { if ( (statbuf.st_mode & _S_IFDIR) == _S_IFDIR ) // and is a directory return true; UT_DEBUGMSG(("Pathname [%s] is not a directory.\n",szDir)); return false; } if (CreateDirectoryW(str.c_str(),NULL)) return true; UT_DEBUGMSG(("Could not create Directory [%s].\n",szDir)); return false; }
void AP_Win32Dialog_CollaborationAccounts::_populateWindowData() { AbiCollabSessionManager* pManager = AbiCollabSessionManager::getManager(); UT_return_if_fail(pManager); m_bPopulating = true; // clear out the old contents, if any ListView_DeleteAllItems(m_hAccountList); for (UT_uint32 i = 0; i < pManager->getAccounts().size(); i++) { AccountHandler* pAccount = pManager->getAccounts()[i]; UT_continue_if_fail(pAccount); UT_Win32LocaleString sAccountText = AP_Win32App::s_fromUTF8ToWinLocale(pAccount->getDescription().utf8_str()); UT_Win32LocaleString sAccountTypeText = AP_Win32App::s_fromUTF8ToWinLocale(pAccount->getDisplayType().utf8_str()); // insert a new account record LVITEMW lviAccount; lviAccount.mask = LVIF_STATE | LVIF_IMAGE | LVIF_PARAM; lviAccount.state = 1; lviAccount.iItem = i; lviAccount.iSubItem = 0; lviAccount.lParam = (LPARAM)pAccount; SendMessageW(m_hAccountList, LVM_INSERTITEMW, 0, (LPARAM) &lviAccount); ListView_SetCheckState(m_hAccountList, i, pAccount->isOnline()); lviAccount.iSubItem=1; lviAccount.pszText= const_cast<LPWSTR>(sAccountText.c_str()); SendMessageW(m_hAccountList, LVM_SETITEMTEXTW, i, (LPARAM) &lviAccount); lviAccount.iSubItem=2; lviAccount.pszText= const_cast<LPWSTR>(sAccountTypeText.c_str()); SendMessageW(m_hAccountList, LVM_SETITEMTEXTW, i, (LPARAM) &lviAccount); } _updateSelection(); m_bPopulating = false; }
/* Does a stringSet exist on disk? */ bool AP_Win32App::doesStringSetExist(const char* pLocale) { HANDLE in; const char * szDirectory = NULL; UT_return_val_if_fail(pLocale, false); getPrefsValueDirectory(true,AP_PREF_KEY_StringSetDirectory,&szDirectory); UT_return_val_if_fail(((szDirectory) && (*szDirectory)), false); char *szPathname = (char*) UT_calloc(sizeof(char),strlen(szDirectory)+strlen(pLocale)+100); UT_return_val_if_fail(szPathname, false); char *szDest = szPathname; strcpy(szDest, szDirectory); szDest += strlen(szDest); if ((szDest > szPathname) && (szDest[-1]!='\\')) *szDest++='\\'; lstrcpyA(szDest,pLocale); lstrcatA(szDest,".strings"); UT_Win32LocaleString wsFilename; wsFilename.fromUTF8(szPathname); in = CreateFileW(wsFilename.c_str(),0,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL, OPEN_EXISTING,0,NULL); g_free (szPathname); if (in!=INVALID_HANDLE_VALUE) { CloseHandle(in); return true; } return false; }
BOOL AP_Win32Dialog_Styles::_onCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { WORD wNotifyCode = HIWORD(wParam); WORD wId = LOWORD(wParam); HWND hWndCtrl = (HWND)lParam; switch (wId) { case AP_RID_DIALOG_STYLES_TOP_BUTTON_APPLY: { const gchar * szStyle = getCurrentStyle(); if(szStyle && *szStyle) { getView()->setStyle(szStyle); } } m_answer = a_OK; return 1; case AP_RID_DIALOG_STYLES_TOP_BUTTON_CLOSE: case IDCANCEL: m_answer = a_CANCEL; EndDialog(hWnd,0); return 1; case IDOK: { const XAP_StringSet * pSS = m_pApp->getStringSet (); WCHAR stylename[MAX_EBX_LENGTH+1]; // Verfiy a name value for the style // TODO - Verify unique name value GetDlgItemTextW(hWnd,AP_RID_DIALOG_STYLES_NEWMODIFY_EBX_NAME,stylename,MAX_EBX_LENGTH); /*_win32DialogNewModify.getControlText( AP_RID_DIALOG_STYLES_NEWMODIFY_EBX_NAME, m_newStyleName, MAX_EBX_LENGTH );*/ UT_UTF8String str; str.appendUCS2((const UT_UCS2Char*)stylename,0); strcpy(m_newStyleName,str.utf8_str()); if( !m_newStyleName || !strlen(m_newStyleName) ) { getFrame()->showMessageBox( pSS->getValue (AP_STRING_ID_DLG_Styles_ErrBlankName), XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK); return 1; } //strcpy (m_newStyleName, (AP_Win32App::s_fromWinLocaleToUTF8(m_newStyleName)).utf8_str()); } m_answer = a_OK; EndDialog(hWnd,0); return 1; case AP_RID_DIALOG_STYLES_TOP_COMBO_LIST: if( wNotifyCode == CBN_SELCHANGE ) { switch(_win32Dialog.getComboSelectedIndex(AP_RID_DIALOG_STYLES_TOP_COMBO_LIST)) { case 0: m_whichType = USED_STYLES; break; case 1: m_whichType = ALL_STYLES; break; case 2: m_whichType = USER_STYLES; break; } _populateWindowData(); } return 1; case AP_RID_DIALOG_STYLES_TOP_LIST_STYLES: if (wNotifyCode == LBN_SELCHANGE) { UT_uint32 nData = -1; const char* name; const PD_Style * pcStyle = NULL; int row = _win32Dialog.getListSelectedIndex(AP_RID_DIALOG_STYLES_TOP_LIST_STYLES); nData = _win32Dialog.getListDataItem( AP_RID_DIALOG_STYLES_TOP_LIST_STYLES, row); if (row!=LB_ERR) { getDoc()->enumStyles(nData, &name, &pcStyle); m_selectedStyle = name; m_nSelectedStyleIdx = nData; // refresh the previews _populatePreviews(false); } break; } return 1; case AP_RID_DIALOG_STYLES_TOP_BUTTON_DELETE: { if( m_selectedStyle != "" ) { if ( !getDoc()->removeStyle(m_selectedStyle.c_str()) ) // actually remove the style { const XAP_StringSet * pSS = m_pApp->getStringSet(); getFrame()->showMessageBox( pSS->getValue (AP_STRING_ID_DLG_Styles_ErrStyleCantDelete), XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK ); return 1; } getFrame()->repopulateCombos(); _populateWindowData(); // force a refresh getDoc()->signalListeners(PD_SIGNAL_UPDATE_LAYOUT); m_selectedStyle = ""; } } return 1; case AP_RID_DIALOG_STYLES_TOP_BUTTON_NEW: { m_bisNewStyle = true; //_win32Dialog.showWindow(SW_HIDE); XAP_Frame* pFrame = getFrame(); //_win32DialogNewModify.runModal(pFrame, AP_DIALOG_ID_STYLES, AP_RID_DIALOG_STYLES_NEWMODIFY, this); createModal(pFrame, MAKEINTRESOURCEW(AP_RID_DIALOG_STYLES_NEWMODIFY)); if(m_answer == AP_Dialog_Styles::a_OK) { createNewStyle((gchar *) m_newStyleName); _populateCList(); } destroyAbiPreview(); DELETEP(m_pAbiPreviewWidget); //_win32Dialog.showWindow(SW_SHOW); } return 1; case AP_RID_DIALOG_STYLES_TOP_BUTTON_MODIFY: { // Verify that a style is selected if( m_selectedStyle == "" ) { XAP_Frame * pFrame = getFrame(); const XAP_StringSet * pSS = m_pApp->getStringSet(); 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 1; } else { PD_Style * pStyle = NULL; getDoc()->getStyle(m_selectedStyle.c_str(), &pStyle); m_bisNewStyle = false; XAP_Frame* pFrame = getFrame(); XAP_Win32App * pWin32App = static_cast<XAP_Win32App *>(getApp()); createModal (pFrame, MAKEINTRESOURCEW(AP_RID_DIALOG_STYLES_NEWMODIFY)); /*LPCWSTR lpTemplate = MAKEINTRESOURCEW(AP_RID_DIALOG_STYLES_NEWMODIFY); int result = DialogBoxParamW(pWin32App->getInstance(), lpTemplate, static_cast<XAP_Win32FrameImpl*>(pFrame->getFrameImpl())->getTopLevelWindow(), (DLGPROC)s_dlgProc, (LPARAM)this);*/ if(m_answer == AP_Dialog_Styles::a_OK) { applyModifiedStyleToDoc(); getDoc()->updateDocForStyleChange(getCurrentStyle(),true); getDoc()->signalListeners(PD_SIGNAL_UPDATE_LAYOUT); } destroyAbiPreview(); DELETEP(m_pAbiPreviewWidget); } } return 1; case AP_RID_DIALOG_STYLES_NEWMODIFY_BTN_REMOVE: { char szTemp[128]; _win32DialogNewModify.getControlText( AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_REMOVE, szTemp, sizeof(szTemp) ); removeVecProp(szTemp); rebuildDeleteProps(); updateCurrentStyle(); } return 1; case AP_RID_DIALOG_STYLES_NEWMODIFY_BTN_TOGGLEITEMS: { RECT rect; HMENU hMenu; int x,y; HWND hWndButton; static int menu_items[]={AP_STRING_ID_DLG_Styles_ModifyParagraph, AP_STRING_ID_DLG_Styles_ModifyFont, AP_STRING_ID_DLG_Styles_ModifyTabs, AP_STRING_ID_DLG_Styles_ModifyNumbering, AP_STRING_ID_DLG_Styles_ModifyLanguage }; UT_Win32LocaleString str; hWndButton = GetDlgItem(hWnd, AP_RID_DIALOG_STYLES_NEWMODIFY_BTN_TOGGLEITEMS); XAP_Win32App * app = static_cast<XAP_Win32App *> (m_pApp); const XAP_StringSet * pSS = m_pApp->getStringSet(); // Get button position GetWindowRect(hWndButton, &rect); x = rect.left; y = rect.bottom; // Menu creation hMenu = CreatePopupMenu(); str; for (int i=0; i<5; i++) { str.fromUTF8(pSS->getValue(menu_items[i])); AppendMenuW(hMenu, MF_ENABLED|MF_STRING, i+1, (LPCWSTR)str.c_str()); } // show and track the menu m_selectToggle = TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_NONOTIFY|TPM_RETURNCMD, x,y,0, hWndButton, NULL); switch(m_selectToggle) { case 0: // user has cancelled break; case 1: ModifyParagraph(); break; case 2: ModifyFont(); break; case 3: ModifyTabs(); break; case 4: ModifyLists(); break; case 5: ModifyLang(); break; default: break; } rebuildDeleteProps(); updateCurrentStyle(); DestroyMenu(hMenu); return 1; } case AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_BASEDON: if( wNotifyCode == CBN_SELCHANGE ) { eventBasedOn(); rebuildDeleteProps(); } return 1; case AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_FOLLOWPARA: if( wNotifyCode == CBN_SELCHANGE ) { eventFollowedBy(); } return 1; case AP_RID_DIALOG_STYLES_NEWMODIFY_CBX_TYPE: if( wNotifyCode == CBN_SELCHANGE ) { eventStyleType(); } return 1; default: // we did not handle this notification UT_DEBUGMSG(("WM_Command for id %ld\n",wId)); return 0; // return zero to let windows take care of it. } return 0; // return zero to let windows take care of it. }
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_Win32Dialog_New::_onInitDialog(HWND hWnd, WPARAM wParam, LPARAM lParam) { m_hThisDlg = hWnd; XAP_Win32App * app = static_cast<XAP_Win32App *> (m_pApp); UT_return_val_if_fail (app,1); const XAP_StringSet * pSS = m_pApp->getStringSet(); _win32Dialog.setDialogTitle(pSS->getValue(AP_STRING_ID_DLG_NEW_Title)); // localize controls _DSX(NEW_BTN_OK, DLG_OK); _DSX(NEW_BTN_CANCEL, DLG_Cancel); _DS(NEW_RDO_TEMPLATE, DLG_NEW_Create); _DS(NEW_RDO_EXISTING, DLG_NEW_Open); _DS(NEW_BTN_EXISTING, DLG_NEW_Choose); // set initial state _win32Dialog.setControlText(AP_RID_DIALOG_NEW_EBX_EXISTING, pSS->getValue(AP_STRING_ID_DLG_NEW_NoFile)); HWND hControl = GetDlgItem(hWnd, AP_RID_DIALOG_NEW_LBX_TEMPLATE); long findtag; struct _finddata_t cfile; UT_String templateName, searchDir; templateName = XAP_App::getApp()->getUserPrivateDirectory(); searchDir = XAP_App::getApp()->getUserPrivateDirectory(); searchDir += "\\templates\\*.awt"; findtag = _findfirst( searchDir.c_str(), &cfile ); if( findtag != -1 ) { do { templateName = XAP_App::getApp()->getUserPrivateDirectory(); templateName += "\\templates\\"; templateName += cfile.name; if(!strstr(templateName.c_str(), "normal.awt-")) // don't truncate localized template names templateName = templateName.substr ( 0, templateName.size () - 4 ) ; UT_Win32LocaleString str; str.fromASCII (templateName.c_str()); char *uri = UT_go_filename_to_uri(str.utf8_str().utf8_str()); UT_continue_if_fail(uri); UT_sint32 nIndex = SendMessageW( hControl, LB_ADDSTRING, 0, (LPARAM) UT_basename( uri ) ); SendMessageW( hControl, LB_SETITEMDATA, (WPARAM) nIndex, (LPARAM) 0 ); g_free(uri); } while( _findnext( findtag, &cfile ) == 0 ); } _findclose( findtag ); templateName = XAP_App::getApp()->getAbiSuiteLibDir(); searchDir = XAP_App::getApp()->getAbiSuiteLibDir(); searchDir += "\\templates\\*.awt"; findtag = _findfirst( searchDir.c_str(), &cfile ); if( findtag != -1 ) { do { templateName = XAP_App::getApp()->getAbiSuiteLibDir(); templateName += "\\templates\\"; templateName += cfile.name; if(!strstr(templateName.c_str(), "normal.awt-")) // don't truncate localized template names templateName = templateName.substr ( 0, templateName.size () - 4 ) ; UT_Win32LocaleString str; str.fromASCII (templateName.c_str()); char *uri = UT_go_filename_to_uri(str.utf8_str().utf8_str()); UT_continue_if_fail(uri); UT_sint32 nIndex = SendMessageW( hControl, LB_ADDSTRING, 0, (LPARAM) UT_basename( uri ) ); SendMessageW( hControl, LB_SETITEMDATA, (WPARAM) nIndex, (LPARAM) 1 ); g_free(uri); } while( _findnext( findtag, &cfile ) == 0 ); } _findclose( findtag ); XAP_Win32DialogHelper::s_centerDialog(hWnd); _updateControls(); return 1; // 1 == we did not call SetFocus() }
BOOL AP_Win32Dialog_MailMerge::_onCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { WORD wNotifyCode = HIWORD(wParam); WORD wId = LOWORD(wParam); HWND hWndCtrl = (HWND)lParam; switch (wId) { case AP_RID_DIALOG_MAILMERGE_LISTBOX: if (HIWORD(wParam)==LBN_DBLCLK) { UT_Win32LocaleString str; int nItem = SendMessageW(GetDlgItem(m_hDlg, AP_RID_DIALOG_MAILMERGE_LISTBOX), LB_GETCURSEL, 0, 0); if (nItem!=LB_ERR) { // get the mail merge field from the listbox HWND lBox = GetDlgItem(m_hDlg, AP_RID_DIALOG_MAILMERGE_LISTBOX); UT_sint32 len = SendMessageW(lBox, LB_GETTEXTLEN, nItem, (LPARAM)0); wchar_t* szBuff = (wchar_t*)g_malloc(sizeof(wchar_t) * (len + 1)); SendMessageW(lBox, LB_GETTEXT, nItem, (LPARAM)szBuff); str.fromLocale(szBuff); FREEP(szBuff); setMergeField(str.utf8_str()); addClicked(); } return 1; } else { return 0; } case AP_RID_DIALOG_MAILMERGE_BTN_INSERT: { UT_Win32LocaleString str; int nChars = getDlgItemText(AP_RID_DIALOG_MAILMERGE_EDIT_FIELD, str); if (nChars > 0) { setMergeField(str.utf8_str ()); addClicked(); } else { int nItem = SendMessageW(GetDlgItem(m_hDlg, AP_RID_DIALOG_MAILMERGE_LISTBOX), LB_GETCURSEL, 0, 0); if (nItem!=LB_ERR) { // get the mail merge field from the listbox HWND lBox = GetDlgItem(m_hDlg, AP_RID_DIALOG_MAILMERGE_LISTBOX); UT_sint32 len = SendMessageW(lBox, LB_GETTEXTLEN, nItem, (LPARAM)0); wchar_t* szBuff = (wchar_t*)g_malloc(sizeof(wchar_t) * (len + 1)); SendMessageW(lBox, LB_GETTEXT, nItem, (LPARAM)szBuff); str.fromLocale(szBuff); FREEP(szBuff); setMergeField(str.utf8_str()); addClicked(); } } return 1; } case AP_RID_DIALOG_MAILMERGE_BTN_OPEN: { eventOpen(); SetFocus(m_hDlg); return 1; } case AP_RID_DIALOG_MAILMERGE_BTN_CLOSE: case IDCANCEL: // We want to close button work { destroy(); return 1; } default: // we did not handle this notification UT_DEBUGMSG(("WM_Command for id %ld\n",wId)); return 0; // return zero to let windows take care of it. } }
void XAP_Win32Dialog_FontChooser::runModal(XAP_Frame * pFrame) { UT_return_if_fail(pFrame); XAP_Win32App * pApp = static_cast<XAP_Win32App *>(XAP_App::getApp()); UT_return_if_fail(pApp); const XAP_EncodingManager *pEncMan = pApp->getEncodingManager(); UT_return_if_fail(pEncMan); UT_Win32LocaleString family; UT_DEBUGMSG(("FontChooserStart: Family[%s] Size[%s] Weight[%s] Style[%s] Color[%s] Underline[%d] StrikeOut[%d]\n", m_sFontFamily.c_str(), m_sFontSize.c_str(), m_sFontWeight.c_str(), m_sFontStyle.c_str(), m_sColor.c_str(), m_bUnderline, m_bStrikeout)); m_bWin32Overline = m_bOverline; m_bWin32Hidden = m_bHidden; m_bWin32SuperScript = m_bSuperScript; m_bWin32SubScript = m_bSubScript; /* WARNING: any changes to this function should be closely coordinated with the equivalent logic in Win32Graphics::FindFont() */ LOGFONTW lf; memset(&lf, 0, sizeof(lf)); CHOOSEFONTW cf; memset(&cf, 0, sizeof(cf)); cf.lStructSize = sizeof(cf); cf.hwndOwner = static_cast<XAP_Win32FrameImpl*>(pFrame->getFrameImpl())->getTopLevelWindow(); cf.lpLogFont = &lf; cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_ENABLEHOOK | CF_ENABLETEMPLATE | CF_INITTOLOGFONTSTRUCT; cf.lpTemplateName = MAKEINTRESOURCEW(XAP_RID_DIALOG_FONT); cf.lpfnHook = (LPCFHOOKPROC) s_hookProc; cf.lCustData = (LPARAM) this; cf.hInstance = pApp->getInstance(); if (!m_sFontFamily.empty()) { family.fromUTF8 (m_sFontFamily.c_str()); lstrcpynW(lf.lfFaceName,family.c_str(),LF_FACESIZE); } else cf.Flags |= CF_NOFACESEL; if (!m_sFontSize.empty()) { UT_ASSERT(sizeof(char) == sizeof(gchar)); lf.lfHeight = (long) -(UT_convertToPoints(m_sFontSize.c_str()))*4/3; } else cf.Flags |= CF_NOSIZESEL; if (!m_sFontWeight.empty()) { if (g_ascii_strcasecmp(m_sFontWeight.c_str(),"bold") == 0) lf.lfWeight = 700; // TODO do we need any others here... } else cf.Flags |= CF_NOSTYLESEL; if (!m_sFontStyle.empty()) { if (g_ascii_strcasecmp(m_sFontStyle.c_str(),"italic") == 0) lf.lfItalic = TRUE; } else cf.Flags |= CF_NOSTYLESEL; if (!m_sColor.empty()) { UT_RGBColor c; UT_parseColor(m_sColor.c_str(),c); cf.rgbColors = RGB(c.m_red,c.m_grn,c.m_blu); } if (m_bUnderline) lf.lfUnderline = TRUE; if (m_bStrikeout) lf.lfStrikeOut = TRUE; // run the actual dialog... m_answer = (ChooseFontW(&cf) ? a_OK : a_CANCEL); // Convert the font name returned by the Windows Font Chooser // to UTF-8. family.fromLocale (lf.lfFaceName); UT_UTF8String family_utf = family.utf8_str(); const char *szFontFamily = family_utf.utf8_str(); if (m_answer == a_OK) { if(!m_sFontFamily.empty()) { if((g_ascii_strcasecmp(szFontFamily, m_sFontFamily.c_str()) != 0)) { m_bChangedFontFamily = true; m_sFontFamily = szFontFamily; } } else { if(szFontFamily[0]) { m_bChangedFontFamily = true; m_sFontFamily = szFontFamily; } } bool bIsSizeValid = ((cf.Flags & CF_NOSIZESEL) == 0); bool bWasSizeValid = !m_sFontSize.empty(); char bufSize[10]; if (bIsSizeValid) sprintf(bufSize,"%dpt",(cf.iPointSize/10)); else bufSize[0] = 0; // why? let's see if (bIsSizeValid && (g_ascii_strcasecmp(bufSize,m_sFontSize.c_str()) != 0)) { m_bChangedFontSize = true; m_sFontSize = bufSize; } else { /* nothing changed */ } bool bIsBold = ((cf.nFontType & BOLD_FONTTYPE) != 0); bool bWasBold = (g_ascii_strcasecmp(m_sFontWeight.c_str(),"bold") == 0); bool bIsNormal = ((cf.nFontType & REGULAR_FONTTYPE) != 0); bool bWasNormal = (m_sFontWeight.empty() || (g_ascii_strcasecmp(m_sFontWeight.c_str(),"normal") != 0)); if ((bIsBold != bWasBold) || (bIsNormal != bWasNormal)) { m_bChangedFontWeight = true; if( bIsBold ) m_sFontWeight = "bold"; else m_sFontWeight = "normal"; } bool bIsItalic = ((cf.nFontType & ITALIC_FONTTYPE) != 0); bool bWasItalic = (g_ascii_strcasecmp(m_sFontStyle.c_str(),"italic") == 0); if (bIsItalic != bWasItalic) { m_bChangedFontStyle = true; if( bIsItalic ) m_sFontStyle = "italic"; else m_sFontStyle = "normal"; } char bufColor[10]; sprintf(bufColor,"%02x%02x%02x",GetRValue(cf.rgbColors), GetGValue(cf.rgbColors),GetBValue(cf.rgbColors)); bool bWasColorValid = !m_sColor.empty(); if ( m_bChangedColor && ((bWasColorValid && (g_ascii_strcasecmp(bufColor,m_sColor.c_str()) != 0)) || (!bWasColorValid && (g_ascii_strcasecmp(bufColor,"000000") != 0)))) { m_sColor = bufColor; } m_bChangedUnderline = ((lf.lfUnderline == TRUE) != m_bUnderline); m_bChangedStrikeOut = ((lf.lfStrikeOut == TRUE) != m_bStrikeout); m_bChangedOverline = (m_bWin32Overline != m_bOverline); if (m_bChangedUnderline || m_bChangedStrikeOut || m_bChangedOverline) setFontDecoration( (lf.lfUnderline == TRUE), m_bWin32Overline, (lf.lfStrikeOut == TRUE), NULL, NULL); m_bChangedHidden = (m_bWin32Hidden != m_bHidden); m_bChangedSuperScript = (m_bWin32SuperScript != m_bSuperScript); m_bChangedSubScript = (m_bWin32SubScript != m_bSubScript); if(m_bChangedHidden) setHidden(m_bWin32Hidden); if(m_bChangedSuperScript) setSuperScript(m_bWin32SuperScript); if(m_bChangedSubScript) setSubScript(m_bWin32SubScript); } UT_DEBUGMSG(("FontChooserEnd: Family[%s%s] Size[%s%s] Weight[%s%s] Style[%s%s] Color[%s%s] Underline[%d%s] StrikeOut[%d%s]\n", m_sFontFamily.c_str(), ((m_bChangedFontFamily) ? "(chg)" : ""), m_sFontSize.c_str(), ((m_bChangedFontSize) ? "(chg)" : ""), m_sFontWeight.c_str(), ((m_bChangedFontWeight) ? "(chg)" : ""), m_sFontStyle.c_str(), ((m_bChangedFontStyle) ? "(chg)" : ""), m_sColor.c_str(), ((m_bChangedColor) ? "(chg)" : ""), m_bUnderline, ((m_bChangedUnderline) ? "(chg)" : ""), m_bStrikeout, ((m_bChangedStrikeOut) ? "(chg)" : ""))); // the caller can get the answer from getAnswer(). m_pWin32Frame = NULL; }
void XAP_Win32Slurp::processCommand(HDDEDATA hData) { DWORD bufSize = DdeGetData(hData,NULL,0,0); char * pBuf = (char *)UT_calloc(sizeof(char),bufSize+100); if (!pBuf) { UT_DEBUGMSG(("No memory to allocate DDE buffer [size %d]\n",bufSize)); return; } DdeGetData(hData,(LPBYTE)pBuf,bufSize+99,0); UT_Win32LocaleString wstr; UT_UTF8String astr; wstr.fromLocale((LPCWSTR)pBuf); astr=wstr.utf8_str(); UT_DEBUGMSG(("DDEML received command '%s'\n",astr.utf8_str())); // we expect something of the form: // [Open("<pathname>")] // if anything more complicated is needed, it may be a // good idea to use a regex library // TODO failures just goto Finished. Some error reporting // TODO would be nice // pointer to work through the incoming string const char * next = astr.utf8_str(); // pointer used to copy into command and pathname char * dest = 0; // chomp the [ if ( *next++ != '[' ) goto Finished; // find the next sequence of non ( characters // this will be the dde command char command[1024]; dest = command; for ( ; *next != '('; ++next ) { *dest++ = *next; } *dest = 0; // chomp the ( and the " if ( *next++ != '(' ) goto Finished; if ( *next++ != '"' ) goto Finished; // go until the next " to get the parameter // " are not allowed in filenames, so we should be safe here char pathname[4096]; dest = pathname; for ( ; *next != '"'; ++next ) { *dest++ = *next; } *dest = 0; // chomp the ", ), and ] if ( *next++ != '"' ) goto Finished; if ( *next++ != ')' ) goto Finished; if ( *next++ != ']' ) goto Finished; // now do something useful with the command and its parameter if (g_ascii_strcasecmp(command,"open") == 0) { if (!pathname || !*pathname) { UT_DEBUGMSG(("No pathname given in DDE Open command.\n")); goto Finished; } // ask the application to load this document into a window.... // let's create uri for comparison with filenames from command line // TODO: That method does not always work. Some proper method should // be designed. char *uri = UT_go_filename_to_uri(pathname); XAP_Win32App *p_app = (XAP_Win32App *)XAP_App::getApp(); UT_sint32 ndx = p_app->findFrame(uri); UT_Error error; if ((ndx < 0) || p_app->getFrame(ndx)->isDirty()) { error = p_app->fileOpen(p_app->getLastFocussedFrame(), uri); } if(error != UT_OK) { UT_DEBUGMSG(("Could not load document given in DDE Open command [%s].\n",uri)); } FREEP(uri); goto Finished; } Finished: FREEP(pBuf); DdeFreeDataHandle(hData); }
int AP_Win32App::WinMain(const char * szAppName, HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow) { if (!g_thread_supported ()) g_thread_init (NULL); bool bShowApp = true; BOOL bInitialized = FALSE; // this is a static function and doesn't have a 'this' pointer. MSG msg; #ifdef _MSC_VER _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_DEBUG ); _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_DEBUG ); _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_DEBUG | _CRTDBG_MODE_WNDW); #endif // HACK: load least-common-denominator Rich Edit control // TODO: fix Spell dlg so we don't rely on this // ALT: make it a Preview widget instead HINSTANCE hinstRich = LoadLibraryW(L"riched32.dll"); if (!hinstRich) hinstRich = LoadLibraryW(L"riched20.dll"); UT_return_val_if_fail (hinstRich, 1); AP_Win32App * pMyWin32App; // OLE Stuff if (SUCCEEDED(OleInitialize(NULL))) bInitialized = TRUE; // We put this in a block to force the destruction of Args in the stack { UT_Win32LocaleString scnv; UT_UTF8String sUTFCmdLine; // Load the command line into an XAP_Args class scnv.fromLocale(GetCommandLineW()); sUTFCmdLine=scnv.utf8_str(); XAP_Args XArgs = XAP_Args(sUTFCmdLine.utf8_str()); // Step 1: Initialize our application. pMyWin32App = new AP_Win32App(hInstance, szAppName); AP_Args Args = AP_Args(&XArgs, szAppName, pMyWin32App); Args.parseOptions(); pMyWin32App->initialize(); // Step 2: Handle all non-window args. // process args (calls common arg handler, which then calls platform specific) // As best I understand, it returns true to continue and show window, or // false if no window should be shown (and thus we should simply exit). bool windowlessArgsWereSuccessful = true; if (!Args.doWindowlessArgs(windowlessArgsWereSuccessful)) { pMyWin32App->shutdown(); // properly shutdown the app 1st delete pMyWin32App; return (windowlessArgsWereSuccessful ? 0 : -1); } // Step 3: Create windows as appropriate. // if some args are botched, it returns false and we should // continue out the door. // We used to check for bShowApp here. It shouldn't be needed // anymore, because doWindowlessArgs was supposed to bail already. -PL if (!pMyWin32App->openCmdLineFiles(&Args)) { pMyWin32App->shutdown(); // properly shutdown the app 1st delete pMyWin32App; return 0; } } // // This block is controlled by the Structured Exception Handle // if any crash happens here we will recover it and save the file (cross fingers) // try { UT_uint32 iHeight = 0, iWidth = 0, t_flag =0; UT_sint32 iPosX = 0, iPosY = 0; if (!((XAP_App::getApp()->getGeometry(&iPosX,&iPosY,&iWidth,&iHeight,&t_flag)) && ((iWidth > 0) && (iHeight > 0))) ) XAP_App::getApp()->getDefaultGeometry(iWidth,iHeight,t_flag); if ((t_flag & PREF_FLAG_GEOMETRY_MAXIMIZED)==PREF_FLAG_GEOMETRY_MAXIMIZED) iCmdShow = SW_SHOWMAXIMIZED; if (bShowApp) { // display the windows for(UT_sint32 i = 0; i < pMyWin32App->m_vecFrames.getItemCount(); i++) { AP_Win32Frame * curFrame = (AP_Win32Frame*)pMyWin32App->m_vecFrames[i]; UT_continue_if_fail(curFrame); HWND hwnd = curFrame->getTopLevelWindow(); ShowWindow(hwnd, iCmdShow); UpdateWindow(hwnd); } // do dispatch loop while(UT_GetMessage(&msg, NULL, 0, 0)) { // TranslateMessage is not called because AbiWord // has its own way of decoding keyboard accelerators if (pMyWin32App->handleModelessDialogMessage(&msg)) continue; TranslateMessage(&msg); UT_DispatchMessage(&msg); // Check for idle condition while( !UT_Win32Idle::_isEmpty() && !PeekMessageW(&msg, NULL, 0, 0, PM_NOREMOVE) ) { // Fire idle functions when no pending messages UT_Win32Idle::_fireall(); } } } // Un-init OLE if (bInitialized) OleUninitialize(); FreeLibrary(hinstRich); // unload all loaded plugins (remove some of the memory leaks shown at shutdown :-) XAP_ModuleManager::instance().unloadAllPlugins(); // Step 4: Destroy the App. It should take care of deleting all frames. pMyWin32App->shutdown(); delete pMyWin32App; }// end of thes block is controlled by the Exception Handler // // If an exception happens, with "catch" the block // and then the save it into disk // catch (...) { #ifdef DEBUG throw; #endif AP_Win32App *pApp = (AP_Win32App *) XAP_App::getApp(); UT_return_val_if_fail (pApp,1); // first of all, try to save the current prefs (so that any log entries are dumped // onto disk -- this allows us to save useful info for dbg purposes) we will enclose // this inside of a try/catch block, so that in the (unlikely) case something goes // badly wrong when writing the prefs file, we still get chance to save the open // documents try { if(pApp->getPrefs()) { pApp->getPrefs()->savePrefsFile(); } } catch(...) { // do nothing } IEFileType abiType = IE_Imp::fileTypeForSuffix(".abw"); for (UT_sint32 i = 0; i < pApp->m_vecFrames.getItemCount(); i++) { AP_Win32Frame * curFrame = (AP_Win32Frame*)pApp->m_vecFrames[i]; UT_continue_if_fail(curFrame); // again, we want to catch any exception thrown while saving individual documents, // in order to run through the whole loop try { if (NULL == curFrame->getFilename()) curFrame->backup(".abw.saved", abiType); else curFrame->backup(".saved", abiType); } catch(...) { // do nothing } } // Tell the user was has just happened AP_Win32Frame * curFrame = (AP_Win32Frame*)pApp->m_vecFrames[0]; if (curFrame) { curFrame->showMessageBox(AP_STRING_ID_MSG_Exception,XAP_Dialog_MessageBox::b_O, XAP_Dialog_MessageBox::a_OK); } }// end of except SET_CRT_DEBUG_FIELD( _CRTDBG_LEAK_CHECK_DF ); return msg.wParam; }
void AP_Win32Dialog_Annotation::_get_text(int nID, std::string &text) { UT_Win32LocaleString str; getDlgItemText(nID, str); text = str.utf8_str().utf8_str(); }
BOOL AP_Win32Dialog_FormatFrame::_onCommand(HWND hWnd, WPARAM wParam, LPARAM lParam) { WORD wNotifyCode = HIWORD(wParam); WORD wId = LOWORD(wParam); switch (wId) { case AP_RID_DIALOG_FORMATFRAME_BMP_BOTTOM: { bool bChecked; bChecked = (bool)(IsDlgButtonChecked(m_hDlg, AP_RID_DIALOG_FORMATFRAME_BMP_BOTTOM)==BST_CHECKED); toggleLineType(AP_Dialog_FormatFrame::toggle_bottom, bChecked); event_previewExposed(); return 1; } case AP_RID_DIALOG_FORMATFRAME_BMP_TOP: { bool bChecked; bChecked = (bool)(IsDlgButtonChecked(m_hDlg, AP_RID_DIALOG_FORMATFRAME_BMP_TOP)==BST_CHECKED); toggleLineType(AP_Dialog_FormatFrame::toggle_top, bChecked); event_previewExposed(); return 1; } case AP_RID_DIALOG_FORMATFRAME_BMP_RIGHT: { bool bChecked; bChecked = (bool)(IsDlgButtonChecked(m_hDlg, AP_RID_DIALOG_FORMATFRAME_BMP_RIGHT)==BST_CHECKED); toggleLineType(AP_Dialog_FormatFrame::toggle_right, bChecked); event_previewExposed(); return 1; } case AP_RID_DIALOG_FORMATFRAME_BMP_LEFT: { bool bChecked; bChecked = (bool)(IsDlgButtonChecked(m_hDlg, AP_RID_DIALOG_FORMATFRAME_BMP_LEFT)==BST_CHECKED); toggleLineType(AP_Dialog_FormatFrame::toggle_left, bChecked); event_previewExposed(); return 1; } case AP_RID_DIALOG_FORMATFRAME_BTN_BORDERCOLOR: { CHOOSECOLORW cc; static COLORREF acrCustClr[16]; /* Initialize CHOOSECOLOR */ ZeroMemory(&cc, sizeof(CHOOSECOLORW)); cc.lStructSize = sizeof(CHOOSECOLORW); cc.hwndOwner = m_hDlg; cc.lpCustColors = (LPDWORD) acrCustClr; cc.rgbResult = 0; cc.Flags = CC_FULLOPEN | CC_RGBINIT; if(ChooseColorW(&cc)) { setBorderColor(UT_RGBColor(GetRValue( cc.rgbResult), GetGValue(cc.rgbResult), GetBValue(cc.rgbResult))); m_borderButton.setColour(cc.rgbResult); /*Force redraw*/ InvalidateRect(GetDlgItem(hWnd, AP_RID_DIALOG_FORMATFRAME_BTN_BORDERCOLOR), NULL, FALSE); event_previewExposed(); } return 1; } case AP_RID_DIALOG_FORMATFRAME_BTN_BACKCOLOR: { CHOOSECOLORW cc; static COLORREF acrCustClr2[16]; /* Initialize CHOOSECOLOR */ ZeroMemory(&cc, sizeof(CHOOSECOLORW)); cc.lStructSize = sizeof(CHOOSECOLORW); cc.hwndOwner = m_hDlg; cc.lpCustColors = (LPDWORD) acrCustClr2; cc.rgbResult = 0; cc.Flags = CC_FULLOPEN | CC_RGBINIT; if(ChooseColorW(&cc)) { setBGColor(UT_RGBColor(GetRValue( cc.rgbResult), GetGValue(cc.rgbResult), GetBValue(cc.rgbResult))); m_backgButton.setColour(cc.rgbResult); /*Force redraw*/ InvalidateRect(GetDlgItem(hWnd, AP_RID_DIALOG_FORMATFRAME_BTN_BACKCOLOR), NULL, FALSE); event_previewExposed(); } return 1; } case AP_RID_DIALOG_FORMATFRAME_CHK_TEXTWRAP: { bool bChecked; bChecked = (bool)(IsDlgButtonChecked(m_hDlg, AP_RID_DIALOG_FORMATFRAME_CHK_TEXTWRAP)==BST_CHECKED); setWrapping(bChecked); // Not necessary now, but we may some day show // text wrapping in the preview. event_previewExposed(); return 1; } case AP_RID_DIALOG_FORMATFRAME_BTN_CANCEL: m_answer = AP_Dialog_FormatFrame::a_CLOSE; destroy(); event_Close(); EndDialog(hWnd,0); return 1; case AP_RID_DIALOG_FORMATFRAME_COMBO_THICKNESS: { if (wNotifyCode == CBN_SELCHANGE) { int nSelected = getComboSelectedIndex (AP_RID_DIALOG_FORMATFRAME_COMBO_THICKNESS); if (nSelected != CB_ERR) { UT_LocaleTransactor t(LC_NUMERIC, "C"); UT_Win32LocaleString thickness; UT_UTF8String thickness_utf8 = thickness.utf8_str (); getComboTextItem(AP_RID_DIALOG_FORMATFRAME_COMBO_THICKNESS, nSelected, thickness); setBorderThicknessAll(thickness_utf8); event_previewExposed(); } } return 1; } case AP_RID_DIALOG_FORMATFRAME_BUTTON_SELIMAGE: askForGraphicPathName(); return 1; case AP_RID_DIALOG_FORMATFRAME_BUTTON_NOIMAGE: clearImage(); return 1; case AP_RID_DIALOG_FORMATFRAME_RADIO_PARA: setPositionMode(FL_FRAME_POSITIONED_TO_BLOCK); return 1; case AP_RID_DIALOG_FORMATFRAME_RADIO_COLUMN: setPositionMode(FL_FRAME_POSITIONED_TO_COLUMN); return 1; case AP_RID_DIALOG_FORMATFRAME_RADIO_PAGE: setPositionMode(FL_FRAME_POSITIONED_TO_PAGE); return 1; case AP_RID_DIALOG_FORMATFRAME_BTN_APPLY: applyChanges(); return 1; default: // we did not handle this notification UT_DEBUGMSG(("WM_Command for id %ld\n",wId)); return 0; // return zero to let windows take care of it. } }
BOOL AP_Win32Dialog_Columns::_onCommand(HWND hWnd, WPARAM wParam, LPARAM /*lParam*/) { WORD wNotifyCode = HIWORD(wParam); WORD wId = LOWORD(wParam); wchar_t buf[BUFSIZE]; UT_Win32LocaleString str; switch (wId) { case IDCANCEL: // also AP_RID_DIALOG_COLUMN_BTN_CANCEL m_answer = a_CANCEL; // fall through case IDOK: // also AP_RID_DIALOG_COLUMN_BTN_OK EndDialog(hWnd,0); return 1; case AP_RID_DIALOG_COLUMN_RADIO_ONE: setColumns(1); checkButton(AP_RID_DIALOG_COLUMN_RADIO_TWO, false); checkButton(AP_RID_DIALOG_COLUMN_RADIO_THREE, false); SetDlgItemTextW(m_hDlg, AP_RID_DIALOG_COLUMN_EDIT_NUMCOLUMNS, _itow(getColumns(),buf,10)); return 1; case AP_RID_DIALOG_COLUMN_RADIO_TWO: setColumns(2); checkButton(AP_RID_DIALOG_COLUMN_RADIO_ONE, false); checkButton(AP_RID_DIALOG_COLUMN_RADIO_THREE, false); SetDlgItemTextW(m_hDlg, AP_RID_DIALOG_COLUMN_EDIT_NUMCOLUMNS, _itow(getColumns(),buf,10)); return 1; case AP_RID_DIALOG_COLUMN_RADIO_THREE: setColumns(3); checkButton(AP_RID_DIALOG_COLUMN_RADIO_ONE, false); checkButton(AP_RID_DIALOG_COLUMN_RADIO_TWO, false); SetDlgItemTextW(m_hDlg, AP_RID_DIALOG_COLUMN_EDIT_NUMCOLUMNS, _itow(getColumns(),buf,10)); return 1; case AP_RID_DIALOG_COLUMN_CHECK_LINE_BETWEEN: setLineBetween( isChecked(AP_RID_DIALOG_COLUMN_CHECK_LINE_BETWEEN)==BST_CHECKED ); return 1; case AP_RID_DIALOG_COLUMN_EDIT_NUMCOLUMNS: if( wNotifyCode == EN_KILLFOCUS ) { GetDlgItemTextW( hWnd, wId, buf, BUFSIZE ); if( _wtoi( buf ) > 0 && _wtoi(buf) != (signed) getColumns() ) { setColumns( _wtoi(buf) ); } SetDlgItemTextW(m_hDlg, wId, _itow(getColumns(),buf,10)); checkButton(AP_RID_DIALOG_COLUMN_RADIO_ONE, (getColumns()==1)); checkButton(AP_RID_DIALOG_COLUMN_RADIO_TWO, (getColumns()==2)); checkButton(AP_RID_DIALOG_COLUMN_RADIO_THREE, (getColumns()==3)); } return 1; case AP_RID_DIALOG_COLUMN_EDIT_SPACEAFTER: if( wNotifyCode == EN_KILLFOCUS ) { GetDlgItemTextW( hWnd, wId, buf, BUFSIZE ); str.fromLocale (buf); setSpaceAfter( str.utf8_str().utf8_str() ); str.fromUTF8 (getSpaceAfterString ()); SetDlgItemTextW(m_hDlg, wId, str.c_str ()); } return 1; case AP_RID_DIALOG_COLUMN_EDIT_MAXSIZE: if( wNotifyCode == EN_KILLFOCUS ) { GetDlgItemTextW( hWnd, wId, buf, BUFSIZE ); str.fromLocale (buf); setMaxHeight( str.utf8_str().utf8_str() ); str.fromUTF8 (getHeightString()); SetDlgItemTextW(m_hDlg, wId, str.c_str ()); } return 1; case AP_RID_DIALOG_COLUMN_CHECK_RTL_ORDER: setColumnOrder( (UT_uint32) (isChecked(AP_RID_DIALOG_COLUMN_CHECK_RTL_ORDER) == BST_CHECKED) ); return 1; default: // we did not handle this notification UT_DEBUGMSG(("WM_Command for id %ld\n",wId)); return 0; // return zero to let windows take care of it. } }
bool AP_Win32App::initialize(void) { bool bSuccess = true; const char * szUserPrivateDirectory = getUserPrivateDirectory(); bool bVerified = s_createDirectoryIfNecessary(szUserPrivateDirectory); UT_return_val_if_fail (bVerified, false); // create templates directory UT_String sTemplates = szUserPrivateDirectory; sTemplates += "/templates"; s_createDirectoryIfNecessary(sTemplates.c_str()); // load the preferences. m_prefs = new AP_Win32Prefs(); UT_return_val_if_fail (m_prefs, false); m_prefs->fullInit(); // now that preferences are established, let the xap init m_pClipboard = new AP_Win32Clipboard(); UT_return_val_if_fail (m_pClipboard, false); m_pEMC = AP_GetEditMethods(); UT_return_val_if_fail (m_pEMC, false); m_pBindingSet = new AP_BindingSet(m_pEMC); UT_return_val_if_fail (m_pBindingSet, false); m_pMenuActionSet = AP_CreateMenuActionSet(); UT_return_val_if_fail (m_pMenuActionSet,false); m_pToolbarActionSet = AP_CreateToolbarActionSet(); UT_return_val_if_fail (m_pToolbarActionSet,false); ////////////////////////////////////////////////////////////////// // load the dialog and message box strings ////////////////////////////////////////////////////////////////// { // assume we will be using the builtin set (either as the main // set or as the fallback set). AP_BuiltinStringSet * pBuiltinStringSet = new AP_BuiltinStringSet(this,AP_PREF_DEFAULT_StringSet); UT_return_val_if_fail (pBuiltinStringSet, false); m_pStringSet = pBuiltinStringSet; // see if we should load an alternate set from the disk const char * szDirectory = NULL; const char * szStringSet = NULL; if ( (getPrefsValue(AP_PREF_KEY_StringSet,&szStringSet)) && (szStringSet) && (*szStringSet) && (g_ascii_strcasecmp(szStringSet,AP_PREF_DEFAULT_StringSet) != 0)) { getPrefsValueDirectory(true,AP_PREF_KEY_StringSetDirectory,&szDirectory); UT_return_val_if_fail ((szDirectory) && (*szDirectory), false); char * szPathname = (char *)UT_calloc(sizeof(char),strlen(szDirectory)+strlen(szStringSet)+100); UT_return_val_if_fail (szPathname, false); sprintf(szPathname,"%s%s%s.strings", szDirectory, ((szDirectory[strlen(szDirectory)-1]=='\\') ? "" : "\\"), szStringSet); AP_DiskStringSet * pDiskStringSet = new AP_DiskStringSet(this); UT_return_val_if_fail (pDiskStringSet, false); if (pDiskStringSet->loadStringsFromDisk(szPathname)) { pDiskStringSet->setFallbackStringSet(m_pStringSet); m_pStringSet = pDiskStringSet; UT_Language_updateLanguageNames(); UT_DEBUGMSG(("Using StringSet [%s]\n",szPathname)); } else { UT_DEBUGMSG(("Unable to load StringSet [%s] -- using builtin strings instead.\n",szPathname)); DELETEP(pDiskStringSet); } g_free(szPathname); } } // AP_App::initilize() calls for us XAP_Win32App::initialize() if (! AP_App::initialize()) return false; // let various window types register themselves if (!AP_Win32Frame::RegisterClass(this)) { UT_DEBUGMSG(("couldn't register class\n")); return false; } ////////////////////////////////////////////////////////////////// // Initialize the importers/exporters ////////////////////////////////////////////////////////////////// IE_ImpExp_RegisterXP (); ////////////////////////////////////////////////////////////////// // initializes the spell checker. ////////////////////////////////////////////////////////////////// { #if ENABLE_SPELL SpellManager::instance(); #endif } // Now we have the strings loaded we can populate the field names correctly int i; for (i = 0; fp_FieldTypes[i].m_Type != FPFIELDTYPE_END; i++) { (&fp_FieldTypes[i])->m_Desc = m_pStringSet->getValue(fp_FieldTypes[i].m_DescId); UT_DEBUGMSG(("Setting field type desc for type %d, desc=%s\n", fp_FieldTypes[i].m_Type, fp_FieldTypes[i].m_Desc)); } for (i = 0; fp_FieldFmts[i].m_Tag != NULL; i++) { (&fp_FieldFmts[i])->m_Desc = m_pStringSet->getValue(fp_FieldFmts[i].m_DescId); UT_DEBUGMSG(("Setting field desc for field %s, desc=%s\n", fp_FieldFmts[i].m_Tag, fp_FieldFmts[i].m_Desc)); } /////////////////////////////////////////////////////////////////////// /// Build a labelset so the plugins can add themselves to something /// /////////////////////////////////////////////////////////////////////// const char * szMenuLabelSetName = NULL; if (getPrefsValue( AP_PREF_KEY_StringSet, (const gchar**)&szMenuLabelSetName) && (szMenuLabelSetName) && (*szMenuLabelSetName)) { ; } else szMenuLabelSetName = AP_PREF_DEFAULT_StringSet; getMenuFactory()->buildMenuLabelSet(szMenuLabelSetName); ////////////////////////////////////////////////////////////////// // Check for necessary DLLs now that we can do localized error messages ////////////////////////////////////////////////////////////////// // Ensure that common control DLL is loaded HINSTANCE hinstCC = LoadLibraryW(L"comctl32.dll"); UT_return_val_if_fail (hinstCC, false); InitCommonControlsEx_fn pInitCommonControlsEx = NULL; if( hinstCC != NULL ) pInitCommonControlsEx = (InitCommonControlsEx_fn)GetProcAddress( hinstCC, "InitCommonControlsEx"); if( pInitCommonControlsEx != NULL ) { INITCOMMONCONTROLSEX icex; icex.dwSize = sizeof(INITCOMMONCONTROLSEX); icex.dwICC = ICC_COOL_CLASSES | ICC_BAR_CLASSES // load the rebar and toolbar | ICC_TAB_CLASSES | ICC_UPDOWN_CLASS // and tab and spin controls | ICC_STANDARD_CLASSES; pInitCommonControlsEx(&icex); } else { InitCommonControls(); UT_Win32LocaleString err; err.fromUTF8 (m_pStringSet->getValue(AP_STRING_ID_WINDOWS_COMCTL_WARNING)); MessageBoxW(NULL, err.c_str(), NULL, MB_OK); } ////////////////////////////////////////////////////////////////// // load the all Plugins from the correct directory ////////////////////////////////////////////////////////////////// #ifndef DISABLE_BUILTIN_PLUGINS abi_register_builtin_plugins(); #endif bool bLoadPlugins = true; bool bFound = getPrefsValueBool(XAP_PREF_KEY_AutoLoadPlugins,&bLoadPlugins); if(bLoadPlugins || !bFound) { WCHAR szPath[PATH_MAX]; WCHAR szPlugin[PATH_MAX]; _getExeDir( szPath, PATH_MAX); #ifdef _MSC_VER lstrcatW(szPath, L"..\\plugins\\*.dll"); #else #define ABI_WIDE_STRING(t) L ## t lstrcatW(szPath, ABI_WIDE_STRING("..\\lib\\" PACKAGE L"-" ABIWORD_SERIES L"\\plugins\\*.dll")); #endif WIN32_FIND_DATAW cfile; HANDLE findtag = FindFirstFileW( szPath, &cfile ); if( findtag != INVALID_HANDLE_VALUE ) { do { _getExeDir( szPlugin, PATH_MAX ); #ifdef _MSC_VER lstrcatW( szPlugin, L"..\\plugins\\" ); #else lstrcatW( szPlugin, ABI_WIDE_STRING("..\\lib\\" PACKAGE L"-" ABIWORD_SERIES L"\\plugins\\" )); #endif lstrcatW( szPlugin, cfile.cFileName ); XAP_ModuleManager::instance().loadModule( getUTF8String(szPlugin) ); } while( FindNextFileW ( findtag, &cfile ) ); FindClose( findtag ); } UT_String pluginName( getUserPrivateDirectory() ); UT_String pluginDir( getUserPrivateDirectory() ); pluginDir += "\\AbiWord\\plugins\\*.dll"; UT_Win32LocaleString str; str.fromUTF8(pluginDir.c_str()); findtag = FindFirstFileW( str.c_str(), &cfile ); if( findtag != INVALID_HANDLE_VALUE ) { do { pluginName = getUserPrivateDirectory(); pluginName += "\\AbiWord\\plugins\\"; pluginName += getUTF8String(cfile.cFileName); XAP_ModuleManager::instance().loadModule( pluginName.c_str() ); } while( FindNextFileW( findtag, &cfile ) ); FindClose( findtag ); } } return bSuccess; }
void XAP_Win32Slurp::stuffRegistry(const char * szSuffix, const char * szApplicationName, LPCWSTR szExePathname, const char * szContentType) { // load the system registry if there's no info // for us already present for the given suffix. // we assume that the string contains the dot. // // TODO consider raising a dialog asking if they // TODO want us to override any existing settings // TODO if they currently don't point to us. like // TODO MSFT and NSCP currently (politely) fight // TODO for the .html suffix.... // // we construct the following pattern in the registry: // // HKEY_CLASSES_ROOT\<suffix> = <foo> // HKEY_CLASSES_ROOT\<suffix>\Content Type = <content_type> // HKEY_CLASSES_ROOT\<foo> = <application_name> ## " Document" // HKEY_CLASSES_ROOT\<foo>\shell\open\command = <exe_pathname> // HKEY_CLASSES_ROOT\<foo>\shell\open\ddeexec = [Open("%1")] // HKEY_CLASSES_ROOT\<foo>\shell\open\ddeexec\application = <application_name> // HKEY_CLASSES_ROOT\<foo>\shell\open\ddeexec\topic = System // HKEY_CLASSES_ROOT\<foo>\DefaultIcon = <exe_pathname,2> #define VALUE_DDEEXEC_OPEN "[Open(\"%1\")]" #define FORMAT_OUR_INDIRECTION "AbiSuite.%s" #define CONTENT_TYPE_KEY "Content Type" #define DOCUMENT_ICON_POSITION 2 #define xx(s) ((LPBYTE)(s)),(strlen(s)+1) #define xxw(s) ((LPBYTE)(s)),((lstrlenW(s)+1)<<1) char buf[1024]; char bufOurFoo[1024]; WCHAR bufOurFooValue[1024]; WCHAR bufDefaultIconValue[1024]; DWORD dType; LONG eResult; ULONG len; bool bUpdateContentType; bool bCreateOrOverwrite = false; HKEY hKeyFoo = 0; HKEY hKeySuffix = 0; HKEY hKeyShell = 0; HKEY hKeyCommand = 0; HKEY hKeyOpen = 0; HKEY hKeyDdeExec = 0; HKEY hKeyApplication = 0; HKEY hKeyTopic = 0; HKEY hKeyDefaultIcon = 0; sprintf(bufOurFoo,"AbiSuite.%s",szApplicationName); strtok(bufOurFoo," "); // trim key at first whitespace const XAP_StringSet *pSS = XAP_App::getApp()->getStringSet(); const gchar *pStr = "%s Document"; UT_Win32LocaleString tmpl; char tdbuf[512]; sprintf(tdbuf,pStr,szApplicationName); tmpl.fromUTF8(tdbuf); wcscpy(bufOurFooValue,tmpl.c_str()); /////////////////////////////////////////////////////////////////// // See if someone has claimed this suffix. // HKEY_CLASSES_ROOT\<suffix> = <foo> /////////////////////////////////////////////////////////////////// switch ( _fetchKey(HKEY_CLASSES_ROOT,szSuffix,&hKeySuffix) ) { case X_Error: goto CleanupMess; case X_CreatedKey: // we are free to create what we want. bCreateOrOverwrite = true; break; case X_ExistingKey: // see what's already there { /////////////////////////////////////////////////////////////////// // HKEY_CLASSES_ROOT\<suffix> = <foo> // was already present. Verify the value. /////////////////////////////////////////////////////////////////// len = G_N_ELEMENTS(buf); eResult = RegQueryValueEx(hKeySuffix,NULL,NULL,&dType,(LPBYTE)buf,&len); if ((eResult != ERROR_SUCCESS) || (dType != REG_SZ) || (len==0)) break; // bogus data, overwrite it. UT_DEBUGMSG(("Registry: suffix [HKEY_CLASSES_ROOT\\%s] --> [%s]\n", szSuffix,buf)); if (g_ascii_strcasecmp(buf,bufOurFoo) != 0) // we didn't create this so ask first. { if (!_askForStealFromAnotherApplication()) goto CleanupMess; bCreateOrOverwrite = true; break; } } } if (bCreateOrOverwrite) { /////////////////////////////////////////////////////////////////// // Set the value <foo> in // HKEY_CLASSES_ROOT\<suffix> = <foo> /////////////////////////////////////////////////////////////////// UT_ASSERT(hKeySuffix); eResult = RegSetValueEx(hKeySuffix,NULL,0,REG_SZ,xx(bufOurFoo)); UT_DEBUGMSG(("Register: HKEY_CLASSES_ROOT\\%s <-- %s [error %d]\n", szSuffix,bufOurFoo,eResult)); if (eResult != ERROR_SUCCESS) goto CleanupMess; } /////////////////////////////////////////////////////////////////// // See if "HKEY_CLASSES_ROOT\<suffix>\Content Type" is present // as a value under the current key. /////////////////////////////////////////////////////////////////// bUpdateContentType = true; len = G_N_ELEMENTS(buf); eResult = RegQueryValueEx(hKeySuffix,CONTENT_TYPE_KEY,NULL,&dType,(LPBYTE)buf,&len); if ((eResult == ERROR_SUCCESS) && (dType == REG_SZ)) { UT_DEBUGMSG(("Registry: Existing ContentType [%s]\n",buf)); if (g_ascii_strcasecmp(buf,szContentType) == 0) bUpdateContentType = false; else // we didn't create this so ask first. bUpdateContentType = (_askForStealMimeFromAnotherApplication()); } if (bUpdateContentType) // bogus or stale data, overwrite it. { /////////////////////////////////////////////////////////////////// // Set the value <content_type> in // HKEY_CLASSES_ROOT\<suffix>\Content Type = <content_type> /////////////////////////////////////////////////////////////////// UT_ASSERT(hKeySuffix); eResult = RegSetValueEx(hKeySuffix,CONTENT_TYPE_KEY,0,REG_SZ,xx(szContentType)); UT_DEBUGMSG(("Register: HKEY_CLASSES_ROOT\\%s\\Content Type <-- %s [error %d]\n", szSuffix,szContentType,eResult)); // content-type is not a critical field, so if it fails we just go on. // if (eResult != ERROR_SUCCESS) goto CleanupMess; } /////////////////////////////////////////////////////////////////// // Verify that the suffix indirection is defined. // HKEY_CLASSES_ROOT\<foo> = ... /////////////////////////////////////////////////////////////////// switch ( _fetchKey(HKEY_CLASSES_ROOT,bufOurFoo,&hKeyFoo) ) { case X_Error: goto CleanupMess; case X_ExistingKey: UT_ASSERT(hKeyFoo); len = G_N_ELEMENTS(buf); eResult = RegQueryValueExW(hKeyFoo,NULL,0,&dType,(LPBYTE)buf,&len); if ((eResult==ERROR_SUCCESS) && (dType==REG_SZ) && (lstrcmpiW((LPCWSTR)buf,bufOurFooValue)==0)) break; // already has correct value, no need to overwrite. /* otherwise, replace the value */ /* fall thru intended */ case X_CreatedKey: UT_ASSERT(hKeyFoo); eResult = RegSetValueExW(hKeyFoo,NULL,0,REG_SZ,xxw(bufOurFooValue)); if (eResult != ERROR_SUCCESS) goto CleanupMess; break; } /////////////////////////////////////////////////////////////////// // Inspect the command path // HKEY_CLASSES_ROOT\<foo>\shell\open\command = <exe_pathname> /////////////////////////////////////////////////////////////////// WCHAR commandPathWithParam[1024]; wcscpy ( commandPathWithParam, szExePathname ); wcscat ( commandPathWithParam, L" \"%1\"" ); if (_fetchKey(hKeyFoo,"shell",&hKeyShell) == X_Error) goto CleanupMess; if (_fetchKey(hKeyShell,"open",&hKeyOpen) == X_Error) goto CleanupMess; switch ( _fetchKey(hKeyOpen,"command",&hKeyCommand) ) { case X_Error: goto CleanupMess; case X_ExistingKey: UT_ASSERT(hKeyCommand); len = G_N_ELEMENTS((LPWSTR)buf); eResult = RegQueryValueExW(hKeyCommand,NULL,0,&dType,(LPBYTE)buf,&len); if ((eResult==ERROR_SUCCESS) && (dType==REG_SZ)) { if (lstrcmpiW((LPCWSTR)buf,commandPathWithParam) == 0) break; // already has correct value, no need to overwrite. if(memcmp(buf, commandPathWithParam, lstrlenW(commandPathWithParam)<<1) == 0) { // Path name is the same but has extra at the end. // Probably "%1" // Fall throught to update path name. } else { if (!_askForUpdateExePathname()) goto CleanupMess; } } /* otherwise, replace the value */ /* fall thru intended */ case X_CreatedKey: UT_ASSERT(hKeyCommand); eResult = RegSetValueExW(hKeyCommand,NULL,0,REG_SZ,xxw(commandPathWithParam)); if (eResult != ERROR_SUCCESS) goto CleanupMess; break; } /////////////////////////////////////////////////////////////////// // Inspect the ddeexec key // HKEY_CLASSES_ROOT\<foo>\shell\open\ddeexec = [Open(%1)] /////////////////////////////////////////////////////////////////// switch ( _fetchKey(hKeyOpen,"ddeexec",&hKeyDdeExec) ) { case X_Error: goto CleanupMess; case X_ExistingKey: UT_ASSERT(hKeyDdeExec); len = G_N_ELEMENTS(buf); eResult = RegQueryValueEx(hKeyDdeExec,NULL,0,&dType,(LPBYTE)buf,&len); if ((eResult==ERROR_SUCCESS) && (dType==REG_SZ) && (g_ascii_strcasecmp(buf,VALUE_DDEEXEC_OPEN)==0)) break; // already has correct value, no need to overwrite. /* otherwise, replace the value */ /* fall thru intended */ case X_CreatedKey: UT_ASSERT(hKeyDdeExec); eResult = RegSetValueEx(hKeyDdeExec,NULL,0,REG_SZ,xx(VALUE_DDEEXEC_OPEN)); if (eResult != ERROR_SUCCESS) goto CleanupMess; break; } /////////////////////////////////////////////////////////////////// // Inspect the application key // HKEY_CLASSES_ROOT\<foo>\shell\open\ddeexec\application = <application_name> /////////////////////////////////////////////////////////////////// switch ( _fetchKey(hKeyDdeExec,"application",&hKeyApplication) ) { case X_Error: goto CleanupMess; case X_ExistingKey: UT_ASSERT(hKeyApplication); len = G_N_ELEMENTS(buf); eResult = RegQueryValueEx(hKeyApplication,NULL,0,&dType,(LPBYTE)buf,&len); if ((eResult==ERROR_SUCCESS) && (dType==REG_SZ) && (g_ascii_strcasecmp(buf,szApplicationName)==0)) break; // already has correct value, no need to overwrite. /* otherwise, replace the value */ /* fall thru intended */ case X_CreatedKey: UT_ASSERT(hKeyApplication); eResult = RegSetValueEx(hKeyApplication,NULL,0,REG_SZ,xx(szApplicationName)); if (eResult != ERROR_SUCCESS) goto CleanupMess; break; } /////////////////////////////////////////////////////////////////// // Inspect the topic key // HKEY_CLASSES_ROOT\<foo>\shell\open\ddeexec\topic = System /////////////////////////////////////////////////////////////////// switch ( _fetchKey(hKeyDdeExec,"topic",&hKeyTopic) ) { case X_Error: goto CleanupMess; case X_ExistingKey: UT_ASSERT(hKeyTopic); len = G_N_ELEMENTS((LPWSTR)buf); eResult = RegQueryValueExW(hKeyTopic,NULL,0,&dType,(LPBYTE)buf,&len); if ((eResult==ERROR_SUCCESS) && (dType==REG_SZ) && (wcsicmp((LPWSTR)buf,MY_DDE_TOPICNAME)==0)) break; // already has correct value, no need to overwrite. /* otherwise, replace the value */ /* fall thru intended */ case X_CreatedKey: UT_ASSERT(hKeyTopic); eResult = RegSetValueExW(hKeyTopic,NULL,0,REG_SZ,xxw(MY_DDE_TOPICNAME)); if (eResult != ERROR_SUCCESS) goto CleanupMess; break; } /////////////////////////////////////////////////////////////////// // Set the default icon for the suffix (this is for Explorer et al. // HKEY_CLASSES_ROOT\<foo>\DefaultIcon = <exe_pathname,2> /////////////////////////////////////////////////////////////////// wsprintfW(bufDefaultIconValue,L"%s,%d",szExePathname,DOCUMENT_ICON_POSITION); switch ( _fetchKey(hKeyFoo,"DefaultIcon",&hKeyDefaultIcon) ) { case X_Error: goto CleanupMess; case X_ExistingKey: UT_ASSERT(hKeyDefaultIcon); len = G_N_ELEMENTS((LPWSTR)buf); eResult = RegQueryValueExW(hKeyDefaultIcon,NULL,0,&dType,(LPBYTE)buf,&len); if ((eResult==ERROR_SUCCESS) && (dType==REG_SZ) && (lstrcmpiW((LPWSTR)buf,bufDefaultIconValue)==0)) break; // already has correct value, no need to overwrite. /* otherwise, replace the value */ /* fall thru intended */ case X_CreatedKey: UT_ASSERT(hKeyDefaultIcon); eResult = RegSetValueExW(hKeyDefaultIcon,NULL,0,REG_SZ,xxw(bufDefaultIconValue)); if (eResult != ERROR_SUCCESS) goto CleanupMess; break; } /////////////////////////////////////////////////////////////////// // Success. /////////////////////////////////////////////////////////////////// UT_DEBUGMSG(("Successfully stuffed the registry for suffix [%s].\n",szSuffix)); CleanupMess: #define KILLKEY(k) do { if (k) RegCloseKey(k); (k) = 0; } while (0) KILLKEY(hKeyFoo); KILLKEY(hKeySuffix); KILLKEY(hKeyShell); KILLKEY(hKeyCommand); KILLKEY(hKeyOpen); KILLKEY(hKeyDdeExec); KILLKEY(hKeyApplication); KILLKEY(hKeyTopic); KILLKEY(hKeyDefaultIcon); return; }