Пример #1
0
		internal void GenerateTooltip (GeneratorContext ctx, Widget widget)
		{
			if (WidgetUtils.CompareVersions (Project.TargetGtkVersion, "2.12") <= 0) {
				ctx.Statements.Add (
					new CodeAssignStatement (
						new CodePropertyReferenceExpression (ctx.WidgetMap.GetWidgetExp (widget), "TooltipMarkup"),
						new CodePrimitiveExpression (widget.Tooltip)
					)
				);
				return;
			}
 
			if (generatedTooltips == null) {
				string tid = ctx.NewId ();
				Type t = typeof(Gtk.Widget).Assembly.GetType ("Gtk.Tooltips");
				CodeVariableDeclarationStatement vardec = new CodeVariableDeclarationStatement (
					t.ToGlobalTypeRef (), tid, new CodeObjectCreateExpression (t)
				);
				ctx.Statements.Add (vardec);
				generatedTooltips = new CodeVariableReferenceExpression (tid);
			}
			ctx.Statements.Add (
				new CodeMethodInvokeExpression (
					generatedTooltips,
					"SetTip",
					ctx.WidgetMap.GetWidgetExp (widget),
					new CodePrimitiveExpression (widget.Tooltip),
					new CodePrimitiveExpression (widget.Tooltip)
				)
			);
		}
		internal protected override void GenerateBuildCode (GeneratorContext ctx, CodeExpression var)
		{
			if (!String.IsNullOrEmpty (UIManagerName)) {
				// Create an UI manager
				CodeFieldReferenceExpression uixp = new CodeFieldReferenceExpression (new CodeThisReferenceExpression (), UIManagerName);
				CodeAssignStatement uim_init = new CodeAssignStatement (uixp, new CodeObjectCreateExpression (typeof (Gtk.UIManager).ToGlobalTypeRef ()));
				ctx.Statements.Add (uim_init);
				
				includedActionGroups = new ArrayList ();
				
				// Generate action group creation
				foreach (ActionGroup actionGroup in actionGroups) {
					
					// Create the action group
					string grpVar = ctx.NewId ();
					CodeVariableDeclarationStatement uidec = new CodeVariableDeclarationStatement (
						typeof (Gtk.ActionGroup).ToGlobalTypeRef (),
						grpVar,
						actionGroup.GenerateObjectCreation (ctx)
					);
					ctx.Statements.Add (uidec);
					actionGroup.GenerateBuildCode (ctx, new CodeVariableReferenceExpression (grpVar));
					
					// Insert the action group in the UIManager
					CodeMethodInvokeExpression mi = new CodeMethodInvokeExpression (
						uixp,
						"InsertActionGroup",
						new CodeVariableReferenceExpression (grpVar),
						new CodePrimitiveExpression (includedActionGroups.Count)
					);
					ctx.Statements.Add (mi);
				
					includedActionGroups.Add (actionGroup);
				}
				
				// Adds the accel group to the window
				Window w = GetTopLevel () as Window;
				if (w != null) {
					CodeMethodInvokeExpression ami = new CodeMethodInvokeExpression (
						ctx.WidgetMap.GetWidgetExp (w),
						"AddAccelGroup",
						new CodePropertyReferenceExpression (
							uixp,
							"AccelGroup"
						)
					);
					ctx.Statements.Add (ami);
				} else {
					// There is no top level window, this must be a custom widget.
					// The only option is to register the accel group when
					// the widget is realized. This is done by the Bin wrapper.
				}
			}
			
			if (tooltip != null && tooltip.Length > 0)
				GetTopLevel().GenerateTooltip (ctx, this);
			
			base.GenerateBuildCode (ctx, var);
		}
