1 /* AbiSource Application Framework
2 * Copyright (C) 1998 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23
24 #include "ut_assert.h"
25 #include "ut_string.h"
26 #include "ut_debugmsg.h"
27
28 #include "gr_Graphics.h"
29
30 #include "xap_Dlg_Insert_Symbol.h"
31 #include "xap_Dialog_Id.h"
32 #include "xap_DialogFactory.h"
33 #include "xap_Dlg_MessageBox.h"
34 #include "xap_Draw_Symbol.h"
35 #include "xap_App.h"
36 #include "xap_Frame.h"
37
XAP_Dialog_Insert_Symbol(XAP_DialogFactory * pDlgFactory,XAP_Dialog_Id id)38 XAP_Dialog_Insert_Symbol::XAP_Dialog_Insert_Symbol(XAP_DialogFactory * pDlgFactory, XAP_Dialog_Id id)
39 : XAP_Dialog_Modeless(pDlgFactory,id, "interface/dialogsymbol")
40 {
41 m_Inserted_Symbol = ' ';
42 m_answer = a_CANCEL;
43 m_DrawSymbol = NULL;
44 m_pListener = NULL;
45 // m_pDialog = (XAP_Dialog_Insert_Symbol *) this;
46 }
~XAP_Dialog_Insert_Symbol(void)47 XAP_Dialog_Insert_Symbol::~XAP_Dialog_Insert_Symbol(void)
48 {
49 DELETEP(m_DrawSymbol);
50 UT_ASSERT(!m_bInUse);
51 }
52
useStart(void)53 void XAP_Dialog_Insert_Symbol::useStart(void)
54 {
55 // XAP_Dialog_AppPersistent::useStart();
56 }
57
useEnd(void)58 void XAP_Dialog_Insert_Symbol::useEnd(void)
59 {
60 // XAP_Dialog_AppPersistent::useEnd();
61 }
62
63
getInsertedSymbol(void)64 UT_UCSChar XAP_Dialog_Insert_Symbol::getInsertedSymbol(void)
65 {
66 return m_Inserted_Symbol;
67 }
68
69
getInsertedFont(void)70 char * XAP_Dialog_Insert_Symbol::getInsertedFont(void)
71 {
72 UT_return_val_if_fail(m_DrawSymbol, NULL);
73 strncpy(m_FontName, m_DrawSymbol->getSelectedFont(), sizeof(m_FontName)-1);
74 m_FontName[sizeof(m_FontName)-1] = '\0';
75
76 return m_FontName;
77 }
78
getAnswer(void) const79 XAP_Dialog_Insert_Symbol::tAnswer XAP_Dialog_Insert_Symbol::getAnswer(void) const
80 {
81 // let our caller know if user hit ok, cancel, etc.
82 return m_answer;
83 }
84
85
86 /************************************************************************/
87
_updateDrawSymbol()88 void XAP_Dialog_Insert_Symbol::_updateDrawSymbol()
89 {
90 m_DrawSymbol->draw();
91 }
92
_createSymbolFromGC(GR_Graphics * gc,UT_uint32 width,UT_uint32 height)93 void XAP_Dialog_Insert_Symbol::_createSymbolFromGC(GR_Graphics * gc,
94 UT_uint32 width, UT_uint32 height)
95 {
96 UT_ASSERT(gc);
97 DELETEP(m_DrawSymbol);
98 m_DrawSymbol = new XAP_Draw_Symbol(gc);
99 UT_ASSERT(m_DrawSymbol);
100 m_DrawSymbol->setWindowSize(width, height);
101 }
102
_getCurrentSymbolMap(void)103 XAP_Draw_Symbol * XAP_Dialog_Insert_Symbol::_getCurrentSymbolMap( void)
104 {
105 return m_DrawSymbol;
106 }
107
108 /************************************************************************/
109
_updateDrawSymbolarea(UT_UCSChar c,UT_UCSChar p)110 void XAP_Dialog_Insert_Symbol::_updateDrawSymbolarea(UT_UCSChar c, UT_UCSChar p)
111 {
112 m_DrawSymbol->drawarea(c,p);
113 }
114
_createSymbolareaFromGC(GR_Graphics * gc,UT_uint32 width,UT_uint32 height)115 void XAP_Dialog_Insert_Symbol::_createSymbolareaFromGC(GR_Graphics * gc,
116 UT_uint32 width, UT_uint32 height)
117 {
118 UT_ASSERT(gc);
119 UT_ASSERT(m_DrawSymbol);
120 m_DrawSymbol->setAreaGc(gc);
121 m_DrawSymbol->setAreaSize(width, height);
122 }
123
124
_onInsertButton()125 void XAP_Dialog_Insert_Symbol::_onInsertButton()
126 {
127 // get the character to be inserted
128 UT_UCSChar c = getInsertedSymbol();
129 // get the font of the symbol to be inserted
130 gchar * symfont = (gchar *) getInsertedFont();
131 // do the actual insert
132 _insert(c, const_cast<const gchar*>(symfont));
133 }
134
_insert(UT_UCSChar c,const char * symfont)135 void XAP_Dialog_Insert_Symbol::_insert(UT_UCSChar c, const char* symfont)
136 {
137 UT_return_if_fail(m_pListener);
138 UT_ASSERT(symfont);
139 if (c == 0x00)
140 {
141 // Pango certainly doesn't like shaping 0x00 characters (it crashes when trying),
142 // and I'm not sure if other font renderers do. Since it doesn't really make
143 // any sense to allow such characters in the first place, let's just drop
144 // it on the floor. - MARCM
145 UT_DEBUGMSG(("Dropping 0x00 character on the floor\n"));
146 return;
147 }
148
149 // connect to the current active frame using the robust getActiveFrame
150 m_pListener->setView(getActiveFrame()->getCurrentView());
151
152 UT_DEBUGMSG(("Insert Char %x \n",c));
153 m_pListener->insertSymbol(c, symfont);
154 }
155
setActiveFrame(XAP_Frame * pFrame)156 void XAP_Dialog_Insert_Symbol::setActiveFrame(XAP_Frame *pFrame)
157 {
158
159 m_pListener->setView( pFrame->getCurrentView() );
160
161 // Update the platform code of this change in frame
162
163 notifyActiveFrame(pFrame);
164 }
165
166
ConstructWindowName()167 void XAP_Dialog_Insert_Symbol::ConstructWindowName()
168 {
169 const XAP_StringSet * pSS = m_pApp->getStringSet();
170 gchar * tmp = NULL;
171 std::string sTitle;
172 pSS->getValueUTF8(XAP_STRING_ID_DLG_Insert_SymbolTitle,sTitle);
173
174 UT_XML_cloneNoAmpersands(tmp, sTitle.c_str());
175 BuildWindowName((char *) m_WindowName,(char*)tmp,sizeof(m_WindowName));
176 FREEP(tmp);
177 }
178
179
180
181
182
183
184
185
186
187
188