:pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Tue Nov 27 05:17 CET 2001
[gnokii.git] / xgnokii / xgnokii_logos.c
1 /*
2
3    $Id$
4    
5   X G N O K I I
6
7   A Linux/Unix GUI for Nokia mobile phones.
8   Copyright (C) 1999 Pavel Janík ml., Hugh Blemings
9   & Ján Derfiòák <ja@mail.upjs.sk>.
10
11   Released under the terms of the GNU GPL, see file COPYING for more details.
12
13    $Log$
14    Revision 1.1.1.1  2001/11/25 21:59:31  short
15    :pserver:cvs@pserver.samba.org:/cvsroot - gnokii - Sun Nov 25 22:56 CET 2001
16
17    Revision 1.9  2001/09/14 12:53:00  pkot
18    New preview logos.
19    Localization fixes.
20    Set valid operator on logos xgnokii screen.
21
22    Revision 1.8  2001/05/24 20:47:31  chris
23    More updating of 7110 code and some of xgnokii_lowlevel changed over.
24
25    Revision 1.7  2001/03/23 08:24:56  ja
26    New preview for 6210 in xgnokii's logos module.
27
28          
29 */
30           
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <fcntl.h>
34 #include <signal.h>
35 #include <sys/types.h>
36 #include <string.h>
37 #include <gtk/gtk.h>
38
39 #include "misc.h"
40 #include "gsm-common.h"
41 #include "gsm-api.h"
42 #include "cfgreader.h"
43 #include "gsm-networks.h"
44 #include "gsm-filetypes.h"
45 #include "gsm-bitmaps.h"
46
47 #include "xgnokii_logos.h"
48 #include "xgnokii_common.h"
49 #include "xgnokii_lowlevel.h"
50 #include "xgnokii.h"
51
52 #include "xpm/Operator_logo.xpm"
53 #include "xpm/Startup_logo.xpm"
54 #include "xpm/Caller_logo.xpm"
55
56 #include "xpm/Black_point.xpm"
57 #include "xpm/Green_point.xpm"
58 #include "xpm/Green_pixel.xpm"
59
60 #include "xpm/New.xpm"
61 #include "xpm/Send.xpm"
62 #include "xpm/Read.xpm"
63 #include "xpm/Open.xpm"
64 #include "xpm/Save.xpm"
65
66 #include "xpm/Edit_invert.xpm"
67 #include "xpm/Edit_flip_horizontal.xpm"
68 #include "xpm/Edit_flip_vertical.xpm"
69
70 #include "xpm/Tool_brush.xpm"
71 #include "xpm/Tool_line.xpm"
72 #include "xpm/Tool_rectangle.xpm"
73 #include "xpm/Tool_filled_rectangle.xpm"
74
75 extern GSM_Network GSM_Networks[];
76 extern GSM_Statemachine statemachine;
77
78 GtkWidget *GUI_LogosWindow;
79
80 ErrorDialog errorDialog = {NULL, NULL};
81 InfoDialog infoDialog = {NULL, NULL};
82
83 /* stuff for drawingArea */
84 GtkWidget *drawingArea = NULL;
85 GdkPixmap *drawingPixmap = NULL;
86 GdkPixmap *greenPointPixmap, *blackPointPixmap;
87 int drawingAreaWidth, drawingAreaHeight; /* in pixels */
88 int mouseButtonPushed = 0;
89
90 /* stuff for previewArea */
91 GtkWidget *previewArea = NULL;
92 GdkPixmap *previewPixmap = NULL;
93 GdkPixmap *greenPixelPixmap;
94 int previewPixmapWidth, previewPixmapHeight;
95 int previewAvailable = 1, showPreviewErrorDialog = 1;
96 int previewPixmapNumber = 0;
97
98 GSM_Bitmap bitmap, oldBitmap;
99 GSM_NetworkInfo networkInfo;
100
101 /* widgets for toolbar - some, need global variables */
102 GtkWidget *buttonStartup, *buttonOperator, *buttonCaller;
103 GtkWidget *networkCombo, *callerCombo;
104
105 int activeTool = TOOL_BRUSH;
106 int toolStartX, toolStartY, toolLastX, toolLastY;
107
108 /* tools for drawing */
109 static GtkWidget *buttonBrush, *buttonLine, *buttonRectangle;
110 static GtkWidget *buttonFilledRectangle;
111
112 /* Contains fileName for Export dialog. */
113 typedef struct {
114   gchar *fileName;
115 } ExportDialogData;
116
117 static ExportDialogData exportDialogData = {NULL};
118
119 GtkWidget *FileSelection;
120
121 static int callersGroupsInitialized = 0;
122
123 /* returns lowest number from three numbers */
124 int GetMinFrom3(int a, int b, int c) {
125   if (a > b) {
126     if (b > c)
127       return c;
128     else
129       return b;
130   } else {
131     if (a > c)
132       return c;
133     else
134       return a;    
135   }
136 }
137
138 /* returns highest number from three numbers */
139 int GetMaxFrom3(int a, int b, int c) {
140   if (a > b) {
141     if (c > a)
142       return c;
143     else
144       return a;
145   } else {
146     if (c > b)
147       return c;
148     else
149       return b;
150   }
151 }
152
153 /* load preview pixmap from file */
154 GdkPixmap *GetPreviewPixmap (GtkWidget *widget) {
155   GdkPixmap *pixmap;
156   GdkBitmap *mask;
157   gchar *file;
158
159   if (previewPixmapNumber == 0)
160   {
161     if (!strcmp (xgnokiiConfig.model, "6110") ||
162         !strcmp (xgnokiiConfig.model, "6120"))
163     {
164       file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
165                              "/xpm/Preview_6110.xpm");
166       previewPixmapNumber = 1;
167     }
168     else if (!strcmp (xgnokiiConfig.model, "6130") ||
169              !strcmp (xgnokiiConfig.model, "6150") ||
170              !strcmp (xgnokiiConfig.model, "616x") ||
171              !strcmp (xgnokiiConfig.model, "6185") ||
172              !strcmp (xgnokiiConfig.model, "6190"))
173     {
174       file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
175                              "/xpm/Preview_6150.xpm");
176       previewPixmapNumber = 2;
177     }
178     else if (!strcmp (xgnokiiConfig.model, "3210"))
179     {
180       file = g_strdup_printf("%s%s", xgnokiiConfig.xgnokiidir,
181                              "/xpm/Preview_3210.xpm");
182       previewPixmapNumber = 3;
183     }
184     else if (!strcmp (xgnokiiConfig.model, "3310") ||
185              !strcmp (xgnokiiConfig.model, "3330"))
186     {
187       file = g_strdup_printf("%s%s", xgnokiiConfig.xgnokiidir,
188                              "/xpm/Preview_3310.xpm");
189       previewPixmapNumber = 4;
190     }
191     else if (!strcmp (xgnokiiConfig.model, "5110") ||
192              !strcmp (xgnokiiConfig.model, "5130"))
193     {
194       file = g_strdup_printf("%s%s", xgnokiiConfig.xgnokiidir,
195                              "/xpm/Preview_5110.xpm");
196       previewPixmapNumber = 5;
197     }
198     else if (!strcmp (xgnokiiConfig.model, "6250"))
199     {
200       file = g_strdup_printf("%s%s", xgnokiiConfig.xgnokiidir,
201                              "/xpm/Preview_6250.xpm");
202       previewPixmapNumber = 6;
203     }
204     else if (!strcmp (xgnokiiConfig.model, "7110"))
205     {
206       file = g_strdup_printf("%s%s", xgnokiiConfig.xgnokiidir,
207                              "/xpm/Preview_7110.xpm");
208       previewPixmapNumber = 7;
209     }
210     else
211     {
212       file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
213                              "/xpm/Preview_6210.xpm");
214       previewPixmapNumber = 8;
215     }
216   }
217   else
218     switch (previewPixmapNumber)
219     {
220       case 1: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
221                                      "/xpm/Preview_6110.xpm"); 
222               break;
223       case 2: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
224                                      "/xpm/Preview_6150.xpm"); 
225               break;
226       case 3: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
227                                      "/xpm/Preview_3210.xpm"); 
228               break;
229       case 4: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
230                                      "/xpm/Preview_3310.xpm"); 
231               break;
232       case 5: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
233                                      "/xpm/Preview_5110.xpm"); 
234               break;
235       case 6: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
236                                      "/xpm/Preview_6250.xpm"); 
237               break;
238       case 7: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
239                                      "/xpm/Preview_7110.xpm"); 
240               break;
241       default: file = g_strdup_printf("%s%s",xgnokiiConfig.xgnokiidir,
242                                       "/xpm/Preview_6210.xpm");
243               break;
244     }
245
246   pixmap = gdk_pixmap_create_from_xpm(widget->window,&mask,
247                                       &widget->style->bg[GTK_STATE_NORMAL],
248                                       file);
249
250   g_free(file);
251
252   return pixmap;
253 }
254
255 /* ********************************************************
256  * ** SET/CLEAR POINTS ************************************
257  * ********************************************************
258  */
259 void SetPreviewPoint(GtkWidget *widget, int x, int y, int update) {
260   if (!previewAvailable) return;
261   
262   /* there is difference between positiong of startupLogo and others */
263   if (bitmap.type != GSM_StartupLogo) {
264     x += PREVIEWJUMPX;
265     y += PREVIEWJUMPY;
266   }
267
268   /* draw point to pixmap */
269   if (previewPixmap)
270     gdk_draw_point(previewPixmap,widget->style->black_gc,
271                    x+PREVIEWSTARTX,y+PREVIEWSTARTY);
272
273   if (update) {
274     GdkRectangle updateRect;
275
276     /* update point on screen */
277     updateRect.width = 1;
278     updateRect.height = 1;
279     updateRect.x = PREVIEWSTARTX+x;
280     updateRect.y = PREVIEWSTARTY+y;
281
282     gtk_widget_draw(previewArea,&updateRect);
283   }  
284 }
285
286 void ClearPreviewPoint(GtkWidget *widget, int x, int y, int update) {
287   if (!previewAvailable) return;
288   
289   /* there is difference between positiong of startupLogo and others */
290   if (bitmap.type != GSM_StartupLogo) {
291     x += PREVIEWJUMPX;
292     y += PREVIEWJUMPY;
293   }
294
295   /* clean point from pixmap - any idea how to draw green point without pixmap? */
296   if (previewPixmap)
297     gdk_draw_pixmap(previewPixmap,
298                     widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
299                     greenPixelPixmap,0,0,x+PREVIEWSTARTX,y+PREVIEWSTARTY,1,1);
300   if (update) {
301     GdkRectangle updateRect;
302
303     /* clean from screen too */
304     updateRect.width = 1;
305     updateRect.height = 1;
306     updateRect.x = PREVIEWSTARTX+x;
307     updateRect.y = PREVIEWSTARTY+y;
308
309     gtk_widget_draw(previewArea,&updateRect);
310   }
311 }
312
313 int IsPoint(int x, int y) {
314   return GSM_IsPointBitmap(&bitmap,x,y);
315 }
316
317 void SetPoint(GtkWidget *widget, int x, int y, int update) {
318   /* difference between settings points in startupLogo and others */
319   GSM_SetPointBitmap(&bitmap,x,y);
320
321   /* draw point to pixmap */
322   gdk_draw_pixmap(drawingPixmap,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
323           blackPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
324
325   if (update) {
326     GdkRectangle updateRect;
327
328     /* calculate update rectangle */
329     updateRect.width = POINTSIZE+2;
330     updateRect.height = POINTSIZE+2;
331     updateRect.x = x * (POINTSIZE+1);
332     updateRect.y = y * (POINTSIZE+1);
333
334     /* update on screen */
335     gtk_widget_draw(drawingArea,&updateRect);
336   }
337
338   /* draw preview point too */
339   if (previewAvailable) SetPreviewPoint(widget,x,y,update); 
340 }
341
342 void ClearPoint(GtkWidget *widget, int x, int y, int update) {
343   /* difference between settings points in startupLogo and others */
344   GSM_ClearPointBitmap(&bitmap,x,y);
345
346   /* clear point from pixmap */
347   gdk_draw_pixmap(drawingPixmap,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
348           greenPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
349
350   if (update) {
351     GdkRectangle updateRect;
352
353     /* calculate update rectangle */
354     updateRect.width = POINTSIZE+2;
355     updateRect.height = POINTSIZE+2;
356     updateRect.x = x * (POINTSIZE+1);
357     updateRect.y = y * (POINTSIZE+1);
358           
359     /* update on screen */
360     gtk_widget_draw(drawingArea,&updateRect);
361   }
362
363   /* clear point from previewArea too */
364   if (previewAvailable) ClearPreviewPoint(widget,x,y,update); 
365 }
366
367 /* ****************************************************
368  * *** UPDATES - PREVIEW & DRAWING AREAS **************
369  * ****************************************************
370  */
371
372 /* this redraw all logo points - preview & drawing area */
373 void UpdatePointsRectangle(GtkWidget *widget, int x1, int y1, int x2, int y2) {
374   GdkRectangle updateRect;
375   int x, y, dx = 0, dy = 0;
376
377   if (bitmap.type != GSM_StartupLogo) {
378     dx = PREVIEWJUMPX;
379     dy = PREVIEWJUMPY;
380   }
381
382   if (x1 > x2) {
383     x = x1;
384     x1 = x2;
385     x2 = x;
386   }
387
388   if (y1 > y2) {
389     y = y1;
390     y1 = y2;
391     y2 = y;
392   }
393   
394   for (y = y1;y <= y2;y++)
395     for (x = x1;x <= x2;x++) {
396       if (IsPoint(x,y)) {
397         /* set on drawing area */
398         gdk_draw_pixmap(drawingPixmap,
399                         drawingArea->style->fg_gc[GTK_WIDGET_STATE(drawingArea)],
400                         blackPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
401
402         /* set on preview */
403         if (previewAvailable && previewPixmap) 
404           gdk_draw_point(previewPixmap,previewArea->style->black_gc,
405                          x+PREVIEWSTARTX+dx,y+PREVIEWSTARTY+dy);
406       } else {
407         /* clear from drawing */
408         gdk_draw_pixmap(drawingPixmap,
409                         drawingArea->style->fg_gc[GTK_WIDGET_STATE(drawingArea)],
410                         greenPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
411
412         /* clear from preview */
413         if (previewAvailable && previewPixmap) 
414           gdk_draw_pixmap(previewPixmap,
415                           previewArea->style->fg_gc[GTK_WIDGET_STATE(previewArea)],
416                           greenPixelPixmap,0,0,x+PREVIEWSTARTX+dx,y+PREVIEWSTARTY+dy,
417                           1,1);
418       }
419     }
420      
421   if (previewAvailable) {  
422     updateRect.x = PREVIEWSTARTX+dx+x1;
423     updateRect.y = PREVIEWSTARTY+dy+y1;
424     updateRect.width = x2-x1+1;
425     updateRect.height = y2-y1+1;
426     gtk_widget_draw(previewArea,&updateRect);
427   }  
428
429   updateRect.x = x1*(POINTSIZE+1);
430   updateRect.y = y1*(POINTSIZE+1);
431   updateRect.width = (x2-x1+1)*(POINTSIZE+1)+1;
432   updateRect.height = (y2-y1+1)*(POINTSIZE+1)+1;
433   gtk_widget_draw(drawingArea,&updateRect); 
434 }
435
436 void UpdatePoints(GtkWidget *widget) {
437   UpdatePointsRectangle(widget,0,0,bitmap.width-1,bitmap.height-1);
438 }
439
440 /* this redraw all logo points in previewArea, NO DRAWING AREA */
441 void UpdatePreviewPoints (void) {
442   GdkRectangle updateRect;
443   int x, y, dx = 0, dy = 0;
444
445   if (!previewPixmap || !previewAvailable) return;  
446   
447   if (bitmap.type != GSM_StartupLogo) {
448     dx = PREVIEWJUMPX;
449     dy = PREVIEWJUMPY;
450   }
451
452   for (y = 0;y < bitmap.height;y++)
453     for (x = 0;x < bitmap.width;x++) {
454       if (IsPoint(x,y)) {
455         gdk_draw_point(previewPixmap,previewArea->style->black_gc,
456                        x+PREVIEWSTARTX+dx,y+PREVIEWSTARTY+dy);
457       } else {
458         gdk_draw_pixmap(previewPixmap,
459                         previewArea->style->fg_gc[GTK_WIDGET_STATE(previewArea)],
460                         greenPixelPixmap,0,0,
461                         x+PREVIEWSTARTX+dx,y+PREVIEWSTARTY+dy,1,1);
462       }
463     }
464               
465   updateRect.x = dx; 
466   updateRect.y = dy;
467   updateRect.width = bitmap.width;
468   updateRect.height = bitmap.height;
469   gtk_widget_draw(previewArea,&updateRect);
470 }
471
472 /* ******************************************************
473  * **** DRAWING TOOLS ***********************************
474  * ******************************************************
475  */
476
477 /* TOOL - BRUSH */
478 void ToolBrush(GtkWidget *widget, int column, int row, int button) {
479   /* only this tool directly update bitmap & screen */
480   if (button > 1) 
481     ClearPoint(widget,column,row,1);
482   else
483     SetPoint(widget,column,row,1);
484 }
485
486 /* TOOL - LINE */
487
488 /* this function clear or draw a line on the screen  USED BY TOOLLINEUPDATE */
489 void ToolLine(GtkWidget *widget, int x1, int y1, int x2, int y2, int draw) {
490         int udx, udy, dx, dy, error, loop, xadd, yadd;
491
492         dx = x2 - x1;  /* x delta */
493         dy = y2 - y1;  /* y delta */
494
495         udx = abs(dx); /* unsigned x delta */
496         udy = abs(dy); /* unsigned y delta */
497
498         if (dx < 0) { xadd = -1; } else { xadd = 1; } /* set directions */
499         if (dy < 0) { yadd = -1; } else { yadd = 1; }
500
501         error = 0;
502         loop = 0;
503         if (udx > udy) { /* delta X > delta Y */
504                 do {
505                         error += udy;
506
507                         if (error >= udx) {  /* is time to move up or down? */
508                                 error -= udx;
509                                 y1 += yadd;
510                         }
511                         loop++;
512                         if (draw == 1) {
513                                 SetPoint(widget,x1,y1,0);
514                         } else {
515                                 /* now clearing line before drawing new one, we must check */
516                                 /* if there is a point in oldBitmap which saves bitmap before */
517                                 /* we starting drawing new line */
518                                 if (!GSM_IsPointBitmap(&oldBitmap,x1,y1)) {
519                                         ClearPoint(widget,x1,y1,0);
520                                 }
521                         }
522                         x1 += xadd;         /* move horizontally */
523                 } while (loop < udx); /* repeat for x length */
524         } else {
525                 do {
526                         error += udx;
527                         if (error >= udy) {  /* is time to move left or right? */
528                                 error -= udy;
529                                 x1 += xadd;
530                         }
531                         loop++;
532                         if (draw == 1) {
533                                 SetPoint(widget,x1,y1,0);
534                         } else {
535                                 /* check comment in delta X > delta Y */
536                                 if (!GSM_IsPointBitmap(&oldBitmap,x1,y1)) {
537                                         ClearPoint(widget,x1,y1,0);
538                                 }
539                         }
540                         y1 += yadd;         /* move vertically */
541                 } while (loop < udy); /* repeat for y length */
542         }
543 }
544
545 /* going to rewrite to Bresenham algorithm */ 
546 void ToolLineUpdate(GtkWidget *widget, int column, int row) {
547         /* clear old line */
548         ToolLine(widget,toolStartX,toolStartY,toolLastX,toolLastY,0);
549         /* draw new one */
550         ToolLine(widget,toolStartX,toolStartY,column,row,1);
551 }
552
553 /* TOOL - FILLED RECT */
554
555 /* FIXME - going to rewrite for optimalized version, clearing and */
556 /*         drawing new parts only before clearing and drawing whole */
557 /*         filled rectangle - it's too slow on diskless terminal ;(( */
558 void ToolFilledRectangleUpdate(GtkWidget *widget, int column, int row) {
559   int i, j, x1, y1, x2, y2;
560
561         /* swap Xs to x1 < x2 */
562   if (toolStartX > toolLastX) {
563     x1 = toolLastX;
564     x2 = toolStartX;
565   } else {
566     x1 = toolStartX;
567     x2 = toolLastX;
568   }
569
570         /* swap Ys to y1 < y2 */
571   if (toolStartY > toolLastY) {
572     y1 = toolLastY;
573     y2 = toolStartY;
574   } else {
575     y1 = toolStartY;
576     y2 = toolLastY;
577   }
578
579         /* clear one now */
580   for (j = y1;j <= y2;j++)
581     for (i = x1;i <= x2;i++)
582       if (!GSM_IsPointBitmap(&oldBitmap,i,j)) ClearPoint(widget,i,j,0);
583
584         /* swap Xs to x1 < x2 */
585   if (toolStartX > column) {
586     x1 = column;
587     x2 = toolStartX;
588   } else {
589     x1 = toolStartX;
590     x2 = column;
591   }
592
593         /* swap Ys to y1 < y2 */
594   if (toolStartY > row) {
595     y1 = row;
596     y2 = toolStartY;
597   } else {
598     y1 = toolStartY;
599     y2 = row;
600   }
601
602         /* draw new one */
603   for (j = y1;j <= y2;j++)
604     for (i = x1;i <= x2;i++)
605       SetPoint(widget,i,j,0);
606 }
607
608 /* TOOL - RECTANGLE */
609 void ToolRectangleUpdate(GtkWidget *widget, int column, int row) {
610   int i, j, x1, y1, x2, y2;
611
612   /* clear old rectangle */
613         /* swap Xs to x1 < x2 */
614   if (toolStartX > toolLastX) {
615     x1 = toolLastX;
616     x2 = toolStartX;
617   } else {
618     x1 = toolStartX;
619     x2 = toolLastX;
620   }
621
622         /* swap Ys to y1 < y2 */
623   if (toolStartY > toolLastY) {
624     y1 = toolLastY;
625     y2 = toolStartY;
626   } else {
627     y1 = toolStartY;
628     y2 = toolLastY;
629   }
630
631         /* clear old one */
632   for (i = x1;i <= x2;i++) {
633     if (!GSM_IsPointBitmap(&oldBitmap,i,y1)) ClearPoint(widget,i,y1,0);
634     if (!GSM_IsPointBitmap(&oldBitmap,i,y2)) ClearPoint(widget,i,y2,0);                
635   }
636
637   for (j = y1;j <= y2;j++) {
638     if (!GSM_IsPointBitmap(&oldBitmap,x1,j)) ClearPoint(widget,x1,j,0);
639     if (!GSM_IsPointBitmap(&oldBitmap,x2,j)) ClearPoint(widget,x2,j,0);
640   }
641
642   /* draw new rectangle */
643         /* swap Xs to x1 < x2 */
644   if (toolStartX > column) {
645     x1 = column;
646     x2 = toolStartX;
647   } else {
648     x1 = toolStartX;
649     x2 = column;
650   }
651
652         /* swap Ys to y1 < y2 */
653   if (toolStartY > row) {
654     y1 = row;
655     y2 = toolStartY;
656   } else {
657     y1 = toolStartY;
658     y2 = row;
659   }
660
661         /* draw new one */
662   for (i = x1;i <= x2;i++) {
663     if (!IsPoint(i,y1)) SetPoint(widget,i,y1,0);
664     if (!IsPoint(i,y2)) SetPoint(widget,i,y2,0);
665   }
666
667   for (j = y1;j <= y2;j++) {
668     if (!IsPoint(x1,j)) SetPoint(widget,x1,j,0);
669     if (!IsPoint(x2,j)) SetPoint(widget,x2,j,0);
670   }
671 }
672
673 /* this update tools actions on the screen - this is for optimalization */
674 /* eg. for faster redrawing tools actions - we do not need redraw pixel */
675 /* by pixel. Faster is redraw whole rectangle which contains all changes */
676 void UpdateToolScreen(GtkWidget *widget, int x1, int y1, int x2, int y2) {
677   GdkRectangle updateRect;
678
679   /* update preview area */
680         if (previewAvailable) {
681           updateRect.x = PREVIEWSTARTX+x1;
682         updateRect.y = PREVIEWSTARTY+y1;
683           if (bitmap.type != GSM_StartupLogo) {
684           updateRect.x += PREVIEWJUMPX;
685             updateRect.y += PREVIEWJUMPY;
686         }
687           updateRect.width = x2-x1+1;
688         updateRect.height = y2-y1+1;
689         gtk_widget_draw(previewArea,&updateRect);
690         }
691
692   /* update drawing area */
693   updateRect.x = x1 * (POINTSIZE+1);
694   updateRect.y = y1 * (POINTSIZE+1);
695   updateRect.width = (x2-x1+1)*(POINTSIZE+2);
696   updateRect.height = (y2-y1+1)*(POINTSIZE+2);
697   gtk_widget_draw(drawingArea,&updateRect);
698 }
699
700 /* *************************************
701  * ** PREVIEW AREA EVENTS **************
702  * *************************************
703  */
704
705 gint PreviewAreaButtonPressEvent(GtkWidget *widget, GdkEventButton *event) {
706   previewPixmapNumber = (previewPixmapNumber % 8) + 1;
707
708   gtk_drawing_area_size(GTK_DRAWING_AREA(previewArea),
709                         previewPixmapWidth,previewPixmapHeight);
710
711   return TRUE;
712 }
713
714 gint PreviewAreaConfigureEvent(GtkWidget *widget, GdkEventConfigure *event) {
715   if (previewPixmap) gdk_pixmap_unref(previewPixmap);
716   previewPixmap = GetPreviewPixmap(widget);
717
718   UpdatePreviewPoints();
719         
720   return TRUE;
721 }
722
723 gint PreviewAreaExposeEvent(GtkWidget *widget, GdkEventExpose *event) {
724   /* got previewPixmap? */
725   if (previewPixmap)
726     /* yes - simply redraw some rectangle */      
727     gdk_draw_pixmap(widget->window,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
728                     previewPixmap,event->area.x,event->area.y,event->area.x,
729                     event->area.y,event->area.width,event->area.height);
730
731   return FALSE;
732 }
733
734 /* ********************************
735  * ** DRAWING AREA EVENTS *********
736  * ********************************
737  */
738
739 gint DrawingAreaButtonPressEvent(GtkWidget *widget, GdkEventButton *event) {
740   /* got drawingPixmap? */
741   if (drawingPixmap == NULL) return TRUE;
742
743   if (!mouseButtonPushed) {
744     if ((event->button == 1 && activeTool != TOOL_BRUSH) || 
745         (activeTool == TOOL_BRUSH)) {
746       /* position from we starting drawing */
747       toolStartX = event->x / (POINTSIZE+1);
748       if (toolStartX < 0) toolStartX = 0;
749       if (toolStartX > bitmap.width-1) toolStartX = bitmap.width-1;
750     
751       toolStartY = event->y / (POINTSIZE+1);
752       if (toolStartY < 0) toolStartY = 0;
753       if (toolStartY > bitmap.height-1) toolStartY = bitmap.height-1;
754
755       toolLastX = toolStartX;
756       toolLastY = toolStartY;
757
758       /* store old bitmap for drawing, resp. for moving, resizing primitive */
759       memcpy(&oldBitmap,&bitmap,sizeof(oldBitmap));
760     }
761
762     if (event->button == 1) mouseButtonPushed = 1;
763   
764     switch (activeTool) { 
765       case TOOL_BRUSH:
766         ToolBrush(widget,toolStartX,toolStartY,event->button);
767         break;
768       case TOOL_LINE:
769       case TOOL_RECTANGLE:
770         if (event->button == 1) ToolBrush(widget,toolStartX,toolStartY,event->button);
771         break;
772     }
773   }
774
775   /* user is drawing some tool other than TOOL_BRUSH and pushed mouse button
776    * another than first => cancel tool and redraw to oldBitmap (bitmap when
777    * user start drawing)
778    */
779   if (mouseButtonPushed && activeTool != TOOL_BRUSH && event->button != 1) {
780     int lowestX, lowestY, highestX, highestY;
781     int i, j;
782
783     lowestX  = GetMinFrom3(toolStartX,toolLastX,toolLastX);
784     lowestY  = GetMinFrom3(toolStartY,toolLastY,toolLastY);
785     highestX = GetMaxFrom3(toolStartX,toolLastX,toolLastX);
786     highestY = GetMaxFrom3(toolStartY,toolLastY,toolLastY);
787
788     for (j = lowestY;j <= highestY;j++)
789       for (i = lowestX;i <= highestX;i++)
790         if (GSM_IsPointBitmap(&oldBitmap,i,j))
791           SetPoint(widget,i,j,0);
792         else
793           ClearPoint(widget,i,j,0);
794     UpdateToolScreen(widget,lowestX,lowestY,highestX,highestY);
795
796     mouseButtonPushed = 0;
797   }
798
799   return TRUE;
800 }
801
802 gint DrawingAreaButtonReleaseEvent(GtkWidget *widget, GdkEventButton *event) {
803   if (event->button == 1)
804     mouseButtonPushed = 0;
805
806   return TRUE;
807 }
808
809 gint DrawingAreaMotionNotifyEvent(GtkWidget *widget, GdkEventMotion *event) {
810   int x,y;
811   GdkModifierType state;
812   
813   if (!mouseButtonPushed && activeTool != TOOL_BRUSH) return TRUE;
814   
815   if (event->is_hint)
816     gdk_window_get_pointer(event->window,&x,&y,&state);
817   else {
818     x = event->x;
819     y = event->y;
820     state = event->state;
821   }
822
823   x = x / (POINTSIZE+1);
824   y = y / (POINTSIZE+1);
825   if (x < 0) x = 0;
826   if (y < 0) y = 0;
827   if (x > bitmap.width-1) x = bitmap.width-1;
828   if (y > bitmap.height-1) y = bitmap.height-1;
829
830   if (y == toolLastY && x == toolLastX) return TRUE;
831   
832   switch (activeTool) {
833     case TOOL_BRUSH:
834       if (state & GDK_BUTTON1_MASK && drawingPixmap != NULL) ToolBrush(widget,x,y,1);
835       if (state & GDK_BUTTON2_MASK && drawingPixmap != NULL) ToolBrush(widget,x,y,2);
836       if (state & GDK_BUTTON3_MASK && drawingPixmap != NULL) ToolBrush(widget,x,y,3);
837       break;
838     case TOOL_RECTANGLE:
839       if (drawingPixmap != NULL) ToolRectangleUpdate(widget,x,y);
840       break;
841     case TOOL_FILLED_RECTANGLE:
842       if (drawingPixmap != NULL) ToolFilledRectangleUpdate(widget,x,y); 
843       break; 
844     case TOOL_LINE:
845       if (drawingPixmap != NULL) ToolLineUpdate(widget,x,y); 
846       break; 
847   }   
848
849   /* what is this?
850    * it's simple, above tools updates only bitmap in memory and this
851    * function update from bitmap to screen, it's made as non-blinking
852    * drawing functions with this, simply draw everything we need and
853    * after that, redraw to screen rectangle in which we made changes 
854    * it's not redrawing pixel by pixel (blinking)
855    */
856   if (activeTool != TOOL_BRUSH) {
857     int lowestX, lowestY, highestX, highestY;
858
859     lowestX  = GetMinFrom3(toolStartX,toolLastX,x);
860     lowestY  = GetMinFrom3(toolStartY,toolLastY,y);
861     highestX = GetMaxFrom3(toolStartX,toolLastX,x);
862     highestY = GetMaxFrom3(toolStartY,toolLastY,y);
863   
864     UpdateToolScreen(widget,lowestX,lowestY,highestX,highestY);  
865   }
866
867   toolLastX = x;
868   toolLastY = y; 
869   return TRUE;  
870 }
871
872 /* configureEvent? -> event when someone resize windows, ... */
873 gint DrawingAreaConfigureEvent(GtkWidget *widget, GdkEventConfigure *event) {
874   int x, y;
875   /* got drawingPixmap? */
876   if (drawingPixmap) gdk_pixmap_unref(drawingPixmap); /* got, erase it */
877
878   /* make a new pixmap */
879   drawingPixmap = gdk_pixmap_new(widget->window,drawingAreaWidth,
880                   drawingAreaHeight,-1);
881
882   /* draw grid into pixmap */
883   for (y = 0;y < bitmap.height;y++)
884     for (x = 0;x < bitmap.width;x++)
885       if (IsPoint(x,y))
886         gdk_draw_pixmap(drawingPixmap,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
887                         blackPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
888       else
889         gdk_draw_pixmap(drawingPixmap,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
890                         greenPointPixmap,0,0,x*(POINTSIZE+1),y*(POINTSIZE+1),-1,-1);
891   
892   return TRUE;
893 }
894
895 gint DrawingAreaExposeEvent(GtkWidget *widget, GdkEventExpose *event) {
896   /* got drawingPixmap? */
897   if (drawingPixmap)
898     /* got - draw it */
899     gdk_draw_pixmap(widget->window,widget->style->fg_gc[GTK_WIDGET_STATE(widget)],
900                     drawingPixmap,
901                     event->area.x,event->area.y,event->area.x,event->area.y,
902                     event->area.width,event->area.height);
903   return FALSE; 
904 }
905
906 /* *****************************************
907  * ** TOOLBAR & MENU EVENTS ****************
908  * *****************************************
909  */
910
911 void GetNetworkInfoEvent(GtkWidget *widget) {
912   GSM_Error error;
913   PhoneEvent *e = (PhoneEvent *)g_malloc(sizeof(PhoneEvent));
914   D_NetworkInfo *data = (D_NetworkInfo *)g_malloc(sizeof(D_NetworkInfo));
915
916   /* prepare data for event */
917   data->info = &networkInfo;
918   e->event = Event_GetNetworkInfo;
919   e->data = data;
920
921   /* launch event and wait for result */
922   GUI_InsertEvent(e);
923   pthread_mutex_lock(&getNetworkInfoMutex);
924   pthread_cond_wait(&getNetworkInfoCond,&getNetworkInfoMutex);
925   pthread_mutex_unlock(&getNetworkInfoMutex);
926   error = data->status;
927   g_free(data);
928
929   /* watch for errors */
930   if (error != GE_NONE) {
931     gchar *buf = g_strdup_printf(_("Error getting network info\n(error=%d)"),error);
932     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
933     gtk_widget_show(errorDialog.dialog);
934     g_free(buf);
935   }
936
937   /* set new operator name to combo */
938   gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(networkCombo)->entry),
939                GSM_GetNetworkName(networkInfo.NetworkCode));
940 }
941
942 void GetLogoEvent(GtkWidget *widget) {
943   GSM_Error error;
944   int i;
945   PhoneEvent *e = (PhoneEvent *) g_malloc(sizeof(PhoneEvent));
946   D_Bitmap *data = (D_Bitmap *)g_malloc(sizeof(D_Bitmap));
947   char *operator = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(networkCombo)->entry));
948
949   /* prepare data for event */
950   strncpy(bitmap.netcode,GSM_GetNetworkCode(operator),7);
951   data->bitmap = &bitmap;
952   e->event = Event_GetBitmap;
953   e->data = data;
954   if (phoneMonitor.supported & PM_CALLERGROUP) {
955     for (i = 0;i < 6;i++) 
956       if (strcmp(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(callerCombo)->entry)),
957                  xgnokiiConfig.callerGroups[i]) == 0) bitmap.number = i; 
958   }
959
960   /* launch event and wait for result */
961   GUI_InsertEvent(e);
962   pthread_mutex_lock(&getBitmapMutex);
963   pthread_cond_wait(&getBitmapCond,&getBitmapMutex);
964   pthread_mutex_unlock(&getBitmapMutex);
965   error = data->status;
966   g_free(data);
967
968   /* watch for errors */
969   if (error != GE_NONE) {
970     gchar *buf = g_strdup_printf(_("Error getting bitmap\n(error=%d)"),error);
971     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
972     gtk_widget_show(errorDialog.dialog);
973     g_free(buf);
974   } else {
975     /* no error, draw logo from phone */
976     UpdatePoints(drawingArea);
977   }
978 }
979
980 void SetLogoEvent(GtkWidget *widget) {
981   GSM_Error error;
982   PhoneEvent *e = (PhoneEvent *)g_malloc(sizeof(PhoneEvent));
983   D_Bitmap *data = (D_Bitmap *)g_malloc(sizeof(D_Bitmap));
984   char *operator = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(networkCombo)->entry));
985   int i;
986
987   /* prepare data */
988   strncpy(bitmap.netcode,GSM_GetNetworkCode(operator),7);
989  
990   if (bitmap.type == GSM_CallerLogo) {
991     /* above condition must be there, because if you launch logos before
992      * callerGroups are available, you will see segfault - callerGroups not initialized 
993      */
994     if (phoneMonitor.supported & PM_CALLERGROUP) {
995       for (i = 0;i < 6;i++) 
996         if (strcmp(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(callerCombo)->entry)),
997                    xgnokiiConfig.callerGroups[i]) == 0) bitmap.number = i; 
998     }  
999   }
1000   
1001   data->bitmap = &bitmap;
1002   e->event = Event_SetBitmap;
1003   e->data = data;
1004
1005   /* launch event and wait for result */
1006   GUI_InsertEvent(e);
1007   pthread_mutex_lock(&setBitmapMutex);
1008   pthread_cond_wait(&setBitmapCond,&setBitmapMutex);
1009   pthread_mutex_unlock(&setBitmapMutex);
1010   error = data->status;
1011   g_free(data);
1012
1013   /* watch for errors */
1014   if (error != GE_NONE) {
1015     gchar *buf = g_strdup_printf(_("Error setting bitmap\n(error=%d)"),error);
1016     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
1017     gtk_widget_show(errorDialog.dialog);
1018     g_free(buf);
1019   }
1020 }
1021
1022 static void ClearLogoEvent(GtkWidget *widget) {
1023   
1024   //  bitmap.size=bitmap.width*bitmap.height/8;
1025   
1026   GSM_ClearBitmap(&bitmap);
1027
1028   UpdatePoints(widget);
1029 }
1030
1031 void InvertLogoEvent(GtkWidget *widget) {
1032   int column, row;
1033
1034   for (column = 0;column < bitmap.width;column++)
1035     for (row = 0;row < bitmap.height;row++)
1036       if (IsPoint(column,row))
1037         GSM_ClearPointBitmap(&bitmap,column,row);
1038       else
1039         GSM_SetPointBitmap(&bitmap,column,row);
1040
1041   UpdatePoints(widget);
1042 }
1043
1044 void UpLogoEvent(GtkWidget *widget) {
1045   int column, row;
1046
1047   GSM_Bitmap tbitmap;
1048   
1049   memcpy(&tbitmap,&bitmap,sizeof(GSM_Bitmap));
1050   
1051   for (row = 0;row < bitmap.height-1;row++)
1052     for (column = 0;column < bitmap.width;column++)
1053       if (IsPoint(column,row+1))
1054         GSM_SetPointBitmap(&bitmap,column,row);
1055       else
1056         GSM_ClearPointBitmap(&bitmap,column,row);
1057
1058   for (column = 0;column < bitmap.width;column++)
1059     if (GSM_IsPointBitmap(&tbitmap,column,0))
1060       GSM_SetPointBitmap(&bitmap,column,bitmap.height-1);
1061     else
1062       GSM_ClearPointBitmap(&bitmap,column,bitmap.height-1);    
1063
1064   UpdatePoints(widget); 
1065 }
1066
1067 void DownLogoEvent(GtkWidget *widget) {
1068   int column, row;
1069
1070   GSM_Bitmap tbitmap;
1071   
1072   memcpy(&tbitmap,&bitmap,sizeof(GSM_Bitmap));
1073
1074   for (row = bitmap.height-1;row > 0;row--)
1075     for (column = 0;column < bitmap.width;column++)
1076       if (IsPoint(column,row-1))
1077         GSM_SetPointBitmap(&bitmap,column,row);
1078       else
1079         GSM_ClearPointBitmap(&bitmap,column,row);
1080
1081   for (column = 0;column < bitmap.width;column++)
1082     if (GSM_IsPointBitmap(&tbitmap,column,bitmap.height-1))
1083       GSM_SetPointBitmap(&bitmap,column,0);
1084     else
1085       GSM_ClearPointBitmap(&bitmap,column,0);
1086
1087   UpdatePoints(widget);
1088 }
1089
1090 void LeftLogoEvent(GtkWidget *widget) {
1091   int column, row;
1092
1093   GSM_Bitmap tbitmap;
1094   
1095   memcpy(&tbitmap,&bitmap,sizeof(GSM_Bitmap));
1096
1097   for (column = 0; column < bitmap.width-1;column++)
1098     for (row = 0;row < bitmap.height;row++)
1099       if (IsPoint(column+1,row))
1100         GSM_SetPointBitmap(&bitmap,column,row);
1101       else
1102         GSM_ClearPointBitmap(&bitmap,column,row);
1103
1104   for (row = 0;row < bitmap.height;row++)
1105     if (GSM_IsPointBitmap(&tbitmap,0,row))
1106       GSM_SetPointBitmap(&bitmap,bitmap.width-1,row);
1107     else
1108       GSM_ClearPointBitmap(&bitmap,bitmap.width-1,row);
1109
1110   UpdatePoints(widget);
1111 }
1112
1113 void RightLogoEvent(GtkWidget *widget) {
1114   int column, row;
1115
1116   GSM_Bitmap tbitmap;
1117   
1118   memcpy(&tbitmap,&bitmap,sizeof(GSM_Bitmap));
1119
1120   for (column = bitmap.width-1;column > 0;column--)
1121     for (row = 0;row < bitmap.height;row++)
1122       if (IsPoint(column-1,row))
1123         GSM_SetPointBitmap(&bitmap,column,row);
1124       else
1125         GSM_ClearPointBitmap(&bitmap,column,row);
1126
1127   for (row = 0;row < bitmap.height;row++)
1128     if (GSM_IsPointBitmap(&tbitmap,bitmap.width-1,row))
1129       GSM_SetPointBitmap(&bitmap,0,row);
1130     else
1131       GSM_ClearPointBitmap(&bitmap,0,row);
1132
1133   UpdatePoints(widget);
1134 }
1135
1136 void FlipVerticalLogoEvent(GtkWidget *widget) {
1137   int row, column, temp;
1138
1139   for (row = 0;row < (bitmap.height/2);row++)
1140     for (column = 0;column < bitmap.width;column++) {
1141       temp = IsPoint(column,row);
1142       if (IsPoint(column,bitmap.height-1-row))
1143         GSM_SetPointBitmap(&bitmap,column,row);
1144       else
1145         GSM_ClearPointBitmap(&bitmap,column,row);
1146
1147       if (temp)
1148         GSM_SetPointBitmap(&bitmap,column,bitmap.height-1-row);
1149       else
1150         GSM_ClearPointBitmap(&bitmap,column,bitmap.height-1-row);
1151     }
1152
1153   UpdatePoints(widget);
1154 }
1155
1156 void FlipHorizontalLogoEvent(GtkWidget *widget) {
1157   int row, column, temp;
1158
1159   for (row = 0;row < bitmap.height;row++)
1160     for (column = 0;column < (bitmap.width/2);column++) {
1161       temp = IsPoint(column,row);
1162
1163       if (IsPoint(bitmap.width-1-column,row))
1164         GSM_SetPointBitmap(&bitmap,column,row);
1165       else
1166         GSM_ClearPointBitmap(&bitmap,column,row);
1167
1168       if (temp)
1169         GSM_SetPointBitmap(&bitmap,bitmap.width-1-column,row);
1170       else
1171         GSM_ClearPointBitmap(&bitmap,bitmap.width-1-column,row);
1172     }
1173
1174   UpdatePoints(widget);
1175
1176
1177 /* this is launched when tool was changed */
1178 gint ToolTypeEvent(GtkWidget *widget) {
1179   if (GTK_TOGGLE_BUTTON(buttonBrush)->active) activeTool = TOOL_BRUSH; else
1180   if (GTK_TOGGLE_BUTTON(buttonLine)->active) activeTool = TOOL_LINE; else
1181   if (GTK_TOGGLE_BUTTON(buttonRectangle)->active) activeTool = TOOL_RECTANGLE; else
1182   if (GTK_TOGGLE_BUTTON(buttonFilledRectangle)->active)
1183     activeTool = TOOL_FILLED_RECTANGLE;
1184
1185   return 0;
1186 }
1187
1188 /* this is launched when logo type was change by buttons on toolbar */
1189 gint LogoTypeEvent(GtkWidget *widget) {
1190   int clear = 0;
1191
1192   /* is startupLogo? */
1193   /* Resize and clear anyway - CK */
1194   if (GTK_TOGGLE_BUTTON(buttonStartup)->active) {
1195     /* look for old bitmap type, clean if another */
1196     clear = 1;
1197     GSM_ResizeBitmap(&bitmap,GSM_StartupLogo, &statemachine.Phone.Info);
1198   }
1199
1200   /* has phone support for callerGroups? */
1201   if (phoneMonitor.supported & PM_CALLERGROUP) {
1202     if (GTK_TOGGLE_BUTTON(buttonCaller)->active && bitmap.type != GSM_CallerLogo) {
1203       /* previous was startup? clear and draw batteries, signal, ... */      
1204             /* Clear anyway for 7110...CK */
1205       clear = 1;
1206       GSM_ResizeBitmap(&bitmap,GSM_CallerLogo, &statemachine.Phone.Info);
1207     }
1208   }
1209
1210   /* is new type operatorLogo? */
1211   if (GTK_TOGGLE_BUTTON(buttonOperator)->active && bitmap.type != GSM_OperatorLogo) {
1212     /* previous startup? clear and draw batteries, signal, ... */      
1213           /* Clear anyway for 7110..CK */
1214     clear = 1;
1215     GSM_ResizeBitmap(&bitmap,GSM_OperatorLogo, &statemachine.Phone.Info);
1216   }
1217
1218   /* must clear? */
1219   if (clear) {
1220     if (previewAvailable) {
1221       /* configure event reload pixmap from disk and redraws */
1222       gtk_drawing_area_size(GTK_DRAWING_AREA(previewArea),
1223                             previewPixmapWidth,previewPixmapHeight);
1224     }   
1225
1226     /* change new drawingArea size */
1227     drawingAreaWidth = bitmap.width * (POINTSIZE+1)+1;
1228     drawingAreaHeight = bitmap.height * (POINTSIZE+1)+1;
1229
1230     gtk_drawing_area_size(GTK_DRAWING_AREA(drawingArea),
1231                           drawingAreaWidth,drawingAreaHeight);
1232   }
1233
1234   return 0;
1235 }
1236
1237 inline void CloseLogosWindow (void) {
1238   gtk_widget_hide(GUI_LogosWindow);
1239 }
1240
1241 void ExportLogoFileMain(gchar *name)
1242 {
1243   GSM_Bitmap tbitmap;
1244   GSM_Error error;
1245   
1246   tbitmap=bitmap;
1247
1248   strncpy(tbitmap.netcode,GSM_GetNetworkCode(networkInfo.NetworkCode),7);
1249
1250   error=GSM_SaveBitmapFile(name,&tbitmap);
1251   if (error!=GE_NONE) {
1252     gchar *buf = g_strdup_printf(_("Error saving file\n(error=%d)"),error);
1253     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
1254     gtk_widget_show(errorDialog.dialog);
1255     g_free(buf);
1256   }
1257 }
1258
1259 static void YesLogoFileExportDialog (GtkWidget *w, gpointer data)
1260 {
1261   gtk_widget_hide (GTK_WIDGET (data));
1262   ExportLogoFileMain(exportDialogData.fileName);
1263 }
1264
1265 static void ExportFileSelected (GtkWidget *w, GtkFileSelection *fs)
1266 {
1267   static YesNoDialog dialog = { NULL, NULL};
1268   FILE *f;
1269   gchar err[80];
1270
1271   exportDialogData.fileName = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
1272   gtk_widget_hide (GTK_WIDGET (fs));
1273
1274   if ((f = fopen (exportDialogData.fileName, "r")) != NULL)
1275   {
1276     fclose (f);
1277     if (dialog.dialog == NULL)
1278     {
1279       CreateYesNoDialog (&dialog, YesLogoFileExportDialog, CancelDialog, GUI_LogosWindow);
1280       gtk_window_set_title (GTK_WINDOW (dialog.dialog), _("Overwrite file?"));
1281       g_snprintf ( err, 80, _("File %s already exist.\nOverwrite?"), exportDialogData.fileName); 
1282       gtk_label_set_text (GTK_LABEL(dialog.text), err);
1283     }
1284     gtk_widget_show (dialog.dialog);
1285   }
1286   else
1287     ExportLogoFileMain(exportDialogData.fileName);
1288 }
1289
1290 void ImportFileSelected(GtkWidget *w, GtkFileSelection *fs)
1291 {
1292   GSM_Bitmap tbitmap;
1293   GSM_Error error=0;
1294   
1295   gchar *fileName;
1296   FILE *f;
1297
1298   fileName = gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
1299   gtk_widget_hide (GTK_WIDGET (fs));
1300
1301   if ((f = fopen (fileName, "r")) == NULL) {
1302     gchar *buf = g_strdup_printf(_("Can't open file %s for reading !"),fileName);
1303     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
1304     gtk_widget_show(errorDialog.dialog);
1305     g_free(buf);
1306     return;
1307   } else fclose(f);
1308
1309   error=GSM_ReadBitmapFile(fileName,&tbitmap);
1310   if (error!=GE_NONE) {
1311     gchar *buf = g_strdup_printf(_("Error reading file\n(error=%d)"),error);
1312     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
1313     gtk_widget_show(errorDialog.dialog);
1314     g_free(buf);
1315     return;
1316   }
1317
1318   exportDialogData.fileName=fileName;
1319   
1320   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonStartup),false);
1321   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonOperator),false);
1322   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonCaller),false);
1323   
1324   if (tbitmap.type==GSM_OperatorLogo) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonOperator),true);
1325   if (tbitmap.type==GSM_StartupLogo) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonStartup),true);
1326   if (tbitmap.type==GSM_CallerLogo) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(buttonCaller),true);
1327   
1328   memcpy(&bitmap,&tbitmap,sizeof(GSM_Bitmap));
1329   
1330   UpdatePoints(drawingArea);
1331 }
1332
1333 void SaveLogoAs(GtkWidget *widget)
1334 {
1335   FileSelection=gtk_file_selection_new (_("Save logo as ..."));
1336
1337   gtk_signal_connect (
1338         GTK_OBJECT (GTK_FILE_SELECTION (FileSelection)->ok_button),
1339         "clicked", (GtkSignalFunc) ExportFileSelected, FileSelection);
1340     
1341   gtk_signal_connect_object (
1342         GTK_OBJECT(GTK_FILE_SELECTION(FileSelection)->cancel_button),
1343         "clicked", (GtkSignalFunc) gtk_widget_destroy,
1344         GTK_OBJECT (FileSelection));
1345     
1346   gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(FileSelection));
1347
1348   gtk_widget_show(FileSelection);
1349 }
1350
1351 void SaveLogo(GtkWidget *widget)
1352 {
1353   if (exportDialogData.fileName==NULL) {
1354     SaveLogoAs(widget);
1355   } else {
1356     ExportLogoFileMain(exportDialogData.fileName);
1357   }
1358 }
1359
1360 void OpenLogo(GtkWidget *widget)
1361 {
1362   FileSelection=gtk_file_selection_new (_("Open logo..."));
1363
1364   gtk_signal_connect (
1365         GTK_OBJECT (GTK_FILE_SELECTION (FileSelection)->ok_button),
1366         "clicked", (GtkSignalFunc) ImportFileSelected, FileSelection);
1367     
1368   gtk_signal_connect_object (
1369         GTK_OBJECT(GTK_FILE_SELECTION(FileSelection)->cancel_button),
1370         "clicked", (GtkSignalFunc) gtk_widget_destroy,
1371         GTK_OBJECT (FileSelection));
1372     
1373   gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(FileSelection));
1374
1375   gtk_widget_show(FileSelection);
1376 }
1377
1378 static GtkItemFactoryEntry logosMenuItems[] = {
1379   { NULL,       NULL,           NULL,                    0, "<Branch>"},
1380   { NULL,       "<control>O",   OpenLogo,                0, NULL},
1381   { NULL,       "<control>S",   SaveLogo,                0, NULL},
1382   { NULL,       NULL,           SaveLogoAs,              0, NULL},
1383   { NULL,       NULL,           NULL,                    0, "<Separator>"},
1384   { NULL,       "<control>G",   GetNetworkInfoEvent,     0, NULL},
1385   { NULL,       NULL,           GetLogoEvent,            0, NULL},
1386   { NULL,       "<control>T",   SetLogoEvent,            0, NULL},
1387   { NULL,       NULL,           NULL,                    0, "<Separator>"},
1388   { NULL,       "<control>W",   CloseLogosWindow,        0, NULL},
1389   { NULL,       NULL,           NULL,                    0, "<Branch>"},
1390   { NULL,       "<control>C",   ClearLogoEvent,          0, NULL},
1391   { NULL,       "<control>I",   InvertLogoEvent,         0, NULL},
1392   { NULL,       NULL,           NULL,                    0, "<Separator>"},
1393   { NULL,       "<control>U",   UpLogoEvent,             0, NULL},
1394   { NULL,       "<control>D",   DownLogoEvent,           0, NULL},
1395   { NULL,       "<control>L",   LeftLogoEvent,           0, NULL},
1396   { NULL,       "<control>R",   RightLogoEvent,          0, NULL},
1397   { NULL,       NULL,           NULL,                    0, "<Separator>"},
1398   { NULL,       "<control>H",   FlipHorizontalLogoEvent, 0, NULL},
1399   { NULL,       "<control>V",   FlipVerticalLogoEvent,   0, NULL},
1400 };
1401
1402 void InitLogosMenu (void) {
1403  logosMenuItems[0].path = g_strdup(_("/_File"));
1404  logosMenuItems[1].path = g_strdup(_("/File/_Open"));
1405  logosMenuItems[2].path = g_strdup(_("/File/_Save"));
1406  logosMenuItems[3].path = g_strdup(_("/File/Save _as ..."));
1407  logosMenuItems[4].path = g_strdup(_("/File/Sep1"));
1408  logosMenuItems[5].path = g_strdup(_("/File/_Get operator"));
1409  logosMenuItems[6].path = g_strdup(_("/File/Get _logo"));
1410  logosMenuItems[7].path = g_strdup(_("/File/Se_t logo"));
1411  logosMenuItems[8].path = g_strdup(_("/File/Sep2"));
1412  logosMenuItems[9].path = g_strdup(_("/File/_Close"));
1413  logosMenuItems[10].path = g_strdup(_("/_Edit"));
1414  logosMenuItems[11].path = g_strdup(_("/Edit/_Clear"));
1415  logosMenuItems[12].path = g_strdup(_("/Edit/_Invert"));
1416  logosMenuItems[13].path = g_strdup(_("/Edit/Sep3"));
1417  logosMenuItems[14].path = g_strdup(_("/Edit/_Up logo"));
1418  logosMenuItems[15].path = g_strdup(_("/Edit/_Down logo"));
1419  logosMenuItems[16].path = g_strdup(_("/Edit/_Left logo"));
1420  logosMenuItems[17].path = g_strdup(_("/Edit/_Right logo"));
1421  logosMenuItems[18].path = g_strdup(_("/Edit/Sep4"));
1422  logosMenuItems[19].path = g_strdup(_("/Edit/Flip _horizontal"));
1423  logosMenuItems[20].path = g_strdup(_("/Edit/Flip _vertical"));
1424 }
1425
1426 void GUI_CreateLogosWindow (void) {
1427   int nMenuItems = sizeof (logosMenuItems) / sizeof (logosMenuItems[0]);
1428   GtkAccelGroup *accelGroup;
1429   GtkItemFactory *itemFactory;
1430   GtkWidget *menuBar;
1431   GtkWidget *toolBar, *vertToolBar;
1432   GtkWidget *vbox;
1433   GtkWidget *hbox;
1434   GtkWidget *drawingBox;
1435   GtkWidget *separator;
1436   GdkBitmap *mask;
1437
1438   GList *glistNetwork = NULL;
1439
1440   int i = 0;
1441  
1442   previewPixmapWidth = PREVIEWWIDTH;
1443   previewPixmapHeight = PREVIEWHEIGHT;
1444   
1445   InitLogosMenu();
1446
1447   /* realize top level window for logos */
1448   GUI_LogosWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1449   gtk_window_set_wmclass(GTK_WINDOW(GUI_LogosWindow), "LogosWindow", "Xgnokii");
1450   gtk_window_set_policy(GTK_WINDOW(GUI_LogosWindow), 1, 1, 1);
1451   gtk_window_set_title(GTK_WINDOW(GUI_LogosWindow), _("Logos"));
1452   gtk_signal_connect(GTK_OBJECT(GUI_LogosWindow), "delete_event",
1453                      GTK_SIGNAL_FUNC(DeleteEvent), NULL);
1454   gtk_widget_realize(GUI_LogosWindow);
1455
1456   CreateErrorDialog(&errorDialog, GUI_LogosWindow);
1457   CreateInfoDialog(&infoDialog, GUI_LogosWindow);
1458
1459   accelGroup = gtk_accel_group_new();
1460   gtk_accel_group_attach(accelGroup, GTK_OBJECT(GUI_LogosWindow));
1461   
1462   /* create main vbox */
1463   vbox = gtk_vbox_new(FALSE, 1);
1464   gtk_container_add(GTK_CONTAINER(GUI_LogosWindow), vbox);
1465   gtk_widget_show(vbox);
1466  
1467   itemFactory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", accelGroup);
1468   gtk_item_factory_create_items(itemFactory, nMenuItems, logosMenuItems, NULL);
1469   menuBar = gtk_item_factory_get_widget(itemFactory, "<main>");
1470
1471   gtk_box_pack_start(GTK_BOX(vbox), menuBar, FALSE, FALSE, 0);
1472   gtk_widget_show(menuBar);
1473
1474   /* toolbar */
1475   toolBar = gtk_toolbar_new(GTK_ORIENTATION_HORIZONTAL, GTK_TOOLBAR_ICONS);
1476   gtk_toolbar_set_button_relief(GTK_TOOLBAR(toolBar), GTK_RELIEF_NORMAL);
1477   gtk_toolbar_set_style(GTK_TOOLBAR(toolBar), GTK_TOOLBAR_ICONS);
1478
1479   gtk_toolbar_append_item(GTK_TOOLBAR(toolBar), NULL, _("Clear logo"), NULL,
1480                   NewPixmap(New_xpm, GUI_LogosWindow->window,
1481                   &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1482                   (GtkSignalFunc)ClearLogoEvent, toolBar);
1483
1484   gtk_toolbar_append_space(GTK_TOOLBAR(toolBar));
1485
1486   gtk_toolbar_append_item(GTK_TOOLBAR(toolBar), NULL, _("Get logo"), NULL,
1487                  NewPixmap(Read_xpm, GUI_LogosWindow->window,
1488                  &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1489                  (GtkSignalFunc)GetLogoEvent, toolBar);
1490
1491   gtk_toolbar_append_item(GTK_TOOLBAR(toolBar), NULL, _("Set logo"), NULL,
1492                  NewPixmap(Send_xpm, GUI_LogosWindow->window,
1493                  &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1494                  (GtkSignalFunc)SetLogoEvent, toolBar);
1495
1496   gtk_toolbar_append_space(GTK_TOOLBAR(toolBar));
1497
1498   gtk_toolbar_append_item (GTK_TOOLBAR (toolBar), NULL, _("Import from file"), NULL,
1499                            NewPixmap(Open_xpm, GUI_LogosWindow->window,
1500                            &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1501                            (GtkSignalFunc) OpenLogo, NULL);
1502   gtk_toolbar_append_item (GTK_TOOLBAR (toolBar), NULL, _("Export to file"), NULL,
1503                            NewPixmap(Save_xpm, GUI_LogosWindow->window,
1504                            &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1505                            (GtkSignalFunc) SaveLogo, NULL);
1506
1507   gtk_toolbar_append_space (GTK_TOOLBAR (toolBar));
1508
1509   buttonStartup = gtk_toolbar_append_element(GTK_TOOLBAR(toolBar),
1510                   GTK_TOOLBAR_CHILD_RADIOBUTTON, NULL, NULL, _("Startup logo"),
1511                   "", NewPixmap(Startup_logo_xpm, GUI_LogosWindow->window,
1512                   &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1513                   GTK_SIGNAL_FUNC(LogoTypeEvent), NULL);
1514
1515   buttonOperator = gtk_toolbar_append_element(GTK_TOOLBAR(toolBar),
1516                   GTK_TOOLBAR_CHILD_RADIOBUTTON, buttonStartup, NULL, _("Operator logo"),
1517                   "", NewPixmap(Operator_logo_xpm, GUI_LogosWindow->window,
1518                   &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1519                   GTK_SIGNAL_FUNC(LogoTypeEvent), NULL);
1520
1521   buttonCaller = gtk_toolbar_append_element(GTK_TOOLBAR(toolBar),
1522                  GTK_TOOLBAR_CHILD_RADIOBUTTON,
1523                  buttonOperator,
1524                  NULL, _("Caller logo"),
1525                  "", NewPixmap(Caller_logo_xpm, GUI_LogosWindow->window,
1526                  &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1527                  GTK_SIGNAL_FUNC(LogoTypeEvent), NULL);
1528
1529   gtk_toolbar_append_space(GTK_TOOLBAR(toolBar));
1530   
1531   networkCombo = gtk_combo_new();
1532   gtk_combo_set_use_arrows_always(GTK_COMBO(networkCombo), 1);
1533   while (strcmp(GSM_Networks[i].Name, "unknown"))
1534     glistNetwork = g_list_insert_sorted(glistNetwork, GSM_Networks[i++].Name,
1535                    (GCompareFunc)strcmp);
1536   gtk_combo_set_popdown_strings(GTK_COMBO(networkCombo), glistNetwork);
1537   gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(networkCombo)->entry), FALSE);
1538   gtk_toolbar_append_widget(GTK_TOOLBAR(toolBar), networkCombo, "", "");
1539   gtk_widget_show(networkCombo);
1540   g_list_free(glistNetwork);
1541
1542   callerCombo = gtk_combo_new();
1543   gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(callerCombo)->entry), FALSE);
1544   gtk_toolbar_append_widget(GTK_TOOLBAR(toolBar), callerCombo, "", "");
1545   gtk_widget_show(callerCombo);
1546   
1547   gtk_box_pack_start(GTK_BOX(vbox), toolBar, FALSE, FALSE, 0);
1548   gtk_widget_show(toolBar); 
1549
1550   /* vertical separator */
1551   separator = gtk_hseparator_new();
1552   gtk_box_pack_start(GTK_BOX(vbox),GTK_WIDGET(separator),FALSE,FALSE,0);
1553   
1554   /* create horizontal box for preview and drawing areas */
1555   hbox = gtk_hbox_new(FALSE,5);
1556   gtk_box_pack_start(GTK_BOX(vbox),hbox,FALSE,FALSE,0);
1557   gtk_widget_show(hbox);
1558  
1559   /* set GSM_Bitmap width,height needed for creating drawinArea
1560    * we are starting, default is startupLogo
1561    */
1562   bitmap.type = GSM_StartupLogo;
1563   bitmap.height = 48;
1564   bitmap.width = 84;
1565   bitmap.size = bitmap.height * bitmap.width / 8;
1566   drawingAreaWidth = bitmap.width * (POINTSIZE+1)+1;
1567   drawingAreaHeight = bitmap.height * (POINTSIZE+1)+1;
1568  
1569   /* previewArea */
1570   previewPixmap = GetPreviewPixmap(GUI_LogosWindow);
1571
1572   if (previewPixmap != NULL) {
1573     previewArea = gtk_drawing_area_new();
1574     gtk_drawing_area_size(GTK_DRAWING_AREA(previewArea),
1575                           previewPixmapWidth,previewPixmapHeight);
1576     
1577     greenPixelPixmap = gdk_pixmap_create_from_xpm_d(GUI_LogosWindow->window,
1578                        &mask,&GUI_LogosWindow->style->bg[GTK_STATE_NORMAL],
1579                        Green_pixel_xpm);
1580
1581     gtk_signal_connect(GTK_OBJECT(previewArea),"expose_event",
1582                        (GtkSignalFunc)PreviewAreaExposeEvent,NULL);
1583     gtk_signal_connect(GTK_OBJECT(previewArea),"configure_event",
1584                        (GtkSignalFunc)PreviewAreaConfigureEvent,NULL);
1585     gtk_signal_connect(GTK_OBJECT(previewArea),"button_press_event",
1586                        (GtkSignalFunc)PreviewAreaButtonPressEvent,NULL);
1587
1588     gtk_widget_set_events(previewArea,GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK );
1589
1590     gtk_box_pack_start(GTK_BOX(hbox),previewArea,FALSE,FALSE,0);
1591     gtk_widget_show(previewArea);
1592     
1593     /* clear battery, signal, menu & names from preview phone */
1594     UpdatePreviewPoints (); 
1595
1596   } else previewAvailable = 0;
1597
1598   /* drawingArea */
1599   greenPointPixmap = gdk_pixmap_create_from_xpm_d(GUI_LogosWindow->window,
1600                   &mask,&GUI_LogosWindow->style->bg[GTK_STATE_NORMAL],Green_point_xpm);
1601   blackPointPixmap = gdk_pixmap_create_from_xpm_d(GUI_LogosWindow->window,
1602                   &mask,&GUI_LogosWindow->style->bg[GTK_STATE_NORMAL],Black_point_xpm);
1603   
1604   drawingBox = gtk_vbox_new(FALSE,3);
1605   gtk_box_pack_start(GTK_BOX(hbox),drawingBox,FALSE,FALSE,0);
1606   gtk_widget_show(drawingBox);
1607
1608   drawingArea = gtk_drawing_area_new();
1609   gtk_drawing_area_size(GTK_DRAWING_AREA(drawingArea),
1610                   drawingAreaWidth,drawingAreaHeight);
1611
1612   gtk_signal_connect(GTK_OBJECT(drawingArea),"configure_event",
1613                   (GtkSignalFunc)DrawingAreaConfigureEvent,NULL);
1614   gtk_signal_connect(GTK_OBJECT(drawingArea),"expose_event",
1615                   (GtkSignalFunc)DrawingAreaExposeEvent,NULL);
1616   gtk_signal_connect(GTK_OBJECT(drawingArea),"button_press_event",
1617                   (GtkSignalFunc)DrawingAreaButtonPressEvent,NULL);
1618   gtk_signal_connect(GTK_OBJECT(drawingArea),"button_release_event",
1619                   (GtkSignalFunc)DrawingAreaButtonReleaseEvent,NULL);
1620   gtk_signal_connect(GTK_OBJECT(drawingArea),"motion_notify_event",
1621                   (GtkSignalFunc)DrawingAreaMotionNotifyEvent,NULL);
1622   
1623   gtk_widget_set_events(drawingArea,GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK |
1624                   GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | 
1625                   GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
1626
1627   gtk_box_pack_start(GTK_BOX(drawingBox),drawingArea,FALSE,FALSE,0);
1628   gtk_widget_show(drawingArea);
1629
1630   /* vertical tool bar */
1631   vertToolBar = gtk_toolbar_new(GTK_ORIENTATION_VERTICAL,GTK_TOOLBAR_ICONS);
1632   gtk_toolbar_set_button_relief(GTK_TOOLBAR(vertToolBar),GTK_RELIEF_NORMAL);
1633   gtk_toolbar_set_style(GTK_TOOLBAR(vertToolBar),GTK_TOOLBAR_ICONS);
1634
1635   buttonBrush = gtk_toolbar_append_element(GTK_TOOLBAR(vertToolBar),
1636                 GTK_TOOLBAR_CHILD_RADIOBUTTON, NULL, NULL, _("Brush tool"),
1637                 "", NewPixmap(Tool_brush_xpm, GUI_LogosWindow->window,
1638                 &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1639                 GTK_SIGNAL_FUNC(ToolTypeEvent), NULL);
1640
1641   buttonLine = gtk_toolbar_append_element(GTK_TOOLBAR(vertToolBar),
1642                GTK_TOOLBAR_CHILD_RADIOBUTTON, buttonBrush, NULL, _("Line tool"),
1643                "", NewPixmap(Tool_line_xpm, GUI_LogosWindow->window,
1644                &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1645                GTK_SIGNAL_FUNC(ToolTypeEvent), NULL);
1646
1647   buttonRectangle = gtk_toolbar_append_element(GTK_TOOLBAR(vertToolBar),
1648                     GTK_TOOLBAR_CHILD_RADIOBUTTON, buttonLine, NULL, _("Rectangle tool"),
1649                     "", NewPixmap(Tool_rectangle_xpm, GUI_LogosWindow->window,
1650                     &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1651                     GTK_SIGNAL_FUNC(ToolTypeEvent), NULL);
1652
1653   buttonFilledRectangle = gtk_toolbar_append_element(GTK_TOOLBAR(vertToolBar),
1654                           GTK_TOOLBAR_CHILD_RADIOBUTTON, buttonRectangle, NULL,
1655                           _("Filled rectangle tool"),
1656                           "", NewPixmap(Tool_filled_rectangle_xpm,
1657                           GUI_LogosWindow->window,
1658                           &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1659                           GTK_SIGNAL_FUNC(ToolTypeEvent), NULL);
1660
1661   gtk_toolbar_append_space(GTK_TOOLBAR(vertToolBar));
1662  
1663   gtk_toolbar_append_item(GTK_TOOLBAR(vertToolBar), NULL, _("Invert logo"), NULL,
1664                           NewPixmap(Edit_invert_xpm, GUI_LogosWindow->window,
1665                           &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1666                           (GtkSignalFunc)InvertLogoEvent, vertToolBar);
1667
1668   gtk_toolbar_append_item(GTK_TOOLBAR(vertToolBar), NULL, _("Horizontal flip"), NULL,
1669                           NewPixmap(Edit_flip_horizontal_xpm, GUI_LogosWindow->window,
1670                           &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1671                           (GtkSignalFunc)FlipHorizontalLogoEvent, vertToolBar);
1672
1673   gtk_toolbar_append_item(GTK_TOOLBAR(vertToolBar), NULL, _("Vertical flip"), NULL,
1674                           NewPixmap(Edit_flip_vertical_xpm, GUI_LogosWindow->window,
1675                           &GUI_LogosWindow->style->bg[GTK_STATE_NORMAL]),
1676                           (GtkSignalFunc)FlipVerticalLogoEvent, vertToolBar);
1677
1678   
1679   gtk_box_pack_start(GTK_BOX(hbox),vertToolBar,FALSE,FALSE,0);
1680   gtk_widget_show(vertToolBar);
1681
1682   GUIEventAdd(GUI_EVENT_CALLERS_GROUPS_CHANGED,&GUI_RefreshLogosGroupsCombo);
1683 }
1684
1685 void GUI_RefreshLogosGroupsCombo (void) {
1686   GList *callerList = NULL;
1687   int i;
1688   
1689   for (i = 0;i < 6;i++)
1690     callerList = g_list_insert(callerList,xgnokiiConfig.callerGroups[i],i);
1691   
1692   gtk_combo_set_popdown_strings(GTK_COMBO(callerCombo),callerList);
1693   g_list_free(callerList);
1694
1695   if (!callersGroupsInitialized) callersGroupsInitialized = 1;
1696 }
1697
1698 void GUI_ShowLogosWindow (void) {
1699   /* Set network name taken from the phone */
1700   GetNetworkInfoEvent(NULL);
1701   /* if phone support caller groups, read callerGroups names */
1702   if (phoneMonitor.supported & PM_CALLERGROUP) {
1703     if (xgnokiiConfig.callerGroups[0] == NULL) {
1704       GUI_Refresh(); 
1705       GUI_InitCallerGroupsInf ();
1706     }
1707     if (!callersGroupsInitialized) GUI_RefreshLogosGroupsCombo (); 
1708     gtk_widget_show(buttonCaller);
1709     gtk_widget_show(callerCombo); 
1710   } else {
1711     /* if not supported, hide widget for handling callerGroups */
1712     gtk_widget_hide(buttonCaller);
1713     gtk_widget_hide(callerCombo); 
1714   }        
1715
1716   /* Call to reset Startup logo size */
1717   LogoTypeEvent(GUI_LogosWindow);
1718
1719   gtk_widget_show(GUI_LogosWindow);
1720
1721   if (!previewAvailable && showPreviewErrorDialog) {
1722     gchar *buf = g_strdup(_("Load preview pixmap error, feature disabled."));
1723     gtk_label_set_text(GTK_LABEL(errorDialog.text),buf);
1724     gtk_widget_show(errorDialog.dialog);
1725     g_free(buf);
1726
1727     showPreviewErrorDialog = 0;
1728   }
1729 }