How to display a clickable button in our beloved IRIX motif style.

IRIX/Nekoware development, porting and related topics.
Forum rules
Any posts concerning pirated software or offering to buy/sell/trade commercial software are subject to removal.
User avatar
jimmer
Donor
Donor
Posts: 466
Joined: Tue Oct 12, 2004 3:54 pm
Location: London, Ingerlund

How to display a clickable button in our beloved IRIX motif style.

Unread postby jimmer » Fri Apr 29, 2016 10:55 am

In 2012 I posted an annotated example of displaying the familiar 'Hello World' greeting using Viewkit/Motif. In an astounding display of naivite, I imagined that this small gesture would inspire you all to Fell Deeds and light the coding fires under your collective arses ushering in a Glorious New Era of hobbyist software development for IRIX.

You can stop laughing now.

Four years later, I find myself squashed under a mountain of pain called 'The using of the Java for to make Great and Glorious Softwares for the Android' and it seems totally sane to waste precious real-life time putting together another pointless example of Viewkit/Motif 101.

Queue scratchy Shaw Brother's movie flying logo music.


0. Make sure you have the MIPSpro C/C++ compiler installed. cf. my 2012 Hello World example for an explanation of why gcc wont work with the stock IRIX Viewkit.

1. Start your favourite text editor and open a new file.

2. Copy/Paste the following into your editor and save it into a file called 'Makefile'. This is a GNU Make makefile, it wont work with IRIX's smake/pmake. Nekoware is your friend.

Code: Select all

APP_NAME    = button

APP_OBJS    = Main.o

DIRS_INC    = -I.
DIRS_LIB   =

LIBS_STD_C   = -lm
LIBS_STD_CXX   = -lC -lCio
LIBS_X11   = -lXt -lX11 -lPW
LIBS_MOTIF   = -lSgm -lXm
LIBS_DMEDIA   = -lmoviefile -lmovieplay -ldmedia
LIBS_OPENGL   = -lGLw -lGLU -lGL
LIBS_VK    = -lvk
LIBS_EXTRA    =

LIBS      = $(LIBS_EXTRA)    \
        $(LIBS_VK)       \
        $(LIBS_OPENGL)    \
        $(LIBS_MOTIF)      \
        $(LIBS_X11)      \
        $(LIBS_STD_CXX)   \
        $(LIBS_STD_C)

CC      = c99
CC_OPTS    = -O2

CXXC      = CC
CXXC_OPTS    = -O2 -LANG:std

# Suppress MIPSpro compiler warnings:
# 15 - Multiply defined
# 84 - libxxx not used for resolving any symbol
LINK_OPTS   = -woff 15,84

all : $(APP_NAME)

$(APP_NAME): ${APP_OBJS}
   ${CXXC} ${APP_OBJS} ${DIRS_LIB} ${LIBS} ${LINK_OPTS} -o ${APP_NAME}

%.o : %.c   
   ${CC} ${CC_OPTS} ${DEFINES} ${DIRS_INC} -c $<

%.o : %.C   
   ${CXXC} ${CXXC_OPTS} ${DEFINES} ${DIRS_INC} -c $<


clean :
   rm -rf ${APP_NAME} *.o core *~ ii_* dir.txt



3. Open another new file and enter the most basic of C++ in order to have a runnable bit of skeleton code:

Code: Select all

int
main(int argc, char *argv[]) {

   return 0;
}

4. Save this into a file called 'Main.C'.

5. Open a terminal and change to the directory containing these files and run

Code: Select all

make


Junk will fly past and you will find there's an executable binary in your directory called 'button'

6. Run it

Code: Select all

./button


and experience the glory of a compiled bit of C++ code that does absolutely nothing.

7. Modify your C++ code to look like this:

Code: Select all

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial");

   return 0;
}


8. Save the file and run make. It will fail.

9. The reason for the failure is the fact that our code tries to use code that is not built-in to the C++ language. Specifically the notion of a 'VkApp' simply doesn't exist in C++. Instead it's a pile of C++ code that the nice folks at SGI wrote 25 years ago and we need to 'include' it into our C++ code before we can use it.