Пример #3
0
		void GenerateSetInternalChild (GeneratorContext ctx, CodeExpression parentVar, TypedPropertyDescriptor prop)
		{
			Gtk.Widget child = prop.GetValue (container) as Gtk.Widget;
			Widget cwrapper = Widget.Lookup (child);
			if (cwrapper != null) {
				ctx.Statements.Add (new CodeCommentStatement ("Internal child " + Wrapped.Name + "." + prop.Name));
				string childVar = ctx.NewId ();
				CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement (child.GetType().ToGlobalTypeRef (), childVar);
				ctx.Statements.Add (varDec);
				varDec.InitExpression = new CodePropertyReferenceExpression (parentVar, prop.Name);
			
				ctx.GenerateBuildCode (cwrapper, new CodeVariableReferenceExpression (childVar));
				return;
			}
		}
Пример #4
0
		protected void GenerateSetPacking (GeneratorContext ctx, CodeExpression parentVar, CodeExpression childVar, ObjectWrapper containerChildWrapper)
		{
			Gtk.Container.ContainerChild cc = containerChildWrapper.Wrapped as Gtk.Container.ContainerChild;
			ClassDescriptor klass = containerChildWrapper.ClassDescriptor;
			
			// Generate a variable that holds the container child
			
			string contChildVar = ctx.NewId ();
			CodeVariableDeclarationStatement varDec = new CodeVariableDeclarationStatement (cc.GetType().ToGlobalTypeRef (), contChildVar);
			varDec.InitExpression = new CodeCastExpression ( 
				cc.GetType ().ToGlobalTypeRef (),
				new CodeIndexerExpression (parentVar, childVar)
			);
			
			CodeVariableReferenceExpression var = new CodeVariableReferenceExpression (contChildVar);
			
			// Set the container child properties

			ctx.Statements.Add (varDec);
			int count = ctx.Statements.Count;
			
			foreach (ItemGroup group in klass.ItemGroups) {
				foreach (ItemDescriptor item in group) {
					PropertyDescriptor prop = item as PropertyDescriptor;
					if (prop == null || !prop.IsRuntimeProperty)
						continue;
					GenerateChildPropertySet (ctx, var, klass, prop, cc);
				}
			}
			
			if (ctx.Statements.Count == count) {
				ctx.Statements.Remove (varDec);
			}
		}
Пример #5
0
 internal void GenerateTooltip(GeneratorContext ctx, Widget widget)
 {
     if (generatedTooltips == null) {
         string tid = ctx.NewId ();
         CodeVariableDeclarationStatement vardec = new CodeVariableDeclarationStatement (
             typeof(Gtk.Tooltips),
             tid,
             new CodeObjectCreateExpression (typeof(Gtk.Tooltips))
         );
         ctx.Statements.Add (vardec);
         generatedTooltips = new CodeVariableReferenceExpression (tid);
     }
     ctx.Statements.Add (
         new CodeMethodInvokeExpression (
             generatedTooltips,
             "SetTip",
             ctx.WidgetMap.GetWidgetExp (widget),
             new CodePrimitiveExpression (widget.Tooltip),
             new CodePrimitiveExpression (widget.Tooltip)
         )
     );
 }
