3 Minimum Profit - Programmer Text Editor
7 Copyright (C) 1991-2009 Angel Ortega <angel@triptico.com>
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 http://www.triptico.com
39 #include <gdk/gdkkeysyms.h>
52 static GtkWidget
* window
= NULL
;
53 static GtkWidget
* file_tabs
= NULL
;
54 static GtkWidget
* area
= NULL
;
55 static GtkWidget
* scrollbar
= NULL
;
56 static GtkWidget
* status
= NULL
;
57 static GtkWidget
* menu_bar
= NULL
;
58 static GdkGC
* gc
= NULL
;
59 static GtkIMContext
* im
= NULL
;
60 static GdkPixmap
* pixmap
= NULL
;
62 /* character read from the keyboard */
63 static wchar_t im_char
[2];
65 /* font information */
66 static int font_width
= 0;
67 static int font_height
= 0;
68 static PangoFontDescription
* font
= NULL
;
71 static GdkColor
* inks
= NULL
;
72 static GdkColor
* papers
= NULL
;
73 static int * underlines
= NULL
;
75 /* true if the selection is ours */
76 static int got_selection
= 0;
78 /* hack for active waiting for the selection */
79 static int wait_for_selection
= 0;
81 /* global modal status */
82 /* code for the 'normal' attribute */
83 static int normal_attr
= 0;
85 /* mp.drv.form() controls */
87 static GtkWidget
** form_widgets
= NULL
;
88 static mpdm_t form_args
= NULL
;
89 static mpdm_t form_values
= NULL
;
92 static int mouse_down
= 0;
95 static mpdm_t timer_func
= NULL
;
97 /* maximize wanted? */
98 static int maximize
= 0;
102 /** support functions **/
106 static char * wcs_to_utf8(const wchar_t * wptr
)
107 /* converts a wcs to utf-8 */
114 /* do the conversion */
115 ptr
= g_convert((const gchar
*) wptr
, (i
+ 1) * sizeof(wchar_t),
116 "UTF-8", "WCHAR_T", NULL
, &o
, NULL
);
122 static wchar_t * utf8_to_wcs(const char * ptr
)
123 /* converts utf-8 to wcs */
130 /* do the conversion */
131 wptr
= (wchar_t *) g_convert((gchar
*) ptr
, i
+ 1,
132 "WCHAR_T", "UTF-8", NULL
, &o
, NULL
);
138 static char * localize(char * msg
)
142 v
= mpdm_gettext(MPDM_MBS(msg
));
143 return wcs_to_utf8(v
->data
);
147 static void update_window_size(void)
148 /* updates the viewport size in characters */
154 /* get font metrics */
155 pa
= gtk_widget_create_pango_layout(area
, "m");
156 pango_layout_set_font_description(pa
, font
);
157 pango_layout_get_pixel_size(pa
, &font_width
, &font_height
);
160 /* calculate the size in chars */
161 tx
= (area
->allocation
.width
/ font_width
);
162 ty
= (area
->allocation
.height
/ font_height
) + 1;
164 /* store the 'window' size */
165 v
= mpdm_hget_s(mp
, L
"window");
166 mpdm_hset_s(v
, L
"tx", MPDM_I(tx
));
167 mpdm_hset_s(v
, L
"ty", MPDM_I(ty
));
169 /* rebuild the pixmap for the double buffer */
171 gdk_pixmap_unref(pixmap
);
173 pixmap
= gdk_pixmap_new(area
->window
,
174 area
->allocation
.width
, font_height
, -1);
178 static void build_fonts(void)
179 /* builds the fonts */
183 const char * font_face
= "Mono";
187 pango_font_description_free(font
);
189 /* get current configuration */
190 if ((c
= mpdm_hget_s(mp
, L
"config")) != NULL
) {
193 if ((v
= mpdm_hget_s(c
, L
"font_size")) != NULL
)
194 font_size
= mpdm_ival(v
);
196 mpdm_hset_s(c
, L
"font_size", MPDM_I(font_size
));
198 if ((v
= mpdm_hget_s(c
, L
"font_face")) != NULL
) {
199 v
= MPDM_2MBS(v
->data
);
203 mpdm_hset_s(c
, L
"font_face", MPDM_MBS(font_face
));
206 snprintf(tmp
, sizeof(tmp
) - 1, "%s %d", font_face
, font_size
);
207 tmp
[sizeof(tmp
) - 1] = '\0';
209 font
= pango_font_description_from_string(tmp
);
210 update_window_size();
214 static void build_color(GdkColor
* gdkcolor
, int rgb
)
218 gdkcolor
->blue
= (rgb
& 0x000000ff) << 8;
219 gdkcolor
->green
= (rgb
& 0x0000ff00);
220 gdkcolor
->red
= (rgb
& 0x00ff0000) >> 8;
221 gdk_colormap_alloc_color(gdk_colormap_get_system(), gdkcolor
, FALSE
, TRUE
);
225 static void build_colors(void)
226 /* builds the colors */
233 /* gets the color definitions and attribute names */
234 colors
= mpdm_hget_s(mp
, L
"colors");
235 l
= mpdm_keys(colors
);
238 /* redim the structures */
239 inks
= realloc(inks
, sizeof(GdkColor
) * s
);
240 papers
= realloc(papers
, sizeof(GdkColor
) * s
);
241 underlines
= realloc(underlines
, sizeof(int) * s
);
243 /* loop the colors */
244 for (n
= 0; n
< s
&& (c
= mpdm_aget(l
, n
)) != NULL
; n
++) {
245 mpdm_t d
= mpdm_hget(colors
, c
);
246 mpdm_t v
= mpdm_hget_s(d
, L
"gui");
248 /* store the 'normal' attribute */
249 if (wcscmp(mpdm_string(c
), L
"normal") == 0)
253 mpdm_hset_s(d
, L
"attr", MPDM_I(n
));
255 build_color(&inks
[n
], mpdm_ival(mpdm_aget(v
, 0)));
256 build_color(&papers
[n
], mpdm_ival(mpdm_aget(v
, 1)));
259 v
= mpdm_hget_s(d
, L
"flags");
260 underlines
[n
] = mpdm_seek_s(v
, L
"underline", 1) != -1 ? 1 : 0;
262 if (mpdm_seek_s(v
, L
"reverse", 1) != -1) {
273 /** menu functions **/
275 static void redraw(void);
277 static void menu_item_callback(mpdm_t action
)
278 /* menu click callback */
280 mp_process_action(action
);
283 if (mp_exit_requested
)
288 static void build_submenu(GtkWidget
* menu
, mpdm_t labels
)
289 /* build a submenu */
292 GtkWidget
* menu_item
;
294 for (n
= 0; n
< mpdm_size(labels
); n
++) {
296 mpdm_t v
= mpdm_aget(labels
, n
);
298 /* if the action is a separator... */
299 if (*((wchar_t *)v
->data
) == L
'-')
300 menu_item
= gtk_menu_item_new();
303 mpdm_t d
= mp_menu_label(v
);
305 ptr
= wcs_to_utf8(mpdm_string(d
));
306 menu_item
= gtk_menu_item_new_with_label(ptr
);
310 gtk_menu_append(GTK_MENU(menu
), menu_item
);
311 g_signal_connect_swapped(G_OBJECT(menu_item
), "activate",
312 G_CALLBACK(menu_item_callback
), v
);
313 gtk_widget_show(menu_item
);
318 static void build_menu(void)
319 /* builds the menu */
321 static mpdm_t prev_menu
= NULL
;
325 /* gets the current menu */
326 if ((m
= mpdm_hget_s(mp
, L
"menu")) == NULL
)
329 /* if it's the same, do nothing */
330 if (mpdm_cmp(m
, prev_menu
) == 0)
333 /* create a new menu */
334 menu_bar
= gtk_menu_bar_new();
336 for (n
= 0; n
< mpdm_size(m
); n
++) {
341 GtkWidget
* menu_item
;
344 /* get the label and the items */
345 mi
= mpdm_aget(m
, n
);
346 v
= mpdm_aget(mi
, 0);
348 if ((ptr
= wcs_to_utf8(mpdm_string(mpdm_gettext(v
)))) == NULL
)
351 /* change the & by _ for the mnemonic */
352 for (i
= 0; ptr
[i
]; i
++)
356 /* add the menu and the label */
357 menu
= gtk_menu_new();
358 menu_item
= gtk_menu_item_new_with_mnemonic(ptr
);
361 gtk_widget_show(menu_item
);
362 gtk_menu_item_set_submenu(GTK_MENU_ITEM(menu_item
), menu
);
363 gtk_menu_bar_append(GTK_MENU_BAR(menu_bar
), menu_item
);
365 /* now loop the items */
366 build_submenu(menu
, mpdm_aget(mi
, 1));
371 /** main area drawing functions **/
373 static void switch_page(GtkNotebook
* notebook
, GtkNotebookPage
* page
,
374 gint pg_num
, gpointer data
)
375 /* 'switch_page' handler (filetabs) */
377 /* sets the active one */
378 mpdm_hset_s(mp
, L
"active_i", MPDM_I(pg_num
));
380 gtk_widget_grab_focus(area
);
385 static void draw_filetabs(void)
386 /* draws the filetabs */
388 static mpdm_t last
= NULL
;
392 names
= mp_get_doc_names();
394 /* disconnect redraw signal to avoid infinite loops */
395 g_signal_handlers_disconnect_by_func(G_OBJECT(file_tabs
),
396 G_CALLBACK(switch_page
), NULL
);
398 /* is the list different from the previous one? */
399 if (mpdm_cmp(names
, last
) != 0) {
401 /* delete the current tabs */
402 for (n
= 0; n
< mpdm_size(last
); n
++)
403 gtk_notebook_remove_page(
404 GTK_NOTEBOOK(file_tabs
), 0);
406 /* create the new ones */
407 for (n
= 0; n
< mpdm_size(names
); n
++) {
411 mpdm_t v
= mpdm_aget(names
, n
);
413 if ((ptr
= wcs_to_utf8(v
->data
)) != NULL
) {
414 p
= gtk_label_new(ptr
);
417 f
= gtk_frame_new(NULL
);
420 gtk_notebook_append_page(
421 GTK_NOTEBOOK(file_tabs
), f
, p
);
427 /* store for the next time */
429 last
= mpdm_ref(names
);
432 /* set the active one */
433 gtk_notebook_set_page(GTK_NOTEBOOK(file_tabs
),
434 mpdm_ival(mpdm_hget_s(mp
, L
"active_i")));
436 /* reconnect signal */
437 g_signal_connect(G_OBJECT(file_tabs
), "switch_page",
438 G_CALLBACK(switch_page
), NULL
);
440 gtk_widget_grab_focus(area
);
444 static void draw_status(void)
445 /* draws the status line */
450 /* call mp.status_line() */
451 t
= mp_build_status_line();
453 if (t
!= NULL
&& (ptr
= wcs_to_utf8(t
->data
)) != NULL
) {
454 gtk_label_set_text(GTK_LABEL(status
), ptr
);
460 static gint
scroll_event(GtkWidget
* widget
, GdkEventScroll
* event
)
461 /* 'scroll_event' handler (mouse wheel) */
463 wchar_t * ptr
= NULL
;
465 switch (event
->direction
) {
466 case GDK_SCROLL_UP
: ptr
= L
"mouse-wheel-up"; break;
467 case GDK_SCROLL_DOWN
: ptr
= L
"mouse-wheel-down"; break;
468 case GDK_SCROLL_LEFT
: ptr
= L
"mouse-wheel-left"; break;
469 case GDK_SCROLL_RIGHT
: ptr
= L
"mouse-wheel-right"; break;
473 mp_process_event(MPDM_S(ptr
));
481 static void value_changed(GtkAdjustment
* adj
, gpointer
* data
)
482 /* 'value_changed' handler (scrollbar) */
484 int i
= (int) adj
->value
;
489 /* get current y position */
491 txt
= mpdm_hget_s(doc
, L
"txt");
492 y
= mpdm_ival(mpdm_hget_s(txt
, L
"y"));
494 /* if it's different, set and redraw */
497 mpdm_hset_s(txt
, L
"vy", MPDM_I(i
));
503 static void draw_scrollbar(void)
504 /* updates the scrollbar */
506 GtkAdjustment
* adjustment
;
511 /* gets the active document */
512 if ((d
= mp_active()) == NULL
)
515 /* get the coordinates */
516 v
= mpdm_hget_s(d
, L
"txt");
517 pos
= mpdm_ival(mpdm_hget_s(v
, L
"vy"));
518 max
= mpdm_size(mpdm_hget_s(v
, L
"lines"));
520 v
= mpdm_hget_s(mp
, L
"window");
521 size
= mpdm_ival(mpdm_hget_s(v
, L
"ty"));
523 adjustment
= gtk_range_get_adjustment(GTK_RANGE(scrollbar
));
525 /* if((int)adjustment->upper==max &&
526 (int)adjustment->page_size==size &&
527 (int)adjustment->page_increment==size &&
528 (int)adjustment->value==pos)
531 /* disconnect to avoid infinite loops */
532 g_signal_handlers_disconnect_by_func(G_OBJECT(adjustment
),
533 G_CALLBACK(value_changed
), NULL
);
535 adjustment
->step_increment
= (gfloat
)1;
536 adjustment
->upper
= (gfloat
)max
;
537 adjustment
->page_size
= (gfloat
)size
;
538 adjustment
->page_increment
= (gfloat
)size
;
539 adjustment
->value
= (gfloat
)pos
;
541 gtk_range_set_adjustment(GTK_RANGE(scrollbar
), adjustment
);
543 gtk_adjustment_changed(adjustment
);
544 gtk_adjustment_value_changed(adjustment
);
548 G_OBJECT(gtk_range_get_adjustment(GTK_RANGE(scrollbar
))),
549 "value_changed", G_CALLBACK(value_changed
), NULL
);
553 static void gtk_drv_paint(mpdm_t doc
, int optimize
)
554 /* GTK document draw function */
561 gtk_window_maximize(GTK_WINDOW(window
));
563 /* no gc? create it */
565 gc
= gdk_gc_new(area
->window
);
570 if ((d
= mp_draw(doc
, optimize
)) == NULL
)
575 gr
.width
= area
->allocation
.width
;
576 gr
.height
= font_height
;
578 for (n
= 0; n
< mpdm_size(d
); n
++) {
581 mpdm_t l
= mpdm_aget(d
, n
);
588 /* create the pango stuff */
589 pl
= gtk_widget_create_pango_layout(area
, NULL
);
590 pango_layout_set_font_description(pl
, font
);
591 pal
= pango_attr_list_new();
593 for (m
= u
= p
= 0; m
< mpdm_size(l
); m
++, u
= p
) {
599 /* get the attribute and the string */
600 attr
= mpdm_ival(mpdm_aget(l
, m
++));
603 /* convert the string to utf8 */
604 ptr
= wcs_to_utf8(s
->data
);
606 /* add to the full line */
607 str
= mpdm_poke(str
, &p
, ptr
, strlen(ptr
), 1);
611 /* create the background if it's
612 different from the default */
613 if (papers
[attr
].red
!= papers
[normal_attr
].red
||
614 papers
[attr
].green
!= papers
[normal_attr
].green
||
615 papers
[attr
].blue
!= papers
[normal_attr
].blue
) {
616 pa
= pango_attr_background_new(
617 papers
[attr
].red
, papers
[attr
].green
,
623 pango_attr_list_insert(pal
, pa
);
627 if (underlines
[attr
]) {
628 pa
= pango_attr_underline_new(TRUE
);
633 pango_attr_list_insert(pal
, pa
);
636 /* foreground color */
637 pa
= pango_attr_foreground_new(inks
[attr
].red
,
638 inks
[attr
].green
, inks
[attr
].blue
);
643 pango_attr_list_insert(pal
, pa
);
646 /* store the attributes */
647 pango_layout_set_attributes(pl
, pal
);
648 pango_attr_list_unref(pal
);
650 /* store and free the text */
651 pango_layout_set_text(pl
, str
, p
);
654 /* draw the background */
655 gdk_gc_set_foreground(gc
, &papers
[normal_attr
]);
656 gdk_draw_rectangle(pixmap
, gc
, TRUE
, 0, 0,
657 gr
.width
, gr
.height
);
660 gtk_paint_layout(area
->style
, pixmap
,
661 GTK_STATE_NORMAL
, TRUE
,
662 &gr
, area
, "", 2, 0, pl
);
664 /* dump the pixmap */
665 gdk_draw_pixmap(area
->window
, gc
, pixmap
,
666 0, 0, 0, n
* font_height
, gr
.width
, gr
.height
);
677 static void redraw(void)
679 if (mpdm_size(mpdm_hget_s(mp
, L
"docs")))
680 gtk_drv_paint(mp_active(), 0);
684 static gint
delete_event(GtkWidget
* w
, GdkEvent
* e
, gpointer data
)
685 /* 'delete_event' handler */
687 mp_process_event(MPDM_LS(L
"close-window"));
689 return mp_exit_requested
? FALSE
: TRUE
;
693 static void destroy(GtkWidget
* w
, gpointer data
)
694 /* 'destroy' handler */
700 static gint
key_release_event(GtkWidget
* widget
, GdkEventKey
* event
, gpointer data
)
701 /* 'key_release_event' handler */
703 if (mp_keypress_throttle(0))
704 gtk_drv_paint(mp_active(), 0);
710 static gint
key_press_event(GtkWidget
* widget
, GdkEventKey
* event
, gpointer data
)
711 /* 'key_press_event' handler */
713 wchar_t * ptr
= NULL
;
715 gtk_im_context_filter_keypress(im
, event
);
717 /* set mp.shift_pressed */
718 if (event
->state
& (GDK_SHIFT_MASK
))
719 mpdm_hset_s(mp
, L
"shift_pressed", MPDM_I(1));
721 /* reserve alt for menu mnemonics */
722 if (GDK_MOD1_MASK
& event
->state
)
725 if (event
->state
& (GDK_CONTROL_MASK
)) {
726 switch (event
->keyval
) {
727 case GDK_Up
: ptr
= L
"ctrl-cursor-up"; break;
728 case GDK_Down
: ptr
= L
"ctrl-cursor-down"; break;
729 case GDK_Left
: ptr
= L
"ctrl-cursor-left"; break;
730 case GDK_Right
: ptr
= L
"ctrl-cursor-right"; break;
731 case GDK_Prior
: ptr
= L
"ctrl-page-up"; break;
732 case GDK_Next
: ptr
= L
"ctrl-page-down"; break;
733 case GDK_Home
: ptr
= L
"ctrl-home"; break;
734 case GDK_End
: ptr
= L
"ctrl-end"; break;
735 case GDK_space
: ptr
= L
"ctrl-space"; break;
736 case GDK_KP_Add
: ptr
= L
"ctrl-kp-plus"; break;
737 case GDK_KP_Subtract
: ptr
= L
"ctrl-kp-minus"; break;
738 case GDK_KP_Multiply
: ptr
= L
"ctrl-kp-multiply"; break;
739 case GDK_KP_Divide
: ptr
= L
"ctrl-kp-divide"; break;
740 case GDK_F1
: ptr
= L
"ctrl-f1"; break;
741 case GDK_F2
: ptr
= L
"ctrl-f2"; break;
742 case GDK_F3
: ptr
= L
"ctrl-f3"; break;
743 case GDK_F4
: ptr
= L
"ctrl-f4"; break;
744 case GDK_F5
: ptr
= L
"ctrl-f5"; break;
745 case GDK_F6
: ptr
= L
"ctrl-f6"; break;
746 case GDK_F7
: ptr
= L
"ctrl-f7"; break;
747 case GDK_F8
: ptr
= L
"ctrl-f8"; break;
748 case GDK_F9
: ptr
= L
"ctrl-f9"; break;
749 case GDK_F10
: ptr
= L
"ctrl-f10"; break;
750 case GDK_F11
: ptr
= L
"ctrl-f11"; break;
751 case GDK_F12
: ptr
= L
"ctrl-f12"; break;
753 case GDK_Return
: ptr
= L
"ctrl-enter"; break;
757 char c
= event
->keyval
& 0xdf;
760 case 'A': ptr
= L
"ctrl-a"; break;
761 case 'B': ptr
= L
"ctrl-b"; break;
762 case 'C': ptr
= L
"ctrl-c"; break;
763 case 'D': ptr
= L
"ctrl-d"; break;
764 case 'E': ptr
= L
"ctrl-e"; break;
765 case 'F': ptr
= L
"ctrl-f"; break;
766 case 'G': ptr
= L
"ctrl-g"; break;
767 case 'H': ptr
= L
"ctrl-h"; break;
768 case 'I': ptr
= L
"ctrl-i"; break;
769 case 'J': ptr
= L
"ctrl-j"; break;
770 case 'K': ptr
= L
"ctrl-k"; break;
771 case 'L': ptr
= L
"ctrl-l"; break;
772 case 'M': ptr
= L
"ctrl-m"; break;
773 case 'N': ptr
= L
"ctrl-n"; break;
774 case 'O': ptr
= L
"ctrl-o"; break;
775 case 'P': ptr
= L
"ctrl-p"; break;
776 case 'Q': ptr
= L
"ctrl-q"; break;
777 case 'R': ptr
= L
"ctrl-r"; break;
778 case 'S': ptr
= L
"ctrl-s"; break;
779 case 'T': ptr
= L
"ctrl-t"; break;
780 case 'U': ptr
= L
"ctrl-u"; break;
781 case 'V': ptr
= L
"ctrl-v"; break;
782 case 'W': ptr
= L
"ctrl-w"; break;
783 case 'X': ptr
= L
"ctrl-x"; break;
784 case 'Y': ptr
= L
"ctrl-y"; break;
785 case 'Z': ptr
= L
"ctrl-z"; break;
790 switch (event
->keyval
) {
791 case GDK_Up
: ptr
= L
"cursor-up"; break;
792 case GDK_Down
: ptr
= L
"cursor-down"; break;
793 case GDK_Left
: ptr
= L
"cursor-left"; break;
794 case GDK_Right
: ptr
= L
"cursor-right"; break;
795 case GDK_Prior
: ptr
= L
"page-up"; break;
796 case GDK_Next
: ptr
= L
"page-down"; break;
797 case GDK_Home
: ptr
= L
"home"; break;
798 case GDK_End
: ptr
= L
"end"; break;
799 case GDK_space
: ptr
= L
"space"; break;
800 case GDK_KP_Add
: ptr
= L
"kp-plus"; break;
801 case GDK_KP_Subtract
: ptr
= L
"kp-minus"; break;
802 case GDK_KP_Multiply
: ptr
= L
"kp-multiply"; break;
803 case GDK_KP_Divide
: ptr
= L
"kp-divide"; break;
804 case GDK_F1
: ptr
= L
"f1"; break;
805 case GDK_F2
: ptr
= L
"f2"; break;
806 case GDK_F3
: ptr
= L
"f3"; break;
807 case GDK_F4
: ptr
= L
"f4"; break;
808 case GDK_F5
: ptr
= L
"f5"; break;
809 case GDK_F6
: ptr
= L
"f6"; break;
810 case GDK_F7
: ptr
= L
"f7"; break;
811 case GDK_F8
: ptr
= L
"f8"; break;
812 case GDK_F9
: ptr
= L
"f9"; break;
813 case GDK_F10
: ptr
= L
"f10"; break;
814 case GDK_F11
: ptr
= L
"f11"; break;
815 case GDK_F12
: ptr
= L
"f12"; break;
816 case GDK_Insert
: ptr
= L
"insert"; break;
817 case GDK_BackSpace
: ptr
= L
"backspace"; break;
818 case GDK_Delete
: ptr
= L
"delete"; break;
820 case GDK_Return
: ptr
= L
"enter"; break;
821 case GDK_Tab
: ptr
= L
"tab"; break;
822 case GDK_Escape
: ptr
= L
"escape"; break;
826 /* if there is a pending char in im_char, use it */
827 if (ptr
== NULL
&& im_char
[0] != L
'\0')
830 /* finally process */
832 mp_process_event(MPDM_S(ptr
));
834 /* delete the pending char */
837 if (mp_exit_requested
)
840 if (mp_keypress_throttle(1))
841 gtk_drv_paint(mp_active(), 1);
847 static gint
button_press_event(GtkWidget
* widget
, GdkEventButton
* event
, gpointer data
)
848 /* 'button_press_event' handler (mouse buttons) */
851 wchar_t * ptr
= NULL
;
855 /* mouse instant positioning */
856 x
= ((int)event
->x
) / font_width
;
857 y
= ((int)event
->y
) / font_height
;
859 mpdm_hset_s(mp
, L
"mouse_x", MPDM_I(x
));
860 mpdm_hset_s(mp
, L
"mouse_y", MPDM_I(y
));
862 switch (event
->button
) {
863 case 1: ptr
= L
"mouse-left-button"; break;
864 case 2: ptr
= L
"mouse-middle-button"; break;
865 case 3: ptr
= L
"mouse-right-button"; break;
866 case 4: ptr
= L
"mouse-wheel-up"; break;
867 case 5: ptr
= L
"mouse-wheel-down"; break;
871 mp_process_event(MPDM_S(ptr
));
879 static gint
button_release_event(GtkWidget
* widget
, GdkEventButton
* event
, gpointer data
)
880 /* 'button_release_event' handle (mouse buttons) */
888 static gint
motion_notify_event(GtkWidget
*widget
, GdkEventMotion
* event
, gpointer data
)
889 /* 'motion_notify_event' handler (mouse movement) */
898 x
= ((int)event
->x
) / font_width
;
899 y
= ((int)event
->y
) / font_height
;
901 if (ox
!= x
&& oy
!= y
) {
902 mpdm_hset_s(mp
, L
"mouse_to_x", MPDM_I(x
));
903 mpdm_hset_s(mp
, L
"mouse_to_y", MPDM_I(y
));
905 mp_process_event(MPDM_LS(L
"mouse-drag"));
906 gtk_drv_paint(mp_active(), 1);
914 /** clipboard functions **/
916 static void commit(GtkIMContext
* i
, char * str
, gpointer u
)
917 /* 'commit' handler */
921 wstr
= (wchar_t *) g_convert(str
, -1,
922 "WCHAR_T", "UTF-8", NULL
, NULL
, NULL
);
931 static void realize(GtkWidget
* widget
)
932 /* 'realize' handler */
934 im
= gtk_im_multicontext_new();
935 g_signal_connect(im
, "commit", G_CALLBACK(commit
), NULL
);
936 gtk_im_context_set_client_window(im
, widget
->window
);
940 static gint
expose_event(GtkWidget
* widget
, GdkEventExpose
* event
)
941 /* 'expose_event' handler */
949 static gint
configure_event(GtkWidget
* widget
, GdkEventConfigure
* event
)
950 /* 'configure_event' handler */
952 static GdkEventConfigure o
;
954 if (memcmp(&o
, event
, sizeof(o
)) == 0)
957 memcpy(&o
, event
, sizeof(o
));
959 update_window_size();
966 static gint
selection_clear_event(GtkWidget
* widget
,
967 GdkEventSelection
* event
, gpointer data
)
968 /* 'selection_clear_event' handler */
976 static void selection_get(GtkWidget
* widget
,
977 GtkSelectionData
* sel
, guint info
, guint tm
)
978 /* 'selection_get' handler */
987 /* gets the clipboard and joins */
988 d
= mpdm_hget_s(mp
, L
"clipboard");
989 d
= mpdm_join(MPDM_LS(L
"\n"), d
);
991 /* convert to current locale */
992 ptr
= (unsigned char *) mpdm_wcstombs(d
->data
, &s
);
994 /* pastes into primary selection */
995 gtk_selection_data_set(sel
, GDK_SELECTION_TYPE_STRING
, 8, ptr
, (gsize
) s
);
1001 static void selection_received(GtkWidget
* widget
,
1002 GtkSelectionData
* sel
, gpointer data
)
1003 /* 'selection_received' handler */
1007 if (sel
->data
!= NULL
) {
1009 wchar_t * wptr
= utf8_to_wcs((char *)sel
->data
);
1013 /* split and set as the clipboard */
1014 mpdm_hset_s(mp
, L
"clipboard", mpdm_split(MPDM_LS(L
"\n"), d
));
1015 mpdm_hset_s(mp
, L
"clipboard_vertical", MPDM_I(0));
1017 /* wait no more for the selection */
1018 wait_for_selection
= 0;
1021 wait_for_selection
= -1;
1025 static mpdm_t
gtk_drv_clip_to_sys(mpdm_t a
)
1026 /* driver-dependent mp to system clipboard */
1028 got_selection
= gtk_selection_owner_set(area
,
1029 GDK_SELECTION_PRIMARY
, GDK_CURRENT_TIME
);
1035 static mpdm_t
gtk_drv_sys_to_clip(mpdm_t a
)
1036 /* driver-dependent system to mp clipboard */
1038 if (!got_selection
) {
1040 char * formats
[] = { "UTF8_STRING", "STRING", NULL
};
1042 for(n
= 0; formats
[n
] != NULL
; n
++) {
1044 /* triggers a selection capture */
1045 if (gtk_selection_convert(area
, GDK_SELECTION_PRIMARY
,
1046 gdk_atom_intern(formats
[n
], FALSE
),
1047 GDK_CURRENT_TIME
)) {
1049 /* processes the pending events
1050 (i.e., the 'selection_received' handler) */
1051 wait_for_selection
= 1;
1053 while(wait_for_selection
== 1)
1054 gtk_main_iteration();
1056 if (!wait_for_selection
)
1066 /** interface functions **/
1068 static void clicked_ok(GtkWidget
* widget
, gpointer data
)
1069 /* 'clicked_on' signal handler (for gtk_drv_form) */
1073 for (n
= 0; n
< mpdm_size(form_args
); n
++) {
1074 GtkWidget
* widget
= form_widgets
[n
];
1075 mpdm_t w
= mpdm_aget(form_args
, n
);
1076 wchar_t * wptr
= mpdm_string(mpdm_hget_s(w
, L
"type"));
1079 /* if there is already a value there, if was
1080 previously set from a callback */
1081 if (mpdm_aget(form_values
, n
) != NULL
)
1084 if (wcscmp(wptr
, L
"text") == 0 ||
1085 wcscmp(wptr
, L
"password") == 0) {
1087 GtkWidget
* gw
= widget
;
1090 if (wcscmp(wptr
, L
"text") == 0)
1091 gw
= GTK_COMBO(widget
)->entry
;
1093 if ((ptr
= gtk_editable_get_chars(
1094 GTK_EDITABLE(gw
), 0, -1)) != NULL
&&
1095 (wptr
= utf8_to_wcs(ptr
)) != NULL
) {
1101 /* if it has history, fill it */
1102 if ((h
= mpdm_hget_s(w
, L
"history")) != NULL
&&
1103 v
!= NULL
&& mpdm_cmp(v
, MPDM_LS(L
"")) != 0) {
1104 h
= mp_get_history(h
);
1106 if (mpdm_cmp(v
, mpdm_aget(h
, -1)) != 0)
1111 if (wcscmp(wptr
, L
"checkbox") == 0) {
1112 v
= MPDM_I(gtk_toggle_button_get_active(
1113 GTK_TOGGLE_BUTTON(widget
)));
1116 if (wcscmp(wptr
, L
"list") == 0) {
1117 GtkWidget
* list
= gtk_bin_get_child(GTK_BIN(widget
));
1118 GtkTreeSelection
* selection
=
1119 gtk_tree_view_get_selection(GTK_TREE_VIEW(list
));
1120 GList
* selected
= gtk_tree_selection_get_selected_rows(selection
, NULL
);
1121 GtkTreePath
* path
= selected
->data
;
1123 v
= MPDM_I(gtk_tree_path_get_indices(path
)[0]);
1124 gtk_tree_path_free(path
);
1125 g_list_free(selected
);
1129 mpdm_aset(form_values
, v
, n
);
1134 static gint
timer_callback(gpointer data
)
1136 mpdm_exec(timer_func
, NULL
);
1143 static void build_form_data(mpdm_t widget_list
)
1144 /* builds the necessary information for a list of widgets */
1146 mpdm_unref(form_args
);
1147 form_args
= mpdm_ref(widget_list
);
1149 mpdm_unref(form_values
);
1150 form_values
= widget_list
== NULL
? NULL
:
1151 mpdm_ref(MPDM_A(mpdm_size(form_args
)));
1153 /* resize the widget array */
1154 form_widgets
= (GtkWidget
**) realloc(form_widgets
,
1155 mpdm_size(form_args
) * sizeof(GtkWidget
*));
1159 /** dialog functions **/
1161 #define DIALOG_BUTTON(l,f) do { GtkWidget * btn; \
1162 ptr = localize(l); btn = gtk_button_new_with_label(ptr); \
1163 g_signal_connect_swapped(G_OBJECT(btn), "clicked", \
1164 G_CALLBACK(f), G_OBJECT(dlg)); \
1165 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->action_area), \
1166 btn, TRUE, TRUE, 0); \
1170 static mpdm_t
gtk_drv_alert(mpdm_t a
)
1171 /* alert driver function */
1177 build_form_data(NULL
);
1179 /* 1# arg: prompt */
1180 wptr
= mpdm_string(mpdm_aget(a
, 0));
1182 if ((ptr
= wcs_to_utf8(wptr
)) == NULL
)
1185 dlg
= gtk_message_dialog_new(GTK_WINDOW(window
), GTK_DIALOG_MODAL
,
1186 GTK_MESSAGE_WARNING
, GTK_BUTTONS_OK
, ptr
);
1187 gtk_window_set_title(GTK_WINDOW(dlg
), "mp " VERSION
);
1190 gtk_dialog_run(GTK_DIALOG(dlg
));
1191 gtk_widget_destroy(dlg
);
1197 static mpdm_t
gtk_drv_confirm(mpdm_t a
)
1198 /* confirm driver function */
1205 build_form_data(NULL
);
1207 /* 1# arg: prompt */
1208 wptr
= mpdm_string(mpdm_aget(a
, 0));
1210 if ((ptr
= wcs_to_utf8(wptr
)) == NULL
)
1213 dlg
= gtk_message_dialog_new(GTK_WINDOW(window
), GTK_DIALOG_MODAL
,
1214 GTK_MESSAGE_QUESTION
, GTK_BUTTONS_NONE
, ptr
);
1215 gtk_window_set_title(GTK_WINDOW(dlg
), "mp " VERSION
);
1218 gtk_dialog_add_button(GTK_DIALOG(dlg
), GTK_STOCK_YES
, 1);
1219 gtk_dialog_add_button(GTK_DIALOG(dlg
), GTK_STOCK_NO
, 2);
1220 gtk_dialog_add_button(GTK_DIALOG(dlg
), GTK_STOCK_CANCEL
, 0);
1222 response
= gtk_dialog_run(GTK_DIALOG(dlg
));
1223 gtk_widget_destroy(dlg
);
1225 if (response
== GTK_RESPONSE_DELETE_EVENT
)
1228 return MPDM_I(response
);
1232 static mpdm_t
gtk_drv_form(mpdm_t a
)
1233 /* 'form' driver function */
1237 GtkWidget
* content_area
;
1241 /* first argument: list of widgets */
1242 build_form_data(mpdm_aget(a
, 0));
1244 dlg
= gtk_dialog_new_with_buttons("mp " VERSION
, GTK_WINDOW(window
),
1245 GTK_DIALOG_MODAL
| GTK_DIALOG_NO_SEPARATOR
,
1246 GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
1247 GTK_STOCK_OK
, GTK_RESPONSE_OK
, NULL
);
1248 gtk_dialog_set_default_response(GTK_DIALOG(dlg
), GTK_RESPONSE_OK
);
1249 gtk_container_set_border_width(GTK_CONTAINER(dlg
), 5);
1251 content_area
= GTK_DIALOG(dlg
)->vbox
;
1252 gtk_box_set_spacing(GTK_BOX(content_area
), 2);
1254 table
= gtk_table_new(mpdm_size(a
), 2, FALSE
);
1255 gtk_container_set_border_width(GTK_CONTAINER(table
), 5);
1256 gtk_table_set_col_spacings(GTK_TABLE(table
), 12);
1257 gtk_table_set_row_spacings(GTK_TABLE(table
), 6);
1259 for (n
= 0; n
< mpdm_size(form_args
); n
++) {
1260 mpdm_t w
= mpdm_aget(form_args
, n
);
1261 GtkWidget
* widget
= NULL
;
1267 type
= mpdm_string(mpdm_hget_s(w
, L
"type"));
1269 if ((t
= mpdm_hget_s(w
, L
"label")) != NULL
) {
1273 if ((wptr
= mpdm_string(mpdm_gettext(t
))) != NULL
&&
1274 (ptr
= wcs_to_utf8(wptr
)) != NULL
) {
1275 label
= gtk_label_new(ptr
);
1276 gtk_misc_set_alignment(GTK_MISC(label
), 0, .5);
1278 gtk_table_attach_defaults(GTK_TABLE(table
),
1279 label
, 0, wcscmp(type
, L
"label") == 0 ? 2 : 1,
1288 t
= mpdm_hget_s(w
, L
"value");
1290 if (wcscmp(type
, L
"text") == 0) {
1291 GList
* combo_items
= NULL
;
1295 widget
= gtk_combo_new();
1296 gtk_widget_set_size_request(widget
, 300, -1);
1297 gtk_combo_set_use_arrows_always(GTK_COMBO(widget
), TRUE
);
1298 gtk_combo_set_case_sensitive(GTK_COMBO(widget
), TRUE
);
1299 gtk_entry_set_activates_default(GTK_ENTRY(GTK_COMBO(widget
)->entry
), TRUE
);
1301 if ((h
= mpdm_hget_s(w
, L
"history")) != NULL
) {
1304 /* has history; fill it */
1305 h
= mp_get_history(h
);
1307 for (i
= 0; i
< mpdm_size(h
); i
++) {
1308 wptr
= mpdm_string(mpdm_aget(h
, i
));
1309 ptr
= wcs_to_utf8(wptr
);
1311 combo_items
= g_list_prepend(combo_items
, ptr
);
1316 wptr
= mpdm_string(t
);
1317 ptr
= wcs_to_utf8(wptr
);
1319 combo_items
= g_list_prepend(combo_items
, ptr
);
1322 gtk_combo_set_popdown_strings(GTK_COMBO(widget
), combo_items
);
1323 g_list_free(combo_items
);
1326 if (wcscmp(type
, L
"password") == 0) {
1327 widget
= gtk_entry_new();
1328 gtk_widget_set_size_request(widget
, 300, -1);
1329 gtk_entry_set_visibility(GTK_ENTRY(widget
), FALSE
);
1332 if (wcscmp(type
, L
"checkbox") == 0) {
1333 widget
= gtk_check_button_new();
1335 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget
),
1336 mpdm_ival(t
) ? TRUE
: FALSE
);
1339 if (wcscmp(type
, L
"list") == 0) {
1341 GtkListStore
* list_store
;
1342 GtkCellRenderer
* renderer
;
1343 GtkTreeViewColumn
* column
;
1348 if ((i
= 450 / mpdm_size(form_args
)) < 100)
1351 widget
= gtk_scrolled_window_new(NULL
, NULL
);
1352 gtk_widget_set_size_request(widget
, 500, i
);
1353 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget
),
1354 GTK_POLICY_NEVER
, GTK_POLICY_AUTOMATIC
);
1355 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(widget
),
1358 list_store
= gtk_list_store_new(1, G_TYPE_STRING
);
1359 list
= gtk_tree_view_new_with_model(GTK_TREE_MODEL(list_store
));
1360 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(list
), FALSE
);
1361 renderer
= gtk_cell_renderer_text_new();
1362 column
= gtk_tree_view_column_new_with_attributes("", renderer
,
1364 gtk_tree_view_append_column(GTK_TREE_VIEW(list
), column
);
1365 gtk_container_add(GTK_CONTAINER(widget
), list
);
1367 l
= mpdm_hget_s(w
, L
"list");
1369 for (i
= 0; i
< mpdm_size(l
); i
++) {
1370 wchar_t * wptr
= mpdm_string(mpdm_aget(l
, i
));
1372 if ((ptr
= wcs_to_utf8(wptr
)) != NULL
) {
1374 gtk_list_store_append(list_store
, &iter
);
1375 gtk_list_store_set(list_store
, &iter
, 0, ptr
, -1);
1380 /* initial position */
1383 path
= gtk_tree_path_new_from_indices(i
, -1);
1384 gtk_tree_view_set_cursor(GTK_TREE_VIEW(list
), path
, NULL
, FALSE
);
1385 gtk_tree_path_free(path
);
1387 g_signal_connect_swapped(G_OBJECT(list
), "row-activated",
1388 G_CALLBACK(gtk_window_activate_default
), dlg
);
1391 if (widget
!= NULL
) {
1392 form_widgets
[n
] = widget
;
1393 gtk_table_attach_defaults(GTK_TABLE(table
),
1394 widget
, col
, 2, n
, n
+ 1);
1398 gtk_widget_show_all(table
);
1400 gtk_box_pack_start(GTK_BOX(content_area
), table
, TRUE
, TRUE
, 0);
1402 if (gtk_dialog_run(GTK_DIALOG(dlg
)) == GTK_RESPONSE_OK
) {
1403 clicked_ok(NULL
, NULL
);
1406 gtk_widget_destroy(dlg
);
1412 static mpdm_t
run_filechooser(mpdm_t a
, gboolean save
)
1413 /* openfile driver function */
1421 /* 1# arg: prompt */
1422 wptr
= mpdm_string(mpdm_aget(a
, 0));
1424 if ((ptr
= wcs_to_utf8(wptr
)) == NULL
)
1428 dlg
= gtk_file_chooser_dialog_new(ptr
, GTK_WINDOW(window
),
1429 GTK_FILE_CHOOSER_ACTION_OPEN
, GTK_STOCK_CANCEL
, GTK_RESPONSE_CANCEL
,
1430 GTK_STOCK_OK
, GTK_RESPONSE_OK
, NULL
);
1433 dlg
= gtk_file_chooser_dialog_new(ptr
, GTK_WINDOW(window
),
1434 GTK_FILE_CHOOSER_ACTION_SAVE
, GTK_STOCK_CANCEL
, GTK_STOCK_CANCEL
,
1435 GTK_STOCK_OK
, GTK_RESPONSE_OK
, NULL
);
1436 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dlg
), TRUE
);
1440 build_form_data(NULL
);
1442 gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(dlg
), TRUE
);
1443 response
= gtk_dialog_run(GTK_DIALOG(dlg
));
1445 if (response
== GTK_RESPONSE_OK
) {
1450 filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dlg
));
1451 utf8name
= g_filename_to_utf8(filename
, -1, NULL
, NULL
, NULL
);
1453 wfilename
= utf8_to_wcs(utf8name
);
1455 ret
= MPDM_S(wfilename
);
1458 gtk_widget_destroy(dlg
);
1464 static mpdm_t
gtk_drv_openfile(mpdm_t a
)
1465 /* openfile driver function */
1467 return run_filechooser(a
, FALSE
);
1471 static mpdm_t
gtk_drv_savefile(mpdm_t a
)
1472 /* savefile driver function */
1474 return run_filechooser(a
, TRUE
);
1478 static mpdm_t
gtk_drv_update_ui(mpdm_t a
)
1490 static mpdm_t
gtk_drv_timer(mpdm_t a
)
1492 static guint prev
= 0;
1493 int msecs
= mpdm_ival(mpdm_aget(a
, 0));
1494 mpdm_t func
= mpdm_aget(a
, 1);
1497 /* previously defined one? remove */
1498 if (timer_func
!= NULL
)
1499 gtk_timeout_remove(prev
);
1501 /* if msecs and func are set, program timer */
1502 if (msecs
> 0 && func
!= NULL
)
1503 prev
= gtk_timeout_add(msecs
, timer_callback
, NULL
);
1505 r
= mpdm_unref(timer_func
);
1506 timer_func
= mpdm_ref(func
);
1512 static mpdm_t
gtk_drv_busy(mpdm_t a
)
1514 int onoff
= mpdm_ival(mpdm_aget(a
, 0));
1516 gdk_window_set_cursor(window
->window
,
1517 gdk_cursor_new(onoff
? GDK_WATCH
: GDK_LEFT_PTR
));
1519 while (gtk_events_pending())
1520 gtk_main_iteration();
1526 static mpdm_t
gtk_drv_main_loop(mpdm_t a
)
1529 if (!mp_exit_requested
) {
1530 gtk_drv_paint(mp_active(), 0);
1539 static mpdm_t
gtk_drv_shutdown(mpdm_t a
)
1544 if ((v
= mpdm_hget_s(mp
, L
"exit_message")) != NULL
) {
1545 mpdm_write_wcs(stdout
, mpdm_string(v
));
1553 static void register_functions(void)
1557 drv
= mpdm_hget_s(mp
, L
"drv");
1558 mpdm_hset_s(drv
, L
"main_loop", MPDM_X(gtk_drv_main_loop
));
1559 mpdm_hset_s(drv
, L
"shutdown", MPDM_X(gtk_drv_shutdown
));
1561 mpdm_hset_s(drv
, L
"clip_to_sys", MPDM_X(gtk_drv_clip_to_sys
));
1562 mpdm_hset_s(drv
, L
"sys_to_clip", MPDM_X(gtk_drv_sys_to_clip
));
1563 mpdm_hset_s(drv
, L
"update_ui", MPDM_X(gtk_drv_update_ui
));
1564 mpdm_hset_s(drv
, L
"timer", MPDM_X(gtk_drv_timer
));
1565 mpdm_hset_s(drv
, L
"busy", MPDM_X(gtk_drv_busy
));
1567 mpdm_hset_s(drv
, L
"alert", MPDM_X(gtk_drv_alert
));
1568 mpdm_hset_s(drv
, L
"confirm", MPDM_X(gtk_drv_confirm
));
1569 mpdm_hset_s(drv
, L
"openfile", MPDM_X(gtk_drv_openfile
));
1570 mpdm_hset_s(drv
, L
"savefile", MPDM_X(gtk_drv_savefile
));
1571 mpdm_hset_s(drv
, L
"form", MPDM_X(gtk_drv_form
));
1575 static mpdm_t
gtk_drv_startup(mpdm_t a
)
1576 /* driver initialization */
1586 register_functions();
1588 window
= gtk_window_new(GTK_WINDOW_TOPLEVEL
);
1590 /* get real screen and pick a usable size for the main area */
1591 screen
= gtk_window_get_screen(GTK_WINDOW(window
));
1592 w
= (gdk_screen_get_width(screen
) * 3) / 4;
1593 h
= (gdk_screen_get_height(screen
) * 2) / 3;
1595 g_signal_connect(G_OBJECT(window
), "delete_event",
1596 G_CALLBACK(delete_event
), NULL
);
1598 g_signal_connect(G_OBJECT(window
), "destroy",
1599 G_CALLBACK(destroy
), NULL
);
1602 file_tabs
= gtk_notebook_new();
1603 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(file_tabs
), GTK_POS_TOP
);
1604 GTK_WIDGET_UNSET_FLAGS(file_tabs
,GTK_CAN_FOCUS
);
1605 gtk_notebook_set_scrollable(GTK_NOTEBOOK(file_tabs
), 1);
1607 vbox
= gtk_vbox_new(FALSE
, 2);
1608 gtk_container_add(GTK_CONTAINER(window
), vbox
);
1611 gtk_box_pack_start(GTK_BOX(vbox
), menu_bar
, FALSE
, FALSE
, 0);
1613 gtk_box_pack_start(GTK_BOX(vbox
), file_tabs
, FALSE
, FALSE
, 0);
1615 /* horizontal box holding the text and the scrollbar */
1616 hbox
= gtk_hbox_new(FALSE
, 2);
1617 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, TRUE
, TRUE
, 0);
1619 /* the Minimum Profit area */
1620 area
= gtk_drawing_area_new();
1621 gtk_box_pack_start(GTK_BOX(hbox
), area
, TRUE
, TRUE
, 0);
1622 gtk_widget_set_size_request(GTK_WIDGET(area
), w
, h
);
1623 gtk_widget_set_events(GTK_WIDGET(area
), GDK_BUTTON_PRESS_MASK
|
1624 GDK_BUTTON_RELEASE_MASK
| GDK_POINTER_MOTION_MASK
|
1625 GDK_LEAVE_NOTIFY_MASK
);
1627 gtk_widget_set_double_buffered(area
, FALSE
);
1629 g_signal_connect(G_OBJECT(area
),"configure_event",
1630 G_CALLBACK(configure_event
), NULL
);
1632 g_signal_connect(G_OBJECT(area
),"expose_event",
1633 G_CALLBACK(expose_event
), NULL
);
1635 g_signal_connect(G_OBJECT(area
), "realize",
1636 G_CALLBACK(realize
), NULL
);
1638 g_signal_connect(G_OBJECT(window
),"key_press_event",
1639 G_CALLBACK(key_press_event
), NULL
);
1641 g_signal_connect(G_OBJECT(window
),"key_release_event",
1642 G_CALLBACK(key_release_event
), NULL
);
1644 g_signal_connect(G_OBJECT(area
),"button_press_event",
1645 G_CALLBACK(button_press_event
), NULL
);
1647 g_signal_connect(G_OBJECT(area
),"button_release_event",
1648 G_CALLBACK(button_release_event
), NULL
);
1650 g_signal_connect(G_OBJECT(area
),"motion_notify_event",
1651 G_CALLBACK(motion_notify_event
), NULL
);
1653 g_signal_connect(G_OBJECT(area
), "selection_clear_event",
1654 G_CALLBACK(selection_clear_event
), NULL
);
1656 g_signal_connect(G_OBJECT(area
), "selection_get",
1657 G_CALLBACK(selection_get
), NULL
);
1659 g_signal_connect(G_OBJECT(area
), "selection_received",
1660 G_CALLBACK(selection_received
), NULL
);
1662 g_signal_connect(G_OBJECT(area
), "scroll_event",
1663 G_CALLBACK(scroll_event
), NULL
);
1665 gtk_selection_add_target(area
, GDK_SELECTION_PRIMARY
,
1666 GDK_SELECTION_TYPE_STRING
, 1);
1668 g_signal_connect(G_OBJECT(file_tabs
),"switch_page",
1669 G_CALLBACK(switch_page
), NULL
);
1672 scrollbar
= gtk_vscrollbar_new(NULL
);
1673 gtk_box_pack_start(GTK_BOX(hbox
), scrollbar
, FALSE
, FALSE
, 0);
1676 G_OBJECT(gtk_range_get_adjustment(GTK_RANGE(scrollbar
))),
1677 "value_changed", G_CALLBACK(value_changed
), NULL
);
1679 /* the status bar */
1680 status
= gtk_label_new("mp " VERSION
);
1681 gtk_box_pack_start(GTK_BOX(vbox
), status
, FALSE
, FALSE
, 0);
1682 gtk_misc_set_alignment(GTK_MISC(status
), 0, 0.5);
1683 gtk_label_set_justify(GTK_LABEL(status
), GTK_JUSTIFY_LEFT
);
1685 gtk_widget_show_all(window
);
1687 /* _mpv_font_size--;
1690 if (mpv_gtk_maximize)
1691 gtk_window_maximize(GTK_WINDOW(window));
1695 /* if(!mpv_gtk_maximize)
1697 if(_mpv_gtk_xpos >= 0 && _mpv_gtk_ypos >= 0)
1698 gdk_window_move(GTK_WIDGET(window)->window,
1699 _mpv_gtk_xpos, _mpv_gtk_ypos);
1701 if(_mpv_gtk_width > 0 && _mpv_gtk_height > 0)
1703 if(_mpv_gtk_width < 150) _mpv_gtk_width=150;
1704 if(_mpv_gtk_height < 150) _mpv_gtk_height=150;
1706 gtk_window_set_default_size(GTK_WINDOW(window),
1707 _mpv_gtk_width, _mpv_gtk_height);
1709 gdk_window_resize(GTK_WIDGET(window)->window,
1710 _mpv_gtk_width, _mpv_gtk_height);
1715 /* _mpv_create_colors();
1719 mp_log("X11 geometry set to %dx%d+%d+%d\n", _mpv_gtk_width, _mpv_gtk_height,
1720 _mpv_gtk_xpos, _mpv_gtk_ypos);
1723 /* set application icon */
1724 pixmap
= gdk_pixmap_create_from_xpm_d(window
->window
,
1725 &mask
, NULL
, mp_xpm
);
1726 gdk_window_set_icon(window
->window
, NULL
, pixmap
, mask
);
1730 if ((v
= mpdm_hget_s(mp
, L
"config")) != NULL
&&
1731 mpdm_ival(mpdm_hget_s(v
, L
"maximize")) > 0)
1738 int gtk_drv_detect(int * argc
, char *** argv
)
1742 if (!gtk_init_check(argc
, argv
))
1745 drv
= mpdm_hget_s(mp
, L
"drv");
1746 mpdm_hset_s(drv
, L
"id", MPDM_LS(L
"gtk"));
1747 mpdm_hset_s(drv
, L
"startup", MPDM_X(gtk_drv_startup
));
1752 #endif /* CONFOPT_GTK */