10. Modify your C++ like so:

Code: Select all

#include <Vk/VkApp.h>

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial");

   return 0;
}


11. Save the file and run make. It will fail, but differently.

12. The C++ compiler provides useful though often cryptic error messages. Do not ignore them as 'jibberish', instead try and understand what the compiler is complaining about.

13. In our case this 2nd error tells us that:

Code: Select all

No instance of constructor "VkApp::VkApp" matches the argument list.


granted it's hard to understand this error without more background, which I;m too lazy to provide here, but notice how the compiler shows you a little bit of your code and a nice caret (^) at the point where it gets confused... The compiler is telling you (more or less) where it gets confused and that your invocation of VkApp is incomplete or incorrect.

14. We need more knowledge; at your terminal run

Code: Select all

man vkapp


the plain-text manual page for vkapp will appear. I leave it to the reader to peruse its full contents and the contents of other relevant man pages, but for now notice how under the 'PUBLIC PROTOCOL SUMMARY' heading there's a heading 'Constructors' which describes two versions of VkApp's 'invocation'. If you look closely, you'll see that both versions require a

Code: Select all

char *appClassName

which we seem to have in our current code, but then there's

Code: Select all

int *arg_c
char **arg_v

which our code is curently lacking. Nice of the compiler to tell me :)

15. Press 'q' to quit man and look at your minimal C++ code. Notice how

Code: Select all

main(int argc, char *argv[])


seems to carry the other values that VkApp needs.

16. Modify your C++ like so:

Code: Select all

#include <Vk/VkApp.h>

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   return 0;
}


17. Save your file and run make. It will succeed.

18. Run the binary and notice that nothing seems to be happening. However, understand that behind the scenes the values argc and argv are being propagated through your progamme. You're not seeing any of it because we've not told our code to show us anything.

19. Modify you code as follows:

Code: Select all

#include <Vk/VkApp.h>

int
main(int argc, char *argv[]) {

   cout << argc << endl;

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   return 0;
}



20. The compiler will complain. Again, carefully read the errors it displays. Obviously it's an error of a type we've seen before, we're missing some code from someplace. In this case we need to pull in the C++ 'show us stuff on the terminal' functions we're trying to use.

21. Modify you code as follows:

Code: Select all

#include <iostream>
using namespace std;

#include <Vk/VkApp.h>

int
main(int argc, char *argv[]) {

   cout << argc << endl;

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   return 0;
}


22. Run make and more junk than usual will fly past but the compilation should succeed.

23. Run

Code: Select all

./button


and notice how it displays a '1' before you get your prompt back. It seems the token 'argv' contains the value 1.

24. Modify your code to read like so:

Code: Select all

#include <iostream>
using namespace std;

#include <Vk/VkApp.h>

int
main(int argc, char *argv[]) {

   cout << argc
       << ", "
       << argv[0]
       << endl;

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   return 0;
}

Notice how the cout 'line' in our code is spead out over 4 actual lines. C/C++ doesn't care about your whitespace all it needs is matching bracket closure and correct semi-colon placement at the end of 'lines'.

25. It would seem that argc and argv contain information about the command line arguments with which our programme was called. argc contains the number of items on the command line and argv contains all the actual items passed on the command line.

26. Run our binary like so:

Code: Select all

./button arg1 arg2 arg3


and notice how how the argc value is now 4.

27. Modify the code like so:

Code: Select all

#include <iostream>
using namespace std;

#include <Vk/VkApp.h>

int
main(int argc, char *argv[]) {

   cout << argc
       << ", "
       << argv[0]
       << endl;

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   cout << app->argc()
       << ", "
       << app->argv(0)
       << endl;

   return 0;
}


28. Run make and then run the resulting binary. You should see two identical lines echo on your terminal. The first set of values are the ones directly sent into main() from the command line. The second line of values are the ones that VkApp received as copies of the ones from main(). It seems that the various values are actually being pushed around inside our programme.

29. To wrap this up, modify your code to read:

Code: Select all

#include <iostream>
using namespace std;

