linuxdcpp-team team mailing list archive
-
linuxdcpp-team team
-
Mailing list archive
-
Message #02014
[Branch ~dcplusplus-team/dcplusplus/trunk] Rev 2248: Customize the font selection dialog, save the charset
------------------------------------------------------------
revno: 2248
committer: poy <poy@xxxxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-09-28 23:29:06 +0200
message:
Customize the font selection dialog, save the charset
modified:
changelog.txt
dwt/include/dwt/Rectangle.h
dwt/include/dwt/widgets/FontDialog.h
dwt/src/Rectangle.cpp
dwt/src/widgets/FontDialog.cpp
win32/Appearance2Page.cpp
win32/WinUtil.cpp
--
lp:dcplusplus
https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk
Your team Dcplusplus-team is subscribed to branch lp:dcplusplus.
To unsubscribe from this branch go to https://code.launchpad.net/~dcplusplus-team/dcplusplus/trunk/+edit-subscription
=== modified file 'changelog.txt'
--- changelog.txt 2010-09-21 20:28:03 +0000
+++ changelog.txt 2010-09-28 21:29:06 +0000
@@ -9,8 +9,6 @@
* [L#606435] Prevent potential re-hashing (thanks vasily.n)
* Automatic incoming connection type detection - enabled by default (emtee)
* Add "Close all hubs" to Window menu (emtee)
-* Use boost's locking mechanisms (arnetheduck)
-* Use boost's timing functions (arnetheduck)
* New icons
* Update the links in the "Help" menu (poy)
* Prevent current-directory Windows DLL injection (cologic)
@@ -20,6 +18,7 @@
* [L#617517] More portable critical sections (thanks big muscle)
* Removed stlport support (probably defunct by now...)
* Modernize the installer and make it translatable (poy)
+* Customize the font selection dialog, save the charset (poy)
-- 0.770 2010-07-05 --
* [L#550300] Catch more potential file corruptions (thanks bigmuscle)
=== modified file 'dwt/include/dwt/Rectangle.h'
--- dwt/include/dwt/Rectangle.h 2010-02-11 21:44:13 +0000
+++ dwt/include/dwt/Rectangle.h 2010-09-28 21:29:06 +0000
@@ -125,7 +125,7 @@
* shrink( long border ) is similar, but removes a constant border amount of
* pixels on all sides.
*/
- Rectangle shrink( double factor ) const;
+ Rectangle shrinkFactor( double factor ) const;
/// Move inwards by xBorder and shrink the size by 2*xBorder
/** A rectangle of #### changes to ##.<br>
=== modified file 'dwt/include/dwt/widgets/FontDialog.h'
--- dwt/include/dwt/widgets/FontDialog.h 2010-02-11 21:44:13 +0000
+++ dwt/include/dwt/widgets/FontDialog.h 2010-09-28 21:29:06 +0000
@@ -41,51 +41,39 @@
namespace dwt {
-/// ChooseFontDialog class
-/** \ingroup WidgetControls
- * \image html choosefont.PNG
- * Class for showing a common ChooseFontDialog box. <br>
- * Either derive from it or call WidgetFactory::createChooseFont. <br>
- * Note! <br>
- * If you wish to use this class with Parent classes other than those from SmartWin
- * you need to expose a public function called "parent" taking no arguments returning
- * an HWND on the template parameter class. <br>
- * the complete signature of the function will then be "HWND parent()"
- */
class FontDialog
{
public:
- /// Class type
- typedef FontDialog ThisType;
-
- /// Object type
- /** Note, not a pointer!!!!
- */
- typedef ThisType ObjectType;
-
- /// Shows the dialog
- bool open(DWORD dwFlags, LOGFONT& font, DWORD& rgbColors);
-
/// Constructor Taking pointer to parent
- explicit FontDialog( Widget* parent = 0 );
-
- ~FontDialog() { }
+ explicit FontDialog(Widget* parent = 0);
+
+ struct Options {
+ bool strikeout; /// if false, the "Strikeout" check-box will be hidden
+ bool underline; /// if false, the "Underline" check-box will be hidden
+
+ bool customBgColor;
+ COLORREF bgColor;
+
+ Options() : strikeout(true), underline(true), customBgColor(false) { }
+ void setBgColor(COLORREF color) { customBgColor = true; bgColor = color; }
+ };
+
+ /** Shows the dialog
+ * @param font initial and returned font (only changed if the user presses OK)
+ * @param color initial and returned color (only changed if the user presses OK)
+ * @param flags additional flags besides those that dwt automatically adds (see the CHOOSEFONT doc)
+ * @return whether the user pressed OK
+ */
+ bool open(LOGFONT& font, DWORD& color, Options* options = 0, DWORD flags = 0);
private:
Widget* itsParent;
- HWND getParentHandle() { return itsParent ? itsParent->handle() : NULL; }
+ HWND getParentHandle() const { return itsParent ? itsParent->handle() : NULL; }
+
+ static UINT_PTR CALLBACK CFHookProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
};
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-// Implementation of class
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
-inline FontDialog::FontDialog( Widget * parent )
- : itsParent( parent )
-{
-}
-
}
#endif
=== modified file 'dwt/src/Rectangle.cpp'
--- dwt/src/Rectangle.cpp 2010-02-11 21:44:13 +0000
+++ dwt/src/Rectangle.cpp 2010-09-28 21:29:06 +0000
@@ -57,7 +57,7 @@
// Size of the rectangle will be * factor.
// Position adjusted for the same center.
-Rectangle Rectangle::shrink( double factor ) const
+Rectangle Rectangle::shrinkFactor( double factor ) const
{
double posFactor = ( 1.0 - factor ) * 0.5;
return subRect( posFactor, posFactor, factor, factor );
=== modified file 'dwt/src/widgets/FontDialog.cpp'
--- dwt/src/widgets/FontDialog.cpp 2010-02-11 21:44:13 +0000
+++ dwt/src/widgets/FontDialog.cpp 2010-09-28 21:29:06 +0000
@@ -31,21 +31,114 @@
#include <dwt/widgets/FontDialog.h>
+#include <dlgs.h>
+#include <dwt/CanvasClasses.h>
+#include <dwt/resources/Brush.h>
+#include <dwt/util/win32/ApiHelpers.h>
+
namespace dwt {
-bool FontDialog::open(DWORD dwFlags, LOGFONT& font, DWORD& rgbColors)
+FontDialog::FontDialog(Widget* parent) :
+itsParent(parent)
{
+}
+
+UINT_PTR CALLBACK FontDialog::CFHookProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
+ switch(msg) {
+ case WM_INITDIALOG:
+ {
+ /* this may seem like hacking around the resources of a dialog we don't own, but it is
+ actually quite legit as the resources for the font dialog have officially been
+ published (see Font.dlg in the MS SDK). */
+
+ Options& options = *reinterpret_cast<Options*>(reinterpret_cast<LPCHOOSEFONT>(lParam)->lCustData);
+
+ if(!options.strikeout) {
+ // remove the "Strikeout" box
+ HWND box = ::GetDlgItem(hwnd, chx1);
+ ::EnableWindow(box, FALSE);
+ ::ShowWindow(box, SW_HIDE);
+ }
+
+ if(!options.underline) {
+ // remove the "Underline" box
+ HWND box = ::GetDlgItem(hwnd, chx2);
+ ::EnableWindow(box, FALSE);
+ ::ShowWindow(box, SW_HIDE);
+ }
+
+ if(options.customBgColor) {
+ ::SetProp(hwnd, _T("bgColor"), &options.bgColor);
+ }
+
+ break;
+ }
+
+ case WM_PAINT:
+ {
+ HANDLE prop = ::GetProp(hwnd, _T("bgColor"));
+ if(!prop)
+ break;
+
+ /* instead of creating a standard control to show the preview, Windows chooses to
+ catch WM_PAINT and paint at the position of the preview control, which is actually
+ hidden. our only solution to paint a background is therefore to reproduce that painting
+ by ourselves. thanks to Wine (dlls/comdlg32/fontdlg.c) for showing how this is done. */
+
+ PaintCanvas canvas(hwnd);
+ bool oldMode = canvas.setBkMode(true);
+
+ HWND box = ::GetDlgItem(hwnd, stc5);
+
+ ::RECT rc;
+ ::GetClientRect(box, &rc);
+ ::MapWindowPoints(box, hwnd, reinterpret_cast<LPPOINT>(&rc), 2);
+ Rectangle rect(rc);
+
+ canvas.fill(rect, Brush(*reinterpret_cast<COLORREF*>(prop)));
+
+ HWND colorCombo = ::GetDlgItem(hwnd, cmb4);
+ int i = ComboBox_GetCurSel(colorCombo);
+ if(i != CB_ERR)
+ canvas.setTextColor(ComboBox_GetItemData(colorCombo, i));
+
+ LOGFONT logFont;
+ ::SendMessage(hwnd, WM_CHOOSEFONT_GETLOGFONT, 0, reinterpret_cast<LPARAM>(&logFont));
+ Font font(::CreateFontIndirect(&logFont), true);
+ Canvas::Selector select(canvas, font);
+
+ canvas.drawText(util::win32::getWindowText(box), rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
+
+ canvas.setBkMode(oldMode);
+ return 1;
+ }
+
+ case WM_DESTROY:
+ {
+ ::RemoveProp(hwnd, _T("bgColor"));
+ break;
+ }
+ }
+ return 0;
+}
+
+bool FontDialog::open(LOGFONT& font, DWORD& color, Options* options, DWORD flags) {
CHOOSEFONT cf = { sizeof(CHOOSEFONT) };
- // Initialize CHOOSEFONT
cf.hwndOwner = getParentHandle();
- cf.Flags = dwFlags | CF_INITTOLOGFONTSTRUCT;
- cf.lpLogFont = &font;
- cf.rgbColors = rgbColors;
+ cf.Flags = CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT | CF_EFFECTS | flags;
+ LOGFONT font_ = font;
+ cf.lpLogFont = &font_;
+ cf.rgbColors = color;
+ if(options) {
+ cf.Flags |= CF_ENABLEHOOK;
+ cf.lCustData = reinterpret_cast<LPARAM>(options);
+ cf.lpfnHook = CFHookProc;
+ }
- if ( ::ChooseFont( & cf ) )
- {
- rgbColors = cf.rgbColors;
+ if(::ChooseFont(&cf)) {
+ font = *cf.lpLogFont;
+ color = cf.rgbColors;
return true;
}
return false;
=== modified file 'win32/Appearance2Page.cpp'
--- win32/Appearance2Page.cpp 2010-07-10 14:36:48 +0000
+++ win32/Appearance2Page.cpp 2010-09-28 21:29:06 +0000
@@ -169,11 +169,11 @@
}
void Appearance2Page::handleTextClicked() {
- LOGFONT logFont_ = logFont;
- DWORD fg_ = fg;
- if(FontDialog(this).open(CF_EFFECTS | CF_SCREENFONTS, logFont_, fg_)) {
- logFont = logFont_;
- fg = fg_;
+ FontDialog::Options options;
+ options.strikeout = false;
+ options.underline = false;
+ options.setBgColor(bg);
+ if(FontDialog(this).open(logFont, fg, &options)) {
font = dwt::FontPtr(new dwt::Font(::CreateFontIndirect(&logFont), true));
example->setColor(fg, bg);
example->setFont(font);
=== modified file 'win32/WinUtil.cpp'
--- win32/WinUtil.cpp 2010-08-29 13:02:34 +0000
+++ win32/WinUtil.cpp 2010-09-28 21:29:06 +0000
@@ -100,7 +100,7 @@
bgBrush = dwt::BrushPtr(new dwt::Brush(bgColor));
LOGFONT lf;
- ::GetObject((HFONT) GetStockObject(DEFAULT_GUI_FONT), sizeof(lf), &lf);
+ ::GetObject(reinterpret_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT)), sizeof(lf), &lf);
SettingsManager::getInstance()->setDefault(SettingsManager::TEXT_FONT, Text::fromT(encodeFont(lf)));
decodeFont(Text::toT(SETTING(TEXT_FONT)), lf);
@@ -289,6 +289,8 @@
res += Text::toT(Util::toString(font.lfWeight));
res += _T(',');
res += Text::toT(Util::toString(font.lfItalic));
+ res += _T(',');
+ res += Text::toT(Util::toString(font.lfCharSet));
return res;
}
@@ -306,13 +308,16 @@
StringTokenizer<tstring> st(setting, _T(','));
TStringList &sl = st.getTokens();
- ::GetObject((HFONT) GetStockObject(DEFAULT_GUI_FONT), sizeof(dest), &dest);
+ ::GetObject(reinterpret_cast<HFONT>(::GetStockObject(DEFAULT_GUI_FONT)), sizeof(dest), &dest);
tstring face;
- if(sl.size() == 4) {
+ if(sl.size() >= 4) {
face = sl[0];
dest.lfHeight = Util::toInt(Text::fromT(sl[1]));
dest.lfWeight = Util::toInt(Text::fromT(sl[2]));
- dest.lfItalic = (BYTE) Util::toInt(Text::fromT(sl[3]));
+ dest.lfItalic = static_cast<BYTE>(Util::toInt(Text::fromT(sl[3])));
+ if(sl.size() >= 5) {
+ dest.lfCharSet = static_cast<BYTE>(Util::toInt(Text::fromT(sl[4])));
+ }
}
if(!face.empty()) {