xref: /aoo4110/main/toolkit/source/layout/core/vcl.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <vcl.hxx>
25 
26 #include <sal/types.h>
27 #include <vcl/button.hxx>
28 
get_button(Dialog const * dialog,sal_uInt32 type)29 static PushButton* get_button (Dialog const* dialog, sal_uInt32 type)
30 {
31     Window* child = dialog->GetWindow (WINDOW_FIRSTCHILD);
32     while (child)
33     {
34         if (child->GetType () == type)
35             return static_cast <PushButton*> (child);
36         child = child->GetWindow (WINDOW_NEXT);
37     }
38 
39     return 0;
40 }
41 
42 #define IMPLEMENT_CLOSING_DIALOG(cls)\
43     Closing##cls::Closing##cls (Window* parent, WinBits bits)\
44     : cls (parent, bits)\
45         , mClosing (false)\
46     {\
47     }\
48     sal_Bool Closing##cls::Close ()\
49     {\
50         if (mClosing)\
51             EndDialog (false);\
52         else if (PushButton *cancel = get_button (this, WINDOW_CANCELBUTTON))\
53             cancel->Click ();\
54         else if (PushButton *ok = get_button (this, WINDOW_OKBUTTON))\
55             ok->Click ();\
56         mClosing = true;\
57         return false;\
58     }
59 
60 IMPLEMENT_CLOSING_DIALOG (Dialog);
61 IMPLEMENT_CLOSING_DIALOG (ModelessDialog);
62 IMPLEMENT_CLOSING_DIALOG (ModalDialog);
63