#include <Vk/VkApp.h>

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   cout << app->name()
       << endl;

   return 0;
}


Once it's initialised properly, VkApp knows how to give you certain bits of information relating to you application in a sane manner. Calling app->name() is much clearer than app->argv(0). Run 'man VkApp' or dive into the excellent 'ViewKit Programmers guide' PDF for more information on the VkApp functions - or 'methods' as they are called in C++ parlance.

30. Well, that's all hunky dory but where's that button? It's coming, but first we need to make a window to display the button in.

31. Modify your code like so:

Code: Select all

#include <iostream>
using namespace std;

#include <Vk/VkApp.h>
#include <Vk/VkSimpleWindow.h>

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   VkSimpleWindow *win = new VkSimpleWindow("Vindu");

   return 0;
}


32. Run make and then 'button'. Once again nothing seems to be happening...

33. Much like before with our invisible arguments issue, the programme isn't showing much activity. However, it is doing stuff but being a very simple minded programme it's only doing what it's been told and we haven't told it to show itself.

34. Modify the code like so:

Code: Select all

#include <iostream>
using namespace std;

#include <Vk/VkApp.h>
#include <Vk/VkSimpleWindow.h>

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   VkSimpleWindow *win = new VkSimpleWindow("Vindu");

   win->show();

   return 0;
}


compile and run code and be frustrated that it still doesn't show much.

35. At this point we need to mention that GUI programming is 'event driven'. This means that things inside our programme happen in response to 'events' on the outside. Events being things as diverse as mouse movements and clicks or the arrival of network traffic. Currently however, there's nothing in our code that sits around waiting for such events to happen. Therefore, we're not seeing much on the screen when we run our programme. Fortunately, VkApp has a simple method which starts and then keeps this 'event loop' running for us.


36. Modify the code like so:

Code: Select all

#include <iostream>
using namespace std;

#include <Vk/VkApp.h>
#include <Vk/VkSimpleWindow.h>

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   VkSimpleWindow *win = new VkSimpleWindow("Vindu");

   win->show();

   app->run();

   return 0;
}


37. Run make and then run the resulting binary. Fist pump.

38. The window is fully functional but unfortunately displays a horrible icon when minimised. Naturally, this must be fixed before we carry on.

39. Create a 85x67 pixel SGI rgb bitmap which you want to use as your icon image.

40. Rename this file to <VkApp name>.icon and place it in

Code: Select all

$HOME/.icons


In our current case the file would be:

Code: Select all

$HOME/.icons/Tutorial.icon


note that the filename is case sensitive and that it has to exactly match the name you used when you called VkApp(). Run ./button again and when you minimise it you should see that it now carries a shiny new icon.

41. Amd while we're dealing with cosmetics, notice that the icon label and window title are the same as the name you passed to VkSimpleWindow(). You might want to change this programmatically...

42. Modify your code like so:

Code: Select all

#include <iostream>
using namespace std;

#include <Vk/VkApp.h>
#include <Vk/VkSimpleWindow.h>

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   VkSimpleWindow *win = new VkSimpleWindow("Vindu");

   win->setTitle("Kitty Killer v0.1");
   win->setIconName("Kitty Killer");

   win->show();

   app->run();

   return 0;
}


43. Now, for our button. Modify the code like so:

Code: Select all

#include <iostream>
using namespace std;

#include <Xm/PushB.h>

#include <Vk/VkApp.h>
#include <Vk/VkSimpleWindow.h>

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   VkSimpleWindow *win = new VkSimpleWindow("Vindu");

   win->setTitle("Kitty Killer v0.1");
   win->setIconName("Kitty Killer");

   int x = 0;
   Arg   args[10];

   XmString label;

    label = XmStringCreateLocalized("Click me!");

   XtSetArg(args[x], XmNlabelString, label); x++;

   Widget btn = XtCreateWidget("myBtn", xmPushButtonWidgetClass, win->mainWindowWidget(), args, x);

   XtManageChild(btn);

   win->show();

   app->run();

   return 0;
}


