| 1 |
/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ |
| 2 |
|
| 3 |
/* AbiSource Application Framework |
| 4 |
* Copyright (C) 1998 AbiSource, Inc. |
| 5 |
* Copyright (C) 2009 Hubert Figuiere |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU General Public License |
| 9 |
* as published by the Free Software Foundation; either version 2 |
| 10 |
* of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* |
| 17 |
* You should have received a copy of the GNU General Public License |
| 18 |
* along with this program; if not, write to the Free Software |
| 19 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 20 |
* 02110-1301 USA. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifndef XAP_DIALOG_FONTCHOOSER_H |
| 24 |
#define XAP_DIALOG_FONTCHOOSER_H |
| 25 |
|
| 26 |
/* pre-emptive dismissal; ut_types.h is needed by just about everything, |
| 27 |
* so even if it's commented out in-file that's still a lot of work for |
| 28 |
* the preprocessor to do... |
| 29 |
*/ |
| 30 |
#ifndef UT_TYPES_H |
| 31 |
#include "ut_types.h" |
| 32 |
#endif |
| 33 |
|
| 34 |
#include <map> |
| 35 |
#include <string> |
| 36 |
#include <vector> |
| 37 |
|
| 38 |
#include "ut_string.h" |
| 39 |
|
| 40 |
#include "xap_Dialog.h" |
| 41 |
#include "xap_Preview.h" |
| 42 |
#include "gr_Graphics.h" |
| 43 |
|
| 44 |
class GR_Graphics; |
| 45 |
class XAP_Preview_FontPreview; //forward, see below |
| 46 |
|
| 47 |
/*****************************************************************/ |
| 48 |
|
| 49 |
class ABI_EXPORT XAP_Dialog_FontChooser : public XAP_Dialog_NonPersistent |
| 50 |
{ |
| 51 |
public: |
| 52 |
typedef std::map<std::string,std::string> PropMap; |
| 53 |
|
| 54 |
XAP_Dialog_FontChooser(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id); |
| 55 |
virtual ~XAP_Dialog_FontChooser(void); |
| 56 |
|
| 57 |
virtual void runModal(XAP_Frame * pFrame) = 0; |
| 58 |
|
| 59 |
typedef enum { a_OK, a_CANCEL, a_YES, a_NO } tAnswer; |
| 60 |
|
| 61 |
void setDrawString (const UT_UCSChar * str); |
| 62 |
|
| 63 |
const UT_UCSChar * getDrawString () const |
| 64 |
{ |
| 65 |
return m_drawString; |
| 66 |
} |
| 67 |
|
| 68 |
void addOrReplaceVecProp(const std::string & pszProp, |
| 69 |
const std::string & pszVal); |
| 70 |
void event_previewExposed(const UT_UCSChar * pszChars); |
| 71 |
void event_previewClear(void); |
| 72 |
std::string getVal(const std::string & sProp) const; |
| 73 |
void setAllPropsFromVec(const std::vector<std::string> & vProps); |
| 74 |
|
| 75 |
void setGraphicsContext(GR_Graphics * pGraphics); |
| 76 |
void setFontFamily(const std::string& sFontFamily); |
| 77 |
void setFontSize(const std::string& sFontSize); |
| 78 |
void setFontWeight(const std::string& sFontWeight); |
| 79 |
void setFontStyle(const std::string& sFontStyle); |
| 80 |
void setColor(const std::string& sColor); |
| 81 |
void setBGColor(const std::string& sBGColor); |
| 82 |
void setFontDecoration(bool bUnderline, bool bOverline, bool bStrikeOut, bool bTopline, bool bBottomline); |
| 83 |
void setHidden(bool bHidden); |
| 84 |
void setSuperScript(bool bSuperScript); |
| 85 |
void setSubScript(bool bSubScript); |
| 86 |
void setBackGroundColor (const gchar * pBackGroundColor); |
| 87 |
void setTextTransform (const std::string& pTextTransform); |
| 88 |
|
| 89 |
XAP_Dialog_FontChooser::tAnswer getAnswer(void) const; |
| 90 |
|
| 91 |
// the following return TRUE iff the user changed the value |
| 92 |
// of the control in the dialog. they also return the value |
| 93 |
// of the field in the supplied argument w/o regard to whether |
| 94 |
// they changed it or not. this value is a static string in |
| 95 |
// the dialog and must be valid only until the dialog is released. |
| 96 |
bool didPropChange(const std::string & v1, const std::string & v2) const; |
| 97 |
bool getChangedTextTransform(std::string&) const; |
| 98 |
bool getChangedFontFamily(std::string&) const; |
| 99 |
bool getChangedFontSize(std::string&) const; |
| 100 |
bool getChangedFontWeight(std::string&) const; |
| 101 |
bool getChangedFontStyle(std::string&) const; |
| 102 |
bool getChangedColor(std::string&) const; |
| 103 |
bool getChangedBGColor(std::string&) const; |
| 104 |
bool getChangedUnderline(bool * pbUnderline) const; |
| 105 |
bool getChangedOverline(bool * pbOverline) const; |
| 106 |
bool getChangedStrikeOut(bool * pbStrikeOut) const; |
| 107 |
bool getChangedTopline(bool * pbTopline) const; |
| 108 |
bool getChangedBottomline(bool * pbBottomline) const; |
| 109 |
bool getChangedHidden(bool * pbHidden) const; |
| 110 |
bool getChangedSuperScript(bool * pbSuperScript) const; |
| 111 |
bool getChangedSubScript(bool * pbSubScript) const; |
| 112 |
|
| 113 |
protected: |
| 114 |
void _createFontPreviewFromGC(GR_Graphics * gc, |
| 115 |
UT_uint32 width, |
| 116 |
UT_uint32 height); |
| 117 |
|
| 118 |
XAP_Dialog_FontChooser::tAnswer m_answer; |
| 119 |
GR_Graphics * m_pGraphics; /* input */ |
| 120 |
std::string m_sColorBackground; |
| 121 |
std::string m_sFontFamily; /* input/output */ |
| 122 |
std::string m_sFontSize; /* input/output */ |
| 123 |
std::string m_sFontWeight; /* input/output */ |
| 124 |
std::string m_sFontStyle; /* input/output */ |
| 125 |
std::string m_sColor; /* input/output */ |
| 126 |
std::string m_sBGColor; /* input/output */ |
| 127 |
bool m_bUnderline; /* input/output */ |
| 128 |
bool m_bOverline; /* input/output */ |
| 129 |
bool m_bStrikeout; /* input/output */ |
| 130 |
bool m_bTopline; /* input/output */ |
| 131 |
bool m_bBottomline; /* input/output */ |
| 132 |
bool m_bHidden; /* input/output */ |
| 133 |
bool m_bSuperScript; /* input/output */ |
| 134 |
bool m_bSubScript; /* input/output */ |
| 135 |
std::string m_sTextTransform; /* input/output */ |
| 136 |
|
| 137 |
PropMap m_mapProps; // Holds the current |
| 138 |
XAP_Preview_FontPreview * m_pFontPreview; |
| 139 |
|
| 140 |
bool m_bChangedFontFamily; /* output */ |
| 141 |
bool m_bChangedFontSize; /* output */ |
| 142 |
bool m_bChangedFontWeight; /* output */ |
| 143 |
bool m_bChangedFontStyle; /* output */ |
| 144 |
bool m_bChangedColor; /* output */ |
| 145 |
bool m_bChangedBGColor; /* output */ |
| 146 |
bool m_bChangedUnderline; /* output */ |
| 147 |
bool m_bChangedOverline; /* output */ |
| 148 |
bool m_bChangedStrikeOut; /* output */ |
| 149 |
bool m_bChangedTopline; /* output */ |
| 150 |
bool m_bChangedBottomline; /* output */ |
| 151 |
bool m_bChangedHidden; /* output */ |
| 152 |
bool m_bChangedSuperScript; /* output */ |
| 153 |
bool m_bChangedSubScript; /* output */ |
| 154 |
bool m_bChangedTextTransform; /* output */ |
| 155 |
|
| 156 |
UT_UCSChar * m_drawString; |
| 157 |
}; |
| 158 |
|
| 159 |
class ABI_EXPORT XAP_Preview_FontPreview : public XAP_Preview |
| 160 |
{ |
| 161 |
public: |
| 162 |
explicit XAP_Preview_FontPreview(GR_Graphics * gc, const gchar * pszClrBackgound); |
| 163 |
virtual ~XAP_Preview_FontPreview(void); |
| 164 |
void setVecProperties( const XAP_Dialog_FontChooser::PropMap * vFontProps); |
| 165 |
std::string getVal(const std::string &) const; |
| 166 |
void draw(const UT_Rect *clip=NULL); |
| 167 |
void setDrawString( const UT_UCSChar * pszChars) {m_pszChars = pszChars;} |
| 168 |
void clearScreen(void); |
| 169 |
|
| 170 |
|
| 171 |
protected: |
| 172 |
const XAP_Dialog_FontChooser::PropMap * m_mapProps; |
| 173 |
UT_RGBColor m_clrBackground; |
| 174 |
const UT_UCSChar * m_pszChars; |
| 175 |
|
| 176 |
private: |
| 177 |
|
| 178 |
XAP_Preview_FontPreview(); |
| 179 |
XAP_Preview_FontPreview(const XAP_Preview_FontPreview &other); |
| 180 |
XAP_Preview_FontPreview& operator=(const XAP_Preview_FontPreview & other); |
| 181 |
|
| 182 |
GR_Font * m_pFont; |
| 183 |
|
| 184 |
UT_sint32 m_iAscent; |
| 185 |
UT_sint32 m_iDescent; |
| 186 |
UT_sint32 m_iHeight; |
| 187 |
}; |
| 188 |
|
| 189 |
#endif /* XAP_DIALOG_FONTCHOOSER_H */ |