VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Directory :  /usr/share/GNUstep/Documentation/Developer/Gui/ProgrammingManual/AppKit/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/share/GNUstep/Documentation/Developer/Gui/ProgrammingManual/AppKit/gnustepapplications.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- (C) 2005-2006 Christopher Armstrong.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2, as published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

This documentation is provided on an "AS IS" BASIS, WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND USEFULNESS
OF THE DOCUMENTATION IS WITH YOU (THE LICENSEE). IN NO EVENT WILL THE COPYRIGHT
HOLDERS BE LIABLE FOR DAMAGES, INCLUDING ANY DIRECT, INDIRECT,
SPECIAL, GENERAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF
THE USE OR INABILITY TO USE THIS DOCUMENTATION (INCLUDING BUT NOT
LIMITED TO LOSS OF DATA, USE, OR PROFITS; PROCUREMENT OF SUBSTITUTE
GOODS AND SERVICES; OR BUSINESS INTERUPTION) HOWEVER CAUSED, EVEN
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -->
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>gnustepapplications (Using the GNUstep AppKit 0.1)</title>

<meta name="description" content="gnustepapplications (Using the GNUstep AppKit 0.1)">
<meta name="keywords" content="gnustepapplications (Using the GNUstep AppKit 0.1)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="index.html" rel="start" title="Top">
<link href="conceptindex.html" rel="index" title="conceptindex">
<link href="index.html" rel="up" title="Top">
<link href="applicationmakefiles.html" rel="next" title="applicationmakefiles">
<link href="basicconcepts.html" rel="prev" title="basicconcepts">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en">
<span id="gnustepapplications"></span><div class="header">
<p>
Next: <a href="applicationmakefiles.html" accesskey="n" rel="next">applicationmakefiles</a>, Previous: <a href="basicconcepts.html" accesskey="p" rel="prev">basicconcepts</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> &nbsp; [<a href="conceptindex.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<span id="GNUstep-Applications"></span><h2 class="chapter">3 GNUstep Applications</h2>

<span id="index-AppKit"></span>
<p>The AppKit provides services to develop complex and modern GUI applications. Some of these services include generic controls and displays, pasteboard and true drag-and-drop, separated interface and code files, etc.
</p>
<span id="index-application_002dcentric-programming"></span>
<p>Compared to other platforms and development toolkits, GNUstep takes a slightly different paradigm to development. Operating systems such as Microsoft Windows treat applications in a more window-centric manner, e.g. each document starts a new instance of the application, in a new window with its own menu.
</p>
<p>In GNUstep, applications are treated in an application centric manner. This means that there is one menu for the application, and documents and other windows are associated with this menu instance. This probably requires a different attitude to development, but the AppKit is quite well integrated and logical to convey some of the ideas it introduces.
</p>
<span id="Components"></span><h3 class="section">3.1 Components</h3>

<span id="index-applications_002c-components"></span>
<p>A GNUstep application has various components that are assembled (from a developer&rsquo;s perspective) into an <em>app wrapper</em>. An app (application) wrapper is a directory with the extension <samp>.app</samp> that holds the application&rsquo;s <em>executable</em> and <em>resource files</em>, as noted below.
</p>
<span id="Interface-File_0028s_0029"></span><h4 class="subsection">3.1.1 Interface File(s)</h4>

<p>An application has one or more <em>interface files</em>. These are separate file entities that are used to display the graphical interface that your application has. They are comparable to .glade interface files used in GNOME or those used in Qt, however they go a bit further, permitting easy linking against your objects, so that you are freed from writing wrapper code. They are created using Gorm, GNUstep&rsquo;s application modelling programme. It allows real drag and drop GUI assembly and direct control editing.
</p>
<p>Most applications take one interface file, which contains their main menu and their main window, presented to the user. They will also take you preferences and other auxilliary windows that you application requires. They take no Objective-C code (being strictly interface only), but generic class templates are able to be generated for outlets and actions that you set Gorm to integrate with.
</p>
<p>Interface files are commonly referred to as &quot;nib&quot; files or &quot;gorm&quot; files, taken from the name of programmes used to generate them. They appear as a directory on your filesystem, and often take the name of your application with the extension <samp>.gorm</samp>.
</p>
<span id="Application-property-list"></span><h4 class="subsection">3.1.2 Application property list</h4>

<p>This file is a property list, containing the defaults and some information used to load your application, include the main interface file, supported document types and interapplication services. It usually takes the name <samp>Info-gnustep.plist</samp>. See the base manual for more details about the syntax and structure of property lists. We will provide the details of application property lists through this manual.
</p>
<span id="Makefile"></span><h4 class="subsection">3.1.3 Makefile</h4>
<span id="index-makefiles"></span>

<p>Like GNUstep tools, applications have a file, <samp>GNUmakefile</samp>, for easy application compilation, linking and assembly into an app wrapper. It includes the name and version of your application, source code file, required libraries and frameworks and  your resource files (detailed below). 
</p>
<span id="index-resource-files"></span>
<span id="Resource-Files"></span><h4 class="subsection">3.1.4 Resource Files</h4>

<p><em>Resource Files</em> are any sorts of resources that your application will need to operate, including interface files and any icons, images, data, etc. that your application uses. They are stored in the <samp>Resources</samp> directory in your application&rsquo;s app wrapper.
</p>
<p>You will most likely ever need only two resources: your interface file, and your application&rsquo;s property list (Info-gnustep.plist).
</p>
<span id="Constructing-an-application"></span><h3 class="section">3.2 Constructing an application</h3>

<span id="index-applications_002c-construction"></span>
<p>Below, we have listed the main steps required in the building of an application from scratch. These steps are listed in a general, but you will generally need to come back to them again e.g. if you add new source or interface files to your application, you will need to come back and modify the makefile.  See the chapters on Makefile creation, Interface files and Application property lists for more details on the construction of these various files.
</p>
<ol>
<li> GNUmakefile

<p>You will need to create a GNUmakefile to build your application. A generic template is shown in the chapter entitled see <a href="applicationmakefiles.html#Application-Makefiles">Application Makefiles</a>.
</p>
</li><li> Interface Files

<p>You will need at least one interface file (<samp>.gorm</samp>) for your application, however, you can create your interface programatically if necessary (although this is rarely recommended).
</p>

</li><li> Application Property List

<p>This is generally necessary, especially if you want to define your main interface file, however it is possible to let the <code>make</code> application generate it for you.
</p>
</li><li> Other Resource Files

<p>These may include icons, images, other property lists, application-specific data files. You can add whatever resource files you like, including directories (which should be added recursively).
</p>
</li></ol>

<span id="Building-a-First-Application"></span><h3 class="section">3.3 Building a First Application</h3>

<p>This section attempts to run you through the steps that you would usually go through to assemble an application from scratch. We expect that you have some experience programming with Objective-C, especially with GNUstep, and that you at least have it installed and running with some applications installed.
</p>
<p>Apart from helping you setup the infrastructure for a basic application, we&rsquo;ve provided instructions for a basic control and event handler as an example. You may wish to ignore these steps, but they&rsquo;re useful reminders if you use these instructions in the future.
</p>
<p>A checklist includes:
</p><ol>
<li> GNUstep
Make sure that you have gnustep-make, gnustep-base, gnustep-gui and gnustep-back installed and running on your system. There system-specific instructions for installing GNUstep on different systems at the website, <cite>http://www.gnustep.org</cite>. We also expect that you have some experience using it, such as sourcing the GNUstep startup shell file and starting applications. There are various tutorials and instructions available on the internet for getting GNUstep up and running.

</li><li> Gorm.app
Gorm, as mentioned above, is the GNUstep interface builder. It&rsquo;s available as an application from the GNUstep web site, and is the recommended means to build interfaces for applications. Make sure that it will startup and operate correctly on your system. We will use it to build the interface for our application.

</li><li> A text editor
Depending on what platform your working on and whether or not you&rsquo;re using a GUI, an editor could be anything simple from <code>vim</code> to a good quality free editor like <code>gedit</code> or <code>kate</code>. You will need it to edit the source code files and makefiles we will use to build the application.

</li><li> A shell
GNUstep&rsquo;s makefile system depends heavily on the shell environment that <code>make</code> commands are invoked in. On Unix, this could be <samp>sh</samp>, <samp>bash</samp>, <samp>ksh</samp>, <samp>csh</samp> or whatever you prefer to work with. On Windows, you will want to use MSYS which comes with a minimal Unix-like shell (a port of <code>bash</code>) which is sufficient for use with GNUstep. If you use the installable binary version of GNUstep for Windows, you should have a copy of MSYS installed.

<p>We will assume somewhat that you know your way around your filesystem using it, and that you know most basic commands for creating files, starting programmes, manipulating directory structures, etc.
</p>
</li></ol>

<span id="Setup"></span><h4 class="subsection">3.3.1 Setup</h4>

<p>Startup your shell and source GNUstep.sh from your GNUstep installation (if it&rsquo;s not sourced by default). Create a directory for your application sources to be created in. For example:
</p><div class="example">
<pre class="example">&gt; cd ~
&gt; mkdir firstapp
&gt; cd firstapp
&gt; . /usr/lib/GNUstep/System/Library/Makefiles/GNUstep.sh
&gt;
</pre></div>

<p>In the above, we simply created a new directory under our home directory called <samp>firstapp</samp>, changed into it and sourced our GNUstep installation (which in this case is under <samp>/usr/lib</samp><a id="DOCF1" href="#FOOT1"><sup>1</sup></a>).
</p>
<p>Next we will create our makefile. Using your favourite editor, create a file called <samp>GNUmakefile</samp> (the case is important). In this case we&rsquo;re using <code>vim</code>:
</p><div class="example">
<pre class="example">touch GNUmakefile
vim GNUmakefile
</pre></div>

<p>And in the makefile, add the following:
</p><div class="example">
<pre class="example">include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = FirstApp

FirstApp_OBJC FILES =  main.m  \
  MyController.m 

FirstApp_MAIN_MODEL_FILE = FirstApp.gorm

FirstApp_RESOURCE_FILES = FirstApp.gorm

include $(GNUSTEP_MAKEFILES)/application.make

</pre></div>

<p>The first line of the makefile includes some declarations common to all makefiles (tools, bundles, etc).
</p>
<p><var>APP_NAME</var> contains a space-separated list of the applications to build. In this case we&rsquo;re only building one (FirstApp). The application wrapper that is outputted will be called <samp>FirstApp.app</samp>. This name also is used to prefix each of the following variables. If you were to change this value, you would have to change the value of <var>_OBJC_FILES</var>, <var>_MAIN_MODEL_FILE</var>, etc. accordingly.
</p>
<p><var>FirstApp_OBJC_FILES</var> contains a list of each of the Objective-C files that will be compiled into this programme. Note that like normal makefiles, you can split a variable declaration like this over a number of lines by using the &quot;\&quot; delimeter.
</p>
<p><var>FirstApp_MAIN_MODEL_FILE</var> is the main interface file wrapper. 
</p>
<p><var>FirstApp_RESOURCE_FILES</var> contains a list of all the resources, including interface files, icons, property lists etc.
</p>
<p>The final line lets the makefile system know we want to build an application.
</p>
<span id="Interface-File"></span><h4 class="subsection">3.3.2 Interface File</h4>

<p>Make sure you are familiar with Gorm before using this. Refer to the <cite>Gorm Manual</cite>, a link to which should be at http://www.gnustep.org/experience/Gorm.html.
</p>
<p>Load up <code>Gorm.app</code> and create a &quot;New Application&quot;. A window should appear with the title and a project called &quot;UNTITLED&quot;. 
</p><div class="example">
<pre class="example">openapp Gorm.app

From the menu, select Document-&gt;New Application
</pre></div>

<p>Save your project as &quot;FirstApp.gorm&quot; by going to Document-&gt;Save, navigating to the project directory, typing in &quot;FirstApp&quot; as the filename and clicking &quot;OK&quot;.
</p>
<p>Select your window in the project pane. Switch to the Inspector and give it a new name such as &quot;My First Application&quot;.
</p>
<p>Switch back to the project pane. Select &quot;Classes&quot; from the toolbar. From the class view, select &quot;NSObject&quot;, goto the main menu and select Classes-&gt;Create Subclass.
</p>
<p>Double-click the new class in the class view, and double-click to rename it to &quot;MyController&quot; (case is important). Click &quot;OK&quot; if prompted. We&rsquo;re going to use this class as our application&rsquo;s main controller, but you can create as many &quot;controller&quot; classes as you like with whatever names you choose. It just so happens that we&rsquo;ve decided to create a file with the name &quot;MyController.m&quot; that will contain the implementation of this class. Note that GNUstep doesn&rsquo;t enforce a strict MVC pattern on your classes; it merely separates the view part into it&rsquo;s own classes which you configure in Gorm.app, and lets you handle data and behaviour (Model and Controller) in your code as you like.
</p>
<p>Select the button in the &quot;Action&quot; column for &quot;MyController&quot; then goto Classes-&gt;Add Outlet/Action. Rename the action to &quot;myAction:&quot;. Select the class again, and goto Classes-&gt;Instantiate. Again, we could call this action whatever we like, just make sure that it&rsquo;s not something generic like &quot;click:&quot;, which are used by the NSResponder class. The name of the button in method name form is often a good choice.
</p>
<p>For the MyController class, goto the main menu and select Classes-&gt;Create Class Files. Save them as &quot;MyController.h&quot; and &quot;MyController.m&quot;. Gorm.app fills out the basic details for this class (including the action). If you modify the actions and/or outlets on the class in Gorm.app in the future, you will want to add them to your class interface and implementation manually. Gorm.app will override your modifications to files if you tell it to create the class files at some time in the future.<a id="DOCF2" href="#FOOT2"><sup>2</sup></a>
</p>
<p>Goto the palette, click the third toolbar button and then click and drag a new button object onto the window. Double-click the button to rename it and call it &quot;My Action&quot;.
</p>
<p>We now want to connect the button to the action on <var>MyController</var>. First switch to the &quot;Objects&quot; pane in the project view. Note that our <var>MyController</var> class is listed as an object instance, as we instantiated it before. Select it, switch to the Inspector and then select &quot;Connections&quot; from the drop-down box.
</p>
<p>Now, make sure that the application window with the button on it and the project window are both visible at the same time. Hold down your first control key (usually left-Ctrl), click the button on the window, and drag the icon to the <var>MyController</var> object in the Objects pane and release. While you are dragging the mouse, you will note that the icon looks like a small circle with a &quot;T&quot; in it. The source object (the button) will continue to contain the &quot;S&quot; circle while the target object (the <var>MyController</var> instance) contains the &quot;T&quot; circle.
</p>
<p>Goto File-&gt;Save to save your interface file and then quit Gorm.app.
</p>
<span id="Code"></span><h4 class="subsection">3.3.3 Code</h4>

<p>Although we have got Gorm.app to autogenerate our class files, we will want to modify them so that they do something (marginally) useful. Open &quot;MyController.m&quot;. At the moment it should look something like:
</p><div class="example">
<pre class="example">#import &quot;MyController.h&quot;
#import &lt;AppKit/AppKit.h&gt;

@implementation MyController

- (void) myAction:(id) sender
{
}

@end

</pre></div>


<div class="footnote">
<hr>
<h4 class="footnotes-heading">Footnotes</h4>

<h5><a id="FOOT1" href="#DOCF1">(1)</a></h3>
<p>Replace <samp>/usr/lib</samp> with the path to your GNUstep installation</p>
<h5><a id="FOOT2" href="#DOCF2">(2)</a></h3>
<p>If you really don&rsquo;t want to add the outlets/actions to your class by hand if you modify the interface in the future, you could just save the classes to differently named files and then merge the changes back into the original files.</p>
</div>
<hr>
<div class="header">
<p>
Next: <a href="applicationmakefiles.html" accesskey="n" rel="next">applicationmakefiles</a>, Previous: <a href="basicconcepts.html" accesskey="p" rel="prev">basicconcepts</a>, Up: <a href="index.html" accesskey="u" rel="up">Top</a> &nbsp; [<a href="conceptindex.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>

VaKeR 2022