44. Run make and run the resulting binary - a button will appear in the window. Yay! However, clicking it will do very little as of yet.

The active ingredients in all of this are a pair of X ToolKit (Xt) functions: XtCreateWidget() and XtManageChild(). Remember, because Motif is built on/with Xt it's natural that you'll see Xt functions being caaled in Motif code. Though I'm not sure why XtManageChild() wasn't called XtManageWidget() which seems tidier to me. Regardless, those are the two functions we need to use in order to make any sort of Motif 'widget' appear in our User Interface.

The first function creates a widget of a certain type when we provide it with a name, a widget type, a parent and its various properties like colour, font and caption.

The second function brings the widget 'under management' - ie. it makes the widget visible to the user.

This however is the oldest form of XtCreateWidget()/XtManageChild(). We need to specify the various widget properties by passing an array of 'args', and we need to keep track of how many items we have in the array. and finally we need to explicitly call XtManageChild(). There is a less ancient and marginally easier to read format for doing all this.

45. Modify the code like so:

Code: Select all

#include <iostream>
using namespace std;

#include <Xm/PushB.h>

#include <Vk/VkApp.h>
#include <Vk/VkSimpleWindow.h>

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   VkSimpleWindow *win = new VkSimpleWindow("Vindu");

   win->setTitle("Kitty Killer v0.1");
   win->setIconName("Kitty Killer");

   Widget btn = XtVaCreateManagedWidget(

      "myBtn", xmPushButtonWidgetClass, win->mainWindowWidget(),

      XmNlabelString, XmStringCreateLocalized("Click me!"),

      NULL);

   win->show();

   app->run();

   return 0;
}

46. Now that we have the button, modify the code like so to make it 'work':

Code: Select all

#include <iostream>
using namespace std;

#include <Xm/PushB.h>

#include <Vk/VkApp.h>
#include <Vk/VkSimpleWindow.h>

void
cb_btnClick(Widget w, XtPointer clientData, XtPointer callData) {

   cout << "EEEEP!" << endl;
}

int
main(int argc, char *argv[]) {

   VkApp *app = new VkApp("Tutorial", &argc, argv);

   VkSimpleWindow *win = new VkSimpleWindow("Vindu");

   win->setTitle("Kitty Killer v0.1");
   win->setIconName("Kitty Killer");

   Widget btn_1 = XtVaCreateManagedWidget(

      "myBtn", xmPushButtonWidgetClass, win->mainWindowWidget(),

      XmNlabelString, XmStringCreateLocalized("Click me!"),

      NULL);

   XtAddCallback(btn_1, XmNactivateCallback, cb_btnClick, NULL);
   
   win->show();

   app->run();

   return 0;
}

And there you have it. XtAddCallback() connects the button's XmNactivateCallback to the cb_btnClick() function which makes the button come 'alive'.

Of course in a non-toy programme you'd be setting up your widgets and callbacks in a much different way. Also I've glossed ove a ton of C/C++ issues and the way I've added a widget here is super mega uber evil; I'm totally glossing over the notion of the Widget Tree and where that 'parent' widget comes from. Not Good. That said, this thing here does cover the basics of Motif widget creation and callback connection.

Maybe I'll cover those topics in the next installment - four years from now :)

Hope this helps.

J.
:Fuel: redbox 800Mhz 4Gb V12
:O2: bluebox 200Mhz 256Mb AV1+O2Cam

User avatar
vishnu
Donor
Donor
Posts: 3174
Joined: Sun Mar 18, 2007 3:25 pm
Location: Minneapolis, Minnesota USA

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby vishnu » Fri Apr 29, 2016 11:10 am

jimmer wrote:I imagined that this small gesture would inspire you all to Fell Deeds and light the coding fires under your collective arses ushering in a Glorious New Era of hobbyist software development for IRIX.

Hey from the Payback is a Bee-yotch Department I never saw you participate in my Blackjack simulator for Irix thread, though admittedly it's written purely in Motif but only because my Linux and Solaris boxes don't have Viewkit... :roll:

Thanks for posting this I'll give it a try when I get back to my Irix box tonight... :P
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...

