1 #include "editmenu.h" /* This must be the MODIFIED .h file */
10 #define LOGPROGRAM "xconsole"
11 #define ERRMSGFIFO "/tmp/WINGsWindowfifo"
12 #define FIFONAMELEN 20
13 #define NOLOGWINDOW (-2) /* value when there is no console window */
14 #define FIFOERROR (-1) /* value when there is a problem w/ console */
15 #define FIFOLOWESTPOSS 0
21 char fifofilename
[FIFONAMELEN
+5];
29 /* functions for the message window part: */
31 void redirectmsg(int sig
){
33 // clean up after SIGCHLD, and set fifonr to flag it
35 if (!access(fifofilename
,F_OK
|W_OK
))
41 int showMessageWindow(){
43 sprintf(fifofilename
,"%s%i",ERRMSGFIFO
,(unsigned short)getpid());
45 (void) signal(SIGCHLD
,redirectmsg
); // clean up if message console is killed
47 if(access(fifofilename
,F_OK
)==-1)
48 fifonr
=mknod(fifofilename
,0640|O_EXCL
|S_IFIFO
,(dev_t
)0);
49 else {fifonr
=FIFOERROR
;
50 wwarning("Fifo file already exists\n");
52 /* fifonr == FIFOERROR if mknod/mkfifo or access failed, mknod returns -1 on failure */
54 if(fifonr
!=FIFOERROR
){
58 execlp(LOGPROGRAM
, LOGPROGRAM
, "-file",fifofilename
,"-geometry","250x400", "-title","Window Messages",(char *)0);
61 fifonr
=open(fifofilename
,O_WRONLY
);
66 /* general and menu handling functions */
68 void closeAll(WMWidget
*self
,void *data
){
70 WMDestroyWidget(self
);
71 if(--windowCounter
<1){
72 if (fifonr
>=FIFOLOWESTPOSS
)
74 if (!access(fifofilename
,F_OK
|W_OK
))
81 void menuItemAction(void *self
, void *data
){
83 if (fifonr
<FIFOLOWESTPOSS
)fifonr
=showMessageWindow(); // try again in case FIFOERROR
84 if (fifonr
==FIFOERROR
) // give up and print to stderr
85 fprintf(stderr
,"%i: %s selected\n", getpid(), WGetEditMenuItemTitle(self
));
88 snprintf(textbuffer
,100, "%i: %s selected\n", getpid(), WGetEditMenuItemTitle(self
));
89 write(fifonr
, textbuffer
,strlen(textbuffer
));
94 void menuItemCloseAction(void *self
, void *data
){
96 WMPostNotificationName("WMWindowClose", self
, NULL
);
100 void getMenu(WMWidget
*self
, void *data
){
103 struct dataStruct
*tmp
=(struct dataStruct
*)data
;
105 if(WMGetButtonSelected(self
)){
106 position
=WMGetViewScreenPosition(WMWidgetView(tmp
->window
));
107 WEditMenuShowAt(tmp
->menu
,(position
.x
>MENUWIDTH
)?position
.x
-MENUWIDTH
:0, position
.y
+MENITEMHT
,tmp
->window
);
109 WEditMenuHide(tmp
->menu
);
110 WDeselectItem(tmp
->menu
); // remove selection before next pop up
115 static void notificationHandler(void *self
, WMNotification
*notif
){
117 if(!strcmp("WMWindowClose",WMGetNotificationName(notif
)))
119 if(!strcmp(WMViewSizeDidChangeNotification
,WMGetNotificationName(notif
))){
121 WMSize size
= WMGetViewSize(WMWidgetView(self
));
125 /* main widget creating functions */
127 WMWindow
* makeMainwindow(Display
*display
, WMScreen
*screen
){
130 window
= WMCreateWindow(screen
, "Menu");
131 WMResizeWidget(window
, WINWIDTH
, WINHEIGHT
);
132 WMSetWindowCloseAction(window
, closeAll
, NULL
);
133 WMAddNotificationObserver(notificationHandler
, window
, "WMWindowClose", WMWidgetView(window
));
134 WMSetViewNotifySizeChanges(WMWidgetView(window
), True
);
135 WMAddNotificationObserver(notificationHandler
, window
, WMViewSizeDidChangeNotification
, WMWidgetView(window
));
136 WMAddNotificationObserver(notificationHandler
, window
, "WMWindowClose", NULL
);
137 WMRealizeWidget(window
);
142 WEditMenu
* makeMenus(WMScreen
*screen
,WEditMenu
*menu
, WEditMenu
*submenu
){
143 WEditMenuItem
* menuitem
;
145 submenu
=WCreateEditMenu(screen
,"Submenu");
146 menuitem
=WAddMenuItemWithTitle(submenu
,"Submenu item");
147 WSetEditMenuItemAction( menuitem
, menuItemAction
);
148 menuitem
=WAddMenuItemWithTitle(submenu
,"2nd submenu item");
149 WSetEditMenuItemAction( menuitem
, menuItemAction
);
150 menuitem
=WAddMenuItemWithTitle(submenu
,"3d submenu item");
151 WSetEditMenuItemAction( menuitem
, menuItemAction
);
152 menu
=WCreateEditMenu(screen
,"Main menu");
153 menuitem
= WAddMenuItemWithTitle(menu
,"1st main item");
154 WSetEditMenuItemAction( menuitem
, menuItemAction
);
155 menuitem
= WAddMenuItemWithTitle(menu
,"2nd main item");
156 WSetEditMenuItemAction( menuitem
, menuItemAction
);
157 menuitem
= WAddMenuItemWithTitle(menu
,"To submenu");
158 WSetEditMenuSubmenu(menu
, menuitem
, submenu
);
159 menuitem
= WAddMenuItemWithTitle(menu
,"Quit");
160 WSetEditMenuItemAction( menuitem
, menuItemCloseAction
);
161 WMRealizeWidget(submenu
);WMRealizeWidget(menu
);
166 WMButton
* makeButtonsTop( WMWidget
*window
, void *AppData
){
169 Button
=WMCreateButton(window
,WBTPushOnPushOff
);
170 WMSetButtonText (Button
, "Menu");
171 WMSetButtonAction (Button
, getMenu
, AppData
);
172 WMMoveWidget(Button
, 4,2);
173 WMRealizeWidget(Button
);
178 int main (int argc
, char **argv
){
182 WMWindow
*mainwindow
;
183 WEditMenu
*submenu
, *menu
;
184 WEditMenuItem
* menuitem
;
185 struct dataStruct Mainmenu
;
186 WMButton
*menubutton
;
190 WMInitializeApplication("MenuWindow", &argc
, argv
);
191 display
= XOpenDisplay("");
192 screen
= WMCreateScreen(display
, DefaultScreen(display
));
193 mainwindow
= makeMainwindow(display
, screen
) ;
195 menu
=makeMenus(screen
,menu
,submenu
);
197 Mainmenu
.window
=mainwindow
;
199 menubutton
=makeButtonsTop(mainwindow
, &Mainmenu
);
201 WMMapSubwidgets(mainwindow
);
202 WMMapWidget(mainwindow
);
204 WMScreenMainLoop(screen
);