wmgen

Генератор WINGs апликација
git clone https://git.sr.ht/~strahinja/wmgen
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

mainwindow.c (4095B)


      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <string.h>
      4 
      5 #include "app.h"
      6 #include "appicon.xpm"
      7 #define INCLUDE_STATIC_FUNCS
      8 #include "mainwindow.h"
      9 #include "windowmanager.h"
     10 
     11 #include "config.h"
     12 
     13 /* Assumes main window has been created */
     14 void
     15 create_icon(struct WMNewApp* wma)
     16 {
     17 	RContextAttributes attr;
     18 
     19 	memset((void*)&attr, 0, sizeof(RContextAttributes));
     20 	attr.flags		= (RC_RenderMode | RC_ColorsPerChannel);
     21 	attr.render_mode	= 0;
     22 	attr.colors_per_channel = 4;
     23 
     24 	if (!(wma->rctx
     25 		    = RCreateContext(wma->dpy, DefaultScreen(wma->dpy), &attr)))
     26 		exit(error(1, "RCreateContext failed\n"));
     27 	if (!(wma->app_image = RGetImageFromXPMData(wma->rctx, appicon_xpm)))
     28 		exit(error(1, "RGetImageFromXPMData failed\n"));
     29 
     30 	if (!RConvertImageMask(wma->rctx, wma->app_image, &wma->app_icon,
     31 		    &wma->app_mask, 0))
     32 		exit(error(1, "RConvertImageMask failed\n"));
     33 	wma->hints->icon_pixmap = wma->app_icon;
     34 	wma->hints->icon_mask	= wma->app_mask;
     35 	wma->hints->flags |= (IconPixmapHint | IconMaskHint);
     36 	XSetWMHints(wma->dpy, WMWidgetXID(wma->mainwin->window), wma->hints);
     37 
     38 	if (!(wma->wmpixmap
     39 		    = WMCreatePixmapFromRImage(wma->scr, wma->app_image, 0)))
     40 		exit(error(1, "WMCreatePixmapFromRImage failed\n"));
     41 	WMSetApplicationIconPixmap(wma->scr, wma->wmpixmap);
     42 }
     43 
     44 void
     45 create_main_window(struct WMNewApp* wma)
     46 {
     47 	MyGNUstepWMAttributes attributes;
     48 
     49 	if (!(wma->class_hint = XAllocClassHint()))
     50 		exit(error(1, "XAllocClassHint failed\n"));
     51 	wma->class_hint->res_name  = "wmnewapp";
     52 	wma->class_hint->res_class = "WMNewApp";
     53 
     54 	if (!(wma->mainwin
     55 		    = (struct WMMainWindow*)calloc(sizeof(struct WMMainWindow),
     56 			    1)))
     57 		exit(error(1, "calloc failed\n"));
     58 	wma->mainwin->app = wma;
     59 	wma->mainwin->window
     60 		= WMCreateWindow(wma->scr, wma->class_hint->res_name);
     61 	WMRealizeWidget(wma->mainwin->window);
     62 
     63 	if (!(wma->hints = XAllocWMHints()))
     64 		exit(error(1, "XAllocWMHints failed\n"));
     65 	wma->hints->window_group = WMWidgetXID(wma->mainwin->window);
     66 	wma->hints->flags	 = WindowGroupHint;
     67 
     68 	set_mainwin_title(wma);
     69 	WMResizeWidget(wma->mainwin->window, 640, 480);
     70 	WMSetWindowCloseAction(wma->mainwin->window, exit_action, wma);
     71 
     72 	XSetClassHint(wma->dpy, WMWidgetXID(wma->mainwin->window),
     73 		wma->class_hint);
     74 	XSetWMHints(wma->dpy, WMWidgetXID(wma->mainwin->window), wma->hints);
     75 
     76 	memset((void*)&attributes, 0, sizeof(MyGNUstepWMAttributes));
     77 	attributes.window_style = (WMClosableWindowMask | WMTitledWindowMask
     78 		| WMMiniaturizableWindowMask | WMResizableWindowMask);
     79 	attributes.window_level = WMNormalWindowLevel;
     80 	attributes.extra_flags	= GSFullKeyboardEventsFlag;
     81 	attributes.flags
     82 		= (GSWindowStyleAttr | GSWindowLevelAttr | GSExtraFlagsAttr);
     83 	MyWMSetWindowAttributes(wma->dpy, WMWidgetXID(wma->mainwin->window),
     84 		&attributes);
     85 
     86 	WMSetViewNotifySizeChanges(WMWidgetView(wma->mainwin->window), True);
     87 	WMAddNotificationObserver(handle_mainwin_resize, wma,
     88 		WMViewSizeDidChangeNotification,
     89 		WMWidgetView(wma->mainwin->window));
     90 
     91 }
     92 
     93 void
     94 destroy_main_window(struct WMNewApp* wma)
     95 {
     96 	if (wma->mainwin)
     97 		free(wma->mainwin);
     98 }
     99 
    100 void
    101 handle_mainwin_resize(void* data, WMNotification* notification)
    102 {
    103 	struct WMNewApp* wma = (struct WMNewApp*)data;
    104 	WMSize new_size = WMGetViewSize(WMWidgetView(wma->mainwin->window));
    105 	WMLog(wma, "handle_mainwin_resize called (\n");
    106 	WMLog(wma, "\tname: {%s}\n", WMGetNotificationName(notification));
    107 	WMLog(wma, "\tnew size: (w = %d, h = %d)\n", new_size.width,
    108 		new_size.height);
    109 	WMLog(wma, ")\n");
    110 	/* Resize widgets... */
    111 }
    112 
    113 void
    114 map_main_window(struct WMNewApp* wma)
    115 {
    116 	WMMapSubwidgets(wma->mainwin->window);
    117 	WMMapWidget(wma->mainwin->window);
    118 }
    119 
    120 void
    121 set_mainwin_title(struct WMNewApp* wma)
    122 {
    123 	if (wma->state.file_open)
    124 		snprintf(wma->mainwin->title,
    125 			strlen(mainwin_title_fmt) - 2 - 2 + PATH_MAX
    126 				+ strlen(program_name) + 1,
    127 			mainwin_title_fmt, program_name,
    128 			wma->state.dirty ? "*" : "",
    129 			*(wma->state.filename) ? wma->state.filename
    130 					       : default_filename);
    131 	else
    132 		snprintf(wma->mainwin->title, strlen(program_name) + 1, "%s",
    133 			program_name);
    134 	WMSetWindowTitle(wma->mainwin->window, wma->mainwin->title);
    135 }