Map tips
MotifUtilities.h
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 

 

// MotifUtilities.h
// 
// This file contains declarations of general Motif utility functions
// and associated structures, macros, etc.

#ifndef _DEV_CPP_MOTIF_UTILITIES_H_
#define _DEV_CPP_MOTIF_UTILITIES_H_

// Motif headers
#define String         esriXString
#define Time           esriXTime
#define Cursor         esriXCursor
#define Object         esriXObject
#define ObjectClass    esriXObjectClass
#include <Xm/Xm.h>
#include <Xm/ComboBox.h>
#include <Xm/DialogS.h>
#include <Xm/SelectioB.h>
#include <Xm/FileSB.h>
#include <Xm/RowColumn.h>
#include <Xm/MessageB.h>
#include <Xm/PushB.h>
#include <Xm/Text.h>
#include <Xm/CascadeB.h>
#include <Xm/PushBG.h>
#undef String
#undef Time
#undef Cursor
#undef Object
#undef ObjectClass

// Standard C/C++ headers
#include <iostream>
using std::cerr;
using std::endl;

// Macros
#define BUTTON1 1
#define BUTTON2 2
#define OK 1
#define CANCEL 2

// Structures
typedef struct _ModalTextPromptCallDataStruct {
  int answer;
  char strResp[256];
} ModalTextPromptCallDataStruct;

typedef struct _MenuItem {
  const char*text;
  const char*accelText;
  const char*accel;
  XtPointer callbackData;
  void (*callback)(Widget menu_item, XtPointer client_data, XtPointer call_data);
} MenuItem;

// Modal dialog function prototypes

// ModalPrompt
// 
// Routine to display a modal prompt to a user with 2 choices.  The
// function initializes an int (the answer) to 0 and passes this as
// call_data to the callback.  While this int is 0 your application
// essentially does nothing and blocks in a loop.  The callback
// changes the value of this int according to which button the user
// pressed, causing the loop to exit.  
//
// RETURNS: either BUTTON1 or BUTTON2
// IN: XtAppContext app - your application's XtAppContext
// IN: Widget parent - the dialog's parent
// IN: const char*question - the dialog's question (e.g. "Save document?")
// IN: const char*ans1 - text for button 1 (e.g. "Yes" or "Ok")
// IN: const char*ans2 - text for button 2 (e.g. "No" or "Cancel")
// IN: int default_ans - either BUTTON1 or BUTTON2
//
// example usage:
//
// if (ModalPrompt(app, parent, "Overwrite existing file?", "Yes", "No", BUTTON2) == BUTTON1)
// /* Overwrite the file because the user clicked Yes */
int ModalPrompt (
  XtAppContext app,
  Widget parent,
  const char*question,
  const char*ans1,
  const char*ans2,
  int default_ans);

// ModalTextPrompt
// 
// Routine to display a modal prompt to a user and return a text
// value.  The function initializes the values of a static callback
// structure and passes this as call_data to its callback.  The
// callback structure contains an int (the button which the user
// clicked) and a character array to hold the response.  While the int
// is 0 your application essentially does nothing and blocks in a
// loop.  The callback changes the value of this int according to
// which button the user pressed, causing the loop to exit, and also
// copies the text of the response into the callback structure's char
// array. The function then uses the callback structure's character
// array as its return value.

// RETURNS: const char* string of the text the user types
// IN: XtAppContext app - your application's XtAppContext
// IN: Widget parent - the dialog's parent
// IN: const char*inPrompt - the dialog's question (e.g. "Enter file name:")
// OUT: outClickedCancel - this is set to either OK or CANCEL
//      depending on what the user clicked
//
// example usage:
//
// int button = CANCEL; 
// char *newValue = ModalTextPrompt(app, parent,"New value:", &button);
// if (button == OK)
//   value = newValue;
char *ModalTextPrompt (
  XtAppContext app,
  Widget parent,
  const char*inPrompt,
  int *outClickedCancel);