Пример #6
0
        protected override void GenerateChildBuildCode(GeneratorContext ctx, CodeExpression parentExp, Widget wrapper)
        {
            Gtk.Widget child = (Gtk.Widget)wrapper.Wrapped;

            if (notebook.PageNum(child) == -1)
            {
                // It's a tab

                ctx.Statements.Add(new CodeCommentStatement("Notebook tab"));
                Gtk.Widget     page = null;
                CodeExpression pageVar;

                // Look for the page widget contained in this tab
                for (int n = 0; n < notebook.NPages; n++)
                {
                    if (notebook.GetTabLabel(notebook.GetNthPage(n)) == child)
                    {
                        page = notebook.GetNthPage(n);
                        break;
                    }
                }

                // If the page contains a placeholder, generate a dummy page
                if (page is Stetic.Placeholder)
                {
                    CodeVariableDeclarationStatement dvar = new CodeVariableDeclarationStatement(
                        "Gtk.Label".ToGlobalTypeRef(),
                        ctx.NewId(),
                        new CodeObjectCreateExpression("Gtk.Label".ToGlobalTypeRef())
                        );
                    ctx.Statements.Add(dvar);
                    ctx.Statements.Add(
                        new CodeAssignStatement(
                            new CodePropertyReferenceExpression(
                                new CodeVariableReferenceExpression(dvar.Name),
                                "Visible"
                                ),
                            new CodePrimitiveExpression(true)
                            )
                        );
                    ctx.Statements.Add(
                        new CodeMethodInvokeExpression(
                            parentExp,
                            "Add",
                            new CodeVariableReferenceExpression(dvar.Name)
                            )
                        );
                    pageVar = new CodeVariableReferenceExpression(dvar.Name);
                }
                else
                {
                    pageVar = ctx.WidgetMap.GetWidgetExp(page);
                }

                // Generate code for the tab
                CodeExpression var = ctx.GenerateNewInstanceCode(wrapper);

                // Assign the tab to the page
                CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression(
                    parentExp,
                    "SetTabLabel",
                    pageVar,
                    var
                    );
                ctx.Statements.Add(invoke);

                // Workaround for GTK bug. ShowAll is not propagated to tab labels.
                invoke = new CodeMethodInvokeExpression(
                    var,
                    "ShowAll"
                    );
                ctx.Statements.Add(invoke);
            }
            else
            {
                base.GenerateChildBuildCode(ctx, parentExp, wrapper);
            }
        }
Пример #7
0
		protected override void GenerateChildBuildCode (GeneratorContext ctx, CodeExpression parentExp, Widget wrapper)
		{
			Gtk.Widget child = (Gtk.Widget) wrapper.Wrapped;
			
			if (notebook.PageNum (child) == -1) {
				// It's a tab
				
				ctx.Statements.Add (new CodeCommentStatement ("Notebook tab"));
				Gtk.Widget page = null;
				CodeExpression pageVar;
				
				// Look for the page widget contained in this tab
				for (int n=0; n < notebook.NPages; n++) {
					if (notebook.GetTabLabel (notebook.GetNthPage (n)) == child) {
						page = notebook.GetNthPage (n);
						break;
					}
				}
				
				// If the page contains a placeholder, generate a dummy page
				if (page is Stetic.Placeholder) {
					CodeVariableDeclarationStatement dvar = new CodeVariableDeclarationStatement (
						"Gtk.Label".ToGlobalTypeRef (),
						ctx.NewId (),
						new CodeObjectCreateExpression ("Gtk.Label".ToGlobalTypeRef ())
					);
					ctx.Statements.Add (dvar);
					ctx.Statements.Add (
						new CodeAssignStatement (
							new CodePropertyReferenceExpression (
								new CodeVariableReferenceExpression (dvar.Name),
								"Visible"
							),
							new CodePrimitiveExpression (true)
						)
					);
					ctx.Statements.Add (
						new CodeMethodInvokeExpression (
							parentExp,
							"Add",
							new CodeVariableReferenceExpression (dvar.Name)
						)
					);
					pageVar = new CodeVariableReferenceExpression (dvar.Name);
				} else
					pageVar = ctx.WidgetMap.GetWidgetExp (page);
				
				// Generate code for the tab
				CodeExpression var = ctx.GenerateNewInstanceCode (wrapper);
				
				// Assign the tab to the page
				CodeMethodInvokeExpression invoke = new CodeMethodInvokeExpression (
					parentExp,
					"SetTabLabel",
					pageVar,
					var
				);
				ctx.Statements.Add (invoke);
				
				// Workaround for GTK bug. ShowAll is not propagated to tab labels.
				invoke = new CodeMethodInvokeExpression (
					var,
					"ShowAll"
				);
				ctx.Statements.Add (invoke);
			} else
				base.GenerateChildBuildCode (ctx, parentExp, wrapper);
		}