:Tezro: :Octane2:

jpstewart
Donor
Donor
Posts: 429
Joined: Tue Sep 21, 2010 3:31 pm
Location: Southwestern Ontario, Canada

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby jpstewart » Sat Apr 30, 2016 7:47 am

Wow, that's a great write-up jimmer! It's a nice step-by-step guide that shows non-programmers a simplified version of the iterative process that typically goes into software development in addition to teaching a bit about ViewKit. Very well done!

Does this mean you're now Professor Jimmer of Nekochan University?
:Indigo2IMP: :Octane: :Indigo: :O3x0:
Sun SPARCstation 20, Blade 2500, T5240
HP C8000

User avatar
uunix
Donor
Donor
Posts: 1795
Joined: Sun Mar 27, 2011 12:48 pm
Location: Stourbridge / England / UK

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby uunix » Sat Apr 30, 2016 8:16 am

I am going to follow this, this very afternoon.. evening.. morning.. and then I'm going to incorporate my super non-predicting lotto prediction program in some way!!

Thank god it's not Eurovision song contest night!
-----------------------------------------------------------------------
Hey Ho! Pip & Dandy!
:Octane2: :O2: :Indigo: :Indy:
-----------------------------------------------------------------------

User avatar
commodorejohn
Posts: 652
Joined: Tue Oct 02, 2012 1:22 pm
Contact:

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby commodorejohn » Sat Apr 30, 2016 11:05 am

jimmer wrote:In 2012 I posted an annotated example of displaying the familiar 'Hello World' greeting using Viewkit/Motif. In an astounding display of naivite, I imagined that this small gesture would inspire you all to Fell Deeds and light the coding fires under your collective arses ushering in a Glorious New Era of hobbyist software development for IRIX.

Scarily enough I think I'm probably going to have to delve into this general area in the not-too-distant future, once my game-engine project is far enough along that I start needing a construction-set program for the actual content...
Computers: Amiga 1200, DEC VAXStation 4000/60, DEC MicroPDP-11/73
Synthesizers: Roland JX-10/SH-09/HS-80/MT-32/D-50, Yamaha DX7-II/V50/TX7/TG33/FB-01, Korg MS-20 Mini/ARP Odyssey/DW-8000/M1, Ensoniq SQ-80, E-mu Emax HD/Proteus-2, Casio CZ-5000, Moog Satellite, Sequential Circuits Prophet-600

User avatar
vishnu
Donor
Donor
Posts: 3174
Joined: Sun Mar 18, 2007 3:25 pm
Location: Minneapolis, Minnesota USA

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby vishnu » Sat Apr 30, 2016 7:04 pm

commodorejohn wrote:
jimmer wrote:In 2012 I posted an annotated example of displaying the familiar 'Hello World' greeting using Viewkit/Motif. In an astounding display of naivite, I imagined that this small gesture would inspire you all to Fell Deeds and light the coding fires under your collective arses ushering in a Glorious New Era of hobbyist software development for IRIX.

Scarily enough I think I'm probably going to have to delve into this general area in the not-too-distant future, once my game-engine project is far enough along that I start needing a construction-set program for the actual content...

Keep in mind that Viewkit only runs on Irix boxes, unless you're willing to fork over the cash to ICS for the Linux version, which I did 16 or 17 years ago. Needless to say you don't get the source code just the shared object library, static library (and the header files), and I can't recall if you can distribute it with your application free of charge. Anyway, from the looks of it's page at the ICS website, it appears to be abandonware. Too bad, because Viewkit is vastly superior in every way to gtk. Not that that's saying much. Link to the Viewkit page at ICS: http://motif.ics.com/products/viewkit
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...

:Tezro: :Octane2:

User avatar
commodorejohn
Posts: 652
Joined: Tue Oct 02, 2012 1:22 pm
Contact:

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby commodorejohn » Sat Apr 30, 2016 9:46 pm

