~ubuntu-branches/ubuntu/karmic/iterm/karmic

« back to all changes in this revision

Viewing changes to unix/Xaw/src/popup_menu.c

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Fok
  • Date: 2004-02-27 04:13:16 UTC
  • Revision ID: james.westby@ubuntu.com-20040227041316-q0jn37sia8mt0t9u
Tags: upstream-0.5
ImportĀ upstreamĀ versionĀ 0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This software is subject to the terms of the Common Public License
 
2
   You must accept the terms of this license to use this software.
 
3
 
 
4
   Copyright (C) 2002, International Business Machines Corporation
 
5
   and others.  All Rights Reserved.
 
6
 
 
7
   Further information about Common Public License Version 0.5 is obtained
 
8
   from url http://oss.software.ibm.com/developer/opensource/license-cpl.html */
 
9
 
 
10
#include <X11/Intrinsic.h>
 
11
#include <X11/Xaw/SimpleMenu.h>
 
12
#include <X11/Xaw/SmeBSB.h>
 
13
#include <X11/StringDefs.h>
 
14
#include "Iterm.h"
 
15
 
 
16
extern Widget iterm;
 
17
extern Pixmap menu_item_bitmap;
 
18
 
 
19
/* prototypes */
 
20
static void font_callback(Widget w, XtPointer p, XtPointer p2);
 
21
static void toggle_scrollbar(Widget w, XtPointer p, XtPointer p2);
 
22
static void toggle_scrollbar_left(Widget w, XtPointer p, XtPointer p2);
 
23
static void toggle_visual_bell(Widget w, XtPointer p, XtPointer p2);
 
24
static void toggle_reverse_video(Widget w, XtPointer p, XtPointer p2);
 
25
 
 
26
struct MenuEntry
 
27
{
 
28
  char *name;
 
29
  XtCallbackProc proc;
 
30
  Widget entry_widget;
 
31
};
 
32
 
 
33
struct MenuEntry font_menu_entry[] ={
 
34
    {"default", font_callback,NULL},
 
35
    {"fontSet1", font_callback,NULL},
 
36
    {"fontSet2", font_callback,NULL},
 
37
    {"fontSet3", font_callback,NULL},
 
38
    {"fontSet4", font_callback,NULL},
 
39
    {"fontSet5", font_callback,NULL},
 
40
    {"fontSet6", font_callback,NULL},
 
41
    {NULL,NULL,NULL}};
 
42
 
 
43
struct MenuEntry option_menu_entry[] ={
 
44
    {"enableScrollbar", toggle_scrollbar,NULL},
 
45
    {"enableScrollbarLeft", toggle_scrollbar_left,NULL},
 
46
    {"enableVisualBell",toggle_visual_bell,NULL},
 
47
    {"enableReverseVideo",toggle_reverse_video,NULL},
 
48
    {NULL,NULL,NULL}};
 
49
 
 
50
#define SetBitmap(w,bool) \
 
51
  XtVaSetValues(w, \
 
52
                XtNleftBitmap, \
 
53
                bool?menu_item_bitmap:(XtArgVal)0, \
 
54
                NULL)
 
55
    
 
56
 
 
57
 
 
58
static void font_callback(Widget w, XtPointer p, XtPointer p2)
 
59
{
 
60
  int num = (int)p;
 
61
  int i;
 
62
  struct MenuEntry *entries = font_menu_entry;
 
63
  if(0<=num && num<=6)
 
64
      ItermSelectFont(iterm,num);
 
65
 
 
66
  for(i=0;entries[i].name != NULL;i++)
 
67
  {
 
68
    SetBitmap(entries[i].entry_widget,i==num);
 
69
  }
 
70
}
 
71
 
 
72
static void toggle_scrollbar(Widget w, XtPointer p, XtPointer p2)
 
73
{
 
74
  ItermSetScrollbar(iterm,!ItermIsScrollbarOn(iterm));
 
75
  SetBitmap(w,ItermIsScrollbarOn(iterm));
 
76
}
 