// ModalSelectionDialog
// 
// Routine to display a modal SelectionDialog to a user and return a
// text value representing the user's selection.  The function
// initializes the values of a static callback structure and passes
// this as call_data to its callback.  The callback structure contains
// an int (the button which the user clicked) and a character array to
// hold the response.  While the int is 0 your application essentially
// does nothing and blocks in a loop.  The callback changes the value
// of this int according to which button the user pressed, causing the
// loop to exit, and also copies the text of the response into the
// callback structure's char array. The function then uses the
// callback structure's character array as its return value.

//  RETURNS: char * string of the text the user types
//  IN: XtAppContext app - your application's XtAppContext
//  IN: Widget parent - the dialog's parent
//  IN: const char*prompt - the dialog's question (e.g. "Enter file name:")
//  XmString *inItems - an XmStringTable containing the items for the dialog
//  int inItemCount - count of inItems items
//  OUT: outClickedCancel - this is set to either OK or CANCEL
//       depending on what the user clicked
//
// example usage:
//
// int button = CANCEL;
// char *selectedItem = ModalSelectionDialog(
//    app,
//    parent,
//    "Select an item:",
//    str,               /* an XmStringTable */
//    strCount,          /* count of items in str */
//    &button);
// if (button == OK)
//   DoSomething (selectedItem);
char *ModalSelectionDialog (
  XtAppContext app,
  Widget parent,
  const char*inPrompt,
  XmString *inItems,
  int inItemCount,
  int *outClickedCancel);

// ModalFileSelectionDialog
// 
// Routine to display a modal FileSelectionDialog to a user and return
// a text value representing the user's selection.  The function
// initializes the values of a static callback structure and passes
// this as call_data to its callback.  The callback structure contains
// an int (the button which the user clicked) and a character array to
// hold the response.  While the int is 0 your application essentially
// does nothing and blocks in a loop.  The callback changes the value
// of this int according to which button the user pressed, causing the
// loop to exit, and also copies the text of the response into the
// callback structure's char array. The function then uses the
// callback structure's character array as its return value.

//  RETURNS: char * string representing the file name 
//  IN: XtAppContext app - your application's XtAppContext
//  IN: Widget parent - the dialog's parent
//  IN: const char*inPrompt - the dialog's question (e.g. "Enter file name:")
//  IN: const char*inMask - which types of files to show (e.g. "*.lyr")
//  OUT: outClickedCancel - this is set to either OK or CANCEL
//       depending on what the user clicked
//
// example usage:
//
// int button = CANCEL;
// char *selectedItem = ModalSelectionDialog(
//    app,
//    parent,
//    "Select an item:",
//    str,               /* an XmStringTable */
//    strCount,          /* count of items in str */
//    &button);
// if (button == OK)
//   DoSomething (selectedItem);
char *ModalFileSelectionDialog (
  XtAppContext app,
  Widget parent,
  const char*inPrompt,
  const char*inMask,
  int *outClickedCancel);

// Modal dialog callback function prototypes
void ModalPromptCallback (
  Widget widget,
  XtPointer client_data,
  XtPointer call_data);
void ModalTextPromptCallback (
  Widget widget,
  XtPointer client_data,
  XtPointer call_data);
void ModalSelectionDialogCallback (
  Widget widget,
  XtPointer client_data,
  XtPointer call_data);
void ModalFileSelectionDialogCallback (
  Widget widget,
  XtPointer client_data,
  XtPointer call_data);
    
// Utility function to dispay a MessageDialog
void ShowMessage (
  Widget parent,
  const char *dialogtitle,
  const char *text,
  bool asError);

// Remove all items from a combobox widget
void ClearCombo(Widget w);

// Removes the item w/ value inItem from the inCombobox and resets its
// textfield. 
void RemovePosition(Widget inCombobox, char *inItem);

// Method to set the contents of a combobox
void SetComboboxItems (Widget inCombobox, XmString *inItems, int inItemCount);

// Create a menu containing the items specified in items.  Uses the
// variable mainmenu as the menubar.  mnem can be NULL,
// everything else cannot be (except for items when number == 0).
void CreateMenu (
  Widget menubar,
  Widget menu,
  const char* menuname,
  char mnem,
  MenuItem *items,
  int number,
  Widget widgetIDs []);

void CenterDialog (Widget centerOver, Widget toCenter);

#endif //_DEV_CPP_MOTIF_UTILITIES_H_