Well, that's why I said "general area" - probably won't be ViewKit, but sooner or later I'm going to have to learn my way around one of 'em (I have no idea what, though - Qt looks like a nightmare of crazy preprocessor shenanigans and is C++ oriented, and Gtk seems to be run by the same kind of masturbatory prescriptivist UI theorists that already wrecked GNOME. I'll have to do some digging.)
Computers: Amiga 1200, DEC VAXStation 4000/60, DEC MicroPDP-11/73
Synthesizers: Roland JX-10/SH-09/HS-80/MT-32/D-50, Yamaha DX7-II/V50/TX7/TG33/FB-01, Korg MS-20 Mini/ARP Odyssey/DW-8000/M1, Ensoniq SQ-80, E-mu Emax HD/Proteus-2, Casio CZ-5000, Moog Satellite, Sequential Circuits Prophet-600

User avatar
jimmer
Donor
Donor
Posts: 466
Joined: Tue Oct 12, 2004 3:54 pm
Location: London, Ingerlund

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby jimmer » Sat Apr 30, 2016 11:49 pm

vishnu wrote:Keep in mind that Viewkit only runs on Irix boxes, unless you're willing to fork over the cash to ICS for the Linux version, which I did 16 or 17 years ago. Needless to say you don't get the source code just the shared object library, static library (and the header files), and I can't recall if you can distribute it with your application free of charge.


take a look at http://viewklass.sourceforge.net/

I'm sure you'll have to clean it up a bit for it to compile on modern systems. Also, there's a chunk of functionality missing. No use of overlay planes and the process management stuff is not implemented. Some of the complex 'gift' components like VkDeck, VkOutline, VkPie etc. are missing too, but the core stuff is all there.

Somebody should give it a go, see how it flies...
:Fuel: redbox 800Mhz 4Gb V12
:O2: bluebox 200Mhz 256Mb AV1+O2Cam

User avatar
foetz
Moderator
Moderator
Posts: 6543
Joined: Mon Apr 14, 2003 4:34 am
Contact:

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby foetz » Sun May 01, 2016 12:38 am

since the topic says nothing about viewkit in particular i figured i could just as well show the other method of getting the indigo magic look without viewkit. the key to achieve that is adding some specific fallback resources and then linking against libSgm. this has some major advantages:

- more control
- no c++
- no additional layer on top of motif which itself is quite full of wrappers already
- not bound to irix i.e. if you have other unix machines you can run it there as well

for the sake of formatting i attached the source file to this post as well as an irix 5.3 binary of the program which should run on 5.3 and all later versions. so without further delay here it comes:

Code: Select all

/*   $Id: im_look.c 175 2016-05-01 01:46:11Z root $
 *
 *
   10000000010101010             01111                        110   1010100111
    0100010000010010              1010110                     100    000111010
    01   10101011011  111100101  000  11100        001110100  001             
   1011  00000111000  001011010  100     01111     000100011  011             
   1101     010101               111    10111100              101001110101110 
   0100       110010             000  01000001110             1010000001001010
 *
 *
 *   Demo of how to get the IRIX look without ViewKit.
 *
 *   IRIX 5: cc -O4 -Olimit 9999 im_look.c -lSgm -lXm -lXt -lX11 -lfastm -lmalloc
 */

#ifdef __sgi
#include <malloc.h>
#endif

#include <Xm/LabelG.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
#include <Xm/Xm.h>

#include <stdio.h>
#include <stdlib.h>
#include <sys/utsname.h>


/* functions */
static XtCallbackProc buttonCB(w, client_data, cbs)
   Widget w;
   XtPointer client_data;
   XmPushButtonCallbackStruct *cbs; {

   /* big ass uber-stuff happens here ... or not :-P */
   puts("someone clicked me, w00t!");
   return 0;
}


main(argc, argv)
   char *argv[]; {

   Widget master, rowcol_base, button, label;
   XtAppContext app;
   XmString label_string;
   int rc;
   char sinfo[64];
   static String fallback_resources[16];
   struct utsname u_name;

   rc = uname(&u_name);

   if (rc == -1) {
      perror("getting os info failed");
      exit(1);
   }

   /*
    *   some content for the titlebar. max. lengths differ depending on the os.
    *
    *   IRIX 4:   SYS_NMLN = 9
    *   IRIX >= 5:   SYS_NMLN = 257 (SVR4.0 size of utsname elements)
    *   Tru64: SYS_NMLN = 32
    *
    *   except for IRIX 4 we can't cover the full length so users with
    *   crazy lengths are just out of luck :-P
    *
   */
   sprintf(sinfo, "*.master.title: IRIX Style Demo :: %s %s %s [%s]", u_name.sysname, u_name.release, u_name.machine, u_name.nodename);
   rc = 0;
   fallback_resources[rc] = sinfo; ++rc;

   if (strstr(u_name.sysname, "IRIX") && atoi(u_name.release) > 4) {
      fallback_resources[rc] = "*sgiMode: TRUE"; ++rc;
      fallback_resources[rc] = "*SgNuseEnhancedFSB: TRUE"; ++rc;
      fallback_resources[rc] = "*useSchemes: all"; ++rc;
      fallback_resources[rc] = NULL;
      puts("Indigo Magic mode, yay!");
   } else {
      /* non-sgi and irix < 5 styling goes here */
   }

   /* there shall be widgets */
   master = XtVaAppInitialize(&app, "master", NULL, 0, &argc, argv, fallback_resources, NULL);
   XtVaSetValues(master,
      XmNiconName, "ISD",
      NULL);
   rowcol_base = XtVaCreateManagedWidget("rowcolumn_base",
      xmRowColumnWidgetClass, master,
      XmNorientation, XmVERTICAL,
      NULL);

   /* the stuff you can actually see */
   label_string = XmStringCreateSimple("Hi, i'm a totally useless program :-D");
   label = XtVaCreateManagedWidget("label",
      xmLabelGadgetClass, rowcol_base,
      XmNlabelString, label_string,
      XmNmarginHeight, 8,
      NULL);
   XmStringFree(label_string);

   /* the button */
   button = XmCreatePushButton(rowcol_base, "Button", NULL, 0);
   XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)buttonCB, NULL);
   XtManageChild(button);

   /* let's fire it up */
   XtRealizeWidget(master);
   XtAppMainLoop(app);
}