77
 
 
78
static void toggle_scrollbar_left(Widget w, XtPointer p, XtPointer p2)
 
79
{
 
80
  ItermSetScrollbarLeft(iterm,!ItermIsScrollbarLeft(iterm));
 
81
  SetBitmap(w,ItermIsScrollbarLeft(iterm));
 
82
}
 
83
 
 
84
static void toggle_visual_bell(Widget w, XtPointer p, XtPointer p2)
 
85
{
 
86
  ItermSetVisualBell(iterm,!ItermIsVisualBell(iterm));
 
87
  SetBitmap(w,ItermIsVisualBell(iterm));
 
88
}
 
89
 
 
90
static void toggle_reverse_video(Widget w, XtPointer p, XtPointer p2)
 
91
{
 
92
  ItermSetReverseVideo(iterm,!ItermIsReverseVideo(iterm));
 
93
  SetBitmap(w,ItermIsReverseVideo(iterm));
 
94
}
 
95
 
 
96
static Widget create_popup_menu(Widget parent,
 
97
                                char *widget_name,
 
98
                                struct MenuEntry *entries)
 
99
{
 
100
  Widget popup;
 
101
  XtCallbackRec cb[2] = { { NULL, 0 }, { NULL, NULL }};
 
102
  Arg arg[] = {{ XtNcallback, (XtArgVal) cb},};
 
103
  int i;
 
104
  popup = XtVaCreatePopupShell(widget_name,simpleMenuWidgetClass,parent,
 
105
                               NULL);
 
106
  for(i=0;entries[i].name != NULL;i++)
 
107
  {
 
108
    cb[0].callback = entries[i].proc;
 
109
    cb[0].closure =(XtPointer)i;
 
110
    entries[i].entry_widget = XtCreateManagedWidget(entries[i].name,
 
111
                                                     smeBSBObjectClass,
 
112
                                                     popup,
 
113
                                                     arg,XtNumber(arg));
 
114
  }
 
115
  return popup;
 
116
}
 
117
 
 
118
Widget init_font_menu(Widget parent)
 
119
{
 
120
  Widget menu = create_popup_menu(parent,"fontMenu",font_menu_entry);
 
121
  XtVaSetValues(font_menu_entry[0].entry_widget,
 
122
                XtNleftBitmap,menu_item_bitmap,
 
123
                NULL);
 
124
  return menu;
 
125
}
 
126
 
 
127
Widget init_option_menu(Widget parent)
 
128
{
 
129
  Widget menu = create_popup_menu(parent,"optionMenu",option_menu_entry);
 
130
  XtVaSetValues(option_menu_entry[0].entry_widget,
 
131
                XtNleftBitmap,
 
132
                ItermIsScrollbarOn(iterm)?menu_item_bitmap:(XtArgVal)0,
 
133
                NULL);
 
134
  XtVaSetValues(option_menu_entry[1].entry_widget,
 
135
                XtNleftBitmap,
 
136
                ItermIsScrollbarLeft(iterm)?menu_item_bitmap:(XtArgVal)0,
 
137
                NULL);
 
138
  XtVaSetValues(option_menu_entry[2].entry_widget,
 
139
                XtNleftBitmap,
 
140
                ItermIsVisualBell(iterm)?menu_item_bitmap:(XtArgVal)0,
 
141
                NULL);
 
142
  XtVaSetValues(option_menu_entry[3].entry_widget,
 
143
                XtNleftBitmap,
 
144
                ItermIsReverseVideo(iterm)?menu_item_bitmap:(XtArgVal)0,
 
145
                NULL);
 
146
  
 
147
  return menu;
 
148
}
 
149
 
 
150
static void videoChanged(Widget w, XtPointer p1, XtPointer p2)
 
151
{
 
152
  SetBitmap((Widget)p1,p2);
 
153
}
 
154
 
 
155
void set_callbacks(Widget iterm)
 
156
{
 
157
  XtAddCallback(iterm,XtNvideoChanged,videoChanged,
 
158
                option_menu_entry[3].entry_widget); 
 
159
 
 
160
}