Add -fpermissive to linux standard c++ option define in linux.cf
[oweals/cde.git] / cde / programs / dtprintinfo / UI / DtActions.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $TOG: DtActions.C /main/4 1998/08/03 16:30:18 mgreess $ */
24 /*                                                                      *
25  * (c) Copyright 1993, 1994 Hewlett-Packard Company                     *
26  * (c) Copyright 1993, 1994 International Business Machines Corp.       *
27  * (c) Copyright 1993, 1994 Sun Microsystems, Inc.                      *
28  * (c) Copyright 1993, 1994 Novell, Inc.                                *
29  */
30
31 #include "stdlib.h"
32
33 #include "DtActions.h"
34 #include "DtMainW.h"
35 #include "Button.h"
36 #include "Sep.h"
37
38 DtActions::DtActions(AnyUI *parent,
39                      char *name,
40                      char *mnemonic)
41         : Menu(parent, name, mnemonic)
42 {
43    // Empty
44 }
45
46 class DtAction : public Button {
47
48  public:
49
50    static void ActionCB(void *);
51    char *actionReferenceName;
52    ActionCallback actionCallback;
53    void *actionCallbackData;
54
55    ~DtAction();
56
57    DtAction(char *category, AnyUI *parent, char *name, char *mnemonic,
58             char *acceleratorText, char *accelerator, char *actionReferenceName,
59             ActionCallback callbackCB, void *callback_data);
60 };
61
62 DtAction::DtAction(char *category,
63                    AnyUI *parent,
64                    char *name,
65                    char *mnemonic,
66                    char *acceleratorText,
67                    char *accelerator,
68                    char *actionName,
69                    ActionCallback callbackCB,
70                    void *callback_data)
71         : Button(category, parent, name, PUSH_BUTTON, NULL, NULL, 
72                  mnemonic, acceleratorText, accelerator)
73 {
74    actionReferenceName = strdup(actionName);
75    actionCallback = callbackCB;
76    actionCallbackData = callback_data;
77    Callback(ActionCB);
78 }
79
80 DtAction::~DtAction()
81 {
82    free(actionReferenceName);
83 }
84
85 void DtAction::ActionCB(void *callback_data)
86 {
87    DtAction *action = (DtAction *) callback_data;
88    BaseUI *obj = ((DtActions *)action->Parent())->SelectedObject();
89    if (obj && action->actionCallback)
90       (*action->actionCallback)(action->actionCallbackData, obj,
91                                 action->actionReferenceName);
92 }
93
94 void DtActions::AddSep(char *objectClassName)
95 {
96    new Sep(objectClassName, this);
97 }
98
99 void DtActions::AddAction(char *name, char *category, char *actionReferenceName,
100                           ActionCallback callback, void *callback_data,
101                           char *mnemonic, char *acceleratorText,
102                           char *accelerator)
103 {
104    new DtAction(category, this, name, mnemonic, acceleratorText, accelerator,
105                 actionReferenceName, callback, callback_data);
106 }
107
108 void DtActions::UpdateActions(int n_items, BaseUI *obj)
109 {
110    if (n_items == 1)
111     {
112       Active(true);
113       int i;
114       for (i = 0; i < _numChildren; i++)
115        {
116          if (!_children[i]->Category() ||
117              !STRCMP(_children[i]->Category(), obj->Category()))
118             _children[i]->Visible(true);
119          else
120             _children[i]->Visible(false);
121        }
122     }
123    else
124       Active(false);
125    selected_object = obj;
126 }
127
128 boolean DtActions::HandleHelpRequest()
129 {
130    DtMainW *window = (DtMainW *)Parent()->Parent();
131    if (Active())
132     {
133       if (strcmp(selected_object->Category(), "Queue"))
134          window->DisplayHelp("SelectedPrintJobMenuDE");
135       else
136          window->DisplayHelp("SelectedPrinterMenuDE");
137     }
138    else if (window->PrinterAppMode() == PRINT_MANAGER)
139       window->DisplayHelp("SelectedMenuDE");
140    else
141       window->DisplayHelp("PJSelectedMenuDE");
142    return true;
143 }