| 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 |
#ifdef HAVE_CONFIG_H |
| 24 |
#include "config.h" |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <stdlib.h> |
| 28 |
#include <string.h> |
| 29 |
#include <string> |
| 30 |
#include <vector> |
| 31 |
|
| 32 |
#include "ut_string.h" |
| 33 |
#include "ut_assert.h" |
| 34 |
#include "ut_debugmsg.h" |
| 35 |
#include "ut_vector.h" |
| 36 |
#include "ut_hash.h" |
| 37 |
|
| 38 |
#include "gr_UnixCairoGraphics.h" |
| 39 |
|
| 40 |
// This header defines some functions for Unix dialogs, |
| 41 |
// like centering them, measuring them, etc. |
| 42 |
#include "xap_UnixDialogHelper.h" |
| 43 |
|
| 44 |
#include "xap_App.h" |
| 45 |
#include "xap_UnixApp.h" |
| 46 |
#include "xap_Frame.h" |
| 47 |
#include "xap_UnixFrameImpl.h" |
| 48 |
|
| 49 |
#include "xap_Dialog_Id.h" |
| 50 |
#include "xap_Dlg_Insert_Symbol.h" |
| 51 |
#include "xap_UnixDlg_Insert_Symbol.h" |
| 52 |
#include "xap_Draw_Symbol.h" |
| 53 |
|
| 54 |
|
| 55 |
/*****************************************************************/ |
| 56 |
/*****************************************************************/ |
| 57 |
|
| 58 |
#define WIDGET_ID_TAG_KEY "id" |
| 59 |
|
| 60 |
static UT_sint32 s_Insert_Symbol_first = 0; |
| 61 |
static std::string s_Prev_Font; |
| 62 |
|
| 63 |
static UT_UCSChar m_CurrentSymbol; |
| 64 |
static UT_UCSChar m_PreviousSymbol; |
| 65 |
|
| 66 |
XAP_Dialog * XAP_UnixDialog_Insert_Symbol::static_constructor(XAP_DialogFactory * pFactory, |
| 67 |
XAP_Dialog_Id id) |
| 68 |
{ |
| 69 |
XAP_UnixDialog_Insert_Symbol * p = new XAP_UnixDialog_Insert_Symbol(pFactory,id); |
| 70 |
return p; |
| 71 |
} |
| 72 |
|
| 73 |
XAP_UnixDialog_Insert_Symbol::XAP_UnixDialog_Insert_Symbol(XAP_DialogFactory * pDlgFactory, |
| 74 |
XAP_Dialog_Id id) |
| 75 |
: XAP_Dialog_Insert_Symbol(pDlgFactory,id), |
| 76 |
m_windowMain(NULL), |
| 77 |
m_SymbolMap(NULL) |
| 78 |
{ |
| 79 |
m_areaCurrentSym = NULL; |
| 80 |
m_unixGraphics = NULL; |
| 81 |
m_unixarea = NULL; |
| 82 |
m_ix = 0; |
| 83 |
m_iy = 0; |
| 84 |
} |
| 85 |
|
| 86 |
XAP_UnixDialog_Insert_Symbol::~XAP_UnixDialog_Insert_Symbol(void) |
| 87 |
{ |
| 88 |
DELETEP(m_unixGraphics); |
| 89 |
DELETEP(m_unixarea); |
| 90 |
} |
| 91 |
|
| 92 |
void XAP_UnixDialog_Insert_Symbol::runModal(XAP_Frame * ) |
| 93 |
{ |
| 94 |
} |
| 95 |
|
| 96 |
void XAP_UnixDialog_Insert_Symbol::activate(void) |
| 97 |
{ |
| 98 |
UT_return_if_fail(m_windowMain); |
| 99 |
ConstructWindowName(); |
| 100 |
gtk_window_set_title (GTK_WINDOW (m_windowMain), m_WindowName); |
| 101 |
gdk_window_raise(gtk_widget_get_window(m_windowMain)); |
| 102 |
} |
| 103 |
|
| 104 |
void XAP_UnixDialog_Insert_Symbol::notifyActiveFrame(XAP_Frame *) |
| 105 |
{ |
| 106 |
UT_ASSERT(m_windowMain); |
| 107 |
ConstructWindowName(); |
| 108 |
gtk_window_set_title (GTK_WINDOW (m_windowMain), m_WindowName); |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
void XAP_UnixDialog_Insert_Symbol::runModeless(XAP_Frame * pFrame) |
| 113 |
{ |
| 114 |
// Build the window's widgets and arrange them |
| 115 |
GtkWidget * mainWindow = _constructWindow(); |
| 116 |
UT_return_if_fail(mainWindow); |
| 117 |
|
| 118 |
abiSetupModelessDialog(GTK_DIALOG(mainWindow), pFrame, this, BUTTON_INSERT); |
| 119 |
|
| 120 |
// *** this is how we add the gc for symbol table *** |
| 121 |
// attach a new graphics context to the drawing area |
| 122 |
//XAP_UnixApp * unixapp = static_cast<XAP_UnixApp *> (m_pApp); |
| 123 |
//UT_ASSERT(unixapp); |
| 124 |
|
| 125 |
UT_ASSERT(m_SymbolMap && gtk_widget_get_window(m_SymbolMap)); |
| 126 |
|
| 127 |
// make a new Unix GC |
| 128 |
DELETEP (m_unixGraphics); |
| 129 |
|
| 130 |
{ |
| 131 |
GR_UnixCairoAllocInfo ai(m_SymbolMap); |
| 132 |
m_unixGraphics = |
| 133 |
(GR_CairoGraphics*) XAP_App::getApp()->newGraphics(ai); |
| 134 |
} |
| 135 |
// let the widget materialize |
| 136 |
GtkAllocation alloc; |
| 137 |
gtk_widget_get_allocation(m_SymbolMap, &alloc); |
| 138 |
_createSymbolFromGC(m_unixGraphics, |
| 139 |
static_cast<UT_uint32>(alloc.width), |
| 140 |
static_cast<UT_uint32>(alloc.height)); |
| 141 |
|
| 142 |
// *** Re use the code to draw into the selected symbol area. |
| 143 |
UT_ASSERT(m_areaCurrentSym && gtk_widget_get_window(m_areaCurrentSym)); |
| 144 |
|
| 145 |
// make a new Unix GC |
| 146 |
DELETEP (m_unixarea); |
| 147 |
{ |
| 148 |
GR_UnixCairoAllocInfo ai(m_areaCurrentSym); |
| 149 |
m_unixarea = |
| 150 |
(GR_CairoGraphics*) XAP_App::getApp()->newGraphics(ai); |
| 151 |
} |
| 152 |
// let the widget materialize |
| 153 |
gtk_widget_get_allocation(m_areaCurrentSym, &alloc); |
| 154 |
_createSymbolareaFromGC(m_unixarea, |
| 155 |
static_cast<UT_uint32>(alloc.width), |
| 156 |
static_cast<UT_uint32>(alloc.height)); |
| 157 |
|
| 158 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 159 |
UT_return_if_fail(iDrawSymbol); |
| 160 |
|
| 161 |
// We use this code to insert the default font name into to static |
| 162 |
// called. Afterwards it is just whatever was left from the last |
| 163 |
// call. |
| 164 |
|
| 165 |
if ( s_Insert_Symbol_first == 0) |
| 166 |
{ |
| 167 |
iDrawSymbol->setSelectedFont(DEFAULT_UNIX_SYMBOL_FONT); |
| 168 |
UT_UCSChar c = iDrawSymbol->calcSymbol(0, 0); |
| 169 |
if (c) |
| 170 |
{ |
| 171 |
m_PreviousSymbol = c; |
| 172 |
m_CurrentSymbol = c; |
| 173 |
iDrawSymbol->calculatePosition(m_CurrentSymbol, m_ix, m_iy); |
| 174 |
} |
| 175 |
s_Insert_Symbol_first = 1; |
| 176 |
} |
| 177 |
else |
| 178 |
{ |
| 179 |
iDrawSymbol->setSelectedFont(s_Prev_Font.c_str()); |
| 180 |
} |
| 181 |
|
| 182 |
_setScrolledWindow (); |
| 183 |
|
| 184 |
// Show the top level dialog |
| 185 |
gtk_widget_show(mainWindow); |
| 186 |
|
| 187 |
// Put the current font in the entry box |
| 188 |
const char* iSelectedFont = iDrawSymbol->getSelectedFont(); |
| 189 |
s_Prev_Font = iSelectedFont; |
| 190 |
UT_DEBUGMSG(("Selected Font at startup %s \n",iSelectedFont)); |
| 191 |
gtk_entry_set_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(m_fontcombo))), |
| 192 |
iSelectedFont); |
| 193 |
|
| 194 |
// Show the Previously selected symbol |
| 195 |
|
| 196 |
m_PreviousSymbol = m_CurrentSymbol; |
| 197 |
iDrawSymbol->drawarea(m_CurrentSymbol, m_PreviousSymbol); |
| 198 |
|
| 199 |
// return to ap_Editmethods and wait for something interesting |
| 200 |
// to happen. |
| 201 |
} |
| 202 |
|
| 203 |
void XAP_UnixDialog_Insert_Symbol::event_Insert(void) |
| 204 |
{ |
| 205 |
m_Inserted_Symbol = m_CurrentSymbol; |
| 206 |
_onInsertButton(); |
| 207 |
} |
| 208 |
|
| 209 |
void XAP_UnixDialog_Insert_Symbol::event_WindowDelete(void) |
| 210 |
{ |
| 211 |
m_answer = XAP_Dialog_Insert_Symbol::a_CANCEL; |
| 212 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 213 |
// |
| 214 |
// Save last font |
| 215 |
// |
| 216 |
if (iDrawSymbol) |
| 217 |
s_Prev_Font = iDrawSymbol->getSelectedFont(); |
| 218 |
m_InsertS_Font_list.clear(); |
| 219 |
|
| 220 |
modeless_cleanup(); |
| 221 |
gtk_widget_destroy(m_windowMain); |
| 222 |
m_windowMain = NULL; |
| 223 |
} |
| 224 |
|
| 225 |
void XAP_UnixDialog_Insert_Symbol::New_Font(void ) |
| 226 |
{ |
| 227 |
const gchar * buffer = gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(m_fontcombo)))); |
| 228 |
|
| 229 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 230 |
UT_return_if_fail(iDrawSymbol); |
| 231 |
|
| 232 |
// need a fallback value here, as this can get called from one of the gtk |
| 233 |
// callbacks when no font has been set. |
| 234 |
iDrawSymbol->setSelectedFont( buffer && *buffer ? static_cast<const char *>(buffer) : |
| 235 |
"Symbol"); |
| 236 |
|
| 237 |
// we get strange things if the previous Symbol does not exists in the |
| 238 |
// new font. Reset it |
| 239 |
UT_UCSChar c = iDrawSymbol->calcSymbol(0, 0); |
| 240 |
if (c) |
| 241 |
{ |
| 242 |
m_PreviousSymbol = c; |
| 243 |
m_CurrentSymbol = c; |
| 244 |
iDrawSymbol->calculatePosition(m_CurrentSymbol, m_ix, m_iy); |
| 245 |
} |
| 246 |
|
| 247 |
_setScrolledWindow (); |
| 248 |
iDrawSymbol->draw(); |
| 249 |
iDrawSymbol->drawarea(m_CurrentSymbol, m_PreviousSymbol); |
| 250 |
} |
| 251 |
|
| 252 |
void XAP_UnixDialog_Insert_Symbol::New_Row(void) |
| 253 |
{ |
| 254 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 255 |
UT_return_if_fail(iDrawSymbol); |
| 256 |
|
| 257 |
// FIXME rounding is better |
| 258 |
UT_uint32 row = UT_uint32 (gtk_adjustment_get_value(m_vadjust)); |
| 259 |
|
| 260 |
iDrawSymbol->setRow (row); |
| 261 |
} |
| 262 |
|
| 263 |
void XAP_UnixDialog_Insert_Symbol::Scroll_Event (int direction) |
| 264 |
{ |
| 265 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 266 |
UT_return_if_fail(iDrawSymbol); |
| 267 |
double value = gtk_adjustment_get_value(m_vadjust); |
| 268 |
|
| 269 |
if (direction && gtk_adjustment_get_upper(m_vadjust) > value) |
| 270 |
{ |
| 271 |
gtk_adjustment_set_value(m_vadjust, value + 1); |
| 272 |
} |
| 273 |
else if (!direction && gtk_adjustment_get_lower(m_vadjust) <= value - 1) |
| 274 |
{ |
| 275 |
gtk_adjustment_set_value(m_vadjust, value - 1); |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
/*****************************************************************/ |
| 281 |
|
| 282 |
static void s_dlg_response ( GtkWidget * widget, gint id, |
| 283 |
XAP_UnixDialog_Insert_Symbol * dlg ) |
| 284 |
{ |
| 285 |
UT_return_if_fail(widget && dlg); |
| 286 |
|
| 287 |
switch ( id ) |
| 288 |
{ |
| 289 |
case XAP_UnixDialog_Insert_Symbol::BUTTON_INSERT: |
| 290 |
dlg->event_Insert(); |
| 291 |
break; |
| 292 |
|
| 293 |
case XAP_UnixDialog_Insert_Symbol::BUTTON_CLOSE: |
| 294 |
abiDestroyWidget(widget); // emit the destroy signal |
| 295 |
break; |
| 296 |
} |
| 297 |
} |
| 298 |
|
| 299 |
static void s_destroy_clicked(GtkWidget * /* widget */, |
| 300 |
XAP_UnixDialog_Insert_Symbol * dlg) |
| 301 |
{ |
| 302 |
dlg->event_WindowDelete(); |
| 303 |
} |
| 304 |
|
| 305 |
static void s_delete_clicked(GtkWidget * widget, |
| 306 |
gpointer, |
| 307 |
XAP_UnixDialog_Insert_Symbol * /*dlg*/) |
| 308 |
{ |
| 309 |
abiDestroyWidget(widget); |
| 310 |
} |
| 311 |
|
| 312 |
static void s_new_font(GtkWidget * /*widget*/, XAP_UnixDialog_Insert_Symbol * dlg) |
| 313 |
{ |
| 314 |
dlg->New_Font(); |
| 315 |
} |
| 316 |
|
| 317 |
static void s_new_row(GtkWidget * /*widget*/, XAP_UnixDialog_Insert_Symbol * dlg) |
| 318 |
{ |
| 319 |
dlg->New_Row(); |
| 320 |
} |
| 321 |
|
| 322 |
static void s_scroll_event(GtkWidget * /*widget*/, GdkEventScroll * event, XAP_UnixDialog_Insert_Symbol * dlg) |
| 323 |
{ |
| 324 |
dlg->Scroll_Event (static_cast <int> (event->direction)); |
| 325 |
} |
| 326 |
|
| 327 |
#if GTK_CHECK_VERSION(3,0,0) |
| 328 |
static gboolean s_sym_SymbolMap_draw(GtkWidget * /*widget*/, cairo_t * /*cr*/, XAP_UnixDialog_Insert_Symbol * dlg) |
| 329 |
#else |
| 330 |
static gboolean s_sym_SymbolMap_draw(GtkWidget * /*widget*/, GdkEvent * /*cr*/, XAP_UnixDialog_Insert_Symbol * dlg) |
| 331 |
#endif |
| 332 |
{ |
| 333 |
dlg->SymbolMap_exposed(); |
| 334 |
return FALSE; |
| 335 |
} |
| 336 |
|
| 337 |
static gboolean s_size_request(GtkWidget *, GtkAllocation* req, XAP_UnixDialog_Insert_Symbol * dlg) |
| 338 |
{ |
| 339 |
dlg->setSymbolMap_size (req->width, req->height); |
| 340 |
return FALSE; |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
#if GTK_CHECK_VERSION(3,0,0) |
| 345 |
static gboolean s_Symbolarea_draw(GtkWidget * , cairo_t * , XAP_UnixDialog_Insert_Symbol * dlg) |
| 346 |
#else |
| 347 |
static gboolean s_Symbolarea_draw(GtkWidget * , GdkEvent * , XAP_UnixDialog_Insert_Symbol * dlg) |
| 348 |
#endif |
| 349 |
{ |
| 350 |
dlg->Symbolarea_exposed(); |
| 351 |
return FALSE; |
| 352 |
} |
| 353 |
|
| 354 |
static gboolean s_SymbolMap_clicked(GtkWidget *, GdkEvent * e, XAP_UnixDialog_Insert_Symbol * dlg) |
| 355 |
{ |
| 356 |
dlg->SymbolMap_clicked( e ); |
| 357 |
return FALSE; |
| 358 |
} |
| 359 |
|
| 360 |
static gboolean s_CurrentSymbol_clicked(GtkWidget *, GdkEvent * e, XAP_UnixDialog_Insert_Symbol * dlg) |
| 361 |
{ |
| 362 |
dlg->CurrentSymbol_clicked( e ); |
| 363 |
return FALSE; |
| 364 |
} |
| 365 |
|
| 366 |
static gboolean s_keypressed(GtkWidget *, GdkEventKey * e, XAP_UnixDialog_Insert_Symbol * dlg) |
| 367 |
{ |
| 368 |
return dlg->Key_Pressed( e ); |
| 369 |
} |
| 370 |
|
| 371 |
/*****************************************************************/ |
| 372 |
|
| 373 |
void XAP_UnixDialog_Insert_Symbol::SymbolMap_exposed(void ) |
| 374 |
{ |
| 375 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 376 |
UT_return_if_fail(iDrawSymbol); |
| 377 |
iDrawSymbol->draw(); |
| 378 |
UT_DEBUGMSG(("main symbol area exposed \n")); |
| 379 |
/* |
| 380 |
Need this to see the blue square after an expose event |
| 381 |
*/ |
| 382 |
iDrawSymbol->drawarea(m_CurrentSymbol, m_PreviousSymbol); |
| 383 |
} |
| 384 |
|
| 385 |
void XAP_UnixDialog_Insert_Symbol::Symbolarea_exposed(void ) |
| 386 |
{ |
| 387 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 388 |
UT_return_if_fail(iDrawSymbol); |
| 389 |
iDrawSymbol->drawarea(m_CurrentSymbol, m_PreviousSymbol); |
| 390 |
} |
| 391 |
|
| 392 |
void XAP_UnixDialog_Insert_Symbol::setSymbolMap_size(UT_uint32 width, UT_uint32 height) |
| 393 |
{ |
| 394 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 395 |
UT_return_if_fail(iDrawSymbol); |
| 396 |
UT_return_if_fail(m_windowMain); |
| 397 |
UT_return_if_fail(m_SymbolMap); |
| 398 |
|
| 399 |
|
| 400 |
static UT_uint32 diff_width = 0; |
| 401 |
static UT_uint32 diff_height = 0; |
| 402 |
|
| 403 |
|
| 404 |
// only in the beginnig we can measure the difference |
| 405 |
// between window and drawingarea this show stay constant |
| 406 |
GtkRequisition diff; |
| 407 |
GtkAllocation alloc; |
| 408 |
gtk_widget_get_requisition (m_windowMain, &diff); |
| 409 |
gtk_widget_get_allocation (m_SymbolMap, &alloc); |
| 410 |
if (!diff_width || !diff_height) |
| 411 |
{ |
| 412 |
diff_width = diff.width - alloc.width; |
| 413 |
diff_height = diff.height - alloc.height; |
| 414 |
} |
| 415 |
diff.width = width - diff_width; |
| 416 |
diff.height = height - diff_height; |
| 417 |
|
| 418 |
// set new sizes |
| 419 |
iDrawSymbol->setWindowSize(diff.width, diff.height); |
| 420 |
iDrawSymbol->setFontString (); |
| 421 |
} |
| 422 |
|
| 423 |
|
| 424 |
// |
| 425 |
// This function allows the symbol to be selected via the keyboard |
| 426 |
// |
| 427 |
|
| 428 |
gboolean XAP_UnixDialog_Insert_Symbol::Key_Pressed(GdkEventKey * e) |
| 429 |
{ |
| 430 |
int move = 0; |
| 431 |
UT_uint32 ix = m_ix; |
| 432 |
UT_uint32 iy = m_iy; |
| 433 |
UT_DEBUGMSG(("Current Symbol %x \n",m_CurrentSymbol)); |
| 434 |
switch (e->keyval) |
| 435 |
{ |
| 436 |
case GDK_KEY_Up: |
| 437 |
if(iy > 0) |
| 438 |
{ |
| 439 |
iy--; |
| 440 |
} |
| 441 |
else |
| 442 |
{ |
| 443 |
Scroll_Event (0); |
| 444 |
} |
| 445 |
move = -32; |
| 446 |
break; |
| 447 |
case GDK_KEY_Down: |
| 448 |
if(iy < 6) |
| 449 |
{ |
| 450 |
iy++; |
| 451 |
} |
| 452 |
else |
| 453 |
{ |
| 454 |
Scroll_Event (1); |
| 455 |
} |
| 456 |
move = 32; |
| 457 |
break; |
| 458 |
case GDK_KEY_Left: |
| 459 |
if(ix > 0) |
| 460 |
{ |
| 461 |
ix--; |
| 462 |
} |
| 463 |
else if(iy > 0) |
| 464 |
{ |
| 465 |
iy--; |
| 466 |
ix = 31; |
| 467 |
} |
| 468 |
else |
| 469 |
{ |
| 470 |
Scroll_Event (0); |
| 471 |
ix = 31; |
| 472 |
|
| 473 |
} |
| 474 |
move = -1; |
| 475 |
break; |
| 476 |
case GDK_KEY_Right: |
| 477 |
if(ix < 31) |
| 478 |
{ |
| 479 |
ix++; |
| 480 |
} |
| 481 |
else if(iy < 6) |
| 482 |
{ |
| 483 |
iy++; |
| 484 |
ix = 0; |
| 485 |
} |
| 486 |
else |
| 487 |
{ |
| 488 |
Scroll_Event (1); |
| 489 |
ix = 0; |
| 490 |
|
| 491 |
} |
| 492 |
move = 1; |
| 493 |
break; |
| 494 |
case GDK_KEY_Return: |
| 495 |
g_signal_stop_emission (G_OBJECT(m_windowMain), |
| 496 |
g_signal_lookup ("key_press_event", |
| 497 |
G_OBJECT_TYPE (m_windowMain)), 0); |
| 498 |
event_Insert(); |
| 499 |
return TRUE ; |
| 500 |
break; |
| 501 |
} |
| 502 |
UT_DEBUGMSG(("m_ix %d m_iy %d \n",m_ix,m_iy)); |
| 503 |
if (move != 0) |
| 504 |
{ |
| 505 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 506 |
UT_return_val_if_fail(iDrawSymbol,FALSE); |
| 507 |
UT_UCSChar c = iDrawSymbol->calcSymbolFromCoords(ix, iy); |
| 508 |
if (c) |
| 509 |
{ m_PreviousSymbol = m_CurrentSymbol; |
| 510 |
m_CurrentSymbol = c; |
| 511 |
UT_DEBUGMSG(("m_CurrentSymbol %x \n",m_CurrentSymbol)); |
| 512 |
m_ix = ix; |
| 513 |
m_iy = iy; |
| 514 |
} |
| 515 |
iDrawSymbol->drawarea(m_CurrentSymbol, m_PreviousSymbol); |
| 516 |
|
| 517 |
g_signal_stop_emission (G_OBJECT(m_windowMain), |
| 518 |
g_signal_lookup ("key_press_event", |
| 519 |
G_OBJECT_TYPE (m_windowMain)), 0); |
| 520 |
} |
| 521 |
|
| 522 |
return FALSE ; |
| 523 |
} |
| 524 |
|
| 525 |
void XAP_UnixDialog_Insert_Symbol::SymbolMap_clicked( GdkEvent * event) |
| 526 |
{ |
| 527 |
UT_uint32 x,y; |
| 528 |
x = static_cast<UT_uint32>(event->button.x); |
| 529 |
y = static_cast<UT_uint32>(event->button.y); |
| 530 |
|
| 531 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 532 |
UT_return_if_fail(iDrawSymbol); |
| 533 |
UT_UCSChar c = iDrawSymbol->calcSymbol(x, y); |
| 534 |
if (c) |
| 535 |
{ |
| 536 |
m_PreviousSymbol = m_CurrentSymbol; |
| 537 |
m_CurrentSymbol = c; |
| 538 |
iDrawSymbol->calculatePosition(m_CurrentSymbol, m_ix, m_iy); |
| 539 |
iDrawSymbol->drawarea(m_CurrentSymbol, m_PreviousSymbol); |
| 540 |
|
| 541 |
// double click should also insert the symbol |
| 542 |
if(event->type == GDK_2BUTTON_PRESS) |
| 543 |
event_Insert(); |
| 544 |
} |
| 545 |
} |
| 546 |
|
| 547 |
GtkWidget *XAP_UnixDialog_Insert_Symbol::_previewNew (int w, int h) |
| 548 |
{ |
| 549 |
GtkWidget *pre = createDrawingArea (); |
| 550 |
gtk_widget_show (pre); |
| 551 |
gtk_widget_set_size_request (pre, w, h); |
| 552 |
|
| 553 |
// Enable button press events |
| 554 |
gtk_widget_add_events(pre, GDK_BUTTON_PRESS_MASK); |
| 555 |
gtk_widget_add_events(pre, GDK_BUTTON_RELEASE_MASK); |
| 556 |
gtk_widget_add_events(pre, GDK_KEY_PRESS_MASK); |
| 557 |
gtk_widget_add_events(pre, GDK_KEY_RELEASE_MASK); |
| 558 |
gtk_widget_add_events(pre, GDK_EXPOSURE_MASK); |
| 559 |
gtk_widget_add_events(pre, GDK_ENTER_NOTIFY_MASK); |
| 560 |
gtk_widget_add_events(pre, GDK_LEAVE_NOTIFY_MASK); |
| 561 |
gtk_widget_add_events(pre, GDK_SCROLL_MASK); |
| 562 |
return pre; |
| 563 |
} |
| 564 |
|
| 565 |
void XAP_UnixDialog_Insert_Symbol::CurrentSymbol_clicked(GdkEvent *event) |
| 566 |
{ |
| 567 |
// have single-click insert the symbol |
| 568 |
if(event->type == GDK_BUTTON_PRESS) |
| 569 |
event_Insert(); |
| 570 |
} |
| 571 |
|
| 572 |
void XAP_UnixDialog_Insert_Symbol::destroy(void) |
| 573 |
{ |
| 574 |
UT_DEBUGMSG(("XAP_UnixDialog_Insert_Symbol::destroy()")); |
| 575 |
m_InsertS_Font_list.clear(); |
| 576 |
modeless_cleanup(); |
| 577 |
|
| 578 |
// Just nuke this dialog |
| 579 |
gtk_widget_destroy(m_windowMain); |
| 580 |
m_windowMain = NULL; |
| 581 |
} |
| 582 |
|
| 583 |
/*****************************************************************/ |
| 584 |
|
| 585 |
GtkWidget * XAP_UnixDialog_Insert_Symbol::_constructWindow(void) |
| 586 |
{ |
| 587 |
const XAP_StringSet * pSS = m_pApp->getStringSet(); |
| 588 |
GtkWidget *tmp; |
| 589 |
|
| 590 |
ConstructWindowName(); |
| 591 |
|
| 592 |
m_windowMain = abiDialogNew ("insert symbol dialog", TRUE, m_WindowName); |
| 593 |
gtk_window_set_position(GTK_WINDOW(m_windowMain), GTK_WIN_POS_MOUSE); |
| 594 |
#if !GTK_CHECK_VERSION(3,0,0) |
| 595 |
gtk_dialog_set_has_separator(GTK_DIALOG(m_windowMain), FALSE); |
| 596 |
#endif |
| 597 |
|
| 598 |
// Now put in a Vbox to hold our 3 widgets (Font Selector, Symbol Table |
| 599 |
// and OK -Selected Symbol- Cancel |
| 600 |
tmp = gtk_dialog_get_content_area(GTK_DIALOG(m_windowMain)); |
| 601 |
|
| 602 |
GtkWidget * vbox1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); |
| 603 |
GtkWidget * vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); |
| 604 |
GtkWidget * hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); |
| 605 |
gtk_widget_show (hbox); |
| 606 |
gtk_box_pack_start(GTK_BOX(hbox), vbox1, FALSE, FALSE, 0); |
| 607 |
gtk_box_pack_start(GTK_BOX(hbox), vbox2, TRUE, FALSE, 0); |
| 608 |
gtk_box_pack_start(GTK_BOX(tmp), hbox, FALSE, FALSE, 0); |
| 609 |
|
| 610 |
// Finally construct the combo box |
| 611 |
m_fontcombo = _createComboboxWithFonts (); |
| 612 |
|
| 613 |
// Now put the font combo box at the top of the dialog |
| 614 |
gtk_box_pack_start(GTK_BOX(vbox1), m_fontcombo, FALSE, FALSE, 0); |
| 615 |
|
| 616 |
// Now the Symbol Map. |
| 617 |
// TODO: 32 * x (19) = 608, 7 * y (21) = 147 FIXME! |
| 618 |
// |
| 619 |
GtkWidget * hbox1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); |
| 620 |
gtk_widget_show (hbox1); |
| 621 |
gtk_box_pack_start(GTK_BOX(tmp), hbox1, TRUE, TRUE, 4); |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
m_SymbolMap = _previewNew (608, 147); |
| 626 |
gtk_box_pack_start (GTK_BOX (hbox1), m_SymbolMap, TRUE, TRUE, 0); |
| 627 |
|
| 628 |
m_vadjust = GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 7, 0, 0, 7)); |
| 629 |
GtkWidget *vscroll = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, m_vadjust); |
| 630 |
gtk_widget_show (vscroll); |
| 631 |
gtk_box_pack_start (GTK_BOX (hbox1), vscroll, FALSE, FALSE, 0); |
| 632 |
|
| 633 |
m_areaCurrentSym = _previewNew (60, 45); |
| 634 |
gtk_box_pack_start(GTK_BOX(vbox2), m_areaCurrentSym, TRUE, FALSE, 0); |
| 635 |
|
| 636 |
gtk_widget_show_all (hbox); |
| 637 |
|
| 638 |
abiAddStockButton (GTK_DIALOG(m_windowMain), GTK_STOCK_CLOSE, BUTTON_CLOSE); |
| 639 |
tmp = abiAddButton (GTK_DIALOG(m_windowMain), "&Insert" /* not used */, BUTTON_INSERT); |
| 640 |
localizeButtonUnderline (tmp, pSS, XAP_STRING_ID_DLG_Insert); |
| 641 |
GtkWidget *img = gtk_image_new_from_stock(GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON); |
| 642 |
gtk_button_set_image(GTK_BUTTON(tmp), img); |
| 643 |
|
| 644 |
_connectSignals (); |
| 645 |
|
| 646 |
return m_windowMain; |
| 647 |
} |
| 648 |
|
| 649 |
/* |
| 650 |
This code is to suck all the available fonts and put them in a std::list. |
| 651 |
This can then be displayed on a combo box at the top of the dialog. |
| 652 |
Code stolen from ap_UnixToolbar_FontCombo. Now we remove all the |
| 653 |
duplicate name entries and create the Glist glFonts. This will be |
| 654 |
used in the font selection combo box |
| 655 |
*/ |
| 656 |
void XAP_UnixDialog_Insert_Symbol::_getGlistFonts (std::list<std::string> & glFonts) |
| 657 |
{ |
| 658 |
GR_GraphicsFactory * pGF = XAP_App::getApp()->getGraphicsFactory(); |
| 659 |
if(!pGF) |
| 660 |
{ |
| 661 |
return; |
| 662 |
} |
| 663 |
|
| 664 |
const std::vector<std::string> & names = |
| 665 |
GR_CairoGraphics::getAllFontNames(); |
| 666 |
|
| 667 |
for (std::vector<std::string>::const_iterator i = names.begin(); |
| 668 |
i != names.end(); ++i) |
| 669 |
{ |
| 670 |
const std::string & lgn = *i; |
| 671 |
glFonts.push_back(lgn); |
| 672 |
} |
| 673 |
|
| 674 |
glFonts.sort(); |
| 675 |
|
| 676 |
std::string lastfont; |
| 677 |
for (std::list<std::string>::iterator iter = glFonts.begin(); |
| 678 |
iter != glFonts.end(); ) |
| 679 |
{ |
| 680 |
if (lastfont == *iter) |
| 681 |
{ |
| 682 |
iter = glFonts.erase(iter); |
| 683 |
continue; |
| 684 |
} |
| 685 |
lastfont = *iter; |
| 686 |
++iter; |
| 687 |
} |
| 688 |
} |
| 689 |
|
| 690 |
GtkWidget *XAP_UnixDialog_Insert_Symbol::_createComboboxWithFonts (void) |
| 691 |
{ |
| 692 |
GtkWidget *fontcombo = gtk_combo_box_text_new_with_entry(); |
| 693 |
gtk_widget_show(fontcombo); |
| 694 |
|
| 695 |
// ensure we don't override this without freeing... |
| 696 |
m_InsertS_Font_list.clear(); |
| 697 |
_getGlistFonts (m_InsertS_Font_list); |
| 698 |
for(std::list<std::string>::const_iterator iter = m_InsertS_Font_list.begin(); |
| 699 |
iter != m_InsertS_Font_list.end(); ++iter) |
| 700 |
{ |
| 701 |
gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(fontcombo), iter->c_str()); |
| 702 |
} |
| 703 |
|
| 704 |
// Turn off keyboard entry in the font selection box |
| 705 |
gtk_editable_set_editable(GTK_EDITABLE(gtk_bin_get_child(GTK_BIN(fontcombo))), FALSE); |
| 706 |
|
| 707 |
return fontcombo; |
| 708 |
} |
| 709 |
|
| 710 |
void XAP_UnixDialog_Insert_Symbol::_connectSignals (void) |
| 711 |
{ |
| 712 |
g_signal_connect(G_OBJECT(m_windowMain), |
| 713 |
"response", |
| 714 |
G_CALLBACK(s_dlg_response), |
| 715 |
static_cast<gpointer>(this)); |
| 716 |
|
| 717 |
// Look for "changed" signal on the entry part of the combo box. |
| 718 |
// Code stolen from ev_UnixGnomeToolbar.cpp |
| 719 |
GtkEntry * blah = GTK_ENTRY(gtk_bin_get_child(GTK_BIN(m_fontcombo))); |
| 720 |
g_signal_connect(G_OBJECT(blah), |
| 721 |
"changed", |
| 722 |
G_CALLBACK(s_new_font), |
| 723 |
static_cast<gpointer>(this)); |
| 724 |
|
| 725 |
// the catch-alls |
| 726 |
// Dont use gtk_signal_connect_after for modeless dialogs |
| 727 |
g_signal_connect(G_OBJECT(m_windowMain), |
| 728 |
"destroy", |
| 729 |
G_CALLBACK(s_destroy_clicked), |
| 730 |
static_cast<gpointer>(this)); |
| 731 |
g_signal_connect(G_OBJECT(m_windowMain), |
| 732 |
"delete_event", |
| 733 |
G_CALLBACK(s_delete_clicked), |
| 734 |
static_cast<gpointer>(this)); |
| 735 |
|
| 736 |
|
| 737 |
// The event to choose the Symbol! |
| 738 |
g_signal_connect(G_OBJECT(m_SymbolMap), |
| 739 |
"button_press_event", |
| 740 |
G_CALLBACK(s_SymbolMap_clicked), |
| 741 |
static_cast<gpointer>(this)); |
| 742 |
|
| 743 |
// The event to choose the Symbol! |
| 744 |
g_signal_connect(G_OBJECT(m_areaCurrentSym), |
| 745 |
"button_press_event", |
| 746 |
G_CALLBACK(s_CurrentSymbol_clicked), |
| 747 |
static_cast<gpointer>(this)); |
| 748 |
|
| 749 |
// Look for keys pressed |
| 750 |
g_signal_connect(G_OBJECT(m_windowMain), |
| 751 |
"key_press_event", |
| 752 |
G_CALLBACK(s_keypressed), |
| 753 |
static_cast<gpointer>(this)); |
| 754 |
|
| 755 |
g_signal_connect(G_OBJECT(m_windowMain), |
| 756 |
"size-allocate", |
| 757 |
G_CALLBACK(s_size_request), |
| 758 |
static_cast<gpointer>(this)); |
| 759 |
|
| 760 |
// the expose event of the m_SymbolMap |
| 761 |
g_signal_connect(G_OBJECT(m_SymbolMap), |
| 762 |
#if GTK_CHECK_VERSION(3,0,0) |
| 763 |
"draw", |
| 764 |
#else |
| 765 |
"expose_event", |
| 766 |
#endif |
| 767 |
G_CALLBACK(s_sym_SymbolMap_draw), |
| 768 |
static_cast<gpointer>(this)); |
| 769 |
|
| 770 |
g_signal_connect(G_OBJECT(m_areaCurrentSym), |
| 771 |
#if GTK_CHECK_VERSION(3,0,0) |
| 772 |
"draw", |
| 773 |
#else |
| 774 |
"expose_event", |
| 775 |
#endif |
| 776 |
G_CALLBACK(s_Symbolarea_draw), |
| 777 |
static_cast<gpointer>(this)); |
| 778 |
// VScrollbar events |
| 779 |
g_signal_connect(G_OBJECT(m_vadjust), |
| 780 |
"value-changed", |
| 781 |
G_CALLBACK(s_new_row), |
| 782 |
static_cast<gpointer>(this)); |
| 783 |
|
| 784 |
// Mouse wheel events |
| 785 |
g_signal_connect(G_OBJECT(m_SymbolMap), |
| 786 |
"scroll_event", |
| 787 |
G_CALLBACK(s_scroll_event), |
| 788 |
static_cast<gpointer>(this)); |
| 789 |
|
| 790 |
} |
| 791 |
|
| 792 |
void XAP_UnixDialog_Insert_Symbol::_setScrolledWindow (void) |
| 793 |
{ |
| 794 |
XAP_Draw_Symbol * iDrawSymbol = _getCurrentSymbolMap(); |
| 795 |
UT_return_if_fail(iDrawSymbol); |
| 796 |
UT_return_if_fail(m_vadjust); |
| 797 |
|
| 798 |
UT_uint32 rows = iDrawSymbol->getSymbolRows (); |
| 799 |
rows = (rows <= 7? 1: rows); |
| 800 |
gtk_adjustment_set_lower(m_vadjust, 0); |
| 801 |
gtk_adjustment_set_upper(m_vadjust, gdouble (rows)); |
| 802 |
gtk_adjustment_set_page_size(m_vadjust, 7); |
| 803 |
gtk_adjustment_set_page_increment(m_vadjust, 7); |
| 804 |
gtk_adjustment_set_step_increment(m_vadjust, 1); |
| 805 |
gtk_adjustment_set_value(m_vadjust, 0); |
| 806 |
} |