Пример #8
0
		internal protected override void GenerateBuildCode (GeneratorContext ctx, CodeExpression var)
		{
			if (ClassDescriptor.WrappedTypeName == "Gtk.Bin") {
			
				// Gtk.Bin needs a helper class which handles child allocation.
				// This class needs to be generated since Stetic won't be linked with
				// the app.
				
				bool found = false;
				foreach (CodeTypeDeclaration dec in ctx.GlobalCodeNamespace.Types) {
					if (dec.Name == "BinContainer") {
						found = true;
						break;
					}
				}
				
				if (!found)
					GenerateHelperClass (ctx);
				
				CodeMethodInvokeExpression attachExp = new CodeMethodInvokeExpression (
					new CodeTypeReferenceExpression (new CodeTypeReference (ctx.GlobalCodeNamespace.Name + ".BinContainer", CodeTypeReferenceOptions.GlobalReference)),
					"Attach",
					var
				);
				
				// If the Bin has its own action groups, we need to register
				// the resulting UIManager in the BinContainer, but it needs to be done
				// after generating it. Right now, we only keep a reference to
				// the BinContainer.
				
				string binContainerVar = null;
				
				if (IsTopLevel && LocalActionGroups.Count > 0) {
					binContainerVar = ctx.NewId ();
					ctx.Statements.Add (
						new CodeVariableDeclarationStatement (
							(ctx.GlobalCodeNamespace.Name + ".BinContainer"), 
							binContainerVar,
							attachExp
						)
					);
				} else {
					ctx.Statements.Add (attachExp);
				}
				
				base.GenerateBuildCode (ctx, var);
				
				// Register the UIManager, if the Bin has one
				
				if (binContainerVar != null && UIManagerName != null) {
					ctx.Statements.Add (
						new CodeMethodInvokeExpression (
							new CodeVariableReferenceExpression (binContainerVar),
							"SetUiManager",
							new CodeVariableReferenceExpression (UIManagerName)
						)
					);
				}
				
			} else
				base.GenerateBuildCode (ctx, var);
		}
Пример #9
0
        internal protected override void GenerateBuildCode(GeneratorContext ctx, CodeExpression var)
        {
            if (!String.IsNullOrEmpty(UIManagerName))
            {
                // Create an UI manager
                CodeFieldReferenceExpression uixp     = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), UIManagerName);
                CodeAssignStatement          uim_init = new CodeAssignStatement(uixp, new CodeObjectCreateExpression(typeof(Gtk.UIManager).ToGlobalTypeRef()));
                ctx.Statements.Add(uim_init);

                includedActionGroups = new ArrayList();

                // Generate action group creation
                foreach (ActionGroup actionGroup in actionGroups)
                {
                    // Create the action group
                    string grpVar = ctx.NewId();
                    CodeVariableDeclarationStatement uidec = new CodeVariableDeclarationStatement(
                        typeof(Gtk.ActionGroup).ToGlobalTypeRef(),
                        grpVar,
                        actionGroup.GenerateObjectCreation(ctx)
                        );
                    ctx.Statements.Add(uidec);
                    actionGroup.GenerateBuildCode(ctx, new CodeVariableReferenceExpression(grpVar));

                    // Insert the action group in the UIManager
                    CodeMethodInvokeExpression mi = new CodeMethodInvokeExpression(
                        uixp,
                        "InsertActionGroup",
                        new CodeVariableReferenceExpression(grpVar),
                        new CodePrimitiveExpression(includedActionGroups.Count)
                        );
                    ctx.Statements.Add(mi);

                    includedActionGroups.Add(actionGroup);
                }

                // Adds the accel group to the window
                Window w = GetTopLevel() as Window;
                if (w != null)
                {
                    CodeMethodInvokeExpression ami = new CodeMethodInvokeExpression(
                        ctx.WidgetMap.GetWidgetExp(w),
                        "AddAccelGroup",
                        new CodePropertyReferenceExpression(
                            uixp,
                            "AccelGroup"
                            )
                        );
                    ctx.Statements.Add(ami);
                }
                else
                {
                    // There is no top level window, this must be a custom widget.
                    // The only option is to register the accel group when
                    // the widget is realized. This is done by the Bin wrapper.
                }
            }

            if (tooltip != null && tooltip.Length > 0)
            {
                GetTopLevel().GenerateTooltip(ctx, this);
            }

            base.GenerateBuildCode(ctx, var);
        }