don't let the length of the code mislead you. all of that and more happens with viewkit as well. it's just wrapped up in classes there.
otherwise there's not much to say. i added some comments which should take care of the explanations. for Xt and Xm function details consult whatever docs you might have.
Attachments
isd.bz2
(3.78 KiB) Downloaded 27 times
im_look.c.bz2
(1.55 KiB) Downloaded 32 times

User avatar
vishnu
Donor
Donor
Posts: 3174
Joined: Sun Mar 18, 2007 3:25 pm
Location: Minneapolis, Minnesota USA

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby vishnu » Mon May 02, 2016 10:34 pm

jimmer wrote:take a look at http://viewklass.sourceforge.net/


Yup, that's Chris Toshok's Hungry Viewkit circa 1994-95, I never grabbed it because I've got Viewkit-1.31 for Linux, but not the source code just the shared objects and the headers. I've not tried it lately but probably the so is incompatible with the current version of Linux ELF... :cry:
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...

:Tezro: :Octane2:

User avatar
vishnu
Donor
Donor
Posts: 3174
Joined: Sun Mar 18, 2007 3:25 pm
Location: Minneapolis, Minnesota USA

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby vishnu » Mon Nov 14, 2016 11:01 pm

So I dusted off my copy of Viewkit for Linux from 1998 and yeah, it's useless now. So I grabbed viewklass from sourceforge and it compiles just fine and the tests compile and run, but I can't get it to link vk-hello.cpp (the viewkit equivalent of "hello, world"), I'm no expert on linkers but if the object file compiles using the same header files that the library was compiled from, how can the linker not find the same functions in the library? I would like to get this to work because I know Eric is using viewklass with max desktop and I volunteered to help him as a developer, and I've slugged it out with a lot of linker weirdness over the years but so far this has got me stumped. Anyway, not asking for help, just venting... :roll:
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...

:Tezro: :Octane2:

User avatar
foetz
Moderator
Moderator
Posts: 6543
Joined: Mon Apr 14, 2003 4:34 am
Contact:

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby foetz » Tue Nov 15, 2016 6:34 am

vishnu wrote:how can the linker not find the same functions in the library?

well since that's open sauce just compare the header and lib source files.
also what's your link line?

User avatar
duck
Donor
Donor
Posts: 731
Joined: Mon Oct 27, 2003 5:22 pm
Location: Jakobstad, Finland
Contact:

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby duck » Tue Nov 15, 2016 8:40 am

Here you go, no gnu make required. There's code here for regular C files, isn't that superflous?

Also note that tabs are required before the shell commands, and this paste will mangle them.

Code: Select all

#!smake
APP_NAME   = button

C_SRCS      =
C_OBJS      = $(C_SRCS:S/.c/.o/)

CXX_SRCS   = Main.C
CXX_OBJS   = $(CXX_SRCS:S/.C/.o/)

DIRS_INC   = -I.
DIRS_LIB   =

LIBS_STD_C   = -lm
LIBS_STD_CXX   = -lC -lCio
LIBS_X11   = -lXt -lX11 -lPW
LIBS_MOTIF   = -lSgm -lXm
LIBS_DMEDIA   = -lmoviefile -lmovieplay -ldmedia
LIBS_OPENGL   = -lGLw -lGLU -lGL
LIBS_VK      = -lvk
LIBS_EXTRA   =

LIBS = $(LIBS_EXTRA)    \
   $(LIBS_VK)       \
   $(LIBS_OPENGL)    \
   $(LIBS_MOTIF)      \
   $(LIBS_X11)      \
   $(LIBS_STD_CXX)   \
   $(LIBS_STD_C)

CC      = c99
CC_OPTS      = -O2

CXXC      = CC
CXXC_OPTS   = -O2 -LANG:std

# Suppress MIPSpro compiler warnings:
# 15 - Multiply defined
# 84 - libxxx not used for resolving any symbol
LINK_OPTS   = -woff 15,84

all: $(APP_NAME)

$(APP_NAME): ${CXX_OBJS}
   ${CXXC} ${CXX_OBJS} ${DIRS_LIB} ${LIBS} ${LINK_OPTS} -o ${APP_NAME}

.c.o: $(C_SRCS)   
   ${CC} ${CC_OPTS} ${DEFINES} ${DIRS_INC} -c $<

.C.o: $(CXX_SRCS)
   ${CXXC} ${CXXC_OPTS} ${DEFINES} ${DIRS_INC} -c $<


clean:
   rm -rf ${APP_NAME} *.o core *~ ii_* dir.txt
:Octane: halo, octane Image knightrider, d i g i t a l AlphaPC164, pond, soekris net6501, misc cool stuff in a rack
N.B.: I tend to talk out of my ass. Do not take it too seriously.

User avatar
vishnu
Donor
Donor
Posts: 3174
Joined: Sun Mar 18, 2007 3:25 pm
Location: Minneapolis, Minnesota USA

Re: How to display a clickable button in our beloved IRIX motif style.

Unread postby vishnu » Tue Nov 15, 2016 1:08 pm

foetz wrote:
vishnu wrote:how can the linker not find the same functions in the library?

well since that's open sauce just compare the header and lib source files.

Well yes, but since Viewklass is rather an immense library, if it's borked enough that it can't compile something as simple as vk-hello it's probably more work than makes sense to fix it to the point of usability. I'll have to ask Eric what version of viewklass he's using with maxx desktop... :roll:

foetz wrote:also what's your link line?


Pretty rudimentary:
g++ -o vk-hello vk-hello.o -lvk -lvkhelp -lXm -lXt -lX11 -lXmu -lXpm

duck wrote:Also note that tabs are required before the shell commands


The original author of make said that having tabs be required characters in makefiles was the biggest mistake he ever made. I heartily concur... :lol:
Project:
Temporarily lost at sea...
Plan:
World domination! Or something...

:Tezro: :Octane2:


Return to “SGI: Development”

Who is online

Users browsing this forum: No registered users and 2 guests