SOL9 2.0 Class: FontDialog

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * FontDialog.h 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL++2000
// 2000.02.18
#pragma once

#include <sol\CommonDialog.h>
#include <sol\Font.h>


namespace SOL {

class FontDialog :public CommonDialog {
private:
    LOGFONT        lf;
  
private:
    CHOOSEFONT cf;


public:
    FontDialog():CommonDialog() { }

public:
    FontDialog(View* parent, const TCHAR* name, Args& args)
    :CommonDialog(parent, &cf)
    {
        memset(&cf, 0, sizeof(CHOOSEFONT));
        cf . lStructSize = sizeof(CHOOSEFONT);
        cf . lpLogFont = &lf;
        cf . Flags     = CF_SCREENFONTS|CF_EFFECTS;
        cf . nFontType = SCREEN_FONTTYPE;

        if(parent) {
            cf . hwndOwner = parent -> getWindow();
        }

        cf . hInstance = GetModuleHandle(NULL);//Application::getInstance();

        setValues(args);
    }

public:
    Boolean create(View* parent, const TCHAR* name, Args& args)
    {
        Boolean rc = CommonDialog::create(parent, &cf);

        memset(&cf, 0, sizeof(CHOOSEFONT));
        cf . lStructSize = sizeof(CHOOSEFONT);
        cf . lpLogFont = &lf;
        cf . Flags     = CF_SCREENFONTS|CF_EFFECTS;
        cf . nFontType = SCREEN_FONTTYPE;

        if(parent) {
            cf . hwndOwner = parent -> getWindow();
        }

        cf . hInstance = GetModuleHandle(NULL);//Application::getInstance();

        setValues(args);

        return rc;
    }


public:
    ~FontDialog() 
    {
    }

public:
    void getValues(Args& args)
    {
        ulong* val = NULL;
        int num   = args.getCount();
        Arg* arg  = args.getArgList();

        for (int i = 0; i<num; i++) {
            const TCHAR* name = arg[i].name;
            // <modified date="2000.01.09">
            val = (ulong*)arg[i].value;
            //</modified>

            if (name == XmNflags) {
                *val = (ulong)cf.Flags;
                continue;
            }
            if (name == XmNtype) {
                *val = (ulong)cf . nFontType;
                continue;
            }
            if (name == XmNminimum) {
                *val = (ulong)cf . nSizeMin;
                continue;
            }
            if (name == XmNmaximum) {
                *val = (ulong)cf . nSizeMax;
                continue;
            }
            if (name == XmNlogicalFont) {
                *val = (ulong)cf . lpLogFont;
                continue;
            }
        }
    }


public:
    void setValues(Args& args)
    {
        ulong val;
        if (args.get(XmNdc, &val)) {
            cf . Flags |= CF_PRINTERFONTS;
            cf . nFontType |= PRINTER_FONTTYPE;
            cf . hDC = (HDC)val;
        }
        if (args.get(XmNhook, &val)) {
            cf . Flags |= CF_ENABLEHOOK;
            cf . lpfnHook = (HOOKFUN)hookProc;
        }
        if (args.get(XmNflags, &val)) {
            cf .Flags |= (DWORD)val;
        }
        if (args.get(XmNtype, &val)) {
            cf . nFontType = (UINT)val;
        }
        if (args.get(XmNtemplateName, &val)) {
            cf . Flags |= CF_ENABLETEMPLATE;
            cf . lpTemplateName  = (TCHAR*)val;
        }
        if (args.get(XmNminimum, &val)) {
            cf . nSizeMin = (int)val;
        }
        if (args.get(XmNmaximum, &val)) {
            cf . nSizeMax = (int)val;
        }
    }

public:
    int choose()
    {
        return ::ChooseFont(&cf);
    }

public:
// Modal popup
    void popup(Action& action)
    {
        int result = choose();
    
        action.setResult(result);
    }

public:
    LOGFONT getLogicalFont() {
            return lf;
    }

public:
    Font*    getFont() {
            return new Font(&lf);
    }

//    void    getValues(Args& args);
//    void    setValues(Args& args);

//    void    popup(Action& action);
};

}



Last modified: 1 Feb 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.