aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan Djärv2012-08-28 18:05:17 +0200
committerJan Djärv2012-08-28 18:05:17 +0200
commit7f8941d8b26f373a3fc614edd29166a726bc9d53 (patch)
tree97cb4050adb0c2187c0d89bf64bb638f05562773 /src
parenteada086196ccb005ded188ac2e58d41f3682a125 (diff)
downloademacs-7f8941d8b26f373a3fc614edd29166a726bc9d53.tar.gz
emacs-7f8941d8b26f373a3fc614edd29166a726bc9d53.zip
Improve NS dialogs. Add close button, remove ugly casts.
* nsmenu.m (initWithContentRect:styleMask:backing:defer:): Initialize button_values to NULL. Call setStykeMask so dialogs get a close button. (windowShouldClose:): Set window_closed. (dealloc): New member, free button_values. (process_dialog:): Make member function. Remove window argument, replace window with self. Count buttons and allocate and store values in button_values. (addButton:value:row:): value is int with the name tag. Call setTag with tag. Remove return self, declare return value as void. (addString:row:): Remove return self, declare return value as void. (addSplit): Remove return self, declare return value as void. (clicked:): Remove return self, declare return value as void. Set dialog_return to button_values[seltag]. Code formatting change. (initFromContents:isQuestion:): Adjust call to process_dialog. Code formatting change. (timeout_handler:): Set timer_fired to YES. (runDialogAt:): Set timer_fired to NO. Handle click on close button as quit. * nsterm.h (EmacsDialogPanel): Make timer_fired BOOL. Add window_closed and button_values. Add void as return value for add(Button|String|Split). addButton takes int instead of Lisp_Object. Add process_dialog as new member.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog26
-rw-r--r--src/nsmenu.m82
-rw-r--r--src/nsterm.h10
3 files changed, 79 insertions, 39 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 5bafa1a04f8..b5751d859c0 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,29 @@
12012-08-28 Jan Djärv <jan.h.d@swipnet.se>
2
3 * nsmenu.m (initWithContentRect:styleMask:backing:defer:): Initialize
4 button_values to NULL. Call setStykeMask so dialogs get a close button.
5 (windowShouldClose:): Set window_closed.
6 (dealloc): New member, free button_values.
7 (process_dialog:): Make member function. Remove window argument,
8 replace window with self. Count buttons and allocate and store values
9 in button_values.
10 (addButton:value:row:): value is int with the name tag. Call setTag
11 with tag. Remove return self, declare return value as void.
12 (addString:row:): Remove return self, declare return value as void.
13 (addSplit): Remove return self, declare return value as void.
14 (clicked:): Remove return self, declare return value as void.
15 Set dialog_return to button_values[seltag]. Code formatting change.
16 (initFromContents:isQuestion:): Adjust call to process_dialog.
17 Code formatting change.
18 (timeout_handler:): Set timer_fired to YES.
19 (runDialogAt:): Set timer_fired to NO.
20 Handle click on close button as quit.
21
22 * nsterm.h (EmacsDialogPanel): Make timer_fired BOOL.
23 Add window_closed and button_values. Add void as return value for
24 add(Button|String|Split). addButton takes int instead of Lisp_Object.
25 Add process_dialog as new member.
26
12012-08-28 Eli Zaretskii <eliz@gnu.org> 272012-08-28 Eli Zaretskii <eliz@gnu.org>
2 28
3 * ralloc.c (free_bloc): Don't dereference a 'heap' structure if it 29 * ralloc.c (free_bloc): Don't dereference a 'heap' structure if it
diff --git a/src/nsmenu.m b/src/nsmenu.m
index ab285f26df2..9e290486213 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -1498,6 +1498,7 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1498 NSImage *img; 1498 NSImage *img;
1499 1499
1500 dialog_return = Qundefined; 1500 dialog_return = Qundefined;
1501 button_values = NULL;
1501 area.origin.x = 3*SPACER; 1502 area.origin.x = 3*SPACER;
1502 area.origin.y = 2*SPACER; 1503 area.origin.y = 2*SPACER;
1503 area.size.width = ICONSIZE; 1504 area.size.width = ICONSIZE;
@@ -1579,44 +1580,65 @@ ns_popup_dialog (Lisp_Object position, Lisp_Object contents, Lisp_Object header)
1579 [self setOneShot: YES]; 1580 [self setOneShot: YES];
1580 [self setReleasedWhenClosed: YES]; 1581 [self setReleasedWhenClosed: YES];
1581 [self setHidesOnDeactivate: YES]; 1582 [self setHidesOnDeactivate: YES];
1583 [self setStyleMask:
1584 NSTitledWindowMask|NSClosableWindowMask|NSUtilityWindowMask];
1585
1582 return self; 1586 return self;
1583} 1587}
1584 1588
1585 1589
1586- (BOOL)windowShouldClose: (id)sender 1590- (BOOL)windowShouldClose: (id)sender
1587{ 1591{
1592 window_closed = YES;
1588 [NSApp stop:self]; 1593 [NSApp stop:self];
1589 return NO; 1594 return NO;
1590} 1595}
1591 1596
1597- (void)dealloc
1598{
1599 xfree (button_values);
1600 [super dealloc];
1601}
1592 1602
1593void process_dialog (id window, Lisp_Object list) 1603- (void)process_dialog: (Lisp_Object) list
1594{ 1604{
1595 Lisp_Object item; 1605 Lisp_Object item, lst = list;
1596 int row = 0; 1606 int row = 0;
1607 int buttons = 0, btnnr = 0;
1608
1609 for (; XTYPE (lst) == Lisp_Cons; lst = XCDR (lst))
1610 {
1611 item = XCAR (list);
1612 if (XTYPE (item) == Lisp_Cons)
1613 ++buttons;
1614 }
1615
1616 if (buttons > 0)
1617 button_values = (Lisp_Object *) xmalloc (buttons * sizeof (*button_values));
1597 1618
1598 for (; XTYPE (list) == Lisp_Cons; list = XCDR (list)) 1619 for (; XTYPE (list) == Lisp_Cons; list = XCDR (list))
1599 { 1620 {
1600 item = XCAR (list); 1621 item = XCAR (list);
1601 if (XTYPE (item) == Lisp_String) 1622 if (XTYPE (item) == Lisp_String)
1602 { 1623 {
1603 [window addString: SSDATA (item) row: row++]; 1624 [self addString: SSDATA (item) row: row++];
1604 } 1625 }
1605 else if (XTYPE (item) == Lisp_Cons) 1626 else if (XTYPE (item) == Lisp_Cons)
1606 { 1627 {
1607 [window addButton: SSDATA (XCAR (item)) 1628 button_values[btnnr] = XCDR (item);
1608 value: XCDR (item) row: row++]; 1629 [self addButton: SSDATA (XCAR (item)) value: btnnr row: row++];
1630 ++btnnr;
1609 } 1631 }
1610 else if (NILP (item)) 1632 else if (NILP (item))
1611 { 1633 {
1612 [window addSplit]; 1634 [self addSplit];
1613 row = 0; 1635 row = 0;
1614 } 1636 }
1615 } 1637 }
1616} 1638}
1617 1639
1618 1640
1619- addButton: (char *)str value: (Lisp_Object)val row: (int)row 1641- (void)addButton: (char *)str value: (int)tag row: (int)row
1620{ 1642{
1621 id cell; 1643 id cell;
1622 1644
@@ -1629,15 +1651,13 @@ void process_dialog (id window, Lisp_Object list)
1629 [cell setTarget: self]; 1651 [cell setTarget: self];
1630 [cell setAction: @selector (clicked: )]; 1652 [cell setAction: @selector (clicked: )];
1631 [cell setTitle: [NSString stringWithUTF8String: str]]; 1653 [cell setTitle: [NSString stringWithUTF8String: str]];
1632 [cell setTag: XHASH (val)]; // FIXME: BIG UGLY HACK!! 1654 [cell setTag: tag];
1633 [cell setBordered: YES]; 1655 [cell setBordered: YES];
1634 [cell setEnabled: YES]; 1656 [cell setEnabled: YES];
1635
1636 return self;
1637} 1657}
1638 1658
1639 1659
1640- addString: (char *)str row: (int)row 1660- (void)addString: (char *)str row: (int)row
1641{ 1661{
1642 id cell; 1662 id cell;
1643 1663
@@ -1650,36 +1670,28 @@ void process_dialog (id window, Lisp_Object list)
1650 [cell setTitle: [NSString stringWithUTF8String: str]]; 1670 [cell setTitle: [NSString stringWithUTF8String: str]];
1651 [cell setBordered: YES]; 1671 [cell setBordered: YES];
1652 [cell setEnabled: NO]; 1672 [cell setEnabled: NO];
1653
1654 return self;
1655} 1673}
1656 1674
1657 1675
1658- addSplit 1676- (void)addSplit
1659{ 1677{
1660 [matrix addColumn]; 1678 [matrix addColumn];
1661 cols++; 1679 cols++;
1662 return self;
1663} 1680}
1664 1681
1665 1682
1666- clicked: sender 1683- (void)clicked: sender
1667{ 1684{
1668 NSArray *sellist = nil; 1685 NSArray *sellist = nil;
1669 EMACS_INT seltag; 1686 EMACS_INT seltag;
1670 1687
1671 sellist = [sender selectedCells]; 1688 sellist = [sender selectedCells];
1672 if ([sellist count]<1) 1689 if ([sellist count] < 1)
1673 return self; 1690 return;
1674 1691
1675 seltag = [[sellist objectAtIndex: 0] tag]; 1692 seltag = [[sellist objectAtIndex: 0] tag];
1676 if (seltag != XHASH (Qundefined)) // FIXME: BIG UGLY HACK!! 1693 dialog_return = button_values[seltag];
1677 { 1694 [NSApp stop:self];
1678 dialog_return = seltag;
1679 [NSApp stop:self];
1680 }
1681
1682 return self;
1683} 1695}
1684 1696
1685 1697
@@ -1691,7 +1703,7 @@ void process_dialog (id window, Lisp_Object list)
1691 if (XTYPE (contents) == Lisp_Cons) 1703 if (XTYPE (contents) == Lisp_Cons)
1692 { 1704 {
1693 head = Fcar (contents); 1705 head = Fcar (contents);
1694 process_dialog (self, Fcdr (contents)); 1706 [self process_dialog: Fcdr (contents)];
1695 } 1707 }
1696 else 1708 else
1697 head = contents; 1709 head = contents;
@@ -1711,7 +1723,7 @@ void process_dialog (id window, Lisp_Object list)
1711 if (cols == 1 && rows > 1) /* Never told where to split */ 1723 if (cols == 1 && rows > 1) /* Never told where to split */
1712 { 1724 {
1713 [matrix addColumn]; 1725 [matrix addColumn];
1714 for (i = 0; i<rows/2; i++) 1726 for (i = 0; i < rows/2; i++)
1715 { 1727 {
1716 [matrix putCell: [matrix cellAtRow: (rows+1)/2 column: 0] 1728 [matrix putCell: [matrix cellAtRow: (rows+1)/2 column: 0]
1717 atRow: i column: 1]; 1729 atRow: i column: 1];
@@ -1771,7 +1783,7 @@ void process_dialog (id window, Lisp_Object list)
1771 data1: 0 1783 data1: 0
1772 data2: 0]; 1784 data2: 0];
1773 1785
1774 timer_fired = 1; 1786 timer_fired = YES;
1775 /* We use sto because stopModal/abortModal out of the main loop does not 1787 /* We use sto because stopModal/abortModal out of the main loop does not
1776 seem to work in 10.6. But as we use stop we must send a real event so 1788 seem to work in 10.6. But as we use stop we must send a real event so
1777 the stop is seen and acted upon. */ 1789 the stop is seen and acted upon. */
@@ -1799,9 +1811,9 @@ void process_dialog (id window, Lisp_Object list)
1799 [[NSRunLoop currentRunLoop] addTimer: tmo 1811 [[NSRunLoop currentRunLoop] addTimer: tmo
1800 forMode: NSModalPanelRunLoopMode]; 1812 forMode: NSModalPanelRunLoopMode];
1801 } 1813 }
1802 timer_fired = 0; 1814 timer_fired = NO;
1803 dialog_return = Qundefined; 1815 dialog_return = Qundefined;
1804 ret = [NSApp runModalForWindow: self]; 1816 [NSApp runModalForWindow: self];
1805 ret = dialog_return; 1817 ret = dialog_return;
1806 if (! timer_fired) 1818 if (! timer_fired)
1807 { 1819 {
@@ -1810,11 +1822,11 @@ void process_dialog (id window, Lisp_Object list)
1810 } 1822 }
1811 } 1823 }
1812 1824
1813 { /* FIXME: BIG UGLY HACK!!! */ 1825 if (EQ (ret, Qundefined) && window_closed)
1814 Lisp_Object tmp; 1826 /* Make close button pressed equivalent to C-g. */
1815 *(EMACS_INT*)(&tmp) = ret; 1827 Fsignal (Qquit, Qnil);
1816 return tmp; 1828
1817 } 1829 return ret;
1818} 1830}
1819 1831
1820@end 1832@end
diff --git a/src/nsterm.h b/src/nsterm.h
index 72b8d13cc47..f9149d97571 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -195,13 +195,15 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
195 NSTextField *title; 195 NSTextField *title;
196 NSMatrix *matrix; 196 NSMatrix *matrix;
197 int rows, cols; 197 int rows, cols;
198 int timer_fired; 198 BOOL timer_fired, window_closed;
199 Lisp_Object dialog_return; 199 Lisp_Object dialog_return;
200 Lisp_Object *button_values;
200 } 201 }
201- initFromContents: (Lisp_Object)menu isQuestion: (BOOL)isQ; 202- initFromContents: (Lisp_Object)menu isQuestion: (BOOL)isQ;
202- addButton: (char *)str value: (Lisp_Object)val row: (int)row; 203- (void)process_dialog: (Lisp_Object)list;
203- addString: (char *)str row: (int)row; 204- (void)addButton: (char *)str value: (int)tag row: (int)row;
204- addSplit; 205- (void)addString: (char *)str row: (int)row;
206- (void)addSplit;
205- (Lisp_Object)runDialogAt: (NSPoint)p; 207- (Lisp_Object)runDialogAt: (NSPoint)p;
206- (void)timeout_handler: (NSTimer *)timedEntry; 208- (void)timeout_handler: (NSTimer *)timedEntry;
207@end 209@end