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; }
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. } }
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(); }
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); }
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. } }
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; }
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. } }